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
|
|
@ -11,6 +11,9 @@ export state NpcTestsFakeState {
|
|||
fk_on: []bool = null
|
||||
fk_born: int = 0
|
||||
fk_gone: int = 0
|
||||
fk_trunk: bool = false # a trunk 1 m round at (10, 0.3)
|
||||
fk_out_x: float = 0.0
|
||||
fk_out_z: float = 0.0
|
||||
}
|
||||
|
||||
function fk_setup(npc_st: mut NpcState, npc_tests_fake_st: mut NpcTestsFakeState) -> void {
|
||||
|
|
@ -23,6 +26,7 @@ function fk_setup(npc_st: mut NpcState, npc_tests_fake_st: mut NpcTestsFakeState
|
|||
npc_tests_fake_st.fk_on = [true, false]
|
||||
npc_tests_fake_st.fk_born = 0
|
||||
npc_tests_fake_st.fk_gone = 0
|
||||
npc_tests_fake_st.fk_trunk = false
|
||||
npc_clear(npc_st)
|
||||
npc_reset(npc_st)
|
||||
npc_seed(npc_st, 7)
|
||||
|
|
@ -61,3 +65,22 @@ function fk_count(npc_st: NpcState, what: int) -> int {
|
|||
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }
|
||||
return n
|
||||
}
|
||||
|
||||
# the trunk, when it stands: a body inside it is pushed straight out from its axis, and a line
|
||||
# passing within its radius is not clear
|
||||
function fk_push(npc_tests_fake_st: mut NpcTestsFakeState, x: float, z: float, r: float, y0: float, y1: float) -> bool {
|
||||
let d = npc_d(x, z, 10.0, 0.3)
|
||||
if not npc_tests_fake_st.fk_trunk or d > 1.0 + r or d < 0.0001 { return false }
|
||||
npc_tests_fake_st.fk_out_x = 10.0 + (x - 10.0) / d * (1.0 + r)
|
||||
npc_tests_fake_st.fk_out_z = 0.3 + (z - 0.3) / d * (1.0 + r)
|
||||
return true
|
||||
}
|
||||
function fk_pushed_x(npc_tests_fake_st: NpcTestsFakeState) -> float { return npc_tests_fake_st.fk_out_x }
|
||||
function fk_pushed_z(npc_tests_fake_st: NpcTestsFakeState) -> float { return npc_tests_fake_st.fk_out_z }
|
||||
function fk_clear(npc_tests_fake_st: NpcTestsFakeState, ax: float, ay: float, az: float, bx: float, by: float, bz: float) -> bool {
|
||||
if not npc_tests_fake_st.fk_trunk { return true }
|
||||
let lx = bx - ax
|
||||
let lz = bz - az
|
||||
let t = Math.clamp(((10.0 - ax) * lx + (0.3 - az) * lz) / Math.max(lx * lx + lz * lz, 0.0001), 0.0, 1.0)
|
||||
return npc_d(ax + lx * t, az + lz * t, 10.0, 0.3) > 1.0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ program NpcTest {
|
|||
ground: fn fk_ground
|
||||
water: fn fk_water
|
||||
allowed: fn fk_allowed
|
||||
push: fn fk_push
|
||||
pushed_x: fn fk_pushed_x
|
||||
pushed_z: fn fk_pushed_z
|
||||
clear: fn fk_clear
|
||||
hour: fn fk_hour_now
|
||||
day: fn fk_day_now
|
||||
players: fn fk_players
|
||||
|
|
@ -95,6 +99,21 @@ program NpcTest {
|
|||
expect_near(p.fx, 30.0, 0.01)
|
||||
}
|
||||
|
||||
test "a trunk in the way is walked round, and a line through it is not a clear walk" (npc_st: mut NpcState, npc_tests_fake_st: mut NpcTestsFakeState) {
|
||||
let p = one(npc_st, npc_tests_fake_st, NPCK_HIKER)
|
||||
npc_tests_fake_st.fk_trunk = true
|
||||
expect(not npc_line_ok(0.0, 0.0, 20.0, 0.0))
|
||||
expect(npc_line_ok(0.0, 5.0, 20.0, 5.0))
|
||||
npc_go(npc_st, p, 20.0, 0.0, NPCA_SIT, 30.0)
|
||||
var closest = 100.0
|
||||
for k in 0 .. 600 {
|
||||
npc_tick(npc_st, 0.05)
|
||||
closest = Math.min(closest, npc_d(p.x, p.z, 10.0, 0.3))
|
||||
}
|
||||
expect(closest > 1.3)
|
||||
expect_eq(p.act, NPCA_SIT)
|
||||
}
|
||||
|
||||
test "nobody walks into the lake" (npc_st: mut NpcState, npc_tests_fake_st: mut NpcTestsFakeState) {
|
||||
let p = one(npc_st, npc_tests_fake_st, NPCK_HIKER)
|
||||
npc_go(npc_st, p, -80.0, 0.0, NPCA_SIT, 30.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue