Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/formationupdate/src/orxonox/controllers/FormationController.h @ 9616

Last change on this file since 9616 was 9616, checked in by maxima, 11 years ago

A few changes of the death function. Tried to change the master of the formation.

  • Property svn:eol-style set to native
File size: 5.2 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 takeLeadOfFormation();
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      /* Just for testing purposes: report the master. */
102      FormationController* getMaster( void ) { return myMaster_; }
103      FormationController* getThis( void ) { return this; }
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 setNewMasterWithinFormation();
135
136      void freeSlaves();
137      void forceFreeSlaves();
138      void loseMasterState();
139      void forceFreedom();
140      bool forcedFree();
141
142      void masterAttacked(Pawn* originator);
143
144      void specificMasterActionHold();
145      void turn180Init();
146      void spinInit();
147      void spin();
148      void turn180();
149      void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
150      void followRandomHumanInit();
151      void follow();
152
153      void setTargetPosition(const Vector3& target);
154      void searchRandomTargetPosition();
155
156      void setTargetOrientation(const Quaternion& orient);
157      void setTargetOrientation(Pawn* target);
158
159      virtual void positionReached() {}
160
161      static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
162
163
164      void setTarget(Pawn* target);
165
166      void searchNewTarget();
167      void forgetTarget();
168
169      void targetDied();
170
171      bool bHasTargetPosition_;
172      Vector3 targetPosition_;
173      bool bHasTargetOrientation_;
174      Quaternion targetOrientation_;
175
176      WeakPtr<Pawn> target_;
177      bool bShooting_;
178  };
179
180
181}
182#endif /* _FormationController_h__ */
183
184
Note: See TracBrowser for help on using the repository browser.