[Orxonox-commit 4282] r8953 - in code/branches/formation: data/defaultConfig src/orxonox/controllers
willis at orxonox.net
willis at orxonox.net
Wed Nov 30 16:09:25 CET 2011
Author: willis
Date: 2011-11-30 16:09:25 +0100 (Wed, 30 Nov 2011)
New Revision: 8953
Modified:
code/branches/formation/data/defaultConfig/keybindings.ini
code/branches/formation/src/orxonox/controllers/AIController.cc
code/branches/formation/src/orxonox/controllers/ArtificialController.cc
code/branches/formation/src/orxonox/controllers/ArtificialController.h
code/branches/formation/src/orxonox/controllers/HumanController.cc
code/branches/formation/src/orxonox/controllers/HumanController.h
code/branches/formation/src/orxonox/controllers/Masterable.cc
code/branches/formation/src/orxonox/controllers/Masterable.h
Log:
added different Modes, debugging
Modified: code/branches/formation/data/defaultConfig/keybindings.ini
===================================================================
--- code/branches/formation/data/defaultConfig/keybindings.ini 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/data/defaultConfig/keybindings.ini 2011-11-30 15:09:25 UTC (rev 8953)
@@ -71,7 +71,7 @@
KeyNumLock=
KeyNumRow0=
KeyNumRow1="toggleFormationFlight"
-KeyNumRow2=
+KeyNumRow2="FFChangeMode"
KeyNumRow3=
KeyNumRow4=
KeyNumRow5=
Modified: code/branches/formation/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/AIController.cc 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/src/orxonox/controllers/AIController.cc 2011-11-30 15:09:25 UTC (rev 8953)
@@ -115,9 +115,23 @@
}
- if (this->state_ == SLAVE)
+ if (this->state_ == SLAVE && this->mode_==ATTACK)
{
+ if (!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)
@@ -141,11 +155,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 )
@@ -232,7 +246,7 @@
this->follow();
}
- if (this->state_ == SLAVE)
+ if (this->state_ == SLAVE && this->mode_!=ATTACK)
{
if (this->bHasTargetPosition_)
@@ -240,7 +254,7 @@
}
- if (this->state_ == FREE)
+ if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) )
{
if (this->target_)
{
Modified: code/branches/formation/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/ArtificialController.cc 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/src/orxonox/controllers/ArtificialController.cc 2011-11-30 15:09:25 UTC (rev 8953)
@@ -27,19 +27,8 @@
*/
#include "ArtificialController.h"
-
-#include <vector>
-
-
-#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 "gametypes/TeamDeathmatch.h"
-#include "gametypes/Dynamicmatch.h"
namespace orxonox
Modified: code/branches/formation/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/ArtificialController.h 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/src/orxonox/controllers/ArtificialController.h 2011-11-30 15:09:25 UTC (rev 8953)
@@ -30,12 +30,6 @@
#define _ArtificialController_H__
#include "OrxonoxPrereqs.h"
-
-#include <vector>
-
-#include "util/Math.h"
-#include "Controller.h"
-#include "controllers/NewHumanController.h"
#include "controllers/Masterable.h"
namespace orxonox
Modified: code/branches/formation/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/HumanController.cc 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/src/orxonox/controllers/HumanController.cc 2011-11-30 15:09:25 UTC (rev 8953)
@@ -50,6 +50,7 @@
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);
@@ -104,7 +105,8 @@
// commandslaves when Master of a formation
if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
{
- HumanController::localController_s->commandSlaves();
+ if (HumanController::localController_s->mode_!=ATTACK)
+ HumanController::localController_s->commandSlaves();
}
}
@@ -273,15 +275,21 @@
}
}
+ /**
+ @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->freeSlaves();
- HumanController::localController_s->state_=FREE;
+ HumanController::localController_s->loseMasterState();
orxout(message) <<"FormationFlight disabled "<< endl;
} else //SLAVE or FREE
{
@@ -293,6 +301,37 @@
}
+ /**
+ @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->getMode()) {
+ case NORMAL:
+ HumanController::localController_s->setMode(DEFEND);
+ orxout(message) <<"Mode: DEFEND "<< endl;
+ break;
+ case DEFEND:
+ HumanController::localController_s->setMode(ATTACK);
+ orxout(message) <<"Mode: ATTACK "<< endl;
+ break;
+ case ATTACK:
+ HumanController::localController_s->setMode(NORMAL);
+ orxout(message) <<"Mode: NORMAL "<< endl;
+ break;
+ }
+ changedMode();
+ }
+ }
+
+ void HumanController::changedMode()
+ {
+
+ }
+
void HumanController::addBots(unsigned int amount)
{
if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
Modified: code/branches/formation/src/orxonox/controllers/HumanController.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/HumanController.h 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/src/orxonox/controllers/HumanController.h 2011-11-30 15:09:25 UTC (rev 8953)
@@ -73,7 +73,8 @@
{ return this->boosting_; }
void keepBoosting(void);
void terminateBoosting(void);
-
+
+
static void greet();
static void switchCamera();
static void mouseLook();
@@ -85,6 +86,8 @@
static void myposition();
static void toggleFormationFlight();
+ static void FFChangeMode();
+ static void changedMode();
static void addBots(unsigned int amount);
static void killBots(unsigned int amount = 0);
Modified: code/branches/formation/src/orxonox/controllers/Masterable.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/Masterable.cc 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/src/orxonox/controllers/Masterable.cc 2011-11-30 15:09:25 UTC (rev 8953)
@@ -56,8 +56,8 @@
- static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
- static const int RADIUS_TO_SEARCH_FOR_MASTERS = 20000;
+ 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
@@ -78,6 +78,7 @@
this->freedomCount_ = 0;
this->state_ = FREE;
+ this->mode_ = NORMAL;
this->specificMasterAction_ = NONE;
this->specificMasterActionHoldCount_ = 0;
this->bShooting_ = false;
@@ -443,8 +444,9 @@
{
this->state_ = MASTER;
this->myMaster_ = 0;
- orxout(debug_output) << "search new master: no master found, but teammates"<< endl;
- }
+ orxout(debug_output) << "search new master: no master found, but "<<teamSize<<" teammates"<< endl;
+ } else if (this->state_ != SLAVE)
+ orxout(debug_output) << "search new master: no master found, no teammates..."<< endl;
}
/**
@brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
@@ -588,62 +590,6 @@
//search new Master, then take lead
if (this->state_==FREE)
{
- /*
- float minDistance=(float)RADIUS_TO_SEARCH_FOR_MASTERS;
- Masterable* bestMaster=NULL;
-
- //search nearest Master, store in bestMaster
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
-
- //same team? (doesnt work with a HumanPlayer??!?) TODO
- if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
- continue;
-
- //get Controller
- Controller* controller = 0;
-
- if (it->getController())
- controller = it->getController();
- else if (it->getXMLController())
- controller = it->getXMLController();
-
- if (!controller)
- continue;
-
- //myself?
- if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())
- continue;
-
- Masterable *newMaster = orxonox_cast<Masterable*>(controller);
- if (!newMaster || newMaster->state_!=MASTER) continue;
-
- float distance= (it->getPosition() - this->getControllableEntity()->getPosition()).length();
-
- if (distance<minDistance)
- {
- minDistance=distance;
- bestMaster=newMaster;
- }
- }
-
- if (bestMaster!=NULL)
- {
- //becom slave of formation
- bestMaster->slaves_.push_back(this);
- this->state_=SLAVE;
- this->myMaster_=bestMaster;
- }
- else
- {
- //no formation found to lead, become master of empty formation
- this->state_=MASTER;
- this->slaves_.clear();
- this->myMaster_=0;
- orxout(debug_output) << this << "no formation found!, empty formation"<< endl;
- return;
- }
- */
searchNewMaster();
}
@@ -680,6 +626,23 @@
/**
+ @brief Sets the new mode. If master, set it for all slaves.
+ */
+ void Masterable::setMode(Mode val)
+ {
+ this->mode_=val;
+ if (this->state_==MASTER)
+ {
+ for(std::vector<Masterable*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
+ {
+ (*it)->mode_=val;
+ if (val==ATTACK)
+ (*it)->forgetTarget();
+ }
+ }
+ }
+
+ /**
@brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
*/
void Masterable::specificMasterActionHold()
@@ -934,24 +897,6 @@
this->searchRandomTargetPosition();
}
-
-
-
-
- void Masterable::setMode(Mode mode)
- {
- for (std::vector<Masterable*>::iterator it=slaves_.begin(); it != slaves_.end(); it++)
- {
- //(*it)->myMode_=mode;
- }
- }
-
- Masterable::Mode Masterable::getMode()
- {
- return Masterable::NORMAL;
- }
-
-
bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
{
if (entity1 == entity2)
@@ -991,6 +936,7 @@
if (entity2->getPlayer())
team2 = tdm->getTeam(entity2->getPlayer());
+ return (team1 == team2 && team1 != -1); //temp solution
}
TeamBaseMatchBase* base = 0;
Modified: code/branches/formation/src/orxonox/controllers/Masterable.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/Masterable.h 2011-11-26 17:22:13 UTC (rev 8952)
+++ code/branches/formation/src/orxonox/controllers/Masterable.h 2011-11-30 15:09:25 UTC (rev 8953)
@@ -87,15 +87,14 @@
Attack-leave formation, attack every target
*/
enum Mode {NORMAL,DEFEND,ATTACK};
+
/**
- @brief set a mode in formation
- */
- void setMode(Mode mode);
- /**
- @brief get the current mode
+ @brief Sets the new mode. If master, set it for all slaves.
*/
- Mode getMode();
-
+ void setMode(Mode val);
+ inline Mode getMode() const
+ { return this->mode_; }
+
protected:
bool formationFlight_;
bool passive_;
@@ -103,10 +102,13 @@
unsigned int maxFormationSize_;
int freedomCount_;
enum State {SLAVE, MASTER, FREE};
+
State state_;
std::vector<Masterable*> slaves_;
Masterable* myMaster_;
+ Mode mode_;
+
enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
SpecificMasterAction specificMasterAction_;
int specificMasterActionHoldCount_;
More information about the Orxonox-commit
mailing list