ludic/packages/ludic.vehicles/ports.ludic
Orkuncakilkaya 8b85282502 ludic.zones: a disc per player from their fog, merged into clusters; the simulating packages ask whether a place is simulated
zones_set / zones_clear / zones_merge, zones_contains / zones_nearest and the clusters' bounding circles,
over fixed arrays of ZONES_MAX (16). WildlifeWorld.active freezes an animal outside (no state change, no
dice), NpcWorld.active a walker (and no birth outside), VehicleWorld.active a moored boat, and
ThingsWorld.restocks keeps a morning's restock inside; every default is "everywhere", so an unbound game
is unchanged. Tests: the merge (near players one cluster, far two, a player leaving splits a chain),
contains, nearest, the radius; wildlife, npc, vehicles and things pass as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:53:23 +03:00

90 lines
4.4 KiB
Text

# ports.ludic - what a vehicle asks the world, its hull and its rider. Unbound, the world is dry
# flat ground with nothing in the way and no wind, and the rider is put exactly where asked; the
# hull has no default - a boat is a body in the game's physics.
export port VehicleWorld {
ground: fn(float, float) -> float
water: fn(float, float) -> float = fn ve__dry # the surface over a point
swell: fn(float, float, float, float) -> float = fn ve__calm # (x, z, fx, fz): 0..1 of a stroke lost
wind: fn() -> float = fn ve__zero # 0..1
wind_yaw: fn() -> float = fn ve__zero # the yaw the wind pushes toward
next_id: fn() -> int = fn ve__next
made: fn(Vehicle) -> void = fn ve__nothing # a new vehicle: draw it
placed: fn(Vehicle) -> void = fn ve__nothing # it moved: put its model there
gone: fn(Vehicle) -> void = fn ve__nothing # its owner left: take it away
active: fn(float, float) -> bool = fn ve__yes2 # simulated here: outside, a moored boat is left as it is
}
# a boat's hull in the world's physics (Maroon Lake: a buoyant Jolt body), named by the vehicle's
# nid. The water floats it and the lake bed stops it; the package rows it and reads where it is.
export port VehicleHull {
put: fn(int, float, float, float, float) -> void # (nid, x, y, z, yaw): at rest there, made if new
row: fn(int, float, float) -> void # (nid, forward N, turn N.m) over the next step
drift: fn(int, float, float) -> void # (nid, fx, fz): a push across the water (wind)
read: fn(int) -> bool # (nid): its pose into x .. speed; false if none
x: fn() -> float
y: fn() -> float
z: fn() -> float
yaw: fn() -> float
speed: fn() -> float # along its bow, m/s
gone: fn(int) -> void # (nid): out of the world
}
# the body on board: the game's walking body (ludic.character, through the game)
export port VehicleRider {
board: fn(float, float, float) -> void = fn ve__board # (x, z, yaw)
ride_at: fn(float, float, float, float, float) -> void = fn ve__ride # (x, y, z, yaw, speed)
step_off: fn(float, float) -> void = fn ve__off # (x, z)
safe_spot: fn(float, float, float, float) -> bool = fn ve__safe # (x, z, from_y, max_depth)
safe_x: fn() -> float = fn ve__safe_x
safe_z: fn() -> float = fn ve__safe_z
}
export state VehiclesState {
ve_kept_horse: bool = false
ve_kept_boat: bool = false
ve_kept_food: float = 40.0
ve_ids: int = 0
ve_moved: float = 0.0 # metres the ridden vehicle covered since the game last took them
ve_moved_kind: int = 0
ve_moved_x: float = 0.0
ve_moved_z: float = 0.0
ve_sx: float = 0.0
ve_sz: float = 0.0
ve: VehicleTable = ve__new()
ve_cur: Vehicle = null
ve_dock_x: float = 0.0
ve_dock_z: float = 0.0
ve_dock_yaw: float = 0.0
ve_rail_x: float = 0.0
ve_rail_z: float = 0.0
ve_rail_yaw: float = 0.0
ve_have_dock: bool = false
ve_swell_said: float = 0.0
ve_lx: float = 0.0 # the unbound legs' pose
ve_ly: float = 0.0
ve_lz: float = 0.0
ve_fact_q: Queue<VehicleFact> = ve_fact_q__new()
@max(1024) ve_fpool: []VehicleFact = ve_fpool_new() # every fact record made, reused once no drain holds it
@max(1024) ve_ffree: []VehicleFact = ve_ffree_new()
ve_fnext: int = 0
}
function ve__dry(x: float, z: float) -> float { return -10000.0 }
function ve__calm(x: float, z: float, fx: float, fz: float) -> float { return 0.0 }
function ve__zero() -> float { return 0.0 }
function ve__yes2(x: float, z: float) -> bool { return true }
function ve__next(vehicles_st: mut VehiclesState) -> int {
vehicles_st.ve_ids += 1
return vehicles_st.ve_ids
}
function ve__nothing(v: Vehicle) -> void { }
function ve__board(x: float, z: float, yaw: float) -> void { }
function ve__ride(x: float, y: float, z: float, yaw: float, speed: float) -> void { }
function ve__off(x: float, z: float) -> void { }
function ve__safe(vehicles_st: mut VehiclesState, x: float, z: float, from_y: float, max_depth: float) -> bool {
vehicles_st.ve_sx = x
vehicles_st.ve_sz = z
return true
}
function ve__safe_x(vehicles_st: VehiclesState) -> float { return vehicles_st.ve_sx }
function ve__safe_z(vehicles_st: VehiclesState) -> float { return vehicles_st.ve_sz }
function ve_fact_q__new() -> Queue<VehicleFact> { return queue_new("vehicles.facts") }