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 _CommonController_H__ |
---|
30 | #define _CommonController_H__ |
---|
31 | |
---|
32 | |
---|
33 | #include "controllers/Controller.h" |
---|
34 | #include "worldentities/ControllableEntity.h" |
---|
35 | #include "worldentities/pawns/Pawn.h" |
---|
36 | #include "util/Math.h" |
---|
37 | |
---|
38 | #include "tools/Timer.h" |
---|
39 | #include "tools/interfaces/Tickable.h" |
---|
40 | #include <limits> |
---|
41 | #include "worldentities/Actionpoint.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | |
---|
46 | namespace FormationMode |
---|
47 | { |
---|
48 | enum Value |
---|
49 | { |
---|
50 | FINGER4, DIAMOND, WALL |
---|
51 | }; |
---|
52 | } |
---|
53 | namespace Rank |
---|
54 | { |
---|
55 | enum Value |
---|
56 | { |
---|
57 | NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN |
---|
58 | }; |
---|
59 | |
---|
60 | } |
---|
61 | namespace Action |
---|
62 | { |
---|
63 | enum Value |
---|
64 | { |
---|
65 | NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK |
---|
66 | }; |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | struct Point { |
---|
71 | Action::Value action; |
---|
72 | std::string name; |
---|
73 | Vector3 position; |
---|
74 | } ; |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | class _OrxonoxExport CommonController : public Controller, public Tickable |
---|
81 | { |
---|
82 | |
---|
83 | public: |
---|
84 | static const float hardcoded_projectile_speed = 750; |
---|
85 | static const float ACTION_INTERVAL = 1.0f; |
---|
86 | |
---|
87 | CommonController(Context* context); |
---|
88 | virtual ~CommonController(); |
---|
89 | |
---|
90 | virtual void tick(float dt); |
---|
91 | |
---|
92 | //----[XML data]---- |
---|
93 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
94 | //----[Action data]---- |
---|
95 | Action::Value getAction (); |
---|
96 | void setAction (Action::Value action); |
---|
97 | void setAction (Action::Value action, ControllableEntity* target); |
---|
98 | void setAction (Action::Value action, const Vector3& target); |
---|
99 | void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); |
---|
100 | void setActionXML( std::string val); |
---|
101 | std::string getActionXML(); |
---|
102 | //----[/Action data]---- |
---|
103 | //----[Formation data]---- |
---|
104 | virtual void setFormationModeXML(std::string val); |
---|
105 | virtual std::string getFormationModeXML(); |
---|
106 | virtual void setFormationMode(FormationMode::Value val) |
---|
107 | { this->formationMode_ = val; } |
---|
108 | inline FormationMode::Value getFormationMode() const |
---|
109 | { return this->formationMode_; } |
---|
110 | //----[/Formation data]---- |
---|
111 | //----[Rank data]---- |
---|
112 | virtual void setRank(Rank::Value val) |
---|
113 | { this->rank_ = val; } |
---|
114 | inline Rank::Value getRank() const |
---|
115 | { return this->rank_; } |
---|
116 | //----[/Rank data]---- |
---|
117 | //----[Protect data]---- |
---|
118 | void setProtectXML( std::string val ); |
---|
119 | std::string getProtectXML (); |
---|
120 | void setProtect (ControllableEntity* protect); |
---|
121 | ControllableEntity* getProtect (); |
---|
122 | //----[/Protect data]---- |
---|
123 | //----[Actionpoint data]---- |
---|
124 | void addActionpoint(WorldEntity* waypoint); |
---|
125 | WorldEntity* getActionpoint(unsigned int index) const; |
---|
126 | //----[/Actionpoint data]---- |
---|
127 | //----[/XML data]---- |
---|
128 | |
---|
129 | //----[Interaction with other Controllers]---- |
---|
130 | virtual bool setWingman(CommonController* wingman); |
---|
131 | virtual bool hasWingman(); |
---|
132 | |
---|
133 | void setPositionOfTarget(const Vector3& target); |
---|
134 | void setOrientationOfTarget(const Quaternion& orient); |
---|
135 | |
---|
136 | void setTarget(ControllableEntity* target); |
---|
137 | ControllableEntity* getTarget(); |
---|
138 | bool hasTarget(); |
---|
139 | |
---|
140 | void setTargetPosition(const Vector3& target); |
---|
141 | void setTargetOrientation(const Quaternion& orient); |
---|
142 | void setTargetOrientation(ControllableEntity* target); |
---|
143 | //----[/Interaction with other Controllers]---- |
---|
144 | |
---|
145 | //----[Helper functions]---- |
---|
146 | float randomInRange(float a, float b); |
---|
147 | static float distance(ControllableEntity* entity1, ControllableEntity* entity2); |
---|
148 | static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); |
---|
149 | static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; |
---|
150 | static std::string getName( Pawn* entity ) ; |
---|
151 | |
---|
152 | float squaredDistanceToTarget() const; |
---|
153 | bool isLookingAtTarget(float angle) const; |
---|
154 | //----[/Helper functions]---- |
---|
155 | |
---|
156 | protected: |
---|
157 | //----[Flying functionality]---- |
---|
158 | void stopMoving(); |
---|
159 | |
---|
160 | void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); |
---|
161 | bool moveAndRoll(float dt); |
---|
162 | |
---|
163 | void moveToPosition(const Vector3& target, float dt); |
---|
164 | void moveToTargetPosition(float dt); |
---|
165 | |
---|
166 | void copyOrientation(const Quaternion& orient, float dt); |
---|
167 | void copyTargetOrientation(float dt); |
---|
168 | |
---|
169 | void lookAtTarget(float dt); |
---|
170 | void stopLookingAtTarget(); |
---|
171 | void startLookingAtTarget(); |
---|
172 | |
---|
173 | bool bLookAtTarget_; |
---|
174 | //----[/Flying functionality]---- |
---|
175 | |
---|
176 | //----[Fighting functionality]---- |
---|
177 | void maneuver(); |
---|
178 | void dodge(Vector3& thisPosition, Vector3& diffUnit); |
---|
179 | void aimAtTarget(); |
---|
180 | bool canFire(); |
---|
181 | void doFire(); |
---|
182 | void setClosestTarget(); |
---|
183 | Pawn* closestTarget(); |
---|
184 | |
---|
185 | bool bShooting_; |
---|
186 | int maneuverCounter_; |
---|
187 | //----[/Fighting functionality]---- |
---|
188 | |
---|
189 | //----[where-to-fly information]---- |
---|
190 | bool bHasTargetPosition_; |
---|
191 | Vector3 targetPosition_; |
---|
192 | bool bHasTargetOrientation_; |
---|
193 | Quaternion targetOrientation_; |
---|
194 | |
---|
195 | |
---|
196 | //----[/where-to-fly information]---- |
---|
197 | //----[protect information]---- |
---|
198 | WeakPtr<ControllableEntity> protect_; |
---|
199 | //----[/protect information]---- |
---|
200 | //----[who-to-kill information]---- |
---|
201 | WeakPtr<ControllableEntity> target_; |
---|
202 | |
---|
203 | bool bHasPositionOfTarget_; |
---|
204 | Vector3 positionOfTarget_; |
---|
205 | bool bHasOrientationOfTarget_; |
---|
206 | Quaternion orientationOfTarget_; |
---|
207 | //----[/who-to-kill information]---- |
---|
208 | |
---|
209 | //----[Actionpoint information]---- |
---|
210 | std::vector<WeakPtr<WorldEntity> > actionpoints_; |
---|
211 | float squaredaccuracy_; |
---|
212 | Point currentActionpoint_; |
---|
213 | std::vector<Point > parsedActionpoints_; |
---|
214 | void executeActionpoint(); |
---|
215 | void nextActionpoint(); |
---|
216 | //----[/Actionpoint information]---- |
---|
217 | //----["Private" variables]---- |
---|
218 | FormationMode::Value formationMode_; |
---|
219 | Rank::Value rank_; |
---|
220 | std::string protectName_; |
---|
221 | std::string targetName_; |
---|
222 | Action::Value action_; |
---|
223 | int attackRange_; |
---|
224 | |
---|
225 | //----[/"Private" variables]---- |
---|
226 | }; |
---|
227 | } |
---|
228 | |
---|
229 | #endif /* _CommonController_H__ */ |
---|