Core/Movement: merged more movement commits and fixed build by merging the changes done to movement generators by the header cleanup

This commit is contained in:
Ovahlord
2018-08-02 13:52:12 +02:00
parent 14cdb1aa1d
commit d59a20701e
9 changed files with 43 additions and 19 deletions

View File

@@ -3012,6 +3012,25 @@ void Creature::ReleaseFocus(Spell const* focusSpell, bool withDelay)
m_focusDelay = (!IsPet() && withDelay) ? GameTime::GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs
}
bool Creature::IsMovementPreventedByCasting() const
{
// first check if currently a movement allowed channel is active and we're not casting
if (Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL])
{
if (spell->getState() != SPELL_STATE_FINISHED && spell->IsChannelActive())
if (spell->GetSpellInfo()->IsMoveAllowedChannel())
return false;
}
if (const_cast<Creature*>(this)->IsFocusing(nullptr, true))
return true;
if (HasUnitState(UNIT_STATE_CASTING))
return true;
return false;
}
void Creature::StartPickPocketRefillTimer()
{
_pickpocketLootRestore = time(nullptr) + sWorld->getIntConfig(CONFIG_CREATURE_PICKPOCKET_REFILL);

View File

@@ -322,9 +322,11 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
void MustReacquireTarget() { m_shouldReacquireTarget = true; } // flags the Creature for forced (client displayed) target reacquisition in the next ::Update call
void DoNotReacquireTarget() { m_shouldReacquireTarget = false; m_suppressedTarget = ObjectGuid::Empty; m_suppressedOrientation = 0.0f; }
void FocusTarget(Spell const* focusSpell, WorldObject const* target);
bool IsFocusing(Spell const* focusSpell = nullptr, bool withDelay = false);
bool IsFocusing(Spell const* focusSpell = nullptr, bool withDelay = false) override;
void ReleaseFocus(Spell const* focusSpell = nullptr, bool withDelay = true);
bool IsMovementPreventedByCasting() const override;
CreatureTextRepeatIds GetTextRepeatGroup(uint8 textGroup);
void SetTextRepeatId(uint8 textGroup, uint8 id);
void ClearTextRepeatGroup(uint8 textGroup);

View File

@@ -1587,8 +1587,8 @@ class TC_GAME_API Unit : public WorldObject
int32 GetCurrentSpellCastTime(uint32 spell_id) const;
SpellInfo const* GetCastSpellInfo(SpellInfo const* spellInfo) const;
// Check if our current channel spell has attribute SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING
bool IsMovementPreventedByCasting() const;
virtual bool IsFocusing(Spell const* /*focusSpell*/ = nullptr, bool /*withDelay*/ = false) { return false; }
virtual bool IsMovementPreventedByCasting() const;
SpellHistory* GetSpellHistory() { return m_spellHistory; }
SpellHistory const* GetSpellHistory() const { return m_spellHistory; }

View File

@@ -35,7 +35,7 @@ void FormationMovementGenerator::DoInitialize(Creature* owner)
owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(owner);
init.MoveTo(_destination);
init.MoveTo(_destination.GetPositionX(), _destination.GetPositionY(), _destination.GetPositionZ());
if (_orientation)
init.SetFacing(_destination.GetOrientation());
@@ -81,7 +81,7 @@ bool FormationMovementGenerator::DoUpdate(Creature* owner, uint32 /*diff*/)
owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(owner);
init.MoveTo(_destination);
init.MoveTo(_destination.GetPositionX(), _destination.GetPositionY(), _destination.GetPositionZ());
if (_orientation)
init.SetFacing(_destination.GetOrientation());

View File

@@ -56,7 +56,7 @@ void PointMovementGenerator<T>::DoInitialize(T* owner)
// Call for creature group update
if (Creature* creature = owner->ToCreature())
if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
creature->GetFormation()->LeaderMoveTo(Position(_destination), _movementId);
creature->GetFormation()->LeaderMoveTo(Position(_x, _y, _z), _movementId);
}
template<class T>
@@ -90,7 +90,7 @@ bool PointMovementGenerator<T>::DoUpdate(T* owner, uint32 /*diff*/)
// Call for creature group update
if (Creature* creature = owner->ToCreature())
if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
creature->GetFormation()->LeaderMoveTo(Position(_destination), _movementId);
creature->GetFormation()->LeaderMoveTo(Position(_x, _y, _z), _movementId);
}
return !owner->movespline->Finalized();

View File

