fix agentOnCamera to cope with the wrap
[openc2e.git] / World.h
blobacb64c02dd9eea837c6c3e94f744af4ad175edbe
1 /*
2 * World.h
3 * openc2e
5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #ifndef _WORLD_H
21 #define _WORLD_H
23 #include "Map.h"
24 #include "Scriptorium.h"
25 #include "Camera.h"
26 #include "Agent.h"
27 #include "CompoundPart.h"
28 #include "prayManager.h"
29 #include "historyManager.h"
30 #include "imageManager.h"
31 #include <set>
32 #include <map>
33 #include <boost/filesystem/path.hpp>
35 struct cainfo {
36 float gain;
37 float loss;
38 float diffusion;
41 struct scriptevent {
42 unsigned short scriptno;
43 AgentRef agent, from;
44 caosVar p[2];
47 class World {
48 protected:
49 class PointerAgent *theHand;
50 std::list<scriptevent> scriptqueue;
52 std::list<std::pair<boost::shared_ptr<class AudioSource>, bool> > uncontrolled_sounds; // audio, followingviewport
54 std::map<int, boost::weak_ptr<Agent> > unidmap;
55 std::vector<caosVM *> vmpool;
57 public:
58 bool quitting, saving, paused;
60 Map map;
62 std::multiset<CompoundPart *, partzorder> zorder; // sorted from top to bottom
63 std::multiset<renderable *, renderablezorder> renders; // sorted from bottom to top
64 std::list<boost::shared_ptr<Agent> > agents;
66 std::map<unsigned int, std::map<unsigned int, cainfo> > carates;
67 std::map<std::string, caosVar> variables;
69 std::vector<boost::filesystem::path> data_directories;
70 Scriptorium scriptorium;
71 prayManager praymanager;
72 imageManager gallery;
73 historyManager history;
75 std::string gametype;
76 float pace;
77 unsigned int race;
78 unsigned int ticktime, tickcount;
79 unsigned int worldtickcount;
80 unsigned int timeofday, dayofseason, season, year;
81 MainCamera camera;
82 bool showrooms, autokill, autostop;
84 std::vector<unsigned int> groundlevels;
86 AgentRef selectedcreature;
87 void selectCreature(boost::shared_ptr<Agent> c);
88 AgentRef focusagent; unsigned int focuspart;
89 void setFocus(class TextEntryPart *p);
91 Agent *agentAt(unsigned int x, unsigned int y, bool obey_all_transparency = true, bool needs_mouseable = false);
92 CompoundPart *partAt(unsigned int x, unsigned int y, bool obey_all_transparency = true, bool needs_mouseable = false);
93 class PointerAgent *hand() { return theHand; }
95 caosVM *getVM(Agent *owner);
96 void freeVM(caosVM *);
97 void queueScript(unsigned short event, AgentRef agent, AgentRef from = AgentRef(), caosVar p0 = caosVar(), caosVar p1 = caosVar());
99 World();
100 ~World();
101 void init();
102 void initCatalogue();
103 void shutdown();
105 void executeInitScript(boost::filesystem::path p);
106 void executeBootstrap(boost::filesystem::path p);
107 void executeBootstrap(bool switcher);
109 std::string getUserDataDir();
110 std::string findFile(std::string path);
111 std::vector<std::string> findFiles(std::string dir, std::string wild);
113 boost::shared_ptr<AudioSource> playAudio(std::string filename, AgentRef agent, bool controlled, bool loop, bool followviewport = false);
115 void newMoniker(shared_ptr<genomeFile> g, std::string genefile, AgentRef agent);
116 shared_ptr<genomeFile> loadGenome(std::string &filename);
117 std::string generateMoniker(std::string basename);
119 int findCategory(unsigned char family, unsigned char genus, unsigned short species);
121 void tick();
122 void drawWorld();
123 void drawWorld(Camera *cam, Surface *surface);
125 int newUNID(Agent *whofor);
126 void setUNID(Agent *whofor, int unid);
127 void freeUNID(int unid);
129 shared_ptr<Agent> lookupUNID(int unid);
132 extern World world;
133 #endif
134 /* vim: set noet: */