merge lang/physics-senses: animals and people slide round still things, the aim's, photo's and animals' sight lines are one Jolt ray
Conflicts with 0.R5's state defaults in ludic.wildlife resolved; wl_step writes the push's answer, so its callers take WildlifeState mut again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ac815bf638
28 changed files with 236 additions and 158 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
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ function wl_take_off(wildlife_st: WildlifeState, a: WildAnimal, h: float) -> voi
|
|||
a.fly_h = Math.max(a.fly_h, h)
|
||||
}
|
||||
|
||||
function wl_land(wildlife_st: WildlifeState, a: WildAnimal, dh: float, dt: float) -> void {
|
||||
function wl_land(wildlife_st: mut WildlifeState, a: WildAnimal, dh: float, dt: float) -> void {
|
||||
let s = wl_sp(wildlife_st, a.sp)
|
||||
a.fly_h = Math.max(0.0, a.fly_h - dt * 3.2)
|
||||
a.speed = s.walk * 0.8
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export function wildlife_tick_ground(wildlife_st: mut WildlifeState, a: WildAnim
|
|||
}
|
||||
|
||||
# a charger close enough comes at the nearest player; true while it is charging
|
||||
function wl_charge(wildlife_st: WildlifeState, a: WildAnimal, np: int, dh: float, dt: float) -> bool {
|
||||
function wl_charge(wildlife_st: mut WildlifeState, a: WildAnimal, np: int, dh: float, dt: float) -> bool {
|
||||
let s = wl_sp(wildlife_st, a.sp)
|
||||
if s.charges and a.state != WILD_CHARGE and dh < WildlifeWorld.charge_reach() and not (a.calm > 0.0) {
|
||||
a.state = WILD_CHARGE
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# react.ludic - alert (it stops and looks: the window the camera wants), wary (it puts ground between
|
||||
# you without running) and fleeing; true when it is doing one of them, which is all it does this tick
|
||||
function wl_react(wildlife_st: WildlifeState, a: WildAnimal, np: int, dt: float) -> bool {
|
||||
function wl_react(wildlife_st: mut WildlifeState, a: WildAnimal, np: int, dt: float) -> bool {
|
||||
let s = wl_sp(wildlife_st, a.sp)
|
||||
if a.state == WILD_ALERT {
|
||||
a.speed = 0.0
|
||||
|
|
@ -29,7 +29,7 @@ function wl_react(wildlife_st: WildlifeState, a: WildAnimal, np: int, dt: float)
|
|||
}
|
||||
|
||||
# walking to (or reached) something set out; true while it is
|
||||
function wl_approach(wildlife_st: WildlifeState, a: WildAnimal, dt: float) -> bool {
|
||||
function wl_approach(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float) -> bool {
|
||||
if (a.state == WILD_IDLE or a.state == WILD_WANDER) and wl_attraction(wildlife_st, a) { wl_take_lure(wildlife_st, a) }
|
||||
if a.state != WILD_APPROACH { return false }
|
||||
if a.lure == 0 or not WildlifeWorld.present(a.lure) {
|
||||
|
|
|
|||
|
|
@ -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 = new []WildRange
|
||||
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
|
||||
function wl_step(wildlife_st: WildlifeState, a: WildAnimal, dt: float) -> bool {
|
||||
# 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: WildlifeState, a: WildAnimal, dt: float) -> bool {
|
|||
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: 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)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# want.ludic - thirst and hunger over sixty send it to the water or the forage the game offers for
|
||||
# it (a hungry one on its way turns to food put down nearer); it drinks or grazes there
|
||||
|
||||
function wl_seek(wildlife_st: WildlifeState, a: WildAnimal, dt: float) -> bool {
|
||||
function wl_seek(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float) -> bool {
|
||||
if a.state == WILD_GO_FEED and wl_attraction(wildlife_st, a) and wildlife_st.wl_best.kind == WILD_FEED { wl_take_lure(wildlife_st, a) }
|
||||
if a.state != WILD_GO_DRINK and a.state != WILD_GO_FEED { return false }
|
||||
if a.spot == 0 or not WildlifeWorld.present(a.spot) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue