Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/controllers/FormationController.h @ 9656

Last change on this file since 9656 was 9625, checked in by smerkli, 12 years ago

Merged Maxim's Branch back into trunk.

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
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/Super.h"
36
37#include "util/Math.h"
38#include "core/OrxonoxClass.h"
39#include "controllers/Controller.h"
40#include "worldentities/ControllableEntity.h"
41
42
43namespace orxonox {
44
45  class _OrxonoxExport FormationController : public Controller
46  {
47
48      public:
49      FormationController(BaseObject* creator);
50
51      virtual ~FormationController();
52
53      virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
54
55
56      static void formationflight(const bool form);
57      static void masteraction(const int action);
58      static void followme();
59      static void passivebehaviour(const bool passive);
60      static void formationsize(const int size);
61      void setNewMasterWithinFormation(FormationController* newMaster);
62
63      inline void setFormationFlight(bool formation)
64           { this->formationFlight_ = formation; }
65      inline bool getFormationFlight() const
66           { return this->formationFlight_; }
67
68      inline void setFormationSize(int size)
69           { this->maxFormationSize_ = size; }
70      inline int getFormationSize() const
71           { return this->maxFormationSize_; }
72
73
74      inline void setPassive(bool passive)
75           { this->passive_ = passive; }
76      inline bool getPassive() const
77           { return this->passive_; }
78
79      inline void setTeam(int team)
80           { this->team_ = team; }
81      inline int getTeam() const
82           { return this->team_; }
83
84      /**
85        @brief Mode of the formation, behaviour of slaves
86               Normal-normal behaviour
87               Defend-just defend the master
88               Attack-leave formation, attack every target
89      */
90      enum FormationMode {NORMAL,DEFEND,ATTACK};
91
92      /**
93        @brief Sets the new mode. If master, set it for all slaves.
94      */
95      void setFormationMode(FormationMode val);
96      inline FormationMode getFormationMode() const
97           { return this->formationMode_; }
98
99      virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
100
101      FormationController* getMaster( void ) { return myMaster_; }
102      FormationController* getController( void ) { return this; }
103      FormationController* getSlave( void ) { return this->slaves_.back(); }
104
105  protected:
106      bool formationFlight_;
107      bool passive_;
108      int team_;
109      unsigned int maxFormationSize_;
110      int freedomCount_;
111      enum State {SLAVE, MASTER, FREE};
112
113      State state_;
114      std::vector<FormationController*> slaves_;
115      FormationController* myMaster_;
116
117      FormationMode formationMode_;
118
119      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
120      SpecificMasterAction specificMasterAction_;
121      int specificMasterActionHoldCount_;
122      float speedCounter_; //for speed adjustment when following
123
124      void moveToPosition(const Vector3& target);
125      void moveToTargetPosition();
126      void absoluteMoveToPosition(const Vector3& target);
127      void copyOrientation(const Quaternion& orient);
128      void copyTargetOrientation();
129
130      void removeFromFormation();
131      void unregisterSlave();
132      void searchNewMaster();
133      void commandSlaves();
134      void takeLeadOfFormation();
135      void loseMasterState();
136      void setNewMasterWithinFormation();
137
138      void freeSlaves();
139      void forceFreeSlaves();
140      void forceFreedom();
141      bool forcedFree();
142
143      void masterAttacked(Pawn* originator);
144
145      void specificMasterActionHold();
146      void turn180Init();
147      void spinInit();
148      void spin();
149      void turn180();
150      void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
151      void followRandomHumanInit();
152      void follow();
153
154      void setTargetPosition(const Vector3& target);
155      void searchRandomTargetPosition();
156
157      void setTargetOrientation(const Quaternion& orient);
158      void setTargetOrientation(Pawn* target);
159
160      virtual void positionReached() {}
161
162      static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
163
164
165      void setTarget(Pawn* target);
166
167      void searchNewTarget();
168      void forgetTarget();
169
170      void targetDied();
171
172      bool bHasTargetPosition_;
173      Vector3 targetPosition_;
174      bool bHasTargetOrientation_;
175      Quaternion targetOrientation_;
176
177      WeakPtr<Pawn> target_;
178      bool bShooting_;
179  };
180
181
182}
183#endif /* _FormationController_h__ */
184
185
Note: See TracBrowser for help on using the repository browser.