The pack
creatureZoo
function creatureZoo(): Pack<{ creatureZoo: typeof api }>
Install the creature-zoo API (game.creatureZoo).
Classes
Zoo
class Zoo
A herd of creatures on a ground, kept in list (plain data the game saves).
constructor( /** The kinds, by id. */ readonly kinds: Readonly<Record<string, CreatureKind>>, /** The game. */ readonly host: ZooHost, /** The creatures (the game's own array: it is saved with the game's state). */ public list: Creature[], )sizeOf(k: Creature): number— A creature's current size (eaters grow 40% a stage).attackOf(k: Creature, kind: CreatureKind): CreatureAttack— Its attack now: a grown stage's, or the base one.spawn(kind: CreatureKind, x: number, z: number, herd: number): Creature— One creature at (x, z), in herdherd.spawnGroup(kind: CreatureKind, avoid: { x: number; z: number }): void— A herd ofkind.groupcreatures somewhere it can live, well away fromavoid.step(dt: number): void— One step: choose targets, move, trail segments, eat and grow, lay eggs, attack.
Types
Creature
interface Creature
A creature in play.
id: number— Unique number among all entities.kind: string— Id of itsCreatureKind, the key in the zoo'skinds.x: number— World x.y: number— World y, up.z: number— World z.vx: number— Velocity along x in world units per second.vy: number— Velocity along y (up) in world units per second.vz: number— Velocity along z in world units per second.yaw: number— Heading in radians, with the carpet's convention: 0 looks along +z and increasing turns right.hp: number— Hit points left; it dies at 0 and releases itsmana.mana: number— Mana it holds (released on death).stage: number— Growth stage (0 = the base).herd: number— Herd/flock id.angry: boolean— Has turned hostile (non-aggressive kinds after being hit).target: string— What it is after: the host's reference for the target (mana-conquest: "w:3", "c:2", "b:5", "k:9"), or "".cool: number— Seconds until its next attack.away: number— Seconds left away (teleported), or 0.rise: number— A worm's or kraken's rise 0..1.trail: Array<{ x: number; y: number; z: number }>— Trail of earlier positions (segments follow it).owner: number— The team it fights for (mana-conquest: the wizard of an undead army), or -1 for wild.age: number— Seconds it has lived.homeX: number— World x of the spot it wanders around; a flock's anchor drifts.homeZ: number— World z of the spot it wanders around; a flock's anchor drifts.alive: boolean— False once dead.lay: number— Laying timer (grown crabs).
CreatureAttack
interface CreatureAttack
A creature's attack.
kind: "melee" | (string & {})—melee(claws or stings at touching range: the creature closes in) or a name the host carries out as it likes (mana-conquest's: fireball, rapid, boulder, arrow, lightning, meteor); a ranged attack stands off.damage: number— Damage of each hit to what it strikes.range: number— Reach (world units).every: number— Seconds between attacks.
CreatureKind
interface CreatureKind
A kind of creature.
id: string— Unique kind name: the key in the zoo'skinds, and what a creature'skindand the host's own lists refer to.name: string— Display name.hp: number— Hit points at full health.mana: number— Mana released when it dies (split into orbs).size: number— Body size (world units across).speed: number— Cruising speed (world units/s).motion: CreatureMotion— How it moves and fights: flocks, flyers, worms, serpents, walkers or sea creatures.altitude: number— Flying height over the ground (flyers).attack: CreatureAttack— Its base attack; agrowsstage replaces it.sight: number— Notices targets within this distance.aggressive: boolean— False: harmless until something hurts it (the griffin), then its whole herd turns.targets: string[]— What it goes for: the classes of target the host offers (mana-conquest: wizard, castle, balloon, creature).humanOnly?: boolean— The host's own flag: of the wizards, it goes only for the human player (Magic Carpet's bees).group: [number, number]— How many come together.regen?: number— Health regained per second.eatsMana?: boolean— Eats loose mana orbs it reaches (the mana is held and released on death).grows?: { per: number; stages: CreatureAttack[]; layEvery?: number }— Grows as it eats: each stage needs this much mana; stage attacks replace the base attack.stealsMana?: number— The host's own rule: steals this much personal mana from a wizard it hits.teleportsAt?: number— The host's own rule: teleports away when hurt below this fraction of its health and comes back restored.converts?: string— The host's own rule: a victim it kills rises as one of this kind (skeletons).seesInvisible?: boolean— The host's own rule: sees invisible wizards.ignoresRebound?: boolean— The host's own rule: its fireballs cannot be rebounded.segments?: number— Segments of a worm or serpent.
CreatureMotion
type CreatureMotion = /** Flies in a loose flock that wanders and swoops on targets (vultures, bees, griffins). */ | "flock" /** Flies alone, circling and diving (genie, wyvern). */ | "flyer" /** A segmented body that swims through the land, rearing up to strike (worms). */ | "worm" /** A segmented body that flies (MC1's dragon). */ | "serpent" /** Walks the land and will not cross water (apes, trolls, skeletons, crabs, emu riders). */ | "walker" /** Lives under the sea and rises to strike (kraken). */ | "sea"
How a creature moves.
ZooFood
interface ZooFood
Food an eater can reach (mana orbs).
id: number— The host's id.x: number— World x.y: number— World y.z: number— World z.amount: number— What eating it is worth.alive: boolean— Still there.
ZooGround
interface ZooGround
What the zoo needs of the ground: a wrapping height field over a sea (a torus-land Land answers all of it).
readonly cell: number— World units per cell.readonly size: number— World units across.readonly sea: number— The sea's level.groundAt(x: number, z: number): number— The height to stay above: land, or the sea over it.heightAt(x: number, z: number): number— The land's own height (the sea bed under water).isWater(x: number, z: number): boolean— Under the sea.wrap(v: number): number— Fold a coordinate onto the world.delta(a: number, b: number): number— Shortestb - aacross the wrap.distance(ax: number, az: number, bx: number, bz: number): number— Distance across the wrap.
ZooHost
interface ZooHost
What a zoo asks of its game.
readonly ground: ZooGround— The ground.rand(): number— The game's seeded random numbers in [0, 1).id(): number— A fresh entity id.targets(k: Creature, kind: CreatureKind): Iterable<ZooTarget>— Every target this creature could go for (filtered bykind.targetsand the game's own rules).locate(ref: string): { x: number; y: number; z: number } | null— Where a target is now, or null when it is gone.keep?(k: Creature, ref: string): boolean— Keep chasing this target even though another is nearer (mana-conquest: a grudge against a wizard). Default no.attack(k: Creature, kind: CreatureKind, atk: CreatureAttack, at: { x: number; y: number; z: number }, to: { x: number; y: number; z: number }): void— Carry out an attack fromatat the target atto: the game owns damage and projectiles.food?(): Iterable<ZooFood>— Food on the ground, for eaters.eat?(k: Creature, food: ZooFood): void— An eater reached this food: the game removes it (the zoo adds its amount and grows the creature).laid?(young: Creature): void— A grown creature laid an egg that hatched here.
ZooTarget
interface ZooTarget
A target the host offers a creature.
ref: string— The host's reference for it (kept inCreature.target).x: number— World x.y: number— World y.z: number— World z.team: number— Its team: a creature never goes for its own.


