[11721] Simplify walk/run movement mode selection code

This commit is contained in:
SilverIce 2011-07-08 19:26:40 +03:00
parent 9d566398ad
commit fc0eb7e9fa
10 changed files with 10 additions and 54 deletions

View file

@ -2487,7 +2487,6 @@ void Creature::SetWalk(bool enable)
WorldPacket data(enable ? SMSG_SPLINE_MOVE_SET_WALK_MODE : SMSG_SPLINE_MOVE_SET_RUN_MODE, 9); WorldPacket data(enable ? SMSG_SPLINE_MOVE_SET_WALK_MODE : SMSG_SPLINE_MOVE_SET_RUN_MODE, 9);
data << GetPackGUID(); data << GetPackGUID();
SendMessageToSet(&data, true); SendMessageToSet(&data, true);
UpdateWalkMode(this, false);
} }
void Creature::SetLevitate(bool enable) void Creature::SetLevitate(bool enable)

View file

@ -518,8 +518,6 @@ class MANGOS_DLL_SPEC Creature : public Unit
void SetWalk(bool enable); void SetWalk(bool enable);
void SetLevitate(bool enable); void SetLevitate(bool enable);
bool IsLevitating() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_LEVITATING);}
bool IsWalking() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_WALK_MODE);}
uint32 GetShieldBlockValue() const // dunno mob block value uint32 GetShieldBlockValue() const // dunno mob block value
{ {

View file

@ -286,10 +286,6 @@ void WorldSession::HandleMovementOpcodes( WorldPacket & recv_data )
if (plMover) if (plMover)
plMover->UpdateFallInformationIfNeed(movementInfo, opcode); plMover->UpdateFallInformationIfNeed(movementInfo, opcode);
// after move info set
if (opcode == MSG_MOVE_SET_WALK_MODE || opcode == MSG_MOVE_SET_RUN_MODE)
mover->UpdateWalkMode(mover, false);
WorldPacket data(opcode, recv_data.size()); WorldPacket data(opcode, recv_data.size());
data << mover->GetPackGUID(); // write guid data << mover->GetPackGUID(); // write guid
movementInfo.Write(data); // write data movementInfo.Write(data); // write data

View file

@ -283,8 +283,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana); SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana);
} }
UpdateWalkMode(owner);
AIM_Initialize(); AIM_Initialize();
map->Add((Creature*)this); map->Add((Creature*)this);

View file

@ -4719,8 +4719,6 @@ void Spell::DoSummon(SpellEffectIndex eff_idx)
spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false); spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
spawnCreature->UpdateWalkMode(m_caster);
spawnCreature->AIM_Initialize(); spawnCreature->AIM_Initialize();
spawnCreature->InitPetCreateSpells(); spawnCreature->InitPetCreateSpells();
spawnCreature->InitLevelupSpellsForLevel(); spawnCreature->InitLevelupSpellsForLevel();
@ -5640,8 +5638,6 @@ void Spell::EffectSummonPet(SpellEffectIndex eff_idx)
NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000); NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id); NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
NewSummon->UpdateWalkMode(m_caster);
NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true); NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true);
// this enables pet details window (Shift+P) // this enables pet details window (Shift+P)

View file

@ -83,6 +83,7 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
Movement::MoveSplineInit init(owner); Movement::MoveSplineInit init(owner);
init.MoveTo(x,y,z); init.MoveTo(x,y,z);
init.SetWalk(((D*)this)->EnableWalking());
init.Launch(); init.Launch();
} }
@ -216,15 +217,15 @@ void ChaseMovementGenerator<T>::Reset(T &owner)
//-----------------------------------------------// //-----------------------------------------------//
template<> template<>
void FollowMovementGenerator<Creature>::_updateWalkMode(Creature &u) bool FollowMovementGenerator<Creature>::EnableWalking() const
{ {
if (i_target.isValid() && u.IsPet()) return i_target.isValid() && i_target->IsWalking();
u.UpdateWalkMode(i_target.getTarget());
} }
template<> template<>
void FollowMovementGenerator<Player>::_updateWalkMode(Player &) bool FollowMovementGenerator<Player>::EnableWalking() const
{ {
return false;
} }
template<> template<>
@ -249,7 +250,6 @@ template<>
void FollowMovementGenerator<Player>::Initialize(Player &owner) void FollowMovementGenerator<Player>::Initialize(Player &owner)
{ {
owner.addUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE); owner.addUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE);
_updateWalkMode(owner);
_updateSpeed(owner); _updateSpeed(owner);
_setTargetLocation(owner); _setTargetLocation(owner);
} }
@ -258,7 +258,6 @@ template<>
void FollowMovementGenerator<Creature>::Initialize(Creature &owner) void FollowMovementGenerator<Creature>::Initialize(Creature &owner)
{ {
owner.addUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE); owner.addUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE);
_updateWalkMode(owner);
_updateSpeed(owner); _updateSpeed(owner);
_setTargetLocation(owner); _setTargetLocation(owner);
} }
@ -267,7 +266,6 @@ template<class T>
void FollowMovementGenerator<T>::Finalize(T &owner) void FollowMovementGenerator<T>::Finalize(T &owner)
{ {
owner.clearUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE); owner.clearUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE);
_updateWalkMode(owner);
_updateSpeed(owner); _updateSpeed(owner);
} }
@ -275,7 +273,6 @@ template<class T>
void FollowMovementGenerator<T>::Interrupt(T &owner) void FollowMovementGenerator<T>::Interrupt(T &owner)
{ {
owner.clearUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE); owner.clearUnitState(UNIT_STAT_FOLLOW|UNIT_STAT_FOLLOW_MOVE);
_updateWalkMode(owner);
_updateSpeed(owner); _updateSpeed(owner);
} }

