Changeset 10249 in orxonox.OLD for branches/ai
- Timestamp:
- Jan 17, 2007, 12:23:35 PM (18 years ago)
- Location:
- branches/ai/src/ai
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_team.cc
r10244 r10249 17 17 #include "swarm_gorel.h" 18 18 #include "swarm_module.h" 19 #include "swarm_wait.h" 19 20 #include "debug.h" 21 #include "player.h" 22 #include "playable.h" 23 #include "state.h" 20 24 21 25 void AITeam::process(float dt) … … 25 29 26 30 if(it->second->taskDone()){ 27 std::cout << "Task Done!\n"; 31 std::cout << "Swarm Task Complete!\n"; 32 33 if(enemyList->size()==0){ 34 changeSwarmModule(it, new SwarmWait); 35 it->second->orderMaxTime(2); //sleep 2 seconds.. 36 it->second->process(dt); 37 continue; 38 } 39 40 Vector position=it->second->getPosition(); 41 Vector newPosition; 42 WorldEntity* target=enemyList->at(0); 43 44 //check if enemy is the player.. 45 bool isPlayer=(State::getPlayer()->getPlayable()==target); 46 float speed; 47 48 //find new Position 49 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 56 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; 64 } 65 }else{ 66 67 } 68 28 69 changeSwarmModule(it, new SwarmGoRel); 29 70 30 71 if(enemyList->size()>0){ 31 72 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); 73 it->second->orderRelObject(target); 74 it->second->orderRelPos(newPosition); 75 it->second->orderSpeed(speed); 76 //it->second->orderView(Vector(0,0,1)); 77 it->second->orderMaxTime((rand()%6)+5); //5-10 78 //it->second->newOrder(); 37 79 } 38 80 } -
branches/ai/src/ai/swarm_gorel.cc
r10244 r10249 28 28 } 29 29 averageRadius=averageRadius/members.size(); 30 aMax=1000/averageRadius; 31 vMax=1000/averageRadius; 30 aMax=500/averageRadius; 31 vMax=500/averageRadius; 32 viewChangeMax=90/averageRadius; 32 33 33 34 //load correct ai-module.. … … 36 37 } 37 38 39 //get swarm position.. 40 //position=this->getPosition(); 38 41 } 39 42 … … 42 45 std::map<WorldEntity*,AIModule*>::iterator it; 43 46 44 Vector swarmPosition=this->getPosition();47 //Vector swarmPosition=this->getPosition(); 45 48 Vector correction=Vector(0,0,0); 46 49 Vector destination; … … 48 51 if(taskRelObject!=NULL && taskMaxTime>0){ 49 52 destination=taskRelObject->getAbsCoor()+taskRelPos; 50 correction=(destination- swarmPosition)-view*speed;53 correction=(destination-position)-view*speed; 51 54 correction.y=0; 52 55 taskMaxTime-=dt; … … 64 67 if(movementLen>vMax)movement=movement/movementLen*vMax; 65 68 66 speed=movement.len(); 67 view=movement.getNormalized(); 69 float newSpeed=movement.len(); 70 Vector newView=movement.getNormalized(); 71 72 if((newSpeed<=taskSpeed && speed>=taskSpeed)||(newSpeed>=taskSpeed && speed<=taskSpeed)){ 73 newSpeed=taskSpeed; 74 }else if((newSpeed>speed && speed<taskSpeed) || (newSpeed < speed && speed < taskSpeed)){ 75 newSpeed=taskSpeed; 76 } 77 78 if(angleDeg(view,newView)>viewChangeMax){ 79 std::cout << "alarm\n"; 80 } 81 speed=newSpeed; 82 view=newView; 83 position=position+view*speed*dt; 68 84 69 85 //tell orders to swarm-members... 70 86 for (it= members.begin(); it!= members.end(); it++ ){ 71 it->second->setDestination( swarmPosition);72 it->second->setDestinationMovement( movement);87 it->second->setDestination(position); 88 it->second->setDestinationMovement(view*speed); 73 89 it->second->process(dt); 74 90 } … … 76 92 //check if destination reached 77 93 if(!taskComplete){ 78 swarmPosition=this->getPosition();79 if((destination- swarmPosition).len()<10)taskComplete=true;94 //swarmPosition=this->getPosition(); 95 if((destination-position).len()<10)taskComplete=true; 80 96 } 81 97 } -
branches/ai/src/ai/swarm_gorel.h
r10244 r10249 17 17 float vMax; 18 18 float aMax; 19 float viewChangeMax; 19 20 }; 20 21 -
branches/ai/src/ai/swarm_module.cc
r10244 r10249 44 44 } 45 45 46 Vector SwarmModule::get Position()46 Vector SwarmModule::getSwarmPosition() 47 47 { 48 48 Vector center=Vector(0,0,0); … … 76 76 this->view=other->getView(); 77 77 this->enemys=other->getEnemyList(); 78 this->position=other->getPosition(); 78 79 79 80 this->initialize(); -
branches/ai/src/ai/swarm_module.h
r10244 r10249 19 19 inline void setEnemyList(std::vector<WorldEntity*>* enemys){this->enemys=enemys;} 20 20 21 inline void newOrder(){this->taskComplete=false;} 21 22 inline void orderRelPos(Vector taskRelPos){this->taskRelPos=taskRelPos;} 22 23 inline void orderAbsPos(Vector taskAbsPos){this->taskAbsPos=taskAbsPos;} … … 26 27 inline void orderMaxTime(float taskMaxTime){this->taskMaxTime=taskMaxTime;} 27 28 28 Vector getPosition(); 29 Vector getSwarmPosition(); 30 inline Vector getPosition(){return position;} 29 31 inline float getSpeed(){return speed;} 30 32 inline Vector getView(){return view;} … … 45 47 46 48 Vector view; 49 Vector position; 47 50 float speed; 48 51 -
branches/ai/src/ai/swarm_wait.h
r10244 r10249 8 8 class SwarmWait : public SwarmModule{ 9 9 public: 10 SwarmWait() ;10 SwarmWait(){} 11 11 virtual ~SwarmWait(){} 12 12 virtual void process(float dt);
Note: See TracChangeset
for help on using the changeset viewer.