[Orxonox-commit 6050] r10709 - in code/branches/AI_HS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Mon Oct 26 17:44:31 CET 2015
Author: gania
Date: 2015-10-26 17:44:31 +0100 (Mon, 26 Oct 2015)
New Revision: 10709
Modified:
code/branches/AI_HS15/data/levels/AITest.oxw
code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
Log:
Restructured
Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/data/levels/AITest.oxw 2015-10-26 16:44:31 UTC (rev 10709)
@@ -32,10 +32,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"/>
<SpawnPoint team=0 position="-2000,-1000,3000" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
-
+ <!-->
+
<?lua
for i = 0, 5, 1 do
?>
+
<StaticEntity position="0,-10000,0" direction="0,-1,0" >
<controller>
<FleetController team=1>
@@ -58,7 +60,37 @@
</controller>
</SpaceShip>
<?lua end ?>
-
+ </!-->
+
+ <SpaceShip position = "-1000, -1000, -1000">
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
+ <FleetController accuracy=10 team=1 >
+ </FleetController>
+ </controller>
+ </SpaceShip>
+
+ <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0">
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
+ <WingmanController team=1>
+ </WingmanController>
+ </controller>
+ </SpaceShip>
+ <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
+ <WingmanController team=1>
+ </WingmanController>
+ </controller>
+ </SpaceShip>
+ <!-->
<?lua
for i = 0, 5, 1 do
?>
@@ -72,8 +104,8 @@
</controller>
</SpaceShip>
<?lua end ?>
+ </!-->
-
</Scene>
</Level>
Modified: code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt 2015-10-26 16:44:31 UTC (rev 10709)
@@ -12,7 +12,6 @@
ControllerDirector.cc
FleetController.cc
DivisionController.cc
- SectionController.cc
LeaderController.cc
WingmanController.cc
)
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-10-26 16:44:31 UTC (rev 10709)
@@ -34,7 +34,7 @@
RegisterClass(DivisionController);
- DivisionController::DivisionController(Context* context) : FleetController(context)
+ DivisionController::DivisionController(Context* context) : LeaderController(context)
{
RegisterObject(DivisionController);
}
@@ -46,7 +46,10 @@
}
}
-
+ void DivisionController::setLeader(LeaderController* leader)
+ {
+ this->leader_ = leader;
+ }
/*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(DivisionController, XMLPort, xmlelement, mode);
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h 2015-10-26 16:44:31 UTC (rev 10709)
@@ -29,12 +29,13 @@
#ifndef _DivisionController_H__
#define _DivisionController_H__
-#include "controllers/FleetController.h"
+#include "controllers/LeaderController.h"
+
namespace orxonox
{
- class _OrxonoxExport DivisionController : public FleetController
+ class _OrxonoxExport DivisionController : public LeaderController
{
public:
DivisionController(Context* context);
@@ -47,20 +48,10 @@
void setFormationMode(FormationMode val);
inline FormationMode getFormationMode() const
{ return this->formationMode_; }
+ virtual void setLeader(LeaderController* leader);
+
- virtual void doFire();
- //WAYPOINT FUNCTIONS`
- void addWaypoint(WorldEntity* waypoint);
- WorldEntity* getWaypoint(unsigned int index) const;
-
- inline void setAccuracy(float accuracy)
- { this->squaredaccuracy_ = accuracy*accuracy; }
- inline float getAccuracy() const
- { return sqrt(this->squaredaccuracy_); }
- void updatePointsOfInterest(std::string name, float distance);
- void manageWaypoints();
-
protected:
//Target enemy, set by fleet controller.
@@ -69,7 +60,9 @@
Vector3 targetPosition_;
bool bHasTargetOrientation_;
Quaternion targetOrientation_;
- void setTargetPosition(const Vector3& target);
+ FormationMode formationMode_;
+
+ /*void setTargetPosition(const Vector3& target);
void searchRandomTargetPosition();
void setTargetOrientation(const Quaternion& orient);
@@ -77,7 +70,6 @@
virtual void positionReached() {}
- static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
void setTarget(Pawn* target);
@@ -108,13 +100,11 @@
void turn180Init();
void spinInit();
void spin();
- void turn180();
+ void turn180();*/
- //WAYPOINT DATA
- std::vector<WeakPtr<WorldEntity> > waypoints_;
- size_t currentWaypoint_;
- float squaredaccuracy_;
- WorldEntity* defaultWaypoint_;
+ LeaderController* leader_;
+
+
private:
};
Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc 2015-10-26 16:44:31 UTC (rev 10709)
@@ -34,7 +34,7 @@
RegisterClass(FleetController);
- FleetController::FleetController(Context* context) : Controller(context)
+ FleetController::FleetController(Context* context) : FormationController(context)
{
RegisterObject(FleetController);
@@ -42,6 +42,9 @@
this->goalPosition_ = NULL;
this->goalTarget_ = NULL;
this->goalProtect_ = NULL;
+ this->nTicks_ = 0;
+ this->bTicked_ = false;
+ //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
}
FleetController::~FleetController()
@@ -51,7 +54,98 @@
}
}
-
+ void FleetController::action()
+ {
+
+
+ }
+ void FleetController::tick(float dt)
+ {
+
+ if (nTicks_ == 30)
+ {
+ std::vector<WeakPtr<WingmanController> > wingmen;
+ std::vector<WeakPtr<LeaderController> > leaders;
+
+ //--------------------------Put all WingmanController's in a vector--------------------------
+ for (ObjectList<WingmanController>::iterator it = ObjectList<WingmanController>::begin(); it; ++it)
+ {
+
+
+ if ((*it)->getTeam() == this->getTeam())
+ {
+ orxout(internal_error) << "ANOTHER SUCKER" << endl;
+ wingmen.push_back(*it);
+ }
+
+ }
+ //--------------------------Substitute half of WingmanController's with LeaderController--------------------------
+
+ bool nowLeader = true;
+ LeaderController* leader;
+
+ for (std::vector<WeakPtr<WingmanController> >::iterator it = wingmen.begin() ; it != wingmen.end(); ++it)
+ {
+ if (nowLeader)
+ {
+ leader = new LeaderController(this->getContext());
+ leader->setTeam(this->team_);
+
+ (*it)->getControllableEntity()->setController(leader);
+ leaders.push_back(leader);
+ nowLeader = !nowLeader;
+ orxout(internal_error) << "NEW SUCKER" << endl;
+
+ }
+ else
+ {
+ if (leader)
+ {
+ leader->setWingman(*it);
+ nowLeader = !nowLeader;
+ orxout(internal_error) << "I OWN THE SUCKER" << endl;
+
+ }
+ }
+ }
+
+ //--------------------------Substitute half of LeaderController's with DivisionController--------------------------
+ bool nowDivision = true;
+ DivisionController* division;
+
+ for (std::vector<WeakPtr<LeaderController> >::iterator it = leaders.begin() ; it != leaders.end(); ++it)
+ {
+ if (nowDivision)
+ {
+ division = new DivisionController(this->getContext());
+ division->setTeam(this->team_);
+
+ (*it)->getControllableEntity()->setController(division);
+
+ divisions_.push_back(division);
+
+ nowDivision = !nowDivision;
+ }
+ else
+ {
+ if (division)
+ {
+ division->setLeader(*it);
+ nowDivision = !nowDivision;
+ }
+ }
+ }
+ bTicked_ = true;
+ nTicks_ += 1;
+ }
+ else if (!bTicked_)
+ {
+ nTicks_ += 1;
+
+ }
+ SUPER(FleetController, tick, dt);
+
+ }
void FleetController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(FleetController, XMLPort, xmlelement, mode);
Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.h 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.h 2015-10-26 16:44:31 UTC (rev 10709)
@@ -28,16 +28,18 @@
#ifndef _FleetController_H__
#define _FleetController_H__
+#include "controllers/FormationController.h"
#include "controllers/Controller.h"
+#include "controllers/DivisionController.h"
+#include "controllers/LeaderController.h"
+#include "controllers/WingmanController.h"
#include "OrxonoxPrereqs.h"
#include "core/class/Super.h"
#include "core/CoreIncludes.h"
-#include "core/XMLPort.h"
-#include "core/command/ConsoleCommandIncludes.h"
-#include "core/command/Executor.h"
+
#include <vector>
#include "util/Math.h"
#include <climits>
@@ -50,25 +52,18 @@
#include "worldentities/pawns/Pawn.h"
#include "worldentities/pawns/TeamBaseMatchBase.h"
-#include "gametypes/TeamDeathmatch.h"
-#include "gametypes/Dynamicmatch.h"
-#include "gametypes/Mission.h"
-#include "gametypes/Gametype.h"
-#include "controllers/WaypointPatrolController.h"
-#include "controllers/NewHumanController.h"
-#include "controllers/DroneController.h"
-
namespace orxonox
{
- class _OrxonoxExport FleetController : public Controller
+ class _OrxonoxExport FleetController : public FormationController, public Tickable
{
public:
FleetController(Context* context);
virtual ~FleetController();
+ virtual void tick(float dt); //<! Carrying out the targets set in action().
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
@@ -79,28 +74,9 @@
//PROTECT makes a fleet protect a target (set in variable goalProtect_)
enum GameGoal {DOMINATE, MOVE, DESTROY, PROTECT};
- /*void setGameGoal(GameGoal gameGoal)
- { this->gameGoal_ = gameGoal; }
- GameGoal getGameGoal() const
- { return this->gameGoal_; }
- void setGoalPosition(Vector3* goalPosition)
- { this->goalPosition_ = goalPosition; }
- Vector3* getGoalPosition() const
- { return this->goalPosition_; }
-
- void setGoalTarget(Pawn* goalTarget)
- { this->goalTarget_ = goalTarget; }
- Pawn* getGoalTarget() const
- { return this->goalTarget_; }
-
- void setGoalProtect(Pawn* goalProtect)
- { this->goalProtect_ = goalProtect; }
- Pawn* getGoalProtect() const
- { return this->goalProtect_; }*/
-
protected:
@@ -109,7 +85,14 @@
WeakPtr<Pawn> goalTarget_;
WeakPtr<Pawn> goalProtect_;
+ virtual void action();
+ private:
+ int nTicks_;
+ bool bTicked_;
+ std::vector<WeakPtr<DivisionController> > divisions_;
+ //Timer actionTimer_; //<! Regularly calls action().
+
};
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc 2015-10-26 16:44:31 UTC (rev 10709)
@@ -32,23 +32,24 @@
namespace orxonox
{
- const float LeaderController::ACTION_INTERVAL = 1.0f;
RegisterClass(LeaderController);
- LeaderController::LeaderController(Context* context) : SectionController(context)
+ LeaderController::LeaderController(Context* context) : WingmanController(context)
{
+
RegisterObject(LeaderController);
- this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
+ //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
}
+
LeaderController::~LeaderController()
{
}
void LeaderController::action()
{
-
+ //this->target_ = this->sectionTarget_;
}
/*
Wingmen and Leaders attack target_, which is a member variable of their classes.
@@ -65,12 +66,12 @@
*/
void LeaderController::tick(float dt)
- {
+ {/*
if (!this->isActive())
return;
//--------------------------Stay in division--------------------------
- this->keepDivisionTick();
+ this->keepDivisionTick();*/
/*keepDivisionTick(){
if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) +
@@ -79,26 +80,27 @@
}
}
*/
- //If ordered to attack -> follow target and shoot
+ /*//If ordered to attack -> follow target and shoot
if (this->bAttackOrder_)
{
-
+
}
//If ordered to move -> move to a target Point
- else if (this->bMoveOrder_)
- {
-
- }
- else
+
//No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
//(Section shoots same target, Boss's section shoots another target)
{
- }
+ }*/
-
+ orxout(internal_error) << "my Wingman is " << this->wingman_ << endl;
+
SUPER(LeaderController, tick, dt);
}
+ void LeaderController::setWingman(WingmanController* wingman)
+ {
+ this->wingman_ = wingman;
+ }
//**********************************************NEW
/* void LeaderController::defaultBehaviour(float maxrand)
{
Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h 2015-10-26 16:44:31 UTC (rev 10709)
@@ -29,43 +29,36 @@
#ifndef _LeaderController_H__
#define _LeaderController_H__
-#include "SectionController.h"
+#include "controllers/WingmanController.h"
+
+
namespace orxonox
{
- class _OrxonoxExport LeaderController : public SectionController, public Tickable
+ class _OrxonoxExport LeaderController : public WingmanController
{
public:
LeaderController(Context* context);
virtual ~LeaderController();
-
+ virtual void setWingman(WingmanController* wingman);
virtual void tick(float dt); //<! Carrying out the targets set in action().
protected:
- enum Mode {KEEPFORMATION, ROCKET, KILLENEMY};
- Mode mode_;
+
virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
//void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
+
+ private:
+ WeakPtr<Pawn> target_;
+
+ WingmanController* wingman_;
- //WEAPONSYSTEM DATA
- 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()
- float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
- 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);
-
- void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost.
-
- private:
- static const float ACTION_INTERVAL;
-
- Timer actionTimer_; //<! Regularly calls action().
+ //Timer actionTimer_; //<! Regularly calls action().
};
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc 2015-10-26 16:44:31 UTC (rev 10709)
@@ -31,14 +31,13 @@
namespace orxonox
{
- const float WingmanController::ACTION_INTERVAL = 1.0f;
RegisterClass(WingmanController);
- WingmanController::WingmanController(Context* context) : SectionController(context)
+ WingmanController::WingmanController(Context* context) : Controller(context)
{
RegisterObject(WingmanController);
- this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
+ //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
}
WingmanController::~WingmanController()
@@ -54,21 +53,17 @@
}*/
void WingmanController::action()
{
- //--------------------------Cover Leader's rear--------------------------
- //check for enemies in Leader's rear that can attack him and if they are visible, meaning there are no other Leader's between Leader and enemies.
- //if there are enemies, set target_ to the nearest one and set bFollowLeader_ to false,
- //otherwise set bFollowLeader_ to true and target_ to sectionTarget_
- this->coverAllyRear(this->sectionLeader_);
+ //this->target_ = this->sectionTarget_;
}
void WingmanController::tick(float dt)
- {
+ {/*
if (!this->isActive())
return;
//--------------------------Stay in formation--------------------------
if (bFollowLeader_)
{
- this->keepSectionTick();
+ this->keepSectionTick();*/
/*keepSectionTick(){
if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
@@ -77,46 +72,17 @@
}
}
*/
-
+ /*
//--------------------------Attack same target as the Leader--------------------------
-
+
if (this->target_)
{
this->aimAtTarget();
this->doFire();
}
- }
- //--------------------------Protect Leader by killing target_--------------------------
-
- else
- {
- if (this->target_)
- {
- //--------------------------Don't attack if not visible--------------------------
- if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
- {
- this->forgetTarget();
- //this->bFollowLeader_ = true;
- }
- //--------------------------Otherwise destroy it--------------------------
- else
- {
- this->aimAtTarget();
- this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily.
- }
- if (this->bHasTargetPosition_)
- {
- this->moveToTargetPosition();
- }
- this->doFire();
- }
- //--------------------------no target? do nothing until next action() -> either new target appears or bFollowLeader_ set to true--------------------------
- else
- {
-
- }
-
- }
+ }*/
+ //orxout(internal_error) << "I am " << this << endl;
+
SUPER(WingmanController, tick, dt);
}
//**********************************************NEW
Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h 2015-10-26 15:07:58 UTC (rev 10708)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h 2015-10-26 16:44:31 UTC (rev 10709)
@@ -30,12 +30,38 @@
#define _WingmanController_H__
-#include "LeaderController.h"
+#include "controllers/Controller.h"
+#include "OrxonoxPrereqs.h"
+#include "core/class/Super.h"
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "core/command/ConsoleCommandIncludes.h"
+#include "core/command/Executor.h"
+
+#include <vector>
+#include "util/Math.h"
+#include <climits>
+
+#include "tools/Timer.h"
+#include "tools/interfaces/Tickable.h"
+
+#include "worldentities/ControllableEntity.h"
+#include "worldentities/pawns/SpaceShip.h"
+#include "worldentities/pawns/Pawn.h"
+#include "worldentities/pawns/TeamBaseMatchBase.h"
+
+#include "gametypes/TeamDeathmatch.h"
+#include "gametypes/Dynamicmatch.h"
+#include "gametypes/Mission.h"
+#include "gametypes/Gametype.h"
+
+
+
namespace orxonox
{
- class _OrxonoxExport WingmanController : public LeaderController
+ class _OrxonoxExport WingmanController : public Controller, public Tickable
{
public:
WingmanController(Context* context);
@@ -50,9 +76,13 @@
private:
- static const float ACTION_INTERVAL;
+ //const float ACTION_INTERVAL;
+
+ WeakPtr<Pawn> target_;
+
+ //LeaderController* leader_;
- Timer actionTimer_; //<! Regularly calls action().
+ //Timer actionTimer_; //<! Regularly calls action().
};
}
More information about the Orxonox-commit
mailing list