View file

@ -80,6 +80,7 @@ class MANGOS_DLL_SPEC ChaseMovementGenerator : public TargetedMovementGeneratorM
static void _clearUnitStateMove(T &u) { u.clearUnitState(UNIT_STAT_CHASE_MOVE); } static void _clearUnitStateMove(T &u) { u.clearUnitState(UNIT_STAT_CHASE_MOVE); }
static void _addUnitStateMove(T &u) { u.addUnitState(UNIT_STAT_CHASE_MOVE); } static void _addUnitStateMove(T &u) { u.addUnitState(UNIT_STAT_CHASE_MOVE); }
bool EnableWalking() const { return false;}
bool _lostTarget(T &u) const { return u.getVictim() != this->GetTarget(); } bool _lostTarget(T &u) const { return u.getVictim() != this->GetTarget(); }
void _reachTarget(T &); void _reachTarget(T &);
}; };
@ -103,10 +104,10 @@ class MANGOS_DLL_SPEC FollowMovementGenerator : public TargetedMovementGenerator
static void _clearUnitStateMove(T &u) { u.clearUnitState(UNIT_STAT_FOLLOW_MOVE); } static void _clearUnitStateMove(T &u) { u.clearUnitState(UNIT_STAT_FOLLOW_MOVE); }
static void _addUnitStateMove(T &u) { u.addUnitState(UNIT_STAT_FOLLOW_MOVE); } static void _addUnitStateMove(T &u) { u.addUnitState(UNIT_STAT_FOLLOW_MOVE); }
bool EnableWalking() const;
bool _lostTarget(T &) const { return false; } bool _lostTarget(T &) const { return false; }
void _reachTarget(T &) {} void _reachTarget(T &) {}
private: private:
void _updateWalkMode(T &u);
void _updateSpeed(T &u); void _updateSpeed(T &u);
}; };

View file

@ -8122,36 +8122,6 @@ bool Unit::canDetectInvisibilityOf(Unit const* u) const
return false; return false;
} }
struct UpdateWalkModeHelper
{
explicit UpdateWalkModeHelper(Unit* _source) : source(_source) {}
void operator()(Unit* unit) const { unit->UpdateWalkMode(source, true); }
Unit* source;
};
void Unit::UpdateWalkMode(Unit* source, bool self)
{
if (GetTypeId() == TYPEID_PLAYER)
CallForAllControlledUnits(UpdateWalkModeHelper(source), CONTROLLED_PET|CONTROLLED_GUARDIANS|CONTROLLED_CHARM|CONTROLLED_MINIPET);
else if (self)
{
bool on = source->m_movementInfo.HasMovementFlag(MOVEFLAG_WALK_MODE);
if (on)
{
if (((Creature*)this)->IsPet() && hasUnitState(UNIT_STAT_FOLLOW))
((Creature*)this)->SetWalk(true);
}
else
{
if (((Creature*)this)->IsPet())
((Creature*)this)->SetWalk(false);
}
}
else
CallForAllControlledUnits(UpdateWalkModeHelper(source), CONTROLLED_PET|CONTROLLED_GUARDIANS|CONTROLLED_CHARM|CONTROLLED_MINIPET);
}
void Unit::UpdateSpeed(UnitMoveType mtype, bool forced, float ratio) void Unit::UpdateSpeed(UnitMoveType mtype, bool forced, float ratio)
{ {
// not in combat pet have same speed as owner // not in combat pet have same speed as owner

View file

@ -1467,6 +1467,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
// recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens // recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens
// if used additional args in ... part then floats must explicitly casted to double // if used additional args in ... part then floats must explicitly casted to double
void SendHeartBeat(); void SendHeartBeat();
bool IsLevitating() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_LEVITATING);}
bool IsWalking() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_WALK_MODE);}
void SetInFront(Unit const* target); void SetInFront(Unit const* target);
void SetFacingTo(float ori); void SetFacingTo(float ori);
@ -1886,7 +1888,6 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void CalculateAbsorbResistBlock(Unit *pCaster, SpellNonMeleeDamage *damageInfo, SpellEntry const* spellProto, WeaponAttackType attType = BASE_ATTACK); void CalculateAbsorbResistBlock(Unit *pCaster, SpellNonMeleeDamage *damageInfo, SpellEntry const* spellProto, WeaponAttackType attType = BASE_ATTACK);
void CalculateHealAbsorb(uint32 heal, uint32 *absorb); void CalculateHealAbsorb(uint32 heal, uint32 *absorb);
void UpdateWalkMode(Unit* source, bool self = true);
void UpdateSpeed(UnitMoveType mtype, bool forced, float ratio = 1.0f); void UpdateSpeed(UnitMoveType mtype, bool forced, float ratio = 1.0f);
float GetSpeed( UnitMoveType mtype ) const; float GetSpeed( UnitMoveType mtype ) const;
float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; } float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11720" #define REVISION_NR "11721"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__