37 lines
1.5 KiB
C++
37 lines
1.5 KiB
C++
#ifndef VCORE_ADVENTURE_GROUP_TRAVEL_POLICY_H
|
|
#define VCORE_ADVENTURE_GROUP_TRAVEL_POLICY_H
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
namespace AdventureGroupTravelPolicy
|
|
{
|
|
constexpr unsigned SampleMs = 500;
|
|
constexpr float SeparationDistance = 500;
|
|
constexpr unsigned SeparationTimeoutMs = 600000;
|
|
constexpr float GroundLeaderHeight = 12;
|
|
constexpr float MaxGroundStep = 1.75f;
|
|
constexpr float MaxGroundSlope = 0.8f;
|
|
struct Offset { float Behind, Side, Height; };
|
|
inline Offset Formation(unsigned slot, unsigned columns, bool moving, bool mounted, bool flying)
|
|
{
|
|
columns = std::clamp(columns, 1u, 3u);
|
|
float spacing = flying ? 7.0f : mounted ? 4.5f : 3.0f;
|
|
if (!moving && !flying) columns = std::min(columns, 3u);
|
|
unsigned row = slot / columns;
|
|
float side = (float(slot % columns) - float(columns - 1) / 2) * spacing;
|
|
return {spacing + float(row) * spacing, side, flying ? float(slot % 2) * 2 : 0};
|
|
}
|
|
inline unsigned Separation(unsigned elapsed, unsigned diff, bool far, bool protectedTravel)
|
|
{
|
|
if (!far) return 0;
|
|
if (protectedTravel) return elapsed;
|
|
return std::min(SeparationTimeoutMs, elapsed + std::min(diff, 30000u));
|
|
}
|
|
inline bool GroundSample(float expected, float actual, float previous, float distance)
|
|
{
|
|
return std::isfinite(actual) && std::fabs(actual - expected) <= MaxGroundStep &&
|
|
std::fabs(actual - previous) <= MaxGroundStep + MaxGroundSlope * distance;
|
|
}
|
|
}
|
|
#endif
|