[Orxonox-commit 6289] r10946 - code/branches/campaignHS15/src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Mon Dec 7 16:06:37 CET 2015
Author: gania
Date: 2015-12-07 16:06:37 +0100 (Mon, 07 Dec 2015)
New Revision: 10946
Modified:
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
Log:
fix for sigsegv?
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-12-07 15:06:37 UTC (rev 10946)
@@ -112,6 +112,8 @@
{
this->moveToTargetPosition(dt);
}
+ if (!this || !this->getControllableEntity())
+ return;
else if (this->bLookAtTarget_)
{
this->lookAtTarget(dt);
@@ -145,6 +147,8 @@
{
this->bDodge_ = true;
}
+ if (!this || !this->getControllableEntity())
+ return;
if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1)
{
//orxout (internal_error) << "Team " << this->getControllableEntity()->getTeam() << (this->hasTarget() ? ", got " : ", don't have") << " target" << endl;
@@ -174,6 +178,8 @@
{
this->doFire();
}
+ if (!this || !this->getControllableEntity())
+ return;
this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
}
@@ -201,10 +207,16 @@
{
if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
{
+ if (!this || !this->getControllableEntity())
+ return;
Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
this->parsedActionpoints_.push_back (p);
}
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->bTakenOver_ = false;
}
if (!this || !this->getControllableEntity())
@@ -219,11 +231,17 @@
ControllableEntity* newTarget = this->closestTarget();
if (newTarget)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->setAction (Action::FIGHTALL, newTarget);
}
else
{
+ if (!this || !this->getControllableEntity())
+ return;
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
@@ -232,19 +250,26 @@
//Action fight -> fight as long as enemies in range
else if (this->action_ == Action::FIGHT)
{
-
if (!this->hasTarget() )
{
//----find a target----
- ControllableEntity* newTarget = this->closestTarget();
+ ControllableEntity* newTarget = this->closestTarget();
+ if (!this || !this->getControllableEntity())
+ return;
if (newTarget &&
CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->setAction (Action::FIGHT, newTarget);
}
else
{
+ if (!this || !this->getControllableEntity())
+ return;
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
}
@@ -256,15 +281,22 @@
if (diffVector.length() > this->attackRange_)
{
ControllableEntity* newTarget = this->closestTarget();
-
+ if (!this || !this->getControllableEntity())
+ return;
if (newTarget &&
CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->setAction (Action::FIGHT, newTarget);
}
else
{
+ if (!this || !this->getControllableEntity())
+ return;
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
}
@@ -274,7 +306,11 @@
{
if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
}
@@ -282,17 +318,28 @@
{
if (!this->getProtect())
{
+ if (!this || !this->getControllableEntity())
+ return;
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
+ if (!this || !this->getControllableEntity())
+ return;
this->stayNearProtect();
}
else if (this->action_ == Action::ATTACK)
{
-
+ if (!this || !this->getControllableEntity())
+ return;
if (!this->hasTarget())
{
+ if (!this || !this->getControllableEntity())
+ return;
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
}
@@ -301,10 +348,12 @@
}
void ActionpointController::setProtect (ControllableEntity* protect)
{
+
this->protect_ = protect;
}
ControllableEntity* ActionpointController::getProtect ()
{
+
return this->protect_;
}
void ActionpointController::addActionpoint(WorldEntity* actionpoint)
@@ -400,6 +449,8 @@
}
void ActionpointController::setAction (Action::Value action, ControllableEntity* target)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->action_ = action;
if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
{
@@ -414,6 +465,8 @@
}
void ActionpointController::setAction (Action::Value action, const Vector3& target)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->action_ = action;
if (action == Action::FLY)
{
@@ -422,6 +475,8 @@
}
void ActionpointController::setAction (Action::Value action, const Vector3& target, const Quaternion& orient )
{
+ if (!this || !this->getControllableEntity())
+ return;
this->action_ = action;
if (action == Action::FLY)
{
@@ -465,14 +520,20 @@
this->action_ = Action::NONE;
return;
}
+ if (!this || !this->getControllableEntity())
+ return;
if (!this->bLoop_ && this->parsedActionpoints_.back().inLoop)
{
//MOVES all points that are in loop to a loop vector
this->fillLoop();
+ if (!this || !this->getControllableEntity())
+ return;
this->bLoop_ = true;
executeActionpoint();
return;
}
+ if (!this || !this->getControllableEntity())
+ return;
this->setAction (p.action);
if (!this || !this->getControllableEntity())
return;
@@ -486,6 +547,8 @@
break;
for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
{
+ if (!this || !this->getControllableEntity())
+ return;
if (CommonController::getName(*itP) == targetName)
{
this->setTarget (static_cast<ControllableEntity*>(*itP));
@@ -496,9 +559,15 @@
case Action::FLY:
{
this->setTargetPosition( p.position );
+ if (!this || !this->getControllableEntity())
+ return;
if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
break;
@@ -552,12 +621,16 @@
{
if (CommonController::getName(*itP) == targetName)
{
+ if (!this || !this->getControllableEntity())
+ return;
this->setTarget (static_cast<ControllableEntity*>(*itP));
}
}
if (!this->hasTarget())
{
this->nextActionpoint();
+ if (!this || !this->getControllableEntity())
+ return;
this->executeActionpoint();
}
break;
@@ -647,10 +720,14 @@
void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
{
- this->parsedActionpoints_ = vector;
- this->loopActionpoints_ = loop;
- this->bLoop_ = b;
- this->bTakenOver_ = true;
+ if (!this || !this->getControllableEntity())
+ return;
+ this->parsedActionpoints_ = vector;
+ if (!this || !this->getControllableEntity())
+ return;
+ this->loopActionpoints_ = loop;
+ this->bLoop_ = b;
+ this->bTakenOver_ = true;
}
void ActionpointController::setClosestTarget()
{
@@ -666,6 +743,8 @@
Gametype* gt = this->getGametype();
for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
{
+ if (!this || !this->getControllableEntity())
+ return 0;
if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
continue;
@@ -691,6 +770,8 @@
{
if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
{
+ if (!this || !this->getControllableEntity())
+ return;
Pawn* newTarget = this->closestTarget();
if ( newTarget &&
CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-12-07 15:06:37 UTC (rev 10946)
@@ -245,15 +245,11 @@
bool bPatrolling_;
bool bDefaultPatrol_;
bool stop_;
- static unsigned int sTicks_; //<! a hack? I don't want action() and maneuver() to be called multiple times in a tick, so I keep
- //<! track of ticks and if current tick is "assigned" to this object, than I call maneuver()/action()
+ static unsigned int sTicks_; //<! a hack? I don't want action() and maneuver() to be called multiple times in a tick, so I keep
+ //<! track of ticks and if current tick is "assigned" to this object, than I call maneuver()/action()
static unsigned int nextActionpointControllerId_; //<! if level has 16 ActionpointControllers, than this variable equals to 17 after first tick
unsigned int actionpointControllerId_; //<! integer from 0 to nextActionpointControllerId_, different for every ActionpointController in level
- unsigned int ticks_; //<! local tick counter
-
-
- private:
-
+ unsigned int ticks_; //<! local tick counter
};
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-12-07 15:06:37 UTC (rev 10946)
@@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
- * of the License, or ( at your option )any later version.
+ * of the License, or (at your option)any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,7 +27,7 @@
*/
#include "controllers/CommonController.h"
-//stuff for sameTeam function
+//here starts stuff for sameTeam function copied from FormationController
#include "gametypes/TeamDeathmatch.h"
#include "gametypes/Gametype.h"
#include "controllers/DroneController.h"
@@ -38,32 +38,47 @@
namespace orxonox
{
- RegisterClass( CommonController );
+ RegisterClass(CommonController);
- CommonController::CommonController( Context* context ): Controller( context )
+ CommonController::CommonController(Context* context): Controller(context)
{
- RegisterObject( CommonController );
+ RegisterObject(CommonController);
}
CommonController::~CommonController()
{
-
+ //no member variables - nothing to destroy
}
-
- float CommonController::randomInRange( float a, float b )
+ /**
+ @brief
+ PRE: a < b.
+ returns random float between a and b.
+ */
+ float CommonController::randomInRange(float a, float b)
{
return a + rnd(1.0f) * (b - a);
}
- float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
+ /**
+ @brief
+ returns distance between two entities, if either is zero pointer, returns infinity
+ */
+ float CommonController::distance (const ControllableEntity* entity1, const ControllableEntity* entity2)
{
if (!entity1 || !entity2)
return std::numeric_limits<float>::infinity();
- return ( entity1->getPosition() - entity2->getPosition() ).length();
+ return (entity1->getPosition() - entity2->getPosition()).length();
}
+ /**
+ @brief
+ bad function from FormationController that returns true if both entities have same team
+ */
bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
{
+ //uncomment following code if functions stops working due to being a hack
/*if (!entity1 || !entity2)
return false;
return entity1->getTeam() == entity2->getTeam();*/
+ if (!entity1 || !entity2)
+ return false;
if (entity1 == entity2)
return true;
@@ -160,7 +175,7 @@
if (entity2->getPlayer())
team2 = dynamic->getParty(entity2->getPlayer());
- if (team1 ==-1 ||team2 ==-1 ) {return false;}
+ if (team1 ==-1 ||team2 ==-1) {return false;}
else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
@@ -169,15 +184,23 @@
return (team1 == team2 && team1 != -1);
}
- bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )
+ /**
+ @brief
+ returns true if entityThatLooks does look at entityBeingLookeAt with a tolerance of angle.
+ */
+ bool CommonController::isLooking(const ControllableEntity* entityThatLooks, const ControllableEntity* entityBeingLookedAt, float angle)
{
- if ( !entityThatLooks || !entityBeingLookedAt )
+ if (!entityThatLooks || !entityBeingLookedAt)
return false;
- return ( getAngle( entityThatLooks ->getPosition() ,
+ return (getAngle(entityThatLooks ->getPosition() ,
entityThatLooks->getOrientation() * WorldEntity::FRONT,
- entityBeingLookedAt->getWorldPosition() ) < angle );
+ entityBeingLookedAt->getWorldPosition()) < angle);
}
- std::string CommonController::getName(Pawn* entity)
+ /**
+ @brief
+ returns a name of a Pawn entity, if no name set, returns string representing address of the Pawn.
+ */
+ std::string CommonController::getName(const Pawn* entity)
{
std::string name = entity->getName();
if (name == "")
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-12-07 15:06:37 UTC (rev 10946)
@@ -30,31 +30,30 @@
#define _CommonController_H__
-#include "controllers/Controller.h"
-#include <limits>
+#include "controllers/Controller.h" //that's what I inherit from
-#include "worldentities/ControllableEntity.h"
-#include "worldentities/pawns/Pawn.h"
+#include <limits> //I use limits pretty much in every class, so might as well include it in the parent class
+#include "worldentities/ControllableEntity.h" //same for ControllableEntity
+#include "worldentities/pawns/Pawn.h" //and Pawn
+
namespace orxonox
{
class _OrxonoxExport CommonController : public Controller
{
public:
- static const float ACTION_INTERVAL = 1.0f;
+ static const float hardcoded_projectile_speed = 750; //<! FightingController uses it to predict enemy position
- static const float hardcoded_projectile_speed = 750;
-
CommonController(Context* context);
virtual ~CommonController();
static float randomInRange(float a, float b);
- static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
+ static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);
static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
- static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
- static std::string getName( Pawn* entity ) ;
+ static bool isLooking(const ControllableEntity* entityThatLooks, const ControllableEntity* entityBeingLookedAt, float angle ) ;
+ static std::string getName(const Pawn* entity ) ;
};
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-12-07 15:06:37 UTC (rev 10946)
@@ -69,7 +69,7 @@
}
void DivisionController::action()
{
- if (!this || !this->getControllableEntity())
+ if (!this || !this->getControllableEntity() || !this->isActive())
return;
ActionpointController::action();
Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-12-07 15:06:37 UTC (rev 10946)
@@ -8,7 +8,7 @@
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
- * of the License, or ( at your option )any later version.
+ * of the License, or (at your option)any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,12 +26,14 @@
* ...
*
*/
+#include <OgreMatrix3.h> //for Quaternion manipulations
+
+#include "util/Math.h"
+#include "core/XMLPort.h"
#include "controllers/FlyingController.h"
-#include "core/XMLPort.h"
-#include "worldentities/pawns/SpaceShip.h"
-#include "util/Math.h"
-#include <OgreMatrix3.h>
+#include "worldentities/pawns/SpaceShip.h" //for boosting
+
namespace orxonox
{
RegisterClass (FlyingController);
@@ -59,19 +61,19 @@
const std::string valUpper = getUppercase(val);
FormationMode::Value value;
- if ( valUpper == "WALL" )
+ if (valUpper == "WALL")
value = FormationMode::WALL;
- else if ( valUpper == "FINGER4" )
+ else if (valUpper == "FINGER4")
value = FormationMode::FINGER4;
- else if ( valUpper == "DIAMOND" )
+ else if (valUpper == "DIAMOND")
value = FormationMode::DIAMOND;
else
- ThrowException(ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'.");
+ ThrowException(ParseError, std::string("Attempting to set an unknown FormationMode: '")+ val + "'.");
this->setFormationMode(value);
}
std::string FlyingController::getFormationModeXML() const
{
- switch ( this->formationMode_ )
+ switch (this->formationMode_)
{
case FormationMode::WALL:
{ return "WALL"; }
@@ -87,40 +89,65 @@
{
this->bHasTargetPosition_ = false;
}
+ /**
+ @brief
+ if distance to targetPosition is smaller than this->tolerance_, no moving should be made, otherwise
+ find amount of yaw and pitch that have to be applied, so that ship looks at targetPosition, then
+ ship is moved forward towards targetPosition. Also target orientation is being applied.
+ */
void FlyingController::moveToPosition(const Vector3& targetPosition, float dt)
{
if (!this->getControllableEntity())
return;
ControllableEntity* entity = this->getControllableEntity();
- float distance = ( targetPosition - entity->getPosition() ).length();
+ float distance = (targetPosition - entity->getPosition()).length();
- if ( distance >= this->tolerance_ )
+ if (distance >= this->tolerance_)
{
+ //function that calculates how much yaw and pitch are to be applied
Vector2 coord = get2DViewCoordinates
- ( entity->getPosition() ,
+ (entity->getPosition() ,
entity->getOrientation() * WorldEntity::FRONT,
entity->getOrientation() * WorldEntity::UP,
- targetPosition );
- float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
- float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
- entity->rotateYaw( ROTATEFACTOR * rotateX * dt );
- entity->rotatePitch( ROTATEFACTOR * rotateY * dt );
-
+ targetPosition);
+ //limit yaw and pitch by [-1,1]
+ float rotateX = -clamp(coord.x * 10, -1.0f, 1.0f);
+ float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
+
+ if (!entity)
+ return;
+
+ //apply yaw and pitch
+ entity->rotateYaw(ROTATEFACTOR * rotateX * dt);
+ entity->rotatePitch(ROTATEFACTOR * rotateY * dt);
+
+ if (!entity)
+ return;
+
+ //only move either if ship looks at target with a certain tolerance, or if ship is far enough for it to be ok to move in a curve.
if (distance > this->tolerance_*1.5f || (rotateX > -0.03 && rotateX < 0.03 && rotateY > -0.03 && rotateY < 0.03))
- entity->moveFrontBack( SPEED * dt );
- copyTargetOrientation(dt);
+ entity->moveFrontBack(SPEED * dt);
+ //roll
+ copyTargetOrientation(dt);
}
else
{
bHasTargetPosition_ = false;
}
}
-
+ /**
+ @brief
+ fly towards a preset targetPosition_
+ */
void FlyingController::moveToTargetPosition(float dt)
{
this->moveToPosition (this->targetPosition_, dt);
}
+ /**
+ @brief
+ roll ship so that it has same roll as orient
+ */
void FlyingController::copyOrientation(const Quaternion& orient, float dt)
{
//copied from
@@ -154,7 +181,10 @@
this->getControllableEntity()->rotateRoll ((rollDelta.valueRadians() - rollMy.valueRadians())*ROTATEFACTOR*dt);
}
}
-
+ /**
+ @brief
+ roll ship so that it has same roll as a preset targetOrientation_
+ */
void FlyingController::copyTargetOrientation(float dt)
{
if (bHasTargetOrientation_)
@@ -162,31 +192,44 @@
this->copyOrientation(targetOrientation_, dt);
}
}
-
+ /**
+ @brief
+ set Vector to fly to
+ */
void FlyingController::setTargetPosition(const Vector3& target)
{
this->targetPosition_ = target;
this->bHasTargetPosition_ = true;
}
-
+ /**
+ @brief
+ set orientation to apply
+ */
void FlyingController::setTargetOrientation(const Quaternion& orient)
{
this->targetOrientation_=orient;
this->bHasTargetOrientation_=true;
}
-
+ /**
+ @brief
+ set orientation to apply
+ */
void FlyingController::setTargetOrientation(ControllableEntity* target)
{
if (target)
this->setTargetOrientation(target->getOrientation());
}
+ /**
+ @brief
+ boost if you can
+ */
void FlyingController::boostControl()
{
if (!this->getControllableEntity())
return;
SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
if(ship == NULL) return;
- if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
+ if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower()) //upper limit ->boost
{
this->getControllableEntity()->boost(true);
}
@@ -195,8 +238,14 @@
this->getControllableEntity()->boost(false);
}
}
+ /**
+ @brief
+ keep this ship in a formation with its division
+ */
void FlyingController::keepFormation(const ControllableEntity* leaderEntity, Vector3& targetRelativePosition)
{
+ if (!this->getControllableEntity())
+ return;
ControllableEntity* myEntity = this->getControllableEntity();
Vector3 myPosition = myEntity->getWorldPosition();
@@ -211,20 +260,26 @@
{
return;
}
+ //calculate where in world coordinates this ship should fly
Vector3 targetAbsolutePosition =
(leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
+ (orient* (targetRelativePosition)));
- //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
+ //let ship finish rotating. also don't call copyOrientation too often as it is a slow function. Don't know how to do it different
if (static_cast<int>(rnd(1.0f) * 100) % 3 == 0)
this->setTargetOrientation (orient);
+ //set a position to fly to
this->setTargetPosition (targetAbsolutePosition);
+
+ //boost if too far
if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
{
this->boostControl();
}
else
{
- this->getControllableEntity()->boost(false);
+ if (!this->getControllableEntity())
+ return;
+ this->getControllableEntity()->boost(false);
}
}
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h 2015-12-07 15:06:37 UTC (rev 10946)
@@ -38,6 +38,8 @@
@brief
FlyingController stores all the flying methods and member variables of AI.
*/
+
+ //Formation mode for the divisions
namespace FormationMode
{
enum Value
@@ -50,16 +52,16 @@
{
public:
- static const float SPEED = 0.9f/0.02f;
- static const float ROTATEFACTOR = 0.6f/0.02f;
+ static const float SPEED = 0.9f/0.02f; //<! ship's speed
+ static const float ROTATEFACTOR = 0.6f/0.02f; //<! ship's rotation factor
FlyingController(Context* context);
virtual ~FlyingController();
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
- void setSpread (int spread)
+ void setSpread (int spread) //<! spread is a multiplier for formation flight, should be bigger than 100
{ this->spread_ = spread; }
- int getSpread () const
+ int getSpread () const
{ return this->spread_; }
void setFormationModeXML(std::string val);
@@ -71,29 +73,30 @@
{ return this->formationMode_; }
protected:
- void stopMoving();
+ void stopMoving(); //<! don't call moveToTargetPosition() in tick, call lookAtTarget() from FightingController instead
- void moveToPosition(const Vector3& target, float dt);
- void moveToTargetPosition(float dt);
+ void moveToPosition(const Vector3& target, float dt); //<! move towards a vector
+ void moveToTargetPosition(float dt); //<! move to the preset position. Don't mix with positionOfTarget!
- void copyOrientation(const Quaternion& orient, float dt);
- void copyTargetOrientation(float dt);
+ void copyOrientation(const Quaternion& orient, float dt); //<! roll to have same roll as orient
+ void copyTargetOrientation(float dt); //<! roll to have a preset orient
- void setTargetPosition(const Vector3& target);
- void setTargetOrientation(const Quaternion& orient);
- void setTargetOrientation(ControllableEntity* target);
- virtual void boostControl();
- void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition);
+ void setTargetPosition(const Vector3& target); //<! preset a Vector to fly to
+ void setTargetOrientation(const Quaternion& orient); //<! preset a desired orientation
+ void setTargetOrientation(ControllableEntity* target); //<! preset a desired orientation
+ virtual void boostControl(); //<! boost if you can
+ void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition); //<! preset targetPosition, so that
+ //<! this stays in a certain position relative to leader
FormationMode::Value formationMode_;
- float rotationProgress_; //<! for slerp
+ float rotationProgress_; //<! for slerping
bool bHasTargetPosition_;
- Vector3 targetPosition_;
+ Vector3 targetPosition_; //<! vector to fly to
bool bHasTargetOrientation_;
- Quaternion targetOrientation_;
- int spread_;
- int tolerance_;
+ Quaternion targetOrientation_; //<! orientation to take
+ int spread_; //<! spread is a multiplier for formation flight, should be bigger than 100
+ int tolerance_; //<! if this ship is tolerance_ away from targetPosition_, ship decides that it finished moving
};
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-12-07 15:06:37 UTC (rev 10946)
@@ -72,7 +72,7 @@
void SectionController::action()
{
- if (!this || !this->getControllableEntity())
+ if (!this || !this->getControllableEntity() || !this->isActive())
return;
//----If no leader, find one----
Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-12-07 15:03:07 UTC (rev 10945)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-12-07 15:06:37 UTC (rev 10946)
@@ -72,7 +72,7 @@
//----action for hard calculations----
void WingmanController::action()
{
- if (!this || !this->getControllableEntity())
+ if (!this || !this->getControllableEntity() || !this->isActive())
return;
//----If no leader, find one----
if (!this->myLeader_)
More information about the Orxonox-commit
mailing list