/** * MaNGOS is a full featured server for World of Warcraft, supporting * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 * * Copyright (C) 2005-2017 MaNGOS project * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * World of Warcraft, and all World of Warcraft or Warcraft art, images, * and lore are copyrighted by Blizzard Entertainment, Inc. */ #ifndef MANGOS_TARGETEDMOVEMENTGENERATOR_H #define MANGOS_TARGETEDMOVEMENTGENERATOR_H #include "MovementGenerator.h" #include "FollowerReference.h" class PathFinder; class TargetedMovementGeneratorBase { public: TargetedMovementGeneratorBase(Unit& target) { i_target.link(&target, this); } void stopFollowing() { } protected: FollowerReference i_target; }; template class TargetedMovementGeneratorMedium : public MovementGeneratorMedium< T, D >, public TargetedMovementGeneratorBase { protected: TargetedMovementGeneratorMedium(Unit& target, float offset, float angle) : TargetedMovementGeneratorBase(target), i_recheckDistance(0), i_offset(offset), i_angle(angle), m_speedChanged(false), i_targetReached(false), i_path(NULL) { } ~TargetedMovementGeneratorMedium() { delete i_path; } public: bool Update(T&, const uint32&); bool IsReachable() const; Unit* GetTarget() const { return i_target.getTarget(); } void unitSpeedChanged() { m_speedChanged = true; } protected: void _setTargetLocation(T&, bool updateDestination); bool RequiresNewPosition(T& owner, float x, float y, float z) const; virtual float GetDynamicTargetDistance(T& owner, bool forRangeCheck) const { return i_offset; } ShortTimeTracker i_recheckDistance; float i_offset; float i_angle; bool m_speedChanged : 1; bool i_targetReached : 1; PathFinder* i_path; }; template class ChaseMovementGenerator : public TargetedMovementGeneratorMedium > { public: ChaseMovementGenerator(Unit& target, float offset, float angle) : TargetedMovementGeneratorMedium >(target, offset, angle) {} ~ChaseMovementGenerator() {} MovementGeneratorType GetMovementGeneratorType() const override { return CHASE_MOTION_TYPE; } void Initialize(T&); void Finalize(T&); void Interrupt(T&); void Reset(T&); static void _clearUnitStateMove(T& u); static void _addUnitStateMove(T& u); bool EnableWalking() const { return false;} bool _lostTarget(T& u) const; void _reachTarget(T&); protected: float GetDynamicTargetDistance(T& owner, bool forRangeCheck) const override; }; template class FollowMovementGenerator : public TargetedMovementGeneratorMedium > { public: FollowMovementGenerator(Unit& target) : TargetedMovementGeneratorMedium >(target) {} FollowMovementGenerator(Unit& target, float offset, float angle) : TargetedMovementGeneratorMedium >(target, offset, angle) {} ~FollowMovementGenerator() {} MovementGeneratorType GetMovementGeneratorType() const override { return FOLLOW_MOTION_TYPE; } void Initialize(T&); void Finalize(T&); void Interrupt(T&); void Reset(T&); static void _clearUnitStateMove(T& u); static void _addUnitStateMove(T& u); bool EnableWalking() const; bool _lostTarget(T&) const { return false; } void _reachTarget(T&) {} private: void _updateSpeed(T& u); protected: float GetDynamicTargetDistance(T& owner, bool forRangeCheck) const override; }; #endif