Make flying creatures fall on ground when killed.

Fix also fly speed computation for creatures.

Signed-off-by: Neo2003 <neo.2003@hotmail.fr>
This commit is contained in:
Neo2003 2008-12-07 00:26:07 +01:00
parent 8eccdbc046
commit 211f987aa9
4 changed files with 39 additions and 2 deletions

View file

@ -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();

View file

@ -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();

View file

@ -59,7 +59,12 @@ struct MANGOS_DLL_DECL Traveller
template<>
inline float Traveller<Creature>::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<>

View file

@ -339,7 +339,8 @@ enum DeathState
JUST_DIED = 1,
CORPSE = 2,
DEAD = 3,
JUST_ALIVED = 4
JUST_ALIVED = 4,
DEAD_FALLING= 5
};
enum UnitState