105 lines
5.2 KiB
Text
105 lines
5.2 KiB
Text
# state.ludic - the line, the record, the numbers a game may change, and what a game asks
|
|
export const FISHING_OFF: int = 0
|
|
export const FISHING_WAIT: int = 1
|
|
export const FISHING_BITE_ON: int = 2
|
|
export const FISHING_REEL: int = 3
|
|
|
|
export state FishingState {
|
|
fishing_st: int = 0
|
|
fishing_t: float = 0.0 # seconds: to the bite, of the bite, of the fight
|
|
fishing_bx: float = 0.0 # where the line is in the water
|
|
fishing_bz: float = 0.0
|
|
fishing_sp: int = -1 # what is on it
|
|
fishing_len: int = 0 # cm
|
|
fishing_bait_on: bool = false
|
|
fishing_lure_on: bool = false
|
|
fishing_mark: float = 0.0 # 0..1 across the bar
|
|
fishing_dir: float = 1.0
|
|
fishing_win_c: float = 0.5 # where the green sits this crossing
|
|
fishing_ring_t: float = 0.0 # Gentle: seconds left to press
|
|
fishing_gentle_on: bool = false
|
|
fishing_won: int = 0 # crossings won
|
|
fishing_need_n: int = 3
|
|
fishing_run_t: float = 0.0 # seconds left of a run
|
|
fishing_run_left: int = 0
|
|
fishing_run_next: float = 0.0
|
|
fishing_dice: Rng = null
|
|
fishing_fact_q: Queue<FishingFact> = fishing_fact_q__new()
|
|
@max(1024) fishing_fpool: []FishingFact = fishing_fpool_new() # every fact record made, reused once no drain holds it (facts.ludic)
|
|
@max(1024) fishing_ffree: []FishingFact = fishing_ffree_new()
|
|
fishing_fnext: []int = words(1)
|
|
fishing_n: int = 0 # the record: caught, the biggest (cm), a legend landed
|
|
fishing_big: int = 0
|
|
fishing_leg: bool = false
|
|
fishing_min_depth: float = 0.15 # a cast needs this much water
|
|
fishing_deep: float = 2.5 # a legend's deep-water chance from here down
|
|
fishing_seed_n: int = 4242
|
|
}
|
|
|
|
|
|
# a cast needs `min_depth` metres; `deep` is where a legend is likelier; the line's own dice
|
|
export function fishing_config(fishing_st: mut FishingState, min_depth: float, deep: float, seed: int) -> void {
|
|
fishing_st.fishing_min_depth = min_depth
|
|
fishing_st.fishing_deep = deep
|
|
fishing_st.fishing_seed_n = seed
|
|
fishing_dice_seed(fishing_st, seed)
|
|
}
|
|
|
|
export function fishing_facts(fishing_st: FishingState) -> Queue<FishingFact> {
|
|
return fishing_st.fishing_fact_q
|
|
}
|
|
|
|
function fishing_rand(fishing_st: mut FishingState) -> float {
|
|
if fishing_st.fishing_dice == null { fishing_dice_seed(fishing_st, fishing_st.fishing_seed_n) }
|
|
return rng_float(fishing_st.fishing_dice)
|
|
}
|
|
|
|
# the line's dice: made the first time, seeded again after (a reset, a new trip)
|
|
function fishing_dice_seed(fishing_st: mut FishingState, seed: int) -> void {
|
|
if fishing_st.fishing_dice != null {
|
|
rng_seed(fishing_st.fishing_dice, seed)
|
|
return
|
|
}
|
|
fishing_st.fishing_dice = fishing_dice_new(seed)
|
|
}
|
|
@alloc_ok("once: the line's dice")
|
|
function fishing_dice_new(seed: int) -> Rng { return rng_new(seed) }
|
|
|
|
function fishing_say(fishing_st: mut FishingState, what: int) -> void {
|
|
let f = fishing_fact_record(fishing_st)
|
|
f.what = what
|
|
f.species = fishing_st.fishing_sp
|
|
f.cm = fishing_st.fishing_len
|
|
f.kg = fishing_weight_of(fishing_st.fishing_sp, fishing_st.fishing_len)
|
|
f.hits = fishing_st.fishing_won
|
|
f.need = fishing_st.fishing_need_n
|
|
f.bait = fishing_st.fishing_bait_on
|
|
f.lure = fishing_st.fishing_lure_on
|
|
f.x = fishing_st.fishing_bx
|
|
f.z = fishing_st.fishing_bz
|
|
q_push(fishing_facts(fishing_st), f)
|
|
}
|
|
|
|
export function fishing_state(fishing_st: FishingState) -> int { return fishing_st.fishing_st }
|
|
export function fishing_active(fishing_st: FishingState) -> bool { return fishing_st.fishing_st != FISHING_OFF }
|
|
export function fishing_species(fishing_st: FishingState) -> int { return fishing_st.fishing_sp }
|
|
export function fishing_cm(fishing_st: FishingState) -> int { return fishing_st.fishing_len }
|
|
export function fishing_line_x(fishing_st: FishingState) -> float { return fishing_st.fishing_bx }
|
|
export function fishing_line_z(fishing_st: FishingState) -> float { return fishing_st.fishing_bz }
|
|
export function fishing_marker(fishing_st: FishingState) -> float { return fishing_st.fishing_mark }
|
|
export function fishing_hits(fishing_st: FishingState) -> int { return fishing_st.fishing_won }
|
|
export function fishing_need(fishing_st: FishingState) -> int { return fishing_st.fishing_need_n }
|
|
export function fishing_running(fishing_st: FishingState) -> bool { return fishing_st.fishing_run_t > 0.0 }
|
|
export function fishing_gentle(fishing_st: FishingState) -> bool { return fishing_st.fishing_gentle_on }
|
|
export function fishing_ring(fishing_st: FishingState) -> float { return fishing_st.fishing_ring_t }
|
|
export function fishing_baited(fishing_st: FishingState) -> bool { return fishing_st.fishing_bait_on }
|
|
export function fishing_lured(fishing_st: FishingState) -> bool { return fishing_st.fishing_lure_on }
|
|
export function fishing_caught(fishing_st: FishingState) -> int { return fishing_st.fishing_n }
|
|
export function fishing_biggest(fishing_st: FishingState) -> int { return fishing_st.fishing_big }
|
|
export function fishing_legend_caught(fishing_st: FishingState) -> bool { return fishing_st.fishing_leg }
|
|
|
|
# can a line land at (x, z)?
|
|
export function fishing_water_at(fishing_st: FishingState, x: float, z: float) -> bool {
|
|
return FishingWorld.afloat() or FishingWorld.depth(x, z) >= fishing_st.fishing_min_depth
|
|
}
|
|
function fishing_fact_q__new() -> Queue<FishingFact> { return queue_new("fishing.facts") }
|