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>
This commit is contained in:
parent
d2cd775309
commit
56e4b6d688
24 changed files with 230 additions and 152 deletions
|
|
@ -31,6 +31,7 @@ export port WildlifeWorld { # every member has a default: a flat dry mead
|
|||
ground, water, slope: fn(float, float) -> float # the ground, the water's surface, the gradient
|
||||
forest: fn(float, float) -> bool
|
||||
sight: fn(ax, ay, az, bx, by, bz) -> bool # nothing between the two points
|
||||
push: fn(x, z, r, feet, head) -> bool, pushed_x, pushed_z # a walker slid clear of still things
|
||||
players: fn() -> int # slots; player_on(p), player_x / _y / _z(p)
|
||||
hidden, noise, scent, stillness # per player: in a hide, 0..1, 0..1, WILD_MOVING / _STILL / _SITTING
|
||||
hour, light, winterness, wind, wind_dir: fn() -> float # the clock, how well it sees now, the season, the weather
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ export port WildlifeWorld {
|
|||
slope: fn(float, float) -> float = fn wl_zero2
|
||||
forest: fn(float, float) -> bool = fn wl_no2
|
||||
sight: fn(float, float, float, float, float, float) -> bool = fn wl_clear # nothing between
|
||||
# (x, z, r, feet, head): true when a still thing takes a body of radius r there; pushed_x / _z say where
|
||||
push: fn(float, float, float, float, float) -> bool = fn wl_no_push
|
||||
pushed_x: fn() -> float = fn wl_asked_x
|
||||
pushed_z: fn() -> float = fn wl_asked_z
|
||||
players: fn() -> int = fn wl_one # player slots
|
||||
player_on: fn(int) -> bool = fn wl_first
|
||||
player_x: fn(int) -> float = fn wl_zero1
|
||||
|
|
@ -52,6 +56,9 @@ function wl_no1(p: int) -> bool { return false }
|
|||
function wl_no2(x: float, z: float) -> bool { return false }
|
||||
function wl_yes1(u: int) -> bool { return true }
|
||||
function wl_clear(ax: float, ay: float, az: float, bx: float, by: float, bz: float) -> bool { return true }
|
||||
function wl_no_push(x: float, z: float, r: float, y0: float, y1: float) -> bool { return false }
|
||||
function wl_asked_x(wildlife_st: WildlifeState) -> float { return wildlife_st.wl_ask_x }
|
||||
function wl_asked_z(wildlife_st: WildlifeState) -> float { return wildlife_st.wl_ask_z }
|
||||
function wl_one() -> int { return 1 }
|
||||
function wl_none0() -> int { return 0 }
|
||||
function wl_first(p: int) -> bool { return p == 0 }
|
||||
|
|
|
|||
|
|
@ -42,6 +42,10 @@ export state WildlifeState {
|
|||
wl_seed_any: bool = false
|
||||
wl_seed_t: float = 0.0
|
||||
wl_ids: int = 0
|
||||
wl_ask_x: float = 0.0 # the point last handed to WildlifeWorld.push, and where it came out
|
||||
wl_ask_z: float = 0.0
|
||||
wl_out_x: float = 0.0
|
||||
wl_out_z: float = 0.0
|
||||
wl_ranges: []WildRange = null
|
||||
wl_found: []int = null # found flags a load brought before the ranges were set out
|
||||
wl_seen: int = 0
|
||||
|
|
|
|||
|
|
@ -13,14 +13,20 @@ function wl_face(a: WildAnimal, tx: float, tz: float, rate: float, dt: float) ->
|
|||
a.yaw = a.yaw + Math.clamp(wl_wrap(want - a.yaw), -r, r)
|
||||
}
|
||||
|
||||
# true when it moved
|
||||
# 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 }
|
||||
let nx = a.x - Math.sin(a.yaw) * d
|
||||
let nz = a.z - Math.cos(a.yaw) * d
|
||||
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)
|
||||
if nh < WildlifeWorld.water(nx, nz) + 0.6 or nh - a.y > d * 1.2 {
|
||||
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
|
||||
|
|
@ -29,13 +35,29 @@ function wl_step(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float) -> bo
|
|||
a.z = nz
|
||||
a.y = nh
|
||||
a.track_d = a.track_d + d
|
||||
if wl_sp(wildlife_st, a.sp).tracks and a.track_d > 2.8 {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ export state WildlifeTestsFakeState {
|
|||
fk_born: int = 0
|
||||
fk_lures: []WildLure = null
|
||||
fk_gone: int = 0 # a uid the port says is no longer there
|
||||
fk_trunk: bool = false # a trunk 1 m round at (0.3, -20)
|
||||
fk_out_x: float = 0.0
|
||||
fk_out_z: float = 0.0
|
||||
}
|
||||
|
||||
function fk_setup(wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) -> void {
|
||||
|
|
@ -27,6 +30,7 @@ function fk_setup(wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut Wi
|
|||
wildlife_tests_fake_st.fk_px[0] = 5000.0
|
||||
wildlife_tests_fake_st.fk_pz[0] = 5000.0
|
||||
wildlife_tests_fake_st.fk_lures = new []WildLure
|
||||
wildlife_tests_fake_st.fk_trunk = false
|
||||
wildlife_clear(wildlife_st)
|
||||
wildlife_species_clear(wildlife_st)
|
||||
fk_species(wildlife_st)
|
||||
|
|
@ -108,3 +112,16 @@ function fk_spot(a: WildAnimal, water: bool, s: WildSpot) -> bool {
|
|||
s.water = water
|
||||
return true
|
||||
}
|
||||
|
||||
# the trunk, when it stands: a body inside it is pushed straight out from its axis
|
||||
function fk_push(wildlife_tests_fake_st: mut WildlifeTestsFakeState, x: float, z: float, r: float, y0: float, y1: float) -> bool {
|
||||
let dx = x - 0.3
|
||||
let dz = z + 20.0
|
||||
let d = Math.sqrt(dx * dx + dz * dz)
|
||||
if not wildlife_tests_fake_st.fk_trunk or d > 1.0 + r or d < 0.0001 { return false }
|
||||
wildlife_tests_fake_st.fk_out_x = 0.3 + dx / d * (1.0 + r)
|
||||
wildlife_tests_fake_st.fk_out_z = -20.0 + dz / d * (1.0 + r)
|
||||
return true
|
||||
}
|
||||
function fk_pushed_x(wildlife_tests_fake_st: WildlifeTestsFakeState) -> float { return wildlife_tests_fake_st.fk_out_x }
|
||||
function fk_pushed_z(wildlife_tests_fake_st: WildlifeTestsFakeState) -> float { return wildlife_tests_fake_st.fk_out_z }
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ program WildlifeTest {
|
|||
water: fn fk_water
|
||||
forest: fn fk_forest
|
||||
sight: fn fk_sight
|
||||
push: fn fk_push
|
||||
pushed_x: fn fk_pushed_x
|
||||
pushed_z: fn fk_pushed_z
|
||||
players: fn fk_players
|
||||
player_on: fn fk_player_on
|
||||
player_x: fn fk_x
|
||||
|
|
@ -177,6 +180,25 @@ program WildlifeTest {
|
|||
expect(wildlife_seen(wildlife_st, 0))
|
||||
}
|
||||
|
||||
test "a walker slides round a trunk rather than through it" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
|
||||
fk_setup(wildlife_st, wildlife_tests_fake_st)
|
||||
let a = deer_at(wildlife_st, 0.0, 0.0)
|
||||
wildlife_tests_fake_st.fk_trunk = true
|
||||
player_at(wildlife_tests_fake_st, 60.0, 0.0)
|
||||
wildlife_tests_fake_st.fk_blocked = true
|
||||
a.state = WILD_WANDER
|
||||
a.tx = 0.0
|
||||
a.tz = -100.0
|
||||
a.timer = 100.0
|
||||
var closest = 100.0
|
||||
for k in 0 .. 800 {
|
||||
wildlife_tick(wildlife_st, 0.05, 0.0)
|
||||
closest = Math.min(closest, Math.sqrt((a.x - 0.3) * (a.x - 0.3) + (a.z + 20.0) * (a.z + 20.0)))
|
||||
}
|
||||
expect(closest > 1.35)
|
||||
expect(a.z < -25.0)
|
||||
}
|
||||
|
||||
test "the record and the found ranges come back from the save section" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
|
||||
fk_setup(wildlife_st, wildlife_tests_fake_st)
|
||||
wildlife_spawn(wildlife_st, 0.0, 0.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue