- Timestamp:
- Dec 21, 2006, 3:49:51 PM (18 years ago)
- Location:
- branches/ai/src/ai
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_engine.cc
r10135 r10137 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 12 10 13 11 ### File Specific: 14 main-programmer: Patrick Boenzli12 main-programmer: Thomas Fahrni 15 13 co-programmer: 16 14 */ 17 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 18 19 16 #include "ai_engine.h" 20 17 #include "debug.h" … … 22 19 AIEngine* AIEngine::singletonRef = NULL; 23 20 24 AIEngine::AIEngine(){ 25 for(int i=0; i < maxTeams; i++ )teams[i]=NULL; 21 void AIEngine::tick(float dt) 22 { 23 std::map<int,AITeam*>::iterator it; 24 for (it= teams.begin(); it!= teams.end(); it++ ) 25 it->second->process(dt); 26 26 } 27 27 28 AITeam* AIEngine::getTeam(int teamNumber)28 void AIEngine::addAI(int teamNumber, int swarmNumber, AIModule* aiModule) 29 29 { 30 if(teamNumber>maxTeams || teamNumber<0)return NULL; 31 return teams[teamNumber]; 30 std::pair<std::map<int,AITeam*>::iterator,bool> p; 31 AITeam* newTeam=new AITeam(); 32 p=teams.insert(std::make_pair(teamNumber,newTeam)); 33 if(!p.second)delete newTeam; 34 p.first->second->addAI(swarmNumber, aiModule); 32 35 } 33 36 34 AITeam* AIEngine::getCreateTeam(int teamNumber)37 void AIEngine::removeAI(int teamNumber, int swarmNumber, AIModule* aiModule) 35 38 { 36 if(teamNumber>maxTeams || teamNumber<0)return NULL; 37 if(teams[teamNumber]==NULL)teams[teamNumber]=new AITeam(); 38 return teams[teamNumber]; 39 std::map<int,AITeam*>::iterator it = teams.find(swarmNumber); 40 if(it==teams.end())return; 41 it->second->removeAI(swarmNumber,aiModule); 42 if(it->second->getTeamSize()==0){ 43 delete it->second; 44 teams.erase(it); 45 } 39 46 } 40 47 41 42 void AIEngine::addTeam(int teamNumber)43 {44 if(teamNumber>maxTeams || teamNumber<0)return;45 teams[teamNumber]=new AITeam();46 }47 48 49 void AIEngine::removeTeam(int teamNumber)50 {51 if(teamNumber>maxTeams || teamNumber<0)return;52 teams[teamNumber]=NULL;53 }54 55 56 void AIEngine::tick(float dt)57 {58 for(int i=0; i < maxTeams; i++ )59 if(teams[i]!=NULL)teams[i]->process(dt);60 }61 62 63 void AIEngine::rebuildAIVector(){64 //AIVector.clear();65 66 //for(int i=0; i < maxTeams; i++ )67 //if(teams[i]!=NULL)AIVector.push_back(teams[i]);68 } -
branches/ai/src/ai/ai_engine.h
r10135 r10137 14 14 15 15 void tick(float dt); 16 17 void addTeam(int teamNumber); 18 void removeTeam(int teamNumber); 19 AITeam* getTeam(int teamNumber); 20 AITeam* getCreateTeam(int teamNumber); 21 16 void addAI(int teamNumber, int swarmNumber, AIModule* aiModule); 17 void removeAI(int teamNumber, int swarmNumber, AIModule* aiModule); 18 22 19 private: 23 void rebuildAIVector(); 24 25 std::vector<AIModule*> AIVector; 26 27 static const int maxTeams=32; 28 AITeam* teams[32]; 29 AIEngine(); 30 20 AIEngine(){} 31 21 static AIEngine* singletonRef; 22 std::map<int,AITeam*> teams; 32 23 }; 33 24 -
branches/ai/src/ai/ai_swarm.cc
r10135 r10137 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 16 14 */ 17 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 18 19 16 #include "ai_swarm.h" 20 17 #include "debug.h" 21 18 22 19 void AISwarm::process(float dt) 23 20 { 24 Vector swarmCenter; 25 26 for(unsigned int i=0;i<swarmMembers.size();i++){ 27 //swarmCenter=swarmCenter+swarmMembers.at(i)->getPosition(); 28 } 29 swarmCenter=swarmCenter/swarmMembers.size(); 30 31 for(unsigned int i=0;i<swarmMembers.size();i++) 32 swarmMembers.at(i)->process(dt); 21 std::set<AIModule*>::iterator it; 22 for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ) 23 (*it)->process(dt); 33 24 } 34 25 35 36 void AISwarm::addToSwarm(AIModule* newMember) 26 void AISwarm::addAI(AIModule* aiModule) 37 27 { 38 swarmMembers. push_back(newMember);28 swarmMembers.insert(aiModule); 39 29 } 40 30 41 42 void AISwarm::removeFromSwarm(AIModule* member) 31 void AISwarm::removeAI(AIModule* aiModule) 43 32 { 44 std::vector<AIModule*>::iterator it = this->swarmMembers.begin(); 45 for(; it < this->swarmMembers.end(); it++) { 46 47 // for(unsigned int i=0;i<swarmMembers.size();i++){ 48 if(*it==member){ 49 swarmMembers.erase(it); 50 return; 51 } 52 } 33 std::set<AIModule*>::iterator it=swarmMembers.find(aiModule); 34 if(it==swarmMembers.end())return; 35 delete (*it); 53 36 } 54 37 55 56 38 int AISwarm::getSwarmSize() 39 { 40 return swarmMembers.size(); 41 } -
branches/ai/src/ai/ai_swarm.h
r10135 r10137 9 9 class AISwarm{ 10 10 public: 11 AISwarm(){} ;12 ~AISwarm(){} ;11 AISwarm(){} 12 ~AISwarm(){} 13 13 void process(float dt); 14 void addToSwarm(AIModule* newMember); 15 void removeFromSwarm(AIModule* member); 14 void addAI(AIModule* newMember); 15 void removeAI(AIModule* oldMember); 16 int getSwarmSize(); 16 17 private: 17 std:: vector<AIModule*> swarmMembers;18 std::set<AIModule*> swarmMembers; 18 19 }; 19 20 -
branches/ai/src/ai/ai_team.cc
r10135 r10137 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 16 14 */ 17 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 18 19 16 #include "ai_team.h" 20 21 AITeam::AITeam(){ 22 for(int i=0; i < maxSwarms; i++ )swarms[i]=NULL; 23 } 24 25 26 AISwarm* AITeam::getSwarm(int swarmNumber) 27 { 28 if(swarmNumber>maxSwarms || swarmNumber<0)return NULL; 29 return swarms[swarmNumber]; 30 } 31 32 33 AISwarm* AITeam::getCreateSwarm(int swarmNumber) 34 { 35 if(swarmNumber>maxSwarms || swarmNumber<0)return NULL; 36 if(swarms[swarmNumber]==NULL)swarms[swarmNumber]=new AISwarm(); 37 return swarms[swarmNumber]; 38 } 39 40 41 void AITeam::addSwarm(int swarmNumber) 42 { 43 if(swarmNumber>maxSwarms || swarmNumber<0)return; 44 swarms[swarmNumber]=new AISwarm(); 45 } 46 47 48 void AITeam::removeSwarm(int swarmNumber) 49 { 50 if(swarmNumber>maxSwarms || swarmNumber<0)return; 51 swarms[swarmNumber]=NULL; 52 } 53 17 #include "debug.h" 54 18 55 19 void AITeam::process(float dt) 56 20 { 57 for(int i=0; i < maxSwarms; i++ ){ 58 if(swarms[i]!=NULL)swarms[i]->process(dt); 21 std::map<int,AISwarm*>::iterator it; 22 for (it= swarms.begin(); it!= swarms.end(); it++ ) 23 it->second->process(dt); 24 } 25 26 void AITeam::addAI(int swarmNumber, AIModule* aiModule) 27 { 28 std::pair<std::map<int,AISwarm*>::iterator,bool> p; 29 AISwarm* newSwarm=new AISwarm(); 30 p=swarms.insert(std::make_pair(swarmNumber,newSwarm)); 31 if(!p.second)delete newSwarm; 32 p.first->second->addAI(aiModule); 33 } 34 35 void AITeam::removeAI(int swarmNumber, AIModule* aiModule) 36 { 37 std::map<int,AISwarm*>::iterator it = swarms.find(swarmNumber); 38 if(it==swarms.end())return; 39 it->second->removeAI(aiModule); 40 if(it->second->getSwarmSize()==0){ 41 delete it->second; 42 swarms.erase(it); 59 43 } 60 44 } 61 45 62 46 int AITeam::getTeamSize() 47 { 48 return swarms.size(); 49 } -
branches/ai/src/ai/ai_team.h
r10135 r10137 7 7 class AITeam{ 8 8 public: 9 ~AITeam(){} ;10 AITeam(); 9 ~AITeam(){} 10 AITeam(){} 11 11 void process(float dt); 12 13 void addSwarm(int swarmNumber); 14 void removeSwarm(int swarmNumber); 15 AISwarm* getSwarm(int swarmNumber); 16 AISwarm* getCreateSwarm(int swarmNumber); 17 12 void addAI(int swarmNumber, AIModule* aiModule); 13 void removeAI(int swarmNumber, AIModule* aiModule); 14 int getTeamSize(); 15 18 16 private: 19 AISwarm* swarms[32]; 20 static const int maxSwarms=32; 17 std::map<int,AISwarm*> swarms; 21 18 }; 22 19
Note: See TracChangeset
for help on using the changeset viewer.