From cf2c8c39e231e9f0fe644da7bc8edf2fcf301832 Mon Sep 17 00:00:00 2001 From: Neo2003 Date: Sun, 7 Dec 2008 00:26:07 +0100 Subject: [PATCH] Make flying creatures fall on ground when killed. Fix also fly speed computation for creatures. Signed-off-by: Neo2003 --- src/game/Creature.cpp | 30 ++++++++++++++++++++++++++++++ src/game/Creature.h | 1 + src/game/Traveller.h | 7 ++++++- src/game/Unit.h | 3 ++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 00aed3c0e..5a1a80f2e 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -446,6 +446,11 @@ void Creature::Update(uint32 diff) m_regenTimer = 2000; break; } + case DEAD_FALLING: + { + if (!FallGround()) + setDeathState(JUST_DIED); + } default: break; } @@ -1487,6 +1492,9 @@ void Creature::setDeathState(DeathState s) if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY) || isWorldBoss()) SaveRespawnTime(); + if (canFly() && FallGround()) + return; + if(!IsStopped()) StopMoving(); } @@ -1501,6 +1509,9 @@ void Creature::setDeathState(DeathState s) if ( LootTemplates_Skinning.HaveLootFor(GetCreatureInfo()->SkinLootId) ) SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); + if (canFly() && FallGround()) + return; + Unit::setDeathState(CORPSE); } if(s == JUST_ALIVED) @@ -1520,6 +1531,25 @@ void Creature::setDeathState(DeathState s) } } +bool Creature::FallGround() +{ + // Let's abort after we called this function one time + if (getDeathState() == DEAD_FALLING) + return false; + + // Let's do with no vmap because no way to get far distance with vmap high call + float tz = GetMap()->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), false); + + // Abort too if the ground is very near + if (fabs(GetPositionZ() - tz) < 0.1f) + return false; + + Unit::setDeathState(DEAD_FALLING); + GetMotionMaster()->MovePoint(0, GetPositionX(), GetPositionY(), tz); + Relocate(GetPositionX(), GetPositionY(), tz); + return true; +} + void Creature::Respawn() { RemoveCorpse(); diff --git a/src/game/Creature.h b/src/game/Creature.h index 98f54017e..3c7825706 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -521,6 +521,7 @@ class MANGOS_DLL_SPEC Creature : public Unit const char* GetNameForLocaleIdx(int32 locale_idx) const; void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState + bool FallGround(); bool LoadFromDB(uint32 guid, Map *map); void SaveToDB(); diff --git a/src/game/Traveller.h b/src/game/Traveller.h index 1d50d488a..9256b9162 100644 --- a/src/game/Traveller.h +++ b/src/game/Traveller.h @@ -59,7 +59,12 @@ struct MANGOS_DLL_DECL Traveller template<> inline float Traveller::Speed() { - return i_traveller.GetSpeed( i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); + if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE)) + return i_traveller.GetSpeed(MOVE_WALK); + else if(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_FLYING2)) + return i_traveller.GetSpeed(MOVE_FLY); + else + return i_traveller.GetSpeed(MOVE_RUN); } template<> diff --git a/src/game/Unit.h b/src/game/Unit.h index 298023665..e4df75950 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -339,7 +339,8 @@ enum DeathState JUST_DIED = 1, CORPSE = 2, DEAD = 3, - JUST_ALIVED = 4 + JUST_ALIVED = 4, + DEAD_FALLING= 5 }; enum UnitState -- 2.11.4.GIT