[2362] | 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: |
---|
[7163] | 25 | * Dominik Solenicki |
---|
[2362] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _ArtificialController_H__ |
---|
| 30 | #define _ArtificialController_H__ |
---|
| 31 | |
---|
| 32 | #include "OrxonoxPrereqs.h" |
---|
| 33 | |
---|
[7163] | 34 | #include <vector> |
---|
| 35 | |
---|
[3196] | 36 | #include "util/Math.h" |
---|
[2362] | 37 | #include "Controller.h" |
---|
[7163] | 38 | #include "controllers/NewHumanController.h" |
---|
[8723] | 39 | #include "weaponsystem/WeaponSystem.h" |
---|
[2362] | 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[5929] | 43 | class _OrxonoxExport ArtificialController : public Controller |
---|
[2362] | 44 | { |
---|
| 45 | public: |
---|
| 46 | ArtificialController(BaseObject* creator); |
---|
| 47 | virtual ~ArtificialController(); |
---|
[6417] | 48 | |
---|
[7163] | 49 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 50 | |
---|
[5929] | 51 | void abandonTarget(Pawn* target); |
---|
[2362] | 52 | |
---|
[7163] | 53 | inline void setTeam(int team) |
---|
| 54 | { this->team_ = team; } |
---|
| 55 | inline int getTeam() const |
---|
| 56 | { return this->team_; } |
---|
| 57 | |
---|
| 58 | inline void setFormationFlight(bool formation) |
---|
| 59 | { this->formationFlight_ = formation; } |
---|
| 60 | inline bool getFormationFlight() const |
---|
| 61 | { return this->formationFlight_; } |
---|
| 62 | |
---|
| 63 | inline void setFormationSize(int size) |
---|
| 64 | { this->maxFormationSize_ = size; } |
---|
| 65 | inline int getFormationSize() const |
---|
| 66 | { return this->maxFormationSize_; } |
---|
| 67 | |
---|
| 68 | inline void setPassive(bool passive) |
---|
| 69 | { this->passive_ = passive; } |
---|
| 70 | inline bool getPassive() const |
---|
| 71 | { return this->passive_; } |
---|
| 72 | |
---|
| 73 | virtual void changedControllableEntity(); |
---|
| 74 | |
---|
| 75 | static void formationflight(const bool form); |
---|
| 76 | static void masteraction(const int action); |
---|
| 77 | static void followme(); |
---|
| 78 | static void passivebehaviour(const bool passive); |
---|
| 79 | static void formationsize(const int size); |
---|
| 80 | |
---|
[8723] | 81 | virtual void doFire(); |
---|
| 82 | void setBotLevel(float level=1.0f); |
---|
| 83 | inline float getBotLevel() const |
---|
| 84 | { return this->botlevel_; } |
---|
| 85 | static void setAllBotLevel(float level); |
---|
| 86 | |
---|
[5929] | 87 | protected: |
---|
[2362] | 88 | |
---|
[7163] | 89 | int team_; |
---|
| 90 | bool formationFlight_; |
---|
| 91 | bool passive_; |
---|
| 92 | unsigned int maxFormationSize_; |
---|
| 93 | int freedomCount_; |
---|
| 94 | enum State {SLAVE, MASTER, FREE}; |
---|
| 95 | State state_; |
---|
| 96 | std::vector<ArtificialController*> slaves_; |
---|
| 97 | ArtificialController *myMaster_; |
---|
| 98 | enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW}; |
---|
| 99 | SpecificMasterAction specificMasterAction_; |
---|
| 100 | int specificMasterActionHoldCount_; |
---|
| 101 | float speedCounter_; //for speed adjustment when following |
---|
| 102 | |
---|
[3049] | 103 | void moveToPosition(const Vector3& target); |
---|
| 104 | void moveToTargetPosition(); |
---|
| 105 | |
---|
[8706] | 106 | virtual void positionReached() {} |
---|
| 107 | |
---|
[7163] | 108 | void removeFromFormation(); |
---|
| 109 | void unregisterSlave(); |
---|
| 110 | void searchNewMaster(); |
---|
| 111 | void commandSlaves(); |
---|
| 112 | void setNewMasterWithinFormation(); |
---|
| 113 | |
---|
| 114 | void freeSlaves(); |
---|
| 115 | void forceFreeSlaves(); |
---|
| 116 | void loseMasterState(); |
---|
| 117 | void forceFreedom(); |
---|
| 118 | bool forcedFree(); |
---|
| 119 | |
---|
| 120 | void specificMasterActionHold(); |
---|
| 121 | void turn180Init(); |
---|
| 122 | void turn180(); |
---|
| 123 | void spinInit(); |
---|
| 124 | void spin(); |
---|
| 125 | void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100); |
---|
| 126 | void followRandomHumanInit(); |
---|
| 127 | void follow(); |
---|
| 128 | void followForSlaves(const Vector3& target); |
---|
| 129 | |
---|
[3049] | 130 | void setTargetPosition(const Vector3& target); |
---|
[2362] | 131 | void searchRandomTargetPosition(); |
---|
[3049] | 132 | |
---|
| 133 | void setTarget(Pawn* target); |
---|
[2362] | 134 | void searchNewTarget(); |
---|
| 135 | void forgetTarget(); |
---|
| 136 | void aimAtTarget(); |
---|
| 137 | |
---|
| 138 | bool isCloseAtTarget(float distance) const; |
---|
| 139 | bool isLookingAtTarget(float angle) const; |
---|
| 140 | |
---|
[7163] | 141 | void targetDied(); |
---|
| 142 | |
---|
[3049] | 143 | static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack |
---|
| 144 | |
---|
[2362] | 145 | bool bHasTargetPosition_; |
---|
| 146 | Vector3 targetPosition_; |
---|
[5929] | 147 | WeakPtr<Pawn> target_; |
---|
[2362] | 148 | bool bShooting_; |
---|
| 149 | |
---|
[8723] | 150 | int numberOfWeapons; //< Used for weapon init function. Displayes number of weapons available for a bot. |
---|
| 151 | int weapons[WeaponSystem::MAX_WEAPON_MODES]; |
---|
| 152 | int projectiles[WeaponSystem::MAX_WEAPON_MODES]; |
---|
| 153 | float botlevel_; //< Makes the level of a bot configurable. |
---|
| 154 | float timeout_; //< Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) |
---|
| 155 | |
---|
| 156 | enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes |
---|
| 157 | Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_; |
---|
| 158 | void setPreviousMode(); |
---|
| 159 | |
---|
[2362] | 160 | private: |
---|
[8723] | 161 | void setupWeapons(); |
---|
| 162 | const std::string& getWeaponname(int i, Pawn* pawn); |
---|
| 163 | bool bSetupWorked; |
---|
[2362] | 164 | }; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | #endif /* _ArtificialController_H__ */ |
---|