Changeset 11071 for code/trunk/src/orxonox/controllers
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/controllers/AIController.cc
r9667 r11071 249 249 } 250 250 else 251 this->setPreviousMode();//If bot dies -> getControllableEntity == NULL-> get out of ROCKET mode251 this->setPreviousMode();//If bot dies -> getControllableEntity == nullptr -> get out of ROCKET mode 252 252 }//END_OF ROCKET MODE 253 253 -
code/trunk/src/orxonox/controllers/AIController.h
r9667 r11071 44 44 virtual ~AIController(); 45 45 46 virtual void tick(float dt) ; //<! Carrying out the targets set in action().46 virtual void tick(float dt) override; //<! Carrying out the targets set in action(). 47 47 48 48 protected: -
code/trunk/src/orxonox/controllers/ActionpointController.cc
r11052 r11071 339 339 inLoop = this->bInLoop_; 340 340 341 Action ::Valuevalue;341 Action value; 342 342 343 343 if ( actionName == "FIGHT" ) … … 371 371 return this->actionpoints_[index]; 372 372 else 373 return 0;373 return nullptr; 374 374 } 375 375 //XML method 376 Action ::ValueActionpointController::getAction ()376 Action ActionpointController::getAction () 377 377 { 378 378 return this->action_; … … 401 401 } 402 402 //XML method 403 void ActionpointController::setAction (Action ::Valueaction)403 void ActionpointController::setAction (Action action) 404 404 { 405 405 this->action_ = action; 406 406 } 407 407 //set action and target/protect 408 void ActionpointController::setAction (Action ::Valueaction, ControllableEntity* target)408 void ActionpointController::setAction (Action action, ControllableEntity* target) 409 409 { 410 410 if (!this || !this->getControllableEntity()) … … 423 423 } 424 424 //set action and target position 425 void ActionpointController::setAction (Action ::Valueaction, const Vector3& target)425 void ActionpointController::setAction (Action action, const Vector3& target) 426 426 { 427 427 if (!this || !this->getControllableEntity()) … … 434 434 } 435 435 //set action and target position and orientation 436 void ActionpointController::setAction (Action ::Valueaction, const Vector3& target, const Quaternion& orient )436 void ActionpointController::setAction (Action action, const Vector3& target, const Quaternion& orient ) 437 437 { 438 438 if (!this || !this->getControllableEntity()) … … 476 476 return; 477 477 478 this->setTarget( 0);478 this->setTarget(nullptr); 479 479 this->setTargetPosition(this->getControllableEntity()->getWorldPosition()); 480 480 this->action_ = Action::NONE; … … 506 506 if (targetName == "") 507 507 break; 508 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)509 { 510 if (!this || !this->getControllableEntity()) 511 return; 512 if (CommonController::getName( *itP) == targetName)508 for (Pawn* pawn : ObjectList<Pawn>()) 509 { 510 if (!this || !this->getControllableEntity()) 511 return; 512 if (CommonController::getName(pawn) == targetName) 513 513 { 514 this->setTarget (static_cast<ControllableEntity*>( *itP));514 this->setTarget (static_cast<ControllableEntity*>(pawn)); 515 515 } 516 516 } … … 541 541 if (protectName == "reservedKeyword:human") 542 542 { 543 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)543 for (Pawn* pawn : ObjectList<Pawn>()) 544 544 { 545 if (orxonox_cast<ControllableEntity*>( *itP) && ((*itP)->getController()) && ((*itP)->getController()->getIdentifier()->getName() == "NewHumanController"))545 if (orxonox_cast<ControllableEntity*>(pawn) && (pawn->getController()) && (pawn->getController()->getIdentifier()->getName() == "NewHumanController")) 546 546 { 547 this->setProtect (static_cast<ControllableEntity*>( *itP));547 this->setProtect (static_cast<ControllableEntity*>(pawn)); 548 548 } 549 549 } … … 551 551 else 552 552 { 553 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)553 for (Pawn* pawn : ObjectList<Pawn>()) 554 554 { 555 if (CommonController::getName( *itP) == protectName)555 if (CommonController::getName(pawn) == protectName) 556 556 { 557 this->setProtect (static_cast<ControllableEntity*>( *itP));557 this->setProtect (static_cast<ControllableEntity*>(pawn)); 558 558 } 559 559 } … … 578 578 std::string targetName = p.name; 579 579 580 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)581 { 582 if (CommonController::getName( *itP) == targetName)580 for (Pawn* pawn : ObjectList<Pawn>()) 581 { 582 if (CommonController::getName(pawn) == targetName) 583 583 { 584 584 if (!this || !this->getControllableEntity()) 585 585 return; 586 this->setTarget (static_cast<ControllableEntity*>( *itP));586 this->setTarget (static_cast<ControllableEntity*>(pawn)); 587 587 } 588 588 } … … 702 702 { 703 703 if (!this || !this->getControllableEntity()) 704 return 0;705 706 Pawn* closestTarget = 0;704 return nullptr; 705 706 Pawn* closestTarget = nullptr; 707 707 float minDistance = std::numeric_limits<float>::infinity(); 708 708 Gametype* gt = this->getGametype(); 709 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)709 for (Pawn* pawn : ObjectList<Pawn>()) 710 710 { 711 711 if (!this || !this->getControllableEntity()) 712 return 0;713 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>( *itP), gt) )712 return nullptr; 713 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), gt) ) 714 714 continue; 715 715 716 float distance = CommonController::distance ( *itP, this->getControllableEntity());716 float distance = CommonController::distance (pawn, this->getControllableEntity()); 717 717 if (distance < minDistance) 718 718 { 719 closestTarget = *itP;719 closestTarget = pawn; 720 720 minDistance = distance; 721 721 } … … 725 725 return closestTarget; 726 726 } 727 return 0;727 return nullptr; 728 728 } 729 729 //push action FIGHT to the stack and set target to the closest enemy -
code/trunk/src/orxonox/controllers/ActionpointController.h
r11052 r11071 65 65 All the demos are in a file called AITest.oxw. In the menu look for New AI Testing Level. 66 66 */ 67 namespaceAction67 enum class Action 68 68 { 69 enum Value 70 { 71 NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK 72 }; 73 74 } 69 NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK 70 }; 75 71 76 72 struct Point { 77 Action ::Valueaction;73 Action action; 78 74 std::string name; 79 75 Vector3 position; 80 76 bool inLoop; 81 } ; 82 namespace PickupType 83 { 84 enum Value 85 { 86 NONE, DAMAGE, HEALTH, SPEED, PORTAL 87 }; 88 } 77 }; 89 78 90 79 class _OrxonoxExport ActionpointController : public FightingController, public Tickable … … 94 83 ActionpointController(Context* context); 95 84 virtual ~ActionpointController(); 96 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;85 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 97 86 98 87 /** … … 101 90 In tick ship flies and fires. 102 91 */ 103 virtual void tick(float dt) ;92 virtual void tick(float dt) override; 104 93 /** 105 94 @brief … … 186 175 virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b); 187 176 188 virtual Action ::ValuegetAction ();177 virtual Action getAction (); 189 178 virtual std::string getActionName(); 190 179 191 void setAction (Action ::Valueaction);192 void setAction (Action ::Valueaction, ControllableEntity* target);193 void setAction (Action ::Valueaction, const Vector3& target);194 void setAction (Action ::Valueaction, const Vector3& target, const Quaternion& orient );180 void setAction (Action action); 181 void setAction (Action action, ControllableEntity* target); 182 void setAction (Action action, const Vector3& target); 183 void setAction (Action action, const Vector3& target, const Quaternion& orient ); 195 184 196 185 virtual bool setWingman(ActionpointController* wingman) … … 210 199 WeakPtr<ActionpointController> myDivisionLeader_; 211 200 //----[Actionpoint information]---- 212 Action ::Valueaction_;201 Action action_; 213 202 std::string protectName_; 214 203 std::string targetName_; 215 std::vector<WeakPtr<WorldEntity> 204 std::vector<WeakPtr<WorldEntity>> actionpoints_; 216 205 float squaredaccuracy_; 217 std::vector<Point > parsedActionpoints_;//<! actionpoints as they are stored here after being parsed from XML218 std::vector<Point > loopActionpoints_;//<! actionpoints that are to be looped206 std::vector<Point> parsedActionpoints_; //<! actionpoints as they are stored here after being parsed from XML 207 std::vector<Point> loopActionpoints_; //<! actionpoints that are to be looped 219 208 bool bInLoop_; //<! variable for addActionpoint method 220 209 bool bLoop_; //<! is state machine looping? -
code/trunk/src/orxonox/controllers/ArtificialController.cc
r11052 r11071 56 56 this->currentWaypoint_ = 0; 57 57 this->setAccuracy(5); 58 this->defaultWaypoint_ = NULL;58 this->defaultWaypoint_ = nullptr; 59 59 this->mode_ = DEFAULT;//Vector-implementation: mode_.push_back(DEFAULT); 60 60 } … … 177 177 { 178 178 this->weaponModes_.clear(); // reset previous weapon information 179 WeaponSlot* wSlot = 0;179 WeaponSlot* wSlot = nullptr; 180 180 for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++) 181 181 { 182 WeaponMode* wMode = 0;182 WeaponMode* wMode = nullptr; 183 183 for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++) 184 184 { … … 207 207 void ArtificialController::setAllBotLevel(float level) 208 208 { 209 for ( ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it != ObjectList<ArtificialController>::end(); ++it)210 it->setBotLevel(level);209 for (ArtificialController* controller : ObjectList<ArtificialController>()) 210 controller->setBotLevel(level); 211 211 } 212 212 … … 222 222 { 223 223 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 224 if(ship == NULL) return;224 if(ship == nullptr) return; 225 225 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost 226 226 this->getControllableEntity()->boost(true); … … 231 231 int ArtificialController::getFiremode(std::string name) 232 232 { 233 for ( std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)234 { 235 if ( it->first == name)236 return it->second;233 for (const auto& mapEntry : this->weaponModes_) 234 { 235 if (mapEntry.first == name) 236 return mapEntry.second; 237 237 } 238 238 return -1; … … 249 249 return this->waypoints_[index]; 250 250 else 251 return 0;251 return nullptr; 252 252 } 253 253 … … 258 258 void ArtificialController::updatePointsOfInterest(std::string name, float searchDistance) 259 259 { 260 WorldEntity* waypoint = NULL;261 for ( ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it)262 { 263 if( (*it)->getIdentifier() == ClassByString(name))260 WorldEntity* waypoint = nullptr; 261 for (WorldEntity* we : ObjectList<WorldEntity>()) 262 { 263 if(we->getIdentifier() == ClassByString(name)) 264 264 { 265 265 ControllableEntity* controllable = this->getControllableEntity(); 266 266 if(!controllable) continue; 267 float actualDistance = ( (*it)->getPosition() - controllable->getPosition() ).length();267 float actualDistance = ( we->getPosition() - controllable->getPosition() ).length(); 268 268 if(actualDistance > searchDistance || actualDistance < 5.0f) continue; 269 269 // TODO: PickupSpawner: adjust waypoint accuracy to PickupSpawner's triggerdistance … … 271 271 else 272 272 { 273 waypoint = *it;273 waypoint = we; 274 274 break; 275 275 } -
code/trunk/src/orxonox/controllers/ArtificialController.h
r9667 r11071 42 42 virtual ~ArtificialController(); 43 43 44 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;44 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 45 45 46 46 void abandonTarget(Pawn* target); 47 47 48 virtual void changedControllableEntity() ;48 virtual void changedControllableEntity() override; 49 49 50 50 virtual void doFire(); … … 89 89 90 90 //WAYPOINT DATA 91 std::vector<WeakPtr<WorldEntity> 91 std::vector<WeakPtr<WorldEntity>> waypoints_; 92 92 size_t currentWaypoint_; 93 93 float squaredaccuracy_; -
code/trunk/src/orxonox/controllers/CommonController.cc
r11052 r11071 83 83 int team2 = entity2->getTeam(); 84 84 85 Controller* controller = 0;85 Controller* controller = nullptr; 86 86 if (entity1->getController()) 87 87 controller = entity1->getController(); … … 120 120 } 121 121 122 TeamBaseMatchBase* base = 0;122 TeamBaseMatchBase* base = nullptr; 123 123 base = orxonox_cast<TeamBaseMatchBase*>(entity1); 124 124 if (base) … … 154 154 } 155 155 156 DroneController* droneController = 0;156 DroneController* droneController = nullptr; 157 157 droneController = orxonox_cast<DroneController*>(entity1->getController()); 158 158 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2) -
code/trunk/src/orxonox/controllers/Controller.cc
r9797 r11071 40 40 RegisterObject(Controller); 41 41 42 this->player_ = 0;43 this->controllableEntity_ = 0;42 this->player_ = nullptr; 43 this->controllableEntity_ = nullptr; 44 44 this->bGodMode_ = false; 45 45 this->team_=-1; -
code/trunk/src/orxonox/controllers/Controller.h
r9797 r11071 45 45 Controller(Context* context); 46 46 virtual ~Controller(); 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 48 48 inline void setPlayer(PlayerInfo* player) 49 49 { this->player_ = player; } -
code/trunk/src/orxonox/controllers/ControllerDirector.cc
r10622 r11071 32 32 33 33 // Initialize member variables 34 this->player_ = NULL;35 this->entity_ = NULL;36 this->pTrigger_ = NULL;34 this->player_ = nullptr; 35 this->entity_ = nullptr; 36 this->pTrigger_ = nullptr; 37 37 this->context_ = context; 38 38 } … … 110 110 { 111 111 this->pTrigger_ = orxonox_cast<PlayerTrigger*>(trigger); 112 this->player_ = NULL;112 this->player_ = nullptr; 113 113 114 114 orxout(verbose) << "Preparation to take Control!" << endl; 115 115 116 116 // Check whether it is a player trigger and extract pawn from it 117 if(this->pTrigger_ != NULL)117 if(this->pTrigger_ != nullptr) 118 118 { 119 119 // Get the object which triggered the event. … … 121 121 122 122 // Check if there actually was a player returned. 123 if( this->player_ == NULL) return false;123 if( this->player_ == nullptr) return false; 124 124 } 125 125 else -
code/trunk/src/orxonox/controllers/ControllerDirector.h
r10622 r11071 43 43 virtual ~ControllerDirector() { } 44 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 46 46 bool party(bool bTriggered, BaseObject* trigger); 47 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) ;47 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override; 48 48 49 49 inline void setScriptName(const std::string& name) { this->scriptname_ = name; } -
code/trunk/src/orxonox/controllers/DivisionController.cc
r11052 r11071 40 40 RegisterObject(DivisionController); 41 41 this->setFormationMode(FormationMode::DIAMOND); 42 this->target_ = 0;43 this->myFollower_ = 0;44 this->myWingman_ = 0;42 this->target_ = nullptr; 43 this->myFollower_ = nullptr; 44 this->myWingman_ = nullptr; 45 45 } 46 46 47 47 DivisionController::~DivisionController() 48 48 { 49 for ( size_t i = 0; i < this->actionpoints_.size(); ++i)49 for (WorldEntity* actionpoint : this->actionpoints_) 50 50 { 51 if (this->actionpoints_[i])52 this->actionpoints_[i]->destroy();51 if (actionpoint) 52 actionpoint->destroy(); 53 53 } 54 54 this->parsedActionpoints_.clear(); 55 55 this->actionpoints_.clear(); 56 56 } 57 58 void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)59 {60 SUPER(DivisionController, XMLPort, xmlelement, mode);61 62 }63 void DivisionController::tick(float dt)64 {65 if (!this->isActive())66 return;67 68 SUPER(DivisionController, tick, dt);69 70 }71 57 void DivisionController::action() 72 58 { -
code/trunk/src/orxonox/controllers/DivisionController.h
r11052 r11071 50 50 //----[/language demanded functions]---- 51 51 52 //----[orxonox demanded functions]----53 virtual void tick(float dt);54 55 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);56 //----[orxonox demanded functions]----57 58 52 //----[own functions]---- 59 virtual bool setFollower(ActionpointController* newFollower) ;60 virtual bool setWingman(ActionpointController* newWingman) ;61 virtual bool hasWingman() ;62 virtual bool hasFollower() ;53 virtual bool setFollower(ActionpointController* newFollower) override; 54 virtual bool setWingman(ActionpointController* newWingman) override; 55 virtual bool hasWingman() override; 56 virtual bool hasFollower() override; 63 57 64 58 //----[/own functions]---- 65 virtual void stayNearProtect() ;59 virtual void stayNearProtect() override; 66 60 67 61 protected: 68 62 //----action must only be managed by this---- 69 virtual void action() ; //<! action() is called in regular intervals managing the bot's behaviour.63 virtual void action() override; //<! action() is called in regular intervals managing the bot's behaviour. 70 64 71 65 private: -
code/trunk/src/orxonox/controllers/DroneController.cc
r9667 r11071 49 49 RegisterObject(DroneController); 50 50 51 this->owner_ = 0;52 this->drone_ = 0;51 this->owner_ = nullptr; 52 this->drone_ = nullptr; 53 53 this->isShooting_ = false; 54 54 this->setAccuracy(10); -
code/trunk/src/orxonox/controllers/DroneController.h
r9667 r11071 53 53 virtual ~DroneController(); 54 54 55 virtual void tick(float dt) ; //!< The controlling happens here. This method defines what the controller has to do each tick.55 virtual void tick(float dt) override; //!< The controlling happens here. This method defines what the controller has to do each tick. 56 56 57 57 void setOwner(Pawn* owner); -
code/trunk/src/orxonox/controllers/FightingController.cc
r11052 r11071 27 27 */ 28 28 #include "controllers/FightingController.h" 29 #include "core/XMLPort.h"30 29 #include "util/Math.h" 31 30 … … 56 55 { 57 56 58 }59 void FightingController::XMLPort( Element& xmlelement, XMLPort::Mode mode )60 {61 SUPER( FightingController, XMLPort, xmlelement, mode );62 57 } 63 58 void FightingController::lookAtTarget(float dt) … … 243 238 { 244 239 if (!this || !this->getControllableEntity()) 245 return 0;246 247 Pawn* closestTarget = 0;240 return nullptr; 241 242 Pawn* closestTarget = nullptr; 248 243 float minDistance = std::numeric_limits<float>::infinity(); 249 244 Gametype* gt = this->getGametype(); 250 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)251 { 252 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>( *itP), gt) )245 for (Pawn* pawn : ObjectList<Pawn>()) 246 { 247 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), gt) ) 253 248 continue; 254 249 255 float distance = CommonController::distance ( *itP, this->getControllableEntity());250 float distance = CommonController::distance (pawn, this->getControllableEntity()); 256 251 if (distance < minDistance) 257 252 { 258 closestTarget = *itP;253 closestTarget = pawn; 259 254 minDistance = distance; 260 255 } … … 264 259 return closestTarget; 265 260 } 266 return 0;261 return nullptr; 267 262 } 268 263 //I checked it out, rockets DO NOT cause any problems! this->getControllableEntity() is always a SpaceShip … … 340 335 { 341 336 this->weaponModes_.clear(); // reset previous weapon information 342 WeaponSlot* wSlot = 0;337 WeaponSlot* wSlot = nullptr; 343 338 for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++) 344 339 { 345 WeaponMode* wMode = 0;340 WeaponMode* wMode = nullptr; 346 341 for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++) 347 342 { … … 361 356 } 362 357 363 int FightingController::getFiremode( std::stringname)364 { 365 for ( std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)366 { 367 if ( it->first == name)368 return it->second;358 int FightingController::getFiremode(const std::string& name) 359 { 360 for (const auto& mapEntry : this->weaponModes_) 361 { 362 if (mapEntry.first == name) 363 return mapEntry.second; 369 364 } 370 365 return -1; -
code/trunk/src/orxonox/controllers/FightingController.h
r11052 r11071 50 50 virtual ~FightingController(); 51 51 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);53 54 52 float squaredDistanceToTarget() const; 55 53 bool isLookingAtTarget(float angle) const; … … 74 72 //<! this and target_ plus or minus some amount in difference vector direction, 75 73 //<! depending on whether it is better to close up or survive. 76 void dodgeTowards (Vector3& position); //fly towards position and awoid being hit77 74 void doFire(); //<! choose weapon, set aim at target_ and fire 78 75 WeakPtr<ControllableEntity> target_; … … 99 96 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 100 97 bool bSetupWorked; //<! If false, setupWeapons() is called. 101 int getFiremode( std::stringname);98 int getFiremode(const std::string& name); 102 99 103 100 }; -
code/trunk/src/orxonox/controllers/FlyingController.cc
r11052 r11071 61 61 } 62 62 63 void FlyingController::setFormationModeXML( std::stringval)63 void FlyingController::setFormationModeXML(const std::string& val) 64 64 { 65 65 const std::string valUpper = getUppercase(val); 66 FormationMode ::Valuevalue;66 FormationMode value; 67 67 68 68 if (valUpper == "WALL") … … 233 233 return; 234 234 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 235 if(ship == NULL) return;235 if(ship == nullptr) return; 236 236 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower()) //upper limit ->boost 237 237 { -
code/trunk/src/orxonox/controllers/FlyingController.h
r11052 r11071 41 41 42 42 //Formation mode for the divisions 43 namespaceFormationMode43 enum class FormationMode 44 44 { 45 enum Value 46 { 47 FINGER4, DIAMOND, WALL 48 }; 49 } 45 FINGER4, DIAMOND, WALL 46 }; 50 47 51 48 class _OrxonoxExport FlyingController : public CommonController … … 58 55 FlyingController(Context* context); 59 56 virtual ~FlyingController(); 60 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;57 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 61 58 62 59 void setSpread (int spread) //<! spread is a multiplier for formation flight, should be bigger than 100 … … 65 62 { return this->spread_; } 66 63 67 void setFormationModeXML( std::stringval);64 void setFormationModeXML(const std::string& val); 68 65 std::string getFormationModeXML() const; 69 66 70 void setFormationMode(FormationMode ::Valueval)67 void setFormationMode(FormationMode val) 71 68 { this->formationMode_ = val; } 72 FormationMode ::ValuegetFormationMode() const69 FormationMode getFormationMode() const 73 70 { return this->formationMode_; } 74 71 bool bCopyOrientation_; //<! set to true by default, MasterController sets it in its tick(), … … 91 88 //<! this stays in a certain position relative to leader 92 89 93 FormationMode ::ValueformationMode_;90 FormationMode formationMode_; 94 91 95 92 float rotationProgress_; //<! for slerping -
code/trunk/src/orxonox/controllers/FormationController.cc
r11052 r11071 58 58 RegisterClass(FormationController); 59 59 60 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;61 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;62 static const float FORMATION_LENGTH = 110;63 static const float FORMATION_WIDTH = 110;64 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy65 static const float SPEED_MASTER = 0.6f;66 static const float ROTATEFACTOR_MASTER = 0.2f;67 static const float SPEED_FREE = 0.8f;68 static const float ROTATEFACTOR_FREE = 0.8f;60 static constexpr unsigned int STANDARD_MAX_FORMATION_SIZE = 9; 61 static constexpr int RADIUS_TO_SEARCH_FOR_MASTERS = 5000; 62 static constexpr float FORMATION_LENGTH = 110; 63 static constexpr float FORMATION_WIDTH = 110; 64 static constexpr int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 65 static constexpr float SPEED_MASTER = 0.6f; 66 static constexpr float ROTATEFACTOR_MASTER = 0.2f; 67 static constexpr float SPEED_FREE = 0.8f; 68 static constexpr float ROTATEFACTOR_FREE = 0.8f; 69 69 70 70 FormationController::FormationController(Context* context) : Controller(context) … … 72 72 RegisterObject(FormationController); 73 73 74 this->target_ = 0;74 this->target_ = nullptr; 75 75 this->formationFlight_ = false; 76 76 this->passive_ = false; 77 77 this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE; 78 this->myMaster_ = 0;78 this->myMaster_ = nullptr; 79 79 this->freedomCount_ = 0; 80 80 … … 97 97 this->removeFromFormation(); 98 98 99 for ( ObjectList<FormationController>::iterator it = ObjectList<FormationController>::begin(); it; ++it)100 { 101 if ( *it!= this)99 for (FormationController* controller : ObjectList<FormationController>()) 100 { 101 if (controller != this) 102 102 { 103 if ( it->myMaster_ == this)103 if (controller->myMaster_ == this) 104 104 { 105 orxout(internal_error) << this << " is still master in " << (*it)<< endl;106 it->myMaster_ = 0;105 orxout(internal_error) << this << " is still master in " << controller << endl; 106 controller->myMaster_ = nullptr; 107 107 } 108 108 109 109 while (true) 110 110 { 111 std::vector<FormationController*>::iterator it2 = std::find( it->slaves_.begin(), it->slaves_.end(), this);112 if (it2 != it->slaves_.end())111 std::vector<FormationController*>::iterator it2 = std::find(controller->slaves_.begin(), controller->slaves_.end(), this); 112 if (it2 != controller->slaves_.end()) 113 113 { 114 orxout(internal_error) << this << " is still slave in " << (*it)<< endl;115 it->slaves_.erase(it2);114 orxout(internal_error) << this << " is still slave in " << controller << endl; 115 controller->slaves_.erase(it2); 116 116 } 117 117 else … … 140 140 void FormationController::formationflight(const bool form) 141 141 { 142 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)143 { 144 Controller* controller = 0;145 146 if ( it->getController())147 controller = it->getController();148 else if ( it->getXMLController())149 controller = it->getXMLController();142 for (Pawn* pawn : ObjectList<Pawn>()) 143 { 144 Controller* controller = nullptr; 145 146 if (pawn->getController()) 147 controller = pawn->getController(); 148 else if (pawn->getXMLController()) 149 controller = pawn->getXMLController(); 150 150 151 151 if (!controller) … … 171 171 void FormationController::masteraction(const int action) 172 172 { 173 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)174 { 175 Controller* controller = 0;176 177 if ( it->getController())178 controller = it->getController();179 else if ( it->getXMLController())180 controller = it->getXMLController();173 for (Pawn* pawn : ObjectList<Pawn>()) 174 { 175 Controller* controller = nullptr; 176 177 if (pawn->getController()) 178 controller = pawn->getController(); 179 else if (pawn->getXMLController()) 180 controller = pawn->getXMLController(); 181 181 182 182 if (!controller) … … 201 201 void FormationController::passivebehaviour(const bool passive) 202 202 { 203 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)204 { 205 Controller* controller = 0;206 207 if ( it->getController())208 controller = it->getController();209 else if ( it->getXMLController())210 controller = it->getXMLController();203 for (Pawn* pawn : ObjectList<Pawn>()) 204 { 205 Controller* controller = nullptr; 206 207 if (pawn->getController()) 208 controller = pawn->getController(); 209 else if (pawn->getXMLController()) 210 controller = pawn->getXMLController(); 211 211 212 212 if (!controller) … … 228 228 void FormationController::formationsize(const int size) 229 229 { 230 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)231 { 232 Controller* controller = 0;233 234 if ( it->getController())235 controller = it->getController();236 else if ( it->getXMLController())237 controller = it->getXMLController();230 for (Pawn* pawn : ObjectList<Pawn>()) 231 { 232 Controller* controller = nullptr; 233 234 if (pawn->getController()) 235 controller = pawn->getController(); 236 else if (pawn->getXMLController()) 237 controller = pawn->getXMLController(); 238 238 239 239 if (!controller) … … 383 383 } 384 384 385 this->myMaster_ = 0;385 this->myMaster_ = nullptr; 386 386 this->state_ = FREE; 387 387 } … … 398 398 int teamSize = 0; 399 399 //go through all pawns 400 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)400 for (Pawn* pawn : ObjectList<Pawn>()) 401 401 { 402 402 … … 405 405 if (!gt) 406 406 { 407 gt= it->getGametype();408 } 409 if (!FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>( *it),gt))407 gt=pawn->getGametype(); 408 } 409 if (!FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(pawn),gt)) 410 410 continue; 411 411 412 412 //has it an FormationController? 413 Controller* controller = 0;414 415 if ( it->getController())416 controller = it->getController();417 else if ( it->getXMLController())418 controller = it->getXMLController();413 Controller* controller = nullptr; 414 415 if (pawn->getController()) 416 controller = pawn->getController(); 417 else if (pawn->getXMLController()) 418 controller = pawn->getXMLController(); 419 419 420 420 if (!controller) … … 422 422 423 423 //is pawn oneself? 424 if (orxonox_cast<ControllableEntity*>( *it) == this->getControllableEntity())424 if (orxonox_cast<ControllableEntity*>(pawn) == this->getControllableEntity()) 425 425 continue; 426 426 … … 433 433 continue; 434 434 435 float distance = ( it->getPosition() - this->getControllableEntity()->getPosition()).length();435 float distance = (pawn->getPosition() - this->getControllableEntity()->getPosition()).length(); 436 436 437 437 // is pawn in range? … … 440 440 if(newMaster->slaves_.size() > this->maxFormationSize_) continue; 441 441 442 for( std::vector<FormationController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)442 for(FormationController* slave : this->slaves_) 443 443 { 444 (*itSlave)->myMaster_ = newMaster;445 newMaster->slaves_.push_back( *itSlave);444 slave->myMaster_ = newMaster; 445 newMaster->slaves_.push_back(slave); 446 446 } 447 447 this->slaves_.clear(); … … 458 458 { 459 459 this->state_ = MASTER; 460 this->myMaster_ = 0;460 this->myMaster_ = nullptr; 461 461 } 462 462 } … … 486 486 int i = 1; 487 487 488 for( std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)488 for(FormationController* slave : slaves_) 489 489 { 490 490 pos = Vector3::ZERO; … … 497 497 dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK); 498 498 } 499 (*it)->setTargetOrientation(orient);500 (*it)->setTargetPosition(pos);499 slave->setTargetOrientation(orient); 500 slave->setTargetPosition(pos); 501 501 left=!left; 502 502 } … … 518 518 newMaster->state_ = MASTER; 519 519 newMaster->slaves_ = this->slaves_; 520 newMaster->myMaster_ = 0;521 522 for( std::vector<FormationController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)523 { 524 (*it)->myMaster_ = newMaster;520 newMaster->myMaster_ = nullptr; 521 522 for(FormationController* slave : newMaster->slaves_) 523 { 524 slave->myMaster_ = newMaster; 525 525 } 526 526 } … … 547 547 newMaster->state_ = MASTER; 548 548 newMaster->slaves_ = this->slaves_; 549 newMaster->myMaster_ = 0;550 551 for( std::vector<FormationController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)549 newMaster->myMaster_ = nullptr; 550 551 for(FormationController* slave : newMaster->slaves_) 552 552 { 553 (*it)->myMaster_ = newMaster;553 slave->myMaster_ = newMaster; 554 554 } 555 555 } … … 569 569 if(this->state_ != MASTER) return; 570 570 571 for( std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)572 { 573 (*it)->state_ = FREE;574 (*it)->myMaster_ = 0;571 for(FormationController* slave : slaves_) 572 { 573 slave->state_ = FREE; 574 slave->myMaster_ = nullptr; 575 575 } 576 576 this->slaves_.clear(); … … 584 584 if(this->state_ != MASTER) return; 585 585 586 for( std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)587 { 588 (*it)->state_ = FREE;589 (*it)->forceFreedom();590 (*it)->targetPosition_ = this->targetPosition_;591 (*it)->bShooting_ = true;586 for(FormationController* slave : slaves_) 587 { 588 slave->state_ = FREE; 589 slave->forceFreedom(); 590 slave->targetPosition_ = this->targetPosition_; 591 slave->bShooting_ = true; 592 592 // (*it)->getControllableEntity()->fire(0);// fire once for fun 593 593 } … … 629 629 630 630 //search new Master, then take lead 631 if (this->state_==FREE && this->myMaster_== 0)631 if (this->state_==FREE && this->myMaster_==nullptr) 632 632 { 633 633 searchNewMaster(); … … 650 650 this->slaves_.push_back(this->myMaster_); 651 651 //set this as new master 652 for( std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)653 { 654 (*it)->myMaster_=this;655 } 656 this->myMaster_= 0;652 for(FormationController* slave : slaves_) 653 { 654 slave->myMaster_=this; 655 } 656 this->myMaster_=nullptr; 657 657 this->state_=MASTER; 658 658 } … … 694 694 if (this->state_ == MASTER) 695 695 { 696 for( std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)697 { 698 (*it)->formationMode_ = val;696 for(FormationController* slave : slaves_) 697 { 698 slave->formationMode_ = val; 699 699 if (val == ATTACK) 700 (*it)->forgetTarget();700 slave->forgetTarget(); 701 701 } 702 702 } … … 773 773 { 774 774 775 Pawn *humanPawn = NULL;776 NewHumanController *currentHumanController = NULL;775 Pawn *humanPawn = nullptr; 776 NewHumanController *currentHumanController = nullptr; 777 777 std::vector<FormationController*> allMasters; 778 778 779 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)780 { 781 Controller* controller = 0;782 783 if ( it->getController())784 controller = it->getController();785 else if ( it->getXMLController())786 controller = it->getXMLController();779 for (Pawn* pawn : ObjectList<Pawn>()) 780 { 781 Controller* controller = nullptr; 782 783 if (pawn->getController()) 784 controller = pawn->getController(); 785 else if (pawn->getXMLController()) 786 controller = pawn->getXMLController(); 787 787 788 788 if (!controller) … … 791 791 currentHumanController = orxonox_cast<NewHumanController*>(controller); 792 792 793 if(currentHumanController) humanPawn = *it;793 if(currentHumanController) humanPawn = pawn; 794 794 795 795 FormationController *aiController = orxonox_cast<FormationController*>(controller); … … 800 800 } 801 801 802 if((humanPawn != NULL) && (allMasters.size() != 0))802 if((humanPawn != nullptr) && (allMasters.size() != 0)) 803 803 { 804 804 float posHuman = humanPawn->getPosition().length(); … … 808 808 int i = 0; 809 809 810 for( std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)811 { 812 if (!FormationController::sameTeam( (*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;813 distance = posHuman - (*it)->getControllableEntity()->getPosition().length();810 for(FormationController* master : allMasters) 811 { 812 if (!FormationController::sameTeam(master->getControllableEntity(), humanPawn, master->getGametype())) continue; 813 distance = posHuman - master->getControllableEntity()->getPosition().length(); 814 814 if(distance < minDistance) index = i; 815 i++; 815 816 } 816 817 allMasters[index]->followInit(humanPawn); … … 826 827 void FormationController::followInit(Pawn* pawn, const bool always, const int secondsToFollow) 827 828 { 828 if (pawn == NULL|| this->state_ != MASTER)829 if (pawn == nullptr || this->state_ != MASTER) 829 830 return; 830 831 this->specificMasterAction_ = FOLLOW; … … 844 845 { 845 846 846 Pawn *humanPawn = NULL;847 NewHumanController *currentHumanController = NULL;848 849 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)850 { 851 if (! it->getController())847 Pawn *humanPawn = nullptr; 848 NewHumanController *currentHumanController = nullptr; 849 850 for (Pawn* pawn : ObjectList<Pawn>()) 851 { 852 if (!pawn->getController()) 852 853 continue; 853 854 854 currentHumanController = orxonox_cast<NewHumanController*>( it->getController());855 currentHumanController = orxonox_cast<NewHumanController*>(pawn->getController()); 855 856 if(currentHumanController) 856 857 { 857 if (!FormationController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;858 humanPawn = *it;858 if (!FormationController::sameTeam(this->getControllableEntity(), pawn, this->getGametype())) continue; 859 humanPawn = pawn; 859 860 break; 860 861 } 861 862 } 862 863 863 if((humanPawn != NULL))864 if((humanPawn != nullptr)) 864 865 this->followInit(humanPawn); 865 866 } … … 918 919 this->forgetTarget(); 919 920 920 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)921 { 922 if (FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>( *it), this->getGametype()))921 for (Pawn* pawn : ObjectList<Pawn>()) 922 { 923 if (FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), this->getGametype())) 923 924 continue; 924 925 925 926 /* So AI won't choose invisible Spaceships as target */ 926 if (! it->getRadarVisibility())927 if (!pawn->getRadarVisibility()) 927 928 continue; 928 929 929 if (static_cast<ControllableEntity*>( *it) != this->getControllableEntity())930 if (static_cast<ControllableEntity*>(pawn) != this->getControllableEntity()) 930 931 { 931 932 float speed = this->getControllableEntity()->getVelocity().length(); 932 933 Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition(); 933 Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();934 if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi)934 Vector3 distanceNew = pawn->getPosition() - this->getControllableEntity()->getPosition(); 935 if (!this->target_ || pawn->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi) 935 936 < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / math::twoPi) + rnd(-250, 250)) 936 937 { 937 this->setTarget( *it);938 this->setTarget(pawn); 938 939 } 939 940 } … … 943 944 void FormationController::forgetTarget() 944 945 { 945 this->target_ = 0;946 this->target_ = nullptr; 946 947 this->bShooting_ = false; 947 948 } … … 963 964 int team2 = entity2->getTeam(); 964 965 965 Controller* controller = 0;966 Controller* controller = nullptr; 966 967 if (entity1->getController()) 967 968 controller = entity1->getController(); … … 1000 1001 } 1001 1002 1002 TeamBaseMatchBase* base = 0;1003 TeamBaseMatchBase* base = nullptr; 1003 1004 base = orxonox_cast<TeamBaseMatchBase*>(entity1); 1004 1005 if (base) … … 1034 1035 } 1035 1036 1036 DroneController* droneController = 0;1037 DroneController* droneController = nullptr; 1037 1038 droneController = orxonox_cast<DroneController*>(entity1->getController()); 1038 1039 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2) -
code/trunk/src/orxonox/controllers/FormationController.h
r10631 r11071 50 50 virtual ~FormationController(); 51 51 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 53 53 54 54 … … 93 93 { return this->formationMode_; } 94 94 95 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) ;95 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) override; 96 96 97 97 FormationController* getMaster( void ) { return myMaster_; } … … 99 99 FormationController* getSlave( void ) { return this->slaves_.back(); } 100 100 101 virtual void changedControllableEntity() ;101 virtual void changedControllableEntity() override; 102 102 103 103 protected: -
code/trunk/src/orxonox/controllers/HumanController.cc
r11052 r11071 65 65 RegisterUnloadableClass(HumanController); 66 66 67 HumanController* HumanController::localController_s = 0;67 HumanController* HumanController::localController_s = nullptr; 68 68 69 69 HumanController::HumanController(Context* context) : FormationController(context) … … 81 81 HumanController::localController_s->removeFromFormation(); 82 82 } 83 HumanController::localController_s = 0;83 HumanController::localController_s = nullptr; 84 84 } 85 85 … … 321 321 return orxonox_cast<Pawn*>(HumanController::localController_s->getControllableEntity()); 322 322 else 323 return NULL;323 return nullptr; 324 324 } 325 325 -
code/trunk/src/orxonox/controllers/HumanController.h
r10624 r11071 47 47 virtual ~HumanController(); 48 48 49 virtual void tick(float dt) ;49 virtual void tick(float dt) override; 50 50 51 51 static void moveFrontBack(const Vector2& value); -
code/trunk/src/orxonox/controllers/MasterController.cc
r11052 r11071 58 58 { 59 59 //fill the vector in the first tick 60 for ( ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)60 for (ActionpointController* controller : ObjectList<ActionpointController>()) 61 61 { 62 62 //----0ptr?---- 63 if (! it)63 if (!controller) 64 64 continue; 65 this->controllers_.push_back( *it);65 this->controllers_.push_back(controller); 66 66 } 67 67 } -
code/trunk/src/orxonox/controllers/MasterController.h
r11052 r11071 61 61 62 62 //----[orxonox demanded functions]---- 63 virtual void tick(float dt) ;63 virtual void tick(float dt) override; 64 64 65 65 //----[orxonox demanded functions]---- … … 68 68 69 69 private: 70 std::vector<WeakPtr<ActionpointController> > controllers_;//<! vector of controllers, which action(), canFire() and maneuver() methods are to be called70 std::vector<WeakPtr<ActionpointController>> controllers_;//<! vector of controllers, which action(), canFire() and maneuver() methods are to be called 71 71 size_t indexOfCurrentController_; //<! index of current controller 72 72 unsigned int numberOfTicksPassedSinceLastActionCall_; -
code/trunk/src/orxonox/controllers/NewHumanController.cc
r10631 r11071 58 58 RegisterUnloadableClass(NewHumanController); 59 59 60 NewHumanController* NewHumanController::localController_s = 0;60 NewHumanController* NewHumanController::localController_s = nullptr; 61 61 62 62 NewHumanController::NewHumanController(Context* context) 63 63 : HumanController(context) 64 , crossHairOverlay_( NULL)65 , centerOverlay_( NULL)66 , damageOverlayTop_( NULL)67 , damageOverlayRight_( NULL)68 , damageOverlayBottom_( NULL)69 , damageOverlayLeft_( NULL)64 , crossHairOverlay_(nullptr) 65 , centerOverlay_(nullptr) 66 , damageOverlayTop_(nullptr) 67 , damageOverlayRight_(nullptr) 68 , damageOverlayBottom_(nullptr) 69 , damageOverlayLeft_(nullptr) 70 70 , damageOverlayTT_(0) 71 71 , damageOverlayTR_(0) 72 72 , damageOverlayTB_(0) 73 73 , damageOverlayTL_(0) 74 , arrowsOverlay1_( NULL)75 , arrowsOverlay2_( NULL)76 , arrowsOverlay3_( NULL)77 , arrowsOverlay4_( NULL)74 , arrowsOverlay1_(nullptr) 75 , arrowsOverlay2_(nullptr) 76 , arrowsOverlay3_(nullptr) 77 , arrowsOverlay4_(nullptr) 78 78 { 79 79 RegisterObject(NewHumanController); … … 445 445 pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 3000 ); 446 446 447 if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != 0)448 this->getControllableEntity()->setTarget( 0);447 if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != nullptr ) 448 this->getControllableEntity()->setTarget( nullptr ); 449 449 450 450 //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000); -
code/trunk/src/orxonox/controllers/NewHumanController.h
r9667 r11071 45 45 virtual ~NewHumanController(); 46 46 47 virtual void tick(float dt) ;47 virtual void tick(float dt) override; 48 48 49 virtual void frontback(const Vector2& value) ;50 virtual void yaw(const Vector2& value) ;51 virtual void pitch(const Vector2& value) ;49 virtual void frontback(const Vector2& value) override; 50 virtual void yaw(const Vector2& value) override; 51 virtual void pitch(const Vector2& value) override; 52 52 53 53 static void accelerate(); 54 54 static void decelerate(); 55 55 56 virtual void doFire(unsigned int firemode) ;56 virtual void doFire(unsigned int firemode) override; 57 57 58 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) ;58 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) override; 59 59 60 60 static void unfire(); … … 65 65 static void changeMode(); 66 66 67 virtual void changedControllableEntity() ;68 virtual void doPauseControl() ;69 virtual void doResumeControl() ;67 virtual void changedControllableEntity() override; 68 virtual void doPauseControl() override; 69 virtual void doResumeControl() override; 70 70 71 71 float getCurrentYaw(){ return this->currentYaw_; } -
code/trunk/src/orxonox/controllers/ScriptController.cc
r10622 r11071 64 64 /* Set default values for all variables */ 65 65 /* - pointers to zero */ 66 this->player_ = NULL;67 this->entity_ = NULL;66 this->player_ = nullptr; 67 this->entity_ = nullptr; 68 68 69 69 /* - times */ … … 121 121 122 122 /* Debugging: print all the scriptcontroller object pointers */ 123 for(ObjectList<ScriptController>::iterator it = 124 ObjectList<ScriptController>::begin(); 125 it != ObjectList<ScriptController>::end(); ++it) 126 { orxout(verbose) << "Have object in list: " << *it << endl; } 123 for(ScriptController* controller : ObjectList<ScriptController>()) 124 { orxout(verbose) << "Have object in list: " << controller << endl; } 127 125 128 126 /* Find the first one with a nonzero ID */ 129 for(ObjectList<ScriptController>::iterator it = 130 ObjectList<ScriptController>::begin(); 131 it != ObjectList<ScriptController>::end(); ++it) 127 for(ScriptController* controller : ObjectList<ScriptController>()) 132 128 { 133 129 // TODO: do some selection here. Currently just returns the first one 134 if( (*it)->getID() > 0 )135 { orxout(verbose) << "Controller to return: " << *it<< endl;136 return *it;130 if( controller->getID() > 0 ) 131 { orxout(verbose) << "Controller to return: " << controller << endl; 132 return controller; 137 133 } 138 134 139 135 } 140 return NULL;136 return nullptr; 141 137 } 142 138 -
code/trunk/src/orxonox/controllers/ScriptController.h
r10622 r11071 71 71 void setPlayer(PlayerInfo* player) { this->player_ = player; } 72 72 73 virtual void tick(float dt) ;73 virtual void tick(float dt) override; 74 74 75 75 // LUA interface -
code/trunk/src/orxonox/controllers/SectionController.cc
r11052 r11071 40 40 this->setFormationMode(FormationMode::FINGER4); 41 41 42 this->myWingman_ = 0;43 this->myDivisionLeader_ = 0;42 this->myWingman_ = nullptr; 43 this->myDivisionLeader_ = nullptr; 44 44 this->bFirstAction_ = true; 45 45 … … 48 48 SectionController::~SectionController() 49 49 { 50 for (size_t i = 0; i < this->actionpoints_.size(); ++i)51 { 52 if (this->actionpoints_[i])53 this->actionpoints_[i]->destroy();50 for (WorldEntity* actionpoint : this->actionpoints_) 51 { 52 if (actionpoint) 53 actionpoint->destroy(); 54 54 } 55 55 this->parsedActionpoints_.clear(); 56 56 this->actionpoints_.clear(); 57 }58 void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)59 {60 SUPER(SectionController, XMLPort, xmlelement, mode);61 }62 63 //----in tick, move (or look) and shoot----64 void SectionController::tick(float dt)65 {66 if (!this->isActive())67 return;68 69 SUPER(SectionController, tick, dt);70 71 57 } 72 58 … … 131 117 { 132 118 //----If division leader fights, cover him by fighting emenies close to his target---- 133 Action ::Valueaction = this->myDivisionLeader_->getAction();119 Action action = this->myDivisionLeader_->getAction(); 134 120 135 121 if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK) … … 147 133 Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition(); 148 134 Gametype* gt = this->getGametype(); 149 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)135 for (Pawn* pawn : ObjectList<Pawn>()) 150 136 { 151 137 //----is enemy?---- 152 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>( *itP), gt) )138 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), gt) ) 153 139 continue; 154 140 //----in range?---- 155 if (( (*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&156 (*itP)!= this->myDivisionLeader_->getTarget())141 if ((pawn->getWorldPosition() - divisionTargetPosition).length() < 3000 && 142 pawn != this->myDivisionLeader_->getTarget()) 157 143 { 158 144 foundTarget = true; 159 target = (*itP);145 target = pawn; 160 146 break; 161 147 } … … 188 174 this->setFormationMode( this->myDivisionLeader_->getFormationMode() ); 189 175 this->spread_ = this->myDivisionLeader_->getSpread(); 190 Vector3* targetRelativePosition;191 176 switch (this->formationMode_){ 192 177 case FormationMode::WALL: 193 { 194 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 0); 195 break; 196 } 178 return Vector3 (-2.0f*this->spread_, 0, 0); 179 197 180 case FormationMode::FINGER4: 198 { 199 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 200 break; 201 } 181 return Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 202 182 203 183 case FormationMode::DIAMOND: 204 { 205 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 206 break; 207 } 208 } 209 Vector3 result = *targetRelativePosition; 210 delete targetRelativePosition; 211 return result; 184 return Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 185 186 default: 187 return Vector3::ZERO; 188 } 212 189 } 213 190 … … 226 203 227 204 if (!this->getControllableEntity()) 228 return 0;229 230 ActionpointController* closestLeader = 0;205 return nullptr; 206 207 ActionpointController* closestLeader = nullptr; 231 208 float minDistance = std::numeric_limits<float>::infinity(); 232 209 //go through all pawns 233 for ( ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)210 for (ActionpointController* controller : ObjectList<ActionpointController>()) 234 211 { 235 212 //0ptr or not DivisionController? 236 if (! (it) || !((it)->getIdentifier()->getName() == "DivisionController") || !(it->getControllableEntity()))213 if (!controller || !(controller->getIdentifier()->getName() == "DivisionController") || !(controller->getControllableEntity())) 237 214 continue; 238 215 //same team? 239 if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))216 if ((this->getControllableEntity()->getTeam() != controller->getControllableEntity()->getTeam())) 240 217 continue; 241 218 242 219 //is equal to this? 243 if (orxonox_cast<ControllableEntity*>( *it) == this->getControllableEntity())220 if (orxonox_cast<ControllableEntity*>(controller) == this->getControllableEntity()) 244 221 continue; 245 222 246 float distance = CommonController::distance ( it->getControllableEntity(), this->getControllableEntity());223 float distance = CommonController::distance (controller->getControllableEntity(), this->getControllableEntity()); 247 224 248 if (distance < minDistance && !( it->hasFollower()))249 { 250 closestLeader = *it;225 if (distance < minDistance && !(controller->hasFollower())) 226 { 227 closestLeader = controller; 251 228 minDistance = distance; 252 229 } … … 258 235 return closestLeader; 259 236 } 260 return 0;237 return nullptr; 261 238 } 262 239 -
code/trunk/src/orxonox/controllers/SectionController.h
r11052 r11071 49 49 //----[/language demanded functions]---- 50 50 51 //----[orxonox demanded functions]----52 virtual void tick(float dt);53 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);55 //----[/orxonox demanded functions]----56 57 51 //----[own functions]---- 58 52 ActionpointController* findNewDivisionLeader(); 59 53 60 virtual bool setWingman(ActionpointController* newWingman) ;61 virtual bool hasWingman() ;62 virtual bool hasFollower() 54 virtual bool setWingman(ActionpointController* newWingman) override; 55 virtual bool hasWingman() override; 56 virtual bool hasFollower() override 63 57 { return false; } 64 58 void chooseTarget(); … … 67 61 protected: 68 62 //----action must only be managed by this---- 69 virtual void action() ; //<! action() is called in regular intervals by MasterController managing the bot's behaviour.63 virtual void action() override; //<! action() is called in regular intervals by MasterController managing the bot's behaviour. 70 64 Vector3 getFormationPosition (); 71 65 void keepFormation(); -
code/trunk/src/orxonox/controllers/WaypointController.cc
r9667 r11071 44 44 WaypointController::~WaypointController() 45 45 { 46 for ( size_t i = 0; i < this->waypoints_.size(); ++i)46 for (WorldEntity* waypoint : this->waypoints_) 47 47 { 48 if( this->waypoints_[i])49 this->waypoints_[i]->destroy();48 if(waypoint) 49 waypoint->destroy(); 50 50 } 51 51 } -
code/trunk/src/orxonox/controllers/WaypointController.h
r9667 r11071 44 44 virtual ~WaypointController(); 45 45 46 virtual void tick(float dt) ;46 virtual void tick(float dt) override; 47 47 48 48 protected: -
code/trunk/src/orxonox/controllers/WaypointPatrolController.cc
r9716 r11071 87 87 float shortestsqdistance = (float)static_cast<unsigned int>(-1); 88 88 89 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)89 for (Pawn* pawn : ObjectList<Pawn>()) 90 90 { 91 if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>( *it), this->getGametype()))91 if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), this->getGametype())) 92 92 continue; 93 93 94 float sqdistance = it->getPosition().squaredDistance(myposition);94 float sqdistance = pawn->getPosition().squaredDistance(myposition); 95 95 if (sqdistance < shortestsqdistance) 96 96 { 97 97 shortestsqdistance = sqdistance; 98 this->target_ = (*it);98 this->target_ = pawn; 99 99 } 100 100 } 101 101 102 102 if (shortestsqdistance > (this->alertnessradius_ * this->alertnessradius_)) 103 this->target_ = 0;103 this->target_ = nullptr; 104 104 } 105 105 } -
code/trunk/src/orxonox/controllers/WaypointPatrolController.h
r9716 r11071 43 43 virtual ~WaypointPatrolController() {} 44 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) ;46 virtual void tick(float dt) ;45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 46 virtual void tick(float dt) override; 47 47 48 48 inline void setAlertnessRadius(float radius) -
code/trunk/src/orxonox/controllers/WingmanController.cc
r11052 r11071 39 39 { 40 40 RegisterObject(WingmanController); 41 this->myLeader_ = 0;41 this->myLeader_ = nullptr; 42 42 this->bFirstAction_ = true; 43 43 … … 46 46 WingmanController::~WingmanController() 47 47 { 48 for ( size_t i = 0; i < this->actionpoints_.size(); ++i)48 for (WorldEntity* actionpoint : this->actionpoints_) 49 49 { 50 if (this->actionpoints_[i])51 this->actionpoints_[i]->destroy();50 if (actionpoint) 51 actionpoint->destroy(); 52 52 } 53 53 this->parsedActionpoints_.clear(); 54 54 this->actionpoints_.clear(); 55 }56 57 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)58 {59 SUPER(WingmanController, XMLPort, xmlelement, mode);60 }61 62 //----in tick, move (or look) and shoot----63 void WingmanController::tick(float dt)64 {65 if (!this->isActive())66 return;67 68 SUPER(WingmanController, tick, dt);69 70 55 } 71 56 … … 122 107 Vector3 WingmanController::getFormationPosition () 123 108 { 124 125 126 109 this->setFormationMode( this->myLeader_->getFormationMode() ); 127 Vector3* targetRelativePosition;128 110 this->spread_ = this->myLeader_->getSpread(); 129 111 if (this->myLeader_->getIdentifier()->getName() == "DivisionController") … … 131 113 switch (this->formationMode_){ 132 114 case FormationMode::WALL: 133 { 134 targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 135 break; 136 } 115 return Vector3 (2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 137 116 case FormationMode::FINGER4: 138 { 139 targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 140 break; 141 } 117 return Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 142 118 case FormationMode::DIAMOND: 143 { 144 targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 145 break; 146 } 119 return Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 120 default: 121 return Vector3::ZERO; 147 122 } 148 123 } … … 151 126 switch (this->formationMode_){ 152 127 case FormationMode::WALL: 153 { 154 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 155 break; 156 } 128 return Vector3 (-2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 157 129 case FormationMode::FINGER4: 158 { 159 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 160 break; 161 } 130 return Vector3 (-2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 162 131 case FormationMode::DIAMOND: 163 { 164 targetRelativePosition = new Vector3 (2.0f*this->spread_, -1.0f*this->spread_, 0 - 1.0f*this->tolerance_); 165 break; 166 } 132 return Vector3 (2.0f*this->spread_, -1.0f*this->spread_, 0 - 1.0f*this->tolerance_); 133 default: 134 return Vector3::ZERO; 167 135 } 168 136 } 169 Vector3 result = *targetRelativePosition;170 delete targetRelativePosition;171 return result;172 137 } 173 138 void WingmanController::keepFormation() … … 185 150 186 151 if (!this->getControllableEntity()) 187 return 0;152 return nullptr; 188 153 189 154 //----vars for finding the closest leader---- 190 ActionpointController* closestLeader = 0;155 ActionpointController* closestLeader = nullptr; 191 156 float minDistance = std::numeric_limits<float>::infinity(); 192 157 Gametype* gt = this->getGametype(); 193 158 194 for ( ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)159 for (ActionpointController* controller : ObjectList<ActionpointController>()) 195 160 { 196 161 //----0ptr or not a leader or dead?---- 197 if (! it ||198 ( it->getIdentifier()->getName() != "SectionController" && it->getIdentifier()->getName() != "DivisionController") ||199 !( it->getControllableEntity()))162 if (!controller || 163 (controller->getIdentifier()->getName() != "SectionController" && controller->getIdentifier()->getName() != "DivisionController") || 164 !(controller->getControllableEntity())) 200 165 continue; 201 166 202 167 //----same team?---- 203 if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity(), gt) )168 if ( !CommonController::sameTeam (this->getControllableEntity(), controller->getControllableEntity(), gt) ) 204 169 continue; 205 170 206 171 //----check distance---- 207 float distance = CommonController::distance ( it->getControllableEntity(), this->getControllableEntity());208 if (distance < minDistance && !( it->hasWingman()))172 float distance = CommonController::distance (controller->getControllableEntity(), this->getControllableEntity()); 173 if (distance < minDistance && !(controller->hasWingman())) 209 174 { 210 closestLeader = *it;175 closestLeader = controller; 211 176 minDistance = distance; 212 177 } … … 222 187 } 223 188 } 224 return 0;189 return nullptr; 225 190 } 226 191 -
code/trunk/src/orxonox/controllers/WingmanController.h
r11052 r11071 51 51 52 52 //----[orxonox demanded functions]---- 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 55 virtual void tick(float dt); 56 virtual bool hasWingman() 53 virtual bool hasWingman() override 57 54 { return false; } 58 virtual bool hasFollower() 55 virtual bool hasFollower() override 59 56 { return false; } 60 57 //----[/orxonox demanded functions]---- … … 66 63 protected: 67 64 //----action must only be managed by this---- 68 virtual void action() ; //<! action() is called in regular intervals managing the bot's behaviour.65 virtual void action() override; //<! action() is called in regular intervals managing the bot's behaviour. 69 66 Vector3 getFormationPosition (); 70 67 void keepFormation();
Note: See TracChangeset
for help on using the changeset viewer.