[Orxonox-commit 6296] r10953 - in code/branches/campaignHS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Mon Dec 7 20:42:03 CET 2015
Author: gania
Date: 2015-12-07 20:42:03 +0100 (Mon, 07 Dec 2015)
New Revision: 10953
Modified:
code/branches/campaignHS15/data/levels/AITest.oxw
code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt
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/FightingController.cc
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
code/branches/campaignHS15/src/orxonox/controllers/FormationController.cc
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
Log:
converted hack to a legal class
Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/data/levels/AITest.oxw 2015-12-07 19:42:03 UTC (rev 10953)
@@ -37,7 +37,12 @@
<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="2000, 2000, 2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
-
+ <Pawn position = "100000, 100000, 100000">
+ <controller>
+ <MasterController>
+ </MasterController>
+ </controller>
+ </Pawn>
<!--
<PickupSpawner pickup=largedamageboostpickup position="0,0,0" triggerDistance="20" respawnTime="30" maxSpawnedItems="10" />
<PickupSpawner pickup=crazyhealthpickup position="0,0,0" triggerDistance="50" respawnTime="30" maxSpawnedItems="10" />
Modified: code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw 2015-12-07 19:42:03 UTC (rev 10953)
@@ -1025,7 +1025,13 @@
</collisionShapes>
</Pawn>
<!--SHIPS -->
-
+ <!-- one Controller to rule them all -->
+ <Pawn position = "100000, 100000, 100000">
+ <controller>
+ <MasterController>
+ </MasterController>
+ </controller>
+ </Pawn>
<!--Allied units-->
<?lua
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-12-07 19:42:03 UTC (rev 10953)
@@ -31,7 +31,6 @@
#include "core/XMLPort.h"
#include <algorithm>
#include "worldentities/Actionpoint.h"
-
namespace orxonox
{
@@ -39,9 +38,6 @@
ActionpointController::ActionpointController(Context* context) : FightingController(context)
{
- this->actionpointControllerId_ = 0;
- ActionpointController::sTicks_ = 0;
- ActionpointController::nextActionpointControllerId_ = 0;
this->ticks_ = 0;
this->bPatrolling_ = false;
this->bInLoop_ = false;
@@ -74,35 +70,22 @@
loopActionpoints_.clear();
parsedActionpoints_.clear();
actionpoints_.clear();
- this->actionpointControllerId_ = 0;
}
void ActionpointController::tick(float dt)
{
if (!this || !this->getControllableEntity() || !this->isActive() || this->stop_)
return;
+
++this->ticks_;
- // orxout (internal_error) << "this id = " << this->actionpointControllerId_ << endl;
- if (ActionpointController::sTicks_ < this->ticks_)
+ if (this->ticks_ == 1)
{
- // orxout (internal_error) << "total id's = " << ActionpointController::nextActionpointControllerId_ << endl;
- ++ActionpointController::sTicks_;
- }
-
- if (!this || !this->getControllableEntity())
- return;
-
- if (ActionpointController::sTicks_ == 1)
- {
-
- this->actionpointControllerId_ = ActionpointController::nextActionpointControllerId_++;
std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
std::reverse(actionpoints_.begin(), actionpoints_.end());
if (this->parsedActionpoints_.empty())
{
this->action_ = Action::FIGHTALL;
}
- //orxout (internal_error) << "first tick was called by id = " << this->actionpointControllerId_ << ", total = " << ActionpointController::nextActionpointControllerId_ << endl;
}
if (!this || !this->getControllableEntity())
@@ -112,8 +95,6 @@
{
this->moveToTargetPosition(dt);
}
- if (!this || !this->getControllableEntity())
- return;
else if (this->bLookAtTarget_)
{
this->lookAtTarget(dt);
@@ -124,22 +105,18 @@
return;
if (timeout_ <= 0)
+ {
this->bFiredRocket_ = false;
-
-
- if (!this || !this->getControllableEntity())
- return;
- if (this->timeout_ > 0 && this->bFiredRocket_)
+ }
+ else if (this->bFiredRocket_)
{
--this->timeout_;
}
-
if (!this || !this->getControllableEntity())
return;
- //maneuver every 0.25 sec ->
- int step = 4;
- if (ActionpointController::sTicks_ % 100 <= 10)
+
+ if (this->ticks_ % 80 <= 10)
{
this->bDodge_ = false;
}
@@ -147,44 +124,14 @@
{
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;
- this->action();
- }
-
if (!this || !this->getControllableEntity())
return;
- /* orxout (internal_error) << "id = " << this->actionpointControllerId_ << ", in total # ids = " << ActionpointController::nextActionpointControllerId_
- << ", I " << (this->hasTarget() ? "have" : "don't have") << " a target, my team is " << this->getControllableEntity()->getTeam() << endl;
- */ if (this->hasTarget() && ActionpointController::sTicks_ % (ActionpointController::nextActionpointControllerId_ + 1) == (this->actionpointControllerId_))
+
+ if (this->bShooting_)
{
-
-
- if (!this || !this->getControllableEntity())
- return;
- this->maneuver();
- if (!this || !this->getControllableEntity())
- return;
- this->bShooting_ = this->canFire();
-
- if (!this || !this->getControllableEntity())
- return;
-
- if (this->bShooting_)
- {
- 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();
+ this->doFire();
}
-
-
SUPER(ActionpointController, tick, dt);
}
@@ -192,9 +139,11 @@
void ActionpointController::action()
{
- if (!this || !this->getControllableEntity())
+ if (!this || !this->getControllableEntity() || !this->isActive())
return;
+ this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
+ this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
{
this->startAttackingEnemiesThatAreClose();
@@ -797,6 +746,4 @@
}
}
}
- unsigned int ActionpointController::nextActionpointControllerId_ = 0;
- unsigned int ActionpointController::sTicks_ = 0;
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-12-07 19:42:03 UTC (rev 10953)
@@ -35,7 +35,9 @@
#include "../modules/pickup/PickupSpawner.h"
#include <map>
+#include <boost/shared_ptr.hpp>
+
namespace orxonox
{
/**
@@ -245,11 +247,8 @@
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 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
+
};
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt 2015-12-07 19:42:03 UTC (rev 10953)
@@ -17,4 +17,5 @@
ActionpointController.cc
FlyingController.cc
FightingController.cc
+ MasterController.cc
)
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-12-07 19:42:03 UTC (rev 10953)
@@ -39,7 +39,6 @@
{
RegisterClass(CommonController);
-
CommonController::CommonController(Context* context): Controller(context)
{
RegisterObject(CommonController);
@@ -92,6 +91,8 @@
controller = entity1->getXMLController();
if (controller)
{
+ if (controller->getIdentifier()->getName() == "MasterController")
+ return true;
CommonController* ac = orxonox_cast<CommonController*>(controller);
if (ac)
team1 = ac->getTeam();
@@ -103,6 +104,8 @@
controller = entity2->getXMLController();
if (controller)
{
+ if (controller->getIdentifier()->getName() == "MasterController")
+ return true;
CommonController* ac = orxonox_cast<CommonController*>(controller);
if (ac)
team2 = ac->getTeam();
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-12-07 19:42:03 UTC (rev 10953)
@@ -48,7 +48,7 @@
CommonController(Context* context);
virtual ~CommonController();
-
+ virtual void action(){}; //<! action() is called in regular intervals managing the bot's behaviour.
static float randomInRange(float a, float b);
static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);
static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-12-07 19:42:03 UTC (rev 10953)
@@ -64,6 +64,7 @@
{
if (!this->isActive())
return;
+
SUPER(DivisionController, tick, dt);
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc 2015-12-07 19:42:03 UTC (rev 10953)
@@ -142,7 +142,7 @@
}
else
{
- bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
+ bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f)
|| this->deltaHp < 0;
this->bKeepFormation_ = false;
@@ -219,7 +219,7 @@
this->setPositionOfTarget(newPositionOfTarget);
}
- return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 10.0f);
+ return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.h 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.h 2015-12-07 19:42:03 UTC (rev 10953)
@@ -54,7 +54,11 @@
ControllableEntity* getTarget() const
{ return this->target_; }
bool bKeepFormation_; //even if action_ == FIGHT, you might still want to keep formation if far enough form the target
-
+ virtual void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on
+ //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.
+ bool bShooting_;
+ bool canFire(); //<! check if target_ is in radius and if this is looking at target_
+
protected:
void setTarget(ControllableEntity* target); //set a target to shoot at
@@ -64,13 +68,10 @@
void startLookingAtTarget(); //<! if close to target, no need to fly, just rotate yourself
void lookAtTarget(float dt); //<! rotate yourself towards target
- void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on
- //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.
void dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between
//<! this and target_ plus or minus some amount in difference vector direction,
//<! depending on whether it is better to close up or survive.
void dodgeTowards (Vector3& position); //fly towards position and awoid being hit
- bool canFire(); //<! check if target_ is in radius and if this is looking at target_
void doFire(); //<! choose weapon, set aim at target_ and fire
WeakPtr<ControllableEntity> target_;
void setClosestTarget();
@@ -83,7 +84,6 @@
bool bDodge_;
int attackRange_;
- bool bShooting_;
bool bLookAtTarget_;
float deltaHp;
float previousHp;
Modified: code/branches/campaignHS15/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FormationController.cc 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/FormationController.cc 2015-12-07 19:42:03 UTC (rev 10953)
@@ -969,6 +969,8 @@
controller = entity1->getXMLController();
if (controller)
{
+ if (controller->getIdentifier()->getName() == "MasterController")
+ return true;
FormationController* ac = orxonox_cast<FormationController*>(controller);
if (ac)
team1 = ac->getTeam();
@@ -980,6 +982,8 @@
controller = entity2->getXMLController();
if (controller)
{
+ if (controller->getIdentifier()->getName() == "MasterController")
+ return true;
FormationController* ac = orxonox_cast<FormationController*>(controller);
if (ac)
team2 = ac->getTeam();
Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-12-07 16:29:43 UTC (rev 10952)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-12-07 19:42:03 UTC (rev 10953)
@@ -94,10 +94,7 @@
}
if (!this->myLeader_)
{
- ActionpointController::action();
- if (!this || !this->getControllableEntity())
- return;
-
+ ActionpointController::action();
}
else if (this->myLeader_)
{
More information about the Orxonox-commit
mailing list