feat(ecs): ludic.vehicles on a Table<Vehicle>
The vehicles are rows of a ludic.base Table with kind and owner as columns, every player's own by an owner index and a nid map: vehicle_of walks only that player's rows, vehicle_by_nid is a map lookup, and a player who leaves has their rows removed instead of the whole list rebuilt. ve_add takes the owner, so the owner is filed once and never assigned around the table. Positions stay on the record: a boat moves every frame and there are at most two a player. vehicles_test holds the table (9 tests); the game builds against it and lab/unit passes (88 tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
52270ab5d1
commit
045bf22e10
8 changed files with 87 additions and 18 deletions
|
|
@ -18,7 +18,7 @@ function ve_say(vehicles_st: VehiclesState, what: int, v: Vehicle, n: float) ->
|
|||
q_push(vehicle_facts(vehicles_st), f)
|
||||
}
|
||||
|
||||
function ve_all(vehicles_st: VehiclesState) -> []Vehicle { return vehicles_st.ve_list }
|
||||
function ve_all(vehicles_st: VehiclesState) -> []Vehicle { return vehicles_st.ve.tab.rec }
|
||||
|
||||
# every vehicle in the valley, to draw and to aim at (change one only through the verbs)
|
||||
export function vehicles_all(vehicles_st: VehiclesState) -> []Vehicle { return ve_all(vehicles_st) }
|
||||
|
|
@ -32,8 +32,9 @@ export function vehicle_ride_kind(vehicles_st: VehiclesState) -> int {
|
|||
export function vehicle_current(vehicles_st: VehiclesState) -> Vehicle { return vehicles_st.ve_cur }
|
||||
|
||||
export function vehicle_of(vehicles_st: VehiclesState, pid: int, kind: int) -> Vehicle {
|
||||
let rows = ix_rows(vehicles_st.ve.owners, pid)
|
||||
let l = ve_all(vehicles_st)
|
||||
for i in 0 .. len(l) { if l[i].kind == kind and l[i].owner == pid { return l[i] } }
|
||||
for k in 0 .. len(rows) { if l[rows[k]].kind == kind { return l[rows[k]] } }
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue