- Timestamp:
- Dec 20, 2006, 7:47:45 PM (18 years ago)
- Location:
- branches/ai/src
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/Makefile.am
r10045 r10135 8 8 ai_module.cc \ 9 9 ai_team.cc \ 10 ai_swarm.cc \ 10 11 ai_team_member.cc \ 11 12 movement_module.cc \ … … 16 17 ai_module.h \ 17 18 ai_team.h \ 19 ai_swarm.h \ 18 20 ai_team_member.h \ 19 21 movement_module.h \ -
branches/ai/src/ai/ai_engine.cc
r10045 r10135 22 22 AIEngine* AIEngine::singletonRef = NULL; 23 23 24 AIEngine::AIEngine(){ 25 for(int i=0; i < maxTeams; i++ )teams[i]=NULL; 26 } 24 27 25 AIEngine::AIEngine() 26 {} 28 AITeam* AIEngine::getTeam(int teamNumber) 29 { 30 if(teamNumber>maxTeams || teamNumber<0)return NULL; 31 return teams[teamNumber]; 32 } 27 33 28 AIEngine::~AIEngine() 29 {} 30 31 32 33 /*AITeam* AIEngine::newTeam() 34 AITeam* AIEngine::getCreateTeam(int teamNumber) 34 35 { 35 AITeam* newTeam=new AITeam; 36 teams.push_back(newTeam); 37 return newTeam; 38 }*/ 39 int AIEngine::newTeam() 40 { 41 AITeam* newTeam=new AITeam; 42 teams.push_back(newTeam); 43 return teams.size()-1; 36 if(teamNumber>maxTeams || teamNumber<0)return NULL; 37 if(teams[teamNumber]==NULL)teams[teamNumber]=new AITeam(); 38 return teams[teamNumber]; 44 39 } 45 40 46 41 47 48 AITeam* AIEngine::getTeam(int aiTeamNumber) 42 void AIEngine::addTeam(int teamNumber) 49 43 { 50 //if(teams.size()>aiTeamNumber) 51 return teams.at(aiTeamNumber); 52 //return NULL; 44 if(teamNumber>maxTeams || teamNumber<0)return; 45 teams[teamNumber]=new AITeam(); 53 46 } 54 47 55 48 49 void AIEngine::removeTeam(int teamNumber) 50 { 51 if(teamNumber>maxTeams || teamNumber<0)return; 52 teams[teamNumber]=NULL; 53 } 56 54 57 void AIEngine::tick(float dtS) 55 56 void AIEngine::tick(float dt) 58 57 { 59 this->dtS=dtS; 60 int teamCount=teams.size(); 61 for(int i=0; i < teamCount; i++ ) 62 { 63 //std::cout << "hello"; 64 //std::cout << "DT " << dtS << "...\n"; 65 teams.at(i)->process(); 66 } 58 for(int i=0; i < maxTeams; i++ ) 59 if(teams[i]!=NULL)teams[i]->process(dt); 67 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
r10045 r10135 9 9 class AIEngine{ 10 10 public: 11 ~AIEngine(); 11 ~AIEngine(){} 12 12 13 13 static AIEngine* getInstance() { if( singletonRef == NULL) singletonRef = new AIEngine(); return singletonRef; } 14 14 15 void tick(float dtS); 16 AITeam* getTeam(int); 17 int newTeam(); 18 float dtS; 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 19 22 private: 23 void rebuildAIVector(); 24 25 std::vector<AIModule*> AIVector; 26 27 static const int maxTeams=32; 28 AITeam* teams[32]; 20 29 AIEngine(); 21 30 22 private: 23 std::vector<AITeam*> teams; 24 25 static AIEngine* singletonRef; 26 31 static AIEngine* singletonRef; 27 32 }; 28 33 -
branches/ai/src/ai/ai_module.h
r10112 r10135 9 9 10 10 11 class AIModule {11 class AIModule { 12 12 public: 13 13 AIModule(); 14 14 virtual ~AIModule() {} 15 15 16 virtual void process() {} 16 17 virtual void process(float dt) {} 18 17 19 void setDifficulty(int newDifficulty); 18 20 void setOwner(AITeamMember* newOwner); 21 22 19 23 protected: 20 24 int difficulty; 25 int myTeam; 26 int mySwarm; 27 21 28 AITeamMember* owner; 22 29 NPC2* myNPC; 30 WorldEntity* myWorldEnity; 23 31 }; 24 32 -
branches/ai/src/ai/ai_team.cc
r10045 r10135 19 19 #include "ai_team.h" 20 20 21 AITeam::AITeam() 22 {} 21 AITeam::AITeam(){ 22 for(int i=0; i < maxSwarms; i++ )swarms[i]=NULL; 23 } 23 24 24 AITeam::~AITeam()25 {}26 25 27 void AITeam::process()26 AISwarm* AITeam::getSwarm(int swarmNumber) 28 27 { 29 int teamSize=teamMembers.size(); 30 for(int i=0; i < teamSize; i++ ) 31 { 32 //std::cout << "Processing TeamMember " << i << "...\n"; 33 teamMembers.at(i)->process(); 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 54 55 void AITeam::process(float dt) 56 { 57 for(int i=0; i < maxSwarms; i++ ){ 58 if(swarms[i]!=NULL)swarms[i]->process(dt); 34 59 } 35 60 } 36 61 37 62 38 void AITeam::addMember(AITeamMember* newMember)39 {40 teamMembers.push_back(newMember);41 }42 43 44 AITeamMember* AITeam::getTeamMember(int teamMemberID)45 {46 return teamMembers.at(teamMemberID);47 } -
branches/ai/src/ai/ai_team.h
r10041 r10135 3 3 #define _AI_TEAM_H 4 4 5 //class AITeamMember; 6 #include "ai_team_member.h" 5 #include "ai_swarm.h" 7 6 8 7 class AITeam{ 9 8 public: 10 AITeam(); 11 ~AITeam(); 12 void process(); 13 void addMember(AITeamMember*); 14 AITeamMember* getTeamMember(int); 9 ~AITeam(){}; 10 AITeam(); 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 15 18 private: 16 std::vector<AITeamMember*> teamMembers; 19 AISwarm* swarms[32]; 20 static const int maxSwarms=32; 17 21 }; 18 22 -
branches/ai/src/ai/ai_team_member.cc
r10071 r10135 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 17 #include "ai_team_member.h" 18 #include "movement_module.h" 19 #include "ai_engine.h" 20 #include "debug.h" 21 22 23 AITeamMember::AITeamMember() 24 {} 25 26 AITeamMember::~AITeamMember() 27 {} 28 29 30 31 void AITeamMember::process() 32 { 33 int moduleCount=modules.size(); 34 for(int i=0; i < moduleCount; i++ ) 35 { 36 //std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n"; 37 modules.at(i)->process(); 38 } 39 } 40 41 42 43 44 void AITeamMember::addToTeam(int aiTeamNumber) 45 { 46 //macht nicht so ganz das was es eigntlich machen sollte.. 47 AIEngine* aiEngine=AIEngine::getInstance(); 48 int teamNumber=aiEngine->newTeam(); 49 aiEngine->getTeam(teamNumber)->addMember(this); 50 51 MovementModule* nMod=new MovementModule; 52 addModule(nMod); 53 //nMod->testModule=nMod; 54 } 55 56 57 58 59 void AITeamMember::addModule(AIModule* newModule) 60 { 61 std::cout << "AIModule added\n"; 62 modules.push_back(newModule); 63 newModule->setOwner(this); 64 } 16 // #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 17 // #include "ai_team_member.h" 18 // #include "movement_module.h" 19 // #include "ai_engine.h" 20 // #include "debug.h" 21 // 22 // 23 // 24 // void AITeamMember::process() 25 // { 26 // int moduleCount=modules.size(); 27 // for(int i=0; i < moduleCount; i++ ) 28 // { 29 // //std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n"; 30 // modules.at(i)->process(); 31 // } 32 // } 33 // 34 // 35 // 36 // 37 // void AITeamMember::addToTeam(int aiTeamNumber) 38 // { 39 // //macht nicht so ganz das was es eigntlich machen sollte.. 40 // AIEngine* aiEngine=AIEngine::getInstance(); 41 // int teamNumber=aiEngine->newTeam(); 42 // aiEngine->getTeam(teamNumber)->addMember(this); 43 // 44 // MovementModule* nMod=new MovementModule; 45 // addModule(nMod); 46 // //nMod->testModule=nMod; 47 // } 48 // 49 // 50 // 51 // 52 // void AITeamMember::addModule(AIModule* newModule) 53 // { 54 // std::cout << "AIModule added\n"; 55 // modules.push_back(newModule); 56 // newModule->setOwner(this); 57 // } -
branches/ai/src/ai/ai_team_member.h
r10045 r10135 8 8 //class AIModule; 9 9 10 class AITeamMember : public WorldEntity{ 11 public: 12 AITeamMember(); 13 ~AITeamMember(); 14 15 void process(); 16 void addToTeam(int); 17 void addModule(AIModule*); 18 private: 19 std::vector<AIModule*> modules; 10 class AITeamMember : public WorldEntity { 11 // public: 12 // AITeamMember(){}; 13 // ~AITeamMember(){}; 14 // 15 // void process(); 16 // void addToTeam(int); 17 // void addModule(AIModule*); 18 // 19 // inline void setTeamNumber(int teamNumber){this->teamNumber=teamNumber;} 20 // inline int getTeamNumber(){return this->teamNumber;} 21 // inline void setSwarmNumber(int swarmNumber){this->swarmNumber=swarmNumber;} 22 // inline int getSwarmNumber(){return this->swarmNumber;} 23 // 24 // private: 25 // AIModule* aiModule; 26 // int teamNumber; 27 // int swarmNumber; 28 // int difficulty; 20 29 }; 21 30 -
branches/ai/src/ai/movement_module.cc
r10112 r10135 25 25 26 26 #include "shell_command.h" 27 SHELL_COMMAND(setDistanceToPlayer, MovementModule, setDistanceToPlayer);28 SHELL_COMMAND(setDistanceToNPC, MovementModule, setDistanceToNPC);29 SHELL_COMMAND(setMaxAccleartion, MovementModule, setMaxAccleartion);30 31 float MovementModule::distanceToPlayer=15;32 float MovementModule::distanceToNPC=2;33 float MovementModule::maxAccleration=200.0f;34 35 void MovementModule::setDistanceToPlayer(float newValue){ distanceToPlayer=newValue; }36 void MovementModule::setDistanceToNPC(float newValue){ distanceToNPC=newValue; }37 void MovementModule::setMaxAccleartion(float newValue){ maxAccleration=newValue; }38 39 40 41 42 43 44 std::vector<Vector> MovementModule::hidingPoint;45 std::vector<float> MovementModule::hidingPointSize;46 47 std::vector<NPC2*> MovementModule::npcList;48 std::vector<Vector> MovementModule::npcPosition;49 std::vector<float> MovementModule::npcRadius;50 std::vector<int> MovementModule::npcSwarm;51 std::vector<int> MovementModule::npcTeam;52 53 Vector MovementModule::playerPosition;54 Vector MovementModule::playerMovement;55 float MovementModule::playerRadius;56 57 std::vector<Vector> MovementModule::swarmCenter;58 std::vector<int> MovementModule::swarmMemberCount;59 60 61 62 63 27 // SHELL_COMMAND(setDistanceToPlayer, MovementModule, setDistanceToPlayer); 28 // SHELL_COMMAND(setDistanceToNPC, MovementModule, setDistanceToNPC); 29 // SHELL_COMMAND(setMaxAccleartion, MovementModule, setMaxAccleartion); 30 // 31 // float MovementModule::distanceToPlayer=15; 32 // float MovementModule::distanceToNPC=2; 33 // float MovementModule::maxAccleration=200.0f; 34 // 35 // void MovementModule::setDistanceToPlayer(float newValue){ distanceToPlayer=newValue; } 36 // void MovementModule::setDistanceToNPC(float newValue){ distanceToNPC=newValue; } 37 // void MovementModule::setMaxAccleartion(float newValue){ maxAccleration=newValue; } 38 // 39 // 40 // 41 // 42 // 43 // 44 // std::vector<Vector> MovementModule::hidingPoint; 45 // std::vector<float> MovementModule::hidingPointSize; 46 // 47 // std::vector<NPC2*> MovementModule::npcList; 48 // std::vector<Vector> MovementModule::npcPosition; 49 // std::vector<float> MovementModule::npcRadius; 50 // std::vector<int> MovementModule::npcSwarm; 51 // std::vector<int> MovementModule::npcTeam; 52 // 53 // Vector MovementModule::playerPosition; 54 // Vector MovementModule::playerMovement; 55 // float MovementModule::playerRadius; 56 // 57 // std::vector<Vector> MovementModule::swarmCenter; 58 // std::vector<int> MovementModule::swarmMemberCount; 59 // 60 // 61 // 62 // 63 // 64 64 MovementModule::MovementModule(NPC2* object){ this->myNPC=object; } 65 65 MovementModule::~MovementModule(){} … … 72 72 AABB* aabb = object->getModelAABB(); 73 73 if( aabb == NULL)return -1; 74 74 75 75 float a = aabb->halfLength[0]; 76 76 float b = aabb->halfLength[1]; … … 87 87 88 88 89 void MovementModule::collectInformation(float dt) 89 // void MovementModule::collectInformation(float dt) 90 // { 91 // //return if already processed.. 92 // if(dt==this->oldDT)return; 93 // this->oldDT=dt; 94 // 95 // 96 // //clear old Information.. 97 // hidingPoint.clear(); 98 // hidingPointSize.clear(); 99 // 100 // npcList.clear(); 101 // npcPosition.clear(); 102 // npcRadius.clear(); 103 // npcSwarm.clear(); 104 // npcTeam.clear(); 105 // 106 // swarmCenter.clear(); 107 // swarmMemberCount.clear(); 108 // 109 // 110 // //get all NPCs.. 111 // for(ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); it != NPC2::objectList().end(); ++it) 112 // { 113 // npcList.push_back(*it); 114 // npcRadius.push_back(getRadius(*it)); 115 // npcPosition.push_back((*it)->getAbsCoor()); 116 // npcSwarm.push_back((*it)->swarm); 117 // npcTeam.push_back((*it)->team); 118 // } 119 // 120 // 121 // //Swarm Information 122 // unsigned int tmpSwarm; 123 // for(unsigned int i=0;i<npcList.size();i++){ 124 // tmpSwarm = npcSwarm.at(i); 125 // if(tmpSwarm > swarmMemberCount.size()){ 126 // //swarmMemberCount.insert(swarmMemberCount.size(), tmpSwarm - swarmMemberCount.size(), 0); 127 // //swarmCenter.insert(swarmCenter.size(), tmpSwarm - swarmCenter.size(), Vector(0,0,0)); 128 // } 129 // //swarmMemberCount.at(tmpSwarm)++; 130 // //swarmCenter.at(tmpSwarm)=swarmCenter.at(tmpSwarm)+npcPosition.at(i); 131 // } 132 // for(unsigned int i=0;i<swarmCenter.size();i++){ 133 // //swarmCenter.at(i)=swarmCenter.at(i)/swarmMemberCount.at(i); 134 // } 135 // 136 // 137 // //get information about Player 138 // Player* pl = State::getPlayer(); 139 // if( pl != NULL){ 140 // playerPosition = pl->getPlayable()->getAbsCoor(); 141 // playerRadius=getRadius( pl->getPlayable() ); 142 // //PRINTF(0)("Player Radius: %f\n",playerRadius); 143 // } 144 // 145 // 146 // //calculate hiding Points.. 147 // 148 // } 149 150 151 void MovementModule::process(float dt) 90 152 { 91 //return if already processed.. 92 if(dt==this->oldDT)return; 93 this->oldDT=dt; 94 95 96 //clear old Information.. 97 hidingPoint.clear(); 98 hidingPointSize.clear(); 99 100 npcList.clear(); 101 npcPosition.clear(); 102 npcRadius.clear(); 103 npcSwarm.clear(); 104 npcTeam.clear(); 105 106 swarmCenter.clear(); 107 swarmMemberCount.clear(); 108 109 110 //get all NPCs.. 111 for(ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); it != NPC2::objectList().end(); ++it) 112 { 113 npcList.push_back(*it); 114 npcRadius.push_back(getRadius(*it)); 115 npcPosition.push_back((*it)->getAbsCoor()); 116 npcSwarm.push_back((*it)->swarm); 117 npcTeam.push_back((*it)->team); 118 } 119 120 121 //Swarm Information 122 unsigned int tmpSwarm; 123 for(unsigned int i=0;i<npcList.size();i++){ 124 tmpSwarm = npcSwarm.at(i); 125 if(tmpSwarm > swarmMemberCount.size()){ 126 //swarmMemberCount.insert(swarmMemberCount.size(), tmpSwarm - swarmMemberCount.size(), 0); 127 //swarmCenter.insert(swarmCenter.size(), tmpSwarm - swarmCenter.size(), Vector(0,0,0)); 128 } 129 //swarmMemberCount.at(tmpSwarm)++; 130 //swarmCenter.at(tmpSwarm)=swarmCenter.at(tmpSwarm)+npcPosition.at(i); 131 } 132 for(unsigned int i=0;i<swarmCenter.size();i++){ 133 //swarmCenter.at(i)=swarmCenter.at(i)/swarmMemberCount.at(i); 134 } 135 136 153 if(myNPC == NULL)return; 154 137 155 //get information about Player 138 156 Player* pl = State::getPlayer(); 139 if( pl != NULL){ 140 playerPosition = pl->getPlayable()->getAbsCoor(); 141 playerRadius=getRadius( pl->getPlayable() ); 142 //PRINTF(0)("Player Radius: %f\n",playerRadius); 143 } 144 145 146 //calculate hiding Points.. 147 148 } 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 void MovementModule::process() 164 { 165 this->process(AIEngine::getInstance()->dtS); 166 } 167 168 169 void MovementModule::process(float dt) 170 { 171 collectInformation(dt); 172 173 if(myNPC == NULL)return; 174 157 if( pl == NULL)return; 158 159 Vector playerPosition = pl->getPlayable()->getAbsCoor(); 160 float playerRadius=getRadius( pl->getPlayable() ); 161 162 163 // collectInformation(dt); 164 175 165 Vector myPosition = myNPC->getAbsCoor(); 176 166 float myRadius = getRadius(myNPC); 177 int mySwarm = myNPC->swarm; 178 int myTeam = myNPC->team; 179 167 168 180 169 Vector vectorToPlayer = playerPosition - myPosition; 181 170 182 171 Vector tmpVector; 183 172 float tmpFloat; 184 185 Vector npcCollision;186 Vector swarmVector;173 174 // Vector npcCollision; 175 // Vector swarmVector; 187 176 Vector playerCollision; 188 177 189 178 190 179 191 180 //float a=200.0f; 192 181 float vMax=200.0f; 182 float maxAccleration=300.0f; 193 183 //float safetyDistance=2.0f; 194 184 195 185 196 186 //Anti Player Collision 197 tmpFloat=vectorToPlayer.len()-playerRadius-myRadius- distanceToPlayer;187 tmpFloat=vectorToPlayer.len()-playerRadius-myRadius-30;//distanceToPlayer; 198 188 if(tmpFloat<0.1)tmpFloat=0.1; 199 189 playerCollision=vectorToPlayer/(tmpFloat*tmpFloat)*(-1); 200 201 202 203 for (unsigned int i=0;i<npcList.size();i++) 204 { 205 if(npcList.at(i)==myNPC)continue; 206 207 //Anti NPC Collision 208 tmpVector=myPosition-npcPosition.at(i); 209 tmpFloat=tmpVector.len()-myRadius-npcRadius.at(i)-distanceToNPC; 210 211 if(tmpFloat<0.1)tmpFloat=0.1; 212 tmpVector=tmpVector/(tmpFloat*tmpFloat); 213 214 npcCollision=npcCollision+tmpVector; 215 216 //Schwarmverhalten 217 if(npcSwarm.at(i) == mySwarm){ 218 219 220 } 221 } 222 223 224 225 226 227 Vector correction=playerCollision*50+npcCollision*50+vectorToPlayer-myMovement; 190 191 192 193 // for (unsigned int i=0;i<npcList.size();i++) 194 // { 195 // if(npcList.at(i)==myNPC)continue; 196 // 197 // //Anti NPC Collision 198 // tmpVector=myPosition-npcPosition.at(i); 199 // tmpFloat=tmpVector.len()-myRadius-npcRadius.at(i)-distanceToNPC; 200 // 201 // if(tmpFloat<0.1)tmpFloat=0.1; 202 // tmpVector=tmpVector/(tmpFloat*tmpFloat); 203 // 204 // npcCollision=npcCollision+tmpVector; 205 // 206 // //Schwarmverhalten 207 // if(npcSwarm.at(i) == mySwarm){ 208 // 209 // 210 // } 211 // } 212 213 214 215 216 217 //Vector correction=playerCollision*50+npcCollision*50+vectorToPlayer+Vector(70,0,0)-myMovement; 218 Vector correction=playerCollision*50+vectorToPlayer+Vector(50,0,0)-myMovement; 219 228 220 correction.y=0; 229 221 float correctionLen=correction.len(); -
branches/ai/src/ai/movement_module.h
r10112 r10135 11 11 12 12 class MovementModule : public AIModule{ 13 14 public:15 MovementModule() {}16 MovementModule(NPC2* object);17 virtual ~MovementModule();18 virtual void process();19 virtual void process(float dt);20 13 21 static void setDistanceToPlayer(float newValue); 22 static void setDistanceToNPC(float newValue); 23 static void setMaxAccleartion(float newValue); 24 25 private: 26 void collectInformation(float dt); 27 28 29 static std::vector<Vector> hidingPoint; 30 static std::vector<float> hidingPointSize; 31 32 static std::vector<NPC2*> npcList; 33 static std::vector<Vector> npcPosition; 34 static std::vector<float> npcRadius; 35 static std::vector<int> npcSwarm; 36 static std::vector<int> npcTeam; 37 38 static Vector playerPosition; 39 static Vector playerMovement; 40 static float playerRadius; 41 42 static std::vector<Vector> swarmCenter; 43 static std::vector<int> swarmMemberCount; 44 45 Vector myMovement; 46 float myMaxAccleration; 47 float myMaxSpeed; 48 49 50 float getRadius(WorldEntity* object); 51 static float aa; 52 float oldDT; 53 54 static float maxAccleration; 55 static float distanceToPlayer; 56 static float distanceToNPC; 14 public: 15 MovementModule() {} 16 MovementModule(NPC2* object); 17 virtual ~MovementModule(); 18 virtual void process(float dt); 19 20 // static void setDistanceToPlayer(float newValue); 21 // static void setDistanceToNPC(float newValue); 22 // static void setMaxAccleartion(float newValue); 23 // 24 private: 25 // void collectInformation(float dt); 26 // 27 // 28 // static std::vector<Vector> hidingPoint; 29 // static std::vector<float> hidingPointSize; 30 // 31 // static std::vector<NPC2*> npcList; 32 // static std::vector<Vector> npcPosition; 33 // static std::vector<float> npcRadius; 34 // static std::vector<int> npcSwarm; 35 // static std::vector<int> npcTeam; 36 // 37 // static Vector playerPosition; 38 // static Vector playerMovement; 39 // static float playerRadius; 40 // 41 // static std::vector<Vector> swarmCenter; 42 // static std::vector<int> swarmMemberCount; 43 44 Vector myMovement; 45 float myMaxAccleration; 46 float myMaxSpeed; 47 48 49 float getRadius(WorldEntity* object); 50 // static float aa; 51 // float oldDT; 52 // 53 // static float maxAccleration; 54 // static float distanceToPlayer; 55 // static float distanceToNPC; 57 56 }; 58 57 -
branches/ai/src/world_entities/npcs/npc_test.cc
r10112 r10135 19 19 20 20 #include "npc_test.h" 21 21 #include <stdio.h> 22 22 23 23 #include "state.h" … … 34 34 #include "movement_module.h" 35 35 #include "ai_module.h" 36 36 #include "ai_team.h" 37 #include "ai_swarm.h" 38 #include "ai_engine.h" 37 39 38 40 ObjectListDefinitionID(NPC2, CL_NPC_TEST2); … … 43 45 { 44 46 this->registerObject(this, NPC2::_objectList); 45 if (root != NULL)this->loadParams(root); 46 47 this->aiModule=new MovementModule(this); 47 48 if (root != NULL) 49 this->loadParams(root); 50 51 std::cout << "Team Number: " << teamNumber << "\n"; 52 std::cout << "Swarm Number:" << swarmNumber << "\n"; 53 54 AITeam* myTeam=AIEngine::getInstance()->getCreateTeam(teamNumber); 55 //std::cout << "Testpoint 4: " << myTeam << "\n"; 56 AISwarm* mySwarm=myTeam->getCreateSwarm(swarmNumber); 57 //std::cout << "Testpoint 5: " << mySwarm << "\n"; 58 mySwarm->addToSwarm(new MovementModule(this)); 59 48 60 } 49 61 50 51 NPC2::~NPC2 ()52 {}53 62 54 63 … … 56 65 { 57 66 NPC::loadParams(root); 67 68 LoadParam(root, "team", this, NPC2, setTeamNumber) 69 .describe("this sets the team number") 70 .defaultValues(0); 71 72 LoadParam(root, "swarm", this, NPC2, setSwarmNumber) 73 .describe("this sets the swarm number") 74 .defaultValues(0); 58 75 } 59 76 … … 65 82 if( likely(this->getModel(0) != NULL) && this->getModel(0)->isA(MD2Model::staticClassID())) 66 83 ((MD2Model*)this->getModel(0))->tick(dt); 67 68 // processing AI69 //PRINTF(0)("Processing NPC\n");70 if(this->aiModule!=NULL)this->aiModule->process(dt);71 84 } 72 85 -
branches/ai/src/world_entities/npcs/npc_test.h
r10112 r10135 11 11 12 12 class NPC2 : public NPC { 13 13 ObjectListDeclaration(NPC2); 14 14 15 16 17 virtual ~NPC2 ();18 19 15 public: 16 NPC2 (const TiXmlElement* root); 17 virtual ~NPC2 (){}; 18 virtual void loadParams(const TiXmlElement* root); 19 virtual void tick(float dt); 20 20 21 int team; 22 int swarm; 23 int difficulty; 24 AIModule* aiModule; 21 22 private: 23 inline void setTeamNumber(int number){teamNumber=number;} 24 inline void setSwarmNumber(int number){swarmNumber=number;} 25 26 int teamNumber; 27 int swarmNumber; 28 int difficulty; 29 30 AIModule* aiModule; 25 31 }; 26 32
Note: See TracChangeset
for help on using the changeset viewer.