Changeset 6888 for code/branches/ai
- Timestamp:
- May 10, 2010, 4:32:26 PM (15 years ago)
- Location:
- code/branches/ai
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/data/levels/teamdeathmatch.oxw
r5781 r6888 35 35 36 36 <?lua 37 for i = 1, 70, 137 for i = 1, 8, 1 38 38 do ?> 39 39 <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 1000 + 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>"> -
code/branches/ai/src/orxonox/controllers/AIController.cc
r6850 r6888 127 127 128 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() < 5)131 this->loseMasterState();129 // random = rnd(maxrand); 130 // if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 ) 131 // this->loseMasterState(); 132 132 133 133 // look out for outher masters if formation is small … … 167 167 { 168 168 this->bShooting_ = true; 169 this->forceFreeSlaves();169 // this->forceFreeSlaves(); 170 170 } 171 171 // stop shooting -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6850 r6888 36 36 #include "gametypes/TeamDeathmatch.h" 37 37 #include "controllers/WaypointPatrolController.h" 38 #include "util/Math.h" 38 39 39 40 namespace orxonox 40 41 { 42 43 static const unsigned int MAX_FORMATION_SIZE = 6; 44 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 45 static const float SPEED_MASTER = 0.6f; 46 static const float ROTATEFACTOR_MASTER = 0.2f; 47 static const float SPEED_FREE = 0.8f; 48 static const float ROTATEFACTOR_FREE = 0.8f; 49 41 50 ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator) 42 51 { … … 69 78 void ArtificialController::changedControllableEntity() 70 79 { 71 COUT(0) << "~changedControllableEntity 0" << std::endl;72 80 if(!getControllableEntity()) 73 81 { 74 COUT(0) << "~changedControllableEntity 1" << std::endl;75 82 if (this->state_ == SLAVE) unregisterSlave(); 76 COUT(0) << "~changedControllableEntity 2" << std::endl;77 83 if (this->state_ == MASTER) setNewMasterWithinFormation(); 78 COUT(0) << "~changedControllableEntity 3" << std::endl;79 84 this->slaves_.clear(); 80 COUT(0) << "~changedControllableEntity 4" << std::endl;81 85 this->state_ = FREE; 82 COUT(0) << "~changedControllableEntity 5" << std::endl; 86 83 87 } 84 88 } … … 92 96 float distance = (target - this->getControllableEntity()->getPosition()).length(); 93 97 94 if (this->target_ || distance > 10) 95 { 96 // Multiply with rotateFactor to make them a bit slower 97 float rotateFactor; 98 if(this->state_ == SLAVE) rotateFactor = 1.0f; 99 if(this->state_ == MASTER) rotateFactor = 0.4f; 100 else rotateFactor = 0.8f; 101 102 this->getControllableEntity()->rotateYaw(-1.0f * rotateFactor * sgn(coord.x) * coord.x*coord.x); 103 this->getControllableEntity()->rotatePitch(rotateFactor * sgn(coord.y) * coord.y*coord.y); 104 105 106 107 } 108 109 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 110 { 111 if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(-0.8f); 112 else this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance 113 } else { 114 if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(2.5f); 115 if(this->state_ == MASTER) this->getControllableEntity()->moveFrontBack(0.4f); 116 else this->getControllableEntity()->moveFrontBack(0.8f); 98 99 if(this->state_ == FREE) 100 { 101 if (this->target_ || distance > 10) 102 { 103 // Multiply with 0.8 to make them a bit slower 104 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x); 105 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y); 106 } 107 108 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 109 { 110 this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance 111 } else this->getControllableEntity()->moveFrontBack(SPEED_FREE); 112 } 113 114 115 116 if(this->state_ == MASTER) 117 { 118 if (this->target_ || distance > 10) 119 { 120 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 121 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 122 123 } 124 125 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 126 { 127 this->getControllableEntity()->moveFrontBack(-0.05f); 128 } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 129 } 130 131 132 133 if(this->state_ == SLAVE) 134 { 135 // if (this->target_ || distance > 10) 136 // { 137 float rotateFactor; 138 if(this->state_ == SLAVE) rotateFactor = 1.0f; 139 140 141 this->getControllableEntity()->rotateYaw(-1.0f * rotateFactor * sgn(coord.x) * coord.x*coord.x); 142 this->getControllableEntity()->rotatePitch(rotateFactor * sgn(coord.y) * coord.y*coord.y); 143 144 145 146 // } 147 148 if (this->target_ && distance < 500 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 149 { 150 if (this->target_ && distance < 60) 151 { 152 this->getControllableEntity()->setVelocity(0.8f*this->target_->getVelocity()); 153 } else this->getControllableEntity()->moveFrontBack(-1.0f*exp(distance/100.0)); 154 155 } else { 156 this->getControllableEntity()->moveFrontBack(1.0f + distance/500.0f); 157 } 117 158 } 118 159 } … … 131 172 if(myMaster_) 132 173 { 133 myMaster_->slaves_.remove(this); 134 COUT(0) << "~unregister slave" << std::endl; 174 std::vector<ArtificialController*>::iterator it = std::find(myMaster_->slaves_.begin(), myMaster_->slaves_.end(), this); 175 if( it != myMaster_->slaves_.end() ) 176 myMaster_->slaves_.erase(it); 177 //COUT(0) << "~unregister slave" << std::endl; 135 178 } 136 179 } … … 162 205 continue; 163 206 207 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 208 164 209 //is pawn oneself? && is pawn in range? 165 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 166 { 167 if(newMaster->slaves_.size() > 6) continue; 168 169 //this->freeSlaves(); 170 171 for(std::list<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++) 210 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() && distance < 5000) 211 { 212 if(newMaster->slaves_.size() > MAX_FORMATION_SIZE) continue; 213 214 for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++) 172 215 { 173 216 (*itSlave)->myMaster_ = newMaster; … … 185 228 186 229 //hasn't encountered any masters in range? -> become a master 187 if (state_!=SLAVE) state_ = MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop within master mode in AIcontroller... 188 COUT(0) << "~searcheNewMaster" << std::endl; 230 if (state_!=SLAVE) state_ = MASTER;//master encounters master? ->done 189 231 } 190 232 191 233 void ArtificialController::commandSlaves() { 192 234 193 for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 194 { 195 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); 235 Quaternion orient = this->getControllableEntity()->getOrientation(); 236 Vector3 dest = this->getControllableEntity()->getPosition(); 237 238 // 1 slave: follow 239 if (this->slaves_.size() == 1) 240 { 241 dest += 4*orient*WorldEntity::BACK; 242 this->slaves_.front()->setTargetPosition(dest); 243 } 244 245 // 2 slaves: triangle 246 if (this->slaves_.size() == 2) 247 { 248 dest += 10*orient*WorldEntity::BACK; 249 this->slaves_[0]->setTargetPosition(dest + 10*orient*WorldEntity::LEFT); 250 this->slaves_[1]->setTargetPosition(dest + 10*orient*WorldEntity::RIGHT); 251 } 252 253 if (this->slaves_.size() > MAX_FORMATION_SIZE) 254 { 255 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 256 { 257 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); 258 } 196 259 } 197 260 } … … 200 263 void ArtificialController::setNewMasterWithinFormation() 201 264 { 202 COUT(0) << "~setNewMasterWithinFormation 1" << std::endl; 265 203 266 if (this->slaves_.empty()) 204 267 return; 205 COUT(0) << "~setNewMasterWithinFormation 1b" << std::endl;206 268 207 269 ArtificialController *newMaster = this->slaves_.back(); 208 COUT(0) << "~setNewMasterWithinFormation 2" << std::endl;209 270 this->slaves_.pop_back(); 210 COUT(0) << "~setNewMasterWithinFormation 3" << std::endl; 271 211 272 if(!newMaster) return; 212 COUT(0) << "~setNewMasterWithinFormation 4" << std::endl;213 273 newMaster->state_ = MASTER; 214 274 newMaster->slaves_ = this->slaves_; 275 215 276 this->slaves_.clear(); 216 217 277 this->state_ = SLAVE; 218 278 this->myMaster_ = newMaster; 219 279 220 COUT(0) << "~setNewMasterWithinFormation 5" << std::endl; 221 for(std::list<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++) 222 { 223 COUT(0) << "~setNewMasterWithinFormation 6" << std::endl; 280 for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++) 281 { 224 282 (*it)->myMaster_ = newMaster; 225 283 } 226 COUT(0) << "~setNewMasterWithinFormation 7" << std::endl;227 284 228 285 } … … 230 287 void ArtificialController::freeSlaves() 231 288 { 232 for(std:: list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)289 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 233 290 { 234 291 (*it)->state_ = FREE; … … 239 296 void ArtificialController::forceFreeSlaves() 240 297 { 241 for(std:: list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)298 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 242 299 { 243 300 (*it)->state_ = FREE; … … 245 302 (*it)->targetPosition_ = this->targetPosition_; 246 303 (*it)->bShooting_ = true; 247 (*it)->getControllableEntity()->fire(0); 304 (*it)->getControllableEntity()->fire(0);// fire once for fun 248 305 } 249 306 } … … 257 314 void ArtificialController::forceFreedom() 258 315 { 259 this->freedomCount_ = 5;316 this->freedomCount_ = FREEDOM_COUNT; 260 317 } 261 318 -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6850 r6888 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include <vector> 35 34 36 #include "util/Math.h" 35 37 #include "Controller.h" … … 43 45 virtual ~ArtificialController(); 44 46 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //new47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 48 47 49 void abandonTarget(Pawn* target); … … 60 62 enum State {SLAVE, MASTER, FREE}; 61 63 State state_; 62 std:: list<ArtificialController*> slaves_;64 std::vector<ArtificialController*> slaves_; 63 65 64 66 void targetDied(); 65 67 66 68 void moveToPosition(const Vector3& target); 67 //void speedToTargetPosition(const Vector3& target);68 69 void moveToTargetPosition(); 69 70
Note: See TracChangeset
for help on using the changeset viewer.