/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * */ #ifndef _CommonController_H__ #define _CommonController_H__ #include "controllers/Controller.h" #include "worldentities/ControllableEntity.h" #include "worldentities/pawns/Pawn.h" #include "util/Math.h" #include "tools/Timer.h" #include "tools/interfaces/Tickable.h" #include #include "worldentities/Actionpoint.h" namespace orxonox { namespace FormationMode { enum Value { FINGER4, DIAMOND, WALL }; } namespace Rank { enum Value { NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN }; } namespace Action { enum Value { NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK }; } struct Point { Action::Value action; std::string name; Vector3 position; } ; class _OrxonoxExport CommonController : public Controller, public Tickable { public: static const float hardcoded_projectile_speed = 750; static const float ACTION_INTERVAL = 1.0f; CommonController(Context* context); virtual ~CommonController(); virtual void tick(float dt); //----[XML data]---- virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //----[Action data]---- Action::Value getAction (); void setAction (Action::Value action); void setAction (Action::Value action, ControllableEntity* target); void setAction (Action::Value action, const Vector3& target); void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); void setActionXML( std::string val); std::string getActionXML(); //----[/Action data]---- //----[Formation data]---- virtual void setFormationModeXML(std::string val); virtual std::string getFormationModeXML(); virtual void setFormationMode(FormationMode::Value val) { this->formationMode_ = val; } inline FormationMode::Value getFormationMode() const { return this->formationMode_; } //----[/Formation data]---- //----[Rank data]---- virtual void setRank(Rank::Value val) { this->rank_ = val; } inline Rank::Value getRank() const { return this->rank_; } //----[/Rank data]---- //----[Protect data]---- void setProtectXML( std::string val ); std::string getProtectXML (); void setProtect (ControllableEntity* protect); ControllableEntity* getProtect (); //----[/Protect data]---- //----[Actionpoint data]---- void addActionpoint(WorldEntity* waypoint); WorldEntity* getActionpoint(unsigned int index) const; //----[/Actionpoint data]---- //----[/XML data]---- //----[Interaction with other Controllers]---- virtual bool setWingman(CommonController* wingman); virtual bool hasWingman(); void setPositionOfTarget(const Vector3& target); void setOrientationOfTarget(const Quaternion& orient); void setTarget(ControllableEntity* target); ControllableEntity* getTarget(); bool hasTarget(); void setTargetPosition(const Vector3& target); void setTargetOrientation(const Quaternion& orient); void setTargetOrientation(ControllableEntity* target); //----[/Interaction with other Controllers]---- //----[Helper functions]---- float randomInRange(float a, float b); static float distance(ControllableEntity* entity1, ControllableEntity* entity2); static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; static std::string getName( Pawn* entity ) ; float squaredDistanceToTarget() const; bool isLookingAtTarget(float angle) const; //----[/Helper functions]---- protected: //----[Flying functionality]---- void stopMoving(); void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); bool moveAndRoll(float dt); void moveToPosition(const Vector3& target, float dt); void moveToTargetPosition(float dt); void copyOrientation(const Quaternion& orient, float dt); void copyTargetOrientation(float dt); void lookAtTarget(float dt); void stopLookingAtTarget(); void startLookingAtTarget(); bool bLookAtTarget_; //----[/Flying functionality]---- //----[Fighting functionality]---- void maneuver(); void dodge(Vector3& thisPosition, Vector3& diffUnit); void aimAtTarget(); bool canFire(); void doFire(); void setClosestTarget(); Pawn* closestTarget(); bool bShooting_; int maneuverCounter_; //----[/Fighting functionality]---- //----[where-to-fly information]---- bool bHasTargetPosition_; Vector3 targetPosition_; bool bHasTargetOrientation_; Quaternion targetOrientation_; //----[/where-to-fly information]---- //----[protect information]---- WeakPtr protect_; //----[/protect information]---- //----[who-to-kill information]---- WeakPtr target_; bool bHasPositionOfTarget_; Vector3 positionOfTarget_; bool bHasOrientationOfTarget_; Quaternion orientationOfTarget_; //----[/who-to-kill information]---- //----[Actionpoint information]---- std::vector > actionpoints_; float squaredaccuracy_; Point currentActionpoint_; std::vector parsedActionpoints_; void executeActionpoint(); void nextActionpoint(); //----[/Actionpoint information]---- //----["Private" variables]---- FormationMode::Value formationMode_; Rank::Value rank_; std::string protectName_; std::string targetName_; Action::Value action_; int attackRange_; //----[/"Private" variables]---- }; } #endif /* _CommonController_H__ */