ludic/packages/ludic.wildlife/species.ludic

92 lines
4.3 KiB
Text

# species.ludic - what a kind of animal IS, as far as its day goes: the game hands the table in,
# one entry per species, and the entry's place in it is the species' number
export const WILD_MEADOW: int = 0
export const WILD_FOREST: int = 1
export const WILD_SHORE: int = 2
export const WILD_CLIFF: int = 3
# what it eats, and so what food and which lures it comes to
export const WILD_PLANTS: int = 0
export const WILD_FISH: int = 1
export const WILD_HAY: int = 2
export const WILD_SEED: int = 3
export property WildSpecies {
key: string = ""
walk: float = 1.0 # m/s
run: float = 1.0 # m/s
flee: float = 30.0 # its nerve: how far off a player starts to reach it, m
home: float = 60.0 # how far it roams about its home, m
habitat: int = 0 # WILD_MEADOW .. WILD_CLIFF
tracks: bool = false # a walker that leaves prints (and droppings, and beds)
size: int = 0 # 0 small (a snare holds it), 1 medium, 2 large
diet: int = 0 # WILD_PLANTS .. WILD_SEED
flies: bool = false # a bird: it circles, lands and lifts off
tame: bool = false # minds nobody (a horse)
charges: bool = false # comes at a player who gets too close (a bear)
forget: float = 2.5 # alert points a second it lets go of
land_shy: float = 80.0 # a bird: how close it comes down with somebody about, m
land_chance: float = 0.1 # and how readily it comes down at all
keep_away: float = 60.0 # how far its ranges keep from where the valley starts, m
range: float = 100.0 # how wide one of its ranges is, m
scale: float = 1.0 # its size, times
spacing: float = 2.0 # how much room it keeps from others walking by (a herd more): a crowd's separation
}
export state WildlifeState {
wl_facts: Queue<WildFact> = wl_facts__new()
@max(1024) wl_fpool: []WildFact = wl_fpool_new() # every fact record made, reused once no drain holds it
@max(1024) wl_ffree: []WildFact = wl_ffree_new() # of those, the ones free at the last look
wl_fnext: []int = words(1) # the next of them to hand out
wl_own: WildTable = null # a guest's own animals, put away whole while it draws the host's
wl_host: WildTable = wl__new() # the table the host's are drawn into: made once, cleared per join
wl_px: float = 0.0
wl_pz: float = 0.0
wl_ask: WildLure = new WildLure
wl_best: WildLure = new WildLure
wl_ask_rg: WildRange = new WildRange # what WildlifeWorld.range_at fills, copied only when it answers
wl_seed_any: bool = false
wl_seed_t: float = 0.0
wl_ids: int = 0
wl_ask_x: float = 0.0 # the point last handed to WildlifeWorld.push, and where it came out
wl_ask_z: float = 0.0
wl_out_x: float = 0.0
wl_out_z: float = 0.0
wl_ranges: []WildRange = new []WildRange
wl_found: []int = null # found flags a load brought before the ranges were set out
wl_seen: int = 0
wl_fed: int = 0
wl_fed_any: bool = false
wl_near_i: int = 0
wl_species: []WildSpecies = new []WildSpecies
wl: WildTable = wl__new()
wl_keys: int = 0
wl_dice: Rng = rng_new(97)
wl_hold: bool = false # staged: nobody thinks, everybody keeps their speed
wl_spot_ask: WildSpot = new WildSpot
wl_turned: int = 0 # steps refused and turned 75 degrees instead: the fallback, counted
wl_turned_wet: int = 0 # of those, for water ahead
wl_turned_steep: int = 0 # for a climb too steep
}
function wl_sp_all(wildlife_st: WildlifeState) -> []WildSpecies {
return wildlife_st.wl_species
}
export function wildlife_species_clear(wildlife_st: mut WildlifeState) -> void { wildlife_st.wl_species = new []WildSpecies }
# the next species; returns its number
export function wildlife_species_add(wildlife_st: WildlifeState, s: WildSpecies) -> int {
push(wl_sp_all(wildlife_st), s)
return len(wl_sp_all(wildlife_st)) - 1
}
export function wildlife_species_count(wildlife_st: WildlifeState) -> int { return len(wl_sp_all(wildlife_st)) }
export function wildlife_species(wildlife_st: WildlifeState, sp: int) -> WildSpecies {
if sp < 0 or sp >= len(wl_sp_all(wildlife_st)) { return null }
return wl_sp_all(wildlife_st)[sp]
}
function wl_sp(wildlife_st: WildlifeState, sp: int) -> WildSpecies { return wl_sp_all(wildlife_st)[sp] }
function wl_facts__new() -> Queue<WildFact> { return queue_new("wildlife.facts") }