CorsixTH Lua Documentation

Rat Class

A `Rat` which runs from hole to hole

Declared on: line 22 of Lua/entities/rat.lua.
Inheritance: Rat ยป Entity

Method Index

Member Index

(*) only used in superclass methods
function Rat:Rat(animation)

Parameters:

NameTypeDescription
animation ? ?

Declared on: line 71 of Lua/entities/rat.lua.

function Rat:_arrive()

The rat has reached the end of its run: enter the target hole if it is a real rathole, otherwise just vanish.

Declared on: line 119 of Lua/entities/rat.lua.

function Rat:_beginRun()

Find a corridor path to the target hole and start following it, or leave if there is no route.

Declared on: line 108 of Lua/entities/rat.lua.

function Rat:_chooseTarget()

Pick a destination rathole other than the one the rat started on.

("north"/"west"/"east"/"south").

Declared on: line 129 of Lua/entities/rat.lua.

function Rat:_determinePath(dest_x, dest_y)

Compute and store a corridor-only path from the rat's tile to the given destination.

Parameters:

NameTypeDescription
dest_x integer Destination tile X coordinate.
dest_y integer Destination tile Y coordinate.

Declared on: line 166 of Lua/entities/rat.lua.

function Rat:_emerge()

Play the leaving-hole animation when emerging from a north hole, then run. Other walls have no leaving animation, so the rat sets off immediately.

Declared on: line 93 of Lua/entities/rat.lua.

function Rat:_enterHole()

Play the entering-hole animation for the target hole's wall (north and west have one; east and south holes are hidden), then remove the rat.

Declared on: line 222 of Lua/entities/rat.lua.

function Rat:_isCorridorPath(xs, ys)

Whether every tile on the given path is corridor (not inside a room), so the rat stays out of rooms and never squeezes through closed doors -- matching the original game, where rats scurry only in corridors.

Parameters:

NameTypeDescription
xs list Path tile X coordinates.
ys list Path tile Y coordinates.

Declared on: line 150 of Lua/entities/rat.lua.

function Rat:_walkToNextTile()

Walk the rat one tile further along its path, mirroring how humanoids move (see `action_walk_raw`). The rat animates across a single tile over `walk_quantity` ticks, then this runs again for the following tile until the destination hole is reached. Keeping the tile position authoritative means the rat stays clickable and detectable on the entity map.

Declared on: line 180 of Lua/entities/rat.lua.

function Rat:init(origin_wall)

Send the rat scurrying from its hole, along the corridors, to another rathole where it disappears.

to pick the leaving animation (only north holes have one).

Parameters:

NameTypeDescription
origin_wall string or or or nil The wall of the hole it emerges from, used

Declared on: line 78 of Lua/entities/rat.lua.

function Rat:onClick(ui, button)

Shoot the rat on left-click: play the sounds, leave a dead-rat splat where it was, and remove it. Guarded so a stale cursor entity cannot shoot the same rat twice.

Parameters:

NameTypeDescription
ui GameUI The game UI.
button string The mouse button used.

Declared on: line 238 of Lua/entities/rat.lua.