ludic/packages/ludic.wildlife/steer.ludic
Orkuncakilkaya 56e4b6d688 feat(senses): walkers slide round still things, and lines of sight are the world's to answer
- ludic.wildlife: WildlifeWorld.push / pushed_x / pushed_z (defaults change nothing); a ground
  walker's step is slid clear of a still thing with a body from its species' size and scale, and
  a step that gets nowhere turns away as the water does. Birds are not pushed; no dice added.
- ludic.npc: NpcWorld.push / pushed_x / pushed_z (a person 0.35 m round) in npc_walk, and
  NpcWorld.clear (default true), which npc_line_ok asks at 1 m so a detour does not cut a trunk.
- ludic.aim: AimView.clear replaces AimView.ground and the ground march; the pick asks the line
  a body's width short of where the ray enters the thing (aim_clear_at(t, back)), so a solid
  thing does not hide itself. probe.ludic (the ground-agreement probe) and AimView.dry are gone.
- ludic.photo: PhotoLens.clear replaces PhotoLens.ground, PhotoLens.trunk and the march.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 00:59:39 +03:00

86 lines
2.9 KiB
Text

# steer.ludic - turning toward a point at a rate, a step along the facing that turns away from water
# and a climb, and a target somewhere about home; a walker leaves a print every 2.8 m
function wl_wrap(a: float) -> float {
var r = a
while r > 3.1415927 { r = r - WL_TAU }
while r < -3.1415927 { r = r + WL_TAU }
return r
}
function wl_face(a: WildAnimal, tx: float, tz: float, rate: float, dt: float) -> void {
let want = Math.atan2(-(tx - a.x), -(tz - a.z))
let r = rate * dt
a.yaw = a.yaw + Math.clamp(wl_wrap(want - a.yaw), -r, r)
}
# true when it moved; a walker is slid round a still thing (a trunk, a tent), a bird is not
function wl_step(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float) -> bool {
let d = a.speed * dt
if d < 0.0001 { return false }
var nx = a.x - Math.sin(a.yaw) * d
var nz = a.z - Math.cos(a.yaw) * d
let s = wl_sp(wildlife_st, a.sp)
if not s.flies and wl_push(wildlife_st, a, s, nx, nz) {
nx = wildlife_st.wl_out_x
nz = wildlife_st.wl_out_z
}
let nh = WildlifeWorld.ground(nx, nz)
let moved = Math.abs(nx - a.x) + Math.abs(nz - a.z)
if nh < WildlifeWorld.water(nx, nz) + 0.6 or nh - a.y > d * 1.2 or moved < d * 0.2 {
a.yaw = a.yaw + Math.deg_to_rad(75.0)
a.timer = 0.0
return false
}
a.x = nx
a.z = nz
a.y = nh
a.track_d = a.track_d + d
if s.tracks and a.track_d > 2.8 {
a.track_d = 0.0
wl_fact(wildlife_st, WILD_PRINT, a)
}
return true
}
# (x, z) pushed clear of every still thing for a body its size; wl_out_x / _z say where
function wl_push(wildlife_st: mut WildlifeState, a: WildAnimal, s: WildSpecies, x: float, z: float) -> bool {
wildlife_st.wl_ask_x = x
wildlife_st.wl_ask_z = z
let k = Math.clamp(float(s.size), 0.0, 2.0)
let r = (0.2 + 0.2 * k) * s.scale * a.scale
let hit = WildlifeWorld.push(x, z, r, a.y + 0.1, a.y + (0.5 + 0.7 * k) * s.scale * a.scale)
wildlife_st.wl_out_x = x
wildlife_st.wl_out_z = z
if hit {
wildlife_st.wl_out_x = WildlifeWorld.pushed_x()
wildlife_st.wl_out_z = WildlifeWorld.pushed_z()
}
return hit
}
function wl_pick_target(wildlife_st: mut WildlifeState, a: WildAnimal, radius: float) -> void {
let ang = wl_rnd(wildlife_st) * WL_TAU
let d = wl_rnd(wildlife_st) * radius
a.tx = a.home_x + Math.cos(ang) * d
a.tz = a.home_z + Math.sin(ang) * d
}
function wl_at_target(a: WildAnimal, r: float) -> bool {
let dx = a.tx - a.x
let dz = a.tz - a.z
return dx * dx + dz * dz < r * r
}
# back to wandering about home after `t` seconds of whatever it was doing
function wl_wander(wildlife_st: mut WildlifeState, a: WildAnimal, t: float) -> void {
a.state = WILD_WANDER
a.timer = t
wl_pick_target(wildlife_st, a, wl_sp(wildlife_st, a.sp).home)
}
# home where it stands now, kept inside its range
function wl_rehome(wildlife_st: mut WildlifeState, a: WildAnimal) -> void {
a.home_x = a.x
a.home_z = a.z
wl_clamp(wildlife_st, a)
}