refactor(packages): 0.R5 - the rest of the lazy starts are defaults - hints' rail (sized by hints_config), lab's CRC table, rpg's crafting / items / inventory / quests / dialog, shooter's weapons, prefs, and npc's and gameplay's empty ensures gone; gameplay's faction table sits beside its state, since a default names only what is declared before it; --tighten over their tests and examples
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9e4f4edb92
commit
f516148e46
15 changed files with 73 additions and 169 deletions
|
|
@ -1,7 +1,6 @@
|
|||
# census.ludic - making one (a slot reused before a new one, a look, a name, a start on its own
|
||||
# ground out of the players' sight where that can be had), a post's fixed person, and leaving
|
||||
export function npc_spawn(npc_st: mut NpcState, kind: int) -> NpcPerson {
|
||||
np_ensure()
|
||||
if npc_st.np_n >= npc_st.np_max or kind < 0 or kind >= NPCK_COUNT { return null }
|
||||
var p: NpcPerson = null
|
||||
for i in 0 .. len(npc_st.np_walkers) {
|
||||
|
|
@ -94,7 +93,6 @@ export function npc_set_at(p: NpcPerson, x: float, z: float) -> void {
|
|||
# somebody fixed at a post (a vendor behind the counter): never walks, never counted, never leaves,
|
||||
# turns to a player within its kind's notice and back to `yaw` when they go
|
||||
export function npc_place(npc_st: mut NpcState, kind: int, x: float, z: float, yaw: float, name: string, look: int) -> NpcPerson {
|
||||
np_ensure()
|
||||
let p = new NpcPerson
|
||||
p.slot = len(npc_st.np_posts)
|
||||
np_fresh(p, kind, look)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
# on: this machine's own walkers leave, and only the host's are drawn until it is turned off
|
||||
export function npc_mirror(npc_st: mut NpcState, on: bool) -> void {
|
||||
np_ensure()
|
||||
if npc_st.np_mirror == on { return }
|
||||
npc_st.np_mirror = on
|
||||
for i in 0 .. len(npc_st.np_walkers) { npc_retire(npc_st, npc_st.np_walkers[i]) }
|
||||
|
|
@ -14,7 +13,6 @@ export function npc_mirroring(npc_st: NpcState) -> bool { return npc_st.np_mirro
|
|||
|
||||
# the host's slot: somebody new in it (born), or nobody (gone)
|
||||
export function npc_put(npc_st: mut NpcState, slot: int, id: int, kind: int, look: int, seed: float, name: string, hx: float, hz: float) -> NpcPerson {
|
||||
np_ensure()
|
||||
if slot < 0 or slot >= npc_st.np_max or kind < 0 or kind >= NPCK_COUNT { return null }
|
||||
while len(npc_st.np_walkers) <= slot {
|
||||
let q = new NpcPerson
|
||||
|
|
@ -60,7 +58,6 @@ export function npc_heard(npc_st: NpcState, slot: int, x: float, y: float, z: fl
|
|||
export function npc_heard_lately(npc_st: NpcState, p: NpcPerson) -> bool { return p.heard and npc_st.np_clock - p.heard_t <= 6.0 }
|
||||
|
||||
export function npc_mirror_tick(npc_st: mut NpcState, dt: float) -> void {
|
||||
np_ensure()
|
||||
npc_st.np_clock = npc_st.np_clock + dt
|
||||
let k = Math.min(1.0, dt * 8.0)
|
||||
for i in 0 .. len(npc_st.np_walkers) {
|
||||
|
|
|
|||
|
|
@ -39,37 +39,30 @@ function np_fact(npc_st: NpcState, what: int, p: NpcPerson, player: int) -> NpcF
|
|||
return f
|
||||
}
|
||||
|
||||
function np_ensure() -> void {
|
||||
}
|
||||
|
||||
# how many walkers the place can hold at once
|
||||
export function npc_config(npc_st: mut NpcState, max: int) -> void { npc_st.np_max = max }
|
||||
|
||||
export function npc_seed(npc_st: NpcState, n: int) -> void {
|
||||
np_ensure()
|
||||
rng_seed(npc_st.np_dice, n)
|
||||
}
|
||||
|
||||
# 0 .. 1, and whole seconds lo .. hi, off the package's dice
|
||||
export function npc_rnd(npc_st: NpcState) -> float {
|
||||
np_ensure()
|
||||
return rng_float(npc_st.np_dice)
|
||||
}
|
||||
|
||||
export function npc_between(npc_st: NpcState, lo: int, hi: int) -> int {
|
||||
np_ensure()
|
||||
return rng_between(npc_st.np_dice, lo, hi)
|
||||
}
|
||||
|
||||
export function npc_secs(npc_st: NpcState, lo: int, hi: int) -> float { return float(npc_between(npc_st, lo, np_hi(lo, hi))) }
|
||||
|
||||
export function npc_walkers(npc_st: NpcState) -> []NpcPerson {
|
||||
np_ensure()
|
||||
return npc_st.np_walkers
|
||||
}
|
||||
|
||||
export function npc_posts(npc_st: NpcState) -> []NpcPerson {
|
||||
np_ensure()
|
||||
return npc_st.np_posts
|
||||
}
|
||||
|
||||
|
|
@ -79,19 +72,16 @@ export function npc_max(npc_st: NpcState) -> int { return npc_st.np_max }
|
|||
|
||||
# a walker's slot or a post, and anyone by id
|
||||
export function npc_at(npc_st: NpcState, slot: int) -> NpcPerson {
|
||||
np_ensure()
|
||||
if slot < 0 or slot >= len(npc_st.np_walkers) { return null }
|
||||
return npc_st.np_walkers[slot]
|
||||
}
|
||||
|
||||
export function npc_post(npc_st: NpcState, i: int) -> NpcPerson {
|
||||
np_ensure()
|
||||
if i < 0 or i >= len(npc_st.np_posts) { return null }
|
||||
return npc_st.np_posts[i]
|
||||
}
|
||||
|
||||
export function npc_by_id(npc_st: NpcState, id: int) -> NpcPerson {
|
||||
np_ensure()
|
||||
for i in 0 .. len(npc_st.np_walkers) { if npc_st.np_walkers[i].active and npc_st.np_walkers[i].id == id { return npc_st.np_walkers[i] } }
|
||||
for i in 0 .. len(npc_st.np_posts) { if npc_st.np_posts[i].active and npc_st.np_posts[i].id == id { return npc_st.np_posts[i] } }
|
||||
return null
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
# tick.ludic - a step of everyone, on the machine that runs the place: the census on the half hour,
|
||||
# the day's end (only ever out of every player's sight), the walk or the act, and who noticed whom
|
||||
export function npc_tick(npc_st: mut NpcState, dt: float) -> void {
|
||||
np_ensure()
|
||||
for i in 0 .. len(npc_st.np_posts) { if npc_st.np_posts[i].active { np_step_post(npc_st, npc_st.np_posts[i], dt) } }
|
||||
if npc_st.np_hold or npc_st.np_mirror { return }
|
||||
np_census(npc_st)
|
||||
|
|
@ -15,7 +14,6 @@ export function npc_tick(npc_st: mut NpcState, dt: float) -> void {
|
|||
|
||||
# the posts alone: a machine that does not run the place still turns its vendors to whoever comes
|
||||
export function npc_posts_tick(npc_st: mut NpcState, dt: float) -> void {
|
||||
np_ensure()
|
||||
for i in 0 .. len(npc_st.np_posts) { if npc_st.np_posts[i].active { np_step_post(npc_st, npc_st.np_posts[i], dt) } }
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +80,6 @@ export function npc_hold(npc_st: mut NpcState, on: bool) -> void { npc_st.np_hol
|
|||
|
||||
# everyone gone, as a new trip starts; the posts are the place's and stay
|
||||
export function npc_reset(npc_st: mut NpcState) -> void {
|
||||
np_ensure()
|
||||
for i in 0 .. len(npc_st.np_walkers) { npc_retire(npc_st, npc_st.np_walkers[i]) }
|
||||
npc_st.np_n = 0
|
||||
npc_st.np_next_h = 0.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue