36 lines
1.4 KiB
Text
36 lines
1.4 KiB
Text
# a toy mechanic: casting a line. It uses ludic.base and nothing else.
|
|
module toy_fishing uses ludic_base
|
|
numbers float
|
|
import "ludic.base"
|
|
export property Caught { species: int = 0, weight: float = 0.0 }
|
|
export port FishingWorld { is_water: fn(float, float) -> bool } # its port
|
|
export state ToyFishingState {
|
|
dice: Rng = null
|
|
casts: int = 0
|
|
caught: Queue<Caught> = null # its facts
|
|
}
|
|
export function fishing_cast(toy_fishing_st: mut ToyFishingState, x: float, z: float) -> bool { # its verb
|
|
if not FishingWorld.is_water(x, z) { return false }
|
|
toy_fishing_st.casts += 1
|
|
return true
|
|
}
|
|
function fishing_reset(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState) -> void {
|
|
toy_fishing_st.casts = 0
|
|
toy_fishing_st.dice = rng_new(7)
|
|
toy_fishing_st.caught = queue_new(base_st, "fishing.caught")
|
|
}
|
|
function fishing_tick(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState, t: Tick) -> void {
|
|
while toy_fishing_st.casts > 0 {
|
|
let c = new Caught
|
|
c.species = rng_between(toy_fishing_st.dice, 0, 2)
|
|
c.weight = 0.5 + rng_float(toy_fishing_st.dice)
|
|
q_push(base_st, toy_fishing_st.caught, c)
|
|
toy_fishing_st.casts -= 1
|
|
}
|
|
}
|
|
export function fishing_system() -> System {
|
|
let s = system_new("fishing", PH_SIMULATE)
|
|
s.reset = fn fishing_reset
|
|
s.tick = fn fishing_tick
|
|
return s
|
|
}
|