refactor(packages): 0.R5 - the shop's week is rolled by its tick and asking reads it; needs start filled and vehicles start with their list; character, physics, vehicles and nativeecho's lazy starts are defaults; --tighten over all four
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67d8079c47
commit
87259f989d
31 changed files with 104 additions and 111 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# 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 {
|
||||
function ve_add(vehicles_st: 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()
|
||||
|
|
@ -41,7 +41,7 @@ function ve_put(v: Vehicle, x: float, z: float) -> void {
|
|||
|
||||
# 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 {
|
||||
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)
|
||||
|
|
@ -78,7 +78,7 @@ export function vehicles_release(vehicles_st: mut VehiclesState, pid: int) -> vo
|
|||
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 {
|
||||
export function vehicle_feed(vehicles_st: 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)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const VE_HORSE_GALLOP: float = 11.0
|
|||
const VE_HORSE_ACC: float = 4.0
|
||||
const VE_HORSE_TURN: float = 1.6
|
||||
|
||||
function ve_ride_horse(vehicles_st: mut VehiclesState, v: Vehicle, ix: float, iz: float, run: bool, dt: float) -> void {
|
||||
function ve_ride_horse(vehicles_st: VehiclesState, v: Vehicle, ix: float, iz: float, run: bool, dt: float) -> void {
|
||||
var top = VE_HORSE_WALK
|
||||
if run and v.fuel > 5.0 { top = VE_HORSE_GALLOP }
|
||||
v.speed = v.speed + Math.clamp(iz * top - v.speed, -VE_HORSE_ACC * dt, VE_HORSE_ACC * dt)
|
||||
|
|
@ -21,7 +21,7 @@ function ve_ride_horse(vehicles_st: mut VehiclesState, v: Vehicle, ix: float, iz
|
|||
}
|
||||
|
||||
# a horse only on dry ground, up a walkable rise, clear of what is in its way
|
||||
function ve_travel(vehicles_st: mut VehiclesState, v: Vehicle, nx: float, nz: float, d: float) -> void {
|
||||
function ve_travel(vehicles_st: VehiclesState, v: Vehicle, nx: float, nz: float, d: float) -> void {
|
||||
let nh = VehicleWorld.ground(nx, nz)
|
||||
var ok = true
|
||||
if nh < VehicleWorld.water(nx, nz) + 0.4 { ok = false }
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export function vehicle_place_z(vehicles_st: VehiclesState, kind: int, k: int) -
|
|||
}
|
||||
|
||||
# who is in place k: the boat lying in the berth or the horse tied in the bay, or null
|
||||
export function vehicle_in_place(vehicles_st: mut VehiclesState, kind: int, k: int) -> Vehicle {
|
||||
export function vehicle_in_place(vehicles_st: VehiclesState, kind: int, k: int) -> Vehicle {
|
||||
let px = vehicle_place_x(vehicles_st, kind, k)
|
||||
let pz = vehicle_place_z(vehicles_st, kind, k)
|
||||
let l = ve_all(vehicles_st)
|
||||
|
|
@ -64,13 +64,13 @@ export function vehicle_in_place(vehicles_st: mut VehiclesState, kind: int, k: i
|
|||
}
|
||||
|
||||
# the first free place, or -1
|
||||
export function vehicle_free_place(vehicles_st: mut VehiclesState, kind: int) -> int {
|
||||
export function vehicle_free_place(vehicles_st: VehiclesState, kind: int) -> int {
|
||||
for k in 0 .. VEHICLE_PLACES { if vehicle_in_place(vehicles_st, kind, k) == null { return k } }
|
||||
return -1
|
||||
}
|
||||
|
||||
# this player's own is lying in one of the places
|
||||
export function vehicle_mine_in_place(vehicles_st: mut VehiclesState, kind: int) -> bool {
|
||||
export function vehicle_mine_in_place(vehicles_st: VehiclesState, kind: int) -> bool {
|
||||
let mine = vehicle_find(vehicles_st, kind)
|
||||
if mine == null { return false }
|
||||
for k in 0 .. VEHICLE_PLACES {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export state VehiclesState {
|
|||
ve_ids: int = 0
|
||||
ve_sx: float = 0.0
|
||||
ve_sz: float = 0.0
|
||||
ve_list: []Vehicle = null
|
||||
ve_list: []Vehicle = new []Vehicle
|
||||
ve_cur: Vehicle = null
|
||||
ve_dock_x: float = 0.0
|
||||
ve_dock_z: float = 0.0
|
||||
|
|
@ -56,7 +56,7 @@ export state VehiclesState {
|
|||
ve_rail_yaw: float = 0.0
|
||||
ve_have_dock: bool = false
|
||||
ve_swell_said: float = 0.0
|
||||
ve_fact_q: Queue<VehicleFact> = null
|
||||
ve_fact_q: Queue<VehicleFact> = ve_fact_q__new()
|
||||
}
|
||||
function ve__dry(x: float, z: float) -> float { return -10000.0 }
|
||||
function ve__open(x: float, z: float, r: float) -> bool { return false }
|
||||
|
|
@ -77,3 +77,4 @@ function ve__safe(vehicles_st: mut VehiclesState, x: float, z: float, from_y: fl
|
|||
}
|
||||
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") }
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ function ve_swell(vehicles_st: mut VehiclesState, v: Vehicle, iz: float, dt: flo
|
|||
}
|
||||
|
||||
# every boat: its hull read back, and the wind pushing it across the lake, ridden or not
|
||||
export function vehicles_tick(vehicles_st: mut VehiclesState, dt: float) -> void {
|
||||
export function vehicles_tick(vehicles_st: VehiclesState, dt: float) -> void {
|
||||
let l = ve_all(vehicles_st)
|
||||
let w = VehicleWorld.wind() * VE_WIND
|
||||
let wy = VehicleWorld.wind_yaw()
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@
|
|||
# from, and the facts
|
||||
const ve_pi: float = 3.14159265
|
||||
|
||||
export function vehicle_facts(vehicles_st: mut VehiclesState) -> Queue<VehicleFact> {
|
||||
if vehicles_st.ve_fact_q == null { vehicles_st.ve_fact_q = queue_new("vehicles.facts") }
|
||||
export function vehicle_facts(vehicles_st: VehiclesState) -> Queue<VehicleFact> {
|
||||
return vehicles_st.ve_fact_q
|
||||
}
|
||||
|
||||
function ve_say(vehicles_st: mut VehiclesState, what: int, v: Vehicle, n: float) -> void {
|
||||
function ve_say(vehicles_st: VehiclesState, what: int, v: Vehicle, n: float) -> void {
|
||||
let f = new VehicleFact
|
||||
f.what = what
|
||||
f.nid = v.nid
|
||||
|
|
@ -19,13 +18,10 @@ function ve_say(vehicles_st: mut VehiclesState, what: int, v: Vehicle, n: float)
|
|||
q_push(vehicle_facts(vehicles_st), f)
|
||||
}
|
||||
|
||||
function ve_all(vehicles_st: mut VehiclesState) -> []Vehicle {
|
||||
if vehicles_st.ve_list == null { vehicles_st.ve_list = new []Vehicle }
|
||||
return vehicles_st.ve_list
|
||||
}
|
||||
function ve_all(vehicles_st: VehiclesState) -> []Vehicle { return vehicles_st.ve_list }
|
||||
|
||||
# every vehicle in the valley, to draw and to aim at (change one only through the verbs)
|
||||
export function vehicles_all(vehicles_st: mut VehiclesState) -> []Vehicle { return ve_all(vehicles_st) }
|
||||
export function vehicles_all(vehicles_st: VehiclesState) -> []Vehicle { return ve_all(vehicles_st) }
|
||||
|
||||
# the kind this machine's player is riding, 0 none
|
||||
export function vehicle_ride_kind(vehicles_st: VehiclesState) -> int {
|
||||
|
|
@ -35,17 +31,17 @@ 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: mut VehiclesState, pid: int, kind: int) -> Vehicle {
|
||||
export function vehicle_of(vehicles_st: VehiclesState, pid: int, kind: int) -> Vehicle {
|
||||
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] } }
|
||||
return null
|
||||
}
|
||||
|
||||
# this player's own boat or horse
|
||||
export function vehicle_find(vehicles_st: mut VehiclesState, kind: int) -> Vehicle { return vehicle_of(vehicles_st, 0, kind) }
|
||||
export function vehicle_find(vehicles_st: VehiclesState, kind: int) -> Vehicle { return vehicle_of(vehicles_st, 0, kind) }
|
||||
|
||||
# the nearest vehicle nobody is on within `reach` of (x, z); nothing while riding
|
||||
export function vehicle_nearest(vehicles_st: mut VehiclesState, x: float, z: float, reach: float) -> Vehicle {
|
||||
export function vehicle_nearest(vehicles_st: VehiclesState, x: float, z: float, reach: float) -> Vehicle {
|
||||
if vehicles_st.ve_cur != null { return null }
|
||||
var best: Vehicle = null
|
||||
var bd = reach
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export function vehicles_reset(vehicles_st: mut VehiclesState) -> void {
|
|||
q_clear(vehicle_facts(vehicles_st))
|
||||
}
|
||||
|
||||
export function vehicles_save(vehicles_st: mut VehiclesState) -> Val {
|
||||
export function vehicles_save(vehicles_st: VehiclesState) -> Val {
|
||||
let v = Value.object()
|
||||
let h = vehicle_find(vehicles_st, VEHICLE_HORSE)
|
||||
let b = vehicle_find(vehicles_st, VEHICLE_BOAT)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ program VehiclesTest {
|
|||
vehicles_test_st.swell = 0.0
|
||||
vehicles_test_st.wind = 0.0
|
||||
}
|
||||
function facts(vehicles_st: mut VehiclesState) -> []VehicleFact { return q_drain(vehicle_facts(vehicles_st)) }
|
||||
function facts(vehicles_st: VehiclesState) -> []VehicleFact { return q_drain(vehicle_facts(vehicles_st)) }
|
||||
function count(fs: []VehicleFact, what: int) -> int {
|
||||
var n = 0
|
||||
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue