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 "core/ClassTreeMask.h" |
---|
37 | |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | |
---|
42 | namespace FormationMode |
---|
43 | { |
---|
44 | enum Value |
---|
45 | { |
---|
46 | VEE, FINGER4, DIAMOND, WALL |
---|
47 | }; |
---|
48 | } |
---|
49 | namespace Rank |
---|
50 | { |
---|
51 | enum Value |
---|
52 | { |
---|
53 | NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN |
---|
54 | }; |
---|
55 | |
---|
56 | } |
---|
57 | //none for a formation flight without attacking, neutral when opponent and this have no |
---|
58 | //advantage over each other, offensive when this spotted opponent first, |
---|
59 | //defensive otherwise |
---|
60 | namespace ManeuverType |
---|
61 | { |
---|
62 | enum Value |
---|
63 | { |
---|
64 | NONE, NEUTRAL, OFFENSIVE, DEFENCIVE |
---|
65 | }; |
---|
66 | |
---|
67 | } |
---|
68 | namespace Action |
---|
69 | { |
---|
70 | enum Value |
---|
71 | { |
---|
72 | FLY, FIGHT, PROTECT |
---|
73 | }; |
---|
74 | } |
---|
75 | //none for a formation flight |
---|
76 | namespace Maneuver |
---|
77 | { |
---|
78 | enum Value |
---|
79 | { |
---|
80 | NONE, GUNSD, SCISSORS, COMBATSPREAD, DEFENSIVESPLIT, BREAK, BARRELROLL, SWOOP, IMMELMANN, |
---|
81 | WINGOVER, LOWYOYO, HIGHYOYO, LAGDISPLACEMENTROLL |
---|
82 | }; |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | class _OrxonoxExport CommonController : public Controller |
---|
87 | { |
---|
88 | |
---|
89 | public: |
---|
90 | static const float hardcoded_projectile_speed = 750; |
---|
91 | |
---|
92 | static const float ACTION_INTERVAL = 1.0f; |
---|
93 | |
---|
94 | |
---|
95 | CommonController(Context* context); |
---|
96 | virtual ~CommonController(); |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | virtual void setFormationMode(FormationMode::Value val) |
---|
103 | { this->formationMode_ = val; } |
---|
104 | inline FormationMode::Value getFormationMode() const |
---|
105 | { return this->formationMode_; } |
---|
106 | virtual void setFormationModeXML(std::string val); |
---|
107 | virtual std::string getFormationModeXML(); |
---|
108 | |
---|
109 | virtual void setRank(Rank::Value val) |
---|
110 | { this->rank_ = val; } |
---|
111 | inline Rank::Value getRank() const |
---|
112 | { return this->rank_; } |
---|
113 | |
---|
114 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | virtual bool setWingman(CommonController* wingman); |
---|
119 | virtual bool hasWingman(); |
---|
120 | |
---|
121 | void setTarget(ControllableEntity* target); |
---|
122 | bool hasTarget(); |
---|
123 | ControllableEntity* getTarget(); |
---|
124 | void setTargetOrientation(const Quaternion& orient); |
---|
125 | void setTargetOrientation(ControllableEntity* target); |
---|
126 | void setTargetPosition(const Vector3& target); |
---|
127 | |
---|
128 | /*void spin(); |
---|
129 | void turn180();*/ |
---|
130 | Action::Value getAction (); |
---|
131 | void setAction (Action::Value action, ControllableEntity* target); |
---|
132 | void setAction (Action::Value action, const Vector3& target); |
---|
133 | void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); |
---|
134 | |
---|
135 | protected: |
---|
136 | void dodge(Vector3& thisPosition, Vector3& diffUnit); |
---|
137 | int counter; |
---|
138 | void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); |
---|
139 | bool moveAndRoll(float dt); |
---|
140 | |
---|
141 | void moveToPosition(const Vector3& target, float dt); |
---|
142 | void moveToTargetPosition(float dt); |
---|
143 | //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes |
---|
144 | |
---|
145 | //Mode mode_; |
---|
146 | void copyOrientation(const Quaternion& orient, float dt); |
---|
147 | void copyTargetOrientation(float dt); |
---|
148 | |
---|
149 | float squaredDistanceToTarget() const; |
---|
150 | void doFire(); |
---|
151 | void aimAtTarget(); |
---|
152 | bool isLookingAtTarget(float angle) const; |
---|
153 | bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )const; |
---|
154 | |
---|
155 | //checks if spaceship points at enemy and if there are allies inbetween |
---|
156 | bool canFire(); |
---|
157 | std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() |
---|
158 | //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() |
---|
159 | float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) |
---|
160 | void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. |
---|
161 | bool bSetupWorked; //<! If false, setupWeapons() is called. |
---|
162 | int getFiremode(std::string name); |
---|
163 | |
---|
164 | float randomInRange(float a, float b); |
---|
165 | bool bHasTargetPosition_; |
---|
166 | Vector3 targetPosition_; |
---|
167 | bool bHasTargetOrientation_; |
---|
168 | Quaternion targetOrientation_; |
---|
169 | |
---|
170 | Vector3 destination_; |
---|
171 | bool bHasDestination; |
---|
172 | |
---|
173 | |
---|
174 | void stopMoving(); |
---|
175 | void setPositionOfTarget(const Vector3& target); |
---|
176 | void setOrientationOfTarget(const Quaternion& orient); |
---|
177 | bool bHasPositionOfTarget_; |
---|
178 | Vector3 positionOfTarget_; |
---|
179 | bool bHasOrientationOfTarget_; |
---|
180 | Quaternion orientationOfTarget_; |
---|
181 | |
---|
182 | |
---|
183 | WeakPtr<ControllableEntity> target_; |
---|
184 | //WeakPtr<ControllableEntity> thisEntity_; |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | Action::Value action_; |
---|
189 | bool bEngaging_; |
---|
190 | bool bShooting_; |
---|
191 | WeakPtr<ControllableEntity> objectiveTarget_; |
---|
192 | |
---|
193 | void lookAtTarget(float dt); |
---|
194 | void stopLookingAtTarget(); |
---|
195 | void startLookingAtTarget(); |
---|
196 | bool bLookAtTarget_; |
---|
197 | void maneuver(); |
---|
198 | void chooseManeuverType(); |
---|
199 | void gunsD(); |
---|
200 | void attack(); |
---|
201 | void scissors(); |
---|
202 | FormationMode::Value formationMode_; |
---|
203 | Rank::Value rank_; |
---|
204 | ManeuverType::Value maneuverType_; |
---|
205 | Maneuver::Value maneuver_; |
---|
206 | |
---|
207 | bool executingManeuver_; |
---|
208 | bool executingMoveToPoint_; |
---|
209 | |
---|
210 | private: |
---|
211 | |
---|
212 | |
---|
213 | }; |
---|
214 | } |
---|
215 | |
---|
216 | #endif /* _CommonController_H__ */ |
---|