ludic/packages/ludic.vehicles/call.ludic
Orkuncakilkaya 71735b10a2 feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune
ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v),
q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding
facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)).

ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no
longer uses, nor anything it calls, and the argument that fills it - including an argument for a
parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is
told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would
make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 04:19:56 +03:00

101 lines
3.6 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
function ve_add(vehicles_st: mut VehiclesState, kind: 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.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)
push(ve_all(vehicles_st), v)
VehicleWorld.made(v)
return 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) }
v.home_x = x
v.home_z = z
}
# 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: mut 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, vehicle_place_x(vehicles_st, kind, k), vehicle_place_z(vehicles_st, kind, k), yaw)
if made == null { return false }
made.owner = pid
if pid == 0 { ve_apply_kept(vehicles_st, made) }
return true
}
if v.rider >= 0 { return false }
ve_put(v, vehicle_place_x(vehicles_st, kind, k), vehicle_place_z(vehicles_st, kind, k))
v.yaw = yaw
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 keep = new []Vehicle
let l = ve_all(vehicles_st)
for i in 0 .. len(l) {
if l[i].owner != pid { push(keep, l[i]) } else { VehicleWorld.gone(l[i]) }
}
vehicles_st.ve_list = keep
}
# hired or rented for the trip
export function vehicle_own(v: Vehicle) -> void { if v != null { v.owned = true } }
# hay for a horse, up to a full belly
export function vehicle_feed(vehicles_st: mut VehiclesState, v: Vehicle, amount: float) -> void {
if v == null { return }
v.food = Math.min(v.food + amount, 100.0)
ve_say(vehicles_st, VEHICLE_FED, v, amount)
}
# a horse nobody rides goes where its animal goes, round the home it is tied at (home_x, home_z)
export function vehicle_follow(v: Vehicle, x: float, y: float, z: float, yaw: float) -> void {
if v == null or v.rider >= 0 { return }
v.x = x
v.y = y
v.z = z
v.yaw = yaw
}
# a saved trip's word on this player's own: hired, and how fed
export function vehicle_restore(vehicles_st: mut VehiclesState, kind: int, owned: bool, food: float) -> void {
if kind == VEHICLE_HORSE {
vehicles_st.ve_kept_horse = owned
vehicles_st.ve_kept_food = food
} else { vehicles_st.ve_kept_boat = owned }
let v = vehicle_find(vehicles_st, kind)
if v != null { ve_apply_kept(vehicles_st, v) }
}
function ve_apply_kept(vehicles_st: VehiclesState, v: Vehicle) -> void {
if v.kind == VEHICLE_HORSE {
v.owned = vehicles_st.ve_kept_horse
v.food = vehicles_st.ve_kept_food
} else { v.owned = vehicles_st.ve_kept_boat }
}