Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

The AIController of the new HumanController is deleted.

  • 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      void loseMasterState();
63
64      inline void setFormationFlight(bool formation)
65           { this->formationFlight_ = formation; }
66      inline bool getFormationFlight() const
67           { return this->formationFlight_; }
68
69      inline void setFormationSize(int size)
70           { this->maxFormationSize_ = size; }
71      inline int getFormationSize() const
72           { return this->maxFormationSize_; }
73
74
75      inline void setPassive(bool passive)
76           { this->passive_ = passive; }
77      inline bool getPassive() const
78           { return this->passive_; }
79
80      inline void setTeam(int team)
81           { this->team_ = team; }
82      inline int getTeam() const
83           { return this->team_; }
84
85      /**
86        @brief Mode of the formation, behaviour of slaves
87               Normal-normal behaviour
88               Defend-just defend the master
89               Attack-leave formation, attack every target
90      */
91      enum FormationMode {NORMAL,DEFEND,ATTACK};
92
93      /**
94        @brief Sets the new mode. If master, set it for all slaves.
95      */
96      void setFormationMode(FormationMode val);
97      inline FormationMode getFormationMode() const
98           { return this->formationMode_; }
99
100      virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
101
102      /* Just for testing purposes: report the master. */
103      FormationController* getMaster( void ) { return myMaster_; }
104      FormationController* getThis( void ) { return this; }
105
106  protected:
107      bool formationFlight_;
108      bool passive_;
109      int team_;
110      unsigned int maxFormationSize_;
111      int freedomCount_;
112      enum State {SLAVE, MASTER, FREE};
113
114      State state_;
115      std::vector<FormationController*> slaves_;
116      FormationController* myMaster_;
117
118      FormationMode formationMode_;
119
120      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
121      SpecificMasterAction specificMasterAction_;
122      int specificMasterActionHoldCount_;
123      float speedCounter_; //for speed adjustment when following
124
125      void moveToPosition(const Vector3& target);
126      void moveToTargetPosition();
127      void absoluteMoveToPosition(const Vector3& target);
128      void copyOrientation(const Quaternion& orient);
129      void copyTargetOrientation();
130
131      void removeFromFormation();
132      void unregisterSlave();
133      void searchNewMaster();
134      void commandSlaves();
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.