diff options
author | megamage <none@none> | 2009-02-26 20:35:40 -0600 |
---|---|---|
committer | megamage <none@none> | 2009-02-26 20:35:40 -0600 |
commit | 85d5d94e71e4ad2b49889253da1c2b1679050541 (patch) | |
tree | 023c5bec611c75779ee5e4876c265febf749991f /src/game/Unit.cpp | |
parent | 0f9238ecb1f0706320d71fd658aa6029a49fa6a9 (diff) |
[7333] Refactoring DestinationHolder/Traveler/Unit::SendMonsterMoveWithSpeed code. Author: VladimirMangos
* Move common code in appropriate functions.
* Correct select speed and 2D/3D distance for creature/player walk/fly
--HG--
branch : trunk
Diffstat (limited to 'src/game/Unit.cpp')
-rw-r--r-- | src/game/Unit.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 92bf97e9e02..b31eab7572c 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -47,6 +47,7 @@ #include "CellImpl.h" #include "Path.h" #include "CreatureGroups.h" +#include "Traveller.h" #include <math.h> @@ -276,28 +277,23 @@ void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player* player) { float x, y, z; if(GetMotionMaster()->GetDestination(x, y, z)) - SendMonsterMoveWithSpeed(x, y, z, GetUnitMovementFlags(), 0, player); + SendMonsterMoveWithSpeed(x, y, z, 0, player); } -void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime, Player* player) +void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime, Player* player) { if (!transitTime) { - float dx = x - GetPositionX(); - float dy = y - GetPositionY(); - float dz = z - GetPositionZ(); - - float dist = ((dx*dx) + (dy*dy) + (dz*dz)); - if(dist<0) - dist = 0; + if(GetTypeId()==TYPEID_PLAYER) + { + Traveller<Player> traveller(*(Player*)this); + transitTime = traveller.GetTotalTrevelTimeTo(x,y,z); + } else - dist = sqrt(dist); - - double speed = GetSpeed((MovementFlags & MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); - if(speed<=0) - speed = 2.5f; - speed *= 0.001f; - transitTime = static_cast<uint32>(dist / speed + 0.5); + { + Traveller<Creature> traveller(*(Creature*)this); + transitTime = traveller.GetTotalTrevelTimeTo(x,y,z); + } } //float orientation = (float)atan2((double)dy, (double)dx); SendMonsterMove(x, y, z, transitTime, player); |