@@ -16,13 +16,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RandomMovementGenerator.h"
#include "Creature.h"
#include "CreatureGroups.h"
#include "Map.h"
#include "MoveSplineInit.h"
#include "MoveSpline.h"
#include "PathGenerator.h"
#include "RandomMovementGenerator.h"
#include "Random.h"
template<class T>
@@ -44,7 +44,7 @@ void RandomMovementGenerator<Creature>::DoInitialize(Creature* owner)
return;
owner->AddUnitState(UNIT_STATE_ROAMING);
owner->GetPosition(_reference.x, _reference.y, _reference.z);
_reference = owner->GetPosition();
owner->StopMoving();
if (!_wanderDistance)
@@ -91,7 +91,7 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
owner->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Position position(_reference.x, _reference.y, _reference.z);
Position position(_reference);
float distance = frand(0.f, 1.f) * _wanderDistance;
float angle = frand(0.f, 1.f) * float(M_PI) * 2.f;
owner->MovePositionToFirstCollision(position, distance, angle);

View File

@@ -20,13 +20,14 @@
#define TRINITY_RANDOMMOTIONGENERATOR_H
#include "MovementGenerator.h"
#include "Position.h"
#include "Timer.h"
template<class T>
class RandomMovementGenerator : public MovementGeneratorMedium< T, RandomMovementGenerator<T> >
{
public:
explicit RandomMovementGenerator(float distance = 0.0f) : _path(nullptr), _timer(0), _reference(0.f, 0.f, 0.f), _wanderDistance(distance), _interrupt(false) { }
explicit RandomMovementGenerator(float distance = 0.0f) : _path(nullptr), _timer(0), _reference(), _wanderDistance(distance), _interrupt(false) { }
~RandomMovementGenerator();
MovementGeneratorType GetMovementGeneratorType() const override { return RANDOM_MOTION_TYPE; }
@@ -41,7 +42,7 @@ class RandomMovementGenerator : public MovementGeneratorMedium< T, RandomMovemen
PathGenerator* _path;
TimeTracker _timer;
G3D::Vector3 _reference;
Position _reference;
float _wanderDistance;
bool _interrupt;
};

View File

@@ -41,8 +41,7 @@ bool TargetedMovementGenerator<T, D>::DoUpdate(T* owner, uint32 diff)
if (!owner || !owner->IsAlive())
return false;
if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || owner->IsMovementPreventedByCasting() || HasLostTarget(owner)
|| (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsFocusing(nullptr, true)))
if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || owner->IsMovementPreventedByCasting() || HasLostTarget(owner))
{
_interrupt = true;
owner->StopMoving();
@@ -82,7 +81,9 @@ bool TargetedMovementGenerator<T, D>::DoUpdate(T* owner, uint32 diff)
}
if (targetMoved)
SetTargetLocation(owner, targetMoved);
SetTargetLocation(owner, true);
else if (_speedChanged)
SetTargetLocation(owner, false);
if (!_targetReached && owner->movespline->Finalized())
{
@@ -136,8 +137,7 @@ void TargetedMovementGenerator<T, D>::SetTargetLocation(T* owner, bool updateDes
if (!owner || !owner->IsAlive())
return;
if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || owner->IsMovementPreventedByCasting() || HasLostTarget(owner)
|| (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsFocusing(nullptr, true)))
if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || owner->IsMovementPreventedByCasting() || HasLostTarget(owner))
{
_interrupt = true;
owner->StopMoving();
@@ -204,6 +204,7 @@ void TargetedMovementGenerator<T, D>::SetTargetLocation(T* owner, bool updateDes
_targetReached = false;
_recalculateTravel = false;
_speedChanged = false;
AddUnitStateMove(owner);

View File

@@ -45,11 +45,11 @@ template<class T, typename D>
class TargetedMovementGenerator : public MovementGeneratorMedium< T, D >, public TargetedMovementGeneratorBase
{
public:
explicit TargetedMovementGenerator(Unit* target, float offset, float angle) : TargetedMovementGeneratorBase(target), _path(nullptr), _timer(0), _advanceMovementTimer(0), _offset(offset), _angle(angle), _recalculateTravel(false), _targetReached(false), _interrupt(false) { }
explicit TargetedMovementGenerator(Unit* target, float offset, float angle) : TargetedMovementGeneratorBase(target), _path(nullptr), _timer(0), _advanceMovementTimer(0), _offset(offset), _angle(angle), _recalculateTravel(false), _speedChanged(false), _targetReached(false), _interrupt(false) { }
~TargetedMovementGenerator();
bool DoUpdate(T*, uint32);
void UnitSpeedChanged() override { _recalculateTravel = true; }
void UnitSpeedChanged() override { _speedChanged = true; }
virtual void ClearUnitStateMove(T*) { }
virtual void AddUnitStateMove(T*) { }
@@ -69,6 +69,7 @@ class TargetedMovementGenerator : public MovementGeneratorMedium< T, D >, public
float _offset;
float _angle;
bool _recalculateTravel;
bool _speedChanged;
bool _targetReached;
bool _interrupt;
};