ludic/packages/ludic.wildlife/system.ludic

44 lines
1.5 KiB
Text

# system.ludic - the wildlife as a system: its save section is this player's record (the species
# seen and fed) and which ranges they have found; the animals themselves are respawned with the
# valley, so a reset forgets the record and nothing else
export function wildlife_reset(wildlife_st: mut WildlifeState) -> void {
wl_record_reset(wildlife_st)
wildlife_st.wl_found = null
let rs = wildlife_ranges(wildlife_st)
for i in 0 .. len(rs) { rs[i].found = false }
q_clear(wildlife_facts(wildlife_st))
}
export function wildlife_save(wildlife_st: WildlifeState) -> Val {
let v = Value.object()
sv_put_int(v, "seen", wildlife_st.wl_seen)
sv_put_int(v, "fed", wildlife_st.wl_fed)
sv_put_bool(v, "fed_any", wildlife_st.wl_fed_any)
let found = new []int
let rs = wildlife_ranges(wildlife_st)
for i in 0 .. len(rs) {
var f = 0
if rs[i].found { f = 1 }
push(found, f)
}
sv_put_ints(v, "found", found)
return v
}
export function wildlife_load(wildlife_st: mut WildlifeState, v: Val, version: int) -> void {
wildlife_reset(wildlife_st)
wildlife_st.wl_seen = sv_int(v, "seen", 0)
wildlife_st.wl_fed = sv_int(v, "fed", 0)
wildlife_st.wl_fed_any = sv_bool(v, "fed_any", false)
wildlife_st.wl_found = sv_ints(v, "found")
wl_found_apply(wildlife_st)
}
# PH_SIMULATE with no tick of its own: the game steps it (wildlife_tick) where the world is owned
export function wildlife_system() -> System {
let s = system_new("wildlife", PH_SIMULATE)
s.reset = fn wildlife_reset
s.save = fn wildlife_save
s.load = fn wildlife_load
return s
}