A called boat and one got out of drifted across the lake on the wind (the user's play of the bundle). The tests hold a boat at its berth in a full wind for eight seconds, and one dropped out on the lake where it was left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
3 KiB
Text
84 lines
3 KiB
Text
# call.ludic - a player's boat or horse brought to a place: made there the first time, fetched there
|
|
# after; gone when its player leaves
|
|
@alloc_ok("a player's own boat or horse, made the first time it is called and fetched after")
|
|
function ve_add(vehicles_st: VehiclesState, kind: int, owner: int, x: float, z: float, yaw: float) -> Vehicle {
|
|
if kind != VEHICLE_HORSE and kind != VEHICLE_BOAT { return null }
|
|
let v = new Vehicle
|
|
v.nid = VehicleWorld.next_id()
|
|
v.kind = kind
|
|
v.owner = owner
|
|
v.yaw = yaw
|
|
if kind == VEHICLE_HORSE {
|
|
v.seat_h = 1.35
|
|
v.fuel = 100.0
|
|
v.food = 40.0
|
|
} else {
|
|
v.seat_h = 0.30
|
|
}
|
|
ve_put(v, x, z)
|
|
ve_file(vehicles_st.ve, v)
|
|
ve_settle(v)
|
|
VehicleWorld.made(v)
|
|
return v
|
|
}
|
|
|
|
# a boat's hull or a horse's legs put where the vehicle now is, at rest
|
|
function ve_settle(v: Vehicle) -> void {
|
|
if v.kind == VEHICLE_BOAT { VehicleHull.put(v.nid, v.x, v.y, v.z, v.yaw) } else { VehicleLegs.stand(v.nid, v.x, v.y, v.z) }
|
|
}
|
|
|
|
# gone from the world: its model and its hull or legs
|
|
function ve_gone(v: Vehicle) -> void {
|
|
if v.kind == VEHICLE_BOAT { VehicleHull.gone(v.nid) } else { VehicleLegs.gone(v.nid) }
|
|
VehicleWorld.gone(v)
|
|
}
|
|
|
|
# at rest at (x, z): a boat on the water, a horse on the ground and tied there
|
|
function ve_put(v: Vehicle, x: float, z: float) -> void {
|
|
v.x = x
|
|
v.z = z
|
|
v.speed = 0.0
|
|
if v.kind == VEHICLE_BOAT { v.y = VehicleWorld.water(x, z) + 0.02 } else { v.y = VehicleWorld.ground(x, z) }
|
|
ve_moor(v)
|
|
}
|
|
|
|
# a boat nobody rows holds here (vehicles_tick); a horse is tied here
|
|
function ve_moor(v: Vehicle) -> void {
|
|
v.home_x = v.x
|
|
v.home_z = v.z
|
|
v.home_yaw = v.yaw
|
|
}
|
|
|
|
# Bring player pid's boat or horse to place k. False when the place is somebody else's, or it is
|
|
# being ridden. A horse faces the trough: the bay lies on its near side.
|
|
export function vehicle_call_for(vehicles_st: VehiclesState, pid: int, kind: int, k: int) -> bool {
|
|
if not vehicles_st.ve_have_dock or k < 0 or k >= VEHICLE_PLACES { return false }
|
|
let here = vehicle_in_place(vehicles_st, kind, k)
|
|
let v = vehicle_of(vehicles_st, pid, kind)
|
|
if here != null { return v != null and here.nid == v.nid }
|
|
var yaw = vehicles_st.ve_dock_yaw
|
|
if kind == VEHICLE_HORSE { yaw = vehicles_st.ve_rail_yaw }
|
|
if v == null {
|
|
let made = ve_add(vehicles_st, kind, pid, vehicle_place_x(vehicles_st, kind, k), vehicle_place_z(vehicles_st, kind, k), yaw)
|
|
if made == null { return false }
|
|
if pid == 0 { ve_apply_kept(vehicles_st, made) }
|
|
return true
|
|
}
|
|
if v.rider >= 0 { return false }
|
|
v.yaw = yaw
|
|
ve_put(v, vehicle_place_x(vehicles_st, kind, k), vehicle_place_z(vehicles_st, kind, k))
|
|
ve_settle(v)
|
|
VehicleWorld.placed(v)
|
|
return true
|
|
}
|
|
|
|
# a player left: their boat and horse go with them, and their places are free
|
|
export function vehicles_release(vehicles_st: mut VehiclesState, pid: int) -> void {
|
|
if pid == 0 { return }
|
|
let rows = ix_rows(vehicles_st.ve.owners, pid)
|
|
while len(rows) > 0 {
|
|
let v = ve_all(vehicles_st)[rows[len(rows) - 1]]
|
|
ve_gone(v)
|
|
ve_unfile(vehicles_st.ve, v)
|
|
}
|
|
}
|