Changeset 7034
- Timestamp:
- May 31, 2010, 5:31:50 AM (14 years ago)
- Location:
- code/branches/presentation3
- Files:
-
- 15 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3
- Property svn:mergeinfo changed
/code/branches/ai (added) merged: 6592,6601,6640,6683,6695-6696,6782,6795,6832-6833,6847,6850,6854,6888,6891,6918-6919,6958,6978,6986,6991,6997,7029,7033
- Property svn:mergeinfo changed
-
code/branches/presentation3/data/levels/pickups.oxw
r7032 r7034 25 25 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" /> 26 26 <SpawnPoint position="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /> 27 28 <!-- Drone pickup --> 29 30 <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10"> 31 <pickup> 32 <DronePickup droneTemplate=droneTemplate /> 33 </pickup> 34 </PickupSpawner> 27 35 28 36 <!-- Shield pickups --> -
code/branches/presentation3/data/levels/templates/pickup_representation_templates.oxt
r6998 r7034 426 426 </PickupCollection> 427 427 </Template> 428 428 429 <Template name=droneTemplate> 430 <Drone name="meineDrohne" mass= "50" linearDamping = "0.7" angularDamping = "0.99999" maxDistanceToOwner_=150 minDistanceToOwner_=50 primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50> 431 <attached> 432 <Model scale="1" mesh="drone.mesh"/> 433 </attached> 434 <collisionShapes> 435 <BoxCollisionShape position="0,0,0" halfExtents="1, 1, 1" /> 436 </collisionShapes> 437 <weaponslots> 438 <WeaponSlot position=" 0, 0,0" /> 439 </weaponslots> 440 <weaponsets> 441 <WeaponSet firemode=0 /> 442 </weaponsets> 443 <weapons> 444 <WeaponPack> 445 <links> 446 <DefaultWeaponmodeLink firemode=0 weaponmode=0 /> 447 </links> 448 <Weapon> 449 <attached> 450 <Model mesh="hs-w01.mesh" roll="195" position="0,1,0" scale=2 /> 451 <Model mesh="hs-w01s.mesh" roll="195" position="0.1,0.5,0" scale=2 /> 452 </attached> 453 <HsW01 mode=0 munitionpershot=0 delay=0.125 material="Flares/point_lensflare" muzzleoffset=" 0.7, 1.5,-4" /> 454 <HsW01 mode=0 munitionpershot=0 delay=0 material="Flares/point_lensflare" muzzleoffset="-0.9, 1.1,-4" /> 455 </Weapon> 456 </WeaponPack> 457 </weapons> 458 </Drone> 459 </Template> -
code/branches/presentation3/data/levels/templates/spaceship_pirate.oxt
r5781 r7034 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/presentation3/src/modules/pickup/PickupPrereqs.h
r6998 r7034 75 75 76 76 //items 77 class DronePickup; 77 78 class HealthPickup; 78 79 class InvisiblePickup; -
code/branches/presentation3/src/modules/pickup/items/CMakeLists.txt
r6998 r7034 3 3 InvisiblePickup.cc 4 4 MetaPickup.cc 5 DronePickup.cc 5 6 SpeedPickup.cc 6 7 ShieldPickup.cc -
code/branches/presentation3/src/modules/pickup/items/DronePickup.cc
- Property svn:eol-style set to native
-
code/branches/presentation3/src/modules/pickup/items/DronePickup.h
- Property svn:eol-style set to native
-
code/branches/presentation3/src/orxonox/OrxonoxPrereqs.h
r7031 r7034 82 82 class ArtificialController; 83 83 class Controller; 84 class DroneController; 84 85 class HumanController; 85 86 class ScriptController; … … 162 163 class CameraPosition; 163 164 class ControllableEntity; 165 class Drone; 164 166 class EffectContainer; 165 167 class ExplosionChunk; -
code/branches/presentation3/src/orxonox/controllers/AIController.cc
r7030 r7034 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 56 56 float maxrand = 100.0f / ACTION_INTERVAL; 57 57 58 // search enemy 59 random = rnd(maxrand); 60 if (random < 15 && (!this->target_)) 61 this->searchNewTarget(); 62 63 // forget enemy 64 random = rnd(maxrand); 65 if (random < 5 && (this->target_)) 66 this->forgetTarget(); 67 68 // next enemy 69 random = rnd(maxrand); 70 if (random < 10 && (this->target_)) 71 this->searchNewTarget(); 72 73 // fly somewhere 74 random = rnd(maxrand); 75 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 76 this->searchRandomTargetPosition(); 77 78 // stop flying 79 random = rnd(maxrand); 80 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 81 this->bHasTargetPosition_ = false; 82 83 // fly somewhere else 84 random = rnd(maxrand); 85 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 86 this->searchRandomTargetPosition(); 87 88 // shoot 89 random = rnd(maxrand); 90 if (random < 75 && (this->target_ && !this->bShooting_)) 91 this->bShooting_ = true; 92 93 // stop shooting 94 random = rnd(maxrand); 95 if (random < 25 && (this->bShooting_)) 96 this->bShooting_ = false; 58 if (this->state_ == FREE) 59 { 60 61 if (this->formationFlight_) 62 { 63 // return to Master after being forced free 64 if (this->freedomCount_ == 1) 65 { 66 this->state_ = SLAVE; 67 this->freedomCount_ = 0; 68 } 69 70 random = rnd(maxrand); 71 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree())) 72 this->searchNewMaster(); 73 } 74 75 // search enemy 76 random = rnd(maxrand); 77 if (random < 15 && (!this->target_)) 78 this->searchNewTarget(); 79 80 // forget enemy 81 random = rnd(maxrand); 82 if (random < 5 && (this->target_)) 83 this->forgetTarget(); 84 85 // next enemy 86 random = rnd(maxrand); 87 if (random < 10 && (this->target_)) 88 this->searchNewTarget(); 89 90 // fly somewhere 91 random = rnd(maxrand); 92 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 93 this->searchRandomTargetPosition(); 94 95 // stop flying 96 random = rnd(maxrand); 97 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 98 this->bHasTargetPosition_ = false; 99 100 // fly somewhere else 101 random = rnd(maxrand); 102 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 103 this->searchRandomTargetPosition(); 104 105 // shoot 106 random = rnd(maxrand); 107 if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_)) 108 this->bShooting_ = true; 109 110 // stop shooting 111 random = rnd(maxrand); 112 if (random < 25 && (this->bShooting_)) 113 this->bShooting_ = false; 114 115 } 116 117 if (this->state_ == SLAVE) 118 { 119 120 } 121 122 if (this->state_ == MASTER) 123 { 124 125 126 this->commandSlaves(); 127 128 if (this->specificMasterAction_ != NONE) 129 { 130 this->specificMasterActionHold(); 131 132 // if (this->specificMasterAction_ == TURN180) 133 // this->turn180Init(); 134 135 // if (this->specificMasterAction_ == SPIN) 136 // this->spinInit(); 137 138 // if (this->specificMasterAction_ == FOLLOWHUMAN) 139 // this->followHuman(this->HumanToFollow_, false); 140 } 141 142 else { 143 144 // make 180 degree turn - a specific Master Action 145 random = rnd(1000.0f); 146 if (random < 5) 147 this->turn180Init(); 148 149 // spin around - a specific Master Action 150 random = rnd(1000.0f); 151 if (random < 5) 152 this->spinInit(); 153 154 // lose master status (only if less than 4 slaves in formation) 155 random = rnd(maxrand); 156 if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 ) 157 this->loseMasterState(); 158 159 // look out for outher masters if formation is small 160 random = rnd(maxrand); 161 if(this->slaves_.size() < 3 && random < 20) 162 this->searchNewMaster(); 163 164 // search enemy 165 random = rnd(maxrand); 166 if (random < 15 && (!this->target_)) 167 this->searchNewTarget(); 168 169 // forget enemy 170 random = rnd(maxrand); 171 if (random < 5 && (this->target_)) 172 this->forgetTarget(); 173 174 // next enemy 175 random = rnd(maxrand); 176 if (random < 10 && (this->target_)) 177 this->searchNewTarget(); 178 179 // fly somewhere 180 random = rnd(maxrand); 181 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 182 this->searchRandomTargetPosition(); 183 184 185 // fly somewhere else 186 random = rnd(maxrand); 187 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 188 this->searchRandomTargetPosition(); 189 190 // shoot 191 random = rnd(maxrand); 192 if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_)) 193 { 194 this->bShooting_ = true; 195 this->forceFreeSlaves(); 196 } 197 198 // stop shooting 199 random = rnd(maxrand); 200 if (random < 25 && (this->bShooting_)) 201 this->bShooting_ = false; 202 203 } 204 } 205 97 206 } 98 207 … … 102 211 return; 103 212 104 if (this->target_) 105 this->aimAtTarget(); 106 107 if (this->bHasTargetPosition_) 108 this->moveToTargetPosition(); 109 110 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 111 this->getControllableEntity()->fire(0); 213 if (this->state_ == MASTER) 214 { 215 if (this->specificMasterAction_ == NONE) 216 { 217 if (this->target_) 218 this->aimAtTarget(); 219 220 if (this->bHasTargetPosition_) 221 this->moveToTargetPosition(); 222 223 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 224 this->getControllableEntity()->fire(0); 225 } 226 227 if (this->specificMasterAction_ == TURN180) 228 this->turn180(); 229 230 if (this->specificMasterAction_ == SPIN) 231 this->spin(); 232 if (this->specificMasterAction_ == FOLLOWHUMAN) 233 this->follow(); 234 } 235 236 if (this->state_ == SLAVE) 237 { 238 239 if (this->bHasTargetPosition_) 240 this->moveToTargetPosition(); 241 242 } 243 244 if (this->state_ == FREE) 245 { 246 if (this->target_) 247 this->aimAtTarget(); 248 249 if (this->bHasTargetPosition_) 250 this->moveToTargetPosition(); 251 252 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 253 this->getControllableEntity()->fire(0); 254 } 112 255 113 256 SUPER(AIController, tick, dt); -
code/branches/presentation3/src/orxonox/controllers/ArtificialController.cc
r7031 r7034 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 29 29 #include "ArtificialController.h" 30 30 31 #include <vector> 31 32 #include "core/CoreIncludes.h" 33 #include "core/XMLPort.h" 32 34 #include "worldentities/ControllableEntity.h" 33 35 #include "worldentities/pawns/Pawn.h" … … 36 38 #include "gametypes/Dynamicmatch.h" 37 39 #include "controllers/WaypointPatrolController.h" 40 #include "controllers/NewHumanController.h" 41 #include "controllers/DroneController.h" 42 #include "util/Math.h" 43 #include "core/ConsoleCommand.h" 38 44 39 45 namespace orxonox 40 46 { 47 SetConsoleCommand(ArtificialController, formationflight, true); 48 SetConsoleCommand(ArtificialController, masteraction, true); 49 SetConsoleCommand(ArtificialController, followme, true); 50 SetConsoleCommand(ArtificialController, passivebehaviour, true); 51 SetConsoleCommand(ArtificialController, formationsize, true); 52 53 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7; 54 static const int FORMATION_LENGTH = 130; 55 static const int FORMATION_WIDTH = 110; 56 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 57 static const float SPEED_MASTER = 0.6f; 58 static const float ROTATEFACTOR_MASTER = 0.2f; 59 static const float SPEED_FREE = 0.8f; 60 static const float ROTATEFACTOR_FREE = 0.8f; 61 static const int SECONDS_TO_FOLLOW_HUMAN = 100; 62 41 63 ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator) 42 64 { … … 44 66 45 67 this->target_ = 0; 68 this->formationFlight_ = true; 69 this->passive_ = false; 70 this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE; 71 this->myMaster_ = 0; 72 this->freedomCount_ = 0; 73 this->team_ = -1; 74 this->state_ = FREE; 75 this->specificMasterAction_ = NONE; 76 this->specificMasterActionHoldCount_ = 0; 46 77 this->bShooting_ = false; 47 78 this->bHasTargetPosition_ = false; 48 79 this->targetPosition_ = Vector3::ZERO; 80 this->humanToFollow_ = NULL; 49 81 50 82 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); … … 54 86 { 55 87 } 88 89 void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 90 { 91 SUPER(ArtificialController, XMLPort, xmlelement, mode); 92 93 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1); 94 XMLPortParam(ArtificialController, "formationflight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true); 95 XMLPortParam(ArtificialController, "formation_size", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE); 96 } 97 98 // Documentation only here to get a faster overview for creating a useful documentation... 99 100 /** 101 @brief Activates / deactivates formationflight behaviour 102 @param form activate formflight if form is true 103 */ 104 void ArtificialController::formationflight(bool form) 105 { 106 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 107 { 108 if (!it->getController()) 109 continue; 110 111 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 112 113 if(aiController) 114 { 115 aiController->formationFlight_ = form; 116 if(!form) 117 { 118 if(aiController->state_ == MASTER) aiController->freeSlaves(); 119 aiController->state_ = FREE; 120 } 121 } 122 } 123 } 124 125 /** 126 @brief Get all masters to do a "specific master action" 127 @param action which action to perform (integer, so it can be called with a console command (tmp solution)) 128 */ 129 void ArtificialController::masteraction(int action) 130 { 131 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 132 { 133 if (!it->getController()) 134 continue; 135 136 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 137 138 if(aiController && aiController->state_ == MASTER) 139 { 140 if (action == 1) 141 aiController->spinInit(); 142 if (action == 2) 143 aiController->turn180Init(); 144 } 145 } 146 } 147 148 /** 149 @brief A human player gets followed by its nearest master. Initiated by console command, intended for demonstration puproses. Does not work at the moment. 150 */ 151 void ArtificialController::followme() 152 { 153 154 Pawn *humanPawn = NULL; 155 NewHumanController *currentHumanController = NULL; 156 std::vector<ArtificialController*> allMasters; 157 158 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 159 { 160 if (!it->getController()) 161 continue; 162 163 currentHumanController = orxonox_cast<NewHumanController*>(it->getController()); 164 165 if(currentHumanController) humanPawn = *it; 166 167 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 168 169 if(aiController || aiController->state_ == MASTER) 170 allMasters.push_back(aiController); 171 172 } 173 174 if((humanPawn != NULL) && (allMasters.size() != 0)) 175 { 176 float posHuman = humanPawn->getPosition().length(); 177 float distance = 0.0f; 178 float minDistance = FLT_MAX; 179 int index = 0; 180 int i = 0; 181 182 for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++) 183 { 184 distance = posHuman - (*it)->getControllableEntity()->getPosition().length(); 185 if(distance < minDistance) index = i; 186 } 187 allMasters[index]->humanToFollow_ = humanPawn; 188 // allMasters[index]->followHuman(humanPawn, false); 189 } 190 191 } 192 193 /** 194 @brief Sets shooting behaviour of pawns. 195 @param passive if true, bots won't shoot. 196 */ 197 void ArtificialController::passivebehaviour(bool passive) 198 { 199 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 200 { 201 if (!it->getController()) 202 continue; 203 204 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 205 206 if(aiController) 207 { 208 aiController->passive_ = passive; 209 } 210 } 211 } 212 213 214 /** 215 @brief Sets maximal formation size 216 @param size maximal formation size. 217 */ 218 void ArtificialController::formationsize(int size) 219 { 220 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 221 { 222 if (!it->getController()) 223 continue; 224 225 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 226 227 if(aiController) 228 { 229 aiController->maxFormationSize_ = size; 230 } 231 } 232 } 233 234 /** 235 @brief Gets called when ControllableEntity is being changed. Resets the bot when it dies. 236 */ 237 void ArtificialController::changedControllableEntity() 238 { 239 if(!getControllableEntity()) 240 { 241 if (this->state_ == SLAVE) unregisterSlave(); 242 if (this->state_ == MASTER) setNewMasterWithinFormation(); 243 this->slaves_.clear(); 244 this->state_ = FREE; 245 246 } 247 } 248 56 249 57 250 void ArtificialController::moveToPosition(const Vector3& target) … … 63 256 float distance = (target - this->getControllableEntity()->getPosition()).length(); 64 257 65 if (this->target_ || distance > 10) 66 { 67 // Multiply with 0.8 to make them a bit slower 68 this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x); 69 this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 70 } 71 72 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 73 this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance 74 else 75 this->getControllableEntity()->moveFrontBack(0.8f); 258 259 if(this->state_ == FREE) 260 { 261 if (this->target_ || distance > 10) 262 { 263 // Multiply with 0.8 to make them a bit slower 264 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x); 265 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y); 266 } 267 268 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 269 { 270 this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance 271 } else this->getControllableEntity()->moveFrontBack(SPEED_FREE); 272 } 273 274 275 276 if(this->state_ == MASTER) 277 { 278 if (this->target_ || distance > 10) 279 { 280 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 281 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 282 } 283 284 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 285 { 286 this->getControllableEntity()->moveFrontBack(-0.05f); 287 } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 288 } 289 290 291 292 if(this->state_ == SLAVE) 293 { 294 295 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 296 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 297 298 if (distance < 300) 299 { 300 if (distance < 40) 301 { 302 this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER); 303 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 304 305 } else { 306 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f); 307 } 308 } 76 309 } 77 310 … … 80 313 this->moveToPosition(this->targetPosition_); 81 314 } 315 316 int ArtificialController::getState() 317 { 318 return this->state_; 319 } 320 321 /** 322 @brief Unregisters a slave from its master. Called by a slave. 323 */ 324 void ArtificialController::unregisterSlave() { 325 if(myMaster_) 326 { 327 std::vector<ArtificialController*>::iterator it = std::find(myMaster_->slaves_.begin(), myMaster_->slaves_.end(), this); 328 if( it != myMaster_->slaves_.end() ) 329 myMaster_->slaves_.erase(it); 330 } 331 } 332 333 void ArtificialController::searchNewMaster() 334 { 335 336 if (!this->getControllableEntity()) 337 return; 338 339 this->targetPosition_ = this->getControllableEntity()->getPosition(); 340 this->forgetTarget(); 341 int teamSize = 0; 342 //go through all pawns 343 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 344 { 345 346 //same team? 347 if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 348 continue; 349 350 //has it an ArtificialController? 351 if (!it->getController()) 352 continue; 353 354 //is pawn oneself? 355 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 356 continue; 357 358 teamSize++; 359 360 ArtificialController *newMaster = orxonox_cast<ArtificialController*>(it->getController()); 361 362 //is it a master? 363 if (!newMaster || newMaster->getState() != MASTER) 364 continue; 365 366 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 367 368 // is pawn in range? 369 if (distance < 5000) 370 { 371 if(newMaster->slaves_.size() > this->maxFormationSize_) continue; 372 373 for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++) 374 { 375 (*itSlave)->myMaster_ = newMaster; 376 newMaster->slaves_.push_back(*itSlave); 377 } 378 this->slaves_.clear(); 379 this->state_ = SLAVE; 380 381 this->myMaster_ = newMaster; 382 newMaster->slaves_.push_back(this); 383 384 break; 385 } 386 } 387 388 if (state_ != SLAVE && teamSize != 0) state_ = MASTER; 389 390 } 391 392 /** 393 @brief Commands the slaves of a master into a formation. Called by a master. 394 */ 395 void ArtificialController::commandSlaves() 396 { 397 if(this->state_ != MASTER) return; 398 399 Quaternion orient = this->getControllableEntity()->getOrientation(); 400 Vector3 dest = this->getControllableEntity()->getPosition(); 401 402 // 1 slave: follow 403 if (this->slaves_.size() == 1) 404 { 405 dest += 4*orient*WorldEntity::BACK; 406 this->slaves_.front()->setTargetPosition(dest); 407 } 408 else 409 { 410 dest += 1.0f*orient*WorldEntity::BACK; 411 Vector3 pos = Vector3::ZERO; 412 int i = 1; 413 414 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 415 { 416 pos = Vector3::ZERO; 417 if (i <= 1) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::LEFT); 418 if (i == 2) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::RIGHT); 419 if (i == 3) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::UP); 420 if (i >= 4) 421 { 422 pos += dest + FORMATION_WIDTH*(orient*WorldEntity::DOWN); 423 i = 1; 424 dest += FORMATION_LENGTH*(orient*WorldEntity::BACK); 425 (*it)->setTargetPosition(pos); 426 continue; 427 } 428 i++; 429 (*it)->setTargetPosition(pos); 430 } 431 } 432 } 433 434 /** 435 @brief Sets a new master within the formation. Called by a master. 436 */ 437 void ArtificialController::setNewMasterWithinFormation() 438 { 439 if(this->state_ != MASTER) return; 440 441 if (this->slaves_.empty()) 442 return; 443 444 ArtificialController *newMaster = this->slaves_.back(); 445 this->slaves_.pop_back(); 446 447 if(!newMaster) return; 448 newMaster->state_ = MASTER; 449 newMaster->slaves_ = this->slaves_; 450 451 this->slaves_.clear(); 452 this->state_ = SLAVE; 453 this->myMaster_ = newMaster; 454 455 for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++) 456 { 457 (*it)->myMaster_ = newMaster; 458 } 459 460 } 461 462 /** 463 @brief Frees all slaves form a master. Called by a master. 464 */ 465 void ArtificialController::freeSlaves() 466 { 467 if(this->state_ != MASTER) return; 468 469 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 470 { 471 (*it)->state_ = FREE; 472 } 473 this->slaves_.clear(); 474 } 475 476 /** 477 @brief Master sets its slaves free for @var FREEDOM_COUNT seconds. 478 */ 479 void ArtificialController::forceFreeSlaves() 480 { 481 if(this->state_ != MASTER) return; 482 483 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 484 { 485 (*it)->state_ = FREE; 486 (*it)->forceFreedom(); 487 (*it)->targetPosition_ = this->targetPosition_; 488 (*it)->bShooting_ = true; 489 // (*it)->getControllableEntity()->fire(0);// fire once for fun 490 } 491 } 492 493 void ArtificialController::loseMasterState() 494 { 495 this->freeSlaves(); 496 this->state_ = FREE; 497 } 498 499 500 void ArtificialController::forceFreedom() 501 { 502 this->freedomCount_ = FREEDOM_COUNT; 503 } 504 505 /** 506 @brief Checks wether caller has been forced free, decrements time to stay forced free. 507 @return true if forced free. 508 */ 509 bool ArtificialController::forcedFree() 510 { 511 if(this->freedomCount_ > 0) 512 { 513 this->freedomCount_--; 514 return true; 515 } else return false; 516 } 517 518 /** 519 @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after. 520 */ 521 void ArtificialController::specificMasterActionHold() 522 { 523 if(this->state_ != MASTER) return; 524 525 if (specificMasterActionHoldCount_ == 0) 526 { 527 this->specificMasterAction_ = NONE; 528 this->searchNewTarget(); 529 } 530 else specificMasterActionHoldCount_--; 531 } 532 533 /** 534 @brief Master initializes a 180 degree turn. Leads to a "specific master action". 535 */ 536 void ArtificialController::turn180Init() 537 { 538 COUT(0) << "~turnInit" << std::endl; 539 if(this->state_ != MASTER) return; 540 541 Quaternion orient = this->getControllableEntity()->getOrientation(); 542 543 this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK); 544 545 this->specificMasterActionHoldCount_ = 4; 546 547 this->specificMasterAction_ = TURN180; 548 } 549 550 /** 551 @brief Execute the 180 degree turn. Called within tick. 552 */ 553 void ArtificialController::turn180() 554 { 555 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_); 556 557 this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x); 558 this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y); 559 560 this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 561 } 562 563 /** 564 @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action". Not yet implemented. 565 */ 566 void ArtificialController::spinInit() 567 { 568 COUT(0) << "~spinInit" << std::endl; 569 if(this->state_ != MASTER) return; 570 this->specificMasterAction_ = SPIN; 571 this->specificMasterActionHoldCount_ = 10; 572 } 573 574 /** 575 @brief Execute the spin. Called within tick. 576 */ 577 void ArtificialController::spin() 578 { 579 this->moveToTargetPosition(); 580 this->getControllableEntity()->rotateRoll(0.8f); 581 } 582 583 /** 584 @brief Master begins to follow a human player. Is a "specific master action". 585 @param humanController human to follow. 586 @param alaways follows human forever if true, else it follows it for @var SECONDS_TO_FOLLOW_HUMAN seconds. 587 */ 588 void ArtificialController::followHumanInit(Pawn* human, bool always) 589 { 590 COUT(0) << "~followInit" << std::endl; 591 if (human == NULL || this->state_ != MASTER) 592 return; 593 594 this->specificMasterAction_ = FOLLOWHUMAN; 595 596 this->setTarget(human); 597 if (!always) 598 this->specificMasterActionHoldCount_ = SECONDS_TO_FOLLOW_HUMAN; 599 else 600 this->specificMasterActionHoldCount_ = INT_MAX; //for now... 601 602 } 603 604 /** 605 @brief Follows target with adjusted speed. Called within tick. 606 */ 607 void ArtificialController::follow() 608 { 609 this->moveToTargetPosition(); //standard position apprach for now. 610 } 611 612 82 613 83 614 void ArtificialController::setTargetPosition(const Vector3& target) … … 145 676 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 146 677 147 Pawn* pawn = dynamic_cast<Pawn*>(this->getControllableEntity());678 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 148 679 if (pawn) 149 680 pawn->setAimPosition(this->targetPosition_); … … 189 720 int team2 = -1; 190 721 191 if (entity1->getXMLController()) 192 { 193 WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity1->getXMLController()); 194 if (wpc) 195 team1 = wpc->getTeam(); 196 } 197 if (entity2->getXMLController()) 198 { 199 WaypointPatrolController* wpc = orxonox_cast<WaypointPatrolController*>(entity2->getXMLController()); 200 if (wpc) 201 team2 = wpc->getTeam(); 722 Controller* controller = 0; 723 if (entity1->getController()) 724 controller = entity1->getController(); 725 else 726 controller = entity1->getXMLController(); 727 if (controller) 728 { 729 ArtificialController* ac = orxonox_cast<ArtificialController*>(controller); 730 if (ac) 731 team1 = ac->getTeam(); 732 } 733 734 if (entity1->getController()) 735 controller = entity1->getController(); 736 else 737 controller = entity1->getXMLController(); 738 if (controller) 739 { 740 ArtificialController* ac = orxonox_cast<ArtificialController*>(controller); 741 if (ac) 742 team2 = ac->getTeam(); 202 743 } 203 744 … … 246 787 } 247 788 789 DroneController* droneController = 0; 790 droneController = orxonox_cast<DroneController*>(entity1->getController()); 791 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2) 792 return true; 793 droneController = orxonox_cast<DroneController*>(entity2->getController()); 794 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1) 795 return true; 796 DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController()); 797 DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController()); 798 if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner()) 799 return true; 800 248 801 Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype); 249 802 if (dynamic) -
code/branches/presentation3/src/orxonox/controllers/ArtificialController.h
r6417 r7034 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include <vector> 35 34 36 #include "util/Math.h" 35 37 #include "Controller.h" 38 #include "controllers/NewHumanController.h" 36 39 37 40 namespace orxonox … … 43 46 virtual ~ArtificialController(); 44 47 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 45 50 void abandonTarget(Pawn* target); 46 51 52 inline void setTeam(int team) 53 { this->team_ = team; } 54 inline int getTeam() const 55 { return this->team_; } 56 inline void setFormationFlight(bool formation) 57 { this->formationFlight_ = formation; } 58 inline bool getFormationFlight() const 59 { return this->formationFlight_; } 60 inline void setFormationSize(int size) 61 { this->maxFormationSize_ = size; } 62 inline int getFormationSize() const 63 { return this->maxFormationSize_; } 64 virtual void changedControllableEntity(); 65 66 static void formationflight(bool form); 67 static void masteraction(int action); 68 static void followme(); 69 static void passivebehaviour(bool passive); 70 static void formationsize(int size); 71 47 72 protected: 73 74 int team_; 75 bool formationFlight_; 76 bool passive_; 77 unsigned int maxFormationSize_; 78 int freedomCount_; 79 enum State {SLAVE, MASTER, FREE}; 80 State state_; 81 std::vector<ArtificialController*> slaves_; 82 ArtificialController *myMaster_; 83 enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOWHUMAN}; 84 SpecificMasterAction specificMasterAction_; 85 int specificMasterActionHoldCount_; 86 Pawn* humanToFollow_; 87 48 88 void targetDied(); 49 89 50 90 void moveToPosition(const Vector3& target); 51 91 void moveToTargetPosition(); 92 93 int getState(); 94 95 void unregisterSlave(); 96 void searchNewMaster(); 97 void commandSlaves(); 98 void setNewMasterWithinFormation(); 99 100 void freeSlaves(); 101 void forceFreeSlaves(); 102 void loseMasterState(); 103 void forceFreedom(); 104 bool forcedFree(); 105 106 void specificMasterActionHold(); 107 void turn180Init(); 108 void turn180(); 109 void spinInit(); 110 void spin(); 111 void followHumanInit(Pawn* human, bool always); 112 void follow(); 52 113 53 114 void setTargetPosition(const Vector3& target); -
code/branches/presentation3/src/orxonox/controllers/CMakeLists.txt
r6957 r7034 8 8 WaypointController.cc 9 9 WaypointPatrolController.cc 10 DroneController.cc 10 11 ) -
code/branches/presentation3/src/orxonox/controllers/DroneController.cc
- Property svn:eol-style set to native
-
code/branches/presentation3/src/orxonox/controllers/DroneController.h
- Property svn:eol-style set to native
-
code/branches/presentation3/src/orxonox/controllers/WaypointPatrolController.cc
r6502 r7034 42 42 RegisterObject(WaypointPatrolController); 43 43 44 this->team_ = 0;44 //this->team_ = 0; 45 45 this->alertnessradius_ = 500; 46 46 … … 53 53 54 54 XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f); 55 XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);55 // XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0); 56 56 } 57 57 -
code/branches/presentation3/src/orxonox/controllers/WaypointPatrolController.h
r5929 r7034 46 46 virtual void tick(float dt); 47 47 48 inline void setTeam(int team)48 /* inline void setTeam(int team) 49 49 { this->team_ = team; } 50 50 inline int getTeam() const 51 { return this->team_; } 51 { return this->team_; } */ 52 52 53 53 inline void setAlertnessRadius(float radius) … … 59 59 void searchEnemy(); 60 60 61 int team_;61 //int team_; 62 62 float alertnessradius_; 63 63 Timer patrolTimer_; -
code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h
r6965 r7034 54 54 class InvisiblePickup; 55 55 class MetaPickup; 56 class DronePickup; 56 57 class SpeedPickup; 57 58 … … 72 73 friend class InvisiblePickup; 73 74 friend class MetaPickup; 75 friend class DronePickup; 74 76 friend class SpeedPickup; 75 77 -
code/branches/presentation3/src/orxonox/worldentities/CMakeLists.txt
r6957 r7034 5 5 MobileEntity.cc 6 6 ControllableEntity.cc 7 7 Drone.cc 8 8 BigExplosion.cc 9 9 EffectContainer.cc -
code/branches/presentation3/src/orxonox/worldentities/Drone.cc
- Property svn:eol-style set to native
-
code/branches/presentation3/src/orxonox/worldentities/Drone.h
- Property svn:eol-style set to native
Note: See TracChangeset
for help on using the changeset viewer.