mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +00:00
[9110] Some cosmetic cleanup in random movement code.
Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
parent
9ad15e8da2
commit
644cdf70d3
2 changed files with 36 additions and 26 deletions
|
|
@ -59,32 +59,42 @@ RandomMovementGenerator<Creature>::_setRandomLocation(Creature &creature)
|
||||||
nz = Z + distanceZ;
|
nz = Z + distanceZ;
|
||||||
float tz = map->GetHeight(nx, ny, nz-2.0f, false); // Map check only, vmap needed here but need to alter vmaps checks for height.
|
float tz = map->GetHeight(nx, ny, nz-2.0f, false); // Map check only, vmap needed here but need to alter vmaps checks for height.
|
||||||
float wz = map->GetWaterLevel(nx, ny);
|
float wz = map->GetWaterLevel(nx, ny);
|
||||||
|
|
||||||
|
// Problem here, we must fly above the ground and water, not under. Let's try on next tick
|
||||||
if (tz >= nz || wz >= nz)
|
if (tz >= nz || wz >= nz)
|
||||||
return; // Problem here, we must fly above the ground and water, not under. Let's try on next tick
|
return;
|
||||||
}
|
}
|
||||||
//else if (is_water_ok) // 3D system under water and above ground (swimming mode)
|
//else if (is_water_ok) // 3D system under water and above ground (swimming mode)
|
||||||
else // 2D only
|
else // 2D only
|
||||||
{
|
{
|
||||||
dist = dist >= 100.0f ? 10.0f : sqrtf(dist); // 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE)
|
dist = dist >= 100.0f ? 10.0f : sqrtf(dist); // 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE)
|
||||||
|
|
||||||
// The fastest way to get an accurate result 90% of the time.
|
// The fastest way to get an accurate result 90% of the time.
|
||||||
// Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
|
// Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
|
||||||
nz = map->GetHeight(nx,ny,Z+dist-2.0f,false); // Map check
|
nz = map->GetHeight(nx, ny, Z+dist-2.0f, false);
|
||||||
if (fabs(nz-Z)>dist)
|
|
||||||
|
if (fabs(nz-Z) > dist) // Map check
|
||||||
{
|
{
|
||||||
nz = map->GetHeight(nx, ny, Z-2.0f, true); // Vmap Horizontal or above
|
nz = map->GetHeight(nx, ny, Z-2.0f, true); // Vmap Horizontal or above
|
||||||
|
|
||||||
if (fabs(nz-Z) > dist)
|
if (fabs(nz-Z) > dist)
|
||||||
{
|
{
|
||||||
nz = map->GetHeight(nx,ny,Z+dist-2.0f,true); // Vmap Higher
|
// Vmap Higher
|
||||||
|
nz = map->GetHeight(nx, ny, Z+dist-2.0f, true);
|
||||||
|
|
||||||
|
// let's forget this bad coords where a z cannot be find and retry at next tick
|
||||||
if (fabs(nz-Z) > dist)
|
if (fabs(nz-Z) > dist)
|
||||||
return; // let's forget this bad coords where a z cannot be find and retry at next tick
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Traveller<Creature> traveller(creature);
|
Traveller<Creature> traveller(creature);
|
||||||
|
|
||||||
creature.SetOrientation(creature.GetAngle(nx, ny));
|
creature.SetOrientation(creature.GetAngle(nx, ny));
|
||||||
i_destinationHolder.SetDestination(traveller, nx, ny, nz);
|
i_destinationHolder.SetDestination(traveller, nx, ny, nz);
|
||||||
creature.addUnitState(UNIT_STAT_ROAMING);
|
creature.addUnitState(UNIT_STAT_ROAMING);
|
||||||
|
|
||||||
if (is_air_ok)
|
if (is_air_ok)
|
||||||
{
|
{
|
||||||
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "9109"
|
#define REVISION_NR "9110"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue