Changeset 10244 in orxonox.OLD for branches/ai
- Timestamp:
- Jan 17, 2007, 12:43:30 AM (18 years ago)
- Location:
- branches/ai/src/ai
- Files:
-
- 6 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/Makefile.am
r10226 r10244 8 8 ai_module.cc \ 9 9 ai_team.cc \ 10 ai_swarm.cc \11 10 ai_team_member.cc \ 12 11 movement_module.cc \ 13 12 shooting_module.cc \ 14 attack_module.cc 13 attack_module.cc\ 14 swarm_module.cc\ 15 swarm_wait.cc\ 16 swarm_gorel.cc 15 17 16 18 noinst_HEADERS = \ … … 18 20 ai_module.h \ 19 21 ai_team.h \ 20 ai_swarm.h \21 22 ai_team_member.h \ 22 23 movement_module.h \ 23 24 shooting_module.h \ 24 attack_module.h 25 attack_module.h\ 26 swarm_module.h\ 27 swarm_wait.h\ 28 swarm_gorel.h -
branches/ai/src/ai/ai_engine.cc
r10226 r10244 30 30 for (it=teams.begin(); it!= teams.end(); it++ ) 31 31 { 32 //find enemys for the team33 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 32 //add player to enemys (player belongs to team 0) 37 33 if(it->first!=0){ 38 //std::cout << "adding player to enemyList\n";39 34 Player* pl = State::getPlayer(); 40 35 if(pl != NULL)enemyList->push_back(pl->getPlayable()); 41 36 } 37 38 //find other enemys for this team 39 for(ObjectList<NPC2>::const_iterator npc = NPC2::objectList().begin(); npc != NPC2::objectList().end(); ++npc) 40 if((*npc)->getTeam() != it->first)enemyList->push_back(*npc); 42 41 43 42 //process the team -
branches/ai/src/ai/ai_module.h
r10226 r10244 7 7 class AIModule { 8 8 public: 9 AIModule(){}9 inline AIModule(){taskComplete=false;} 10 10 virtual ~AIModule(){} 11 11 virtual void process(float dt){} … … 25 25 inline float getMaxAcceleration(){return accelerationMax;} 26 26 inline float getMaxSpeed(){return speedMax;} 27 inline float getNPCRadius(){return getRadius(npc);} 28 29 inline bool done(){return taskComplete;} 27 30 28 31 void getAttributesFrom(AIModule* oldModule); … … 35 38 Vector destinationView; 36 39 37 40 bool taskComplete; 38 41 Vector movement; 39 42 Vector view; -
branches/ai/src/ai/ai_swarm.cc
r10226 r10244 14 14 */ 15 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 16 #include " ai_swarm.h"16 #include "swarm_gorel.h" 17 17 #include "ai_module.h" 18 18 #include "movement_module.h" … … 33 33 std::map<WorldEntity*,AIModule*>::iterator it; 34 34 35 if(enemys==NULL || enemys->size()<1)return; 36 target=enemys->at(0); 37 35 38 Vector swarmPosition=this->getPosition(); 36 39 Vector targetPosition=target->getAbsCoor(); … … 78 81 79 82 80 83 destination=taskRelObject->getAbsCoor()+taskRelPos; 81 84 Vector correction=(destination+randomVector-swarmPosition)-movement; 82 85 correction.y=0; … … 100 103 } 101 104 } 102 103 104 105 void AISwarm::addAI(WorldEntity* npc)106 {107 std::pair< std::map<WorldEntity*,AIModule*>::iterator , bool > p;108 AIModule* newAIModule=new MovementModule(npc);109 p=members.insert(std::make_pair(npc,newAIModule));110 if(!p.second)delete newAIModule;111 }112 113 114 void AISwarm::removeAI(WorldEntity* npc)115 {116 std::map<WorldEntity*,AIModule*>::iterator it = members.find(npc);117 if(it==members.end())return; //npc not found118 delete it->second; //delete AIModule119 members.erase(it); //remove AIModule from members120 }121 122 123 Vector AISwarm::getPosition()124 {125 Vector center=Vector(0,0,0);126 std::map<WorldEntity*,AIModule*>::iterator it;127 for (it= members.begin(); it!= members.end(); it++ )128 center=center+it->second->getPosition();129 130 return center/members.size();131 }132 133 float AISwarm::getRadius(WorldEntity* object)134 {135 AABB* aabb = object->getModelAABB();136 if( aabb == NULL)return -1;137 138 float a = aabb->halfLength[0];139 float b = aabb->halfLength[1];140 float c = aabb->halfLength[2];141 142 if(a>b){143 return (c>a)?c:a;144 }else{145 return (c>b)?c:b;146 }147 } -
branches/ai/src/ai/ai_swarm.h
r10226 r10244 5 5 #include "world_entity.h" 6 6 #include "ai_module.h" 7 #include "swarm_module.h" 7 8 8 9 9 10 class AISwarm{ 10 class AISwarm : public SwarmModule{ 11 11 public: 12 12 AISwarm(); 13 ~AISwarm(){} 14 void process(float dt); 15 void addAI(WorldEntity*); 16 void removeAI(WorldEntity*); 13 virtual ~AISwarm(){} 14 virtual void process(float dt); 17 15 18 inline int getSwarmSize(){return members.size();}19 16 inline void setDestination(Vector destination){this->destination=destination;} 20 17 inline void setTarget(WorldEntity* target){this->target=target;} 21 Vector getPosition();22 18 23 19 enum statusType{ATTACKING,MOVING,WAITING}; 24 20 25 21 private: 26 float getRadius(WorldEntity* object);27 28 29 22 Vector destination; 30 23 Vector movement; 31 24 WorldEntity* target; 32 25 statusType status; 33 34 std::map<WorldEntity*,AIModule*> members;35 26 36 27 int tickCount; -
branches/ai/src/ai/ai_team.cc
r10226 r10244 15 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI 16 16 #include "ai_team.h" 17 #include "swarm_gorel.h" 18 #include "swarm_module.h" 17 19 #include "debug.h" 18 20 19 21 void AITeam::process(float dt) 20 22 { 21 std::map<int, AISwarm*>::iterator it;23 std::map<int,SwarmModule*>::iterator it; 22 24 for (it= swarms.begin(); it!= swarms.end(); it++ ){ 23 if(enemyList->size()>0){ 24 it->second->setTarget(enemyList->at(0)); 25 it->second->setDestination(enemyList->at(0)->getAbsCoor()); 25 26 if(it->second->taskDone()){ 27 std::cout << "Task Done!\n"; 28 changeSwarmModule(it, new SwarmGoRel); 29 30 if(enemyList->size()>0){ 31 it->second->setEnemyList(enemyList); 32 it->second->orderRelObject(enemyList->at(0)); 33 it->second->orderRelPos(Vector(60,0,0)); 34 it->second->orderSpeed(50); 35 it->second->orderView(Vector(0,0,1)); 36 it->second->orderMaxTime(5); 37 } 26 38 } 27 39 it->second->process(dt); … … 29 41 } 30 42 43 void AITeam::changeSwarmModule(std::map<int,SwarmModule*>::iterator it,SwarmModule* newAI) 44 { 45 SwarmModule* oldAI = it->second; 46 newAI->getAttributesFrom(oldAI); 47 it->second=newAI; 48 delete oldAI; 49 } 50 31 51 32 52 void AITeam::addAI(int swarmNumber, WorldEntity* npc) 33 53 { 34 std::pair<std::map<int, AISwarm*>::iterator,bool> p;35 AISwarm* newSwarm=new AISwarm();54 std::pair<std::map<int,SwarmModule*>::iterator,bool> p; 55 SwarmModule* newSwarm=new SwarmGoRel(); 36 56 p=swarms.insert(std::make_pair(swarmNumber,newSwarm)); 37 57 if(!p.second)delete newSwarm; … … 42 62 void AITeam::removeAI(int swarmNumber, WorldEntity* npc) 43 63 { 44 std::map<int, AISwarm*>::iterator it = swarms.find(swarmNumber);64 std::map<int,SwarmModule*>::iterator it = swarms.find(swarmNumber); 45 65 if(it==swarms.end())return; 46 66 it->second->removeAI(npc); -
branches/ai/src/ai/ai_team.h
r10226 r10244 3 3 #define _AI_TEAM_H 4 4 5 #include " ai_swarm.h"5 #include "swarm_module.h" 6 6 7 7 class AITeam{ … … 17 17 private: 18 18 std::vector<WorldEntity*>* enemyList; 19 std::map<int,AISwarm*> swarms; 19 std::map<int,SwarmModule*> swarms; 20 void changeSwarmModule(std::map<int,SwarmModule*>::iterator it,SwarmModule* newAI); 20 21 }; 21 22 -
branches/ai/src/ai/attack_module.cc
r10227 r10244 45 45 { 46 46 tickCount=0; 47 randomFreq= 60;47 randomFreq=40; 48 48 } 49 49 … … 100 100 //random movement 101 101 //randomFreq=testValue2; 102 if(++tickCount>=randomFreq && movement.len()<60){102 if(++tickCount>=randomFreq){ 103 103 tickCount=0; 104 104 int x = (rand()%101)-50; //-50-50 -
branches/ai/src/ai/movement_module.cc
r10226 r10244 32 32 float MovementModule::distanceToPlayer=15; 33 33 float MovementModule::distanceToNPC=2; 34 float MovementModule::maxAccleration= 300.0f;34 float MovementModule::maxAccleration=250.0f; 35 35 float MovementModule::testValue=2; 36 36 float MovementModule::testValue2=40;
Note: See TracChangeset
for help on using the changeset viewer.