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 | |
---|
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 | FLY, FIGHT, PROTECT |
---|
66 | }; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | class _OrxonoxExport CommonController : public Controller |
---|
71 | { |
---|
72 | |
---|
73 | public: |
---|
74 | static const float hardcoded_projectile_speed = 750; |
---|
75 | static const float ACTION_INTERVAL = 1.0f; |
---|
76 | |
---|
77 | CommonController(Context* context); |
---|
78 | virtual ~CommonController(); |
---|
79 | |
---|
80 | //----[XML data]---- |
---|
81 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
82 | //----[Action data]---- |
---|
83 | Action::Value getAction (); |
---|
84 | void setAction (Action::Value action); |
---|
85 | void setAction (Action::Value action, ControllableEntity* target); |
---|
86 | void setAction (Action::Value action, const Vector3& target); |
---|
87 | void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); |
---|
88 | void setActionXML( std::string val); |
---|
89 | std::string getActionXML(); |
---|
90 | //----[/Action data]---- |
---|
91 | //----[Formation data]---- |
---|
92 | virtual void setFormationModeXML(std::string val); |
---|
93 | virtual std::string getFormationModeXML(); |
---|
94 | virtual void setFormationMode(FormationMode::Value val) |
---|
95 | { this->formationMode_ = val; } |
---|
96 | inline FormationMode::Value getFormationMode() const |
---|
97 | { return this->formationMode_; } |
---|
98 | //----[/Formation data]---- |
---|
99 | //----[Rank data]---- |
---|
100 | virtual void setRank(Rank::Value val) |
---|
101 | { this->rank_ = val; } |
---|
102 | inline Rank::Value getRank() const |
---|
103 | { return this->rank_; } |
---|
104 | //----[/Rank data]---- |
---|
105 | //----[/XML data]---- |
---|
106 | |
---|
107 | //----[Interaction with other Controllers]---- |
---|
108 | virtual bool setWingman(CommonController* wingman); |
---|
109 | virtual bool hasWingman(); |
---|
110 | |
---|
111 | void setPositionOfTarget(const Vector3& target); |
---|
112 | void setOrientationOfTarget(const Quaternion& orient); |
---|
113 | |
---|
114 | void setTarget(ControllableEntity* target); |
---|
115 | ControllableEntity* getTarget(); |
---|
116 | bool hasTarget(); |
---|
117 | |
---|
118 | void setTargetPosition(const Vector3& target); |
---|
119 | void setTargetOrientation(const Quaternion& orient); |
---|
120 | void setTargetOrientation(ControllableEntity* target); |
---|
121 | //----[/Interaction with other Controllers]---- |
---|
122 | |
---|
123 | //----[Helper functions]---- |
---|
124 | float randomInRange(float a, float b); |
---|
125 | static float distance(ControllableEntity* entity1, ControllableEntity* entity2); |
---|
126 | static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2); |
---|
127 | static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; |
---|
128 | |
---|
129 | float squaredDistanceToTarget() const; |
---|
130 | bool isLookingAtTarget(float angle) const; |
---|
131 | //----[/Helper functions]---- |
---|
132 | |
---|
133 | protected: |
---|
134 | //----[Flying functionality]---- |
---|
135 | void stopMoving(); |
---|
136 | |
---|
137 | void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); |
---|
138 | bool moveAndRoll(float dt); |
---|
139 | |
---|
140 | void moveToPosition(const Vector3& target, float dt); |
---|
141 | void moveToTargetPosition(float dt); |
---|
142 | |
---|
143 | void copyOrientation(const Quaternion& orient, float dt); |
---|
144 | void copyTargetOrientation(float dt); |
---|
145 | |
---|
146 | void lookAtTarget(float dt); |
---|
147 | void stopLookingAtTarget(); |
---|
148 | void startLookingAtTarget(); |
---|
149 | |
---|
150 | bool bLookAtTarget_; |
---|
151 | //----[/Flying functionality]---- |
---|
152 | |
---|
153 | //----[Fighting functionality]---- |
---|
154 | void maneuver(); |
---|
155 | void dodge(Vector3& thisPosition, Vector3& diffUnit); |
---|
156 | void aimAtTarget(); |
---|
157 | bool canFire(); |
---|
158 | void doFire(); |
---|
159 | void setClosestTarget(); |
---|
160 | |
---|
161 | bool bShooting_; |
---|
162 | int maneuverCounter_; |
---|
163 | //----[/Fighting functionality]---- |
---|
164 | |
---|
165 | //----[where-to-fly information]---- |
---|
166 | bool bHasTargetPosition_; |
---|
167 | Vector3 targetPosition_; |
---|
168 | bool bHasTargetOrientation_; |
---|
169 | Quaternion targetOrientation_; |
---|
170 | // Vector3 destination_; |
---|
171 | // bool bHasDestination; |
---|
172 | //----[/where-to-fly information]---- |
---|
173 | |
---|
174 | //----[who-to-kill information]---- |
---|
175 | WeakPtr<ControllableEntity> target_; |
---|
176 | //WeakPtr<ControllableEntity> objectiveTarget_; |
---|
177 | |
---|
178 | bool bHasPositionOfTarget_; |
---|
179 | Vector3 positionOfTarget_; |
---|
180 | bool bHasOrientationOfTarget_; |
---|
181 | Quaternion orientationOfTarget_; |
---|
182 | //----[/who-to-kill information]---- |
---|
183 | |
---|
184 | //----["Private" variables]---- |
---|
185 | FormationMode::Value formationMode_; |
---|
186 | Rank::Value rank_; |
---|
187 | Action::Value action_; |
---|
188 | //----[/"Private" variables]---- |
---|
189 | }; |
---|
190 | } |
---|
191 | |
---|
192 | #endif /* _CommonController_H__ */ |
---|