Changeset 10885 for code/branches/campaignHS15/src/orxonox/controllers
- Timestamp:
- Nov 28, 2015, 10:30:56 PM (9 years ago)
- Location:
- code/branches/campaignHS15/src/orxonox/controllers
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10883 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * ... 26 26 * 27 27 */ … … 61 61 void ActionpointController::tick(float dt) 62 62 { 63 if (this->timeout_ > 0 && this->bFiredRocket_) 64 { 65 this->timeout_ -= dt; 66 } 67 if (timeout_ <= 0) 68 this->bFiredRocket_ = false; 69 63 70 if (this->bHasTargetPosition_) 64 71 { … … 69 76 this->lookAtTarget(dt); 70 77 } 71 if ( bShooting_)78 if (this->bShooting_) 72 79 { 73 80 this->doFire(); … … 537 544 538 545 } 539 void ActionpointController::takeActionpoints ( std::vector<Point > vector, std::vector<Point >loop, bool b)546 void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b) 540 547 { 541 548 this->parsedActionpoints_ = vector; -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10877 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 25 * ... … … 55 55 { 56 56 public: 57 //----[language demanded functions]---- 58 ActionpointController(Context* context); 59 virtual ~ActionpointController(); 60 //----[language demanded functions]---- 61 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 57 ActionpointController(Context* context); 58 virtual ~ActionpointController(); 59 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 62 60 63 virtual void tick(float dt); 61 virtual void tick(float dt); 62 64 63 void addActionpoint(WorldEntity* waypoint); 65 64 WorldEntity* getActionpoint(unsigned int index) const; 66 65 virtual void stayNearProtect(); 67 66 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 68 virtual void takeActionpoints (std::vector<Point > vector, std::vector<Point > loop, bool b); 69 Action::Value getAction (); 70 std::string getActionName(); 67 virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b); 68 69 virtual Action::Value getAction (); 70 virtual std::string getActionName(); 71 71 72 72 void setAction (Action::Value action); … … 83 83 virtual bool hasFollower() 84 84 { return true; } 85 85 86 86 protected: 87 void startAttackingEnemiesThatAreClose(); 88 87 void startAttackingEnemiesThatAreClose(); 88 WeakPtr<ActionpointController> myWingman_; 89 WeakPtr<ActionpointController> myFollower_; 90 WeakPtr<ActionpointController> myDivisionLeader_; 89 91 //----[Actionpoint information]---- 90 92 Action::Value action_; … … 103 105 ControllableEntity* getProtect (); 104 106 WeakPtr<ControllableEntity> protect_; 105 107 void fillLoop(); 108 void fillLoopReversed(); 109 void moveBackToTop(); 106 110 void setClosestTarget(); 107 111 Pawn* closestTarget(); … … 109 113 void executeActionpoint(); 110 114 void nextActionpoint(); 111 void fillLoop(); 112 void fillLoopReversed(); 113 void moveBackToTop(); 115 void pushAction(Point& p); 116 void popAction(); 114 117 //----[Actionpoint methods]---- 115 118 bool bFirstTick_; -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10877 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 25 * Dominik Solenicki … … 52 52 float CommonController::randomInRange( float a, float b ) 53 53 { 54 float random = rnd( 1.0f ); 55 float diff = b - a; 56 float r = random * diff; 57 return a + r; 54 return a + rnd(1.0f) * (b - a); 58 55 } 59 56 float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2) … … 193 190 return name; 194 191 } 195 196 197 192 } -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10877 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10883 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * ... 26 26 * 27 27 */ … … 96 96 } 97 97 98 bool DivisionController::setWingman(ActionpointController* wingman)98 bool DivisionController::setWingman(ActionpointController* newWingman) 99 99 { 100 101 WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);102 100 if (!this->myWingman_) 103 101 { 104 102 this->myWingman_ = newWingman; 103 if (!this->hasFollower()) 104 newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); 105 105 return true; 106 106 } … … 110 110 } 111 111 } 112 bool DivisionController::setFollower(ActionpointController* myFollower)112 bool DivisionController::setFollower(ActionpointController* newFollower) 113 113 { 114 LeaderController* newFollower = orxonox_cast<LeaderController*> (myFollower);115 114 if (!this->myFollower_) 116 115 { … … 120 119 this->myWingman_->takeActionpoints (std::vector<Point>(), std::vector<Point>(), false); 121 120 } 121 122 newFollower->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); 123 122 124 return true; 123 125 } -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
r10877 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * ... 26 26 * 27 27 */ … … 52 52 53 53 //----[own functions]---- 54 virtual bool setFollower(ActionpointController* myFollower);55 virtual bool setWingman(ActionpointController* wingman);54 virtual bool setFollower(ActionpointController* newFollower); 55 virtual bool setWingman(ActionpointController* newWingman); 56 56 virtual bool hasWingman(); 57 57 virtual bool hasFollower(); -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10883 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * Fabian 'x3n' Landau, Dominik Solenicki 26 26 * 27 27 */ … … 31 31 32 32 33 #include "worldentities/pawns/SpaceShip.h" 34 35 #include "weaponsystem/WeaponMode.h" 36 #include "weaponsystem/WeaponPack.h" 37 #include "weaponsystem/Weapon.h" 38 #include "weaponsystem/WeaponSlot.h" 39 #include "weaponsystem/WeaponSlot.h" 33 40 namespace orxonox 34 41 { … … 38 45 FightingController::FightingController( Context* context ): FlyingController( context ) 39 46 { 40 this->attackRange_ = 2000;47 this->attackRange_ = 3000; 41 48 this->stopLookingAtTarget(); 42 49 this->bSetupWorked = false; 50 this->timeout_ = 0; 43 51 RegisterObject( FightingController ); 44 52 } … … 78 86 this->bLookAtTarget_ = true; 79 87 } 80 bool FightingController::hasTarget() 88 bool FightingController::hasTarget() const 81 89 { 82 90 if ( this->target_ ) … … 106 114 void FightingController::maneuver() 107 115 { 116 if ( !this->target_ || !this->getControllableEntity()) 117 return; 108 118 maneuverCounter_++; 109 119 if (maneuverCounter_ > 5) 110 120 maneuverCounter_ = 0; 111 121 112 if ( !this->target_ || !this->getControllableEntity())113 return;114 115 122 Vector3 thisPosition = this->getControllableEntity()->getWorldPosition(); 116 this->setPositionOfTarget( getPredictedPosition( 117 thisPosition, 118 hardcoded_projectile_speed, 119 this->target_->getWorldPosition() , 120 this->target_->getVelocity() 121 ) ); 122 this->setOrientationOfTarget( this->target_->getOrientation() ); 123 123 this->setPositionOfTarget(this->target_->getWorldPosition()); 124 //this->setOrientationOfTarget(this->target_->getOrientation()); 124 125 Vector3 diffVector = this->positionOfTarget_ - thisPosition; 125 126 float diffLength = diffVector.length(); 126 127 Vector3 diffUnit = diffVector/diffLength; 127 128 bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/20.0f ); 128 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f); 129 129 130 130 //too far? well, come closer then … … 135 135 this->bKeepFormation_ = true; 136 136 137 this->setTargetPosition( this->positionOfTarget_);137 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f); 138 138 } 139 139 //too close? How do u expect to dodge anything? Just attack! 140 else if ( diffLength < 500)140 else if (diffLength < 500) 141 141 { 142 142 this->bKeepFormation_ = false; 143 143 144 144 //at this point, just look and shoot 145 if ( diffLength < 250)145 if (diffLength < 250) 146 146 { 147 147 this->stopMoving(); … … 150 150 else 151 151 { 152 this->setTargetPosition( this->positionOfTarget_);152 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f); 153 153 } 154 154 } 155 155 //Good distance? Check if target looks at us. It doesn't? Go hunt! 156 else if ( !bTargetIsLookingAtThis)156 else if (!bTargetIsLookingAtThis) 157 157 { 158 158 this->bKeepFormation_ = false; 159 this->setTargetPosition( this->positionOfTarget_);159 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f); 160 160 } 161 161 //That's unfortunate, he is looking and probably shooting... try to dodge what we can... … … 165 165 if (maneuverCounter_ == 0) 166 166 { 167 this->setTargetPosition( this->positionOfTarget_);167 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f); 168 168 return; 169 169 } 170 dodge( thisPosition, diffUnit);170 dodge(thisPosition, diffUnit); 171 171 } 172 172 } 173 173 174 void FightingController::dodge(Vector3& thisPosition, Vector3& diffUnit) 175 { 176 float factorX = 0, factorY = 0, factorZ = 0; 177 float rand = CommonController::randomInRange (0, 1); 178 179 if (rand <= 0.5) 180 { factorX = 1; } 174 void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit) 175 { 176 //d.x*x + d.y*y + d.z*z == 0 177 //z = 1/d.z * (-d.y*y - d.x * x) 178 float x = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 179 float y = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 180 float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y); 181 this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * 1000.0f); 182 this->boostControl(); 183 184 } 185 bool FightingController::canFire() 186 { 187 //no target? why fire? 188 if (!this->target_) 189 return false; 190 Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), 191 hardcoded_projectile_speed, this->target_->getWorldPosition(), 192 this->target_->getVelocity()); 193 if (!newPositionOfTarget.isNaN()) 194 { 195 this->setPositionOfTarget(newPositionOfTarget); 196 } 197 return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f); 198 } 199 // void FightingController::doFire() 200 // { 201 // if ( !this->target_ || !this->getControllableEntity() ) 202 // { 203 // return; 204 // } 205 206 // Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() ); 207 208 // if ( pawn ) 209 // pawn->setAimPosition( this->positionOfTarget_ ); 210 // float distance = CommonController::distance (this->getControllableEntity(), this->target_); 211 // this->getControllableEntity() ->fire(distance < 1500 ? (distance < 1000 && distance > 700 ? 3 : 0) : (1)); 212 // } 213 214 215 float FightingController::squaredDistanceToTarget() const 216 { 217 if (!this->getControllableEntity()) 218 return 0; 219 if (!this->target_ || !this->getControllableEntity()) 220 return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_)); 181 221 else 182 { factorX = -1; } 183 rand = CommonController::randomInRange (0, 1); 184 if (rand <= 0.5) 185 { factorY = 1; } 186 else 187 { factorY = -1; } 188 rand = CommonController::randomInRange (0, 1); 189 if (rand <= 0.5) 190 { factorZ = 1; } 191 else 192 { factorZ = -1; } 193 194 Vector3 target = ( diffUnit )* 8000.0f; 195 Vector3* randVector = new Vector3( 196 factorX * CommonController::randomInRange( 10000, 40000 ), 197 factorY * CommonController::randomInRange( 10000, 40000 ), 198 factorZ * CommonController::randomInRange( 10000, 40000 ) 199 ); 200 Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit; 201 Vector3 randV = *randVector; 202 delete randVector; 203 randV -= projection; 204 target += randV; 205 this->setTargetPosition( thisPosition + target ); 206 } 207 bool FightingController::canFire() 208 { 209 //no target? why fire? 210 if ( !this->target_ ) 211 return false; 212 213 Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , 214 hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() ); 215 if ( newPositionOfTarget != Vector3::ZERO ) 216 { 217 this->setPositionOfTarget( newPositionOfTarget ); 218 } 219 220 float squaredDistance = squaredDistanceToTarget(); 221 222 if ( squaredDistance < this->attackRange_*this->attackRange_ && this->isLookingAtTarget( math::pi / 20.0f)) 223 { 224 return true; 225 } 226 else 227 { 228 return false; 229 } 230 } 231 void FightingController::doFire() 232 { 233 if ( !this->target_ || !this->getControllableEntity() ) 234 { 235 return; 236 } 237 238 Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() ); 239 240 if ( pawn ) 241 pawn->setAimPosition( this->positionOfTarget_ ); 242 this->getControllableEntity() ->fire( 0 ); 243 } 244 float FightingController::squaredDistanceToTarget() const 245 { 246 if ( !this->getControllableEntity() ) 247 return 0; 248 if ( !this->target_ || !this->getControllableEntity() ) 249 return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) ); 250 else 251 return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) ); 252 } 253 bool FightingController::isLookingAtTarget( float angle ) 222 return (this->getControllableEntity()->getPosition().squaredDistance(this->positionOfTarget_)); 223 } 224 bool FightingController::isLookingAtTarget( float angle ) const 254 225 { 255 226 if ( !this->getControllableEntity() || !this->target_ ) … … 257 228 return CommonController::isLooking(this->getControllableEntity(), this->getTarget(), angle); 258 229 } 259 230 void FightingController::setClosestTarget() 260 231 { 261 232 this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 262 233 } 263 234 264 Pawn* FightingController::closestTarget() 235 Pawn* FightingController::closestTarget() const 265 236 { 266 237 if (!this->getControllableEntity()) … … 288 259 return 0; 289 260 } 261 //I checked it out, rockets DO NOT cause any problems! this->getControllableEntity() is always a SpaceShip 262 void FightingController::doFire() 263 { 264 if (!this->bSetupWorked) 265 { 266 this->setupWeapons(); 267 } 268 if (!this->target_ || !this->getControllableEntity()) 269 { 270 return; 271 } 272 Pawn* pawn = orxonox_cast<Pawn*> (this->getControllableEntity()); 273 if (pawn) 274 pawn->setAimPosition (this->positionOfTarget_); 275 276 int firemode; 277 float distance = CommonController::distance (this->getControllableEntity(), this->target_); 278 279 // firemode = distance < 1500 ? (distance > 800 && distance < 1200 ? 280 // (this->rocketsLeft_ > 0 && !this->bFiredRocket_ ? getFiremode("RocketFire") : getFiremode ("HsW01")) 281 // : getFiremode("HsW01")) : 282 // (distance < 2500 ? getFiremode("LightningGun") : getFiremode("HsW01")); 283 if (distance < 800) 284 { 285 if (this->rocketsLeft_ > 0) 286 { 287 firemode = getFiremode ("SimpleRocketFire"); 288 } 289 else 290 { 291 if (distance > 450) 292 firemode = getFiremode ("LightningGun"); 293 else 294 firemode = getFiremode ("HsW01"); 295 } 296 297 } 298 else if (distance < 1200) 299 { 300 if (this->rocketsLeft_ > 0 && !this->bFiredRocket_) 301 { 302 firemode = getFiremode ("RocketFire"); 303 } 304 else 305 { 306 firemode = getFiremode ("HsW01"); 307 } 308 } 309 else if (distance < 1500) 310 { 311 firemode = getFiremode ("LightningGun"); 312 } 313 else 314 { 315 firemode = getFiremode ("HsW01"); 316 } 317 if (firemode < 0) 318 { 319 firemode = getFiremode ("HsW01"); 320 } 321 if (firemode == getFiremode("RocketFire")) 322 { 323 this->timeout_ = 1.0f; 324 this->rocketsLeft_--; 325 this->bFiredRocket_ = true; 326 } 327 if (firemode == getFiremode("SimpleRocketFire")) 328 { 329 this->rocketsLeft_--; 330 } 331 332 this->getControllableEntity()->fire(firemode); 333 334 } 335 void FightingController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions) 336 { 337 this->bSetupWorked = false; 338 if(this->getControllableEntity()) 339 { 340 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 341 if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip 342 { 343 this->weaponModes_.clear(); // reset previous weapon information 344 WeaponSlot* wSlot = 0; 345 for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++) 346 { 347 WeaponMode* wMode = 0; 348 for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++) 349 { 350 std::string wName = wMode->getIdentifier()->getName(); 351 if (wName == "RocketFire") 352 this->rocketsLeft_ = 10; 353 if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new" 354 weaponModes_[wName] = wMode->getMode(); 355 } 356 } 357 if(weaponModes_.size())//at least one weapon detected 358 this->bSetupWorked = true; 359 }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user); 360 } 361 } 362 363 int FightingController::getFiremode(std::string name) 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; 369 } 370 return -1; 371 } 290 372 } -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
r10883 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau, Dominik Solenicki 26 26 * 27 27 */ … … 45 45 46 46 float squaredDistanceToTarget() const; 47 bool isLookingAtTarget(float angle) ;48 bool hasTarget() ;49 ControllableEntity* getTarget() 47 bool isLookingAtTarget(float angle) const; 48 bool hasTarget() const; 49 ControllableEntity* getTarget() const 50 50 { return this->target_; } 51 51 bool bKeepFormation_; … … 61 61 62 62 void maneuver(); 63 void dodge( Vector3& thisPosition, Vector3& diffUnit);63 void dodge(const Vector3& thisPosition, Vector3& diffUnit); 64 64 bool canFire(); 65 65 void doFire(); … … 71 71 bool bHasOrientationOfTarget_; 72 72 Quaternion orientationOfTarget_; 73 Pawn* closestTarget() ;73 Pawn* closestTarget() const; 74 74 75 75 int attackRange_; 76 76 bool bShooting_; 77 77 int maneuverCounter_; 78 bool bLookAtTarget_; 78 bool bLookAtTarget_; 79 80 //WEAPONSYSTEM DATA 81 int rocketsLeft_; 82 float timeout_; 83 bool bFiredRocket_; 84 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() 85 //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() 86 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 87 bool bSetupWorked; //<! If false, setupWeapons() is called. 88 int getFiremode(std::string name); 89 79 90 }; 80 91 } -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
r10882 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau 23 * Gani Aliguzhinov 24 24 25 * Co-authors: 25 26 * Dominik Solenicki … … 31 32 #include "util/Math.h" 32 33 #include <OgreMatrix3.h> 34 33 35 namespace orxonox 34 36 { 35 37 RegisterClass (FlyingController); 36 38 37 FlyingController::FlyingController( Context* context ): CommonController( context ) 38 { 39 FlyingController::FlyingController(Context* context): CommonController(context) 40 { 41 RegisterObject(FlyingController); 39 42 this->rotationProgress_ = 0; 40 43 this->spread_ = 200; 41 this->tolerance_ = 60; 42 RegisterObject( FlyingController ); 44 this->tolerance_ = 100; 43 45 } 44 46 FlyingController::~FlyingController() … … 47 49 } 48 50 49 void FlyingController::XMLPort( Element& xmlelement, XMLPort::Mode mode)50 { 51 XMLPortParam( FlyingController, "spread", setSpread, getSpread, xmlelement, mode);52 XMLPortParam( FlyingController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode);53 SUPER( FlyingController, XMLPort, xmlelement, mode);51 void FlyingController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 52 { 53 XMLPortParam(FlyingController, "spread", setSpread, getSpread, xmlelement, mode); 54 XMLPortParam(FlyingController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode); 55 SUPER(FlyingController, XMLPort, xmlelement, mode); 54 56 } 55 57 56 void FlyingController::setFormationModeXML( std::string val)57 { 58 const std::string valUpper = getUppercase( val);58 void FlyingController::setFormationModeXML(std::string val) 59 { 60 const std::string valUpper = getUppercase(val); 59 61 FormationMode::Value value; 60 62 … … 66 68 value = FormationMode::DIAMOND; 67 69 else 68 ThrowException( ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'.");69 this->setFormationMode( value);70 } 71 std::string FlyingController::getFormationModeXML() 70 ThrowException(ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'."); 71 this->setFormationMode(value); 72 } 73 std::string FlyingController::getFormationModeXML() const 72 74 { 73 75 switch ( this->formationMode_ ) … … 83 85 } 84 86 } 85 86 87 88 87 void FlyingController::stopMoving() 89 88 { 90 89 this->bHasTargetPosition_ = false; 91 90 } 92 93 void FlyingController::moveToPosition( const Vector3& target, float dt ) 91 void FlyingController::moveToPosition(const Vector3& target, float dt) 94 92 { 95 93 ControllableEntity* entity = this->getControllableEntity(); 96 94 97 float distance = ( target - this->getControllableEntity() ->getPosition() ).length(); 98 95 float distance = ( target - entity->getPosition() ).length(); 99 96 100 97 if ( distance >= this->tolerance_ ) … … 107 104 float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f ); 108 105 float rotateY = clamp( coord.y * 10, -1.0f, 1.0f ); 109 this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt ); 110 this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt ); 111 106 entity->rotateYaw( ROTATEFACTOR * rotateX * dt ); 107 entity->rotatePitch( ROTATEFACTOR * rotateY * dt ); 112 108 113 109 if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01)) 114 this->getControllableEntity() ->moveFrontBack( SPEED * dt ); 110 entity->moveFrontBack( SPEED * dt ); 111 copyTargetOrientation(dt); 115 112 } 116 113 else … … 118 115 bHasTargetPosition_ = false; 119 116 } 120 copyTargetOrientation(dt);121 117 } 122 118 … … 125 121 this->moveToPosition (this->targetPosition_, dt); 126 122 } 127 void FlyingController::copyOrientation( const Quaternion& orient, float dt)123 void FlyingController::copyOrientation(const Quaternion& orient, float dt) 128 124 { 129 125 //inspired by … … 167 163 } 168 164 //change log: increased precision, increased rotation speed 169 void FlyingController::copyTargetOrientation( float dt)170 { 171 if ( bHasTargetOrientation_)165 void FlyingController::copyTargetOrientation(float dt) 166 { 167 if (bHasTargetOrientation_) 172 168 { 173 copyOrientation( targetOrientation_, dt);169 copyOrientation(targetOrientation_, dt); 174 170 } 175 171 } 176 172 177 void FlyingController::setTargetPosition( const Vector3& target)173 void FlyingController::setTargetPosition(const Vector3& target) 178 174 { 179 175 this->targetPosition_ = target; … … 181 177 } 182 178 183 void FlyingController::setTargetOrientation( const Quaternion& orient)179 void FlyingController::setTargetOrientation(const Quaternion& orient) 184 180 { 185 181 this->targetOrientation_=orient; … … 187 183 } 188 184 189 void FlyingController::setTargetOrientation( ControllableEntity* target)190 { 191 if ( target)192 setTargetOrientation( target->getOrientation());185 void FlyingController::setTargetOrientation(ControllableEntity* target) 186 { 187 if (target) 188 setTargetOrientation(target->getOrientation()); 193 189 } 194 190 void FlyingController::boostControl() … … 198 194 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost 199 195 { 200 201 196 this->getControllableEntity()->boost(true); 202 197 } … … 206 201 } 207 202 } 208 209 203 } -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
r10881 r10885 56 56 void setSpread (int spread) 57 57 { this->spread_ = spread; } 58 int getSpread () 58 int getSpread () const 59 59 { return this->spread_; } 60 60 61 61 void setFormationModeXML(std::string val); 62 std::string getFormationModeXML() ;62 std::string getFormationModeXML() const; 63 63 64 64 void setFormationMode(FormationMode::Value val) -
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
r10864 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * ... 26 26 * 27 27 */ -
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
r10877 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 25 * ... … … 31 31 32 32 #include "controllers/ActionpointController.h" 33 #include "controllers/WingmanController.h"34 33 35 34 … … 51 50 protected: 52 51 //----private variables----- 53 WeakPtr<WingmanController> myWingman_; 54 WeakPtr<LeaderController> myFollower_; 55 WeakPtr<LeaderController> myDivisionLeader_; 52 56 53 57 54 -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10883 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * ... 26 26 * 27 27 */ … … 96 96 if (!myDivisionLeader_) 97 97 { 98 LeaderController* newDivisionLeader = findNewDivisionLeader();98 ActionpointController* newDivisionLeader = findNewDivisionLeader(); 99 99 this->myDivisionLeader_ = newDivisionLeader; 100 100 //spread copyOrientation called equally among the division 101 101 if (this->myDivisionLeader_) 102 102 { 103 this->actionCounter_ = 8;103 this->actionCounter_ = 5; 104 104 } 105 105 } … … 147 147 + (orient* (targetRelativePosition))); 148 148 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 149 if (this->actionCounter_ % 9== 0 && !this->bHasTargetOrientation_)149 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_) 150 150 this->setAction (Action::FLY, targetAbsolutePosition, orient); 151 151 else … … 300 300 301 301 302 LeaderController* SectionController::findNewDivisionLeader()302 ActionpointController* SectionController::findNewDivisionLeader() 303 303 { 304 304 … … 306 306 return 0; 307 307 308 LeaderController* closestLeader = 0;308 ActionpointController* closestLeader = 0; 309 309 float minDistance = std::numeric_limits<float>::infinity(); 310 310 //go through all pawns 311 for (ObjectList< LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)311 for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it) 312 312 { 313 313 //0ptr or not DivisionController? … … 338 338 return 0; 339 339 } 340 bool SectionController::setWingman(ActionpointController* wingman) 341 { 342 WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman); 340 bool SectionController::setWingman(ActionpointController* newWingman) 341 { 343 342 344 343 if (!this->myWingman_) 345 344 { 346 345 this->myWingman_ = newWingman; 346 newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_); 347 347 return true; 348 348 } -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
r10877 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * ... 26 26 * 27 27 */ … … 51 51 52 52 //----[own functions]---- 53 LeaderController* findNewDivisionLeader();53 ActionpointController* findNewDivisionLeader(); 54 54 55 virtual bool setWingman(ActionpointController* wingman);55 virtual bool setWingman(ActionpointController* newWingman); 56 56 virtual bool hasWingman(); 57 57 virtual bool hasFollower() 58 { return false; } 58 59 void chooseTarget(); 59 60 //----[/own functions]---- -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10883 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * Dominik Solenicki25 * ... 26 26 * 27 27 */ … … 89 89 //spread copyOrientation called equally among the division 90 90 if (this->myLeader_->getIdentifier()->getName() == "SectionController") 91 this->actionCounter_ = 2;91 this->actionCounter_ = 1; 92 92 else 93 this->actionCounter_ = 5;93 this->actionCounter_ = 4; 94 94 } 95 95 } … … 126 126 + (orient* (targetRelativePosition))); 127 127 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 128 if (this->actionCounter_ % 9== 0 && !this->bHasTargetOrientation_)128 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_) 129 129 this->setAction (Action::FLY, targetAbsolutePosition, orient); 130 130 else -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
r10877 r10885 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 25 * ... … … 49 49 50 50 virtual void tick(float dt); 51 virtual bool hasWingman() 52 { return false; } 53 virtual bool hasFollower() 54 { return false; } 51 55 //----[/orxonox demanded functions]---- 52 56
Note: See TracChangeset
for help on using the changeset viewer.