ludic/packages/ludic.fishing/state.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

91 lines
4.6 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> = null
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_st.fishing_dice = rng_new(seed)
}
export function fishing_facts(fishing_st: mut FishingState) -> Queue<FishingFact> {
if fishing_st.fishing_fact_q == null { fishing_st.fishing_fact_q = queue_new("fishing.facts") }
return fishing_st.fishing_fact_q
}
function fishing_rand(fishing_st: mut FishingState) -> float {
if fishing_st.fishing_dice == null { fishing_st.fishing_dice = rng_new(fishing_st.fishing_seed_n) }
return rng_float(fishing_st.fishing_dice)
}
function fishing_say(fishing_st: mut FishingState, what: int) -> void {
let f = new FishingFact
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
}