00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _OPENCITY_ENVIRONMENT_H_
00023 #define _OPENCITY_ENVIRONMENT_H_ 1
00024
00025 #include <vector>
00026 #include <map>
00027 #include "agent.h"
00028
00029 #define MAX_PATH_LENGTH 20
00030
00031 class Destination;
00032 class Structure;
00033 class Layer;
00034
00035
00036 unsigned char randomBool();
00037 int randomInt(int min, int max);
00038 direction_t rotate180(direction_t dir);
00039 direction_t rotateLeft(direction_t dir);
00040 direction_t rotateRight(direction_t dir);
00041
00042
00043
00046 class AgentPosition
00047 {
00048 public:
00049 int x, y;
00050 unsigned long step;
00051
00052 AgentPosition() : x(-1), y(-1), step(0) {}
00053 AgentPosition(int xx, int yy, unsigned long xstep) : x(xx), y(yy), step(xstep) {}
00054 AgentPosition(const AgentPosition &p) : x(p.x), y(p.y), step(p.step) {}
00055 };
00056
00057
00058
00062 class Environment
00063 {
00064 public:
00065
00071 Environment(unsigned int width, unsigned int height, Layer* pBL, Kernel *kernel);
00072
00073 unsigned int getHeight() const;
00074 unsigned int getWidth() const;
00075
00076
00077
00081 void displayAgent();
00082
00083
00084 void registerAgent(Agent* agent, int x, int y);
00085 void unregisterAgent(Agent* agent);
00086
00087 Agent* getAgentAt(int x, int y);
00088 bool hasAgentAt(const Agent* agent, int x, int y) const;
00089 bool moveAgent(Agent* agent, int x, int y);
00090
00091
00092
00097 const bool
00098 findShortestPath(
00099 unsigned int x1, unsigned int y1,
00100 unsigned int x2, unsigned int y2,
00101 std::vector<Destination> & rvdest );
00102
00103 Structure* getBuildingXY(unsigned int x, unsigned int y);
00104
00105
00106
00107
00108
00109
00113 static unsigned int
00114 toSquareDistance(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2);
00115
00116
00117 private:
00118 unsigned int m_width;
00119 unsigned int m_height;
00120 Kernel *m_kernel;
00121 Layer* m_pBuildingLayer;
00122 std::map<Agent*, AgentPosition> m_last_pos;
00123 typedef std::map<Agent*, AgentPosition>::iterator m_last_pos_it;
00124 std::vector<Agent*> m_vector;
00125 typedef std::vector<Agent*>::iterator m_vector_it;
00126 typedef std::vector<Agent*>::const_iterator m_vector_cit;
00127 };
00128
00129
00130 #endif
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163