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 <algorithm> |
---|
42 | #include "worldentities/Actionpoint.h" |
---|
43 | #include "worldentities/pawns/SpaceShip.h" |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | |
---|
48 | namespace FormationMode |
---|
49 | { |
---|
50 | enum Value |
---|
51 | { |
---|
52 | FINGER4, DIAMOND, WALL |
---|
53 | }; |
---|
54 | } |
---|
55 | namespace Rank |
---|
56 | { |
---|
57 | enum Value |
---|
58 | { |
---|
59 | NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN |
---|
60 | }; |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | class _OrxonoxExport CommonController : public Controller, public Tickable |
---|
69 | { |
---|
70 | |
---|
71 | public: |
---|
72 | static const float hardcoded_projectile_speed = 750; |
---|
73 | static const float ACTION_INTERVAL = 1.0f; |
---|
74 | |
---|
75 | CommonController(Context* context); |
---|
76 | virtual ~CommonController(); |
---|
77 | |
---|
78 | virtual void tick(float dt); |
---|
79 | |
---|
80 | //----[XML methods]---- |
---|
81 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
82 | |
---|
83 | void setFormationModeXML(std::string val); |
---|
84 | std::string getFormationModeXML(); |
---|
85 | void setFormationMode(FormationMode::Value val); |
---|
86 | FormationMode::Value getFormationMode() const; |
---|
87 | |
---|
88 | void setRank(Rank::Value val); |
---|
89 | Rank::Value getRank() const; |
---|
90 | |
---|
91 | |
---|
92 | //----[/XML methods]---- |
---|
93 | |
---|
94 | //----[Interaction with other Controllers]---- |
---|
95 | virtual bool setWingman(CommonController* wingman); |
---|
96 | virtual bool hasWingman(); |
---|
97 | |
---|
98 | bool hasTarget(); |
---|
99 | ControllableEntity* getTarget(); |
---|
100 | |
---|
101 | //----[/Interaction with other Controllers]---- |
---|
102 | |
---|
103 | //----[Helper methods]---- |
---|
104 | float randomInRange(float a, float b); |
---|
105 | static float distance(ControllableEntity* entity1, ControllableEntity* entity2); |
---|
106 | static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); |
---|
107 | static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; |
---|
108 | static std::string getName( Pawn* entity ) ; |
---|
109 | |
---|
110 | float squaredDistanceToTarget() const; |
---|
111 | bool isLookingAtTarget(float angle); |
---|
112 | //----[/Helper methods]---- |
---|
113 | |
---|
114 | |
---|
115 | protected: |
---|
116 | //----[Flying methods]---- |
---|
117 | void stopMoving(); |
---|
118 | void stopLookingAtTarget(); |
---|
119 | void startLookingAtTarget(); |
---|
120 | |
---|
121 | void moveToPosition(const Vector3& target, float dt); |
---|
122 | void moveToTargetPosition(float dt); |
---|
123 | |
---|
124 | void copyOrientation(const Quaternion& orient, float dt); |
---|
125 | void copyTargetOrientation(float dt); |
---|
126 | |
---|
127 | void lookAtTarget(float dt); |
---|
128 | |
---|
129 | void setTargetPosition(const Vector3& target); |
---|
130 | void setTargetOrientation(const Quaternion& orient); |
---|
131 | void setTargetOrientation(ControllableEntity* target); |
---|
132 | virtual void boostControl(); |
---|
133 | |
---|
134 | |
---|
135 | //----[/Flying methods]---- |
---|
136 | |
---|
137 | //----[Fighting methods]---- |
---|
138 | void setTarget(ControllableEntity* target); |
---|
139 | |
---|
140 | void setPositionOfTarget(const Vector3& target); |
---|
141 | void setOrientationOfTarget(const Quaternion& orient); |
---|
142 | |
---|
143 | |
---|
144 | void maneuver(); |
---|
145 | void dodge(Vector3& thisPosition, Vector3& diffUnit); |
---|
146 | bool canFire(); |
---|
147 | void doFire(); |
---|
148 | |
---|
149 | //----[/Fighting methods]---- |
---|
150 | |
---|
151 | //----[where-to-fly information]---- |
---|
152 | |
---|
153 | bool bHasTargetPosition_; |
---|
154 | Vector3 targetPosition_; |
---|
155 | bool bHasTargetOrientation_; |
---|
156 | Quaternion targetOrientation_; |
---|
157 | |
---|
158 | //----[/where-to-fly information]---- |
---|
159 | //----[protect information]---- |
---|
160 | WeakPtr<ControllableEntity> protect_; |
---|
161 | //----[/protect information]---- |
---|
162 | //----[who-to-kill information]---- |
---|
163 | WeakPtr<ControllableEntity> target_; |
---|
164 | |
---|
165 | bool bHasPositionOfTarget_; |
---|
166 | Vector3 positionOfTarget_; |
---|
167 | bool bHasOrientationOfTarget_; |
---|
168 | Quaternion orientationOfTarget_; |
---|
169 | //----[/who-to-kill information]---- |
---|
170 | |
---|
171 | |
---|
172 | //----["Private" variables]---- |
---|
173 | FormationMode::Value formationMode_; |
---|
174 | Rank::Value rank_; |
---|
175 | |
---|
176 | int attackRange_; |
---|
177 | bool bLookAtTarget_; |
---|
178 | bool bShooting_; |
---|
179 | int maneuverCounter_; |
---|
180 | int tolerance_; |
---|
181 | bool bFirstTick_; |
---|
182 | |
---|
183 | //----[/"Private" variables]---- |
---|
184 | |
---|
185 | }; |
---|
186 | } |
---|
187 | |
---|
188 | #endif /* _CommonController_H__ */ |
---|