Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/formation/src/orxonox/controllers/Masterable.h @ 8939

Last change on this file since 8939 was 8939, checked in by willis, 13 years ago

moved formationflight to Masterable.* from Artificialcontroller, added formationflight to HumanPlayer

File size: 4.7 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Masterable_h__
30#define _Masterable_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 Masterable : public Controller
46  {
47
48      public:
49      Masterable(BaseObject* creator);
50
51      virtual ~Masterable();
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
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 Mode {NORMAL,DEFEND,ATTACK};
90      /**
91        @brief set a mode in formation
92      */ 
93      void setMode(Mode mode);
94       /**
95        @brief get the current mode
96      */
97      Mode getMode();
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      State state_;
107      std::vector<Masterable*> slaves_;
108      Masterable* myMaster_;
109
110      enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
111      SpecificMasterAction specificMasterAction_;
112      int specificMasterActionHoldCount_;
113      float speedCounter_; //for speed adjustment when following
114
115      void moveToPosition(const Vector3& target);
116      void moveToTargetPosition();
117      void copyOrientation(const Quaternion& orient);
118      void copyTargetOrientation();
119
120      void removeFromFormation();
121      void unregisterSlave();
122      void searchNewMaster();
123      void commandSlaves();
124      void setNewMasterWithinFormation();
125
126      void freeSlaves();
127      void forceFreeSlaves();
128      void loseMasterState();
129      void forceFreedom();
130      bool forcedFree();
131
132      void takeLeadOfFormation();
133
134      void specificMasterActionHold();
135      void turn180Init();
136      void spinInit();
137      void spin();
138      void turn180();
139      void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
140      void followRandomHumanInit();
141      void follow();
142
143      void setTargetPosition(const Vector3& target);
144      void searchRandomTargetPosition();
145
146      void setTargetOrientation(const Quaternion& orient);
147      void setTargetOrientation(Pawn* target);
148
149      virtual void positionReached() {}
150
151      static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
152     
153
154      void setTarget(Pawn* target);
155      void searchNewTarget();
156      void forgetTarget();
157
158      void targetDied();
159     
160      bool bHasTargetPosition_;
161      Vector3 targetPosition_;
162      bool bHasTargetOrientation_;
163      Quaternion targetOrientation_;
164
165      WeakPtr<Pawn> target_;
166      bool bShooting_;
167  };
168
169
170}
171#endif /* _Masterable_h__ */
172
173
Note: See TracBrowser for help on using the repository browser.