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 | //none for a formation flight |
---|
69 | namespace Maneuver |
---|
70 | { |
---|
71 | enum Value |
---|
72 | { |
---|
73 | NONE, GUNSD, SCISSORS, COMBATSPREAD, DEFENSIVESPLIT, BREAK, BARRELROLL, SWOOP, IMMELMANN, |
---|
74 | WINGOVER, LOWYOYO, HIGHYOYO, LAGDISPLACEMENTROLL |
---|
75 | }; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | class _OrxonoxExport CommonController : public Controller |
---|
80 | { |
---|
81 | |
---|
82 | public: |
---|
83 | static const float hardcoded_projectile_speed = 750; |
---|
84 | |
---|
85 | static const float ACTION_INTERVAL = 1.0f; |
---|
86 | |
---|
87 | |
---|
88 | CommonController(Context* context); |
---|
89 | virtual ~CommonController(); |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | virtual void setFormationMode(FormationMode::Value val) |
---|
96 | { this->formationMode_ = val; } |
---|
97 | inline FormationMode::Value getFormationMode() const |
---|
98 | { return this->formationMode_; } |
---|
99 | virtual void setFormationModeXML(std::string val); |
---|
100 | virtual std::string getFormationModeXML(); |
---|
101 | |
---|
102 | virtual void setRank(Rank::Value val) |
---|
103 | { this->rank_ = val; } |
---|
104 | inline Rank::Value getRank() const |
---|
105 | { return this->rank_; } |
---|
106 | |
---|
107 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | virtual bool setWingman(CommonController* wingman); |
---|
112 | virtual bool hasWingman(); |
---|
113 | |
---|
114 | void setTarget(ControllableEntity* target); |
---|
115 | bool hasTarget(); |
---|
116 | void setTargetOrientation(const Quaternion& orient); |
---|
117 | void setTargetOrientation(ControllableEntity* target); |
---|
118 | void setTargetPosition(const Vector3& target); |
---|
119 | |
---|
120 | /*void spin(); |
---|
121 | void turn180();*/ |
---|
122 | |
---|
123 | |
---|
124 | protected: |
---|
125 | |
---|
126 | void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); |
---|
127 | bool moveAndRoll(float dt); |
---|
128 | |
---|
129 | void moveToPosition(const Vector3& target, float dt); |
---|
130 | void moveToTargetPosition(float dt); |
---|
131 | //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes |
---|
132 | |
---|
133 | //Mode mode_; |
---|
134 | void copyOrientation(const Quaternion& orient, float dt); |
---|
135 | void copyTargetOrientation(float dt); |
---|
136 | |
---|
137 | float squaredDistanceToTarget() const; |
---|
138 | void doFire(); |
---|
139 | void aimAtTarget(); |
---|
140 | bool isLookingAtTarget(float angle) const; |
---|
141 | |
---|
142 | //checks if spaceship points at enemy and if there are allies inbetween |
---|
143 | bool canFire(); |
---|
144 | std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() |
---|
145 | //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() |
---|
146 | float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) |
---|
147 | void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. |
---|
148 | bool bSetupWorked; //<! If false, setupWeapons() is called. |
---|
149 | int getFiremode(std::string name); |
---|
150 | |
---|
151 | float randomInRange(float a, float b); |
---|
152 | bool bHasTargetPosition_; |
---|
153 | Vector3 targetPosition_; |
---|
154 | bool bHasTargetOrientation_; |
---|
155 | Quaternion targetOrientation_; |
---|
156 | |
---|
157 | void setPositionOfTarget(const Vector3& target); |
---|
158 | void setOrientationOfTarget(const Quaternion& orient); |
---|
159 | bool bHasPositionOfTarget_; |
---|
160 | Vector3 positionOfTarget_; |
---|
161 | bool bHasOrientationOfTarget_; |
---|
162 | Quaternion orientationOfTarget_; |
---|
163 | |
---|
164 | |
---|
165 | WeakPtr<ControllableEntity> target_; |
---|
166 | bool bShooting_; |
---|
167 | WeakPtr<ControllableEntity> objectiveTarget_; |
---|
168 | |
---|
169 | |
---|
170 | void chooseManeuverType(); |
---|
171 | void gunsD(); |
---|
172 | void attack(); |
---|
173 | void scissors(); |
---|
174 | FormationMode::Value formationMode_; |
---|
175 | Rank::Value rank_; |
---|
176 | ManeuverType::Value maneuverType_; |
---|
177 | Maneuver::Value maneuver_; |
---|
178 | |
---|
179 | bool executingManeuver_; |
---|
180 | bool executingMoveToPoint_; |
---|
181 | |
---|
182 | private: |
---|
183 | |
---|
184 | |
---|
185 | }; |
---|
186 | } |
---|
187 | |
---|
188 | #endif /* _CommonController_H__ */ |
---|