Changeset 6850
- Timestamp:
- May 3, 2010, 6:41:43 PM (15 years ago)
- Location:
- code/branches/ai
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/data/levels/templates/spaceship_pirate.oxt
r5781 r6850 69 69 accelerationupdown = 125 70 70 > 71 < active>71 <EffectContainer condition="not idle"> 72 72 <FadingBillboard mainstate=activity active=false scale=0.02 position=" 1.3, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 /> 73 73 <FadingBillboard mainstate=activity active=false scale=0.02 position=" 0, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 /> 74 74 <FadingBillboard mainstate=activity active=false scale=0.02 position="-1.3, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 /> 75 </ active>76 < forward>75 </EffectContainer> 76 <EffectContainer condition="normal or boost"> 77 77 <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 13, -4, 9.5" colour="1.0, 0.65, 0.2, 1.0" width=8 length=800 lifetime=1 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" /> 78 78 <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-13, -4, 9.5" colour="1.0, 0.65, 0.2, 1.0" width=8 length=800 lifetime=1 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" /> 79 </ forward>80 < boost>79 </EffectContainer> 80 <EffectContainer condition="boost"> 81 81 <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 0, 5, 15.5" colour="1.0, 0.65, 0.2, 1.0" width=16 length=1600 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" /> 82 </ boost>83 < brake>82 </EffectContainer> 83 <EffectContainer condition="brake"> 84 84 <FadingBillboard mainstate=activity active=false scale=0.1 position=" 4.4, -5.5, 5" colour="0.8, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 /> 85 85 <FadingBillboard mainstate=activity active=false scale=0.1 position="-4.4, -5.5, 5" colour="0.8, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 /> 86 </ brake>86 </EffectContainer> 87 87 </MultiStateEngine> 88 88 </Template> -
code/branches/ai/src/orxonox/controllers/AIController.cc
r6795 r6850 49 49 AIController::~AIController() 50 50 { 51 COUT(0) << "~AIController 1" << std::endl;52 if (this->state_ == MASTER) setNewMasterWithinFormation();53 COUT(0) << "~AIController 2" << std::endl;54 if (this->state_ == SLAVE) unregisterSlave();55 COUT(0) << "~AIController 3" << std::endl;56 this->slaves_.clear();57 COUT(0) << "~AIController 4" << std::endl;58 51 } 59 52 … … 63 56 float maxrand = 100.0f / ACTION_INTERVAL; 64 57 65 if (this->state_ == FREE)//FREE 66 { 67 68 //this->state_ = MASTER; 69 // search master 70 //random = rnd(maxrand); 71 //if (random < 101 && (!this->target_)) 58 if (this->state_ == FREE) 59 { 60 61 62 // return to Master after being forced free 63 if (this->freedomCount_ == 1) 64 { 65 this->state_ = SLAVE; 66 this->freedomCount_ = 0; 67 } 68 69 random = rnd(maxrand); 70 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree())) 72 71 this->searchNewMaster(); 73 72 74 }75 76 if (this->state_ == SLAVE)//SLAVE77 {78 // this->bShooting_ = true;79 }80 81 if (this->state_ == MASTER)//MASTER82 {83 84 // command slaves85 this->commandSlaves();86 87 88 // lose master status (only if less than 4 slaves in formation)89 random = rnd(maxrand);90 if(random < 5/(this->slaves_.size()+1) && this->slaves_.size() < 5 )91 this->loseMasterState();92 93 // look out for outher masters if formation is small94 if(this->slaves_.size() < 3)95 this->searchNewMaster();96 73 97 74 // search enemy … … 125 102 this->searchRandomTargetPosition(); 126 103 127 // shoot 128 /*random = rnd(maxrand);104 105 random = rnd(maxrand); 129 106 if (random < 75 && (this->target_ && !this->bShooting_)) 130 107 this->bShooting_ = true; 131 */ 108 132 109 // stop shooting 133 110 random = rnd(maxrand); 134 111 if (random < 25 && (this->bShooting_)) 135 112 this->bShooting_ = false; 136 } 113 114 } 115 116 if (this->state_ == SLAVE) 117 { 118 // this->bShooting_ = true; 119 } 120 121 if (this->state_ == MASTER)//MASTER 122 { 123 124 125 this->commandSlaves(); 126 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() < 5 ) 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_)) 167 { 168 this->bShooting_ = true; 169 this->forceFreeSlaves(); 170 } 171 // stop shooting 172 random = rnd(maxrand); 173 if (random < 25 && (this->bShooting_)) 174 this->bShooting_ = false; 175 } 176 137 177 } 138 178 … … 160 200 this->moveToTargetPosition(); 161 201 162 //this->getControllableEntity()->fire(0); 163 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); 164 214 } 165 215 -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6795 r6850 45 45 this->target_ = 0; 46 46 this->myMaster_ = 0; 47 //this->slaveNumber_ = -1;48 this->team_ = -1; //new49 this->state_ = FREE; //new47 this->freedomCount_ = 0; 48 this->team_ = -1; 49 this->state_ = FREE; 50 50 this->bShooting_ = false; 51 51 this->bHasTargetPosition_ = false; 52 52 this->targetPosition_ = Vector3::ZERO; 53 //this->slaves_ = new std::list<ArtificialController*>;54 53 55 54 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); … … 65 64 66 65 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0); 66 } 67 68 // gets called when Bot dies 69 void ArtificialController::changedControllableEntity() 70 { 71 COUT(0) << "~changedControllableEntity 0" << std::endl; 72 if(!getControllableEntity()) 73 { 74 COUT(0) << "~changedControllableEntity 1" << std::endl; 75 if (this->state_ == SLAVE) unregisterSlave(); 76 COUT(0) << "~changedControllableEntity 2" << std::endl; 77 if (this->state_ == MASTER) setNewMasterWithinFormation(); 78 COUT(0) << "~changedControllableEntity 3" << std::endl; 79 this->slaves_.clear(); 80 COUT(0) << "~changedControllableEntity 4" << std::endl; 81 this->state_ = FREE; 82 COUT(0) << "~changedControllableEntity 5" << std::endl; 83 } 67 84 } 68 85 … … 77 94 if (this->target_ || distance > 10) 78 95 { 79 // Multiply with 0.8 to make them a bit slower 80 this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x); 81 this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 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 82 107 } 83 108 84 109 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 85 this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance 86 else 87 this->getControllableEntity()->moveFrontBack(0.8f); 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); 117 } 88 118 } 89 119 … … 102 132 { 103 133 myMaster_->slaves_.remove(this); 134 COUT(0) << "~unregister slave" << std::endl; 104 135 } 105 136 } … … 126 157 continue; 127 158 128 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 129 if (!controller || controller->getState() != MASTER) 159 ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController()); 160 161 if (!newMaster || newMaster->getState() != MASTER) 130 162 continue; 131 163 … … 133 165 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 134 166 { 135 if(controller->slaves_.size() > 9) continue; 136 137 this->freeAllSlaves(); 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++) 172 { 173 (*itSlave)->myMaster_ = newMaster; 174 newMaster->slaves_.push_back(*itSlave); 175 } 138 176 this->slaves_.clear(); 139 177 this->state_ = SLAVE; 140 178 141 this->myMaster_ = controller;142 controller->slaves_.push_back(this);179 this->myMaster_ = newMaster; 180 newMaster->slaves_.push_back(this); 143 181 144 182 break; … … 148 186 //hasn't encountered any masters in range? -> become a master 149 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... 150 188 COUT(0) << "~searcheNewMaster" << std::endl; 151 189 } 152 190 … … 157 195 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); 158 196 } 159 /*160 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)161 {162 163 if (!it->getController())164 continue;165 166 ArtificialController *controller = static_cast<ArtificialController*>(it->getController());167 if (!controller || controller->getState() != SLAVE)168 continue;169 //controller->setTargetPosition(this->getControllableEntity()->getPosition());170 controller->targetPosition_ = this->getControllableEntity()->getPosition();171 controller->bHasTargetPosition_ = true;172 }173 */174 197 } 175 198 … … 190 213 newMaster->state_ = MASTER; 191 214 newMaster->slaves_ = this->slaves_; 192 //this->slaves_.clear();215 this->slaves_.clear(); 193 216 194 217 this->state_ = SLAVE; … … 205 228 } 206 229 207 void ArtificialController::freeAllSlaves() 208 { 209 210 230 void ArtificialController::freeSlaves() 231 { 211 232 for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 212 233 { 213 234 (*it)->state_ = FREE; 214 235 } 215 /* 216 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 217 { 218 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 219 if (controller && controller->getState() != SLAVE) 220 continue; 221 222 controller->state_ = FREE; 223 } 224 */ 236 this->slaves_.clear(); 237 } 238 239 void ArtificialController::forceFreeSlaves() 240 { 241 for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 242 { 243 (*it)->state_ = FREE; 244 (*it)->forceFreedom(); 245 (*it)->targetPosition_ = this->targetPosition_; 246 (*it)->bShooting_ = true; 247 (*it)->getControllableEntity()->fire(0); 248 } 225 249 } 226 250 227 251 void ArtificialController::loseMasterState() 228 252 { 229 this->free AllSlaves();253 this->freeSlaves(); 230 254 this->state_ = FREE; 255 } 256 257 void ArtificialController::forceFreedom() 258 { 259 this->freedomCount_ = 5; 260 } 261 262 bool ArtificialController::forcedFree() 263 { 264 if(this->freedomCount_ > 0) 265 { 266 this->freedomCount_--; 267 return true; 268 } else return false; 231 269 } 232 270 -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6833 r6850 51 51 inline int getTeam() const 52 52 { return this->team_; } 53 //virtual void changedControllableEntity();53 virtual void changedControllableEntity(); 54 54 55 55 56 56 protected: 57 58 int team_; 59 int freedomCount_; 60 enum State {SLAVE, MASTER, FREE}; 61 State state_; 62 std::list<ArtificialController*> slaves_; 63 57 64 void targetDied(); 58 65 59 66 void moveToPosition(const Vector3& target); 67 //void speedToTargetPosition(const Vector3& target); 60 68 void moveToTargetPosition(); 61 69 62 enum State {SLAVE, MASTER, FREE};63 70 int getState(); 64 std::list<ArtificialController*> slaves_; 71 65 72 void unregisterSlave(); 66 73 void searchNewMaster(); 67 74 void commandSlaves(); 68 75 void setNewMasterWithinFormation(); 69 void freeAllSlaves(); 76 void freeSlaves(); 77 void forceFreeSlaves(); 70 78 void loseMasterState(); 79 void forceFreedom(); 80 bool forcedFree(); 71 81 72 82 ArtificialController *myMaster_; … … 90 100 bool bShooting_; 91 101 92 93 State state_;94 int team_;95 96 102 private: 97 103 }; -
code/branches/ai/src/orxonox/controllers/CMakeLists.txt
r6782 r6850 8 8 WaypointController.cc 9 9 WaypointPatrolController.cc 10 DroneController.cc10 11 11 ) -
code/branches/ai/src/orxonox/worldentities/CMakeLists.txt
r6782 r6850 5 5 MobileEntity.cc 6 6 ControllableEntity.cc 7 Drone.cc8 7 BigExplosion.cc 9 8 EffectContainer.cc
Note: See TracChangeset
for help on using the changeset viewer.