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