Orxonox  0.0.5 Codename: Arcturus
FormationController.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * ...
24  * Co-authors:
25  * ...
26  *
27  */
28 
29 #ifndef _FormationController_h__
30 #define _FormationController_h__
31 
32 #include "OrxonoxPrereqs.h"
33 
34 #include <vector>
35 #include "core/class/Super.h"
36 
37 #include "util/Math.h"
38 #include "controllers/Controller.h"
40 
41 
42 namespace orxonox {
43 
45  {
46 
47  public:
48  FormationController(Context* context);
49 
50  virtual ~FormationController();
51 
52  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
53 
54 
55  static void formationflight(const bool form);
56  static void masteraction(const int action);
57  static void followme();
58  static void passivebehaviour(const bool passive);
59  static void formationsize(const int size);
60  void setNewMasterWithinFormation(FormationController* newMaster);
61 
62  inline void setFormationFlight(bool formation)
63  { this->formationFlight_ = formation; }
64  inline bool getFormationFlight() const
65  { return this->formationFlight_; }
66 
67  inline void setFormationSize(int size)
68  { this->maxFormationSize_ = size; }
69  inline int getFormationSize() const
70  { return this->maxFormationSize_; }
71 
72 
73  inline void setPassive(bool passive)
74  { this->passive_ = passive; }
75  inline bool getPassive() const
76  { return this->passive_; }
77 
78 
79 
86  enum FormationMode {NORMAL,DEFEND,ATTACK};
87 
91  void setFormationMode(FormationMode val);
93  { return this->formationMode_; }
94 
95  virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) override;
96 
97  FormationController* getMaster( void ) { return myMaster_; }
98  FormationController* getController( void ) { return this; }
99  FormationController* getSlave( void ) { return this->slaves_.back(); }
100 
101  virtual void changedControllableEntity() override;
102 
103  protected:
105  bool passive_;
106  unsigned int maxFormationSize_;
108  enum State {SLAVE, MASTER, FREE};
109 
111  std::vector<FormationController*> slaves_;
113 
115 
116  enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
119  float speedCounter_; //for speed adjustment when following
120 
121  void moveToPosition(const Vector3& target);
122  void moveToTargetPosition();
123  void absoluteMoveToPosition(const Vector3& target);
124  void copyOrientation(const Quaternion& orient);
125  void copyTargetOrientation();
126 
127  void removeFromFormation();
128  void unregisterSlave();
129  void searchNewMaster();
130  void commandSlaves();
131  void takeLeadOfFormation();
132  void loseMasterState();
133  void setNewMasterWithinFormation();
134 
135  void freeSlaves();
136  void forceFreeSlaves();
137  void forceFreedom();
138  bool forcedFree();
139 
140  void masterAttacked(Pawn* originator);
141 
142  void specificMasterActionHold();
143  void turn180Init();
144  void spinInit();
145  void spin();
146  void turn180();
147  void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
148  void followRandomHumanInit();
149  void follow();
150 
151  void setTargetPosition(const Vector3& target);
152  void searchRandomTargetPosition();
153 
154  void setTargetOrientation(const Quaternion& orient);
155  void setTargetOrientation(Pawn* target);
156 
157  virtual void positionReached() {}
158 
159  static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
160 
161 
162  void setTarget(Pawn* target);
163 
164  void searchNewTarget();
165  void forgetTarget();
166 
167  void targetDied();
168 
172  Quaternion targetOrientation_;
173 
176  };
177 
178 
179 }
180 #endif /* _FormationController_h__ */
181 
182 
Everything in Orxonox that has a health attribute is a Pawn.
Definition: Pawn.h:56
State state_
Definition: FormationController.h:110
int freedomCount_
Definition: FormationController.h:107
State
Definition: FormationController.h:108
bool formationFlight_
Definition: FormationController.h:104
int getFormationSize() const
Definition: FormationController.h:69
bool bHasTargetOrientation_
Definition: FormationController.h:171
bool bHasTargetPosition_
Definition: FormationController.h:169
FormationController * getSlave(void)
Definition: FormationController.h:99
WeakPtr wraps a pointer to an object, which becomes nullptr if the object is deleted.
Definition: CorePrereqs.h:236
FormationController * getController(void)
Definition: FormationController.h:98
int specificMasterActionHoldCount_
Definition: FormationController.h:118
bool getFormationFlight() const
Definition: FormationController.h:64
bool passive_
Definition: FormationController.h:105
xmlelement
Definition: Super.h:519
Definition: FormationController.h:116
FormationController * myMaster_
Definition: FormationController.h:112
FormationMode getFormationMode() const
Definition: FormationController.h:92
Definition: FormationController.h:44
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
void setFormationFlight(bool formation)
Definition: FormationController.h:62
FormationController * getMaster(void)
Definition: FormationController.h:97
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Mode
Definition: CorePrereqs.h:102
Vector3 targetPosition_
Definition: FormationController.h:170
Definition: Gametype.h:63
Shared library macros, enums, constants and forward declarations for the orxonox library ...
FormationMode
Mode of the formation, behaviour of slaves Normal-normal behaviour Defend-just defend the master Atta...
Definition: FormationController.h:86
void setFormationSize(int size)
Definition: FormationController.h:67
Definition: Context.h:45
void setPassive(bool passive)
Definition: FormationController.h:73
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
FormationMode formationMode_
Definition: FormationController.h:114
Definition: Controller.h:38
bool getPassive() const
Definition: FormationController.h:75
float speedCounter_
Definition: FormationController.h:119
WeakPtr< Pawn > target_
Definition: FormationController.h:174
Quaternion targetOrientation_
Definition: FormationController.h:172
Definition: FormationController.h:86
unsigned int maxFormationSize_
Definition: FormationController.h:106
virtual void positionReached()
Definition: FormationController.h:157
SpecificMasterAction
Definition: FormationController.h:116
Definition of all super-function related macros, used to call functions of the base class...
SpecificMasterAction specificMasterAction_
Definition: FormationController.h:117
The ControllableEntity is derived from the orxonox::MobileEntity.
Definition: ControllableEntity.h:48
bool bShooting_
Definition: FormationController.h:175
std::vector< FormationController * > slaves_
Definition: FormationController.h:111