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 | |
---|
42 | namespace 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 | @brief If master, set the desired position of slaves (Vector2) for all the slaves. |
---|
74 | */ |
---|
75 | inline void setDesiredPositionOfSlaves(); |
---|
76 | |
---|
77 | inline void setPassive(bool passive) |
---|
78 | { this->passive_ = passive; } |
---|
79 | inline bool getPassive() const |
---|
80 | { return this->passive_; } |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | /** |
---|
85 | @brief Mode of the formation, behaviour of slaves |
---|
86 | Normal-normal behaviour |
---|
87 | Defend-just defend the master |
---|
88 | Attack-leave formation, attack every target |
---|
89 | */ |
---|
90 | enum FormationMode {NORMAL,DEFEND,ATTACK}; |
---|
91 | |
---|
92 | /** |
---|
93 | @brief Sets the new mode. If master, set it for all slaves. |
---|
94 | */ |
---|
95 | void setFormationMode(FormationMode val); |
---|
96 | inline FormationMode getFormationMode() const |
---|
97 | { return this->formationMode_; } |
---|
98 | |
---|
99 | virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); |
---|
100 | |
---|
101 | FormationController* getMaster( void ) { return myMaster_; } |
---|
102 | FormationController* getController( void ) { return this; } |
---|
103 | FormationController* getSlave( void ) { return this->slaves_.back(); } |
---|
104 | |
---|
105 | virtual void changedControllableEntity(); |
---|
106 | |
---|
107 | protected: |
---|
108 | bool formationFlight_; |
---|
109 | bool passive_; |
---|
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 takeLeadOfFormation(); |
---|
136 | void loseMasterState(); |
---|
137 | void setNewMasterWithinFormation(); |
---|
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 | |
---|