Changeset 6986 for code/branches/ai
- Timestamp:
- May 27, 2010, 7:52:28 PM (14 years ago)
- Location:
- code/branches/ai/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6978 r6986 47 47 SetConsoleCommand(ArtificialController, masteraction, true); 48 48 SetConsoleCommand(ArtificialController, followme, true); 49 SetConsoleCommand(ArtificialController, passivbehaviour, true); 50 51 static const unsigned int MAX_FORMATION_SIZE = 7; 49 SetConsoleCommand(ArtificialController, passivebehaviour, true); 50 SetConsoleCommand(ArtificialController, formationsize, true); 51 52 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7; 52 53 static const int FORMATION_LENGTH = 10; 53 54 static const int FORMATION_WIDTH = 110; … … 57 58 static const float SPEED_FREE = 0.8f; 58 59 static const float ROTATEFACTOR_FREE = 0.8f; 59 static const int SECONDS_TO_FOLLOW_HUMAN = 10 ;60 static const int SECONDS_TO_FOLLOW_HUMAN = 100; 60 61 61 62 ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator) … … 66 67 this->formationFlight_ = true; 67 68 this->passive_ = false; 69 this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE; 68 70 this->myMaster_ = 0; 69 71 this->freedomCount_ = 0; … … 105 107 continue; 106 108 107 ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());109 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 108 110 109 111 if(aiController) … … 115 117 116 118 /** 117 @brief Get all masters to do a specific action119 @brief Get all masters to do a "specific master action" 118 120 @param action which action to perform (integer, so it can be called with a console command (tmp solution)) 119 121 */ … … 125 127 continue; 126 128 127 ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());129 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 128 130 129 131 if(aiController || aiController->state_ == MASTER) 130 132 { 131 aiController->specificMasterAction_ = TURN180; 132 } 133 } 134 } 135 136 /** 137 @brief A human player gets followed by its nearest master. Initiated by console command, only for demonstration puproses. Does not work at the moment. 133 if (action == 1) 134 aiController->specificMasterAction_ = TURN180; 135 if (action == 2) 136 aiController->specificMasterAction_ = SPIN; 137 } 138 } 139 } 140 141 /** 142 @brief A human player gets followed by its nearest master. Initiated by console command, intended for demonstration puproses. Does not work at the moment. 138 143 */ 139 144 void ArtificialController::followme() … … 149 154 continue; 150 155 151 currentHumanController = static_cast<NewHumanController*>(it->getController());156 currentHumanController = orxonox_cast<NewHumanController*>(it->getController()); 152 157 153 158 if(currentHumanController) humanPawn = *it; 154 159 155 ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());160 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 156 161 157 162 if(aiController || aiController->state_ == MASTER) … … 159 164 160 165 } 161 /*if((humanPawn != NULL) && (allMasters.size != 0)) 162 {163 166 167 if((humanPawn != NULL) && (allMasters.size() != 0)) 168 { 164 169 float posHuman = humanPawn->getPosition().length(); 165 170 float distance = 0.0f; 166 float minDistance = posHuman - allMasters.back()->getControllableEntity()->getPosition().length();171 float minDistance = FLT_MAX; 167 172 int index = 0; 168 173 int i = 0; … … 173 178 if(distance < minDistance) index = i; 174 179 } 175 allMasters[index] .humanToFollow_ = humanPawn;176 allMasters[index] .followHuman(humanPawn, false);177 } */178 179 } 180 181 /** 182 @brief Sets shooting behaviour of pawns.183 @param passive if true, pawns won't shoot.180 allMasters[index]->humanToFollow_ = humanPawn; 181 allMasters[index]->followHuman(humanPawn, false); 182 } 183 184 } 185 186 /** 187 @brief Sets shooting behaviour of pawns. 188 @param passive if true, bots won't shoot. 184 189 */ 185 190 void ArtificialController::passivebehaviour(bool passive) 186 191 { 187 this->passive_ = passive; 192 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 193 { 194 if (!it->getController()) 195 continue; 196 197 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 198 199 if(aiController) 200 { 201 aiController->passive_ = passive; 202 } 203 } 204 } 205 206 207 /** 208 @brief Sets maximal formation size 209 @param size maximal formation size. 210 */ 211 void ArtificialController::formationsize(int size) 212 { 213 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 214 { 215 if (!it->getController()) 216 continue; 217 218 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 219 220 if(aiController) 221 { 222 aiController->maxFormationSize_ = size; 223 } 224 } 188 225 } 189 226 … … 317 354 318 355 //is pawn oneself? 319 if ( static_cast<ControllableEntity*>(*it) == this->getControllableEntity())356 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 320 357 continue; 321 358 322 359 teamSize++; 323 360 324 ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController());361 ArtificialController *newMaster = orxonox_cast<ArtificialController*>(it->getController()); 325 362 326 363 //is it a master? … … 333 370 if (distance < 5000) 334 371 { 335 if(newMaster->slaves_.size() > MAX_FORMATION_SIZE) continue;372 if(newMaster->slaves_.size() > this->maxFormationSize_) continue; 336 373 337 374 for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++) … … 451 488 (*it)->targetPosition_ = this->targetPosition_; 452 489 (*it)->bShooting_ = true; 453 (*it)->getControllableEntity()->fire(0);// fire once for fun490 // (*it)->getControllableEntity()->fire(0);// fire once for fun 454 491 } 455 492 } … … 512 549 513 550 /** 514 @brief Master spins around looking directions axis. Is a "specific master action".551 @brief Master spins around its looking direction axis. Is a "specific master action". Not yet implemented. 515 552 */ 516 553 void ArtificialController::spin() … … 524 561 @brief Master begins to follow a human player. Is a "specific master action". 525 562 @param humanController human to follow. 526 @param alaways follows human forever if true - yet only inplemented for false.563 @param alaways follows human forever if true - only inplemented for false yet. 527 564 */ 528 565 void ArtificialController::followHuman(Pawn* human, bool always) … … 607 644 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 608 645 609 Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());646 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 610 647 if (pawn) 611 648 pawn->setAimPosition(this->targetPosition_); -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6978 r6986 63 63 static void masteraction(int action); 64 64 static void followme(); 65 static void passivebehaviour(bool passive); 66 static void formationsize(int size); 65 67 66 68 protected: … … 68 70 int team_; 69 71 bool formationFlight_; 72 bool passive_; 73 int maxFormationSize_; 70 74 int freedomCount_; 71 75 enum State {SLAVE, MASTER, FREE}; -
code/branches/ai/src/orxonox/controllers/NewHumanController.cc
r6502 r6986 298 298 //y is down positive 299 299 relativeHit.normalise(); 300 300 COUT(0) << (int)this->showDamageOverlay_ << " / " << this->damageOverlayLeft_ << " / " << this->damageOverlayRight_ << std::endl; 301 301 float threshold = 0.3f; 302 302 if (relativeHit.x > threshold) // Left
Note: See TracChangeset
for help on using the changeset viewer.