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