feat(packages): ludic.wildlife - a valley's animals: species handed in as data, ranges placed against the ground and moved with the season, the day's steering, the senses and a net alert that settles, feeding, lures and snares, birds, spawning and repopulation, its own dice, facts and a save section

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 06:54:58 +03:00
parent 80f3468ff8
commit c9dc592dcc
28 changed files with 1956 additions and 0 deletions

View file

@ -0,0 +1,211 @@
# wildlife_test.ludic - species as data, a valley spawned against its ground, the alert (where it
# SETTLES, not only how it rises), cover, stillness and wind, the charge, the hours, prints and the save
import "ludic.wildlife"
import "ludic.base"
import "fake"
program WildlifeTest {
numbers float
bind WildlifeWorld {
ground: fn fk_ground
water: fn fk_water
forest: fn fk_forest
sight: fn fk_sight
players: fn fk_players
player_on: fn fk_player_on
player_x: fn fk_x
player_y: fn fk_y
player_z: fn fk_z
hidden: fn fk_is_hidden
noise: fn fk_noise_of
scent: fn fk_scent_of
stillness: fn fk_still_of
wind: fn fk_wind_of
wind_dir: fn fk_wind_to
winterness: fn fk_winter_of
about: fn fk_about_of
per_range: fn fk_one
lures: fn fk_count
lure: fn fk_lure
present: fn fk_present
born: fn fk_on_born
spot: fn fk_spot
}
function facts() -> []WildFact { return q_drain(wildlife_facts()) }
function count(fs: []WildFact, what: int) -> int {
var n = 0
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }
return n
}
function deer_at(x: float, z: float) -> WildAnimal {
let a = wildlife_make(0, x, z, false, 0.0, 0, 1.0, 1)
a.state = WILD_IDLE
a.timer = 30.0
return a
}
function player_at(x: float, z: float) -> void {
fk_px[0] = x
fk_pz[0] = z
}
function go(a: WildAnimal, secs: float) -> void {
for k in 0 .. int(secs * 20.0) { wildlife_tick_ground(a, 0.05, 0.05 / 60.0) }
}
test "the table handed in numbers the species, and a new animal is born through the port" {
fk_setup()
expect_eq(wildlife_species_count(), 4)
expect(wildlife_species(3).flies)
let a = wildlife_new(0, 10.0, 20.0, false)
expect_eq(fk_born, 1)
expect_near(a.y, 10.0, 0.001)
expect(a.variant >= 0 and a.variant <= 11)
expect(a.scale > 0.87 and a.scale < 1.13)
let j = wildlife_new(3, 0.0, 0.0, false)
expect_eq(j.state, WILD_FLY)
expect(wildlife_new(9, 0.0, 0.0, false) == null)
}
test "a spawn sets ranges out on their own habitat, clear of the start, and fills them" {
fk_setup()
wildlife_spawn(0.0, 0.0)
let rs = wildlife_ranges()
expect(len(rs) >= 6)
for i in 0 .. len(rs) {
expect(wildlife_range_dist(rs[i], 0.0, 0.0) >= wildlife_species(rs[i].sp).keep_away)
if rs[i].sp == 1 { expect(rs[i].z > 400.0) }
expect(rs[i].sx > -300.0)
}
expect(wildlife_count(0) >= 1)
expect_eq(wildlife_count_all(), wildlife_count(0) + wildlife_count(1) + wildlife_count(2) + wildlife_count(3))
}
test "a player far off makes no difference that lasts: the alert settles under the unaware line" {
fk_setup()
let a = deer_at(0.0, 0.0)
player_at(55.0, 0.0)
fk_noise = 0.3
go(a, 60.0)
expect(a.alert < 25.0)
expect(a.state != WILD_FLEE)
}
test "close and in the open it is flushed, runs, and says so" {
fk_setup()
let a = deer_at(0.0, 0.0)
player_at(8.0, 0.0)
fk_noise = 0.8
go(a, 10.0)
expect(a.spook > 0.0)
let fs = facts()
expect(count(fs, WILD_FLED) >= 1)
expect(a.x < 0.0)
}
test "cover hides a player from sight, a hide from everything but the nose" {
fk_setup()
let a = deer_at(0.0, 0.0)
let open = wildlife_alert_rate(a, 0, 30.0)
player_at(30.0, 0.0)
let open2 = wildlife_alert_rate(a, 0, 30.0)
fk_blocked = true
let covered = wildlife_alert_rate(a, 0, 30.0)
fk_blocked = false
fk_hidden = true
let hidden = wildlife_alert_rate(a, 0, 30.0)
expect(open2 > 0.0)
expect(open >= open2)
expect_near(covered, 0.0, 0.0001)
expect_near(hidden, 0.0, 0.0001)
}
test "sitting still makes it forget faster, and the wind carries scent only downwind" {
fk_setup()
let a = deer_at(0.0, 0.0)
let moving = wildlife_alert_decay(a, 0)
fk_still = WILD_SITTING
expect(wildlife_alert_decay(a, 0) > moving * 2.0)
player_at(0.0, -60.0)
fk_blocked = true
fk_scent = 1.0
fk_wind = 0.5
fk_wind_dir = 3.1415927 # blowing toward +z: from the player to the deer
expect(wildlife_downwind(a, 0) > 0.9)
expect(wildlife_alert_rate(a, 0, 60.0) > 0.0)
fk_wind_dir = 0.0
expect_near(wildlife_alert_rate(a, 0, 60.0), 0.0, 0.0001)
}
test "a charger comes at a player inside its reach, and a shove is a fact for the game" {
fk_setup()
let b = wildlife_make(1, 0.0, 0.0, false, 0.0, 0, 1.0, 2)
player_at(6.0, 0.0)
wildlife_tick_ground(b, 0.05, 0.001)
expect_eq(b.state, WILD_CHARGE)
go(b, 2.0)
let fs = facts()
expect_eq(count(fs, WILD_CHARGED), 1)
expect_eq(count(fs, WILD_SHOVED), 1)
expect(b.calm > 0.0)
}
test "away is hidden and skipped, gone is removed and said" {
fk_setup()
let a = deer_at(0.0, 0.0)
player_at(10.0, 0.0)
fk_about = WILD_AWAY
wildlife_tick(0.05, 0.001)
expect(not a.shown and a.alive)
fk_about = WILD_GONE
wildlife_tick(0.05, 0.001)
expect(not a.alive)
expect_eq(count(facts(), WILD_WENT), 1)
}
test "a walker leaves a print every 2.8 m, and player 0 spots a species once" {
fk_setup()
let a = deer_at(0.0, 0.0)
player_at(40.0, 0.0)
fk_blocked = true
a.state = WILD_WANDER
a.tx = 0.0
a.tz = -100.0
a.timer = 100.0
for k in 0 .. 200 { wildlife_tick(0.05, 0.0) }
let fs = facts()
expect(count(fs, WILD_PRINT) >= 3)
expect_eq(count(fs, WILD_SPOTTED), 1)
expect(wildlife_seen(0))
}
test "the record and the found ranges come back from the save section" {
fk_setup()
wildlife_spawn(0.0, 0.0)
wildlife_mark_fed(2)
wildlife_saw(0)
let r = wildlife_ranges()[0]
wildlife_ranges_visit(r.x, r.z)
let v = wildlife_save()
wildlife_reset()
expect(not wildlife_fed_any() and not wildlife_ranges()[0].found)
wildlife_load(v, 1)
expect(wildlife_fed_any())
expect_eq(wildlife_fed_mask(), 4)
expect(wildlife_seen(0))
expect(wildlife_ranges()[0].found)
}
test "a morning moves the ranges toward winter and brings one back to a range that lost its own" {
fk_setup()
wildlife_spawn(0.0, 0.0)
let r = wildlife_ranges()[0]
let x0 = r.x
let all = wildlife_all()
for i in 0 .. len(all) { if all[i].rg == 0 { wildlife_remove(all[i]) } }
fk_winter = 1.0
let added = wildlife_morning()
expect(added >= 1)
expect_eq(wildlife_range_alive(0), 1)
expect_near(r.x, r.wx, 0.001)
expect(r.x != x0 or r.wx == r.sx)
}
}