ludic/packages/ludic.vehicles/ports.ludic
Orkuncakilkaya 510360b002 feat(vehicles): 16.7 - a boat is a buoyant hull in the game's physics (VehicleHull), rowed along its bow and turned by the oars; the scripted bob, the wind's drift and the shore refusal are gone
The water floats the hull, the wind pushes every boat as a force, the lake bed stops it at the shore;
the swell takes the outward share of a stroke. ludic.physics: phys_hull_add (a buoyant box),
phys_row, phys_bow_speed, and a test that floats one a quarter under, rows, turns and grounds it.
The vehicles tests row a real Jolt hull on the fake shore; the horse moved to horse.ludic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 01:33:19 +03:00

79 lines
3.9 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
blocked: fn(float, float, float) -> bool = fn ve__open # (x, z, r): a collider in a horse's way
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
}
# 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_sx: float = 0.0
ve_sz: float = 0.0
ve_list: []Vehicle = null
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_fact_q: Queue<VehicleFact> = null
}
function ve__dry(x: float, z: float) -> float { return -10000.0 }
function ve__open(x: float, z: float, r: float) -> bool { return false }
function ve__calm(x: float, z: float, fx: float, fz: float) -> float { return 0.0 }
function ve__zero() -> float { return 0.0 }
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 }