[Orxonox-commit 6227] r10885 - in code/branches/campaignHS15: data/levels src/orxonox/controllers src/orxonox/worldentities
gania at orxonox.net
gania at orxonox.net
Sat Nov 28 22:30:56 CET 2015
Author: gania
Date: 2015-11-28 22:30:56 +0100 (Sat, 28 Nov 2015)
New Revision: 10885
Modified:
code/branches/campaignHS15/data/levels/AITest.oxw
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/DivisionController.h
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.cc
code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h
Log:
added other weapons
Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-28 21:30:56 UTC (rev 10885)
@@ -31,7 +31,7 @@
>
<Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
- <TeamSpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
+ <TeamSpawnPoint team=0 position="-5000, 3000, -2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
<!-- HERE STARTS DEMO FOR THE "WAYPOINTS" -->
<!--
@@ -126,16 +126,14 @@
<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
<!-- HERE STARTS DEMO FOR FIGHTING -->
- <!--
+
<SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
<templates>
<Template link=spaceshipassff />
</templates>
<controller>
<DivisionController team=0 formationMode="WALL">
- <actionpoints>
- <Actionpoint position="0,0,0" action="ATTACK" attack="ss3" />
- </actionpoints>
+
</DivisionController>
</controller>
</SpaceShip>
@@ -166,16 +164,34 @@
</WingmanController>
</controller>
</SpaceShip>
+ <SpaceShip position="-4000, 1500, -3000" lookat="0,0,0" team=0>
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
+ <DivisionController team=0 formationMode="WALL">
- <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 name="ss3">
+ </DivisionController>
+ </controller>
+ </SpaceShip>
+ <SpaceShip position="-4000, 1900, -3000" lookat="0,0,0" team=0>
<templates>
<Template link=spaceshipassff />
</templates>
<controller>
+ <SectionController team=0>
+ </SectionController>
+ </controller>
+ </SpaceShip>
+
+
+ <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 >
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
<DivisionController team=1 formationMode="WALL">
- <actionpoints>
- <Actionpoint position="0,0,0" action="ATTACk" attack="ss2" />
- </actionpoints>
+
</DivisionController>
</controller>
</SpaceShip>
@@ -206,10 +222,30 @@
</WingmanController>
</controller>
</SpaceShip>
- -->
+ <SpaceShip position="2000, -1500, 3000" lookat="0,0,0" team=1>
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
+ <DivisionController team=1 formationMode="WALL">
+
+ </DivisionController>
+ </controller>
+ </SpaceShip>
+ <SpaceShip position="2000, -1900, 3000" lookat="0,0,0" team=1>
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
+ <SectionController team=1>
+ </SectionController>
+ </controller>
+ </SpaceShip>
+
+
<!-- HERE ENDS DEMO FOR FIGHTING -->
<!-- HERE STARTS DEMO FOR FORMATIONS -->
-
+ <!--
<Model mesh="cube.mesh" scale=8 position=" 0,2000, 0" />
<Model mesh="cube.mesh" scale=8 position=" 0,2000,-2000" />
<Model mesh="cube.mesh" scale=8 position="2000,2000,-2000" />
@@ -258,10 +294,10 @@
</WingmanController>
</controller>
</SpaceShip>
-
+ -->
<!-- HERE ENDS DEMO FOR FORMATIONS -->
<!--
- <SpaceShip position="2000, 2000, 2000" lookat="0,0,0" team=1 name="ss2">
+ <SpaceShip position="-2000, 3000, -2000" lookat="0,0,0" team=1 name="ss2">
<templates>
<Template link=spaceshipassff />
</templates>
@@ -271,8 +307,8 @@
</DivisionController>
</controller>
</SpaceShip>
-
-->
+
</Scene>
</Level>
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * ...
*
*/
@@ -60,6 +60,13 @@
}
void ActionpointController::tick(float dt)
{
+ if (this->timeout_ > 0 && this->bFiredRocket_)
+ {
+ this->timeout_ -= dt;
+ }
+ if (timeout_ <= 0)
+ this->bFiredRocket_ = false;
+
if (this->bHasTargetPosition_)
{
this->moveToTargetPosition(dt);
@@ -68,7 +75,7 @@
{
this->lookAtTarget(dt);
}
- if (bShooting_)
+ if (this->bShooting_)
{
this->doFire();
}
@@ -536,7 +543,7 @@
this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
}
- void ActionpointController::takeActionpoints (std::vector<Point > vector, std::vector<Point > loop, bool b)
+ void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
{
this->parsedActionpoints_ = vector;
this->loopActionpoints_ = loop;
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
* ...
*
@@ -54,21 +54,21 @@
class _OrxonoxExport ActionpointController : public FightingController, public Tickable
{
public:
- //----[language demanded functions]----
- ActionpointController(Context* context);
- virtual ~ActionpointController();
- //----[language demanded functions]----
- virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ ActionpointController(Context* context);
+ virtual ~ActionpointController();
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
- virtual void tick(float dt);
+ virtual void tick(float dt);
+
void addActionpoint(WorldEntity* waypoint);
WorldEntity* getActionpoint(unsigned int index) const;
virtual void stayNearProtect();
virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
- virtual void takeActionpoints (std::vector<Point > vector, std::vector<Point > loop, bool b);
- Action::Value getAction ();
- std::string getActionName();
+ virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b);
+ virtual Action::Value getAction ();
+ virtual std::string getActionName();
+
void setAction (Action::Value action);
void setAction (Action::Value action, ControllableEntity* target);
void setAction (Action::Value action, const Vector3& target);
@@ -82,10 +82,12 @@
{ return false; }
virtual bool hasFollower()
{ return true; }
-
+
protected:
- void startAttackingEnemiesThatAreClose();
-
+ void startAttackingEnemiesThatAreClose();
+ WeakPtr<ActionpointController> myWingman_;
+ WeakPtr<ActionpointController> myFollower_;
+ WeakPtr<ActionpointController> myDivisionLeader_;
//----[Actionpoint information]----
Action::Value action_;
std::string protectName_;
@@ -102,15 +104,16 @@
void setProtect (ControllableEntity* protect);
ControllableEntity* getProtect ();
WeakPtr<ControllableEntity> protect_;
-
+ void fillLoop();
+ void fillLoopReversed();
+ void moveBackToTop();
void setClosestTarget();
Pawn* closestTarget();
//----[Actionpoint methods]----
void executeActionpoint();
void nextActionpoint();
- void fillLoop();
- void fillLoopReversed();
- void moveBackToTop();
+ void pushAction(Point& p);
+ void popAction();
//----[Actionpoint methods]----
bool bFirstTick_;
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
* Dominik Solenicki
*
@@ -51,10 +51,7 @@
float CommonController::randomInRange( float a, float b )
{
- float random = rnd( 1.0f );
- float diff = b - a;
- float r = random * diff;
- return a + r;
+ return a + rnd(1.0f) * (b - a);
}
float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
{
@@ -192,6 +189,4 @@
}
return name;
}
-
-
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * ...
+ * Dominik Solenicki
*
*/
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * ...
*
*/
@@ -95,13 +95,13 @@
ActionpointController::stayNearProtect();
}
- bool DivisionController::setWingman(ActionpointController* wingman)
+ bool DivisionController::setWingman(ActionpointController* newWingman)
{
-
- WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
if (!this->myWingman_)
{
this->myWingman_ = newWingman;
+ if (!this->hasFollower())
+ newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
return true;
}
else
@@ -109,9 +109,8 @@
return false;
}
}
- bool DivisionController::setFollower(ActionpointController* myFollower)
+ bool DivisionController::setFollower(ActionpointController* newFollower)
{
- LeaderController* newFollower = orxonox_cast<LeaderController*> (myFollower);
if (!this->myFollower_)
{
this->myFollower_ = newFollower;
@@ -119,6 +118,9 @@
{
this->myWingman_->takeActionpoints (std::vector<Point>(), std::vector<Point>(), false);
}
+
+ newFollower->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
+
return true;
}
else
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * ...
*
*/
@@ -51,8 +51,8 @@
//----[orxonox demanded functions]----
//----[own functions]----
- virtual bool setFollower(ActionpointController* myFollower);
- virtual bool setWingman(ActionpointController* wingman);
+ virtual bool setFollower(ActionpointController* newFollower);
+ virtual bool setWingman(ActionpointController* newWingman);
virtual bool hasWingman();
virtual bool hasFollower();
Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * Fabian 'x3n' Landau, Dominik Solenicki
*
*/
#include "controllers/FightingController.h"
@@ -30,6 +30,13 @@
#include "util/Math.h"
+#include "worldentities/pawns/SpaceShip.h"
+
+#include "weaponsystem/WeaponMode.h"
+#include "weaponsystem/WeaponPack.h"
+#include "weaponsystem/Weapon.h"
+#include "weaponsystem/WeaponSlot.h"
+#include "weaponsystem/WeaponSlot.h"
namespace orxonox
{
@@ -37,9 +44,10 @@
FightingController::FightingController( Context* context ): FlyingController( context )
{
- this->attackRange_ = 2000;
+ this->attackRange_ = 3000;
this->stopLookingAtTarget();
-
+ this->bSetupWorked = false;
+ this->timeout_ = 0;
RegisterObject( FightingController );
}
FightingController::~FightingController()
@@ -77,7 +85,7 @@
{
this->bLookAtTarget_ = true;
}
- bool FightingController::hasTarget()
+ bool FightingController::hasTarget() const
{
if ( this->target_ )
return true;
@@ -105,27 +113,19 @@
void FightingController::maneuver()
{
+ if ( !this->target_ || !this->getControllableEntity())
+ return;
maneuverCounter_++;
if (maneuverCounter_ > 5)
maneuverCounter_ = 0;
- if ( !this->target_ || !this->getControllableEntity())
- return;
-
Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
- this->setPositionOfTarget( getPredictedPosition(
- thisPosition,
- hardcoded_projectile_speed,
- this->target_->getWorldPosition() ,
- this->target_->getVelocity()
- ) );
- this->setOrientationOfTarget( this->target_->getOrientation() );
-
+ this->setPositionOfTarget(this->target_->getWorldPosition());
+ //this->setOrientationOfTarget(this->target_->getOrientation());
Vector3 diffVector = this->positionOfTarget_ - thisPosition;
float diffLength = diffVector.length();
Vector3 diffUnit = diffVector/diffLength;
-
- bool bTargetIsLookingAtThis = CommonController::isLooking ( this->target_, getControllableEntity(), math::pi/20.0f );
+ bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f);
//too far? well, come closer then
if (diffLength > this->attackRange_)
@@ -134,29 +134,29 @@
this->formationMode_ = FormationMode::WALL;
this->bKeepFormation_ = true;
- this->setTargetPosition( this->positionOfTarget_ );
+ this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
}
//too close? How do u expect to dodge anything? Just attack!
- else if ( diffLength < 500 )
+ else if (diffLength < 500)
{
this->bKeepFormation_ = false;
//at this point, just look and shoot
- if ( diffLength < 250 )
+ if (diffLength < 250)
{
this->stopMoving();
this->startLookingAtTarget();
}
else
{
- this->setTargetPosition( this->positionOfTarget_ );
+ this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
}
}
//Good distance? Check if target looks at us. It doesn't? Go hunt!
- else if ( !bTargetIsLookingAtThis )
+ else if (!bTargetIsLookingAtThis)
{
this->bKeepFormation_ = false;
- this->setTargetPosition( this->positionOfTarget_ );
+ this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
}
//That's unfortunate, he is looking and probably shooting... try to dodge what we can...
else
@@ -164,104 +164,75 @@
this->bKeepFormation_ = false;
if (maneuverCounter_ == 0)
{
- this->setTargetPosition( this->positionOfTarget_ );
+ this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);
return;
}
- dodge( thisPosition, diffUnit );
+ dodge(thisPosition, diffUnit);
}
}
- void FightingController::dodge(Vector3& thisPosition, Vector3& diffUnit)
+ void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit)
{
- float factorX = 0, factorY = 0, factorZ = 0;
- float rand = CommonController::randomInRange (0, 1);
-
- if (rand <= 0.5)
- { factorX = 1; }
- else
- { factorX = -1; }
- rand = CommonController::randomInRange (0, 1);
- if (rand <= 0.5)
- { factorY = 1; }
- else
- { factorY = -1; }
- rand = CommonController::randomInRange (0, 1);
- if (rand <= 0.5)
- { factorZ = 1; }
- else
- { factorZ = -1; }
+ //d.x*x + d.y*y + d.z*z == 0
+ //z = 1/d.z * (-d.y*y - d.x * x)
+ float x = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
+ float y = CommonController::randomInRange (1000, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
+ float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
+ this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * 1000.0f);
+ this->boostControl();
- Vector3 target = ( diffUnit )* 8000.0f;
- Vector3* randVector = new Vector3(
- factorX * CommonController::randomInRange( 10000, 40000 ),
- factorY * CommonController::randomInRange( 10000, 40000 ),
- factorZ * CommonController::randomInRange( 10000, 40000 )
- );
- Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
- Vector3 randV = *randVector;
- delete randVector;
- randV -= projection;
- target += randV;
- this->setTargetPosition( thisPosition + target );
}
bool FightingController::canFire()
{
//no target? why fire?
- if ( !this->target_ )
+ if (!this->target_)
return false;
-
- Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() ,
- hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
- if ( newPositionOfTarget != Vector3::ZERO )
+ Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),
+ hardcoded_projectile_speed, this->target_->getWorldPosition(),
+ this->target_->getVelocity());
+ if (!newPositionOfTarget.isNaN())
{
- this->setPositionOfTarget( newPositionOfTarget );
+ this->setPositionOfTarget(newPositionOfTarget);
}
-
- float squaredDistance = squaredDistanceToTarget();
-
- if ( squaredDistance < this->attackRange_*this->attackRange_ && this->isLookingAtTarget( math::pi / 20.0f))
- {
- return true;
- }
- else
- {
- return false;
- }
+ return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
}
- void FightingController::doFire()
- {
- if ( !this->target_ || !this->getControllableEntity() )
- {
- return;
- }
+ // void FightingController::doFire()
+ // {
+ // if ( !this->target_ || !this->getControllableEntity() )
+ // {
+ // return;
+ // }
- Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
+ // Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
- if ( pawn )
- pawn->setAimPosition( this->positionOfTarget_ );
- this->getControllableEntity() ->fire( 0 );
- }
+ // if ( pawn )
+ // pawn->setAimPosition( this->positionOfTarget_ );
+ // float distance = CommonController::distance (this->getControllableEntity(), this->target_);
+ // this->getControllableEntity() ->fire(distance < 1500 ? (distance < 1000 && distance > 700 ? 3 : 0) : (1));
+ // }
+
+
float FightingController::squaredDistanceToTarget() const
{
- if ( !this->getControllableEntity() )
+ if (!this->getControllableEntity())
return 0;
- if ( !this->target_ || !this->getControllableEntity() )
- return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
+ if (!this->target_ || !this->getControllableEntity())
+ return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_));
else
- return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
+ return (this->getControllableEntity()->getPosition().squaredDistance(this->positionOfTarget_));
}
- bool FightingController::isLookingAtTarget( float angle )
+ bool FightingController::isLookingAtTarget( float angle ) const
{
if ( !this->getControllableEntity() || !this->target_ )
return false;
return CommonController::isLooking(this->getControllableEntity(), this->getTarget(), angle);
}
- void FightingController::setClosestTarget()
+ void FightingController::setClosestTarget()
{
this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) );
}
- Pawn* FightingController::closestTarget()
+ Pawn* FightingController::closestTarget() const
{
if (!this->getControllableEntity())
return 0;
@@ -287,4 +258,115 @@
}
return 0;
}
+ //I checked it out, rockets DO NOT cause any problems! this->getControllableEntity() is always a SpaceShip
+ void FightingController::doFire()
+ {
+ if (!this->bSetupWorked)
+ {
+ this->setupWeapons();
+ }
+ if (!this->target_ || !this->getControllableEntity())
+ {
+ return;
+ }
+ Pawn* pawn = orxonox_cast<Pawn*> (this->getControllableEntity());
+ if (pawn)
+ pawn->setAimPosition (this->positionOfTarget_);
+
+ int firemode;
+ float distance = CommonController::distance (this->getControllableEntity(), this->target_);
+
+ // firemode = distance < 1500 ? (distance > 800 && distance < 1200 ?
+ // (this->rocketsLeft_ > 0 && !this->bFiredRocket_ ? getFiremode("RocketFire") : getFiremode ("HsW01"))
+ // : getFiremode("HsW01")) :
+ // (distance < 2500 ? getFiremode("LightningGun") : getFiremode("HsW01"));
+ if (distance < 800)
+ {
+ if (this->rocketsLeft_ > 0)
+ {
+ firemode = getFiremode ("SimpleRocketFire");
+ }
+ else
+ {
+ if (distance > 450)
+ firemode = getFiremode ("LightningGun");
+ else
+ firemode = getFiremode ("HsW01");
+ }
+
+ }
+ else if (distance < 1200)
+ {
+ if (this->rocketsLeft_ > 0 && !this->bFiredRocket_)
+ {
+ firemode = getFiremode ("RocketFire");
+ }
+ else
+ {
+ firemode = getFiremode ("HsW01");
+ }
+ }
+ else if (distance < 1500)
+ {
+ firemode = getFiremode ("LightningGun");
+ }
+ else
+ {
+ firemode = getFiremode ("HsW01");
+ }
+ if (firemode < 0)
+ {
+ firemode = getFiremode ("HsW01");
+ }
+ if (firemode == getFiremode("RocketFire"))
+ {
+ this->timeout_ = 1.0f;
+ this->rocketsLeft_--;
+ this->bFiredRocket_ = true;
+ }
+ if (firemode == getFiremode("SimpleRocketFire"))
+ {
+ this->rocketsLeft_--;
+ }
+
+ this->getControllableEntity()->fire(firemode);
+
+ }
+ void FightingController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
+ {
+ this->bSetupWorked = false;
+ if(this->getControllableEntity())
+ {
+ Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+ if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip
+ {
+ this->weaponModes_.clear(); // reset previous weapon information
+ WeaponSlot* wSlot = 0;
+ for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++)
+ {
+ WeaponMode* wMode = 0;
+ for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++)
+ {
+ std::string wName = wMode->getIdentifier()->getName();
+ if (wName == "RocketFire")
+ this->rocketsLeft_ = 10;
+ if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new"
+ weaponModes_[wName] = wMode->getMode();
+ }
+ }
+ if(weaponModes_.size())//at least one weapon detected
+ this->bSetupWorked = true;
+ }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
+ }
+ }
+
+ int FightingController::getFiremode(std::string name)
+ {
+ for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
+ {
+ if (it->first == name)
+ return it->second;
+ }
+ return -1;
+ }
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * ...
+ * Fabian 'x3n' Landau, Dominik Solenicki
*
*/
@@ -44,9 +44,9 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
float squaredDistanceToTarget() const;
- bool isLookingAtTarget(float angle);
- bool hasTarget();
- ControllableEntity* getTarget()
+ bool isLookingAtTarget(float angle) const;
+ bool hasTarget() const;
+ ControllableEntity* getTarget() const
{ return this->target_; }
bool bKeepFormation_;
@@ -60,7 +60,7 @@
void lookAtTarget(float dt);
void maneuver();
- void dodge(Vector3& thisPosition, Vector3& diffUnit);
+ void dodge(const Vector3& thisPosition, Vector3& diffUnit);
bool canFire();
void doFire();
WeakPtr<ControllableEntity> target_;
@@ -70,12 +70,23 @@
Vector3 positionOfTarget_;
bool bHasOrientationOfTarget_;
Quaternion orientationOfTarget_;
- Pawn* closestTarget();
+ Pawn* closestTarget() const;
int attackRange_;
bool bShooting_;
int maneuverCounter_;
- bool bLookAtTarget_;
+ bool bLookAtTarget_;
+
+ //WEAPONSYSTEM DATA
+ int rocketsLeft_;
+ float timeout_;
+ bool bFiredRocket_;
+ std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
+ //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
+ void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
+ bool bSetupWorked; //<! If false, setupWeapons() is called.
+ int getFiremode(std::string name);
+
};
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,7 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
+
* Co-authors:
* Dominik Solenicki
*
@@ -30,32 +31,33 @@
#include "worldentities/pawns/SpaceShip.h"
#include "util/Math.h"
#include <OgreMatrix3.h>
+
namespace orxonox
{
RegisterClass (FlyingController);
- FlyingController::FlyingController( Context* context ): CommonController( context )
+ FlyingController::FlyingController(Context* context): CommonController(context)
{
+ RegisterObject(FlyingController);
this->rotationProgress_ = 0;
this->spread_ = 200;
- this->tolerance_ = 60;
- RegisterObject( FlyingController );
+ this->tolerance_ = 100;
}
FlyingController::~FlyingController()
{
}
- void FlyingController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
+ void FlyingController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
- XMLPortParam( FlyingController, "spread", setSpread, getSpread, xmlelement, mode );
- XMLPortParam( FlyingController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode );
- SUPER( FlyingController, XMLPort, xmlelement, mode );
+ XMLPortParam(FlyingController, "spread", setSpread, getSpread, xmlelement, mode);
+ XMLPortParam(FlyingController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode);
+ SUPER(FlyingController, XMLPort, xmlelement, mode);
}
- void FlyingController::setFormationModeXML( std::string val )
+ void FlyingController::setFormationModeXML(std::string val)
{
- const std::string valUpper = getUppercase( val );
+ const std::string valUpper = getUppercase(val);
FormationMode::Value value;
if ( valUpper == "WALL" )
@@ -65,10 +67,10 @@
else if ( valUpper == "DIAMOND" )
value = FormationMode::DIAMOND;
else
- ThrowException( ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'." );
- this->setFormationMode( value );
+ ThrowException(ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'.");
+ this->setFormationMode(value);
}
- std::string FlyingController::getFormationModeXML()
+ std::string FlyingController::getFormationModeXML() const
{
switch ( this->formationMode_ )
{
@@ -82,21 +84,16 @@
return "DIAMOND"; break;
}
}
-
-
-
void FlyingController::stopMoving()
{
this->bHasTargetPosition_ = false;
}
-
- void FlyingController::moveToPosition( const Vector3& target, float dt )
+ void FlyingController::moveToPosition(const Vector3& target, float dt)
{
ControllableEntity* entity = this->getControllableEntity();
- float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
+ float distance = ( target - entity->getPosition() ).length();
-
if ( distance >= this->tolerance_ )
{
Vector2 coord = get2DViewCoordinates
@@ -106,25 +103,24 @@
target );
float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
- this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
- this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
-
+ entity->rotateYaw( ROTATEFACTOR * rotateX * dt );
+ entity->rotatePitch( ROTATEFACTOR * rotateY * dt );
if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
- this->getControllableEntity() ->moveFrontBack( SPEED * dt );
+ entity->moveFrontBack( SPEED * dt );
+ copyTargetOrientation(dt);
}
else
{
bHasTargetPosition_ = false;
}
- copyTargetOrientation(dt);
}
void FlyingController::moveToTargetPosition(float dt)
{
this->moveToPosition (this->targetPosition_, dt);
}
- void FlyingController::copyOrientation( const Quaternion& orient, float dt )
+ void FlyingController::copyOrientation(const Quaternion& orient, float dt)
{
//inspired by
//http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Quaternion+and+Rotation+Primer&structure=Tutorials#Q._How_can_I_make_my_objects_rotate_smoothly_You_mentioned_slerp_etc_
@@ -166,30 +162,30 @@
}
//change log: increased precision, increased rotation speed
- void FlyingController::copyTargetOrientation( float dt )
+ void FlyingController::copyTargetOrientation(float dt)
{
- if ( bHasTargetOrientation_ )
+ if (bHasTargetOrientation_)
{
- copyOrientation( targetOrientation_, dt );
+ copyOrientation(targetOrientation_, dt);
}
}
- void FlyingController::setTargetPosition( const Vector3& target )
+ void FlyingController::setTargetPosition(const Vector3& target)
{
this->targetPosition_ = target;
this->bHasTargetPosition_ = true;
}
- void FlyingController::setTargetOrientation( const Quaternion& orient )
+ void FlyingController::setTargetOrientation(const Quaternion& orient)
{
this->targetOrientation_=orient;
this->bHasTargetOrientation_=true;
}
- void FlyingController::setTargetOrientation( ControllableEntity* target )
+ void FlyingController::setTargetOrientation(ControllableEntity* target)
{
- if ( target )
- setTargetOrientation( target->getOrientation() );
+ if (target)
+ setTargetOrientation(target->getOrientation());
}
void FlyingController::boostControl()
{
@@ -197,7 +193,6 @@
if(ship == NULL) return;
if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
{
-
this->getControllableEntity()->boost(true);
}
else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost
@@ -205,5 +200,4 @@
this->getControllableEntity()->boost(false);
}
}
-
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -55,11 +55,11 @@
void setSpread (int spread)
{ this->spread_ = spread; }
- int getSpread ()
+ int getSpread () const
{ return this->spread_; }
void setFormationModeXML(std::string val);
- std::string getFormationModeXML();
+ std::string getFormationModeXML() const;
void setFormationMode(FormationMode::Value val)
{ this->formationMode_ = val; }
Modified: code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * ...
*
*/
Modified: code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
* ...
*
@@ -30,7 +30,6 @@
#define _LeaderController_H__
#include "controllers/ActionpointController.h"
-#include "controllers/WingmanController.h"
@@ -50,10 +49,8 @@
protected:
//----private variables-----
- WeakPtr<WingmanController> myWingman_;
- WeakPtr<LeaderController> myFollower_;
- WeakPtr<LeaderController> myDivisionLeader_;
+
private:
Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * ...
*
*/
@@ -95,12 +95,12 @@
//----If no leader, find one----
if (!myDivisionLeader_)
{
- LeaderController* newDivisionLeader = findNewDivisionLeader();
+ ActionpointController* newDivisionLeader = findNewDivisionLeader();
this->myDivisionLeader_ = newDivisionLeader;
//spread copyOrientation called equally among the division
if (this->myDivisionLeader_)
{
- this->actionCounter_ = 8;
+ this->actionCounter_ = 5;
}
}
//----If have leader----
@@ -146,7 +146,7 @@
(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.
- if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
+ if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
this->setAction (Action::FLY, targetAbsolutePosition, orient);
else
this->setAction (Action::FLY, targetAbsolutePosition);
@@ -299,16 +299,16 @@
- LeaderController* SectionController::findNewDivisionLeader()
+ ActionpointController* SectionController::findNewDivisionLeader()
{
if (!this->getControllableEntity())
return 0;
- LeaderController* closestLeader = 0;
+ ActionpointController* closestLeader = 0;
float minDistance = std::numeric_limits<float>::infinity();
//go through all pawns
- for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it)
+ for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
{
//0ptr or not DivisionController?
if (!(it) || !((it)->getIdentifier()->getName() == "DivisionController") || !(it->getControllableEntity()))
@@ -337,13 +337,13 @@
}
return 0;
}
- bool SectionController::setWingman(ActionpointController* wingman)
+ bool SectionController::setWingman(ActionpointController* newWingman)
{
- WingmanController* newWingman = orxonox_cast<WingmanController*>(wingman);
if (!this->myWingman_)
{
this->myWingman_ = newWingman;
+ newWingman->takeActionpoints (this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);
return true;
}
else
Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * ...
*
*/
@@ -50,11 +50,12 @@
//----[/orxonox demanded functions]----
//----[own functions]----
- LeaderController* findNewDivisionLeader();
+ ActionpointController* findNewDivisionLeader();
- virtual bool setWingman(ActionpointController* wingman);
+ virtual bool setWingman(ActionpointController* newWingman);
virtual bool hasWingman();
-
+ virtual bool hasFollower()
+ { return false; }
void chooseTarget();
//----[/own functions]----
Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,9 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
- * Dominik Solenicki
+ * ...
*
*/
@@ -88,9 +88,9 @@
{
//spread copyOrientation called equally among the division
if (this->myLeader_->getIdentifier()->getName() == "SectionController")
- this->actionCounter_ = 2;
+ this->actionCounter_ = 1;
else
- this->actionCounter_ = 5;
+ this->actionCounter_ = 4;
}
}
//----If have leader, he will deal with logic----
@@ -125,7 +125,7 @@
(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.
- if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
+ if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_)
this->setAction (Action::FLY, targetAbsolutePosition, orient);
else
this->setAction (Action::FLY, targetAbsolutePosition);
Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
* ...
*
@@ -48,6 +48,10 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
virtual void tick(float dt);
+ virtual bool hasWingman()
+ { return false; }
+ virtual bool hasFollower()
+ { return false; }
//----[/orxonox demanded functions]----
//----[own functions]----
Modified: code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.cc 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.cc 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
* ...
*
Modified: code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h 2015-11-28 19:20:10 UTC (rev 10884)
+++ code/branches/campaignHS15/src/orxonox/worldentities/Actionpoint.h 2015-11-28 21:30:56 UTC (rev 10885)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Fabian 'x3n' Landau
+ * Gani Aliguzhinov
* Co-authors:
* ...
*
More information about the Orxonox-commit
mailing list