[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
This commit is contained in:
megamage
2009-02-26 20:35:40 -06:00
parent 0f9238ecb1
commit 85d5d94e71
9 changed files with 71 additions and 43 deletions
+1 -18
View File
@@ -85,24 +85,7 @@ DestinationHolder<TRAVELLER>::StartTravel(TRAVELLER &traveller, bool sendMove)
i_fromY = traveller.GetPositionY();
i_fromZ = traveller.GetPositionZ();
float dx = i_destX - i_fromX;
float dy = i_destY - i_fromY;
float dz = i_destZ - i_fromZ;
float dist;
//Should be for Creature Flying and Swimming.
if(traveller.GetTraveller().hasUnitState(UNIT_STAT_IN_FLIGHT))
dist = sqrt((dx*dx) + (dy*dy) + (dz*dz));
else //Walking on the ground
dist = sqrt((dx*dx) + (dy*dy));
float speed;
if(traveller.GetTraveller().hasUnitState(UNIT_STAT_CHARGING))
speed = SPEED_CHARGE * 0.001f;
else
speed = traveller.Speed() * 0.001f; // speed is in seconds so convert from second to millisecond
i_totalTravelTime = static_cast<uint32>(dist/speed);
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);