ludic.things: a Thing's seats (a run of the game's seat rows, saved; a bit per seat taken, not); ludic.character: char_sit takes the seat's top and its height above the feet, char_sit_leave names where standing up goes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e84a59aeff
commit
a22b8a572b
12 changed files with 107 additions and 11 deletions
|
|
@ -20,7 +20,8 @@ property Thing {
|
|||
active # false: taken, hidden, used up for now
|
||||
reach # how close it is used from (0: its kind's)
|
||||
timer, used, n # state the kind decides the meaning of
|
||||
sx, sz, syaw # where using it puts the user, and which way that faces
|
||||
sx, sz, syaw # a heading or a point the kind decides the meaning of
|
||||
seat, seats, taken # its seats: the first of the game's seat rows, how many, a bit per one sat in
|
||||
shared # the game copies it to others (a party)
|
||||
}
|
||||
```
|
||||
|
|
@ -83,6 +84,7 @@ the actor the moment the Thing exists (a caller often scales or tints it on the
|
|||
| `thing_remove(t)`, `things_drop(gone: fn(Thing) -> bool)`, `things_clear()` | gone for good (told to the port); a new world, quietly |
|
||||
| `things_reserve(n)`, `things_spare_count()` | room in the grid for `n` Things, made once at the start; how many removed records wait to be placed again |
|
||||
| `thing_move(t, x, z, yaw)`, `thing_move_to(t, x, y, z, yaw)` | on the ground there, or at a height |
|
||||
| `thing_set_seats(t, first, n)`, `thing_seat_take(t, i) -> bool`, `thing_seat_leave(t, i)`, `thing_seat_taken(t, i)`, `thing_seat_free(t) -> int` | its seats: a run of the game's seat rows (`seat`, `seats`, saved) and a bit per seat someone is in (`taken`, never saved; up to `THING_SEATS_MAX`) |
|
||||
| `thing_hide(t)`, `thing_show(t)`, `thing_set_active(t, on)` | `active`, told to the port |
|
||||
| `things_all()`, `things_count()`, `things_ready()`, `thing_by_uid(uid)` | every Thing, in the order placed; whether a world was ever set out |
|
||||
| `thing_find(kind, id)`, `thing_nearest(kind, x, z)`, `things_within(x, z, r)`, `things_each(kind)`, `things_each_all(kind)`, `thing_dist2(t, x, z)` | where they are: only active ones answer except the `_all`; a kind below 0 is any; `within` is nearest first |
|
||||
|
|
|
|||
|
|
@ -15,3 +15,4 @@ import "chunks.ludic"
|
|||
import "dispatch.ludic"
|
||||
import "system.ludic"
|
||||
import "spare.ludic"
|
||||
import "seats.ludic"
|
||||
|
|
|
|||
|
|
@ -15,9 +15,12 @@ export property Thing {
|
|||
timer: float = 0.0 # a clock the kind decides the meaning of
|
||||
used: int = 0 # the kind's own state (split for today, which sign, ...)
|
||||
n: int = 0 # a counter the kind decides the meaning of
|
||||
sx: float = 0.0 # where using it puts the user, and which way that faces
|
||||
sx: float = 0.0 # a heading or a point the kind decides the meaning of
|
||||
sz: float = 0.0
|
||||
syaw: float = 0.0
|
||||
seat: int = -1 # the first of its model's seat rows in the game's table; -1 none
|
||||
seats: int = 0 # how many seat rows follow it
|
||||
taken: int = 0 # a bit per seat someone is sitting in; never saved
|
||||
shared: bool = false # the game copies it to others (a party)
|
||||
ent: int = -1 # its handle in the table, -1 once removed
|
||||
tab: Table<Thing> = null # the table holding it, so a verb on the Thing alone keeps the indexes
|
||||
|
|
|
|||
37
packages/ludic.things/seats.ludic
Normal file
37
packages/ludic.things/seats.ludic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# seats.ludic - a Thing's seats: a run of the game's seat rows, and a bit per seat
|
||||
# for whoever sits in it. The rows are the game's; the package keeps only which are taken.
|
||||
|
||||
export const THING_SEATS_MAX: int = 30
|
||||
|
||||
# the Thing's seats are rows first .. first + n - 1 of the game's table; none are taken
|
||||
export function thing_set_seats(t: Thing, first: int, n: int) -> void {
|
||||
t.seat = first
|
||||
t.seats = Math.clamp(n, 0, THING_SEATS_MAX)
|
||||
if first < 0 { t.seats = 0 }
|
||||
t.taken = 0
|
||||
}
|
||||
|
||||
export function thing_seat_taken(t: Thing, i: int) -> bool {
|
||||
if i < 0 or i >= t.seats { return true }
|
||||
return (t.taken >> i) & 1 == 1
|
||||
}
|
||||
|
||||
# false when it is not one of the Thing's seats or someone is in it
|
||||
export function thing_seat_take(t: Thing, i: int) -> bool {
|
||||
if thing_seat_taken(t, i) { return false }
|
||||
t.taken = t.taken | (1 << i)
|
||||
return true
|
||||
}
|
||||
|
||||
export function thing_seat_leave(t: Thing, i: int) -> void {
|
||||
if i < 0 or i >= t.seats or (t.taken >> i) & 1 == 0 { return }
|
||||
t.taken = t.taken - (1 << i)
|
||||
}
|
||||
|
||||
# the first seat nobody is in, or -1
|
||||
export function thing_seat_free(t: Thing) -> int {
|
||||
for i in 0 .. t.seats {
|
||||
if not thing_seat_taken(t, i) { return i }
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
|
@ -47,6 +47,9 @@ function th_clean(t: Thing) -> Thing {
|
|||
t.sx = 0.0
|
||||
t.sz = 0.0
|
||||
t.syaw = 0.0
|
||||
t.seat = -1
|
||||
t.seats = 0
|
||||
t.taken = 0
|
||||
t.shared = false
|
||||
t.ent = -1
|
||||
t.tab = null
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ function th_to_json(t: Thing) -> Val {
|
|||
sv_put_float(o, "sx", t.sx)
|
||||
sv_put_float(o, "sz", t.sz)
|
||||
sv_put_float(o, "syaw", t.syaw)
|
||||
sv_put_int(o, "seat", t.seat)
|
||||
sv_put_int(o, "seats", t.seats)
|
||||
return o
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +59,8 @@ function th_from_json(things_st: mut ThingsState, o: Val) -> void {
|
|||
t.sx = sv_float(o, "sx", 0.0)
|
||||
t.sz = sv_float(o, "sz", 0.0)
|
||||
t.syaw = sv_float(o, "syaw", 0.0)
|
||||
t.seat = sv_int(o, "seat", -1)
|
||||
t.seats = sv_int(o, "seats", 0)
|
||||
let x = sv_float(o, "x", 0.0)
|
||||
let z = sv_float(o, "z", 0.0)
|
||||
let y = sv_float(o, "y", ThingsWorld.ground(x, z))
|
||||
|
|
|
|||
|
|
@ -266,4 +266,30 @@ program ThingsTest {
|
|||
expect(r2 == r0)
|
||||
expect_eq(third[0].kind, TH_LURE)
|
||||
}
|
||||
|
||||
test "a Thing's seats: taken one at a time, left, saved without who sits in them" (things_st: mut ThingsState) {
|
||||
things_clear(things_st)
|
||||
let l = put(things_st, TH_LURE, 3.0, 4.0)
|
||||
thing_set_seats(l, 7, 2)
|
||||
expect_eq(thing_seat_free(l), 0)
|
||||
expect(thing_seat_take(l, 0))
|
||||
expect(not thing_seat_take(l, 0))
|
||||
expect(not thing_seat_take(l, 2))
|
||||
expect_eq(thing_seat_free(l), 1)
|
||||
expect(thing_seat_take(l, 1))
|
||||
expect_eq(thing_seat_free(l), -1)
|
||||
thing_seat_leave(l, 0)
|
||||
thing_seat_leave(l, 0)
|
||||
expect_eq(thing_seat_free(l), 0)
|
||||
let root = save_tree()
|
||||
save_section(root, "things", 1, things_save(things_st))
|
||||
let text = save_encode(root)
|
||||
things_clear(things_st)
|
||||
let n = load_section(save_decode(text), "things")
|
||||
things_load(things_st, n.data, n.version)
|
||||
let t = thing_find(things_st, TH_LURE, -1)
|
||||
expect_eq(t.seat, 7)
|
||||
expect_eq(t.seats, 2)
|
||||
expect_eq(t.taken, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue