[Orxonox-commit 4321] r8992 - in code/branches/presentation2011: . data/defaultConfig src/orxonox/controllers
jo at orxonox.net
jo at orxonox.net
Fri Dec 16 20:36:41 CET 2011
Author: jo
Date: 2011-12-16 20:36:41 +0100 (Fri, 16 Dec 2011)
New Revision: 8992
Added:
code/branches/presentation2011/src/orxonox/controllers/FormationController.cc
code/branches/presentation2011/src/orxonox/controllers/FormationController.h
Modified:
code/branches/presentation2011/
code/branches/presentation2011/data/defaultConfig/keybindings.ini
code/branches/presentation2011/src/orxonox/controllers/AIController.cc
code/branches/presentation2011/src/orxonox/controllers/AIController.h
code/branches/presentation2011/src/orxonox/controllers/ArtificialController.cc
code/branches/presentation2011/src/orxonox/controllers/ArtificialController.h
code/branches/presentation2011/src/orxonox/controllers/CMakeLists.txt
code/branches/presentation2011/src/orxonox/controllers/HumanController.cc
code/branches/presentation2011/src/orxonox/controllers/HumanController.h
code/branches/presentation2011/src/orxonox/controllers/NewHumanController.cc
Log:
Merged Formation branch. There are still some bugs (just have a look at the tutorial level)
Property changes on: code/branches/presentation2011
___________________________________________________________________
Modified: svn:mergeinfo
- /code/branches/ai:6592-7033
/code/branches/ai2:8721-8880
/code/branches/bigships:8137-8588
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dockingsystem:8101-8192
/code/branches/dockingsystem2:8196-8560
/code/branches/dynamicmatch:6584-7030
/code/branches/environment3:8887-8975
/code/branches/fps:6591-7072
/code/branches/gamecontent:8893-8968
/code/branches/gameimmersion:8102-8577
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hud:8883-8986
/code/branches/hudelements:6584-6941
/code/branches/hudimprovements:7920-8672
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7940-8096,8098-8277
/code/branches/kicklib2:8282-8350
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/mac_osx:7789-8128,8135
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/masterserverfix:8933-8936
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/menue:8884-8976
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network6:7823-8315
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/ois_update:7506-7788
/code/branches/output:8739-8857
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup:8145-8555
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/portals:8087-8455
/code/branches/portals2:8460-8602
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786,8500-8705
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/spaceboundaries:8085-8457
/code/branches/spaceboundaries2:8460-8613
/code/branches/spacerace:8182-8630
/code/branches/steering:5949-6091,8140-8595
/code/branches/tetris:8100-8563
/code/branches/tutoriallevel:7827-8370
/code/branches/tutoriallevel2:8370-8452
/code/branches/tutoriallevel3:8453-8636
/code/branches/unity_build:8440-8716
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051,8143-8591
/code/branches/weaponsystem:2742-2890
+ /code/branches/ai:6592-7033
/code/branches/ai2:8721-8880
/code/branches/bigships:8137-8588
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dockingsystem:8101-8192
/code/branches/dockingsystem2:8196-8560
/code/branches/dynamicmatch:6584-7030
/code/branches/environment3:8887-8975
/code/branches/formation:8885-8991
/code/branches/fps:6591-7072
/code/branches/gamecontent:8893-8968
/code/branches/gameimmersion:8102-8577
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hud:8883-8986
/code/branches/hudelements:6584-6941
/code/branches/hudimprovements:7920-8672
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7940-8096,8098-8277
/code/branches/kicklib2:8282-8350
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/mac_osx:7789-8128,8135
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/masterserverfix:8933-8936
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/menue:8884-8976
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network6:7823-8315
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/ois_update:7506-7788
/code/branches/output:8739-8857
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup:8145-8555
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/portals:8087-8455
/code/branches/portals2:8460-8602
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786,8500-8705
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/spaceboundaries:8085-8457
/code/branches/spaceboundaries2:8460-8613
/code/branches/spacerace:8182-8630
/code/branches/steering:5949-6091,8140-8595
/code/branches/tetris:8100-8563
/code/branches/tutoriallevel:7827-8370
/code/branches/tutoriallevel2:8370-8452
/code/branches/tutoriallevel3:8453-8636
/code/branches/unity_build:8440-8716
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051,8143-8591
/code/branches/weaponsystem:2742-2890
Modified: code/branches/presentation2011/data/defaultConfig/keybindings.ini
===================================================================
--- code/branches/presentation2011/data/defaultConfig/keybindings.ini 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/data/defaultConfig/keybindings.ini 2011-12-16 19:36:41 UTC (rev 8992)
@@ -70,8 +70,8 @@
KeyNoConvert=
KeyNumLock=
KeyNumRow0=
-KeyNumRow1=
-KeyNumRow2=
+KeyNumRow1="toggleFormationFlight"
+KeyNumRow2="FFChangeMode"
KeyNumRow3=
KeyNumRow4=
KeyNumRow5=
Modified: code/branches/presentation2011/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/AIController.cc 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/AIController.cc 2011-12-16 19:36:41 UTC (rev 8992)
@@ -74,11 +74,31 @@
}
this->defaultBehaviour(maxrand);
+
}
- if (this->state_ == SLAVE)
+ if (this->state_ == SLAVE && this->formationMode_ == ATTACK) //TODO: add botlevel parameter
{
+ // search enemy
+ random = rnd(maxrand);
+ if (random < 75 && (!this->target_))
+ this->searchNewTarget();
+ // next enemy
+ random = rnd(maxrand);
+ if (random < 10 && (this->target_))
+ this->searchNewTarget();
+
+ // shoot
+ random = rnd(maxrand);
+ if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
+ this->bShooting_ = true;
+
+ // stop shooting
+ random = rnd(maxrand);
+ if (random < 25 && (this->bShooting_))
+ this->bShooting_ = false;
+
}
if (this->state_ == MASTER)
@@ -100,11 +120,11 @@
if (random < 5)
this->spinInit();
- // follow a randomly chosen human - a specific Master Action
+ /*// follow a randomly chosen human - a specific Master Action
random = rnd(1000.0f);
if (random < 1)
this->followRandomHumanInit();
-
+*/
// lose master status (only if less than 4 slaves in formation)
random = rnd(maxrand);
if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 )
@@ -116,8 +136,10 @@
this->searchNewMaster();
this->defaultBehaviour(maxrand);
+
}
}
+
}
void AIController::tick(float dt)
@@ -128,7 +150,7 @@
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
ControllableEntity* controllable = this->getControllableEntity();
-
+ //DOES: Either move to the waypoint or search for a Point of interest
if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
{
if (this->waypoints_.size() > 0 ) //Waypoint functionality.
@@ -150,8 +172,9 @@
random = rnd(maxrand);
}
}
- if(this->mode_ == DEFAULT)
- {
+
+ if (this->mode_ == DEFAULT)
+ {
if (this->state_ == MASTER)
{
if (this->specificMasterAction_ == NONE)
@@ -164,14 +187,13 @@
{
this->aimAtTarget();
random = rnd(maxrand);
- if(this->botlevel_*100 > random && !this->isCloseAtTarget(20))
+ if(this->botlevel_*70 > random && !this->isCloseAtTarget(100))
this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily.
}
}
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
-
this->doFire();
}
@@ -184,34 +206,27 @@
this->follow();
}
- if (this->state_ == SLAVE)
+ if (this->state_ == SLAVE && this->formationMode_ != ATTACK)
{
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
}
- if (this->state_ == FREE)
+ if (this->state_ == FREE || (this->state_==SLAVE && this->formationMode_ == ATTACK) )
{
if (this->target_)
{
if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
this->forgetTarget();
- else
- {
- this->aimAtTarget();
- random = rnd(maxrand);
-
- if(this->botlevel_*100 > random && !this->isCloseAtTarget(20))
- this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
- }
+ else this->aimAtTarget();
}
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
- this->doFire();
+ this->doFire();
}
- }//END_OF DEFAULT MODE
+ }
else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
{ //Vector-implementation: mode_.back() == ROCKET;
if(controllable)
@@ -236,7 +251,7 @@
SUPER(AIController, tick, dt);
}
-
+//**********************************************NEW
void AIController::defaultBehaviour(float maxrand)
{ float random;
// search enemy
Modified: code/branches/presentation2011/src/orxonox/controllers/AIController.h
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/AIController.h 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/AIController.h 2011-12-16 19:36:41 UTC (rev 8992)
@@ -52,7 +52,7 @@
private:
static const float ACTION_INTERVAL;
- Timer actionTimer_; //<! Regularly calls action().
+ Timer actionTimer_; //<! Regularly calls action().
};
}
Modified: code/branches/presentation2011/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/ArtificialController.cc 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/ArtificialController.cc 2011-12-16 19:36:41 UTC (rev 8992)
@@ -23,81 +23,33 @@
* Fabian 'x3n' Landau
* Co-authors:
* Dominik Solenicki
- *
+ *
*/
#include "ArtificialController.h"
-
-#include <vector>
-#include <climits>
-
-#include "util/Math.h"
#include "core/CoreIncludes.h"
-#include "core/XMLPort.h"
-#include "core/command/ConsoleCommand.h"
-#include "worldentities/ControllableEntity.h"
#include "worldentities/pawns/Pawn.h"
-#include "worldentities/pawns/TeamBaseMatchBase.h"
#include "worldentities/pawns/SpaceShip.h"
-#include "gametypes/TeamDeathmatch.h"
-#include "gametypes/Dynamicmatch.h"
-#include "gametypes/Mission.h"
-#include "controllers/WaypointPatrolController.h"
-#include "controllers/NewHumanController.h"
-#include "controllers/DroneController.h"
+
#include "weaponsystem/WeaponMode.h"
#include "weaponsystem/WeaponPack.h"
#include "weaponsystem/Weapon.h"
#include "weaponsystem/WeaponSlot.h"
#include "weaponsystem/WeaponSlot.h"
+
namespace orxonox
{
- SetConsoleCommand("ArtificialController", "formationflight", &ArtificialController::formationflight);
- SetConsoleCommand("ArtificialController", "masteraction", &ArtificialController::masteraction);
- SetConsoleCommand("ArtificialController", "followme", &ArtificialController::followme);
- SetConsoleCommand("ArtificialController", "passivebehaviour", &ArtificialController::passivebehaviour);
- SetConsoleCommand("ArtificialController", "formationsize", &ArtificialController::formationsize);
- SetConsoleCommand("ArtificialController", "setbotlevel", &ArtificialController::setAllBotLevel);
- static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
- static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
- static const int FORMATION_LENGTH = 130;
- static const int FORMATION_WIDTH = 110;
- static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
- static const float SPEED_MASTER = 0.6f;
- static const float ROTATEFACTOR_MASTER = 0.2f;
- static const float SPEED_FREE = 0.8f;
- static const float ROTATEFACTOR_FREE = 0.8f;
-
-
- ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
+ ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator)
{
- RegisterObject(ArtificialController);
-
- this->target_ = 0;
- this->formationFlight_ = false;
- this->passive_ = false;
- this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
- this->myMaster_ = 0;
- this->freedomCount_ = 0;
- this->team_ = -1;
- this->state_ = FREE;
- this->specificMasterAction_ = NONE;
- this->specificMasterActionHoldCount_ = 0;
- this->bShooting_ = false;
- this->bHasTargetPosition_ = false;
- this->speedCounter_ = 0.2f;
- this->targetPosition_ = Vector3::ZERO;
-
- this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
this->bSetupWorked = false;
this->botlevel_ = 0.5f;
- this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
this->timeout_ = 0;
this->currentWaypoint_ = 0;
this->setAccuracy(5);
this->defaultWaypoint_ = NULL;
+ this->mode_ = DEFAULT;//Vector-implementation: mode_.push_back(DEFAULT);
}
ArtificialController::~ArtificialController()
@@ -105,810 +57,21 @@
if (this->isInitialized())
{//Vector-implementation: mode_.erase(mode_.begin(),mode_.end());
this->waypoints_.clear();
- this->removeFromFormation();
this->weaponModes_.clear();
- for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it)
- {
- if (*it != this)
- {
- if (it->myMaster_ == this)
- {
- orxout(internal_error) << this << " is still master in " << (*it) << endl;
- it->myMaster_ = 0;
- }
-
- while (true)
- {
- std::vector<ArtificialController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this);
- if (it2 != it->slaves_.end())
- {
- orxout(internal_error) << this << " is still slave in " << (*it) << endl;
- it->slaves_.erase(it2);
- }
- else
- break;
- }
- }
- }
}
}
- void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
- {
- SUPER(ArtificialController, XMLPort, xmlelement, mode);
- XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
- XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
- XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
- XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
- }
-
-// Documentation only here to get a faster overview for creating a useful documentation...
-
/**
- @brief Activates / deactivates formationflight behaviour
- @param form activate formflight if form is true
- */
- void ArtificialController::formationflight(const bool form)
- {
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- Controller* controller = 0;
-
- if (it->getController())
- controller = it->getController();
- else if (it->getXMLController())
- controller = it->getXMLController();
-
- if (!controller)
- continue;
-
- ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
-
- if (aiController)
- {
- aiController->formationFlight_ = form;
- if (!form)
- {
- aiController->removeFromFormation();
- }
- }
- }
- }
-
- /**
- @brief Get all masters to do a "specific master action"
- @param action which action to perform (integer, so it can be called with a console command (tmp solution))
- */
- void ArtificialController::masteraction(const int action)
- {
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- Controller* controller = 0;
-
- if (it->getController())
- controller = it->getController();
- else if (it->getXMLController())
- controller = it->getXMLController();
-
- if (!controller)
- continue;
-
- ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
-
- if(aiController && aiController->state_ == MASTER)
- {
- if (action == 1)
- aiController->spinInit();
- if (action == 2)
- aiController->turn180Init();
- }
- }
- }
-
- /**
- @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup).
- */
- void ArtificialController::followme()
- {
-
- Pawn *humanPawn = NULL;
- NewHumanController *currentHumanController = NULL;
- std::vector<ArtificialController*> allMasters;
-
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- Controller* controller = 0;
-
- if (it->getController())
- controller = it->getController();
- else if (it->getXMLController())
- controller = it->getXMLController();
-
- if (!controller)
- continue;
-
- currentHumanController = orxonox_cast<NewHumanController*>(controller);
-
- if(currentHumanController) humanPawn = *it;
-
- ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
-
- if(aiController && aiController->state_ == MASTER)
- allMasters.push_back(aiController);
-
- }
-
- if((humanPawn != NULL) && (allMasters.size() != 0))
- {
- float posHuman = humanPawn->getPosition().length();
- float distance = 0.0f;
- float minDistance = FLT_MAX;
- int index = 0;
- int i = 0;
-
- for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
- {
- if (!ArtificialController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
- distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
- if(distance < minDistance) index = i;
- }
- allMasters[index]->followInit(humanPawn);
- }
-
- }
-
- /**
- @brief Sets shooting behaviour of pawns.
- @param passive if true, bots won't shoot.
- */
- void ArtificialController::passivebehaviour(const bool passive)
- {
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- Controller* controller = 0;
-
- if (it->getController())
- controller = it->getController();
- else if (it->getXMLController())
- controller = it->getXMLController();
-
- if (!controller)
- continue;
-
- ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
-
- if(aiController)
- {
- aiController->passive_ = passive;
- }
- }
- }
-
-
- /**
- @brief Sets maximal formation size
- @param size maximal formation size.
- */
- void ArtificialController::formationsize(const int size)
- {
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- Controller* controller = 0;
-
- if (it->getController())
- controller = it->getController();
- else if (it->getXMLController())
- controller = it->getXMLController();
-
- if (!controller)
- continue;
-
- ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller);
-
- if(aiController)
- {
- aiController->maxFormationSize_ = size;
- }
- }
- }
-
- /**
@brief Gets called when ControllableEntity is being changed. Resets the bot when it dies.
*/
void ArtificialController::changedControllableEntity()
{
if (!this->getControllableEntity())
this->removeFromFormation();
- this->bSetupWorked = false; // reset weapon information
- this->setupWeapons();
}
- void ArtificialController::removeFromFormation()
- {
- if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set
- this->unregisterSlave();
- else if (this->state_ == MASTER)
- this->setNewMasterWithinFormation();
- }
- void ArtificialController::moveToPosition(const Vector3& target)
- {
- if (!this->getControllableEntity())
- return;
-
- // Slave uses special movement if its master is in FOLLOW mode
- if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW)
- {
-// this->followForSlaves(target);
-// return;
- }
-
- Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
- float distance = (target - this->getControllableEntity()->getPosition()).length();
-
-
- if(this->state_ == FREE)
- {
- if (this->target_ || distance > 10)
- {
- // Multiply with ROTATEFACTOR_FREE to make them a bit slower
- this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
- }
-
- if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
- {
- this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
- } else this->getControllableEntity()->moveFrontBack(SPEED_FREE);
- }
-
-
-
- if(this->state_ == MASTER)
- {
- if (this->target_ || distance > 10)
- {
- this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
- }
-
- if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
- {
- this->getControllableEntity()->moveFrontBack(-0.05f);
- } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
- }
-
-
-
- if(this->state_ == SLAVE)
- {
-
- this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
-
- if (distance < 300)
- {
- if (distance < 40)
- {
- this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER);
- } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
-
- } else {
- this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
- }
- }
-
- if (distance < 10)
- {
- this->positionReached();
- }
- }
-
- void ArtificialController::absoluteMoveToPosition(const Vector3& target)
- {
- float minDistance = 40.0f;
- if (!this->getControllableEntity())
- return;
-
- Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
- float distance = (target - this->getControllableEntity()->getPosition()).length();
-
- if (this->target_ || distance > minDistance)
- {
- // Multiply with ROTATEFACTOR_FREE to make them a bit slower
- this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
- this->getControllableEntity()->moveFrontBack(SPEED_FREE);
- }
-
-
- if (distance < minDistance)
- {
- this->positionReached();
- }
- }
-
-
- void ArtificialController::moveToTargetPosition()
- {
- this->moveToPosition(this->targetPosition_);
- }
-
- /**
- @brief Unregisters a slave from its master. Initiated by a slave.
- */
- void ArtificialController::unregisterSlave()
- {
- if (this->myMaster_)
- {
- std::vector<ArtificialController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this);
- if (it != this->myMaster_->slaves_.end())
- this->myMaster_->slaves_.erase(it);
- }
-
- this->myMaster_ = 0;
- this->state_ = FREE;
- }
-
- void ArtificialController::searchNewMaster()
- {
-
- if (!this->getControllableEntity())
- return;
-
- this->targetPosition_ = this->getControllableEntity()->getPosition();
- this->forgetTarget();
- int teamSize = 0;
- //go through all pawns
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- //same team?
- if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
- continue;
-
- //has it an ArtificialController?
- Controller* controller = 0;
-
- if (it->getController())
- controller = it->getController();
- else if (it->getXMLController())
- controller = it->getXMLController();
-
- if (!controller)
- continue;
-
- //is pawn oneself?
- if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
- continue;
-
- teamSize++;
-
- ArtificialController *newMaster = orxonox_cast<ArtificialController*>(controller);
-
- //is it a master?
- if (!newMaster || newMaster->state_ != MASTER)
- continue;
-
- float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
-
- // is pawn in range?
- if (distance < RADIUS_TO_SEARCH_FOR_MASTERS)
- {
- if(newMaster->slaves_.size() > this->maxFormationSize_) continue;
-
- for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
- {
- (*itSlave)->myMaster_ = newMaster;
- newMaster->slaves_.push_back(*itSlave);
- }
- this->slaves_.clear();
- this->state_ = SLAVE;
-
- this->myMaster_ = newMaster;
- newMaster->slaves_.push_back(this);
-
- break;
- }
- }
-
- if (this->state_ != SLAVE && teamSize != 0)
- {
- this->state_ = MASTER;
- this->myMaster_ = 0;
- }
- }
-
- /**
- @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
- */
- void ArtificialController::commandSlaves()
- {
- if(this->state_ != MASTER) return;
-
- Quaternion orient = this->getControllableEntity()->getOrientation();
- Vector3 dest = this->getControllableEntity()->getPosition();
-
- // 1 slave: follow
- if (this->slaves_.size() == 1)
- {
- dest += 4*orient*WorldEntity::BACK;
- this->slaves_.front()->setTargetPosition(dest);
- }
- else
- {
- dest += 1.0f*orient*WorldEntity::BACK;
- Vector3 pos = Vector3::ZERO;
- int i = 1;
-
- for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
- {
- pos = Vector3::ZERO;
- if (i <= 1) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::LEFT);
- if (i == 2) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
- if (i == 3) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::UP);
- if (i >= 4)
- {
- pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::DOWN);
- i = 1;
- dest += (float)FORMATION_LENGTH*(orient*WorldEntity::BACK);
- (*it)->setTargetPosition(pos);
- continue;
- }
- i++;
- (*it)->setTargetPosition(pos);
- }
- }
- }
-
- /**
- @brief Sets a new master within the formation. Called by a master.
- */
- void ArtificialController::setNewMasterWithinFormation()
- {
- if(this->state_ != MASTER) return;
-
- if (!this->slaves_.empty())
- {
- ArtificialController *newMaster = this->slaves_.back();
- this->slaves_.pop_back();
-
- newMaster->state_ = MASTER;
- newMaster->slaves_ = this->slaves_;
- newMaster->myMaster_ = 0;
-
- for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
- {
- (*it)->myMaster_ = newMaster;
- }
- }
-
- this->slaves_.clear();
- this->specificMasterAction_ = NONE;
- this->state_ = FREE;
- }
-
- /**
- @brief Frees all slaves form a master. Initiated by a master.
- */
- void ArtificialController::freeSlaves()
- {
- if(this->state_ != MASTER) return;
-
- for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
- {
- (*it)->state_ = FREE;
- (*it)->myMaster_ = 0;
- }
- this->slaves_.clear();
- }
-
- /**
- @brief Master sets its slaves free for @ref FREEDOM_COUNT seconds.
- */
- void ArtificialController::forceFreeSlaves()
- {
- if(this->state_ != MASTER) return;
-
- for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
- {
- (*it)->state_ = FREE;
- (*it)->forceFreedom();
- (*it)->targetPosition_ = this->targetPosition_;
- (*it)->bShooting_ = true;
-// (*it)->getControllableEntity()->fire(0);// fire once for fun
- }
- }
-
- void ArtificialController::loseMasterState()
- {
- this->freeSlaves();
- this->state_ = FREE;
- }
-
-
- void ArtificialController::forceFreedom()
- {
- this->freedomCount_ = FREEDOM_COUNT;
- }
-
- /**
- @brief Checks wether caller has been forced free, decrements time to stay forced free.
- @return true if forced free.
- */
- bool ArtificialController::forcedFree()
- {
- if(this->freedomCount_ > 0)
- {
- this->freedomCount_--;
- return true;
- } else return false;
- }
-
- /**
- @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
- */
- void ArtificialController::specificMasterActionHold()
- {
- if(this->state_ != MASTER) return;
-
- if (specificMasterActionHoldCount_ == 0)
- {
- this->specificMasterAction_ = NONE;
- this->searchNewTarget();
- }
- else specificMasterActionHoldCount_--;
- }
-
- /**
- @brief Master initializes a 180 degree turn. Leads to a "specific master action".
- */
- void ArtificialController::turn180Init()
- {
- if(this->state_ != MASTER) return;
-
- Quaternion orient = this->getControllableEntity()->getOrientation();
-
- this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK);
-
- this->specificMasterActionHoldCount_ = 4;
-
- this->specificMasterAction_ = TURN180;
- }
-
- /**
- @brief Execute the 180 degree turn. Called within tick.
- */
- void ArtificialController::turn180()
- {
- Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
-
- this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
-
- this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
- }
-
- /**
- @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action".
- */
- void ArtificialController::spinInit()
- {
- if(this->state_ != MASTER) return;
- this->specificMasterAction_ = SPIN;
- this->specificMasterActionHoldCount_ = 10;
- }
-
- /**
- @brief Execute the spin. Called within tick.
- */
- void ArtificialController::spin()
- {
- this->moveToTargetPosition();
- this->getControllableEntity()->rotateRoll(0.8f);
- }
-
- /**
- @brief Master begins to follow a pawn. Is a "specific master action".
- @param pawn pawn to follow.
- @param always follows pawn forever if true (false if omitted).
- @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header).
- */
- void ArtificialController::followInit(Pawn* pawn, const bool always, const int secondsToFollow)
- {
- if (pawn == NULL || this->state_ != MASTER)
- return;
- this->specificMasterAction_ = FOLLOW;
-
- this->setTarget(pawn);
- if (!always)
- this->specificMasterActionHoldCount_ = secondsToFollow;
- else
- this->specificMasterActionHoldCount_ = INT_MAX; //for now...
-
- }
-
-
- /**
- @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
- */
- void ArtificialController::followRandomHumanInit()
- {
-
- Pawn *humanPawn = NULL;
- NewHumanController *currentHumanController = NULL;
-
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- if (!it->getController())
- continue;
-
- currentHumanController = orxonox_cast<NewHumanController*>(it->getController());
- if(currentHumanController)
- {
- if (!ArtificialController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;
- humanPawn = *it;
- break;
- }
- }
-
- if((humanPawn != NULL))
- this->followInit(humanPawn);
- }
-
- /**
- @brief Master follows target with adjusted speed. Called within tick.
- */
- void ArtificialController::follow()
- {
- if (this->target_)
- this->moveToPosition(this->target_->getPosition());
- else
- this->specificMasterActionHoldCount_ = 0;
-/*
- if (!this->getControllableEntity())
- return;
-
- float distance = (this->target_->getPosition() - this->getControllableEntity()->getPosition()).length();
-
- Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->target_->getPosition());
-
-
- this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
-
- float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->target_->getVelocity().squaredLength();
-
-orxout() << "~follow distance: " << distance << "SpeedCounter: " << this->speedCounter_ << "~speedDiv: " << speedDiv << endl;
- if (distance < 800)
- {
- if (distance < 200)
- {
- this->speedCounter_ -= 0.5f;
- if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
- this->getControllableEntity()->moveFrontBack(speedCounter_);
- } else {
- if(speedDiv < 0)
- this->speedCounter_ += 0.01f;
- else
- this->speedCounter_ -= 0.05f;
- this->getControllableEntity()->moveFrontBack(speedCounter_);
- }
-
- } else {
- this->speedCounter_ += 0.05f;
- this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
- }
-// if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
-
-*/
- }
-
-
- /**
- @brief Slave moving behaviour when master is following a pawn, gets redirected from moveToPosition(const Vector3& target)). Called within tick.
- */
- void ArtificialController::followForSlaves(const Vector3& target)
- {
-
-/*
- if (!this->getControllableEntity() && !this->myMaster_ && this->myMaster_->state_ != FOLLOW && !this->myMaster_->target_)
- return;
-
- float distance = (target - this->getControllableEntity()->getPosition()).length();
-
- Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
-
-
- this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
-
-
- float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->myMaster_->target_->getVelocity().squaredLength();
-
-
- if (distance < 800)
- {
- if (distance < 200)
- {
- this->speedCounter_ -= 5.0f;
- if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f;
- this->getControllableEntity()->moveFrontBack(speedCounter_);
- } else {
- if(speedDiv < 0)
- this->speedCounter_ += 0.01f;
- else
- this->speedCounter_ -= 0.05f;
- this->getControllableEntity()->moveFrontBack(speedCounter_);
- }
-
- } else {
- this->speedCounter_ += 0.05f;
- this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f);
- }
-// if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0;
-*/
- }
-
-
- void ArtificialController::setTargetPosition(const Vector3& target)
- {
- this->targetPosition_ = target;
- this->bHasTargetPosition_ = true;
- }
-
- void ArtificialController::searchRandomTargetPosition()
- {
- this->targetPosition_ = Vector3(rnd(-2000,2000), rnd(-2000,2000), rnd(-2000,2000));
- this->bHasTargetPosition_ = true;
- }
-
- void ArtificialController::setTarget(Pawn* target)
- {
- this->target_ = target;
-
- if (target)
- this->targetPosition_ = target->getPosition();
- }
-
- void ArtificialController::searchNewTarget()
- {
- if (!this->getControllableEntity())
- return;
-
- this->targetPosition_ = this->getControllableEntity()->getPosition();
- this->forgetTarget();
-
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
- if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
- continue;
-
- /* So AI won't choose invisible Spaceships as target */
- if (!it->getRadarVisibility())
- continue;
-
- if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
- {
- float speed = this->getControllableEntity()->getVelocity().length();
- Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition();
- Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();
- if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi)
- < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / math::twoPi) + rnd(-250, 250))
- {
- this->target_ = (*it);
- this->targetPosition_ = it->getPosition();
- }
- }
- }
- }
-
- void ArtificialController::forgetTarget()
- {
- this->target_ = 0;
- this->bShooting_ = false;
- }
-
void ArtificialController::aimAtTarget()
{
if (!this->target_ || !this->getControllableEntity())
@@ -949,132 +112,7 @@
this->targetDied();
}
- void ArtificialController::targetDied()
- {
- this->forgetTarget();
- this->searchRandomTargetPosition();
- }
-
- bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
- {
- if(!entity1 || !entity2)
- return true;
- if (entity1 == entity2)
- return true;
-
- int team1 = -1;
- int team2 = -1;
-
- Controller* controller = 0;
- if (entity1->getController())
- controller = entity1->getController();
- else
- controller = entity1->getXMLController();
- if (controller)
- {
- ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
- if (ac)
- team1 = ac->getTeam();
- }
-
- if (entity2->getController())
- controller = entity2->getController();
- else
- controller = entity2->getXMLController();
- if (controller)
- {
- ArtificialController* ac = orxonox_cast<ArtificialController*>(controller);
- if (ac)
- team2 = ac->getTeam();
- }
-
- TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype);
- if (tdm)
- {
- if (entity1->getPlayer())
- team1 = tdm->getTeam(entity1->getPlayer());
-
- if (entity2->getPlayer())
- team2 = tdm->getTeam(entity2->getPlayer());
- }
-
- Mission* miss = orxonox_cast<Mission*>(gametype);
- if (miss)
- {
- if (entity1->getPlayer())
- team1 = miss->getTeam(entity1->getPlayer());
-
- if (entity2->getPlayer())
- team2 = miss->getTeam(entity2->getPlayer());
- }
-
- TeamBaseMatchBase* base = 0;
- base = orxonox_cast<TeamBaseMatchBase*>(entity1);
- if (base)
- {
- switch (base->getState())
- {
- case BaseState::ControlTeam1:
- team1 = 0;
- break;
- case BaseState::ControlTeam2:
- team1 = 1;
- break;
- case BaseState::Uncontrolled:
- default:
- team1 = -1;
- }
- }
- base = orxonox_cast<TeamBaseMatchBase*>(entity2);
- if (base)
- {
- switch (base->getState())
- {
- case BaseState::ControlTeam1:
- team2 = 0;
- break;
- case BaseState::ControlTeam2:
- team2 = 1;
- break;
- case BaseState::Uncontrolled:
- default:
- team2 = -1;
- }
- }
-
- DroneController* droneController = 0;
- droneController = orxonox_cast<DroneController*>(entity1->getController());
- if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
- return true;
- droneController = orxonox_cast<DroneController*>(entity2->getController());
- if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
- return true;
- DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
- DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
- if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
- return true;
-
- Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
- if (dynamic)
- {
- if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
-
- if (entity1->getPlayer())
- team1 = dynamic->getParty(entity1->getPlayer());
-
- if (entity2->getPlayer())
- team2 = dynamic->getParty(entity2->getPlayer());
-
- if (team1 ==-1 ||team2 ==-1 ) {return false;}
- else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
- else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
- else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
- else return true;
- }
-
- return (team1 == team2 && team1 != -1);
- }
-
+//****************************************************************************************** NEW
/**
@brief DoFire is called when a bot should shoot and decides which weapon is used and whether the bot shoots at all.
*/
@@ -1227,7 +265,7 @@
}
/**
- @brief Adds point of interest depending on context. Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
+ @brief Adds point of interest depending on context. TODO: Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
*/
void ArtificialController::manageWaypoints()
{
@@ -1236,5 +274,5 @@
else
this->updatePointsOfInterest("PickupSpawner", 20.0f); // take pickup en passant if there is a default waypoint
}
-
+
}
Modified: code/branches/presentation2011/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/ArtificialController.h 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/ArtificialController.h 2011-12-16 19:36:41 UTC (rev 8992)
@@ -30,54 +30,20 @@
#define _ArtificialController_H__
#include "OrxonoxPrereqs.h"
+#include "controllers/FormationController.h"
-#include <map>
-
-#include "util/Math.h"
-#include "Controller.h"
-#include "controllers/NewHumanController.h"
-#include "weaponsystem/WeaponSystem.h"
-
namespace orxonox
{
- class _OrxonoxExport ArtificialController : public Controller
+ class _OrxonoxExport ArtificialController : public FormationController
{
public:
ArtificialController(BaseObject* creator);
virtual ~ArtificialController();
- virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-
void abandonTarget(Pawn* target);
- inline void setTeam(int team) //TODO: write through to controllable entity.
- { this->team_ = team; }
- inline int getTeam() const
- { return this->team_; }
-
- inline void setFormationFlight(bool formation)
- { this->formationFlight_ = formation; }
- inline bool getFormationFlight() const
- { return this->formationFlight_; }
-
- inline void setFormationSize(int size)
- { this->maxFormationSize_ = size; }
- inline int getFormationSize() const
- { return this->maxFormationSize_; }
-
- inline void setPassive(bool passive)
- { this->passive_ = passive; }
- inline bool getPassive() const
- { return this->passive_; }
-
virtual void changedControllableEntity();
-
- static void formationflight(const bool form);
- static void masteraction(const int action);
- static void followme();
- static void passivebehaviour(const bool passive);
- static void formationsize(const int size);
-
+//************************************************************************* NEW
virtual void doFire();
void setBotLevel(float level=1.0f);
inline float getBotLevel() const
@@ -94,89 +60,39 @@
void updatePointsOfInterest(std::string name, float distance);
void manageWaypoints();
- protected:
+
- int team_;
- bool formationFlight_;
- bool passive_;
- unsigned int maxFormationSize_;
- int freedomCount_;
- enum State {SLAVE, MASTER, FREE};
- State state_;
- std::vector<ArtificialController*> slaves_;
- ArtificialController *myMaster_;
- enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
- SpecificMasterAction specificMasterAction_;
- int specificMasterActionHoldCount_;
- float speedCounter_; //for speed adjustment when following
-
- void moveToPosition(const Vector3& target);
- void moveToTargetPosition();
- void absoluteMoveToPosition(const Vector3& target);
-
- virtual void positionReached() {}
-
- void removeFromFormation();
- void unregisterSlave();
- void searchNewMaster();
- void commandSlaves();
- void setNewMasterWithinFormation();
-
- void freeSlaves();
- void forceFreeSlaves();
- void loseMasterState();
- void forceFreedom();
- bool forcedFree();
-
- void specificMasterActionHold();
- void turn180Init();
- void turn180();
- void spinInit();
- void spin();
- void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
- void followRandomHumanInit();
- void follow();
- void followForSlaves(const Vector3& target);
-
- void setTargetPosition(const Vector3& target);
- void searchRandomTargetPosition();
-
- void setTarget(Pawn* target);
- void searchNewTarget();
- void forgetTarget();
+ protected:
+
void aimAtTarget();
bool isCloseAtTarget(float distance) const;
bool isLookingAtTarget(float angle) const;
-
- void targetDied();
-
- static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
- void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost.
-
- bool bHasTargetPosition_;
- Vector3 targetPosition_;
- WeakPtr<Pawn> target_;
- bool bShooting_;
-
+//************************************************************************* NEW
float botlevel_; //<! Makes the level of a bot configurable.
enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
void setPreviousMode();
+
//WEAPONSYSTEM DATA
- std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()
+ 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);
+
//WAYPOINT DATA
std::vector<WeakPtr<WorldEntity> > waypoints_;
size_t currentWaypoint_;
float squaredaccuracy_;
WorldEntity* defaultWaypoint_;
+
+ void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost.
+
+ private:
};
}
Modified: code/branches/presentation2011/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/CMakeLists.txt 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/CMakeLists.txt 2011-12-16 19:36:41 UTC (rev 8992)
@@ -8,4 +8,5 @@
WaypointController.cc
WaypointPatrolController.cc
DroneController.cc
+ FormationController.cc
)
Copied: code/branches/presentation2011/src/orxonox/controllers/FormationController.cc (from rev 8991, code/branches/formation/src/orxonox/controllers/FormationController.cc)
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/FormationController.cc (rev 0)
+++ code/branches/presentation2011/src/orxonox/controllers/FormationController.cc 2011-12-16 19:36:41 UTC (rev 8992)
@@ -0,0 +1,1065 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * Dominik Solenicki
+ *
+ */
+
+#include <climits>
+#include "controllers/FormationController.h"
+
+#include "core/CoreIncludes.h"
+
+#include "core/XMLPort.h"
+#include "core/command/ConsoleCommand.h"
+
+#include "worldentities/ControllableEntity.h"
+#include "worldentities/pawns/Pawn.h"
+#include "worldentities/pawns/TeamBaseMatchBase.h"
+#include "gametypes/TeamDeathmatch.h"
+#include "gametypes/Dynamicmatch.h"
+#include "gametypes/Mission.h" TODO: include mission after merging
+#include "gametypes/Gametype.h"
+#include "controllers/WaypointPatrolController.h"
+#include "controllers/NewHumanController.h"
+#include "controllers/DroneController.h"
+
+
+namespace orxonox
+{
+
+ SetConsoleCommand("FormationController", "formationflight", &FormationController::formationflight);
+ SetConsoleCommand("FormationController", "masteraction", &FormationController::masteraction);
+ SetConsoleCommand("FormationController", "followme", &FormationController::followme);
+ SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);
+ SetConsoleCommand("FormationController", "formationsize", &FormationController::formationsize);
+
+
+
+
+ static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
+ static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
+ static const int FORMATION_LENGTH = 110;
+ static const int FORMATION_WIDTH = 110;
+ static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
+ static const float SPEED_MASTER = 0.6f;
+ static const float ROTATEFACTOR_MASTER = 0.2f;
+ static const float SPEED_FREE = 0.8f;
+ static const float ROTATEFACTOR_FREE = 0.8f;
+
+ FormationController::FormationController(BaseObject* creator) : Controller(creator)
+ {
+ RegisterObject(FormationController);
+
+ this->target_ = 0;
+ this->formationFlight_ = false;
+ this->passive_ = false;
+ this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE;
+ this->myMaster_ = 0;
+ this->freedomCount_ = 0;
+
+ this->state_ = FREE;
+ this->formationMode_ = NORMAL;
+ this->specificMasterAction_ = NONE;
+ this->specificMasterActionHoldCount_ = 0;
+ this->bShooting_ = false;
+ this->bHasTargetPosition_ = false;
+ this->bHasTargetOrientation_=false;
+ this->speedCounter_ = 0.2f;
+ this->targetPosition_ = Vector3::ZERO;
+ //this->team_=-1;
+ this->target_.setCallback(createFunctor(&FormationController::targetDied, this));
+ }
+
+ FormationController::~FormationController()
+ {
+ if (this->isInitialized())
+ {
+ this->removeFromFormation();
+
+ for (ObjectList<FormationController>::iterator it = ObjectList<FormationController>::begin(); it; ++it)
+ {
+ if (*it != this)
+ {
+ if (it->myMaster_ == this)
+ {
+ orxout(internal_error) << this << " is still master in " << (*it) << endl;
+ it->myMaster_ = 0;
+ }
+
+ while (true)
+ {
+ std::vector<FormationController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this);
+ if (it2 != it->slaves_.end())
+ {
+ orxout(internal_error) << this << " is still slave in " << (*it) << endl;
+ it->slaves_.erase(it2);
+ }
+ else
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(FormationController, XMLPort, xmlelement, mode);
+
+ XMLPortParam(FormationController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
+ XMLPortParam(FormationController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
+ XMLPortParam(FormationController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
+ }
+
+
+
+ /**
+ @brief Activates / deactivates formationflight behaviour
+ @param form activate formflight if form is true
+ */
+ void FormationController::formationflight(const bool form)
+ {
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ Controller* controller = 0;
+
+ if (it->getController())
+ controller = it->getController();
+ else if (it->getXMLController())
+ controller = it->getXMLController();
+
+ if (!controller)
+ continue;
+
+ FormationController *aiController = orxonox_cast<FormationController*>(controller);
+
+ if (aiController)
+ {
+ aiController->formationFlight_ = form;
+ if (!form)
+ {
+ aiController->removeFromFormation();
+ }
+ }
+ }
+ }
+
+ /**
+ @brief Get all masters to do a "specific master action"
+ @param action which action to perform (integer, so it can be called with a console command (tmp solution))
+ */
+ void FormationController::masteraction(const int action)
+ {
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ Controller* controller = 0;
+
+ if (it->getController())
+ controller = it->getController();
+ else if (it->getXMLController())
+ controller = it->getXMLController();
+
+ if (!controller)
+ continue;
+
+ FormationController *aiController = orxonox_cast<FormationController*>(controller);
+
+ if(aiController && aiController->state_ == MASTER)
+ {
+ if (action == 1)
+ aiController->spinInit();
+ if (action == 2)
+ aiController->turn180Init();
+ }
+ }
+ }
+
+ /**
+ @brief Sets shooting behaviour of pawns.
+ @param passive if true, bots won't shoot.
+ */
+ void FormationController::passivebehaviour(const bool passive)
+ {
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ Controller* controller = 0;
+
+ if (it->getController())
+ controller = it->getController();
+ else if (it->getXMLController())
+ controller = it->getXMLController();
+
+ if (!controller)
+ continue;
+
+ FormationController *aiController = orxonox_cast<FormationController*>(controller);
+
+ if(aiController)
+ {
+ aiController->passive_ = passive;
+ }
+ }
+ }
+
+ /**
+ @brief Sets maximal formation size
+ @param size maximal formation size.
+ */
+ void FormationController::formationsize(const int size)
+ {
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ Controller* controller = 0;
+
+ if (it->getController())
+ controller = it->getController();
+ else if (it->getXMLController())
+ controller = it->getXMLController();
+
+ if (!controller)
+ continue;
+
+ FormationController *aiController = orxonox_cast<FormationController*>(controller);
+
+ if(aiController)
+ {
+ aiController->maxFormationSize_ = size;
+ }
+ }
+ }
+
+ void FormationController::removeFromFormation()
+ {
+ if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set
+ this->unregisterSlave();
+ else if (this->state_ == MASTER)
+ this->setNewMasterWithinFormation();
+ }
+
+ void FormationController::moveToPosition(const Vector3& target)
+ {
+ if (!this->getControllableEntity())
+ return;
+
+ // Slave uses special movement if its master is in FOLLOW mode
+ if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW)
+ {
+// this->followForSlaves(target);
+// return;
+ }
+
+ Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+ float distance = (target - this->getControllableEntity()->getPosition()).length();
+
+
+ if(this->state_ == FREE)
+ {
+ if (this->target_ || distance > 10)
+ {
+ // Multiply with ROTATEFACTOR_FREE to make them a bit slower
+ this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
+ this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
+ }
+
+ if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
+ {
+ this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
+ } else this->getControllableEntity()->moveFrontBack(SPEED_FREE);
+ }
+
+
+
+ if(this->state_ == MASTER)
+ {
+ if (this->target_ || distance > 10)
+ {
+ this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
+ this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+ }
+
+ if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
+ {
+ this->getControllableEntity()->moveFrontBack(-0.05f);
+ } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
+ }
+
+
+
+ if(this->state_ == SLAVE)
+ {
+
+ this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
+ this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+
+ if (distance < 300)
+ {
+ if (bHasTargetOrientation_)
+ {
+ copyTargetOrientation();
+ }
+ if (distance < 100)
+ { //linear speed reduction
+ this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
+
+ } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
+
+ } else {
+ this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
+ }
+ }
+
+ if (distance < 10)
+ {
+ this->positionReached();
+ bHasTargetOrientation_=false;
+ }
+ }
+
+
+
+ void FormationController::moveToTargetPosition()
+ {
+ this->moveToPosition(this->targetPosition_);
+ }
+
+ //copy the Roll orientation of given Quaternion.
+ void FormationController::copyOrientation(const Quaternion& orient)
+ {
+ //roll angle difference in radian
+ float diff=orient.getRoll(false).valueRadians()-(this->getControllableEntity()->getOrientation().getRoll(false).valueRadians());
+ while(diff>math::twoPi) diff-=math::twoPi;
+ while(diff<-math::twoPi) diff+=math::twoPi;
+ this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR_MASTER);
+ }
+
+ void FormationController::copyTargetOrientation()
+ {
+ if (bHasTargetOrientation_)
+ {
+ copyOrientation(targetOrientation_);
+ }
+ }
+
+
+ /**
+ @brief Unregisters a slave from its master. Initiated by a slave.
+ */
+ void FormationController::unregisterSlave()
+ {
+ if (this->myMaster_)
+ {
+ std::vector<FormationController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this);
+ if (it != this->myMaster_->slaves_.end())
+ this->myMaster_->slaves_.erase(it);
+ }
+
+ this->myMaster_ = 0;
+ this->state_ = FREE;
+ }
+
+ void FormationController::searchNewMaster()
+ {
+
+ if (!this->getControllableEntity())
+ return;
+
+ this->targetPosition_ = this->getControllableEntity()->getPosition();
+ this->forgetTarget();
+ int teamSize = 0;
+ //go through all pawns
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+
+ //same team?
+ Gametype* gt=this->getGametype();
+ if (!gt)
+ {
+ gt=it->getGametype();
+ }
+ if (!FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it),gt))
+ continue;
+
+ //has it an FormationController?
+ Controller* controller = 0;
+
+ if (it->getController())
+ controller = it->getController();
+ else if (it->getXMLController())
+ controller = it->getXMLController();
+
+ if (!controller)
+ continue;
+
+ //is pawn oneself?
+ if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
+ continue;
+
+ teamSize++;
+
+ FormationController *newMaster = orxonox_cast<FormationController*>(controller);
+
+ //is it a master?
+ if (!newMaster || newMaster->state_ != MASTER)
+ continue;
+
+ float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length();
+
+ // is pawn in range?
+ if (distance < RADIUS_TO_SEARCH_FOR_MASTERS)
+ {
+ if(newMaster->slaves_.size() > this->maxFormationSize_) continue;
+
+ for(std::vector<FormationController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
+ {
+ (*itSlave)->myMaster_ = newMaster;
+ newMaster->slaves_.push_back(*itSlave);
+ }
+ this->slaves_.clear();
+ this->state_ = SLAVE;
+
+ this->myMaster_ = newMaster;
+ newMaster->slaves_.push_back(this);
+
+ break;
+ }
+ }
+
+ if (this->state_ != SLAVE && teamSize != 0)
+ {
+ this->state_ = MASTER;
+ this->myMaster_ = 0;
+ }
+ }
+ /**
+ @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
+ */
+
+void FormationController::commandSlaves()
+ {
+ if(this->state_ != MASTER) return;
+
+ Quaternion orient = this->getControllableEntity()->getOrientation();
+ Vector3 dest = this->getControllableEntity()->getPosition();
+
+ // 1 slave: follow
+ if (this->slaves_.size() == 1)
+ {
+ dest += 4*orient*WorldEntity::BACK;
+ this->slaves_.front()->setTargetPosition(dest);
+ }
+ else
+ // formation:
+ {
+ dest += 1.0f*orient*WorldEntity::BACK;
+ Vector3 pos = Vector3::ZERO;
+ bool left=true;
+ int i = 1;
+
+ for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+ {
+ pos = Vector3::ZERO;
+ if (left)
+ {
+ pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::LEFT);
+ } else{
+ pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
+ i++;
+ dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK);
+ }
+ (*it)->setTargetOrientation(orient);
+ (*it)->setTargetPosition(pos);
+ left=!left;
+ }
+ }
+ }
+
+ /**
+ @brief Sets a new master within the formation. Called by a master.
+ */
+ void FormationController::setNewMasterWithinFormation()
+ {
+ if(this->state_ != MASTER) return;
+
+ if (!this->slaves_.empty())
+ {
+ FormationController *newMaster = this->slaves_.back();
+ this->slaves_.pop_back();
+
+ newMaster->state_ = MASTER;
+ newMaster->slaves_ = this->slaves_;
+ newMaster->myMaster_ = 0;
+
+ for(std::vector<FormationController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
+ {
+ (*it)->myMaster_ = newMaster;
+ }
+ }
+
+ this->slaves_.clear();
+ this->specificMasterAction_ = NONE;
+ this->state_ = FREE;
+ }
+
+
+ /**
+ @brief Frees all slaves form a master. Initiated by a master.
+ */
+ void FormationController::freeSlaves()
+ {
+ if(this->state_ != MASTER) return;
+
+ for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+ {
+ (*it)->state_ = FREE;
+ (*it)->myMaster_ = 0;
+ }
+ this->slaves_.clear();
+ }
+
+ /**
+ @brief Master sets its slaves free for @ref FREEDOM_COUNT seconds.
+ */
+ void FormationController::forceFreeSlaves()
+ {
+ if(this->state_ != MASTER) return;
+
+ for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+ {
+ (*it)->state_ = FREE;
+ (*it)->forceFreedom();
+ (*it)->targetPosition_ = this->targetPosition_;
+ (*it)->bShooting_ = true;
+// (*it)->getControllableEntity()->fire(0);// fire once for fun
+ }
+ }
+
+ void FormationController::loseMasterState()
+ {
+ this->freeSlaves();
+ this->state_ = FREE;
+ }
+
+
+ void FormationController::forceFreedom()
+ {
+ this->freedomCount_ = FREEDOM_COUNT;
+ }
+
+ /**
+ @brief Checks wether caller has been forced free, decrements time to stay forced free.
+ @return true if forced free.
+ */
+ bool FormationController::forcedFree()
+ {
+ if(this->freedomCount_ > 0)
+ {
+ this->freedomCount_--;
+ return true;
+ } else return false;
+ }
+
+
+ /**
+ @brief Call to take the lead of formation (if free, become slave of nearest formation, then, if Slave, become Master)
+ */
+ void FormationController::takeLeadOfFormation()
+ {
+ if (!this->getControllableEntity())
+ return;
+
+ if (this->state_==MASTER) return;
+ //search new Master, then take lead
+ if (this->state_==FREE)
+ {
+ searchNewMaster();
+ }
+
+ if (this->state_==SLAVE) //become master of this formation
+ {
+ this->slaves_=this->myMaster_->slaves_;
+ this->myMaster_->slaves_.clear();
+ this->myMaster_->state_=SLAVE;
+ this->myMaster_->myMaster_=this;
+
+ //delete myself in slavelist
+ std::vector<FormationController*>::iterator it2 = std::find(this->slaves_.begin(), this->slaves_.end(), this);
+ if (it2 != this->slaves_.end())
+ {
+ this->slaves_.erase(it2);
+ }
+ //add previous master
+ this->slaves_.push_back(this->myMaster_);
+ //set this as new master
+ for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+ {
+ (*it)->myMaster_=this;
+ }
+ this->myMaster_=0;
+ this->state_=MASTER;
+ }
+ /*/debug
+ if (this->state_==SLAVE)
+ {orxout(debug_output) << this << " is slave "<< endl;}
+ else if (this->state_==MASTER)
+ {orxout(debug_output) << this << " is now a master of "<<this->slaves_.size()<<" slaves."<< endl;}
+ if (this->state_==FREE)
+ {orxout(debug_output) << this << " is free "<< endl;}*/
+ }
+ /**
+ @brief if called, half of the formation will attack the originator
+ */
+ void FormationController::masterAttacked(Pawn* originator)
+ {
+ if (this->state_!=MASTER) return;
+ unsigned int i=0;
+ for(std::vector<FormationController*>::reverse_iterator it = slaves_.rbegin(); it != slaves_.rend(); it++)
+ {
+ if ((*it)->state_!=FREE)
+ {
+ (*it)->state_=FREE;
+ (*it)->forceFreedom();
+ (*it)->target_=originator;
+ }
+ i++;
+ if (i>=slaves_.size()/2) break; //half the formation should attack.
+ }
+ }
+
+
+ /**
+ @brief Sets the new mode. If master, set it for all slaves.
+ */
+ void FormationController::setFormationMode(FormationMode val)
+ {
+ this->formationMode_ = val;
+ if (this->state_ == MASTER)
+ {
+ for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+ {
+ (*it)->formationMode_ = val;
+ if (val == ATTACK)
+ (*it)->forgetTarget();
+ }
+ }
+ }
+
+ /**
+ @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
+ */
+ void FormationController::specificMasterActionHold()
+ {
+ if(this->state_ != MASTER) return;
+
+ if (specificMasterActionHoldCount_ == 0)
+ {
+ this->specificMasterAction_ = NONE;
+ this->searchNewTarget();
+ }
+ else specificMasterActionHoldCount_--;
+ }
+
+ /**
+ @brief Master initializes a 180 degree turn. Leads to a "specific master action".
+ */
+ void FormationController::turn180Init()
+ {
+ if(this->state_ != MASTER) return;
+
+ Quaternion orient = this->getControllableEntity()->getOrientation();
+
+ this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK);
+
+ this->specificMasterActionHoldCount_ = 4;
+
+ this->specificMasterAction_ = TURN180;
+ }
+
+ /**
+ @brief Execute the 180 degree turn. Called within tick.
+ */
+ void FormationController::turn180()
+ {
+ Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
+
+ this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
+ this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
+
+ this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
+ }
+
+ /**
+ @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action".
+ */
+ void FormationController::spinInit()
+ {
+ if(this->state_ != MASTER) return;
+ this->specificMasterAction_ = SPIN;
+ this->specificMasterActionHoldCount_ = 10;
+ }
+
+ /**
+ @brief Execute the spin. Called within tick.
+ */
+ void FormationController::spin()
+ {
+ this->moveToTargetPosition();
+ this->getControllableEntity()->rotateRoll(0.8f);
+ }
+
+ /**
+ @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup).
+ */
+ void FormationController::followme()
+ {
+
+ Pawn *humanPawn = NULL;
+ NewHumanController *currentHumanController = NULL;
+ std::vector<FormationController*> allMasters;
+
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ Controller* controller = 0;
+
+ if (it->getController())
+ controller = it->getController();
+ else if (it->getXMLController())
+ controller = it->getXMLController();
+
+ if (!controller)
+ continue;
+
+ currentHumanController = orxonox_cast<NewHumanController*>(controller);
+
+ if(currentHumanController) humanPawn = *it;
+
+ FormationController *aiController = orxonox_cast<FormationController*>(controller);
+
+ if(aiController && aiController->state_ == MASTER)
+ allMasters.push_back(aiController);
+
+ }
+
+ if((humanPawn != NULL) && (allMasters.size() != 0))
+ {
+ float posHuman = humanPawn->getPosition().length();
+ float distance = 0.0f;
+ float minDistance = FLT_MAX;
+ int index = 0;
+ int i = 0;
+
+ for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
+ {
+ if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
+ distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
+ if(distance < minDistance) index = i;
+ }
+ allMasters[index]->followInit(humanPawn);
+ }
+
+ }
+
+
+
+
+
+ /**
+ @brief Master begins to follow a pawn. Is a "specific master action".
+ @param pawn pawn to follow.
+ @param always follows pawn forever if true (false if omitted).
+ @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header).
+ */
+ void FormationController::followInit(Pawn* pawn, const bool always, const int secondsToFollow)
+ {
+ if (pawn == NULL || this->state_ != MASTER)
+ return;
+ this->specificMasterAction_ = FOLLOW;
+
+ this->setTarget(pawn);
+ if (!always)
+ this->specificMasterActionHoldCount_ = secondsToFollow;
+ else
+ this->specificMasterActionHoldCount_ = INT_MAX; //for now...
+
+ }
+
+ /**
+ @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
+ */
+ void FormationController::followRandomHumanInit()
+ {
+
+ Pawn *humanPawn = NULL;
+ NewHumanController *currentHumanController = NULL;
+
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ if (!it->getController())
+ continue;
+
+ currentHumanController = orxonox_cast<NewHumanController*>(it->getController());
+ if(currentHumanController)
+ {
+ if (!FormationController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;
+ humanPawn = *it;
+ break;
+ }
+ }
+
+ if((humanPawn != NULL))
+ this->followInit(humanPawn);
+ }
+
+
+ /**
+ @brief Master follows target with adjusted speed. Called within tick.
+ */
+ void FormationController::follow()
+ {
+ if (this->target_)
+ this->moveToPosition(this->target_->getPosition());
+ else
+ this->specificMasterActionHoldCount_ = 0;
+ }
+
+
+ void FormationController::setTargetPosition(const Vector3& target)
+ {
+ this->targetPosition_ = target;
+ this->bHasTargetPosition_ = true;
+ }
+
+ void FormationController::searchRandomTargetPosition()
+ {
+ this->targetPosition_ = Vector3(rnd(-2000,2000), rnd(-2000,2000), rnd(-2000,2000));
+ this->bHasTargetPosition_ = true;
+ }
+
+ void FormationController::setTargetOrientation(const Quaternion& orient)
+ {
+ this->targetOrientation_=orient;
+ this->bHasTargetOrientation_=true;
+ }
+
+ void FormationController::setTargetOrientation(Pawn* target)
+ {
+ if (target)
+ setTargetOrientation(target->getOrientation());
+ }
+
+ void FormationController::setTarget(Pawn* target)
+ {
+ this->target_ = target;
+
+ if (target)
+ this->targetPosition_ = target->getPosition();
+ }
+
+ void FormationController::searchNewTarget()
+ {
+ if (!this->getControllableEntity())
+ return;
+
+ this->targetPosition_ = this->getControllableEntity()->getPosition();
+ this->forgetTarget();
+
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ if (FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+ continue;
+
+ /* So AI won't choose invisible Spaceships as target */
+ if (!it->getRadarVisibility())
+ continue;
+
+ if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
+ {
+ float speed = this->getControllableEntity()->getVelocity().length();
+ Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition();
+ Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();
+ if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi)
+ < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / math::twoPi) + rnd(-250, 250))
+ {
+ this->target_ = (*it);
+ this->targetPosition_ = it->getPosition();
+ }
+ }
+ }
+ }
+
+ void FormationController::forgetTarget()
+ {
+ this->target_ = 0;
+ this->bShooting_ = false;
+ }
+
+ void FormationController::targetDied()
+ {
+ this->forgetTarget();
+ this->searchRandomTargetPosition();
+ }
+
+ bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+ {
+ if (entity1 == entity2)
+ return true;
+
+ int team1 = -1;
+ int team2 = -1;
+
+ Controller* controller = 0;
+ if (entity1->getController())
+ controller = entity1->getController();
+ else
+ controller = entity1->getXMLController();
+ if (controller)
+ {
+ FormationController* ac = orxonox_cast<FormationController*>(controller);
+ if (ac)
+ team1 = ac->getTeam();
+ }
+
+ if (entity2->getController())
+ controller = entity2->getController();
+ else
+ controller = entity2->getXMLController();
+ if (controller)
+ {
+ FormationController* ac = orxonox_cast<FormationController*>(controller);
+ if (ac)
+ team2 = ac->getTeam();
+ }
+
+ TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype);
+ if (tdm)
+ {
+ if (entity1->getPlayer())
+ team1 = tdm->getTeam(entity1->getPlayer());
+
+ if (entity2->getPlayer())
+ team2 = tdm->getTeam(entity2->getPlayer());
+ }
+
+ Mission* miss = orxonox_cast<Mission*>(gametype);
+ if (miss)
+ {
+ if (entity1->getPlayer())
+ team1 = miss->getTeam(entity1->getPlayer());
+
+ if (entity2->getPlayer())
+ team2 = miss->getTeam(entity2->getPlayer());
+ }
+
+ TeamBaseMatchBase* base = 0;
+ base = orxonox_cast<TeamBaseMatchBase*>(entity1);
+ if (base)
+ {
+ switch (base->getState())
+ {
+ case BaseState::ControlTeam1:
+ team1 = 0;
+ break;
+ case BaseState::ControlTeam2:
+ team1 = 1;
+ break;
+ case BaseState::Uncontrolled:
+ default:
+ team1 = -1;
+ }
+ }
+ base = orxonox_cast<TeamBaseMatchBase*>(entity2);
+ if (base)
+ {
+ switch (base->getState())
+ {
+ case BaseState::ControlTeam1:
+ team2 = 0;
+ break;
+ case BaseState::ControlTeam2:
+ team2 = 1;
+ break;
+ case BaseState::Uncontrolled:
+ default:
+ team2 = -1;
+ }
+ }
+
+ DroneController* droneController = 0;
+ droneController = orxonox_cast<DroneController*>(entity1->getController());
+ if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
+ return true;
+ droneController = orxonox_cast<DroneController*>(entity2->getController());
+ if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
+ return true;
+ DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
+ DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
+ if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
+ return true;
+
+ Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
+ if (dynamic)
+ {
+ if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
+
+ if (entity1->getPlayer())
+ team1 = dynamic->getParty(entity1->getPlayer());
+
+ if (entity2->getPlayer())
+ team2 = dynamic->getParty(entity2->getPlayer());
+
+ if (team1 ==-1 ||team2 ==-1 ) {return false;}
+ else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
+ else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
+ else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
+ else return true;
+ }
+
+ return (team1 == team2 && team1 != -1);
+ }
+
+ void FormationController::absoluteMoveToPosition(const Vector3& target)
+ {
+ float minDistance = 40.0f;
+ if (!this->getControllableEntity())
+ return;
+
+ Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+ float distance = (target - this->getControllableEntity()->getPosition()).length();
+
+ if (this->target_ || distance > minDistance)
+ {
+ // Multiply with ROTATEFACTOR_FREE to make them a bit slower
+ this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
+ this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
+ this->getControllableEntity()->moveFrontBack(SPEED_FREE);
+ }
+
+
+ if (distance < minDistance)
+ {
+ this->positionReached();
+ }
+ }
+
+}
Copied: code/branches/presentation2011/src/orxonox/controllers/FormationController.h (from rev 8991, code/branches/formation/src/orxonox/controllers/FormationController.h)
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/FormationController.h (rev 0)
+++ code/branches/presentation2011/src/orxonox/controllers/FormationController.h 2011-12-16 19:36:41 UTC (rev 8992)
@@ -0,0 +1,178 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _FormationController_h__
+#define _FormationController_h__
+
+#include "OrxonoxPrereqs.h"
+
+#include <vector>
+#include "core/Super.h"
+
+#include "util/Math.h"
+#include "core/OrxonoxClass.h"
+#include "controllers/Controller.h"
+#include "worldentities/ControllableEntity.h"
+
+
+namespace orxonox {
+
+ class _OrxonoxExport FormationController : public Controller
+ {
+
+ public:
+ FormationController(BaseObject* creator);
+
+ virtual ~FormationController();
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+
+ static void formationflight(const bool form);
+ static void masteraction(const int action);
+ static void followme();
+ static void passivebehaviour(const bool passive);
+ static void formationsize(const int size);
+
+ inline void setFormationFlight(bool formation)
+ { this->formationFlight_ = formation; }
+ inline bool getFormationFlight() const
+ { return this->formationFlight_; }
+
+ inline void setFormationSize(int size)
+ { this->maxFormationSize_ = size; }
+ inline int getFormationSize() const
+ { return this->maxFormationSize_; }
+
+
+ inline void setPassive(bool passive)
+ { this->passive_ = passive; }
+ inline bool getPassive() const
+ { return this->passive_; }
+
+ inline void setTeam(int team)
+ { this->team_ = team;
+ orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;}
+ inline int getTeam() const
+ { return this->team_; }
+
+ /**
+ @brief Mode of the formation, behaviour of slaves
+ Normal-normal behaviour
+ Defend-just defend the master
+ Attack-leave formation, attack every target
+ */
+ enum FormationMode {NORMAL,DEFEND,ATTACK};
+
+ /**
+ @brief Sets the new mode. If master, set it for all slaves.
+ */
+ void setFormationMode(FormationMode val);
+ inline FormationMode getFormationMode() const
+ { return this->formationMode_; }
+
+ protected:
+ bool formationFlight_;
+ bool passive_;
+ int team_;
+ unsigned int maxFormationSize_;
+ int freedomCount_;
+ enum State {SLAVE, MASTER, FREE};
+
+ State state_;
+ std::vector<FormationController*> slaves_;
+ FormationController* myMaster_;
+
+ FormationMode formationMode_;
+
+ enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
+ SpecificMasterAction specificMasterAction_;
+ int specificMasterActionHoldCount_;
+ float speedCounter_; //for speed adjustment when following
+
+ void moveToPosition(const Vector3& target);
+ void moveToTargetPosition();
+ void absoluteMoveToPosition(const Vector3& target);
+ void copyOrientation(const Quaternion& orient);
+ void copyTargetOrientation();
+
+ void removeFromFormation();
+ void unregisterSlave();
+ void searchNewMaster();
+ void commandSlaves();
+ void setNewMasterWithinFormation();
+
+ void freeSlaves();
+ void forceFreeSlaves();
+ void loseMasterState();
+ void forceFreedom();
+ bool forcedFree();
+
+ void takeLeadOfFormation();
+ void masterAttacked(Pawn* originator);
+
+ void specificMasterActionHold();
+ void turn180Init();
+ void spinInit();
+ void spin();
+ void turn180();
+ void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
+ void followRandomHumanInit();
+ void follow();
+
+ void setTargetPosition(const Vector3& target);
+ void searchRandomTargetPosition();
+
+ void setTargetOrientation(const Quaternion& orient);
+ void setTargetOrientation(Pawn* target);
+
+ virtual void positionReached() {}
+
+ static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
+
+
+ void setTarget(Pawn* target);
+ void searchNewTarget();
+ void forgetTarget();
+
+ void targetDied();
+
+ bool bHasTargetPosition_;
+ Vector3 targetPosition_;
+ bool bHasTargetOrientation_;
+ Quaternion targetOrientation_;
+
+ WeakPtr<Pawn> target_;
+ bool bShooting_;
+ };
+
+
+}
+#endif /* _FormationController_h__ */
+
+
Modified: code/branches/presentation2011/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/HumanController.cc 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/HumanController.cc 2011-12-16 19:36:41 UTC (rev 8992)
@@ -49,6 +49,8 @@
SetConsoleCommand("HumanController", "rotateYaw", &HumanController::rotateYaw ).addShortcut().setAsInputCommand();
SetConsoleCommand("HumanController", "rotatePitch", &HumanController::rotatePitch ).addShortcut().setAsInputCommand();
SetConsoleCommand("HumanController", "rotateRoll", &HumanController::rotateRoll ).addShortcut().setAsInputCommand();
+ SetConsoleCommand("HumanController", "toggleFormationFlight", &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress);
+ SetConsoleCommand("HumanController", "FFChangeMode", &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress);
SetConsoleCommand("HumanController", __CC_fire_name, &HumanController::fire ).addShortcut().keybindMode(KeybindMode::OnHold);
SetConsoleCommand("HumanController", "reload", &HumanController::reload ).addShortcut();
SetConsoleCommand("HumanController", __CC_boost_name, &HumanController::keepBoost ).addShortcut().keybindMode(KeybindMode::OnHold);
@@ -68,21 +70,26 @@
HumanController* HumanController::localController_s = 0;
/*static*/ const float HumanController::BOOSTING_TIME = 0.1f;
- HumanController::HumanController(BaseObject* creator) : Controller(creator)
+ HumanController::HumanController(BaseObject* creator) : FormationController(creator)
{
RegisterObject(HumanController);
this->controlPaused_ = false;
this->boosting_ = false;
this->boosting_ = false;
-
+ this->tempMaster=NULL;
HumanController::localController_s = this;
this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this)));
this->boostingTimeout_.stopTimer();
+ this->state_=FREE;
}
HumanController::~HumanController()
{
+ if (HumanController::localController_s)
+ {
+ HumanController::localController_s->removeFromFormation();
+ }
HumanController::localController_s = 0;
}
@@ -94,6 +101,13 @@
if (!camera)
orxout(internal_warning) << "HumanController, Warning: Using a ControllableEntity without Camera" << endl;
}
+
+ // commandslaves when Master of a formation
+ if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
+ {
+ if (HumanController::localController_s->formationMode_ != ATTACK)
+ HumanController::localController_s->commandSlaves();
+ }
}
void HumanController::moveFrontBack(const Vector2& value)
@@ -159,7 +173,14 @@
void HumanController::doFire(unsigned int firemode)
{
if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
+ {
HumanController::localController_s->controllableEntity_->fire(firemode);
+ //if human fires, set slaves free. See FormationController::forceFreeSlaves()
+ if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->formationMode_ == NORMAL)
+ {
+ HumanController::localController_s->forceFreeSlaves();
+ }
+ }
}
void HumanController::reload()
@@ -261,6 +282,65 @@
}
}
+ /**
+ @brief
+ toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_)
+ */
+ void HumanController::toggleFormationFlight()
+ {
+ if (HumanController::localController_s)
+ {
+ if (!HumanController::localController_s->formationFlight_)
+ {
+ return; //dont use when formationFlight is disabled
+ }
+ if (HumanController::localController_s->state_==MASTER)
+ {
+ HumanController::localController_s->loseMasterState();
+ orxout(message) <<"FormationFlight disabled "<< endl;
+ } else //SLAVE or FREE
+ {
+ HumanController::localController_s->takeLeadOfFormation();
+ orxout(message) <<"FormationFlight enabled "<< endl;
+ }
+
+ }
+
+ }
+
+ /**
+ @brief
+ Switch through the different Modes of formationflight. You must be a master of a formation to use.
+ */
+ void HumanController::FFChangeMode()
+ {
+ if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
+ {
+ switch (HumanController::localController_s->getFormationMode()) {
+ case NORMAL:
+ HumanController::localController_s->setFormationMode(DEFEND);
+ orxout(message) <<"Mode: DEFEND "<< endl;
+ break;
+ case DEFEND:
+ HumanController::localController_s->setFormationMode(ATTACK);
+ orxout(message) <<"Mode: ATTACK "<< endl;
+ break;
+ case ATTACK:
+ HumanController::localController_s->setFormationMode(NORMAL);
+ orxout(message) <<"Mode: NORMAL "<< endl;
+ break;
+ }
+ }
+ }
+
+
+ //used, when slaves are in DEFEND mode.
+ void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
+ {
+ if (!this->formationFlight_ || this->state_!=MASTER || this->formationMode_!=DEFEND) return;
+ this->masterAttacked(originator);
+ }
+
void HumanController::addBots(unsigned int amount)
{
if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
Modified: code/branches/presentation2011/src/orxonox/controllers/HumanController.h
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/HumanController.h 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/HumanController.h 2011-12-16 19:36:41 UTC (rev 8992)
@@ -33,14 +33,14 @@
#include "tools/Timer.h"
#include "tools/interfaces/Tickable.h"
-#include "Controller.h"
+#include "FormationController.h"
// tolua_begin
namespace orxonox
{
class _OrxonoxExport HumanController
// tolua_end
- : public Controller, public Tickable
+ : public FormationController, public Tickable
{ // tolua_export
public:
HumanController(BaseObject* creator);
@@ -73,7 +73,8 @@
{ return this->boosting_; }
void keepBoosting(void);
void terminateBoosting(void);
-
+
+
static void greet();
static void switchCamera();
static void mouseLook();
@@ -84,6 +85,11 @@
static void toggleGodMode();
static void myposition();
+ static void toggleFormationFlight();
+ static void FFChangeMode();
+ virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
+
+
static void addBots(unsigned int amount);
static void killBots(unsigned int amount = 0);
@@ -106,6 +112,7 @@
bool boosting_; // Whether the HumanController is in boosting mode or not.
Timer boostingTimeout_; // A timer to check whether the player is no longer boosting.
static const float BOOSTING_TIME; // The time after it is checked, whether the player is no longer boosting.
+ FormationController* tempMaster;
}; // tolua_export
} // tolua_export
Modified: code/branches/presentation2011/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/presentation2011/src/orxonox/controllers/NewHumanController.cc 2011-12-16 15:56:15 UTC (rev 8991)
+++ code/branches/presentation2011/src/orxonox/controllers/NewHumanController.cc 2011-12-16 19:36:41 UTC (rev 8992)
@@ -276,7 +276,7 @@
HumanController::tick(dt);
}
- void NewHumanController::doFire(unsigned int firemode)
+ void NewHumanController::doFire(unsigned int firemode)//TODO??
{
if (!this->controllableEntity_)
return;
@@ -296,6 +296,9 @@
void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
{
+ //Used in HumanController for formationFlight
+ HumanController::hit(originator,contactpoint,damage);
+
if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
{
Vector3 posA;
More information about the Orxonox-commit
mailing list