49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include "World.h"
|
|
#include "Math.h"
|
|
#include "Physics.h"
|
|
#include "Pathfind.h"
|
|
|
|
namespace vf {
|
|
|
|
enum class MobState : uint8_t {
|
|
Wander = 0,
|
|
Chase = 1,
|
|
};
|
|
|
|
struct Mob {
|
|
Vec3 position; // feet centre (bottom of the collision box)
|
|
Vec3 velocity;
|
|
float width = 0.6f;
|
|
float height = 1.8f;
|
|
bool onGround = false;
|
|
MobState state = MobState::Wander;
|
|
uint32_t rng = 0x2545f491u; // deterministic wander stream
|
|
Vec3 wanderDir;
|
|
};
|
|
|
|
struct MobConfig {
|
|
float moveSpeed = 3.2f;
|
|
float gravity = 26.0f;
|
|
float maxFallSpeed = 55.0f;
|
|
float chaseRadius = 12.0f; // start chasing inside this range
|
|
float loseRadius = 16.0f; // give up chasing beyond this (hysteresis)
|
|
PathConfig path;
|
|
};
|
|
|
|
Aabb mobBox(const Mob& mob);
|
|
Vec3i mobFeetCell(const Mob& mob);
|
|
|
|
// One physics tick: applies the horizontal wish direction and gravity, then
|
|
// resolves AABB collisions against solid voxels axis by axis (move and slide).
|
|
void stepMob(const World& world, Mob& mob, const Vec3& wishDir, const MobConfig& config, float dt);
|
|
|
|
// State machine driving the mob. Chases when the target is within range and a
|
|
// path exists, otherwise wanders. Updates mob.state and returns the horizontal
|
|
// wish direction to hand to stepMob.
|
|
Vec3 updateMobBrain(const World& world, Mob& mob, const Vec3& targetPos, const MobConfig& config);
|
|
|
|
} // namespace vf
|