Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/src/orxonox/controllers/FormationController.h @ 9629

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

BaseObject now requires a Context instead of a creator (BaseObject*) in its constructor.
Namespace, Level, and Scene inherit from Context

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