[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> |
---|
[10719] | 41 | |
---|
[10759] | 42 | |
---|
[10719] | 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 | { |
---|
| 65 | FLY, FIGHT, PROTECT |
---|
| 66 | }; |
---|
| 67 | } |
---|
[10826] | 68 | |
---|
[10761] | 69 | |
---|
[10719] | 70 | class _OrxonoxExport CommonController : public Controller |
---|
| 71 | { |
---|
[10796] | 72 | |
---|
[10719] | 73 | public: |
---|
[10803] | 74 | static const float hardcoded_projectile_speed = 750; |
---|
| 75 | static const float ACTION_INTERVAL = 1.0f; |
---|
[10729] | 76 | |
---|
[10731] | 77 | CommonController(Context* context); |
---|
| 78 | virtual ~CommonController(); |
---|
| 79 | |
---|
[10832] | 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]---- |
---|
[10731] | 106 | |
---|
[10832] | 107 | //----[Interaction with other Controllers]---- |
---|
| 108 | virtual bool setWingman(CommonController* wingman); |
---|
| 109 | virtual bool hasWingman(); |
---|
[10731] | 110 | |
---|
[10832] | 111 | void setPositionOfTarget(const Vector3& target); |
---|
| 112 | void setOrientationOfTarget(const Quaternion& orient); |
---|
[10759] | 113 | |
---|
[10832] | 114 | void setTarget(ControllableEntity* target); |
---|
| 115 | ControllableEntity* getTarget(); |
---|
| 116 | bool hasTarget(); |
---|
[10759] | 117 | |
---|
[10832] | 118 | void setTargetPosition(const Vector3& target); |
---|
| 119 | void setTargetOrientation(const Quaternion& orient); |
---|
| 120 | void setTargetOrientation(ControllableEntity* target); |
---|
| 121 | //----[/Interaction with other Controllers]---- |
---|
[10725] | 122 | |
---|
[10832] | 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 ) ; |
---|
[10731] | 128 | |
---|
[10832] | 129 | float squaredDistanceToTarget() const; |
---|
| 130 | bool isLookingAtTarget(float angle) const; |
---|
| 131 | //----[/Helper functions]---- |
---|
[10731] | 132 | |
---|
[10719] | 133 | protected: |
---|
[10832] | 134 | //----[Flying functionality]---- |
---|
| 135 | void stopMoving(); |
---|
[10789] | 136 | |
---|
[10832] | 137 | void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); |
---|
| 138 | bool moveAndRoll(float dt); |
---|
[10719] | 139 | |
---|
[10832] | 140 | void moveToPosition(const Vector3& target, float dt); |
---|
| 141 | void moveToTargetPosition(float dt); |
---|
[10725] | 142 | |
---|
[10832] | 143 | void copyOrientation(const Quaternion& orient, float dt); |
---|
| 144 | void copyTargetOrientation(float dt); |
---|
[10725] | 145 | |
---|
[10832] | 146 | void lookAtTarget(float dt); |
---|
| 147 | void stopLookingAtTarget(); |
---|
| 148 | void startLookingAtTarget(); |
---|
[10737] | 149 | |
---|
[10832] | 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(); |
---|
[10725] | 160 | |
---|
[10832] | 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_; |
---|
[10805] | 177 | |
---|
[10832] | 178 | bool bHasPositionOfTarget_; |
---|
| 179 | Vector3 positionOfTarget_; |
---|
| 180 | bool bHasOrientationOfTarget_; |
---|
| 181 | Quaternion orientationOfTarget_; |
---|
| 182 | //----[/who-to-kill information]---- |
---|
[10805] | 183 | |
---|
[10832] | 184 | //----["Private" variables]---- |
---|
| 185 | FormationMode::Value formationMode_; |
---|
| 186 | Rank::Value rank_; |
---|
| 187 | Action::Value action_; |
---|
| 188 | //----[/"Private" variables]---- |
---|
[10719] | 189 | }; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | #endif /* _CommonController_H__ */ |
---|