Changeset 10266 in orxonox.OLD for branches/ai
- Timestamp:
- Jan 17, 2007, 4:53:23 PM (18 years ago)
- Location:
- branches/ai/src/ai
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/Makefile.am
r10244 r10266 14 14 swarm_module.cc\ 15 15 swarm_wait.cc\ 16 swarm_gorel.cc 16 swarm_gorel.cc\ 17 swarm_attack.cc 17 18 18 19 noinst_HEADERS = \ … … 26 27 swarm_module.h\ 27 28 swarm_wait.h\ 28 swarm_gorel.h 29 swarm_gorel.h\ 30 swarm_attack.h -
branches/ai/src/ai/ai_engine.cc
r10244 r10266 33 33 if(it->first!=0){ 34 34 Player* pl = State::getPlayer(); 35 if(pl != NULL)enemyList->push_back(pl->getPlayable()); 35 if( pl!=NULL && pl->getPlayable()!=NULL ) 36 enemyList->push_back(pl->getPlayable()); 36 37 } 37 38 38 39 //find other enemys for this team 39 40 for(ObjectList<NPC2>::const_iterator npc = NPC2::objectList().begin(); npc != NPC2::objectList().end(); ++npc) … … 60 61 void AIEngine::removeAI(int teamNumber, int swarmNumber, WorldEntity* npc) 61 62 { 62 std::map<int,AITeam*>::iterator it = teams.find( swarmNumber);63 std::map<int,AITeam*>::iterator it = teams.find(teamNumber); 63 64 if(it==teams.end())return; 64 65 it->second->removeAI(swarmNumber,npc); -
branches/ai/src/ai/ai_team.cc
r10249 r10266 18 18 #include "swarm_module.h" 19 19 #include "swarm_wait.h" 20 #include "swarm_attack.h" 20 21 #include "debug.h" 21 22 #include "player.h" … … 27 28 std::map<int,SwarmModule*>::iterator it; 28 29 for (it= swarms.begin(); it!= swarms.end(); it++ ){ 29 30 30 31 if(it->second->taskDone()){ 31 32 std::cout << "Swarm Task Complete!\n"; 32 33 33 34 if(enemyList->size()==0){ 34 35 changeSwarmModule(it, new SwarmWait); … … 37 38 continue; 38 39 } 39 40 40 41 Vector position=it->second->getPosition(); 41 42 Vector newPosition; 42 43 WorldEntity* target=enemyList->at(0); 43 44 44 45 //check if enemy is the player.. 45 46 bool isPlayer=(State::getPlayer()->getPlayable()==target); 46 47 float speed; 47 48 float maxTime=10; 49 48 50 //find new Position 49 51 if(isPlayer){ 50 float x=(target->getAbsCoor()).x; 51 float z=(target->getAbsCoor()).z; 52 int zNorm=(position.z>z)?1:-1; 53 54 if(x+100 > position.x && x+20 < position.x){ 55 newPosition=Vector(0,0,zNorm*80); //just go away 52 Vector targetPos=target->getAbsCoor(); 53 int zNorm=(position.z>targetPos.z)?1:-1; 54 55 if((position.z-targetPos.z)*zNorm>80){ //go to start position 56 std::cout << "Go Start Position\n"; 57 changeSwarmModule(it, new SwarmGoRel); 58 newPosition=Vector(220,0,zNorm*60); 59 speed=100; 60 }else if(position.x > targetPos.x+150){ //go to attack position 61 std::cout << "Go Attack Position\n"; 62 changeSwarmModule(it, new SwarmGoRel); 63 newPosition=Vector(100,0,0); 64 speed=60; 65 }else if(position.x > targetPos.x+90){ //go to attack mode 66 std::cout << "Go Attack Mode\n"; 67 changeSwarmModule(it, new SwarmAttack); 68 newPosition=Vector(80,0,0); 56 69 speed=80; 57 }else if(x+100 < position.x){ 58 newPosition=Vector(80,0,zNorm*30); //attack 59 speed=70; 60 }else{ 61 zNorm=1-2*(rand()%2); //-1 or 1 62 newPosition=Vector(200,0,zNorm*80); //go to attack position 63 speed=100; 70 maxTime=(rand()%11);//0-10 Sekunden 71 }else{ //go to fallback point 72 std::cout << "Go Fallback Point\n"; 73 changeSwarmModule(it, new SwarmGoRel); 74 newPosition=Vector(0,0,zNorm*150); 75 speed=60; 64 76 } 65 77 }else{ 66 78 67 79 } 68 80 69 changeSwarmModule(it, new SwarmGoRel); 70 81 82 71 83 if(enemyList->size()>0){ 72 84 it->second->setEnemyList(enemyList); … … 75 87 it->second->orderSpeed(speed); 76 88 //it->second->orderView(Vector(0,0,1)); 77 it->second->orderMaxTime( (rand()%6)+5); //5-1089 it->second->orderMaxTime(maxTime); //5-10 78 90 //it->second->newOrder(); 79 91 } -
branches/ai/src/ai/attack_module.cc
r10244 r10266 114 114 115 115 Vector correction= playerCollision*50*3 116 + npcCollision*50*3 116 + npcCollision*50*3 *6/myRadius 117 117 + destinationMovement*2//-movement 118 118 + (vectorToDestination-movement)*3 -
branches/ai/src/ai/movement_module.cc
r10244 r10266 64 64 Player* pl = State::getPlayer(); 65 65 if( pl == NULL)return; 66 WorldEntity* playable = pl->getPlayable(); 67 if( playable == NULL)return; 68 66 69 Vector playerPosition = pl->getPlayable()->getAbsCoor(); 67 70 float playerRadius=getRadius( pl->getPlayable() ); 68 69 71 70 72 //get information about myself … … 104 106 105 107 Vector correction= playerCollision*50*3 106 + npcCollision*50*3 108 + npcCollision*50*3 *6/myRadius 107 109 + Vector(0,0,0) 108 110 + destinationMovement*2//-movement -
branches/ai/src/ai/swarm_gorel.cc
r10249 r10266 21 21 { 22 22 std::map<WorldEntity*,AIModule*>::iterator it; 23 23 24 24 //calculate movement parameters.. 25 25 float averageRadius; … … 31 31 vMax=500/averageRadius; 32 32 viewChangeMax=90/averageRadius; 33 33 34 34 //load correct ai-module.. 35 35 for (it= members.begin(); it!= members.end(); it++ ){ 36 36 changeAIModule(it, new MovementModule()); 37 37 } 38 38 39 39 //get swarm position.. 40 40 //position=this->getPosition(); … … 48 48 Vector correction=Vector(0,0,0); 49 49 Vector destination; 50 50 51 51 if(taskRelObject!=NULL && taskMaxTime>0){ 52 52 destination=taskRelObject->getAbsCoor()+taskRelPos; … … 57 57 taskComplete=true; 58 58 } 59 59 60 60 float correctionLen=correction.len(); 61 61 if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt; … … 66 66 float movementLen=movement.len(); 67 67 if(movementLen>vMax)movement=movement/movementLen*vMax; 68 68 69 69 float newSpeed=movement.len(); 70 70 Vector newView=movement.getNormalized(); 71 71 72 72 if((newSpeed<=taskSpeed && speed>=taskSpeed)||(newSpeed>=taskSpeed && speed<=taskSpeed)){ 73 73 newSpeed=taskSpeed; … … 75 75 newSpeed=taskSpeed; 76 76 } 77 77 78 78 if(angleDeg(view,newView)>viewChangeMax){ 79 79 std::cout << "alarm\n"; … … 89 89 it->second->process(dt); 90 90 } 91 91 92 92 //check if destination reached 93 93 if(!taskComplete){ 94 94 //swarmPosition=this->getPosition(); 95 if((destination-position).len()< 10)taskComplete=true;95 if((destination-position).len()<5)taskComplete=true; 96 96 } 97 97 }
Note: See TracChangeset
for help on using the changeset viewer.