[Orxonox-commit 6255] r10912 - in code/branches/campaignHS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Tue Dec 1 19:03:33 CET 2015
Author: gania
Date: 2015-12-01 19:03:32 +0100 (Tue, 01 Dec 2015)
New Revision: 10912
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/DivisionController.cc
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
Log:
defaultPatrol and defaultFightAll XML commands
Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw 2015-12-01 16:52:53 UTC (rev 10911)
+++ code/branches/campaignHS15/data/levels/AITest.oxw 2015-12-01 18:03:32 UTC (rev 10912)
@@ -35,7 +35,7 @@
include("includes/pickups.oxi")
?>
<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="1500, 1500, 1500" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
+ <TeamSpawnPoint team=0 position="2000, 2000, 2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
<!--
<PickupSpawner pickup=largedamageboostpickup position="0,0,0" triggerDistance="20" respawnTime="30" maxSpawnedItems="10" />
@@ -52,7 +52,7 @@
<Template link=spaceshipassff />
</templates>
<controller>
- <DivisionController team=0 formationMode="finger4">
+ <DivisionController team=1 formationMode="finger4">
<actionpoints>
<Model mesh="cube.mesh" scale=8 position=" 0,2000,-600" />
<Model mesh="cube.mesh" scale=8 position=" 0,2000,-1000" />
@@ -306,27 +306,7 @@
</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 -->
<!--
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-12-01 16:52:53 UTC (rev 10911)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc 2015-12-01 18:03:32 UTC (rev 10912)
@@ -31,6 +31,7 @@
#include "core/XMLPort.h"
#include <algorithm>
#include "worldentities/Actionpoint.h"
+
namespace orxonox
{
@@ -54,14 +55,39 @@
this->bFirstTick_ = true;
this->bStartedDodging_ = false;
this->timeDodged_ = 0;
+ this->bDefaultPatrol_ = true;
+ this->bDefaultFightAll_ = true;
+ this->stop_ = false;
RegisterObject(ActionpointController);
}
void ActionpointController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
{
SUPER( ActionpointController, XMLPort, xmlelement, mode );
+ // XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
+ // XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
+
XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint, xmlelement, mode);
+ XMLPortParam(ActionpointController, "defaultFightAll", setDefaultFightAll, getDefaultFightAll, xmlelement, mode).defaultValues(true);
+ XMLPortParam(ActionpointController, "defaultPatrol", setDefaultPatrol, getDefaultPatrol, xmlelement, mode).defaultValues(true);
}
+ // void ActionpointController::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+ // {
+ // SUPER(ActionpointController, XMLEventPort, xmlelement, mode);
+ // XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
+ // XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
+
+ // }
+ // bool ActionpointController::stop(bool bTriggered, BaseObject* trigger)
+ // {
+ // this->stop_ = true;
+ // return true;
+ // }
+ // bool ActionpointController::go(bool bTriggered, BaseObject* trigger)
+ // {
+ // this->stop_ = false;
+ // return true;
+ // }
ActionpointController::~ActionpointController()
{
loopActionpoints_.clear();
@@ -73,7 +99,8 @@
}
void ActionpointController::tick(float dt)
{
-
+ if (stop_)
+ return;
if (this->timeout_ > 0 && this->bFiredRocket_)
{
this->timeout_ -= dt;
@@ -142,236 +169,19 @@
this->bManeuverCalled_ = false;
SUPER(ActionpointController, tick, dt);
}
- std::pair <ControllableEntity*, ControllableEntity*> ActionpointController::closestTargets()
- {
- WeakPtr<ControllableEntity> firstTarget, secondTarget, tempTarget;
- float firstDistance = std::numeric_limits<float>::infinity(), secondDistance = std::numeric_limits<float>::infinity(), tempDistance = 0;
- Gametype* gt = this->getGametype();
- for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
- {
- tempTarget = static_cast<ControllableEntity*>(*itP);
- if (CommonController::sameTeam (this->getControllableEntity(), tempTarget, gt))
- continue;
+
- tempDistance = CommonController::distance (*itP, this->getControllableEntity());
- if (tempDistance < firstDistance)
- {
- secondDistance = firstDistance;
- secondTarget = firstTarget;
- firstDistance = tempDistance;
- firstTarget = tempTarget;
- }
- else if (tempDistance < secondDistance)
- {
- secondDistance = tempDistance;
- secondTarget = tempTarget;
- }
- }
- return std::make_pair (firstTarget, secondTarget);
- }
-
- //patrol can only be called by divisionController or others if they don't have a leader
- //searches for closest enemy and sets target to it. If wasn't fighting, pushes Action::FIGHT on a stack.
- //patrol gets called constantly either if this is fighting or if this->bDefaultPatrol_ is set to true via XML
- bool ActionpointController::patrol()
- {
- std::pair <ControllableEntity*, ControllableEntity*> newTargets = this->closestTargets();
- if (!newTargets.first)
- return false;
- ControllableEntity* newTarget = newTargets.first;
-
- float distance = CommonController::distance (this->getControllableEntity(), newTarget);
- if (distance < this->attackRange_ && distance < CommonController::distance(this->getControllableEntity(), this->target_))
- {
- this->setTarget (newTarget);
-
- if (this->getIdentifier()->getName() == "DivisionController")
- {
- if (!newTargets.second)
- {
- if (this->myFollower_)
- this->myFollower_->setTarget(newTargets.first);
- }
- else
- {
- if (this->myFollower_ && CommonController::distance(this->getControllableEntity(), newTargets.second) < this->attackRange_ + 600.0f)
- this->myFollower_->setTarget(newTargets.second);
- else if (this->myFollower_)
- this->myFollower_->setTarget(newTargets.first);
- }
- }
- if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
- {
- this->bPatrolling_ = true;
- if (this->bLoop_)
- {
- Point p = { Action::FIGHT, "", Vector3::ZERO, true };
- this->loopActionpoints_.push_back(p);
- this->executeActionpoint();
- }
- else
- {
- Point p = { Action::FIGHT, "", Vector3::ZERO, false };
- this->parsedActionpoints_.push_back(p);
- this->executeActionpoint();
- }
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- //checks if state is still to be executed and makes a transition otherwise.
- //if this->bDefaultPatrol_ == true, patrols area for enemies and, if not fighting, pushes a state with action = FIGHT
- void ActionpointController::stateMachine()
- {
- //Check if calculations needed
- if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()) || !this->isActive())
- return;
-
- //state NONE means that either previous state finished executing and next state is to be fetched or no states are left to execute
- //NONE is never on a stack -> it is only a transition state saved in a variable
- if (this->action_ == Action::NONE || this->bTakenOver_)
- {
- //no actionpoints a.k.a. states left to execute
- if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
- {
- //default action is fighting
- if (this->bDefaultFightAll_)
- {
- //make state
- Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
- //push it on the stack
- this->parsedActionpoints_.push_back (p);
- }
- //default action is nothing
- else
- {
- this->bActive_ = false;
- return;
- }
- }
- //switch to the new state
- this->executeActionpoint();
- this->bTakenOver_ = false;
- }
- if (this->action_ == Action::FIGHTALL)
- {
- if (!this->hasTarget())
- {
- ControllableEntity* newTarget = this->closestTarget();
- if (newTarget)
- {
- this->setTarget (newTarget);
- }
- else
- {
- this->nextActionpoint();
- this->executeActionpoint();
- }
- }
- else
- {
- bool b = this->patrol();
- }
-
- }
- if (this->action_ == Action::FIGHT)
- {
- if (!this->hasTarget() )
- {
- if (!this->patrol())
- {
- if (this->bPatrolling_)
- {
- if (this->bLoop_)
- {
- if (!this->loopActionpoints_.empty())
- {
- this->loopActionpoints_.pop_back();
- }
- }
- else
- {
- if (!this->parsedActionpoints_.empty())
- {
- this->parsedActionpoints_.pop_back();
- }
- }
- this->setAction(Action::NONE);
- this->bHasTargetPosition_ = false;
- this->bPatrolling_ = false;
- }
- else
- {
- this->nextActionpoint();
- }
- this->executeActionpoint();
- }
- }
- else if (this->hasTarget())
- {
- if (CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
- {
- this->setTarget(0);
- this->stateMachine();
- }
- }
- }
- if (this->action_ == Action::FLY)
- {
- if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
- {
- this->nextActionpoint();
- this->executeActionpoint();
- }
- else if (this->bDefaultPatrol_)
- {
- bool b = this->patrol();
- }
- }
- if (this->action_ == Action::PROTECT)
- {
- if (!this->getProtect())
- {
- this->nextActionpoint();
- this->executeActionpoint();
- }
- else
- {
- this->stayNearProtect();
- }
- if (this->bDefaultPatrol_)
- {
- bool b = this->patrol();
- }
- }
- if (this->action_ == Action::ATTACK)
- {
- if (!this->hasTarget())
- {
- this->nextActionpoint();
- this->executeActionpoint();
- }
- if (this->bDefaultPatrol_)
- {
- bool b = this->patrol();
- }
- }
- }
-
-
-
void ActionpointController::action()
{
if (!this || !this->getControllableEntity())
return;
if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
return;
- this->startAttackingEnemiesThatAreClose();
+ if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
+ {
+ this->startAttackingEnemiesThatAreClose();
+ }
this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
@@ -387,14 +197,14 @@
// this->parsedActionpoints_.push_back(point);
// }
- if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
+ if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
{
Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
this->parsedActionpoints_.push_back (p);
}
this->executeActionpoint();
this->bTakenOver_ = false;
- this->action();
+ // this->action();
}
//Action fightall -> fight till nobody alive
if (this->action_ == Action::FIGHTALL)
Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-12-01 16:52:53 UTC (rev 10911)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h 2015-12-01 18:03:32 UTC (rev 10912)
@@ -35,6 +35,8 @@
#include "../modules/pickup/PickupSpawner.h"
#include <map>
+
+
namespace orxonox
{
/**
@@ -158,7 +160,20 @@
can try if feeling lucky.
*/
void addActionpoint(WorldEntity* actionpoint);
- WorldEntity* getActionpoint(unsigned int index) const;
+ WorldEntity* getActionpoint(unsigned int index) const;
+ void setDefaultFightAll(bool value)
+ { this->bDefaultFightAll_ = value; }
+ bool getDefaultFightAll ()
+ { return this->bDefaultFightAll_; }
+ void setDefaultPatrol(bool value)
+ { this->bDefaultPatrol_ = value; }
+ bool getDefaultPatrol ()
+ { return this->bDefaultPatrol_; }
+ // Trigger interface
+ // bool stop(bool bTriggered, BaseObject* trigger);
+ // bool go(bool bTriggered, BaseObject* trigger);
+ // virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+
virtual void stayNearProtect();
virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b);
@@ -179,10 +194,8 @@
{ return false; }
virtual bool hasFollower()
{ return true; }
- void stateMachine();
- bool patrol();
- std::pair <ControllableEntity*, ControllableEntity*> closestTargets();
+
protected:
void startAttackingEnemiesThatAreClose();
WeakPtr<ActionpointController> myWingman_;
@@ -242,9 +255,11 @@
bool bActionCalled_;
bool bManeuverCalled_;
bool bDefaultFightAll_;
+
bool bActive_;
bool bPatrolling_;
bool bDefaultPatrol_;
+ bool stop_;
private:
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-12-01 16:52:53 UTC (rev 10911)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-12-01 18:03:32 UTC (rev 10912)
@@ -59,7 +59,7 @@
void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(DivisionController, XMLPort, xmlelement, mode);
-
+
//XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
}
void DivisionController::tick(float dt)
Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-12-01 16:52:53 UTC (rev 10911)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-12-01 18:03:32 UTC (rev 10912)
@@ -124,12 +124,15 @@
|| this->myDivisionLeader_->getAction() == Action::ATTACK))
{
this->keepFormation();
+ //orxout (internal_error) << "Keeping formation" << endl;
+
}
else if (!this->myDivisionLeader_->bKeepFormation_)
{
if (!this->hasTarget())
{
- this->chooseTarget();
+ //this->chooseTarget();
+ //orxout (internal_error) << "Section ain't got no target" << endl;
}
if (this->hasTarget())
{
More information about the Orxonox-commit
mailing list