Changeset 10177 in orxonox.OLD for branches/ai
- Timestamp:
- Jan 3, 2007, 6:39:09 PM (18 years ago)
- Location:
- branches/ai/src/ai
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_module.h
r10158 r10177 10 10 virtual ~AIModule(){} 11 11 virtual void process(float dt){} 12 12 13 13 void setDifficulty(int newDifficulty); 14 14 inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;} 15 15 inline Vector getPosition(){return myWorldEntity->getAbsCoor();} 16 inline Vector getMovement(){return this->movement;}16 inline Vector getMovement(){return movement;} 17 17 inline void setDestination(Vector destination){this->destination=destination;} 18 18 inline void setDestinationMovement(Vector destinationMovement){this->destinationMovement=destinationMovement;} 19 19 inline void setWeight(int weight){this->weight=weight;} 20 inline void setTarget(WorldEntity* target){this->target=target;} 21 20 22 protected: 21 23 NPC2* myNPC; 22 24 WorldEntity* myWorldEntity; 23 25 std::vector<WorldEntity*>* enemyList; 26 24 27 Vector destination; 25 28 Vector destinationMovement; 26 29 Vector movement; 30 31 float weight; 32 float speedMax; 33 34 WorldEntity* target; 27 35 }; 28 36 -
branches/ai/src/ai/ai_swarm.cc
r10158 r10177 18 18 #include <stdio.h> 19 19 20 AISwarm::AISwarm() 21 { 22 tickCount=0; 23 randomFreq=100; 24 } 25 26 20 27 void AISwarm::process(float dt) 21 28 { 29 if(tickCount>=randomFreq && movement.len()<60){ 30 tickCount=0; 31 int x = (rand()%141)+10; //10-150 32 int z = (rand()%241)-120; //-120-120 33 randomVector=Vector(x,0,z); 34 35 std::cout << "change to: ||" << randomVector.x << " ==" << randomVector.z << "\n"; 36 } 37 tickCount++; 38 39 22 40 std::set<AIModule*>::iterator it; 23 41 Vector swarmPosition=this->getPosition(); 24 42 //std::cout << swarmPosition.x << " " << swarmPosition.z << "\n"; 25 43 26 44 float aMax=70.0f; 27 45 float vMax=1000.0f; 28 29 Vector correction=(destination -swarmPosition)-movement;46 47 Vector correction=(destination+randomVector-swarmPosition)-movement; 30 48 correction.y=0; 31 49 32 50 float correctionLen=correction.len(); 33 51 if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt; 34 52 35 53 //std::cout << angleRad(correction,movement) << "\n"; 36 54 movement+=correction; 37 55 38 56 float movementLen=movement.len(); 39 57 if(movementLen>vMax)movement=movement/movementLen*vMax; 40 41 58 59 42 60 for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ){ 43 61 (*it)->setDestination(swarmPosition); … … 48 66 } 49 67 68 50 69 void AISwarm::addAI(AIModule* aiModule) 51 70 { 52 71 swarmMembers.insert(aiModule); 53 72 } 73 54 74 55 75 void AISwarm::removeAI(AIModule* aiModule) … … 59 79 delete (*it); 60 80 } 81 61 82 62 83 Vector AISwarm::getPosition() -
branches/ai/src/ai/ai_swarm.h
r10158 r10177 8 8 class AISwarm{ 9 9 public: 10 AISwarm() {}10 AISwarm(); 11 11 ~AISwarm(){} 12 12 void process(float dt); … … 22 22 std::vector<WorldEntity*>* enemyList; 23 23 std::set<AIModule*> swarmMembers; 24 int tickCount; 25 int randomFreq; 26 Vector randomVector; 24 27 }; 25 28 -
branches/ai/src/ai/ai_team.cc
r10158 r10177 19 19 void AITeam::process(float dt) 20 20 { 21 //int x;22 //int z;23 //Vector random;24 25 21 std::map<int,AISwarm*>::iterator it; 26 22 for (it= swarms.begin(); it!= swarms.end(); it++ ){ 27 28 //x = 20*(rand()%10 + 1)-100; 29 //z = 20*(rand()%10 + 1)-100; 30 //random=Vector(x,0,z); 31 23 32 24 it->second->setEnemyList(enemyList); 33 25 if(enemyList->size()>0) … … 36 28 } 37 29 } 30 38 31 39 32 void AITeam::addAI(int swarmNumber, AIModule* aiModule) … … 45 38 p.first->second->addAI(aiModule); 46 39 } 40 47 41 48 42 void AITeam::removeAI(int swarmNumber, AIModule* aiModule) -
branches/ai/src/ai/ai_team.h
r10138 r10177 8 8 public: 9 9 ~AITeam(){} 10 11 12 10 AITeam(){} 11 std::vector<WorldEntity*>* getEnemyList(); 12 void process(float dt); 13 13 void addAI(int swarmNumber, AIModule* aiModule); 14 14 void removeAI(int swarmNumber, AIModule* aiModule); … … 16 16 inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;} 17 17 private: 18 18 std::vector<WorldEntity*>* enemyList; 19 19 std::map<int,AISwarm*> swarms; 20 20 }; -
branches/ai/src/ai/movement_module.cc
r10158 r10177 28 28 SHELL_COMMAND(setDistanceToNPC, MovementModule, setDistanceToNPC); 29 29 SHELL_COMMAND(setMaxAccleartion, MovementModule, setMaxAccleartion); 30 SHELL_COMMAND(setTestValue, MovementModule, setTestValue); 31 SHELL_COMMAND(setTestValue2, MovementModule, setTestValue2); 30 32 31 33 float MovementModule::distanceToPlayer=15; 32 34 float MovementModule::distanceToNPC=2; 33 float MovementModule::maxAccleration=200.0f; 35 float MovementModule::maxAccleration=300.0f; 36 float MovementModule::testValue=2; 37 float MovementModule::testValue2=40; 34 38 35 39 void MovementModule::setDistanceToPlayer(float newValue){ distanceToPlayer=newValue; } 36 40 void MovementModule::setDistanceToNPC(float newValue){ distanceToNPC=newValue; } 37 41 void MovementModule::setMaxAccleartion(float newValue){ maxAccleration=newValue; } 42 void MovementModule::setTestValue(float newValue){ testValue=newValue; } 43 void MovementModule::setTestValue2(float newValue){ testValue2=newValue; } 38 44 39 40 41 42 43 44 // std::vector<Vector> MovementModule::hidingPoint; 45 // std::vector<float> MovementModule::hidingPointSize; 46 // 47 // std::vector<NPC2*> MovementModule::npcList; 48 // std::vector<Vector> MovementModule::npcPosition; 49 // std::vector<float> MovementModule::npcRadius; 50 // std::vector<int> MovementModule::npcSwarm; 51 // std::vector<int> MovementModule::npcTeam; 52 // 53 // Vector MovementModule::playerPosition; 54 // Vector MovementModule::playerMovement; 55 // float MovementModule::playerRadius; 56 // 57 // std::vector<Vector> MovementModule::swarmCenter; 58 // std::vector<int> MovementModule::swarmMemberCount; 59 // 60 // 61 // 62 // 63 // 45 MovementModule::MovementModule() 46 { 47 tickCount=0; 48 randomFreq=100; 49 } 64 50 65 51 … … 82 68 83 69 84 85 86 // void MovementModule::collectInformation(float dt)87 // {88 // //return if already processed..89 // if(dt==this->oldDT)return;90 // this->oldDT=dt;91 //92 //93 // //clear old Information..94 // hidingPoint.clear();95 // hidingPointSize.clear();96 //97 // npcList.clear();98 // npcPosition.clear();99 // npcRadius.clear();100 // npcSwarm.clear();101 // npcTeam.clear();102 //103 // swarmCenter.clear();104 // swarmMemberCount.clear();105 //106 //107 // //get all NPCs..108 // for(ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); it != NPC2::objectList().end(); ++it)109 // {110 // npcList.push_back(*it);111 // npcRadius.push_back(getRadius(*it));112 // npcPosition.push_back((*it)->getAbsCoor());113 // npcSwarm.push_back((*it)->swarm);114 // npcTeam.push_back((*it)->team);115 // }116 //117 //118 // //Swarm Information119 // unsigned int tmpSwarm;120 // for(unsigned int i=0;i<npcList.size();i++){121 // tmpSwarm = npcSwarm.at(i);122 // if(tmpSwarm > swarmMemberCount.size()){123 // //swarmMemberCount.insert(swarmMemberCount.size(), tmpSwarm - swarmMemberCount.size(), 0);124 // //swarmCenter.insert(swarmCenter.size(), tmpSwarm - swarmCenter.size(), Vector(0,0,0));125 // }126 // //swarmMemberCount.at(tmpSwarm)++;127 // //swarmCenter.at(tmpSwarm)=swarmCenter.at(tmpSwarm)+npcPosition.at(i);128 // }129 // for(unsigned int i=0;i<swarmCenter.size();i++){130 // //swarmCenter.at(i)=swarmCenter.at(i)/swarmMemberCount.at(i);131 // }132 //133 //134 // //get information about Player135 // Player* pl = State::getPlayer();136 // if( pl != NULL){137 // playerPosition = pl->getPlayable()->getAbsCoor();138 // playerRadius=getRadius( pl->getPlayable() );139 // //PRINTF(0)("Player Radius: %f\n",playerRadius);140 // }141 //142 //143 // //calculate hiding Points..144 //145 // }146 147 148 70 void MovementModule::process(float dt) 149 71 { 150 72 if(myNPC == NULL)return; 151 73 152 //get information about Player 74 Vector tmpVector; 75 float tmpFloat; 76 Vector npcCollision; 77 Vector playerCollision; 78 bool autoRotate=true; 79 target=enemyList->at(0); 80 81 weight=1; 82 speedMax=1000.0f; 83 84 85 //get information about player 153 86 Player* pl = State::getPlayer(); 154 87 if( pl == NULL)return; 155 88 Vector playerPosition = pl->getPlayable()->getAbsCoor(); 156 89 float playerRadius=getRadius( pl->getPlayable() ); 157 90 158 91 159 92 //get information about myself … … 162 95 163 96 97 //anti player collision 164 98 Vector vectorToPlayer = playerPosition - myPosition; 165 99 166 Vector tmpVector;167 float tmpFloat;168 169 Vector npcCollision;170 Vector playerCollision;171 172 173 174 //float a=200.0f;175 float vMax=200.0f;176 //float maxAccleration=300.0f;177 //float safetyDistance=2.0f;178 179 180 //Anti Player Collision181 100 tmpFloat=vectorToPlayer.len()-playerRadius-myRadius-distanceToPlayer; 182 101 if(tmpFloat<0.1)tmpFloat=0.1; … … 184 103 185 104 186 // Anti NPC Collision105 //anti NPC collision 187 106 for(ObjectList<WorldEntity>::const_iterator it = WorldEntity::objectList().begin(); it != WorldEntity::objectList().end(); ++it) 188 107 { … … 199 118 200 119 120 //random movement 121 //randomFreq=testValue2; 122 if(++tickCount>=randomFreq && movement.len()<60){ 123 tickCount=0; 124 int x = (rand()%101)-50; //-50-50 125 int z = (rand()%101)-50; //-50-50 126 randomVector=Vector(x,0,z); 127 randomFreq=(rand()%81)+70; //70-150 Ticks 128 } 201 129 130 131 //calculate correction vector 202 132 Vector vectorToDestination=destination-myPosition; 203 133 … … 205 135 + npcCollision*50*3 206 136 + Vector(0,0,0) 207 + destinationMovement*2//-myMovement 208 + (vectorToDestination-myMovement)*3; 137 + destinationMovement*2//-movement 138 + (vectorToDestination-movement)*3; 139 140 if(movement.len()<testValue2){ 141 //if(testValue2){ 142 correction=correction + randomVector * testValue; 143 autoRotate=false; 144 } 209 145 210 146 correction.y=0; 147 148 149 //limit accleration 211 150 float correctionLen=correction.len(); 212 151 if(correctionLen>maxAccleration*dt)correction=correction/correctionLen*maxAccleration*dt; 213 m yMovement+=correction;152 movement+=correction; 214 153 215 float movementLen=myMovement.len();216 if(movementLen>vMax)myMovement/movementLen*vMax;217 154 218 //Move NPC... 219 myNPC->shiftCoor(myMovement * dt); 155 //limit speed 156 float movementLen=movement.len(); 157 if(movementLen>speedMax)movement=movement/movementLen*speedMax; 220 158 221 //Rotate NPC 222 Vector view = myMovement; 223 //if(vectorToPlayer.dot(v)<0){ 224 // view = v.cross( Vector(0,1,0) ).getNormalized(); 225 //}else{ 226 view = myMovement.cross( Vector(0,1,0) ).getNormalized(); 227 //} 228 //if(dist<keepDist)view=view*-1; 229 //myNPC->setAbsDir( Quaternion( view, Vector(0,1,0))); 159 160 //move NPC... 161 myNPC->shiftCoor(movement * dt); 162 163 164 //rotate NPC 165 Vector view; 166 if(autoRotate){ 167 view = movement.cross( Vector(0,1,0) ).getNormalized(); 168 }else{ 169 view = target->getAbsCoor()-myPosition; 170 view = view.cross( Vector(0,1,0) ).getNormalized(); 171 } 230 172 myNPC->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),3); 231 movement=myMovement; 173 232 174 } 233 175 -
branches/ai/src/ai/movement_module.h
r10138 r10177 13 13 14 14 public: 15 MovementModule() {}15 MovementModule(); 16 16 inline MovementModule(NPC2* object){ this->myNPC=object; this->myWorldEntity=(WorldEntity*)object;} 17 17 virtual ~MovementModule(){} … … 21 21 static void setDistanceToNPC(float newValue); 22 22 static void setMaxAccleartion(float newValue); 23 // 23 static void setTestValue(float newValue); 24 static void setTestValue2(float newValue); 25 24 26 private: 25 26 // static std::vector<NPC2*> npcList;27 // static std::vector<Vector> npcPosition;28 // static std::vector<float> npcRadius;29 // static std::vector<int> npcSwarm;30 // static std::vector<int> npcTeam;31 //32 // static Vector playerPosition;33 // static Vector playerMovement;34 // static float playerRadius;35 36 37 27 Vector myMovement; 38 28 float myMaxAccleration; … … 44 34 static float distanceToPlayer; 45 35 static float distanceToNPC; 36 static float testValue; 37 static float testValue2; 38 39 int tickCount; 40 int randomFreq; 41 Vector randomVector; 46 42 }; 47 43
Note: See TracChangeset
for help on using the changeset viewer.