Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

New function SetNewMasterWithinFormation(FormationController), but it does not work yet.

  • Property svn:eol-style set to native
File size: 5.4 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();
62      //void setNewMasterWithinFormation(FormationController* newMaster);
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      FormationController* getSlave( void ) { return this->slaves_.back(); }
106
107  protected:
108      bool formationFlight_;
109      bool passive_;
110      int team_;
111      unsigned int maxFormationSize_;
112      int freedomCount_;
113      enum State {SLAVE, MASTER, FREE};
114
115      State state_;
116      std::vector<FormationController*> slaves_;
117      FormationController* myMaster_;
118
119      FormationMode formationMode_;
120
121      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
122      SpecificMasterAction specificMasterAction_;
123      int specificMasterActionHoldCount_;
124      float speedCounter_; //for speed adjustment when following
125
126      void moveToPosition(const Vector3& target);
127      void moveToTargetPosition();
128      void absoluteMoveToPosition(const Vector3& target);
129      void copyOrientation(const Quaternion& orient);
130      void copyTargetOrientation();
131
132      void removeFromFormation();
133      void unregisterSlave();
134      void searchNewMaster();
135      void commandSlaves();
136      void takeLeadOfFormation();
137      void loseMasterState();
138
139      void freeSlaves();
140      void forceFreeSlaves();
141      void forceFreedom();
142      bool forcedFree();
143
144      void masterAttacked(Pawn* originator);
145
146      void specificMasterActionHold();
147      void turn180Init();
148      void spinInit();
149      void spin();
150      void turn180();
151      void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
152      void followRandomHumanInit();
153      void follow();
154
155      void setTargetPosition(const Vector3& target);
156      void searchRandomTargetPosition();
157
158      void setTargetOrientation(const Quaternion& orient);
159      void setTargetOrientation(Pawn* target);
160
161      virtual void positionReached() {}
162
163      static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
164
165
166      void setTarget(Pawn* target);
167
168      void searchNewTarget();
169      void forgetTarget();
170
171      void targetDied();
172
173      bool bHasTargetPosition_;
174      Vector3 targetPosition_;
175      bool bHasTargetOrientation_;
176      Quaternion targetOrientation_;
177
178      WeakPtr<Pawn> target_;
179      bool bShooting_;
180  };
181
182
183}
184#endif /* _FormationController_h__ */
185
186
Note: See TracBrowser for help on using the repository browser.