[Orxonox-commit 6191] r10849 - in code/branches/campaignHS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Tue Nov 24 17:21:04 CET 2015
Author: gania
Date: 2015-11-24 17:21:03 +0100 (Tue, 24 Nov 2015)
New Revision: 10849
Modified:
code/branches/campaignHS15/data/levels/AITest.oxw
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
Log:
major change: introduced Actionpoints, look AITest.oxw. Only FLY works for now
Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-24 12:47:43 UTC (rev 10848)
+++ code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-24 16:21:03 UTC (rev 10849)
@@ -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=1 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
+ <TeamSpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
<!--
<?lua
@@ -52,7 +52,7 @@
<!-- <ActionPoint position="12,34,56" action="FIGHT" enemy="ss" />
-->
- <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
+<!-- <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
<templates>
<Template link=spaceshipassff />
</templates>
@@ -60,21 +60,37 @@
<DivisionController formationMode="wall" action="PROTECT" protect="FUCK" team=0>
</DivisionController>
</controller>
- </SpaceShip>
- <SpaceShip position="0, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
+ </SpaceShip> -->
+ <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=1 name="ss2">
<templates>
<Template link=spaceshipassff />
</templates>
<controller>
- <DivisionController team=12>
+ <DivisionController team=1>
<actionpoints>
- <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />
- <Actionpoint position="12,34,56" action="FLY" />
+ <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" />
+ <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
+ <Actionpoint position="-1000,750,-500" action="FLY" />
+ <Actionpoint position="0,0,0" action="FLY" />
</actionpoints>
</DivisionController>
</controller>
</SpaceShip>
-
+ <SpaceShip position="0, 0, 0" lookat="0,0,0" team=2 name="ss4">
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ </SpaceShip>
+ <SpaceShip position="1000, 300, 200" lookat="0,0,0" team=2 name="ss3">
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ </SpaceShip>
+ <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=1 name="fuck">
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ </SpaceShip>
<!-- <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0>
<templates>
<Template link=spaceshipassff />
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-11-24 12:47:43 UTC (rev 10848)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-11-24 16:21:03 UTC (rev 10849)
@@ -57,9 +57,10 @@
CommonController::CommonController( Context* context ): Controller( context )
{
- this->action_ = Action::FLY;
+ this->squaredaccuracy_ = 500;
+ this->action_ = Action::NONE;
this->stopLookingAtTarget();
- this->attackRange_ = 2500;
+ this->attackRange_ = 800;
RegisterObject( CommonController );
}
@@ -68,21 +69,8 @@
{
//orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
}
- void CommonController::backupAction()
- {
- this->actionpoints_.push_back (this->currentActionpoint_);
- }
- void CommonController::restoreAction()
- {
- this->currentActionpoint_ = this->actionpoints_.back();
- this->actionpoints_.pop_back();
- }
- void CommonController::popAction()
- {
- this->currentActionpoint_ = actionpoints_.back();
- actionpoints_.pop_back();
- }
-
+
+
void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
{
SUPER( CommonController, XMLPort, xmlelement, mode );
@@ -119,7 +107,7 @@
{
if (!this->getProtect())
return "noProtectWasSet";
- return CommonController::getName (this->getProtect());
+ return CommonController::getName (orxonox_cast<Pawn*>(this->getProtect()));
}
std::string CommonController::getName(Pawn* entity)
{
@@ -255,7 +243,7 @@
void CommonController::setAction (Action::Value action, ControllableEntity* target)
{
this->action_ = action;
- if (action == Action::FIGHT)
+ if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
{
if (target)
this->setTarget (target);
@@ -333,14 +321,16 @@
}
else
- ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
+ ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
//this->setAction( value );
- parsedActionpoints_.push_back( std::make_tuple (value, targetName, position) );
+ Point p = { value, targetName, position };
+ parsedActionpoints_.push_back(p);
+ orxout(internal_error) << "Pushed " << p.action << endl;
}
else
{
- parsedActionpoints_.push_back(
- std::make_tuple (Action::FLY, "", actionpoint->getWorldPosition()) );
+ Point p = { Action::FLY, "", actionpoint->getWorldPosition() };
+ parsedActionpoints_.push_back(p);
}
this->actionpoints_.push_back(actionpoint);
@@ -356,9 +346,9 @@
}
void CommonController::setClosestTarget()
{
- this->setTarget (closestTarget());
+ this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) );
}
- ControllableEntity* CommonController::closestTarget()
+ Pawn* CommonController::closestTarget()
{
if (!this->getControllableEntity())
return 0;
@@ -380,7 +370,7 @@
}
if (closestTarget)
{
- return static_cast<ControllableEntity*>(closestTarget);
+ return closestTarget;
}
return 0;
}
@@ -390,7 +380,7 @@
{
if (!this->parsedActionpoints_.empty())
{
- this->action_ = std::get<0>( this->parsedActionpoints_.back() );
+ this->action_ = this->parsedActionpoints_.back().action;
switch ( this->action_ )
{
@@ -400,7 +390,7 @@
}
case Action::FLY:
{
- this->setTargetPosition(std::get<2>( this->parsedActionpoints_.back() ));
+ this->setTargetPosition( this->parsedActionpoints_.back().position );
if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
{
this->nextActionpoint();
@@ -410,7 +400,7 @@
}
case Action::PROTECT:
{
- std::string protectName = std::get<1>( this->parsedActionpoints_.back() );
+ std::string protectName = this->parsedActionpoints_.back().name;
for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
{
@@ -436,12 +426,13 @@
}
case Action::ATTACK:
{
- std::string targetName = std::get<1>( this->parsedActionpoints_.back() );
+ std::string targetName = this->parsedActionpoints_.back().name;
for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
{
if (CommonController::getName(*itP) == targetName)
{
+ orxout(internal_error) << "Attacking" << endl;
this->setTarget (static_cast<ControllableEntity*>(*itP));
}
}
@@ -464,6 +455,7 @@
this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
this->action_ = Action::NONE;
}
+ orxout(internal_error) << "Executing action " << this->getActionXML() << endl;
}
void CommonController::nextActionpoint()
{
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-11-24 12:47:43 UTC (rev 10848)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-11-24 16:21:03 UTC (rev 10849)
@@ -64,7 +64,17 @@
{
NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK
};
+
}
+
+ struct Point {
+ Action::Value action;
+ std::string name;
+ Vector3 position;
+ } ;
+
+
+
class _OrxonoxExport CommonController : public Controller, public Tickable
@@ -170,7 +180,7 @@
bool canFire();
void doFire();
void setClosestTarget();
- ControllableEntity* closestTarget();
+ Pawn* closestTarget();
bool bShooting_;
int maneuverCounter_;
@@ -199,8 +209,10 @@
//----[Actionpoint information]----
std::vector<WeakPtr<WorldEntity> > actionpoints_;
float squaredaccuracy_;
- <tuple<Action::Value ,std::string ,Vector3 > > currentActionpoint_;
- std::vector<tuple<Action::Value ,std::string ,Vector3 > > parsedActionpoints_;
+ Point currentActionpoint_;
+ std::vector<Point > parsedActionpoints_;
+ void executeActionpoint();
+ void nextActionpoint();
//----[/Actionpoint information]----
//----["Private" variables]----
FormationMode::Value formationMode_;
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-11-24 12:47:43 UTC (rev 10848)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-11-24 16:21:03 UTC (rev 10849)
@@ -27,8 +27,8 @@
*/
#include "DivisionController.h"
+#include "infos/PlayerInfo.h"
-
namespace orxonox
{
@@ -92,17 +92,19 @@
//analog to attack move
if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
{
- if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) ||
- !this->target_)
+ if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
+ || !this->target_ )
{
- ControllableEntity* newTarget = this->closestTarget();
+ Pawn* newTarget = this->closestTarget();
if ( newTarget &&
- CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_ )
+ CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
+ <= this->attackRange_ )
{
// this->backupAction();
// this->setAction (Action::FIGHT, newTarget);
- this->parsedActionpoints_.push_back(
- std::make_tuple (Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO) );
+ Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO };
+ this->parsedActionpoints_.push_back(p);
+ this->executeActionpoint();
}
}
}
@@ -112,10 +114,9 @@
//otherwise try to execute next action
if (this->action_ == Action::NONE)
{
-
+ this->executeActionpoint();
}
- this->executeActionpoint();
//this->action_ is what I am actually executing, this->target_ is what I am
//actually attacking, etc.
@@ -141,7 +142,7 @@
}
else if (this->action_ == Action::FIGHTALL)
{
- if (newTarget)
+ if (newTarget && newTarget->getController())
{
this->setAction (Action::FIGHTALL, newTarget);
}
@@ -157,6 +158,8 @@
{
//----fly in formation if far enough----
Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+
+
if (diffVector.length() > this->attackRange_)
{
if (this->action_ == Action::FIGHT)
@@ -197,11 +200,23 @@
}
else if (this->action_ == Action::FLY)
{
+
+ if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+ {
+ orxout(internal_error) << "arrived";
+ this->nextActionpoint();
+ return;
+ }
this->setTargetPositionOfWingman();
this->setTargetPositionOfFollower();
}
else if (this->action_ == Action::PROTECT)
{
+ if (!this->getProtect())
+ {
+ this->nextActionpoint();
+ return;
+ }
/* if (this->myWingman_)
this->myWingman_->setAction (Action::PROTECT, this->getProtect());
if (this->myFollower_)
@@ -217,40 +232,40 @@
this->setTargetPositionOfWingman();
this->setTargetPositionOfFollower();
+
}
else if (this->action_ == Action::ATTACK)
{
- if (this->hasTarget())
+ if (!this->hasTarget())
{
- //----fly in formation if far enough----
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
- if (diffVector.length() > this->attackRange_)
+ this->nextActionpoint();
+ return;
+ }
+ //----fly in formation if far enough----
+ Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+ if (diffVector.length() > this->attackRange_)
+ {
+ this->setTargetPositionOfWingman();
+ this->setTargetPositionOfFollower();
+ }
+ else
+ {
+ //----wingmans shall support the fire of their leaders----
+ if (this->myWingman_)
{
- this->setTargetPositionOfWingman();
- this->setTargetPositionOfFollower();
+ this->myWingman_->setAction (this->action_, this->target_);
}
- else
+ if (this->myFollower_)
{
- //----wingmans shall support the fire of their leaders----
- if (this->myWingman_)
- {
- this->myWingman_->setAction (this->action_, this->target_);
- }
- if (this->myFollower_)
- {
- this->myFollower_->setAction (this->action_);
- }
+ this->myFollower_->setAction (this->action_);
+ }
- }
-
}
- if (this->hasTarget())
- {
- //----choose where to go----
- this->maneuver();
- //----fire if you can----
- this->bShooting_ = this->canFire();
- }
+
+ //----choose where to go----
+ this->maneuver();
+ //----fire if you can----
+ this->bShooting_ = this->canFire();
}
}
More information about the Orxonox-commit
mailing list