[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 | } |
---|
[10864] | 63 | |
---|
[10849] | 64 | |
---|
| 65 | |
---|
[10826] | 66 | |
---|
[10761] | 67 | |
---|
[10843] | 68 | class _OrxonoxExport CommonController : public Controller, public Tickable |
---|
[10719] | 69 | { |
---|
[10796] | 70 | |
---|
[10719] | 71 | public: |
---|
[10803] | 72 | static const float hardcoded_projectile_speed = 750; |
---|
| 73 | static const float ACTION_INTERVAL = 1.0f; |
---|
[10729] | 74 | |
---|
[10731] | 75 | CommonController(Context* context); |
---|
| 76 | virtual ~CommonController(); |
---|
| 77 | |
---|
[10840] | 78 | virtual void tick(float dt); |
---|
| 79 | |
---|
[10851] | 80 | //----[XML methods]---- |
---|
[10832] | 81 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
[10851] | 82 | |
---|
[10864] | 83 | void setFormationModeXML(std::string val); |
---|
| 84 | std::string getFormationModeXML(); |
---|
| 85 | void setFormationMode(FormationMode::Value val); |
---|
| 86 | FormationMode::Value getFormationMode() const; |
---|
[10851] | 87 | |
---|
[10864] | 88 | void setRank(Rank::Value val); |
---|
| 89 | Rank::Value getRank() const; |
---|
| 90 | |
---|
| 91 | |
---|
[10851] | 92 | //----[/XML methods]---- |
---|
[10731] | 93 | |
---|
[10832] | 94 | //----[Interaction with other Controllers]---- |
---|
| 95 | virtual bool setWingman(CommonController* wingman); |
---|
| 96 | virtual bool hasWingman(); |
---|
[10851] | 97 | |
---|
| 98 | bool hasTarget(); |
---|
[10832] | 99 | ControllableEntity* getTarget(); |
---|
[10851] | 100 | |
---|
[10864] | 101 | //----[/Interaction with other Controllers]---- |
---|
[10759] | 102 | |
---|
[10851] | 103 | //----[Helper methods]---- |
---|
[10832] | 104 | float randomInRange(float a, float b); |
---|
| 105 | static float distance(ControllableEntity* entity1, ControllableEntity* entity2); |
---|
[10838] | 106 | static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); |
---|
[10832] | 107 | static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; |
---|
[10848] | 108 | static std::string getName( Pawn* entity ) ; |
---|
[10731] | 109 | |
---|
[10832] | 110 | float squaredDistanceToTarget() const; |
---|
[10851] | 111 | bool isLookingAtTarget(float angle); |
---|
| 112 | //----[/Helper methods]---- |
---|
[10731] | 113 | |
---|
[10864] | 114 | |
---|
[10719] | 115 | protected: |
---|
[10851] | 116 | //----[Flying methods]---- |
---|
[10832] | 117 | void stopMoving(); |
---|
[10851] | 118 | void stopLookingAtTarget(); |
---|
| 119 | void startLookingAtTarget(); |
---|
[10789] | 120 | |
---|
[10832] | 121 | void moveToPosition(const Vector3& target, float dt); |
---|
| 122 | void moveToTargetPosition(float dt); |
---|
[10725] | 123 | |
---|
[10832] | 124 | void copyOrientation(const Quaternion& orient, float dt); |
---|
| 125 | void copyTargetOrientation(float dt); |
---|
[10725] | 126 | |
---|
[10832] | 127 | void lookAtTarget(float dt); |
---|
[10737] | 128 | |
---|
[10851] | 129 | void setTargetPosition(const Vector3& target); |
---|
| 130 | void setTargetOrientation(const Quaternion& orient); |
---|
| 131 | void setTargetOrientation(ControllableEntity* target); |
---|
[10856] | 132 | virtual void boostControl(); |
---|
[10851] | 133 | |
---|
| 134 | |
---|
| 135 | //----[/Flying methods]---- |
---|
[10832] | 136 | |
---|
[10851] | 137 | //----[Fighting methods]---- |
---|
| 138 | void setTarget(ControllableEntity* target); |
---|
| 139 | |
---|
| 140 | void setPositionOfTarget(const Vector3& target); |
---|
| 141 | void setOrientationOfTarget(const Quaternion& orient); |
---|
| 142 | |
---|
| 143 | |
---|
[10832] | 144 | void maneuver(); |
---|
| 145 | void dodge(Vector3& thisPosition, Vector3& diffUnit); |
---|
| 146 | bool canFire(); |
---|
| 147 | void doFire(); |
---|
[10864] | 148 | |
---|
[10851] | 149 | //----[/Fighting methods]---- |
---|
[10832] | 150 | |
---|
| 151 | //----[where-to-fly information]---- |
---|
[10851] | 152 | |
---|
[10832] | 153 | bool bHasTargetPosition_; |
---|
| 154 | Vector3 targetPosition_; |
---|
| 155 | bool bHasTargetOrientation_; |
---|
| 156 | Quaternion targetOrientation_; |
---|
[10838] | 157 | |
---|
[10832] | 158 | //----[/where-to-fly information]---- |
---|
[10838] | 159 | //----[protect information]---- |
---|
| 160 | WeakPtr<ControllableEntity> protect_; |
---|
| 161 | //----[/protect information]---- |
---|
[10832] | 162 | //----[who-to-kill information]---- |
---|
| 163 | WeakPtr<ControllableEntity> target_; |
---|
[10847] | 164 | |
---|
[10832] | 165 | bool bHasPositionOfTarget_; |
---|
| 166 | Vector3 positionOfTarget_; |
---|
| 167 | bool bHasOrientationOfTarget_; |
---|
| 168 | Quaternion orientationOfTarget_; |
---|
| 169 | //----[/who-to-kill information]---- |
---|
[10805] | 170 | |
---|
[10854] | 171 | |
---|
[10832] | 172 | //----["Private" variables]---- |
---|
| 173 | FormationMode::Value formationMode_; |
---|
| 174 | Rank::Value rank_; |
---|
[10864] | 175 | |
---|
[10847] | 176 | int attackRange_; |
---|
[10851] | 177 | bool bLookAtTarget_; |
---|
| 178 | bool bShooting_; |
---|
| 179 | int maneuverCounter_; |
---|
| 180 | int tolerance_; |
---|
[10855] | 181 | bool bFirstTick_; |
---|
[10864] | 182 | |
---|
[10856] | 183 | //----[/"Private" variables]---- |
---|
| 184 | |
---|
[10719] | 185 | }; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | #endif /* _CommonController_H__ */ |
---|