ludic/packages/ludic.wildlife/run.ludic
Orkuncakilkaya 5ac3d488a4 wip(ecs): ludic.wildlife on a Table<WildAnimal> - UNBUILT
Written while builds are held (agents share 16 GB; no build or run until the user lifts it), so
it has not been compiled or tested. The animals are rows of a ludic.base Table: x, z, species and
alive as columns, a 32 m grid over the living, the living by species, and a nid map.
wildlife_by_nid is a map lookup instead of a scan of every animal ever made, wildlife_count walks
only its species, wildlife_nearest asks the grid, wildlife_set_alive writes the flag and the row
together, and wildlife_refile files the tick's moves once after it (wildlife_verify holds the
columns to the records). A guest puts its whole table away and brings it back. A test case covers
them; to run once builds are allowed: ludic test packages/ludic.wildlife.

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

59 lines
2.2 KiB
Text

# run.ludic - one step of every animal: the port says whether it is about at this hour; anything
# within 900 m of a player thinks; the gait follows the ground covered; player 0 sees what is near
export function wildlife_tick(wildlife_st: mut WildlifeState, dt: float, gh: float) -> void {
wl_seed_scan(wildlife_st, dt)
let all = wildlife_all(wildlife_st)
for i in 0 .. len(all) { wl_tick_one(wildlife_st, all[i], dt, gh) }
wildlife_refile(wildlife_st)
}
function wl_tick_one(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float, gh: float) -> void {
if not a.alive { return }
let about = WildlifeWorld.about(a)
if about == WILD_AWAY {
a.shown = false
return
}
if about == WILD_GONE {
wildlife_remove(a)
wl_fact(wildlife_st, WILD_WENT, a)
return
}
a.shown = true
let dh = wl_near(wildlife_st, a.x, a.z)
if dh > 900.0 { return }
let s = wl_sp(wildlife_st, a.sp)
if wildlife_st.wl_hold { }
else if a.pinned { a.speed = 0.0 }
else if s.flies { wildlife_tick_bird(wildlife_st, a, dt) } else { wildlife_tick_ground(wildlife_st, a, dt, gh) }
var stride = 1.2 * a.scale
if s.flies { stride = 0.6 }
a.phase = (a.phase + a.speed * dt / stride * WL_TAU) % WL_TAU
if WildlifeWorld.player_on(0) and wl_pdist(0, a) < 60.0 and wildlife_saw(wildlife_st, a.sp) { wl_fact(wildlife_st, WILD_SPOTTED, a) }
}
# the gait advanced by a copy the game moves itself (a guest's copy of the host's animal)
export function wildlife_stride(wildlife_st: WildlifeState, a: WildAnimal, dt: float) -> void {
var stride = 1.2 * a.scale
if wl_sp(wildlife_st, a.sp).flies { stride = 0.6 }
a.phase = (a.phase + a.speed * dt / stride * WL_TAU) % WL_TAU
}
# a snare's catch let go: it bolts, and it holds nothing against anyone
export function wildlife_release(a: WildAnimal) -> void {
if a == null { return }
a.state = WILD_FLEE
a.timer = 4.0
a.calm = 0.0
a.lure = 0
}
# the animal a snare holds, by the snare's uid
export function wildlife_in_snare(wildlife_st: WildlifeState, uid: int) -> WildAnimal {
let all = wildlife_all(wildlife_st)
for i in 0 .. len(all) {
let a = all[i]
if a.alive and a.state == WILD_TRAPPED and a.lure == uid { return a }
}
return null
}