00001 #ifndef AIAGENT_H 00002 #define AIAGENT_H 00003 00004 #ifdef DARWIN 00005 #include <Python/Python.h> 00006 #else 00007 #include <Python.h> 00008 #endif 00009 00010 #include <ngl/Vec3.h> 00011 #include <ngl/TransformStack.h> 00012 #include <ngl/Camera.h> 00013 #include <string> 00014 #include "Brain.h" 00015 #include "Environment.h" 00016 #include "Models.h" 00017 #include "Ammo.h" 00018 #include <stack> 00019 #include <queue> 00020 #include "Agent.h" 00021 00030 00031 //A enumerated variable to hold the directions 00032 enum Direction{east, west, north,south}; 00033 00034 00035 //A structure to check the shortest distance algorithm 00036 struct Tile { 00037 int index; 00038 ngl::Vec3 position; 00039 int distanceFromtarget; 00040 }; 00041 00042 class compareDistance{ 00043 public: 00044 bool operator()(Tile& t1, Tile& t2) 00045 { 00046 if(t1.distanceFromtarget > t2.distanceFromtarget) 00047 { 00048 return true; 00049 } 00050 return false; 00051 } 00052 }; 00053 00054 class Brain; 00055 class Ammo; 00056 class Graph; 00057 class GraphEdge; 00058 class Agent; 00059 00060 class AIagent 00061 { 00062 public : 00063 //---------------------------------------------------------------------------------------------------------------------- 00078 //---------------------------------------------------------------------------------------------------------------------- 00079 AIagent(std::string _file,PyObject *_main,PyObject *_dict,int _index,std::string _meshName,float _radius,Models *_model,Graph *_graph,Agent* _parent,std::string _type,int _ID,int _armyID,std::string _state); 00080 //---------------------------------------------------------------------------------------------------------------------- 00093 //---------------------------------------------------------------------------------------------------------------------- 00094 AIagent(Agent* _parent,std::string _file,PyObject *_main,PyObject *_dict,ngl::Vec3 _pos, std::string _type, float _radius,Models *_model,Graph* _graph, std::string _meshName, int _ID); 00095 00096 //---------------------------------------------------------------------------------------------------------------------- 00098 //---------------------------------------------------------------------------------------------------------------------- 00099 ~AIagent(); 00100 //---------------------------------------------------------------------------------------------------------------------- 00102 //---------------------------------------------------------------------------------------------------------------------- 00103 void update(); 00104 //---------------------------------------------------------------------------------------------------------------------- 00108 //---------------------------------------------------------------------------------------------------------------------- 00109 void draw( 00110 ngl::TransformStack *_tx, 00111 ngl::Camera *_cam 00112 ); 00113 //---------------------------------------------------------------------------------------------------------------------- 00115 //---------------------------------------------------------------------------------------------------------------------- 00116 void reloadScript(); 00117 //---------------------------------------------------------------------------------------------------------------------- 00120 //---------------------------------------------------------------------------------------------------------------------- 00121 void setNewScriptPath( 00122 const std::string &_p 00123 ); 00124 //---------------------------------------------------------------------------------------------------------------------- 00127 //---------------------------------------------------------------------------------------------------------------------- 00128 void inline setWallNormal(const ngl::Vec3 _normal,const float _dist){m_wallNormal = _normal;m_wallDistance = _dist;} 00129 //---------------------------------------------------------------------------------------------------------------------- 00132 //---------------------------------------------------------------------------------------------------------------------- 00133 void inline setApproachingAgentParams(const float _dist,const ngl::Vec3 _pos,const ngl::Vec3 _vel){m_obstacleDistance = _dist; m_obsPos = _pos;m_obsVel = _vel;} 00134 //---------------------------------------------------------------------------------------------------------------------- 00136 //---------------------------------------------------------------------------------------------------------------------- 00137 ngl::Vec3 inline getPos(){return m_pos;} 00138 //---------------------------------------------------------------------------------------------------------------------- 00140 //---------------------------------------------------------------------------------------------------------------------- 00141 ngl::Vec3 inline getVelocity(){return m_velocity;} 00142 //---------------------------------------------------------------------------------------------------------------------- 00144 //---------------------------------------------------------------------------------------------------------------------- 00145 ngl::Vec3 inline getForce(){return m_force;} 00146 //---------------------------------------------------------------------------------------------------------------------- 00149 //---------------------------------------------------------------------------------------------------------------------- 00150 void inline setPosition(const ngl::Vec3 pos){m_pos = pos;} 00151 //---------------------------------------------------------------------------------------------------------------------- 00154 //---------------------------------------------------------------------------------------------------------------------- 00155 void inline setVelocity(const ngl::Vec3 vel){m_velocity = vel;} 00156 //---------------------------------------------------------------------------------------------------------------------- 00158 //---------------------------------------------------------------------------------------------------------------------- 00159 float inline getRadius(){return m_model->getModel(m_meshName)->getSphereRadius();} 00160 //---------------------------------------------------------------------------------------------------------------------- 00162 //---------------------------------------------------------------------------------------------------------------------- 00163 void reset(); 00164 //---------------------------------------------------------------------------------------------------------------------- 00166 //---------------------------------------------------------------------------------------------------------------------- 00167 float inline getScore(){return m_score;} 00168 //---------------------------------------------------------------------------------------------------------------------- 00171 //---------------------------------------------------------------------------------------------------------------------- 00172 void inline setScore(const int _score){m_score += _score;} 00173 //---------------------------------------------------------------------------------------------------------------------- 00175 //---------------------------------------------------------------------------------------------------------------------- 00176 void inline resetScore(){m_score = 0;} 00177 //---------------------------------------------------------------------------------------------------------------------- 00179 //---------------------------------------------------------------------------------------------------------------------- 00180 int inline getReset(){return m_reset;} 00181 //---------------------------------------------------------------------------------------------------------------------- 00183 //---------------------------------------------------------------------------------------------------------------------- 00184 std::string inline getName(){return m_meshName;} 00185 //---------------------------------------------------------------------------------------------------------------------- 00187 //---------------------------------------------------------------------------------------------------------------------- 00188 int inline getNextIndex(){return m_nextIndex;} 00189 //---------------------------------------------------------------------------------------------------------------------- 00191 //---------------------------------------------------------------------------------------------------------------------- 00192 int inline getIndex(){return m_index;} 00193 //---------------------------------------------------------------------------------------------------------------------- 00196 //---------------------------------------------------------------------------------------------------------------------- 00197 void inline setIndex(const int _index){m_index = _index;} 00198 //---------------------------------------------------------------------------------------------------------------------- 00201 //---------------------------------------------------------------------------------------------------------------------- 00202 void inline setNextIndex(const int _nextIndex){m_nextIndex = _nextIndex;} 00203 //---------------------------------------------------------------------------------------------------------------------- 00206 //---------------------------------------------------------------------------------------------------------------------- 00207 void setRoute(std::vector <int> _route); 00208 //---------------------------------------------------------------------------------------------------------------------- 00210 //---------------------------------------------------------------------------------------------------------------------- 00211 int inline getPrecision(){return m_precision;} 00212 //---------------------------------------------------------------------------------------------------------------------- 00214 //---------------------------------------------------------------------------------------------------------------------- 00215 inline Direction getDirection(){return m_direction;} 00216 //---------------------------------------------------------------------------------------------------------------------- 00219 //---------------------------------------------------------------------------------------------------------------------- 00220 void setDirection(int _direction); 00221 //---------------------------------------------------------------------------------------------------------------------- 00224 //---------------------------------------------------------------------------------------------------------------------- 00225 void inline setIntialWallBool(bool _wall){m_wall = _wall;} 00226 //---------------------------------------------------------------------------------------------------------------------- 00228 //---------------------------------------------------------------------------------------------------------------------- 00229 std::string inline getMessage(){return m_message;} 00230 //---------------------------------------------------------------------------------------------------------------------- 00232 //---------------------------------------------------------------------------------------------------------------------- 00233 std::string inline getState(){return m_state;} 00234 //---------------------------------------------------------------------------------------------------------------------- 00237 //---------------------------------------------------------------------------------------------------------------------- 00238 void inline setMessage(const std::string _message){m_message = _message;} 00239 //---------------------------------------------------------------------------------------------------------------------- 00241 //---------------------------------------------------------------------------------------------------------------------- 00242 ngl::Vec3 inline getTargetPos(){return m_targetPos;} 00243 //---------------------------------------------------------------------------------------------------------------------- 00246 //---------------------------------------------------------------------------------------------------------------------- 00247 void inline setTargetPos(const ngl::Vec3 _pos){m_targetPos = _pos;} 00248 //---------------------------------------------------------------------------------------------------------------------- 00250 //---------------------------------------------------------------------------------------------------------------------- 00251 void inline setHitStatus(){m_hit = true;} 00252 //---------------------------------------------------------------------------------------------------------------------- 00254 //---------------------------------------------------------------------------------------------------------------------- 00255 bool inline getHitStatus(){return m_hit;} 00256 //---------------------------------------------------------------------------------------------------------------------- 00258 //---------------------------------------------------------------------------------------------------------------------- 00259 std::string inline getType(){return m_type;} 00260 //---------------------------------------------------------------------------------------------------------------------- 00262 //---------------------------------------------------------------------------------------------------------------------- 00263 ngl::Vec3 getHomePos(){return m_tempPos;} 00264 //---------------------------------------------------------------------------------------------------------------------- 00267 //---------------------------------------------------------------------------------------------------------------------- 00268 void inline setState(const std::string _state){m_state = _state;} 00269 //---------------------------------------------------------------------------------------------------------------------- 00271 //---------------------------------------------------------------------------------------------------------------------- 00272 void queryEnvironment(); 00273 //---------------------------------------------------------------------------------------------------------------------- 00275 //-------------------------------------------------------------------------------------------------------------------- 00276 bool m_wallCollision; 00277 //---------------------------------------------------------------------------------------------------------------------- 00279 //-------------------------------------------------------------------------------------------------------------------- 00280 bool m_ObstacleCollision; 00281 //---------------------------------------------------------------------------------------------------------------------- 00283 //-------------------------------------------------------------------------------------------------------------------- 00284 bool m_approachingAgent; 00285 //---------------------------------------------------------------------------------------------------------------------- 00287 //-------------------------------------------------------------------------------------------------------------------- 00288 ngl::Vec3 m_wallNormal; 00289 //---------------------------------------------------------------------------------------------------------------------- 00291 //-------------------------------------------------------------------------------------------------------------------- 00292 float m_wallDistance; 00293 //---------------------------------------------------------------------------------------------------------------------- 00295 //-------------------------------------------------------------------------------------------------------------------- 00296 float m_obstacleDistance; 00297 //---------------------------------------------------------------------------------------------------------------------- 00299 //-------------------------------------------------------------------------------------------------------------------- 00300 float m_radius; 00301 //---------------------------------------------------------------------------------------------------------------------- 00303 //-------------------------------------------------------------------------------------------------------------------- 00304 ngl::Vec3 m_obsPos; 00305 //---------------------------------------------------------------------------------------------------------------------- 00307 //-------------------------------------------------------------------------------------------------------------------- 00308 ngl::Vec3 m_obsVel; 00309 //---------------------------------------------------------------------------------------------------------------------- 00311 //-------------------------------------------------------------------------------------------------------------------- 00312 int m_reset; 00313 //---------------------------------------------------------------------------------------------------------------------- 00315 //-------------------------------------------------------------------------------------------------------------------- 00316 bool m_shootSphere; 00317 //---------------------------------------------------------------------------------------------------------------------- 00319 //-------------------------------------------------------------------------------------------------------------------- 00320 bool m_shootBlock; 00321 //---------------------------------------------------------------------------------------------------------------------- 00323 //-------------------------------------------------------------------------------------------------------------------- 00324 int m_iterator; 00325 //---------------------------------------------------------------------------------------------------------------------- 00327 //-------------------------------------------------------------------------------------------------------------------- 00328 bool m_wall; 00329 00330 00331 00332 00333 00334 private : 00335 00336 void brainFunction(); 00337 //---------------------------------------------------------------------------------------------------------------------- 00339 //---------------------------------------------------------------------------------------------------------------------- 00340 ngl::Vec3 m_pos; 00341 //---------------------------------------------------------------------------------------------------------------------- 00343 //---------------------------------------------------------------------------------------------------------------------- 00344 ngl::Vec3 m_dir; 00345 //---------------------------------------------------------------------------------------------------------------------- 00347 //---------------------------------------------------------------------------------------------------------------------- 00348 ngl::Vec3 m_velocity; 00350 //---------------------------------------------------------------------------------------------------------------------- 00351 std::string *m_script; 00352 //---------------------------------------------------------------------------------------------------------------------- 00354 //---------------------------------------------------------------------------------------------------------------------- 00355 std::string m_filename; 00356 //---------------------------------------------------------------------------------------------------------------------- 00358 //---------------------------------------------------------------------------------------------------------------------- 00360 //---------------------------------------------------------------------------------------------------------------------- 00361 PyObject *m_main; 00362 //---------------------------------------------------------------------------------------------------------------------- 00364 //---------------------------------------------------------------------------------------------------------------------- 00365 PyObject *m_dict; 00366 //---------------------------------------------------------------------------------------------------------------------- 00368 //---------------------------------------------------------------------------------------------------------------------- 00369 Brain *m_brain; 00370 //---------------------------------------------------------------------------------------------------------------------- 00372 //---------------------------------------------------------------------------------------------------------------------- 00373 ngl::Vec3 m_tempVel; 00374 //---------------------------------------------------------------------------------------------------------------------- 00376 //---------------------------------------------------------------------------------------------------------------------- 00377 ngl::Vec3 m_tempPos; 00378 //---------------------------------------------------------------------------------------------------------------------- 00380 //---------------------------------------------------------------------------------------------------------------------- 00381 ngl::Vec3 m_force; 00382 //---------------------------------------------------------------------------------------------------------------------- 00384 //---------------------------------------------------------------------------------------------------------------------- 00385 Models *m_model; 00386 //---------------------------------------------------------------------------------------------------------------------- 00388 //---------------------------------------------------------------------------------------------------------------------- 00389 std::string m_meshName; 00390 //---------------------------------------------------------------------------------------------------------------------- 00392 //---------------------------------------------------------------------------------------------------------------------- 00393 std::list<Ammo *> m_ammo; 00394 //---------------------------------------------------------------------------------------------------------------------- 00396 //------------------------------------------------------------------------------------------------------------- 00397 Graph *m_graph; 00398 //---------------------------------------------------------------------------------------------------------------------- 00400 //------------------------------------------------------------------------------------------------------------- 00401 int m_index; 00402 //---------------------------------------------------------------------------------------------------------------------- 00404 //------------------------------------------------------------------------------------------------------------- 00405 int m_nextIndex; 00406 //---------------------------------------------------------------------------------------------------------------------- 00408 //---------------------------------------------------------------------------------------------------------------------- 00409 std::vector <int> m_route; 00410 //---------------------------------------------------------------------------------------------------------------------- 00412 //------------------------------------------------------------------------------------------------------------- 00413 int m_precision; 00414 //---------------------------------------------------------------------------------------------------------------------- 00416 //------------------------------------------------------------------------------------------------------------- 00417 Direction m_direction; 00418 //---------------------------------------------------------------------------------------------------------------------- 00420 //------------------------------------------------------------------------------------------------------------- 00421 std::string m_message; 00422 //---------------------------------------------------------------------------------------------------------------------- 00424 //------------------------------------------------------------------------------------------------------------- 00425 Agent* m_parent; 00426 //---------------------------------------------------------------------------------------------------------------------- 00428 //------------------------------------------------------------------------------------------------------------- 00429 bool m_hit; 00430 //---------------------------------------------------------------------------------------------------------------------- 00432 //------------------------------------------------------------------------------------------------------------- 00433 std::string m_type; 00434 //---------------------------------------------------------------------------------------------------------------------- 00436 //------------------------------------------------------------------------------------------------------------- 00437 int m_ID; 00438 //---------------------------------------------------------------------------------------------------------------------- 00440 //------------------------------------------------------------------------------------------------------------- 00441 int m_armyID; 00442 //---------------------------------------------------------------------------------------------------------------------- 00444 //------------------------------------------------------------------------------------------------------------- 00445 std::string m_state; 00446 //---------------------------------------------------------------------------------------------------------------------- 00448 //------------------------------------------------------------------------------------------------------------- 00449 ngl::Vec3 m_targetPos; 00450 //---------------------------------------------------------------------------------------------------------------------- 00452 //------------------------------------------------------------------------------------------------------------- 00453 float m_score; 00454 00455 }; 00456 00457 00458 00459 #endif // AIAGENT_H