Changeset 6919
- Timestamp:
- May 17, 2010, 4:45:50 PM (15 years ago)
- Location:
- code/branches/ai/src/orxonox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/AIController.cc
r6891 r6919 59 59 { 60 60 61 61 if (this->formationFlight_) 62 { 62 63 // return to Master after being forced free 63 if (this->freedomCount_ == 1)64 {64 if (this->freedomCount_ == 1) 65 { 65 66 this->state_ = SLAVE; 66 67 this->freedomCount_ = 0; 67 }68 69 random = rnd(maxrand);70 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))71 this->searchNewMaster();72 68 } 69 70 random = rnd(maxrand); 71 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree())) 72 this->searchNewMaster(); 73 } 73 74 74 75 // search enemy … … 116 117 if (this->state_ == SLAVE) 117 118 { 118 // this->bShooting_ = true; 119 119 120 } 120 121 … … 125 126 this->commandSlaves(); 126 127 127 128 // lose master status (only if less than 4 slaves in formation) 129 // random = rnd(maxrand); 130 // if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 ) 131 // this->loseMasterState(); 132 133 // look out for outher masters if formation is small 134 random = rnd(maxrand); 135 if(this->slaves_.size() < 3 && random < 20) 136 this->searchNewMaster(); 137 138 // search enemy 139 random = rnd(maxrand); 140 if (random < 15 && (!this->target_)) 141 this->searchNewTarget(); 142 143 // forget enemy 144 random = rnd(maxrand); 145 if (random < 5 && (this->target_)) 146 this->forgetTarget(); 147 148 // next enemy 149 random = rnd(maxrand); 150 if (random < 10 && (this->target_)) 151 this->searchNewTarget(); 152 153 // fly somewhere 154 random = rnd(maxrand); 155 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 156 this->searchRandomTargetPosition(); 157 158 159 // fly somewhere else 160 random = rnd(maxrand); 161 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 162 this->searchRandomTargetPosition(); 163 164 // shoot 165 random = rnd(maxrand); 166 if (random < 5 && (this->target_ && !this->bShooting_)) 128 if (this->specificMasterAction_ != NONE) 167 129 { 130 if (this->specificMasterAction_ == HOLD) 131 this->specificMasterActionHold(); 132 133 if (this->specificMasterAction_ == TURN180) 134 this->turn180(); 135 136 if (this->specificMasterAction_ == SPIN) 137 this->spin(); 138 } 139 140 else { 141 142 // make 180 degree turn - a specific Master Action 143 random = rnd(maxrand); 144 if (random < 5) 145 this->specificMasterAction_ = TURN180; 146 147 // spin around - a specific Master Action 148 random = rnd(maxrand); 149 if (random < 5) 150 this->specificMasterAction_ = SPIN; 151 152 // lose master status (only if less than 4 slaves in formation) 153 random = rnd(maxrand); 154 if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 ) 155 this->loseMasterState(); 156 157 // look out for outher masters if formation is small 158 random = rnd(maxrand); 159 if(this->slaves_.size() < 3 && random < 20) 160 this->searchNewMaster(); 161 162 // search enemy 163 random = rnd(maxrand); 164 if (random < 15 && (!this->target_)) 165 this->searchNewTarget(); 166 167 // forget enemy 168 random = rnd(maxrand); 169 if (random < 5 && (this->target_)) 170 this->forgetTarget(); 171 172 // next enemy 173 random = rnd(maxrand); 174 if (random < 10 && (this->target_)) 175 this->searchNewTarget(); 176 177 // fly somewhere 178 random = rnd(maxrand); 179 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 180 this->searchRandomTargetPosition(); 181 182 183 // fly somewhere else 184 random = rnd(maxrand); 185 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 186 this->searchRandomTargetPosition(); 187 188 // shoot 189 random = rnd(maxrand); 190 if (random < 5 && (this->target_ && !this->bShooting_)) 191 { 168 192 this->bShooting_ = true; 169 // this->forceFreeSlaves(); 170 } 171 // stop shooting 172 random = rnd(maxrand); 173 if (random < 25 && (this->bShooting_)) 174 this->bShooting_ = false; 193 this->forceFreeSlaves(); 194 } 195 196 // stop shooting 197 random = rnd(maxrand); 198 if (random < 25 && (this->bShooting_)) 199 this->bShooting_ = false; 200 201 } 175 202 } 176 203 … … 189 216 if (this->bHasTargetPosition_) 190 217 this->moveToTargetPosition(); 218 if (this->specificMasterAction_ == NONE) 219 { 220 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 221 this->getControllableEntity()->fire(0); 222 } 223 } 224 225 if (this->state_ == SLAVE) 226 { 227 228 if (this->bHasTargetPosition_) 229 this->moveToTargetPosition(); 230 231 } 232 233 if (this->state_ == FREE) 234 { 235 if (this->target_) 236 this->aimAtTarget(); 237 238 if (this->bHasTargetPosition_) 239 this->moveToTargetPosition(); 191 240 192 241 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) … … 194 243 } 195 244 196 if (this->state_ == SLAVE)197 {198 199 if (this->bHasTargetPosition_)200 this->moveToTargetPosition();201 202 }203 204 if (this->state_ == FREE)205 {206 if (this->target_)207 this->aimAtTarget();208 209 if (this->bHasTargetPosition_)210 this->moveToTargetPosition();211 212 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))213 this->getControllableEntity()->fire(0);214 }215 216 245 SUPER(AIController, tick, dt); 217 246 } -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6918 r6919 42 42 { 43 43 44 static const unsigned int MAX_FORMATION_SIZE = 6; 44 static const unsigned int MAX_FORMATION_SIZE = 7; 45 static const int FORMATION_LENGTH = 10; 46 static const int FORMATION_WIDTH = 110; 45 47 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 46 48 static const float SPEED_MASTER = 0.6f; … … 54 56 55 57 this->target_ = 0; 58 this->formationFlight_ = true; 56 59 this->myMaster_ = 0; 57 60 this->freedomCount_ = 0; 58 61 this->team_ = -1; 59 62 this->state_ = FREE; 63 this->specificMasterAction_ = NONE; 64 this->specificMasterActionHoldCount_ = 0; 60 65 this->bShooting_ = false; 61 66 this->bHasTargetPosition_ = false; … … 73 78 SUPER(ArtificialController, XMLPort, xmlelement, mode); 74 79 75 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0); 80 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1); 81 // XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true); 76 82 } 77 83 … … 134 140 if(this->state_ == SLAVE) 135 141 { 136 // if (this->target_ || distance > 10) 137 // { 138 float rotateFactor; 139 if(this->state_ == SLAVE) rotateFactor = 1.0f; 140 141 142 this->getControllableEntity()->rotateYaw(-1.0f * rotateFactor * sgn(coord.x) * coord.x*coord.x); 143 this->getControllableEntity()->rotatePitch(rotateFactor * sgn(coord.y) * coord.y*coord.y); 144 145 146 147 // } 148 149 if (this->target_ && distance < 500 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 150 { 151 if (this->target_ && distance < 60) 142 143 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 144 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 145 146 147 148 149 150 if (distance < 300) 151 { 152 if (distance < 40) 152 153 { 153 this->getControllableEntity()-> setVelocity(0.8f*this->target_->getVelocity());154 } else this->getControllableEntity()->moveFrontBack( -1.0f*exp(distance/100.0));154 this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER); 155 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 155 156 156 157 } else { 157 this->getControllableEntity()->moveFrontBack(1. 0f + distance/500.0f);158 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f); 158 159 } 159 160 } … … 176 177 if( it != myMaster_->slaves_.end() ) 177 178 myMaster_->slaves_.erase(it); 178 // COUT(0) << "~unregister slave" << std::endl;179 // COUT(0) << "~unregister slave" << std::endl; 179 180 } 180 181 } … … 188 189 this->targetPosition_ = this->getControllableEntity()->getPosition(); 189 190 this->forgetTarget(); 190 191 int teamSize = 0; 191 192 //go through all pawns 192 193 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) … … 197 198 continue; 198 199 199 //has it an ArtificialController and is it a master?200 //has it an ArtificialController? 200 201 if (!it->getController()) 201 202 continue; 202 203 204 //is pawn oneself? 205 if (static_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 206 continue; 207 208 teamSize++; 209 203 210 ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController()); 204 211 212 //is it a master? 205 213 if (!newMaster || newMaster->getState() != MASTER) 206 214 continue; … … 208 216 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 209 217 210 // is pawn oneself? &&is pawn in range?211 if ( static_cast<ControllableEntity*>(*it) != this->getControllableEntity() && distance < 5000)218 // is pawn in range? 219 if (distance < 5000) 212 220 { 213 221 if(newMaster->slaves_.size() > MAX_FORMATION_SIZE) continue; … … 227 235 } 228 236 }//for 229 230 237 //hasn't encountered any masters in range? -> become a master 231 if (state_!=SLAVE) state_ = MASTER;//master encounters master? ->done 238 if (state_ != SLAVE && teamSize != 0) state_ = MASTER;//master encounters master? ->done 239 232 240 } 233 241 … … 243 251 this->slaves_.front()->setTargetPosition(dest); 244 252 } 245 246 // 2 slaves: triangle 247 if (this->slaves_.size() == 2) 248 { 249 dest += 10*orient*WorldEntity::BACK; 250 this->slaves_[0]->setTargetPosition(dest + 10*orient*WorldEntity::LEFT); 251 this->slaves_[1]->setTargetPosition(dest + 10*orient*WorldEntity::RIGHT); 252 } 253 254 if (this->slaves_.size() > MAX_FORMATION_SIZE) 255 { 253 else 254 { 255 dest += 1.0f*orient*WorldEntity::BACK; 256 Vector3 pos = Vector3::ZERO; 257 int i = 1; 258 256 259 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 257 260 { 258 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); 261 pos = Vector3::ZERO; 262 if (i <= 1) pos += dest + FORMATION_WIDTH*WorldEntity::LEFT; 263 if (i == 2) pos += dest + FORMATION_WIDTH*WorldEntity::RIGHT; 264 if (i == 3) pos += dest + FORMATION_WIDTH*WorldEntity::UP; 265 if (i >= 4) 266 { 267 pos += dest + FORMATION_WIDTH*WorldEntity::DOWN; 268 i = 1; 269 dest += FORMATION_LENGTH*orient*WorldEntity::BACK; 270 (*it)->setTargetPosition(pos); 271 continue; 272 } 273 i++; 274 (*it)->setTargetPosition(pos); 259 275 } 260 276 } … … 326 342 } else return false; 327 343 } 344 345 void ArtificialController::specificMasterActionHold() 346 { 347 if (specificMasterActionHoldCount_ == 0) this->specificMasterAction_ = NONE; 348 else specificMasterActionHoldCount_--; 349 } 350 351 void ArtificialController::turn180() 352 { 353 this->specificMasterAction_ = NONE; 354 } 355 356 void ArtificialController::spin() 357 { 358 this->specificMasterAction_ = NONE; 359 } 360 328 361 329 362 void ArtificialController::setTargetPosition(const Vector3& target) -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6888 r6919 53 53 inline int getTeam() const 54 54 { return this->team_; } 55 inline void setFormationFlight(bool formation) 56 { this->formationFlight_ = formation; } 57 inline bool getFormationFlight() const 58 { return this->formationFlight_; } 55 59 virtual void changedControllableEntity(); 56 60 … … 59 63 60 64 int team_; 65 bool formationFlight_; 61 66 int freedomCount_; 62 67 enum State {SLAVE, MASTER, FREE}; 63 68 State state_; 64 69 std::vector<ArtificialController*> slaves_; 70 ArtificialController *myMaster_; 71 enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180}; 72 SpecificMasterAction specificMasterAction_; 73 int specificMasterActionHoldCount_; 65 74 66 75 void targetDied(); … … 80 89 void forceFreedom(); 81 90 bool forcedFree(); 82 83 ArtificialController *myMaster_; 91 void specificMasterActionHold(); 92 void turn180(); 93 void spin(); 84 94 85 95 void setTargetPosition(const Vector3& target); -
code/branches/ai/src/orxonox/worldentities/ControllableEntity.cc
r6417 r6919 577 577 { 578 578 MobileEntity::setAngularVelocity(velocity); 579 this->client_angular_velocity_ = this->getAngularVelocity();579 // // this->client_angular_velocity_ = this->getAngularVelocity(); 580 580 } 581 581 }
Note: See TracChangeset
for help on using the changeset viewer.