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 _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 | |
---|
43 | namespace 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 | |
---|
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 | orxout(debug_output) << "Set team to: "<<team<<" in "<<this<< endl;} |
---|
81 | inline int getTeam() const |
---|
82 | { return this->team_; } |
---|
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 Mode {NORMAL,DEFEND,ATTACK}; |
---|
91 | |
---|
92 | /** |
---|
93 | @brief Sets the new mode. If master, set it for all slaves. |
---|
94 | */ |
---|
95 | void setMode(Mode val); |
---|
96 | inline Mode getMode() const |
---|
97 | { return this->mode_; } |
---|
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 | Mode mode_; |
---|
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 copyOrientation(const Quaternion& orient); |
---|
121 | void copyTargetOrientation(); |
---|
122 | |
---|
123 | void removeFromFormation(); |
---|
124 | void unregisterSlave(); |
---|
125 | void searchNewMaster(); |
---|
126 | void commandSlaves(); |
---|
127 | void setNewMasterWithinFormation(); |
---|
128 | |
---|
129 | void freeSlaves(); |
---|
130 | void forceFreeSlaves(); |
---|
131 | void loseMasterState(); |
---|
132 | void forceFreedom(); |
---|
133 | bool forcedFree(); |
---|
134 | |
---|
135 | void takeLeadOfFormation(); |
---|
136 | void masterAttacked(Pawn* originator); |
---|
137 | |
---|
138 | void specificMasterActionHold(); |
---|
139 | void turn180Init(); |
---|
140 | void spinInit(); |
---|
141 | void spin(); |
---|
142 | void turn180(); |
---|
143 | void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100); |
---|
144 | void followRandomHumanInit(); |
---|
145 | void follow(); |
---|
146 | |
---|
147 | void setTargetPosition(const Vector3& target); |
---|
148 | void searchRandomTargetPosition(); |
---|
149 | |
---|
150 | void setTargetOrientation(const Quaternion& orient); |
---|
151 | void setTargetOrientation(Pawn* target); |
---|
152 | |
---|
153 | virtual void positionReached() {} |
---|
154 | |
---|
155 | static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack |
---|
156 | |
---|
157 | |
---|
158 | void setTarget(Pawn* target); |
---|
159 | void searchNewTarget(); |
---|
160 | void forgetTarget(); |
---|
161 | |
---|
162 | void targetDied(); |
---|
163 | |
---|
164 | bool bHasTargetPosition_; |
---|
165 | Vector3 targetPosition_; |
---|
166 | bool bHasTargetOrientation_; |
---|
167 | Quaternion targetOrientation_; |
---|
168 | |
---|
169 | WeakPtr<Pawn> target_; |
---|
170 | bool bShooting_; |
---|
171 | }; |
---|
172 | |
---|
173 | |
---|
174 | } |
---|
175 | #endif /* _FormationController_h__ */ |
---|
176 | |
---|
177 | |
---|