Changeset 10138 in orxonox.OLD for branches/ai/src
- Timestamp:
- Dec 21, 2006, 10:14:15 PM (18 years ago)
- Location:
- branches/ai/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_engine.cc
r10137 r10138 16 16 #include "ai_engine.h" 17 17 #include "debug.h" 18 #include "npcs/npc_test.h" 19 #include "player.h" 20 #include "playable.h" 21 #include "state.h" 18 22 19 23 AIEngine* AIEngine::singletonRef = NULL; … … 22 26 { 23 27 std::map<int,AITeam*>::iterator it; 24 for (it= teams.begin(); it!= teams.end(); it++ ) 28 std::vector<WorldEntity*>* enemyList=new std::vector<WorldEntity*>; 29 30 for (it=teams.begin(); it!= teams.end(); it++ ) 31 { 32 //find enemys for the team 33 for(ObjectList<NPC2>::const_iterator npc = NPC2::objectList().begin(); npc != NPC2::objectList().end(); ++npc) 34 if((*npc)->getTeam() != it->first)enemyList->push_back(*npc); 35 36 //add player to enemys (player belongs to team 0) 37 if(it->first!=0){ 38 //std::cout << "adding player to enemyList\n"; 39 Player* pl = State::getPlayer(); 40 if(pl != NULL)enemyList->push_back(pl->getPlayable()); 41 } 42 43 //process the team 44 it->second->setEnemyList(enemyList); 25 45 it->second->process(dt); 46 enemyList->clear(); 47 } 48 49 delete enemyList; 26 50 } 27 51 -
branches/ai/src/ai/ai_module.cc
r10061 r10138 16 16 */ 17 17 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 18 19 18 #include "ai_module.h" 20 //#include "ai_engine.h" 21 //#include "debug.h" 22 23 24 25 AIModule::AIModule() 26 { 27 } 28 29 30 void AIModule::setDifficulty(int newDifficulty) 31 { 32 difficulty=newDifficulty; 33 } 34 35 36 37 void AIModule::setOwner(AITeamMember* newOwner) 38 { 39 owner=newOwner; 40 } 41 19 #include "debug.h" -
branches/ai/src/ai/ai_module.h
r10135 r10138 2 2 #ifndef _AI_MODULE_H 3 3 #define _AI_MODULE_H 4 5 4 #include "world_entity.h" 6 5 class NPC2; 7 class AITeamMember;8 class WorldEntity;9 10 6 11 7 class AIModule { 12 8 public: 13 AIModule(); 14 virtual ~AIModule() {} 15 16 virtual void process() {} 17 virtual void process(float dt) {} 18 9 AIModule(){} 10 virtual ~AIModule(){} 11 virtual void process(float dt){} 12 19 13 void setDifficulty(int newDifficulty); 20 void setOwner(AITeamMember* newOwner); 21 22 14 inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;} 15 inline Vector getPosition(){return myWorldEntity->getAbsCoor();} 16 inline void setDestination(Vector destination){this->destination=destination;} 17 23 18 protected: 24 int difficulty;25 int myTeam;26 int mySwarm;27 28 AITeamMember* owner;29 19 NPC2* myNPC; 30 WorldEntity* myWorldEnity; 20 WorldEntity* myWorldEntity; 21 std::vector<WorldEntity*>* enemyList; 22 Vector destination; 31 23 }; 32 24 -
branches/ai/src/ai/ai_swarm.cc
r10137 r10138 20 20 { 21 21 std::set<AIModule*>::iterator it; 22 for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ) 22 it= swarmMembers.begin(); 23 Vector leaderPosition=(*it)->getPosition(); 24 (*it)->setDestination(destination); 25 (*it)->setEnemyList(enemyList); 26 (*it)->process(dt); 27 28 for (it++; it!= swarmMembers.end(); it++ ){ 29 (*it)->setDestination(leaderPosition); 30 (*it)->setEnemyList(enemyList); 23 31 (*it)->process(dt); 32 } 24 33 } 25 34 … … 36 45 } 37 46 38 int AISwarm::getSwarmSize()47 Vector AISwarm::getPosition() 39 48 { 40 return swarmMembers.size(); 49 Vector center=Vector(0,0,0); 50 std::set<AIModule*>::iterator it; 51 for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ) 52 center=center+(*it)->getPosition(); 53 54 return center/swarmMembers.size(); 41 55 } -
branches/ai/src/ai/ai_swarm.h
r10137 r10138 3 3 #define _AI_SWARM_H 4 4 5 //class AITeamMember; 6 #include "ai_team_member.h" 7 class NPC2; 5 #include "world_entity.h" 6 #include "ai_module.h" 8 7 9 8 class AISwarm{ … … 14 13 void addAI(AIModule* newMember); 15 14 void removeAI(AIModule* oldMember); 16 int getSwarmSize(); 15 inline int getSwarmSize(){return swarmMembers.size();} 16 inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;} 17 inline void setDestination(Vector destination){this->destination=destination;} 18 Vector getPosition(); 17 19 private: 20 Vector destination; 21 std::vector<WorldEntity*>* enemyList; 18 22 std::set<AIModule*> swarmMembers; 19 23 }; -
branches/ai/src/ai/ai_team.cc
r10137 r10138 20 20 { 21 21 std::map<int,AISwarm*>::iterator it; 22 for (it= swarms.begin(); it!= swarms.end(); it++ ) 22 for (it= swarms.begin(); it!= swarms.end(); it++ ){ 23 it->second->setEnemyList(enemyList); 24 if(enemyList->size()>0) 25 it->second->setDestination(enemyList->at(0)->getAbsCoor()); 23 26 it->second->process(dt); 27 } 24 28 } 25 29 … … 43 47 } 44 48 } 45 46 int AITeam::getTeamSize()47 {48 return swarms.size();49 } -
branches/ai/src/ai/ai_team.h
r10137 r10138 9 9 ~AITeam(){} 10 10 AITeam(){} 11 std::vector<WorldEntity*>* getEnemyList(); 11 12 void process(float dt); 12 13 void addAI(int swarmNumber, AIModule* aiModule); 13 14 void removeAI(int swarmNumber, AIModule* aiModule); 14 in t getTeamSize();15 15 inline int getTeamSize(){ return swarms.size(); } 16 inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;} 16 17 private: 18 std::vector<WorldEntity*>* enemyList; 17 19 std::map<int,AISwarm*> swarms; 18 20 }; -
branches/ai/src/ai/movement_module.cc
r10135 r10138 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 // 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 44 // std::vector<Vector> MovementModule::hidingPoint; 45 45 // std::vector<float> MovementModule::hidingPointSize; … … 62 62 // 63 63 // 64 MovementModule::MovementModule(NPC2* object){ this->myNPC=object; }65 MovementModule::~MovementModule(){}66 67 64 68 65 … … 156 153 Player* pl = State::getPlayer(); 157 154 if( pl == NULL)return; 158 159 155 Vector playerPosition = pl->getPlayable()->getAbsCoor(); 160 156 float playerRadius=getRadius( pl->getPlayable() ); 161 162 163 // collectInformation(dt); 164 157 158 159 //get information about myself 165 160 Vector myPosition = myNPC->getAbsCoor(); 166 161 float myRadius = getRadius(myNPC); … … 171 166 Vector tmpVector; 172 167 float tmpFloat; 173 174 // Vector npcCollision; 175 // Vector swarmVector; 168 169 Vector npcCollision; 176 170 Vector playerCollision; 177 171 … … 180 174 //float a=200.0f; 181 175 float vMax=200.0f; 182 float maxAccleration=300.0f;176 //float maxAccleration=300.0f; 183 177 //float safetyDistance=2.0f; 184 178 185 179 186 180 //Anti Player Collision 187 tmpFloat=vectorToPlayer.len()-playerRadius-myRadius- 30;//distanceToPlayer;181 tmpFloat=vectorToPlayer.len()-playerRadius-myRadius-distanceToPlayer; 188 182 if(tmpFloat<0.1)tmpFloat=0.1; 189 183 playerCollision=vectorToPlayer/(tmpFloat*tmpFloat)*(-1); 190 184 191 185 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; 186 //Anti NPC Collision 187 for(ObjectList<WorldEntity>::const_iterator it = WorldEntity::objectList().begin(); it != WorldEntity::objectList().end(); ++it) 188 { 189 if(*it==myNPC)continue; 190 191 tmpVector=myPosition-(*it)->getAbsCoor(); 192 tmpFloat=tmpVector.len()-myRadius-distanceToNPC-getRadius(*it); 193 194 if(tmpFloat<0.1)tmpFloat=0.1; 195 tmpVector=tmpVector/(tmpFloat*tmpFloat); 196 197 npcCollision=npcCollision+tmpVector; 198 } 199 200 201 202 Vector vectorToDestination=destination-myPosition; 203 204 Vector correction=playerCollision*50+npcCollision*50+vectorToDestination+Vector(0,0,0)-myMovement; 219 205 220 206 correction.y=0; … … 234 220 // view = v.cross( Vector(0,1,0) ).getNormalized(); 235 221 //}else{ 236 view = myMovement.cross( Vector(0, -1,0) ).getNormalized();222 view = myMovement.cross( Vector(0,1,0) ).getNormalized(); 237 223 //} 238 224 //if(dist<keepDist)view=view*-1; -
branches/ai/src/ai/movement_module.h
r10135 r10138 14 14 public: 15 15 MovementModule() {} 16 MovementModule(NPC2* object);17 virtual ~MovementModule() ;16 inline MovementModule(NPC2* object){ this->myNPC=object; this->myWorldEntity=(WorldEntity*)object;} 17 virtual ~MovementModule(){} 18 18 virtual void process(float dt); 19 19 20 //static void setDistanceToPlayer(float newValue);21 //static void setDistanceToNPC(float newValue);22 //static void setMaxAccleartion(float newValue);20 static void setDistanceToPlayer(float newValue); 21 static void setDistanceToNPC(float newValue); 22 static void setMaxAccleartion(float newValue); 23 23 // 24 24 private: 25 // void collectInformation(float dt); 26 // 27 // 28 // static std::vector<Vector> hidingPoint; 29 // static std::vector<float> hidingPointSize; 30 // 25 31 26 // static std::vector<NPC2*> npcList; 32 27 // static std::vector<Vector> npcPosition; … … 38 33 // static Vector playerMovement; 39 34 // static float playerRadius; 40 // 41 // static std::vector<Vector> swarmCenter; 42 // static std::vector<int> swarmMemberCount; 35 43 36 44 37 Vector myMovement; … … 46 39 float myMaxSpeed; 47 40 41 float getRadius(WorldEntity* object); 48 42 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; 43 static float maxAccleration; 44 static float distanceToPlayer; 45 static float distanceToNPC; 56 46 }; 57 47 -
branches/ai/src/world_entities/npcs/npc.h
r10041 r10138 4 4 5 5 #include "world_entity.h" 6 #include "ai_team_member.h"7 6 8 7 class AI; 9 8 10 class NPC : public AITeamMember{9 class NPC : public WorldEntity { 11 10 ObjectListDeclaration(NPC); 12 11 public: -
branches/ai/src/world_entities/npcs/npc_test.cc
r10135 r10138 51 51 std::cout << "Team Number: " << teamNumber << "\n"; 52 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 53 aiModule=new MovementModule(this); 54 AIEngine::getInstance()->addAI(teamNumber,swarmNumber,aiModule); 60 55 } 61 56 62 57 NPC2::~NPC2() 58 { 59 AIEngine::getInstance()->removeAI(teamNumber,swarmNumber,aiModule); 60 } 63 61 64 62 void NPC2::loadParams(const TiXmlElement* root) -
branches/ai/src/world_entities/npcs/npc_test.h
r10135 r10138 15 15 public: 16 16 NPC2 (const TiXmlElement* root); 17 virtual ~NPC2 () {};17 virtual ~NPC2 (); 18 18 virtual void loadParams(const TiXmlElement* root); 19 19 virtual void tick(float dt); 20 inline int getTeam(){return teamNumber;} 20 21 21 22 -
branches/ai/src/world_entities/space_ships/spacecraft_2d.cc
r9947 r10138 151 151 this->travelNode = new PNode(); 152 152 153 this->loadModel("models/ships/mantawing.obj", 5.0f);153 this->loadModel("models/ships/mantawing.obj", 2.5f); 154 154 155 155 // camera - issue
Note: See TracChangeset
for help on using the changeset viewer.