feat(wildlife): 17.5 - an animal walks by the world's way where it has one: WildlifeWorld.way (the next corner toward where it is going, asked every half second or on reaching it) steers wandering and going to water or forage, and goal (a spot it can reach) is a wander's target, seeded by the same two draws so the dice do not move; the defaults are the straight line and the old target. way_test: round a wall by its corners, and a wander's target where the world says

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 21:51:35 +03:00
parent 537d3a0ab3
commit 4add35b4ca
9 changed files with 168 additions and 10 deletions

View file

@ -0,0 +1,36 @@
# way.ludic - where an animal walks: by the world's path to where it is going (WildlifeWorld.way, a
# navmesh by its habitat's taste in Maroon Lake), to a target about home it can reach (goal), and
# straight, as before, where the world has no answer
# face the way toward (tx, tz): the next corner of the world's path for it, asked again every
# WL_WAY_EVERY seconds or on reaching the corner; without a path, the straight line as before
const WL_WAY_EVERY: float = 0.5
function wl_head(a: WildAnimal, tx: float, tz: float, rate: float, dt: float) -> void {
a.way_t = a.way_t - dt
let cx = a.wx - a.x
let cz = a.wz - a.z
if a.way_t <= 0.0 or cx * cx + cz * cz < 1.0 {
a.way_t = WL_WAY_EVERY
a.wx = tx
a.wz = tz
if WildlifeWorld.way(a, tx, tz) {
a.wx = WildlifeWorld.way_x()
a.wz = WildlifeWorld.way_z()
}
}
wl_face(a, a.wx, a.wz, rate, dt)
}
# somewhere about home: a spot the world says it can walk to when it knows, seeded by the same two
# draws the old target took, so the dice are the same whether it knows or not
function wl_pick_target(wildlife_st: 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
a.way_t = 0.0
if WildlifeWorld.goal(a, a.home_x, a.home_z, radius, int(ang * 100000.0) + int(d * 1000.0)) {
a.tx = WildlifeWorld.way_x()
a.tz = WildlifeWorld.way_z()
}
}