[10871] | 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: |
---|
[10885] | 23 | * Gani Aliguzhinov |
---|
[10871] | 24 | * Co-authors: |
---|
[10885] | 25 | * Fabian 'x3n' Landau, Dominik Solenicki |
---|
[10871] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _FightingController_H__ |
---|
| 30 | #define _FightingController_H__ |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | #include "controllers/FlyingController.h" |
---|
| 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
[10898] | 37 | /** |
---|
| 38 | @brief |
---|
| 39 | FightingController stores all the fighting methods and member variables of AI. |
---|
| 40 | Main methods here are maneuver() and dodge(). |
---|
| 41 | */ |
---|
[10871] | 42 | class _OrxonoxExport FightingController : public FlyingController |
---|
| 43 | { |
---|
| 44 | |
---|
| 45 | public: |
---|
| 46 | FightingController(Context* context); |
---|
| 47 | virtual ~FightingController(); |
---|
| 48 | |
---|
| 49 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 50 | |
---|
| 51 | float squaredDistanceToTarget() const; |
---|
[10885] | 52 | bool isLookingAtTarget(float angle) const; |
---|
| 53 | bool hasTarget() const; |
---|
| 54 | ControllableEntity* getTarget() const |
---|
[10871] | 55 | { return this->target_; } |
---|
[10898] | 56 | bool bKeepFormation_; //even if action_ == FIGHT, you might still want to keep formation if far enough form the target |
---|
[10871] | 57 | |
---|
| 58 | protected: |
---|
[10898] | 59 | void setTarget(ControllableEntity* target); //set a target to shoot at |
---|
[10871] | 60 | |
---|
[10898] | 61 | void setPositionOfTarget(const Vector3& target); //good to know where target is |
---|
| 62 | void setOrientationOfTarget(const Quaternion& orient); //I don't really use that |
---|
| 63 | void stopLookingAtTarget(); //<! target dead -> you need to be able to fly |
---|
| 64 | void startLookingAtTarget(); //<! if close to target, no need to fly, just rotate yourself |
---|
| 65 | void lookAtTarget(float dt); //<! rotate yourself towards target |
---|
[10871] | 66 | |
---|
[10898] | 67 | void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on |
---|
| 68 | //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_. |
---|
[10906] | 69 | void dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between |
---|
[10898] | 70 | //<! this and target_ plus or minus some amount in difference vector direction, |
---|
| 71 | //<! depending on whether it is better to close up or survive. |
---|
| 72 | void dodgeTowards (Vector3& position); //fly towards position and awoid being hit |
---|
| 73 | bool canFire(); //<! check if target_ is in radius and if this is looking at target_ |
---|
| 74 | void doFire(); //<! choose weapon, set aim at target_ and fire |
---|
[10871] | 75 | WeakPtr<ControllableEntity> target_; |
---|
| 76 | void setClosestTarget(); |
---|
| 77 | |
---|
| 78 | bool bHasPositionOfTarget_; |
---|
| 79 | Vector3 positionOfTarget_; |
---|
| 80 | bool bHasOrientationOfTarget_; |
---|
| 81 | Quaternion orientationOfTarget_; |
---|
[10885] | 82 | Pawn* closestTarget() const; |
---|
[10871] | 83 | |
---|
[10927] | 84 | bool bDodge_; |
---|
[10871] | 85 | int attackRange_; |
---|
| 86 | bool bShooting_; |
---|
[10885] | 87 | bool bLookAtTarget_; |
---|
[10886] | 88 | float deltaHp; |
---|
| 89 | float previousHp; |
---|
[10906] | 90 | bool bStartedDodging_; |
---|
[10885] | 91 | //WEAPONSYSTEM DATA |
---|
| 92 | int rocketsLeft_; |
---|
[10934] | 93 | int timeout_; |
---|
[10885] | 94 | bool bFiredRocket_; |
---|
| 95 | std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() |
---|
| 96 | //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() |
---|
| 97 | void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. |
---|
| 98 | bool bSetupWorked; //<! If false, setupWeapons() is called. |
---|
| 99 | int getFiremode(std::string name); |
---|
| 100 | |
---|
[10871] | 101 | }; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | #endif /* _FightingController_H__ */ |
---|