ludic/packages/ludic.wildlife/species.ludic

79 lines
3.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
}
export state WildlifeState {
wl_facts: Queue<WildFact> = wl_facts__new()
wl_own: []WildAnimal = null
wl_px: float = 0.0
wl_pz: float = 0.0
wl_ask: WildLure = new WildLure
wl_best: WildLure = new WildLure
wl_seed_any: bool = false
wl_seed_t: float = 0.0
wl_ids: int = 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_list: []WildAnimal = new []WildAnimal
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
}
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") }