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; m_regenTimer = 2000;
break; break;
} }
case DEAD_FALLING:
{
if (!FallGround())
setDeathState(JUST_DIED);
}
default: default:
break; break;
} }
@ -1487,6 +1492,9 @@ void Creature::setDeathState(DeathState s)
if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY) || isWorldBoss()) if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY) || isWorldBoss())
SaveRespawnTime(); SaveRespawnTime();
if (canFly() && FallGround())
return;
if(!IsStopped()) if(!IsStopped())
StopMoving(); StopMoving();
} }
@ -1501,6 +1509,9 @@ void Creature::setDeathState(DeathState s)
if ( LootTemplates_Skinning.HaveLootFor(GetCreatureInfo()->SkinLootId) ) if ( LootTemplates_Skinning.HaveLootFor(GetCreatureInfo()->SkinLootId) )
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
if (canFly() && FallGround())
return;
Unit::setDeathState(CORPSE); Unit::setDeathState(CORPSE);
} }
if(s == JUST_ALIVED) 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() void Creature::Respawn()
{ {
RemoveCorpse(); RemoveCorpse();

View file

@ -521,6 +521,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
const char* GetNameForLocaleIdx(int32 locale_idx) const; const char* GetNameForLocaleIdx(int32 locale_idx) const;
void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState
bool FallGround();
bool LoadFromDB(uint32 guid, Map *map); bool LoadFromDB(uint32 guid, Map *map);
void SaveToDB(); void SaveToDB();

View file

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

View file

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