Skip to content

Commit

Permalink
[10068] Fixes in pet movments
Browse files Browse the repository at this point in the history
* Use proper stop packet as expected. In case 0 trevel time used before move packet
  can generate infinity move forward (at client side).
* Avoid reset top movegen before add idle in pet stay command.
* Avoid assign random move to player owned creatures as default movegen.
* Finish follow movegen init including need-stay case.
  • Loading branch information
VladimirMangos committed Jun 16, 2010
1 parent 9f5d9cf commit 51f93a2
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
25 changes: 1 addition & 24 deletions src/game/Creature.cpp
Expand Up @@ -791,29 +791,6 @@ bool Creature::isCanTrainingAndResetTalentsOf(Player* pPlayer) const
&& pPlayer->getClass() == GetCreatureInfo()->trainer_class;
}

void Creature::AI_SendMoveToPacket(float x, float y, float z, uint32 time, SplineFlags flags, SplineType type)
{
/* uint32 timeElap = getMSTime();
if ((timeElap - m_startMove) < m_moveTime)
{
oX = (dX - oX) * ( (timeElap - m_startMove) / m_moveTime );
oY = (dY - oY) * ( (timeElap - m_startMove) / m_moveTime );
}
else
{
oX = dX;
oY = dY;
}
dX = x;
dY = y;
m_orientation = atan2((oY - dY), (oX - dX));
m_startMove = getMSTime();
m_moveTime = time;*/
SendMonsterMove(x, y, z, type, flags, time);
}

void Creature::PrepareBodyLootState()
{
loot.clear();
Expand Down Expand Up @@ -2221,4 +2198,4 @@ void Creature::RelocationNotify()
MaNGOS::CreatureRelocationNotifier relocationNotifier(*this);
float radius = MAX_CREATURE_ATTACK_RADIUS * sWorld.getConfig(CONFIG_FLOAT_RATE_CREATURE_AGGRO);
Cell::VisitAllObjects(this, relocationNotifier, radius);
}
}
1 change: 0 additions & 1 deletion src/game/Creature.h
Expand Up @@ -444,7 +444,6 @@ class MANGOS_DLL_SPEC Creature : public Unit

bool AIM_Initialize();

void AI_SendMoveToPacket(float x, float y, float z, uint32 time, SplineFlags MovementFlags, SplineType type);
CreatureAI* AI() { return i_AI; }

void AddSplineFlag(SplineFlags f)
Expand Down
3 changes: 2 additions & 1 deletion src/game/CreatureAISelector.cpp
Expand Up @@ -90,7 +90,8 @@ namespace FactorySelector
{
MovementGeneratorRegistry &mv_registry(MovementGeneratorRepository::Instance());
ASSERT( creature->GetCreatureInfo() != NULL );
const MovementGeneratorCreator *mv_factory = mv_registry.GetRegistryItem( creature->GetDefaultMovementType());
MovementGeneratorCreator const * mv_factory = mv_registry.GetRegistryItem(
creature->GetOwnerGUID() ? FOLLOW_MOTION_TYPE : creature->GetDefaultMovementType());

/* if( mv_factory == NULL )
{
Expand Down
7 changes: 6 additions & 1 deletion src/game/DestinationHolderImp.h
Expand Up @@ -86,7 +86,12 @@ DestinationHolder<TRAVELLER>::StartTravel(TRAVELLER &traveller, bool sendMove)
i_totalTravelTime = traveller.GetTotalTrevelTimeTo(i_destX,i_destY,i_destZ);
i_timeElapsed = 0;
if(sendMove)
traveller.MoveTo(i_destX, i_destY, i_destZ, i_totalTravelTime);
{
if (i_totalTravelTime)
traveller.MoveTo(i_destX, i_destY, i_destZ, i_totalTravelTime);
else
traveller.Stop();
}
return i_totalTravelTime;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/PetHandler.cpp
Expand Up @@ -86,7 +86,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
{
case COMMAND_STAY: //flat=1792 //STAY
pet->StopMoving();
pet->GetMotionMaster()->Clear();
pet->GetMotionMaster()->Clear(false);
pet->GetMotionMaster()->MoveIdle();
charmInfo->SetCommandState( COMMAND_STAY );
break;
Expand Down
11 changes: 8 additions & 3 deletions src/game/TargetedMovementGenerator.cpp
Expand Up @@ -37,12 +37,17 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
if (owner.hasUnitState(UNIT_STAT_NOT_MOVE))
return;

float x, y, z;

// prevent redundant micro-movement for pets, other followers.
if (i_offset && i_target->IsWithinDistInMap(&owner,2*i_offset))
return;
{
if (i_destinationHolder.HasDestination())
return;

float x, y, z;
if (!i_offset)
owner.GetPosition(x, y, z);
}
else if (!i_offset)
{
// to nearest contact position
i_target->GetContactPoint( &owner, x, y, z );
Expand Down
16 changes: 15 additions & 1 deletion src/game/Traveller.h
Expand Up @@ -55,6 +55,7 @@ struct MANGOS_DLL_DECL Traveller
void Relocation(float x, float y, float z, float orientation) {}
void Relocation(float x, float y, float z) { Relocation(x, y, z, i_traveller.GetOrientation()); }
void MoveTo(float x, float y, float z, uint32 t) {}
void Stop() {}
};

template<class T>
Expand Down Expand Up @@ -102,7 +103,13 @@ inline float Traveller<Creature>::GetMoveDestinationTo(float x, float y, float z
template<>
inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t)
{
i_traveller.AI_SendMoveToPacket(x, y, z, t, i_traveller.GetSplineFlags(), SPLINETYPE_NORMAL);
i_traveller.SendMonsterMove(x, y, z, SPLINETYPE_NORMAL, i_traveller.GetSplineFlags(), t);
}

template<>
inline void Traveller<Creature>::Stop()
{
i_traveller.SendMonsterMove(i_traveller.GetPositionX(), i_traveller.GetPositionY(), i_traveller.GetPositionZ(), SPLINETYPE_STOP, i_traveller.GetSplineFlags(), 0);
}

// specialization for players
Expand Down Expand Up @@ -141,6 +148,13 @@ inline void Traveller<Player>::MoveTo(float x, float y, float z, uint32 t)
i_traveller.SendMonsterMove(x, y, z, SPLINETYPE_NORMAL, SPLINEFLAG_WALKMODE, t);
}

template<>
inline void Traveller<Player>::Stop()
{
//Only send SPLINEFLAG_WALKMODE, client has strange issues with other move flags
i_traveller.SendMonsterMove(i_traveller.GetPositionX(), i_traveller.GetPositionY(), i_traveller.GetPositionZ(), SPLINETYPE_STOP, SPLINEFLAG_WALKMODE, 0);
}

typedef Traveller<Creature> CreatureTraveller;
typedef Traveller<Player> PlayerTraveller;
#endif
2 changes: 1 addition & 1 deletion src/game/Unit.cpp
Expand Up @@ -12783,7 +12783,7 @@ void Unit::StopMoving()

// send explicit stop packet
// player expected for correct work SPLINEFLAG_WALKMODE
SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_NORMAL, GetTypeId() == TYPEID_PLAYER ? SPLINEFLAG_WALKMODE : SPLINEFLAG_NONE, 0);
SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_STOP, GetTypeId() == TYPEID_PLAYER ? SPLINEFLAG_WALKMODE : SPLINEFLAG_NONE, 0);

// update position and orientation for near players
WorldPacket data;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10067"
#define REVISION_NR "10068"
#endif // __REVISION_NR_H__

0 comments on commit 51f93a2

Please sign in to comment.