- Timestamp:
- Jan 24, 2007, 6:55:21 PM (18 years ago)
- Location:
- branches/ai/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_engine.cc
r10266 r10349 50 50 } 51 51 52 void AIEngine::addAI(int teamNumber, int swarmNumber, WorldEntity* npc )52 void AIEngine::addAI(int teamNumber, int swarmNumber, WorldEntity* npc, float maxSpeed, float attackDistance) 53 53 { 54 54 std::pair<std::map<int,AITeam*>::iterator,bool> p; … … 56 56 p=teams.insert(std::make_pair(teamNumber,newTeam)); 57 57 if(!p.second)delete newTeam; 58 p.first->second->addAI(swarmNumber, npc );58 p.first->second->addAI(swarmNumber, npc, maxSpeed, attackDistance); 59 59 } 60 60 -
branches/ai/src/ai/ai_engine.h
r10226 r10349 14 14 15 15 void tick(float dt); 16 void addAI(int teamNumber, int swarmNumber, WorldEntity* npc );16 void addAI(int teamNumber, int swarmNumber, WorldEntity* npc, float maxSpeed, float attackDistance); 17 17 void removeAI(int teamNumber, int swarmNumber, WorldEntity* npc); 18 18 -
branches/ai/src/ai/ai_module.cc
r10226 r10349 43 43 this->target = other->getTarget(); 44 44 this->weight = other->getWeight(); 45 this->speedMax = other->getMaxSpeed(); 45 this->maxSpeed = other->getMaxSpeed(); 46 this->attackDistance = other->getAttackDistance(); 46 47 this->accelerationMax = other->getMaxAcceleration(); 47 48 } -
branches/ai/src/ai/ai_module.h
r10244 r10349 16 16 inline void setTarget(WorldEntity* target){this->target=target;} 17 17 inline void setNPC(WorldEntity* npc){this->npc=npc;} 18 inline void setMaxSpeed(float maxSpeed){this->maxSpeed=maxSpeed;} 19 inline void setAttackDistance(float attackDistance){this->attackDistance=attackDistance;} 18 20 19 21 inline Vector getPosition(){return npc->getAbsCoor();} … … 24 26 inline float getWeight(){return weight;} 25 27 inline float getMaxAcceleration(){return accelerationMax;} 26 inline float getMaxSpeed(){return speedMax;} 28 inline float getMaxSpeed(){return maxSpeed;} 29 inline float getAttackDistance(){return attackDistance;} 27 30 inline float getNPCRadius(){return getRadius(npc);} 28 31 … … 46 49 47 50 float weight; 48 float speedMax; 51 float maxSpeed; 52 float attackDistance; 49 53 float accelerationMax; 50 54 }; -
branches/ai/src/ai/ai_team.cc
r10290 r10349 30 30 31 31 if(it->second->taskDone()){ 32 std::cout << "Swarm Task Complete!\n";32 //std::cout << "Swarm Task Complete!\n"; 33 33 34 34 if(enemyList->size()==0){ … … 51 51 //find new Position 52 52 if(isPlayer){ 53 float attackDistance=it->second->getAttackDistance(); 54 53 55 Vector targetPos=target->getAbsCoor(); 54 56 int zNorm=(position.z>targetPos.z)?1:-1; 55 57 56 58 if((position.z-targetPos.z)*zNorm>60){ //go to start position 57 std::cout << "Go Start Position\n";59 //std::cout << "Go Start Position\n"; 58 60 changeSwarmModule(it, new SwarmGoRel); 59 61 zNorm=1-(rand()%2)*2; //1 or -1 60 newPosition=Vector( 190,0,zNorm*10);62 newPosition=Vector(attackDistance+60,0,zNorm*10); 61 63 speed=60; 62 }else if(position.x > targetPos.x+ 160){ //go to attack position63 std::cout << "Go Attack Position\n";64 }else if(position.x > targetPos.x+attackDistance+40){ //go to attack position 65 //std::cout << "Go Attack Position\n"; 64 66 changeSwarmModule(it, new SwarmGoRel); 65 newPosition=Vector( 130,0,0);67 newPosition=Vector(attackDistance+30,0,0); 66 68 speed=60; 67 }else if(position.x > targetPos.x+ 120){ //go to attack mode68 std::cout << "Go Attack Mode\n";69 }else if(position.x > targetPos.x+attackDistance+20){ //go to attack mode 70 //std::cout << "Go Attack Mode\n"; 69 71 changeSwarmModule(it, new SwarmAttack); 70 newPosition=Vector( 110,0,0);72 newPosition=Vector(attackDistance,0,0); 71 73 speed=60; 72 74 maxTime=(rand()%11)+4;//4-14 Sekunden 73 75 }else{ //go to fallback point 74 std::cout << "Go Fallback Point\n";76 //std::cout << "Go Fallback Point\n"; 75 77 changeSwarmModule(it, new SwarmGoRel); 76 78 newPosition=Vector(80,0,zNorm*90); … … 106 108 107 109 108 void AITeam::addAI(int swarmNumber, WorldEntity* npc )110 void AITeam::addAI(int swarmNumber, WorldEntity* npc, float maxSpeed, float attackDistance) 109 111 { 110 112 std::pair<std::map<int,SwarmModule*>::iterator,bool> p; … … 112 114 p=swarms.insert(std::make_pair(swarmNumber,newSwarm)); 113 115 if(!p.second)delete newSwarm; 114 p.first->second->addAI(npc );116 p.first->second->addAI(npc, maxSpeed, attackDistance); 115 117 } 116 118 -
branches/ai/src/ai/ai_team.h
r10244 r10349 11 11 std::vector<WorldEntity*>* getEnemyList(); 12 12 void process(float dt); 13 void addAI(int swarmNumber, WorldEntity* npc );13 void addAI(int swarmNumber, WorldEntity* npc, float maxSpeed, float attackDistance); 14 14 void removeAI(int swarmNumber, WorldEntity* npc); 15 15 inline int getTeamSize(){ return swarms.size(); } -
branches/ai/src/ai/attack_module.cc
r10283 r10349 62 62 63 63 weight=1; 64 speedMax=1000.0f;65 66 64 67 65 //get information about player … … 71 69 float playerRadius=getRadius( pl->getPlayable() ); 72 70 73 74 71 //get information about myself 75 72 Vector myPosition = npc->getAbsCoor(); 76 73 float myRadius = getRadius(npc); 77 74 //float vMax=1000.0f/myRadius; 75 float vMax=maxSpeed; 76 float aMax=1000/myRadius; 78 77 79 78 //anti player collision … … 117 116 Vector vectorToDestination=destination-myPosition; 118 117 119 Vector correction= playerCollision*50*3 118 Vector correction= playerCollision*50*3 *6/myRadius 120 119 + npcCollision*50*3 *6/myRadius 121 120 + destinationMovement*2//-movement … … 135 134 //limit speed 136 135 float movementLen=movement.len(); 137 if(movementLen> speedMax)movement=movement/movementLen*speedMax;136 if(movementLen>vMax)movement=movement/movementLen*vMax; 138 137 139 138 … … 150 149 view = view.cross( Vector(0,1,0) ).getNormalized(); 151 150 152 npc->setAbsDirSoft( Quaternion( view, Vector(0,1,0)), 1);151 npc->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),8/myRadius); 153 152 154 153 -
branches/ai/src/ai/movement_module.cc
r10283 r10349 51 51 } 52 52 53 MovementModule::MovementModule(WorldEntity* object) 54 { 55 this->npc=object; 56 } 53 57 54 58 void MovementModule::process(float dt) … … 79 83 80 84 float aMax=maxAccleration; 81 float vMax=800.0f/myRadius;82 85 //float vMax=1000.0f/myRadius; 86 float vMax=maxSpeed; 83 87 84 88 //anti player collision … … 111 115 Vector vectorToDestination=destination-myPosition; 112 116 113 Vector correction= playerCollision*50*3 117 Vector correction= playerCollision*50*3 *6/myRadius 114 118 + npcCollision*50*3 *6/myRadius 115 119 + Vector(0,0,0) … … 137 141 //rotate NPC 138 142 view = movement.cross( Vector(0,1,0) ).getNormalized(); 139 npc->setAbsDirSoft( Quaternion( view, Vector(0,1,0)), 3);143 npc->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),10/myRadius); 140 144 141 145 } -
branches/ai/src/ai/movement_module.h
r10226 r10349 14 14 public: 15 15 MovementModule(); 16 inline MovementModule(WorldEntity* object){this->npc=object;}16 MovementModule(WorldEntity* object); 17 17 virtual ~MovementModule(){} 18 18 virtual void process(float dt); -
branches/ai/src/ai/swarm_gorel.cc
r10290 r10349 29 29 averageRadius=averageRadius/members.size(); 30 30 aMax=80;//400/averageRadius; 31 vMax= 80;//300/averageRadius;31 vMax=maxSpeed;//1000/averageRadius;//300/averageRadius; 32 32 viewChangeMax=90/averageRadius; 33 33 -
branches/ai/src/ai/swarm_module.cc
r10249 r10349 24 24 25 25 26 void SwarmModule::addAI(WorldEntity* npc )26 void SwarmModule::addAI(WorldEntity* npc, float maxSpeed, float attackDistance) 27 27 { 28 28 std::pair< std::map<WorldEntity*,AIModule*>::iterator , bool > p; 29 29 AIModule* newAIModule=new MovementModule(npc); 30 newAIModule->setAttackDistance(attackDistance); 31 newAIModule->setMaxSpeed(maxSpeed); 32 this->attackDistance=attackDistance; 33 this->maxSpeed=maxSpeed; 30 34 p=members.insert(std::make_pair(npc,newAIModule)); 31 35 if(!p.second)delete newAIModule; 32 36 33 37 this->initialize(); 34 38 } … … 40 44 delete it->second; //delete AIModule 41 45 members.erase(it); //remove AIModule from members 42 46 43 47 this->initialize(); 44 48 } … … 77 81 this->enemys=other->getEnemyList(); 78 82 this->position=other->getPosition(); 79 83 this->maxSpeed=other->getMaxSpeed(); 84 this->attackDistance=other->getAttackDistance(); 85 80 86 this->initialize(); 81 87 } -
branches/ai/src/ai/swarm_module.h
r10249 r10349 10 10 virtual ~SwarmModule(){} 11 11 virtual void process(float dt){} 12 13 void addAI(WorldEntity* );12 13 void addAI(WorldEntity*, float maxSpeed, float attackDistance); 14 14 void removeAI(WorldEntity*); 15 15 void getAttributesFrom(SwarmModule* oldModule); 16 16 virtual void initialize(){} 17 17 inline bool taskDone(){return taskComplete;} 18 19 inline void setEnemyList(std::vector<WorldEntity*>* enemys){this->enemys=enemys;} 20 18 19 inline void setEnemyList(std::vector<WorldEntity*>* enemys){this->enemys=enemys;} 20 21 21 inline void newOrder(){this->taskComplete=false;} 22 22 inline void orderRelPos(Vector taskRelPos){this->taskRelPos=taskRelPos;} … … 34 34 inline std::vector<WorldEntity*>* getEnemyList(){return enemys;} 35 35 inline std::map<WorldEntity*,AIModule*> getMembers(){return members;} 36 36 inline float getMaxSpeed(){return maxSpeed;} 37 inline float getAttackDistance(){return attackDistance;} 38 37 39 protected: 38 40 float getRadius(WorldEntity* object); … … 45 47 bool taskComplete; 46 48 float taskMaxTime; 47 49 48 50 Vector view; 49 51 Vector position; 50 52 float speed; 51 52 std::map<WorldEntity*,AIModule*> members; 53 54 float maxSpeed; 55 float attackDistance; 56 57 std::map<WorldEntity*,AIModule*> members; 53 58 std::vector<WorldEntity*>* enemys; 54 59 }; -
branches/ai/src/world_entities/npcs/npc.cc
r10275 r10349 55 55 std::cout << "Swarm Number:" << swarmNumber << "\n"; 56 56 57 AIEngine::getInstance()->addAI(teamNumber,swarmNumber,(WorldEntity*)this );57 AIEngine::getInstance()->addAI(teamNumber,swarmNumber,(WorldEntity*)this,maxSpeed,attackDistance); 58 58 59 59 this->bFire = false; … … 132 132 LoadParam(root, "swarm", this, NPC, setSwarmNumber) 133 133 .describe("this sets the swarm number") 134 .defaultValues(0); 135 136 LoadParam(root, "maxSpeed", this, NPC, setMaxSpeed) 137 .describe("this sets the NPC max Speed") 138 .defaultValues(0); 139 140 LoadParam(root, "attackDistance", this, NPC, setAttackDistance) 141 .describe("this sets the NPC distance to target") 134 142 .defaultValues(0); 135 143 } -
branches/ai/src/world_entities/npcs/npc.h
r10275 r10349 36 36 inline void setTeamNumber(int number) { teamNumber=number; } 37 37 inline void setSwarmNumber(int number) { swarmNumber=number; } 38 38 inline void setMaxSpeed(float number) { maxSpeed=number; } 39 inline void setAttackDistance(float number) { attackDistance=number; } 39 40 40 41 private: … … 43 44 int swarmNumber; //!< number of the swarm 44 45 int difficulty; //!< difficulty 46 float maxSpeed; 47 float attackDistance; 45 48 46 49 WeaponManager weaponMan; //!< weapon manager
Note: See TracChangeset
for help on using the changeset viewer.