kts.Tile

Name

kts.Tile – create a new Tile

Synopsis

tile =
    kts.Tile { 
        type = <"", "home", "door", "chest" or "barrel">,

        -- For all tile types:
        access = <access table (see below)>,
        connectivity_check = <integer>,
        control = <control or function>,
        depth = <integer>,
        graphic = <graphic>,
        hit_points = <function or integer>,
        items = <see description below>,
        on_activate = <function>,
        on_approach = <function>,
        on_destroy = <function>,
        on_hit = <function>,
        on_walk_over = <function>,
        on_withdraw = <function>,
        stairs_down = <"special", "north", "south", "east", "west">,
        tutorial = <integer>,
        map_as = <"wall", "floor">,

        -- For type = "home":
        facing = <"north", "south", "east", "west">,
        special_exit = <boolean>,
        unsecured_colour = <integer>,

        -- For type = "door" or "chest":
        open = <boolean>,
        open_graphic = <graphic>,
        lock_chance = <number between 0.0 and 1.0>,
        lock_pick_only_chance = <number between 0.0 and 1.0>,
        keymax = <integer>,
        special_lock = <boolean>,
        on_open_or_close = <function>,
        on_unlock_fail = <function>,

        -- Additionally for type = "chest":
        facing = <"north", "south", "east", "west">,
        trap_chance = <number between 0.0 and 1.0>,
        traps = <function>
    }

where:

<access table> = {
    "flying" = <access type>,
    "missiles" = <access type>,
    "walking" = <access type>
}

<access type> = nil, "approach", "partial", "blocked", "clear"

All fields listed above also accept nil as a valid value.

Description

A "Tile" is an object representing the "terrain" within a particular square of the dungeon. A Tile might therefore represent a wall, a piece of floor, a treasure chest, etc. A given dungeon square can contain more than one Tile, for example a treasure chest tile might be overlaid on top of a floor tile.

The kts.Tile function creates a new Tile. The function takes one parameter, a table, which contains various properties that the new Tile should have. These are as follows:

Return Value

The new Tile (a Lua userdata object) will be returned.

Errors

There are several different errors that can be generated if any of the input parameters are incorrect.

Examples

A simple floor tile:

floor = kts.Tile {
    access = {
        walking = "clear",
        flying = "clear",
        missiles = "clear"
    },
    items = "floor",
    graphic = my_floor_graphic
}

A treasure chest:

chest = kts.Tile {
    type = "chest",

    graphic = my_graphic,   -- previously created by calling kts.Graphic
    open_graphic = my_open_graphic,
    facing = "north",
    depth = -4,

    items = "chest",
    access = {
        walking = "approach",
        flying = "clear",
        missiles = "clear"
    },
    trap_chance = 0.5,
    traps = function(pos, dir)
        if kts.RandomChance(0.5) then
            kts.SetPoisonTrap(pos, poison_trap_item)
        else
            kts.SetBladeTrap(pos, blade_trap_item, bolt_item, dir)
        end
    end,
    lock_chance = 0.5,
    lock_pick_only_chance = 0.16667,
    keymax = 3,
    hit_points = function() return kts.RandomRange(1, 20) end,
    control = my_control,  -- previously created by calling kts.Control

    -- Not shown here:
    -- functions on_open_or_close, on_unlock_fail, on_hit,
    -- which would typically play sound effects and/or show messages.
}

See Also

kts.Activate

kts.AddItem

kts.AddStuff

kts.CloseDoor

kts.ConnectivityCheck

kts.Control

kts.Graphic

kts.IsDoorOpen

kts.ItemType

kts.LoadSegments

kts.LockDoor

kts.OpenDoor

kts.OpenOrCloseDoor

kts.SetBladeTrap

kts.SetPoisonTrap