Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9667 was 9667, checked in by landauf, 11 years ago

merged core6 back to 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/class/Super.h"
36
37#include "util/Math.h"
38#include "controllers/Controller.h"
39#include "worldentities/ControllableEntity.h"
40
41
42namespace orxonox {
43
44  class _OrxonoxExport FormationController : public Controller
45  {
46
47      public:
48      FormationController(Context* context);
49
50      virtual ~FormationController();
51
52      virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
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      inline void setTeam(int team)
79           { this->team_ = team; }
80      inline int getTeam() const
81           { return this->team_; }
82
83      /**
84        @brief Mode of the formation, behaviour of slaves
85               Normal-normal behaviour
86               Defend-just defend the master
87               Attack-leave formation, attack every target
88      */
89      enum FormationMode {NORMAL,DEFEND,ATTACK};
90
91      /**
92        @brief Sets the new mode. If master, set it for all slaves.
93      */
94      void setFormationMode(FormationMode val);
95      inline FormationMode getFormationMode() const
96           { return this->formationMode_; }
97
98      virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
99
100      FormationController* getMaster( void ) { return myMaster_; }
101      FormationController* getController( void ) { return this; }
102      FormationController* getSlave( void ) { return this->slaves_.back(); }
103
104  protected:
105      bool formationFlight_;
106      bool passive_;
107      int team_;
108      unsigned int maxFormationSize_;
109      int freedomCount_;
110      enum State {SLAVE, MASTER, FREE};
111
112      State state_;
113      std::vector<FormationController*> slaves_;
114      FormationController* myMaster_;
115
116      FormationMode formationMode_;
117
118      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
119      SpecificMasterAction specificMasterAction_;
120      int specificMasterActionHoldCount_;
121      float speedCounter_; //for speed adjustment when following
122
123      void moveToPosition(const Vector3& target);
124      void moveToTargetPosition();
125      void absoluteMoveToPosition(const Vector3& target);
126      void copyOrientation(const Quaternion& orient);
127      void copyTargetOrientation();
128
129      void removeFromFormation();
130      void unregisterSlave();
131      void searchNewMaster();
132      void commandSlaves();
133      void takeLeadOfFormation();
134      void loseMasterState();
135      void setNewMasterWithinFormation();
136
137      void freeSlaves();
138      void forceFreeSlaves();
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.