Potions
Terminal game3462 lines of .st2798 lines of generated Rust
================================ Health: 10 / 10 ===============================
Explore the Dungeon. Cursor keys to move.
;
;
";; ";
;;;; ;;
;;;;; ;
;;;;;; ;""
;;;;;;; ;;""
";;;;;"";;;;"
";;;@;;;;;;;;;"
";;;;;;"
"";;;;;;;
";;;;;;"
;;;"";;
;;;" ;;
;;";;
;; ;;
;On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "Rust"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
Screen = {
source = "StructOp/game"
version = "@latest"
}
}
}main.st
ability "call" "NewMap" {
function = ability.function.build_map
}
ability "call" "SpawnPlayer" {
function = ability.function.spawn_player
args = [data.value.player_start.current.x, data.value.player_start.current.y]
depends_on = [ability.call.NewMap]
}
ability "call" "SpawnAmulet" {
function = ability.function.spawn_amulet_of_yala
args = [data.value.amulet_start.current.x, data.value.amulet_start.current.y]
depends_on = [ability.call.SpawnPlayer]
}
ability "call" "SpawnMonsters" {
function = ability.function.spawn_monsters
depends_on = [ability.call.SpawnAmulet]
}
ability "call" "NewCamera" {
function = ability.function.on_player_move
args = [data.value.player_start.current.x, data.value.player_start.current.y]
depends_on = [ability.call.SpawnMonsters]
}
ability "game" "Dungeon" {
title = "Dungeon Crawler"
width = const.DISPLAY_WIDTH
height = const.DISPLAY_HEIGHT
fps = 30
key = ability.value.key
on_tick = [ability.clear.Screen, ability.switch.Turn]
depends_on = [ability.call.NewCamera]
}
ability "clear" "Screen" {
}
ability "switch" "Turn" {
value = data.value.turn_state.current
cases = [
{ value = TurnState.AwaitingInput, run = [ability.call.InputSystems] },
{ value = TurnState.PlayerTurn, run = [ability.call.PlayerSystems] },
{ value = TurnState.MonsterTurn, run = [ability.call.MonsterSystems] },
{ value = TurnState.GameOver, run = [ability.call.GameOver] },
{ value = TurnState.Victory, run = [ability.call.Victory] },
]
}
ability "call" "InputSystems" {
function = ability.function.input_systems
}
ability "call" "PlayerSystems" {
function = ability.function.player_systems
}
ability "call" "MonsterSystems" {
function = ability.function.monster_systems
}
ability "call" "GameOver" {
function = ability.function.game_over
}
ability "call" "Victory" {
function = ability.function.victory
}vars.st
constant "SCREEN_WIDTH" {
type = Int
default = 80
}
constant "SCREEN_HEIGHT" {
type = Int
default = 50
}
constant "DISPLAY_WIDTH" {
type = Int
default = 80
}
constant "DISPLAY_HEIGHT" {
type = Int
default = 25
}
ability "value" "camera" {
type = Camera
}
data "value" "camera" {
of = ability.value.camera
}
# SCREEN_WIDTH * SCREEN_HEIGHT
constant "NUM_TILES" {
type = Int
default = 4000
}
ability "value" "tiles" {
type = Array
of = TileType
size = 4000
}
data "value" "tiles" {
of = ability.value.tiles
}
# map_builder.player_start
ability "value" "player_start" {
type = Point
}
data "value" "player_start" {
of = ability.value.player_start
}
constant "NUM_ROOMS" {
type = Int
default = 20
}
ability "value" "rooms" {
type = List
of = Rect
size = 20
}
data "value" "rooms" {
of = ability.value.rooms
}
# the sorted copy build_corridors works on
ability "value" "sorted" {
type = List
of = Rect
size = 20
}
data "value" "sorted" {
of = ability.value.sorted
}
ability "value" "key" {
type = Key
}
data "value" "key" {
of = ability.value.key
}
ability "value" "turn_state" {
type = TurnState
initial = TurnState.AwaitingInput
}
data "value" "turn_state" {
of = ability.value.turn_state
}
ability "value" "amulet_start" {
type = Point
}
data "value" "amulet_start" {
of = ability.value.amulet_start
}
# Map.revealed_tiles
ability "value" "revealed" {
type = Array
of = Bool
size = 4000
}
data "value" "revealed" {
of = ability.value.revealed
}
ability "value" "monster_spawns" {
type = List
of = Point
size = 64
}
data "value" "monster_spawns" {
of = ability.value.monster_spawns
}
ability "value" "spawnable_tiles" {
type = List
of = Point
size = 4000
}
data "value" "spawnable_tiles" {
of = ability.value.spawnable_tiles
}
ability "value" "new_tiles" {
type = Array
of = TileType
size = 4000
}
data "value" "new_tiles" {
of = ability.value.new_tiles
}
ability "value" "theme" {
type = MapTheme
initial = MapTheme.DungeonTheme
}
data "value" "theme" {
of = ability.value.theme
}automata.st
ability "function" "cellular_architect" {
locals = [{ name = "i", type = Int }, { name = "start", type = Int }, { name = "far", type = Int }]
body = [
ability.call.Noise,
ability.for.Iterations,
ability.set.FindStart,
ability.call.CellularSpawns,
ability.set.CellularStart,
ability.set.CellularFar,
ability.set.CellularAmulet,
]
}
ability "call" "Noise" {
function = ability.function.random_noise_map
}
ability "for" "Iterations" {
counter = i
from = 0
while = i < 10
next = i + 1
body = [ability.call.Iteration]
}
ability "call" "Iteration" {
function = ability.function.iteration
}
ability "set" "FindStart" {
target = start
value = find_start()
}
ability "call" "CellularSpawns" {
function = ability.function.spawn_spots
args = [start % const.SCREEN_WIDTH, start / const.SCREEN_WIDTH]
}
ability "set" "CellularStart" {
target = ability.value.player_start
value = {
x = start % const.SCREEN_WIDTH
y = start / const.SCREEN_WIDTH
}
}
ability "set" "CellularFar" {
target = far
value = find_most_distant()
}
ability "set" "CellularAmulet" {
target = ability.value.amulet_start
value = {
x = far % const.SCREEN_WIDTH
y = far / const.SCREEN_WIDTH
}
}
ability "function" "random_noise_map" {
locals = [{ name = "i", type = Int }, { name = "roll", type = Int }]
body = [ability.for.Noise]
}
ability "for" "Noise" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.random.Noise, ability.if.Noise]
}
ability "random" "Noise" {
target = roll
from = 0
to = 100
}
ability "if" "Noise" {
condition = roll > 55
then = [ability.set.NoiseFloor]
else = [ability.set.NoiseWall]
}
ability "set" "NoiseFloor" {
target = ability.value.tiles[i]
value = TileType.Floor
}
ability "set" "NoiseWall" {
target = ability.value.tiles[i]
value = TileType.Wall
}
ability "function" "count_neighbors" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
returns = Int
locals = [{ name = "neighbors", type = Int }, { name = "ix", type = Int }, { name = "iy", type = Int }]
body = [ability.set.NoNeighbors, ability.for.NeighborRows]
return = neighbors
}
ability "set" "NoNeighbors" {
target = neighbors
value = 0
}
ability "for" "NeighborRows" {
counter = iy
from = -1
while = iy <= 1
next = iy + 1
body = [ability.for.NeighborColumns]
}
ability "for" "NeighborColumns" {
counter = ix
from = -1
while = ix <= 1
next = ix + 1
body = [ability.if.Neighbor]
}
ability "if" "Neighbor" {
condition = !(ix == 0 && iy == 0) && data.value.tiles.current[map_idx(x + ix, y + iy)] == TileType.Wall
then = [ability.set.Neighbor]
}
ability "set" "Neighbor" {
target = neighbors
value = neighbors + 1
}
ability "function" "iteration" {
locals = [{ name = "i", type = Int }, { name = "x", type = Int }, { name = "y", type = Int }, { name = "neighbors", type = Int }]
body = [ability.for.CloneTiles, ability.for.LifeRows, ability.for.KeepTiles]
}
# let mut new_tiles = map.tiles.clone();
ability "for" "CloneTiles" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.set.CloneTile]
}
ability "set" "CloneTile" {
target = ability.value.new_tiles[i]
value = data.value.tiles.current[i]
}
ability "for" "LifeRows" {
counter = y
from = 1
while = y < const.SCREEN_HEIGHT - 1
next = y + 1
body = [ability.for.LifeColumns]
}
ability "for" "LifeColumns" {
counter = x
from = 1
while = x < const.SCREEN_WIDTH - 1
next = x + 1
body = [ability.set.Neighbors, ability.if.Crowded]
}
ability "set" "Neighbors" {
target = neighbors
value = count_neighbors(x, y)
}
ability "if" "Crowded" {
condition = neighbors > 4 || neighbors == 0
then = [ability.set.LifeWall]
else = [ability.set.LifeFloor]
}
ability "set" "LifeWall" {
target = ability.value.new_tiles[map_idx(x, y)]
value = TileType.Wall
}
ability "set" "LifeFloor" {
target = ability.value.new_tiles[map_idx(x, y)]
value = TileType.Floor
}
# map.tiles = new_tiles;
ability "for" "KeepTiles" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.set.KeepTile]
}
ability "set" "KeepTile" {
target = ability.value.tiles[i]
value = data.value.new_tiles.current[i]
}
# the floor tile closest to the centre (min_by keeps the first of equals)
ability "function" "find_start" {
returns = Int
locals = [{ name = "i", type = Int }, { name = "best", type = Int }, { name = "best_d", type = Int }, { name = "d", type = Int }]
body = [ability.set.NoStart, ability.for.Closest]
return = best
}
ability "set" "NoStart" {
target = best
value = -1
}
ability "for" "Closest" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.if.FloorTile]
}
ability "if" "FloorTile" {
condition = data.value.tiles.current[i] == TileType.Floor
then = [ability.set.CentreDistance, ability.if.Closer]
}
ability "set" "CentreDistance" {
target = d
value = (i % const.SCREEN_WIDTH - const.SCREEN_WIDTH / 2) * (i % const.SCREEN_WIDTH - const.SCREEN_WIDTH / 2) + (i / const.SCREEN_WIDTH - const.SCREEN_HEIGHT / 2) * (i / const.SCREEN_WIDTH - const.SCREEN_HEIGHT / 2)
}
ability "if" "Closer" {
condition = best < 0 || d < best_d
then = [ability.set.Best, ability.set.BestD]
}
ability "set" "Best" {
target = best
value = i
}
ability "set" "BestD" {
target = best_d
value = d
}camera.st
ability "struct" "Camera" {
fields = [
{ name = "left_x", type = Int },
{ name = "right_x", type = Int },
{ name = "top_y", type = Int },
{ name = "bottom_y", type = Int },
]
}
# Camera::new(player_position) and on_player_move(player_position): centred on the player
ability "function" "on_player_move" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
body = [ability.set.Camera]
}
ability "set" "Camera" {
target = ability.value.camera
value = {
left_x = x - const.DISPLAY_WIDTH / 2
right_x = x + const.DISPLAY_WIDTH / 2
top_y = y - const.DISPLAY_HEIGHT / 2
bottom_y = y + const.DISPLAY_HEIGHT / 2
}
}components.st
# bracket-lib's Point is a component too
ability "component" "Point" {
fields = [{ name = "x", type = Int }, { name = "y", type = Int }]
}
# ColorPair plus glyph
ability "component" "Render" {
fields = [
{ name = "fg", type = Color },
{ name = "bg", type = Color },
{ name = "glyph", type = Char },
]
}
ability "component" "Player" {
}
ability "component" "Enemy" {
}
ability "component" "MovingRandomly" {
}
# legion's Entity: an entity's number
ability "type" "Entity" {
is = Int
}
# a message of intent: an entity with only this component
ability "component" "WantsToMove" {
fields = [{ name = "entity", type = Entity }, { name = "destination", type = Point }]
}
ability "component" "Health" {
fields = [{ name = "current", type = Int }, { name = "max", type = Int }]
}
# Name(pub String)
ability "component" "Name" {
fields = [{ name = "name", type = String }]
}
ability "component" "WantsToAttack" {
fields = [{ name = "attacker", type = Entity }, { name = "victim", type = Entity }]
}
ability "component" "ChasingPlayer" {
}
ability "component" "Item" {
}
ability "component" "AmuletOfYala" {
}
ability "component" "FieldOfView" {
fields = [
{ name = "visible_tiles", type = Array, of = Bool, size = 4000 },
{ name = "radius", type = Int },
{ name = "is_dirty", type = Bool },
]
}
ability "component" "ProvidesHealing" {
fields = [{ name = "amount", type = Int }]
}
ability "component" "ProvidesDungeonMap" {
}dijkstra.st
# Every step costs 1, so the map is a breadth-first fill from the start tile
# over tiles the player could enter (Map::get_available_exits), up to 1024 steps.
constant "UNREACHABLE" {
type = Int
default = 1000000
}
ability "value" "dijkstra" {
type = Array
of = Int
size = 4000
}
data "value" "dijkstra" {
of = ability.value.dijkstra
}
ability "value" "frontier" {
type = Array
of = Int
size = 4000
}
data "value" "frontier" {
of = ability.value.frontier
}
ability "function" "build_dijkstra" {
params = [{ name = "start", type = Int }]
locals = [
{ name = "i", type = Int },
{ name = "head", type = Int },
{ name = "tail", type = Int },
{ name = "idx", type = Int },
{ name = "x", type = Int },
{ name = "y", type = Int },
{ name = "d", type = Int },
]
body = [ability.for.Unreached, ability.set.StartDistance, ability.set.Head, ability.set.Push, ability.set.Tail, ability.loop.Fill]
}
ability "for" "Unreached" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.set.Unreached]
}
ability "set" "Unreached" {
target = ability.value.dijkstra[i]
value = const.UNREACHABLE
}
ability "set" "StartDistance" {
target = ability.value.dijkstra[start]
value = 0
}
ability "set" "Head" {
target = head
value = 0
}
ability "set" "Push" {
target = ability.value.frontier[0]
value = start
}
ability "set" "Tail" {
target = tail
value = 1
}
ability "loop" "Fill" {
condition = head < tail
body = [
ability.set.Pop,
ability.set.Next,
ability.set.FillX,
ability.set.FillY,
ability.set.Distance,
ability.if.Near,
]
}
ability "set" "Pop" {
target = idx
value = data.value.frontier.current[head]
}
ability "set" "Next" {
target = head
value = head + 1
}
ability "set" "FillX" {
target = x
value = idx % const.SCREEN_WIDTH
}
ability "set" "FillY" {
target = y
value = idx / const.SCREEN_WIDTH
}
ability "set" "Distance" {
target = d
value = data.value.dijkstra.current[idx] + 1
}
ability "if" "Near" {
condition = d <= 1024
then = [ability.call.ExitLeft, ability.call.ExitRight, ability.call.ExitUp, ability.call.ExitDown]
}
ability "call" "ExitLeft" {
function = ability.function.reach
args = [x - 1, y, d, address_of(tail)]
}
ability "call" "ExitRight" {
function = ability.function.reach
args = [x + 1, y, d, address_of(tail)]
}
ability "call" "ExitUp" {
function = ability.function.reach
args = [x, y - 1, d, address_of(tail)]
}
ability "call" "ExitDown" {
function = ability.function.reach
args = [x, y + 1, d, address_of(tail)]
}
# a tile the fill has not reached yet gets distance d and joins the frontier
ability "function" "reach" {
params = [
{ name = "x", type = Int },
{ name = "y", type = Int },
{ name = "d", type = Int },
{ name = "tail", type = Pointer, to = Int },
]
body = [ability.if.Reach]
}
ability "if" "Reach" {
condition = can_enter_tile(x, y) && data.value.dijkstra.current[map_idx(x, y)] > d
then = [ability.set.Reached, ability.set.Queue, ability.store.Grow]
}
ability "set" "Reached" {
target = ability.value.dijkstra[map_idx(x, y)]
value = d
}
ability "set" "Queue" {
target = ability.value.frontier[value_at(tail)]
value = map_idx(x, y)
}
ability "store" "Grow" {
pointer = tail
value = value_at(tail) + 1
}
# DijkstraMap::find_lowest_exit: the open neighbour with the smallest distance,
# the first one on ties (left, right, up, down); -1 when there is none
ability "function" "find_lowest_exit" {
params = [{ name = "idx", type = Int }]
returns = Int
locals = [{ name = "best", type = Int }]
body = [ability.set.NoExit, ability.call.TryLeft, ability.call.TryRight, ability.call.TryUp, ability.call.TryDown]
return = best
}
ability "set" "NoExit" {
target = best
value = -1
}
ability "call" "TryLeft" {
function = ability.function.try_exit
args = [idx % const.SCREEN_WIDTH - 1, idx / const.SCREEN_WIDTH, address_of(best)]
}
ability "call" "TryRight" {
function = ability.function.try_exit
args = [idx % const.SCREEN_WIDTH + 1, idx / const.SCREEN_WIDTH, address_of(best)]
}
ability "call" "TryUp" {
function = ability.function.try_exit
args = [idx % const.SCREEN_WIDTH, idx / const.SCREEN_WIDTH - 1, address_of(best)]
}
ability "call" "TryDown" {
function = ability.function.try_exit
args = [idx % const.SCREEN_WIDTH, idx / const.SCREEN_WIDTH + 1, address_of(best)]
}
ability "function" "try_exit" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }, { name = "best", type = Pointer, to = Int }]
body = [ability.if.Better]
}
ability "if" "Better" {
condition = can_enter_tile(x, y) && (value_at(best) < 0 || data.value.dijkstra.current[map_idx(x, y)] < data.value.dijkstra.current[value_at(best)])
then = [ability.store.Best]
}
ability "store" "Best" {
pointer = best
value = map_idx(x, y)
}drunkard.st
constant "STAGGER_DISTANCE" {
type = Int
default = 400
}
# NUM_TILES / 3
constant "DESIRED_FLOOR" {
type = Int
default = 1333
}
ability "function" "drunkard" {
params = [{ name = "sx", type = Int }, { name = "sy", type = Int }]
locals = [
{ name = "x", type = Int },
{ name = "y", type = Int },
{ name = "distance_staggered", type = Int },
{ name = "roll", type = Int },
]
body = [ability.set.DrunkX, ability.set.DrunkY, ability.set.NotStaggered, ability.loop.Stagger]
}
ability "set" "DrunkX" {
target = x
value = sx
}
ability "set" "DrunkY" {
target = y
value = sy
}
ability "set" "NotStaggered" {
target = distance_staggered
value = 0
}
ability "loop" "Stagger" {
condition = true
body = [
ability.set.Dig,
ability.random.Stagger,
ability.switch.Stagger,
ability.if.OffMap,
ability.set.Staggered,
ability.if.TooFar,
]
}
ability "set" "Dig" {
target = ability.value.tiles[map_idx(x, y)]
value = TileType.Floor
}
ability "random" "Stagger" {
target = roll
from = 0
to = 4
}
ability "switch" "Stagger" {
value = roll
cases = [
{ value = 0, run = [ability.set.StaggerLeft] },
{ value = 1, run = [ability.set.StaggerRight] },
{ value = 2, run = [ability.set.StaggerUp] },
]
default = [ability.set.StaggerDown]
}
ability "set" "StaggerLeft" {
target = x
value = x - 1
}
ability "set" "StaggerRight" {
target = x
value = x + 1
}
ability "set" "StaggerUp" {
target = y
value = y - 1
}
ability "set" "StaggerDown" {
target = y
value = y + 1
}
ability "if" "OffMap" {
condition = !in_bounds(x, y)
then = [ability.break.OffMap]
}
ability "break" "OffMap" {
}
ability "set" "Staggered" {
target = distance_staggered
value = distance_staggered + 1
}
ability "if" "TooFar" {
condition = distance_staggered > const.STAGGER_DISTANCE
then = [ability.break.TooFar]
}
ability "break" "TooFar" {
}
ability "function" "count_floor" {
returns = Int
locals = [{ name = "i", type = Int }, { name = "n", type = Int }]
body = [ability.set.NoFloor, ability.for.CountFloor]
return = n
}
ability "set" "NoFloor" {
target = n
value = 0
}
ability "for" "CountFloor" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.if.CountFloor]
}
ability "if" "CountFloor" {
condition = data.value.tiles.current[i] == TileType.Floor
then = [ability.set.CountFloor]
}
ability "set" "CountFloor" {
target = n
value = n + 1
}
ability "function" "drunkard_architect" {
locals = [{ name = "i", type = Int }, { name = "x", type = Int }, { name = "y", type = Int }, { name = "far", type = Int }]
body = [
ability.call.DrunkWalls,
ability.call.FirstDrunk,
ability.loop.MoreFloor,
ability.call.DrunkSpawns,
ability.set.DrunkStart,
ability.set.DrunkFar,
ability.set.DrunkAmulet,
]
}
ability "call" "DrunkWalls" {
function = ability.function.fill
args = [TileType.Wall]
}
ability "call" "FirstDrunk" {
function = ability.function.drunkard
args = [const.SCREEN_WIDTH / 2, const.SCREEN_HEIGHT / 2]
}
ability "loop" "MoreFloor" {
condition = count_floor() < const.DESIRED_FLOOR
body = [ability.random.DrunkX, ability.random.DrunkY, ability.call.NextDrunk, ability.call.DrunkDijkstra, ability.for.Unreachable]
}
ability "random" "DrunkX" {
target = x
from = 0
to = const.SCREEN_WIDTH
}
ability "random" "DrunkY" {
target = y
from = 0
to = const.SCREEN_HEIGHT
}
ability "call" "NextDrunk" {
function = ability.function.drunkard
args = [x, y]
}
ability "call" "DrunkDijkstra" {
function = ability.function.build_dijkstra
args = [map_idx(const.SCREEN_WIDTH / 2, const.SCREEN_HEIGHT / 2)]
}
# tiles the centre cannot reach become walls again
ability "for" "Unreachable" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.if.Unreachable]
}
ability "if" "Unreachable" {
condition = data.value.dijkstra.current[i] > 2000
then = [ability.set.Unreachable]
}
ability "set" "Unreachable" {
target = ability.value.tiles[i]
value = TileType.Wall
}
ability "call" "DrunkSpawns" {
function = ability.function.spawn_spots
args = [const.SCREEN_WIDTH / 2, const.SCREEN_HEIGHT / 2]
}
ability "set" "DrunkStart" {
target = ability.value.player_start
value = {
x = const.SCREEN_WIDTH / 2
y = const.SCREEN_HEIGHT / 2
}
}
ability "set" "DrunkFar" {
target = far
value = find_most_distant()
}
ability "set" "DrunkAmulet" {
target = ability.value.amulet_start
value = {
x = far % const.SCREEN_WIDTH
y = far / const.SCREEN_WIDTH
}
}empty.st
ability "function" "empty_architect" {
locals = [{ name = "i", type = Int }, { name = "x", type = Int }, { name = "y", type = Int }, { name = "far", type = Int }]
body = [
ability.call.FillFloors,
ability.set.EmptyStart,
ability.set.EmptyFar,
ability.set.EmptyAmulet,
ability.for.EmptySpawns,
]
}
ability "call" "FillFloors" {
function = ability.function.fill
args = [TileType.Floor]
}
ability "set" "EmptyStart" {
target = ability.value.player_start
value = {
x = const.SCREEN_WIDTH / 2
y = const.SCREEN_HEIGHT / 2
}
}
ability "set" "EmptyFar" {
target = far
value = find_most_distant()
}
ability "set" "EmptyAmulet" {
target = ability.value.amulet_start
value = {
x = far % const.SCREEN_WIDTH
y = far / const.SCREEN_WIDTH
}
}
ability "for" "EmptySpawns" {
counter = i
from = 0
while = i < 50
next = i + 1
body = [ability.random.SpawnX, ability.random.SpawnY, ability.add.EmptySpawn]
}
ability "random" "SpawnX" {
target = x
from = 1
to = const.SCREEN_WIDTH
}
ability "random" "SpawnY" {
target = y
from = 1
to = const.SCREEN_HEIGHT
}
ability "add" "EmptySpawn" {
list = ability.value.monster_spawns
value = {
x = x
y = y
}
}fov.st
# A tile is visible when it lies within the radius and the straight (Bresenham)
# line to it crosses no opaque tile; bracket-lib casts rays the same way.
# Every entity with a FieldOfView keeps its own visible_tiles.
ability "function" "is_opaque" {
params = [{ name = "idx", type = Int }]
returns = Bool
return = data.value.tiles.current[idx] != TileType.Floor
}
ability "function" "can_see" {
params = [
{ name = "x0", type = Int },
{ name = "y0", type = Int },
{ name = "x1", type = Int },
{ name = "y1", type = Int },
{ name = "radius", type = Int },
]
returns = Bool
locals = [
{ name = "x", type = Int },
{ name = "y", type = Int },
{ name = "dx", type = Int },
{ name = "dy", type = Int },
{ name = "sx", type = Int },
{ name = "sy", type = Int },
{ name = "err", type = Int },
{ name = "e2", type = Int },
{ name = "clear", type = Bool },
]
body = [
ability.set.LineX,
ability.set.LineY,
ability.set.LineDx,
ability.set.LineDy,
ability.set.LineSx,
ability.set.LineSy,
ability.set.LineErr,
ability.set.InRange,
ability.loop.Line,
]
return = clear
}
ability "set" "LineX" {
target = x
value = x0
}
ability "set" "LineY" {
target = y
value = y0
}
ability "set" "LineDx" {
target = dx
value = max(x1 - x0, x0 - x1)
}
ability "set" "LineDy" {
target = dy
value = -max(y1 - y0, y0 - y1)
}
ability "set" "LineSx" {
target = sx
value = int(x0 < x1) - int(x0 > x1)
}
ability "set" "LineSy" {
target = sy
value = int(y0 < y1) - int(y0 > y1)
}
ability "set" "LineErr" {
target = err
value = dx + dy
}
ability "set" "InRange" {
target = clear
value = dx * dx + dy * dy <= radius * radius
}
ability "loop" "Line" {
condition = clear && !(x == x1 && y == y1)
body = [ability.set.E2, ability.if.StepX, ability.if.StepY, ability.if.Blocked]
}
ability "set" "E2" {
target = e2
value = 2 * err
}
ability "if" "StepX" {
condition = e2 >= dy
then = [ability.set.ErrX, ability.set.MoveX]
}
ability "set" "ErrX" {
target = err
value = err + dy
}
ability "set" "MoveX" {
target = x
value = x + sx
}
ability "if" "StepY" {
condition = e2 <= dx
then = [ability.set.ErrY, ability.set.MoveY]
}
ability "set" "ErrY" {
target = err
value = err + dx
}
ability "set" "MoveY" {
target = y
value = y + sy
}
ability "if" "Blocked" {
condition = !(x == x1 && y == y1) && is_opaque(map_idx(x, y))
then = [ability.set.Blocked]
}
ability "set" "Blocked" {
target = clear
value = false
}
# fov.visible_tiles = field_of_view_set(*pos, fov.radius, map)
ability "function" "field_of_view_set" {
params = [{ name = "view", type = Pointer, to = FieldOfView }, { name = "px", type = Int }, { name = "py", type = Int }, { name = "radius", type = Int }]
locals = [{ name = "i", type = Int }, { name = "x", type = Int }, { name = "y", type = Int }]
body = [ability.for.Unseen, ability.for.FovRows]
}
ability "for" "Unseen" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.set.Unseen]
}
ability "set" "Unseen" {
target = view.visible_tiles[i]
value = false
}
ability "for" "FovRows" {
counter = y
from = py - radius
while = y <= py + radius
next = y + 1
body = [ability.for.FovColumns]
}
ability "for" "FovColumns" {
counter = x
from = px - radius
while = x <= px + radius
next = x + 1
body = [ability.if.Seen]
}
ability "if" "Seen" {
condition = in_bounds(x, y) && can_see(px, py, x, y, radius)
then = [ability.set.Seen]
}
ability "set" "Seen" {
target = view.visible_tiles[map_idx(x, y)]
value = true
}
ability "function" "fov" {
locals = [{ name = "viewer", type = Entity }]
body = [ability.query.Views]
}
ability "query" "Views" {
with = [Point, FieldOfView]
bind = {
pos = Point
view = FieldOfView
}
entity = viewer
body = [ability.if.Dirty]
}
ability "if" "Dirty" {
condition = view.is_dirty
then = [ability.call.ComputeFov, ability.set.Clean]
}
ability "call" "ComputeFov" {
function = ability.function.field_of_view_set
args = [view, pos.x, pos.y, view.radius]
}
ability "set" "Clean" {
target = view.is_dirty
value = false
}game_over.st
ability "function" "game_over" {
body = [
ability.text.QuestEnded,
ability.text.Slain,
ability.text.Unclaimed,
ability.text.TryAgain,
ability.text.PlayAgain,
ability.if.PlayAgain,
]
}
ability "text" "QuestEnded" {
y = 2
message = "Your quest has ended."
color = Color.red
}
ability "text" "Slain" {
y = 4
message = "Slain by a monster, your hero's journey has come to a premature end."
}
ability "text" "Unclaimed" {
y = 5
message = "The Amulet of Yala remains unclaimed, and your home town is not saved."
}
ability "text" "TryAgain" {
y = 8
message = "Don't worry, you can always try again with a new hero."
color = Color.yellow
}
ability "text" "PlayAgain" {
y = 9
message = "Press 1 to play again."
color = Color.green
}
ability "if" "PlayAgain" {
condition = data.value.key.current == Key.key1
then = [ability.call.Reset]
}
ability "call" "Reset" {
function = ability.function.reset_game_state
}
# a new World, Resources, map, player, monsters and camera
ability "function" "reset_game_state" {
body = [
ability.despawn_all.World,
ability.call.ResetMap,
ability.call.ResetPlayer,
ability.call.ResetAmulet,
ability.call.ResetMonsters,
ability.call.ResetCamera,
ability.set.ResetTurn,
]
}
ability "despawn_all" "World" {
}
ability "call" "ResetMap" {
function = ability.function.build_map
}
ability "call" "ResetPlayer" {
function = ability.function.spawn_player
args = [data.value.player_start.current.x, data.value.player_start.current.y]
}
ability "call" "ResetAmulet" {
function = ability.function.spawn_amulet_of_yala
args = [data.value.amulet_start.current.x, data.value.amulet_start.current.y]
}
ability "call" "ResetMonsters" {
function = ability.function.spawn_monsters
}
ability "call" "ResetCamera" {
function = ability.function.on_player_move
args = [data.value.player_start.current.x, data.value.player_start.current.y]
}
ability "set" "ResetTurn" {
target = ability.value.turn_state
value = TurnState.AwaitingInput
}
ability "function" "victory" {
body = [ability.text.Won, ability.text.PutOn, ability.text.Saved, ability.text.WonAgain, ability.if.WonAgain]
}
ability "text" "Won" {
y = 2
message = "You have won!"
color = Color.green
}
ability "text" "PutOn" {
y = 4
message = "You put on the Amulet of Yala and feel its power course through your veins."
}
ability "text" "Saved" {
y = 5
message = "Your town is saved, and you can return to your normal life."
}
ability "text" "WonAgain" {
y = 7
message = "Press 1 to play again."
color = Color.green
}
ability "if" "WonAgain" {
condition = data.value.key.current == Key.key1
then = [ability.call.ResetWon]
}
ability "call" "ResetWon" {
function = ability.function.reset_game_state
}map.st
ability "enum" "TileType" {
values = [Wall, Floor]
}
ability "function" "map_idx" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
returns = Int
return = y * const.SCREEN_WIDTH + x
}
# Map::new(): every tile a floor
ability "function" "new_map" {
locals = [{ name = "i", type = Int }]
body = [ability.for.Fill]
}
ability "for" "Fill" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.set.Floor]
}
ability "set" "Floor" {
target = ability.value.tiles[i]
value = TileType.Floor
}
ability "function" "map_render" {
locals = [{ name = "x", type = Int }, { name = "y", type = Int }, { name = "tint", type = Color }]
body = [ability.query.MapView]
}
# let player_fov = fov.iter(ecs).nth(0).unwrap();
ability "query" "MapView" {
with = [FieldOfView, Player]
bind = {
player_fov = FieldOfView
}
body = [ability.for.Rows]
}
ability "for" "Rows" {
counter = y
from = data.value.camera.current.top_y
while = y <= data.value.camera.current.bottom_y
next = y + 1
body = [ability.for.Columns]
}
ability "for" "Columns" {
counter = x
from = data.value.camera.current.left_x
while = x < data.value.camera.current.right_x
next = x + 1
body = [ability.if.Visible]
}
ability "if" "Visible" {
condition = in_bounds(x, y) && (player_fov.visible_tiles[map_idx(x, y)] || data.value.revealed.current[map_idx(x, y)])
then = [ability.if.Tint, ability.draw.Tile]
}
ability "if" "Tint" {
condition = player_fov.visible_tiles[map_idx(x, y)]
then = [ability.set.Bright]
else = [ability.set.Dim]
}
ability "set" "Bright" {
target = tint
value = Color.white
}
ability "set" "Dim" {
target = tint
value = Color.grey
}
ability "draw" "Tile" {
x = x - data.value.camera.current.left_x
y = y - data.value.camera.current.top_y
glyph = tile_to_render(data.value.theme.current, data.value.tiles.current[map_idx(x, y)])
color = tint
}
ability "function" "in_bounds" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
returns = Bool
return = x >= 0 && x < const.SCREEN_WIDTH && y >= 0 && y < const.SCREEN_HEIGHT
}
ability "function" "can_enter_tile" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
returns = Bool
return = in_bounds(x, y) && data.value.tiles.current[map_idx(x, y)] == TileType.Floor
}
# try_idx: Some(map_idx(x, y)) inside the map, None (-1) outside
ability "function" "try_idx" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
returns = Int
locals = [{ name = "idx", type = Int }]
body = [ability.set.NoIdx, ability.if.Inside]
return = idx
}
ability "set" "NoIdx" {
target = idx
value = -1
}
ability "if" "Inside" {
condition = in_bounds(x, y)
then = [ability.set.SomeIdx]
}
ability "set" "SomeIdx" {
target = idx
value = map_idx(x, y)
}map_builder.st
# bracket-lib's Rect, with_size(x, y, w, h): x2 = x1 + w, y2 = y1 + h
ability "struct" "Rect" {
fields = [
{ name = "x1", type = Int },
{ name = "y1", type = Int },
{ name = "x2", type = Int },
{ name = "y2", type = Int },
]
}
ability "function" "intersect" {
params = [{ name = "a", type = Pointer, to = Rect }, { name = "b", type = Pointer, to = Rect }]
returns = Bool
return = a.x1 <= b.x2 && a.x2 >= b.x1 && a.y1 <= b.y2 && a.y2 >= b.y1
}
ability "function" "fill" {
params = [{ name = "tile", type = TileType }]
locals = [{ name = "i", type = Int }]
body = [ability.for.FillAll]
}
ability "for" "FillAll" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.set.FillTile, ability.set.Unrevealed]
}
ability "set" "FillTile" {
target = ability.value.tiles[i]
value = tile
}
# Map::new(): nothing revealed yet
ability "set" "Unrevealed" {
target = ability.value.revealed[i]
value = false
}
ability "function" "build_random_rooms" {
locals = [
{ name = "room", type = Rect },
{ name = "overlap", type = Bool },
{ name = "r", type = Int },
{ name = "x", type = Int },
{ name = "y", type = Int },
{ name = "w", type = Int },
{ name = "h", type = Int },
]
body = [ability.loop.Rooms]
}
ability "loop" "Rooms" {
condition = length(data.value.rooms.current) < const.NUM_ROOMS
body = [
ability.random.RoomX,
ability.random.RoomY,
ability.random.RoomW,
ability.random.RoomH,
ability.set.Room,
ability.set.NoOverlap,
ability.for.Overlaps,
ability.if.Free,
]
}
ability "random" "RoomX" {
target = x
from = 1
to = const.SCREEN_WIDTH - 10
}
ability "random" "RoomY" {
target = y
from = 1
to = const.SCREEN_HEIGHT - 10
}
ability "random" "RoomW" {
target = w
from = 2
to = 10
}
ability "random" "RoomH" {
target = h
from = 2
to = 10
}
ability "set" "Room" {
target = room
value = {
x1 = x
y1 = y
x2 = x + w
y2 = y + h
}
}
ability "set" "NoOverlap" {
target = overlap
value = false
}
ability "for" "Overlaps" {
counter = r
from = 0
while = r < length(data.value.rooms.current)
next = r + 1
body = [ability.if.Intersects]
}
ability "if" "Intersects" {
condition = intersect(address_of(ability.value.rooms[r]), address_of(room))
then = [ability.set.Overlap]
}
ability "set" "Overlap" {
target = overlap
value = true
}
ability "if" "Free" {
condition = !overlap
then = [ability.for.RoomRows, ability.add.Room]
}
ability "for" "RoomRows" {
counter = y
from = room.y1
while = y < room.y2
next = y + 1
body = [ability.for.RoomColumns]
}
ability "for" "RoomColumns" {
counter = x
from = room.x1
while = x < room.x2
next = x + 1
body = [ability.if.OnMap]
}
ability "if" "OnMap" {
condition = x > 0 && x < const.SCREEN_WIDTH && y > 0 && y < const.SCREEN_HEIGHT
then = [ability.set.Carve]
}
ability "set" "Carve" {
target = ability.value.tiles[map_idx(x, y)]
value = TileType.Floor
}
ability "add" "Room" {
list = ability.value.rooms
value = room
}
ability "function" "apply_vertical_tunnel" {
params = [{ name = "y1", type = Int }, { name = "y2", type = Int }, { name = "x", type = Int }]
locals = [{ name = "y", type = Int }, { name = "idx", type = Int }]
body = [ability.for.Vertical]
}
ability "for" "Vertical" {
counter = y
from = min(y1, y2)
while = y <= max(y1, y2)
next = y + 1
body = [ability.set.VerticalIdx, ability.if.VerticalSome]
}
ability "set" "VerticalIdx" {
target = idx
value = try_idx(x, y)
}
ability "if" "VerticalSome" {
condition = idx >= 0
then = [ability.set.VerticalFloor]
}
ability "set" "VerticalFloor" {
target = ability.value.tiles[idx]
value = TileType.Floor
}
ability "function" "apply_horizontal_tunnel" {
params = [{ name = "x1", type = Int }, { name = "x2", type = Int }, { name = "y", type = Int }]
locals = [{ name = "x", type = Int }, { name = "idx", type = Int }]
body = [ability.for.Horizontal]
}
ability "for" "Horizontal" {
counter = x
from = min(x1, x2)
while = x <= max(x1, x2)
next = x + 1
body = [ability.set.HorizontalIdx, ability.if.HorizontalSome]
}
ability "set" "HorizontalIdx" {
target = idx
value = try_idx(x, y)
}
ability "if" "HorizontalSome" {
condition = idx >= 0
then = [ability.set.HorizontalFloor]
}
ability "set" "HorizontalFloor" {
target = ability.value.tiles[idx]
value = TileType.Floor
}
ability "function" "build_corridors" {
locals = [
{ name = "i", type = Int },
{ name = "j", type = Int },
{ name = "room", type = Rect },
{ name = "prev", type = Point },
{ name = "new", type = Point },
{ name = "coin", type = Int },
]
body = [ability.for.Copy, ability.for.Sort, ability.for.Connect]
}
# let mut rooms = self.rooms.clone();
ability "for" "Copy" {
counter = i
from = 0
while = i < length(data.value.rooms.current)
next = i + 1
body = [ability.add.Copy]
}
ability "add" "Copy" {
list = ability.value.sorted
value = data.value.rooms.current[i]
}
# rooms.sort_by(|a, b| a.center().x.cmp(&b.center().x)), as a stable insertion sort
ability "for" "Sort" {
counter = i
from = 1
while = i < length(data.value.sorted.current)
next = i + 1
body = [ability.set.Key, ability.set.Below, ability.loop.Shift, ability.set.Insert]
}
ability "set" "Key" {
target = room
value = data.value.sorted.current[i]
}
ability "set" "Below" {
target = j
value = i - 1
}
ability "loop" "Shift" {
condition = j >= 0 && (data.value.sorted.current[j].x1 + data.value.sorted.current[j].x2) / 2 > (room.x1 + room.x2) / 2
body = [ability.set.ShiftUp, ability.set.Lower]
}
ability "set" "ShiftUp" {
target = ability.value.sorted[j + 1]
value = data.value.sorted.current[j]
}
ability "set" "Lower" {
target = j
value = j - 1
}
ability "set" "Insert" {
target = ability.value.sorted[j + 1]
value = room
}
ability "for" "Connect" {
counter = i
from = 1
while = i < length(data.value.sorted.current)
next = i + 1
body = [ability.set.Prev, ability.set.New, ability.random.Coin, ability.if.Coin]
}
ability "set" "Prev" {
target = prev
value = {
x = (data.value.sorted.current[i - 1].x1 + data.value.sorted.current[i - 1].x2) / 2
y = (data.value.sorted.current[i - 1].y1 + data.value.sorted.current[i - 1].y2) / 2
}
}
ability "set" "New" {
target = new
value = {
x = (data.value.sorted.current[i].x1 + data.value.sorted.current[i].x2) / 2
y = (data.value.sorted.current[i].y1 + data.value.sorted.current[i].y2) / 2
}
}
ability "random" "Coin" {
target = coin
from = 0
to = 2
}
ability "if" "Coin" {
condition = coin == 1
then = [ability.call.HorizontalFirst, ability.call.VerticalSecond]
else = [ability.call.VerticalFirst, ability.call.HorizontalSecond]
}
ability "call" "HorizontalFirst" {
function = ability.function.apply_horizontal_tunnel
args = [prev.x, new.x, prev.y]
}
ability "call" "VerticalSecond" {
function = ability.function.apply_vertical_tunnel
args = [prev.y, new.y, new.x]
}
ability "call" "VerticalFirst" {
function = ability.function.apply_vertical_tunnel
args = [prev.y, new.y, prev.x]
}
ability "call" "HorizontalSecond" {
function = ability.function.apply_horizontal_tunnel
args = [prev.x, new.x, new.y]
}
# the reachable tile farthest from the player start (max_by keeps the last of equals)
ability "function" "find_most_distant" {
returns = Int
locals = [{ name = "i", type = Int }, { name = "far", type = Int }]
body = [ability.call.FromStart, ability.set.Far, ability.for.Farthest]
return = far
}
ability "call" "FromStart" {
function = ability.function.build_dijkstra
args = [map_idx(data.value.player_start.current.x, data.value.player_start.current.y)]
}
ability "set" "Far" {
target = far
value = map_idx(data.value.player_start.current.x, data.value.player_start.current.y)
}
ability "for" "Farthest" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.if.Farther]
}
ability "if" "Farther" {
condition = data.value.dijkstra.current[i] < const.UNREACHABLE && data.value.dijkstra.current[i] >= data.value.dijkstra.current[far]
then = [ability.set.Farther]
}
ability "set" "Farther" {
target = far
value = i
}
ability "function" "build_map" {
locals = [{ name = "roll", type = Int }]
body = [ability.empty.Rooms, ability.empty.Sorted, ability.empty.Spawns, ability.random.Architect, ability.switch.Architect, ability.call.Prefab, ability.random.Theme, ability.if.Theme]
}
ability "empty" "Rooms" {
list = ability.value.rooms
}
ability "empty" "Sorted" {
list = ability.value.sorted
}
ability "empty" "Spawns" {
list = ability.value.monster_spawns
}
# let mut architect: Box<dyn MapArchitect> = match rng.range(0, 3) { ... }
ability "random" "Architect" {
target = roll
from = 0
to = 3
}
ability "switch" "Architect" {
value = roll
cases = [
{ value = 0, run = [ability.call.Drunkard] },
{ value = 1, run = [ability.call.RoomsArchitect] },
]
default = [ability.call.Cellular]
}
ability "call" "Drunkard" {
function = ability.function.drunkard_architect
}
ability "call" "RoomsArchitect" {
function = ability.function.rooms_architect
}
ability "call" "Cellular" {
function = ability.function.cellular_architect
}
ability "call" "Prefab" {
function = ability.function.apply_prefab
}
# MapBuilder::spawn_monsters: 50 random floor tiles more than 10 tiles from start
ability "function" "spawn_spots" {
params = [{ name = "sx", type = Int }, { name = "sy", type = Int }]
locals = [{ name = "i", type = Int }, { name = "pick", type = Int }]
body = [ability.empty.Spawnable, ability.for.Spawnable, ability.for.Picks]
}
ability "empty" "Spawnable" {
list = ability.value.spawnable_tiles
}
ability "for" "Spawnable" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.if.Spawnable]
}
ability "if" "Spawnable" {
condition = data.value.tiles.current[i] == TileType.Floor && (i % const.SCREEN_WIDTH - sx) * (i % const.SCREEN_WIDTH - sx) + (i / const.SCREEN_WIDTH - sy) * (i / const.SCREEN_WIDTH - sy) > 100
then = [ability.add.Spawnable]
}
ability "add" "Spawnable" {
list = ability.value.spawnable_tiles
value = {
x = i % const.SCREEN_WIDTH
y = i / const.SCREEN_WIDTH
}
}
ability "for" "Picks" {
counter = i
from = 0
while = i < 50
next = i + 1
body = [ability.random.Pick, ability.add.Picked, ability.remove.Picked]
}
# rng.random_slice_index(&spawnable_tiles)
ability "random" "Pick" {
target = pick
from = 0
to = length(data.value.spawnable_tiles.current)
}
ability "add" "Picked" {
list = ability.value.monster_spawns
value = data.value.spawnable_tiles.current[pick]
}
ability "remove" "Picked" {
list = ability.value.spawnable_tiles
index = pick
}
# mb.theme = match rng.range(0, 2) { 0 => DungeonTheme::new(), _ => ForestTheme::new() }
ability "random" "Theme" {
target = roll
from = 0
to = 2
}
ability "if" "Theme" {
condition = roll == 0
then = [ability.set.DungeonTheme]
else = [ability.set.ForestTheme]
}
ability "set" "DungeonTheme" {
target = ability.value.theme
value = MapTheme.DungeonTheme
}
ability "set" "ForestTheme" {
target = ability.value.theme
value = MapTheme.ForestTheme
}prefab.st
# FORTRESS: - floor, # wall, M monster spawn; 12 wide, 11 high, rows after each line break
constant "FORTRESS" {
type = String
default = "\n------------\n---######---\n---#----#---\n---#-M--#---\n-###----###-\n--M------M--\n-###----###-\n---#----#---\n---#----#---\n---######---\n------------\n"
}
constant "FORTRESS_WIDTH" {
type = Int
default = 12
}
constant "FORTRESS_HEIGHT" {
type = Int
default = 11
}
ability "function" "apply_prefab" {
locals = [
{ name = "placed", type = Bool },
{ name = "px", type = Int },
{ name = "py", type = Int },
{ name = "attempts", type = Int },
{ name = "x", type = Int },
{ name = "y", type = Int },
{ name = "tx", type = Int },
{ name = "ty", type = Int },
{ name = "can_place", type = Bool },
{ name = "distance", type = Int },
{ name = "i", type = Int },
{ name = "c", type = Char },
]
body = [ability.set.NotPlaced, ability.call.PrefabDijkstra, ability.set.NoAttempts, ability.loop.Attempts, ability.if.Placed]
}
ability "set" "NotPlaced" {
target = placed
value = false
}
ability "call" "PrefabDijkstra" {
function = ability.function.build_dijkstra
args = [map_idx(data.value.player_start.current.x, data.value.player_start.current.y)]
}
ability "set" "NoAttempts" {
target = attempts
value = 0
}
ability "loop" "Attempts" {
condition = !placed && attempts < 10
body = [
ability.random.VaultX,
ability.random.VaultY,
ability.set.CannotPlace,
ability.for.VaultRows,
ability.if.CanPlace,
ability.set.Attempt,
]
}
ability "random" "VaultX" {
target = x
from = 0
to = const.SCREEN_WIDTH - const.FORTRESS_WIDTH
}
ability "random" "VaultY" {
target = y
from = 0
to = const.SCREEN_HEIGHT - const.FORTRESS_HEIGHT
}
ability "set" "CannotPlace" {
target = can_place
value = false
}
# dimensions.for_each(|pt| ...): any reachable tile 21 to 2000 steps away that is not the amulet
ability "for" "VaultRows" {
counter = ty
from = y
while = ty < y + const.FORTRESS_HEIGHT
next = ty + 1
body = [ability.for.VaultColumns]
}
ability "for" "VaultColumns" {
counter = tx
from = x
while = tx < x + const.FORTRESS_WIDTH
next = tx + 1
body = [ability.set.VaultDistance, ability.if.Fits]
}
ability "set" "VaultDistance" {
target = distance
value = data.value.dijkstra.current[map_idx(tx, ty)]
}
ability "if" "Fits" {
condition = distance < 2000 && distance > 20 && !(data.value.amulet_start.current.x == tx && data.value.amulet_start.current.y == ty)
then = [ability.set.CanPlace]
}
ability "set" "CanPlace" {
target = can_place
value = true
}
ability "if" "CanPlace" {
condition = can_place
then = [ability.set.Placed, ability.set.PlaceX, ability.set.PlaceY, ability.set.LastSpawn, ability.loop.Retain]
}
ability "set" "Placed" {
target = placed
value = true
}
ability "set" "PlaceX" {
target = px
value = x
}
ability "set" "PlaceY" {
target = py
value = y
}
# mb.monster_spawns.retain(|pt| !points.contains(pt)), from the end so removal keeps the index valid
ability "set" "LastSpawn" {
target = i
value = length(data.value.monster_spawns.current) - 1
}
ability "loop" "Retain" {
condition = i >= 0
body = [ability.if.InVault, ability.set.PrevSpawn]
}
ability "if" "InVault" {
condition = data.value.monster_spawns.current[i].x >= x && data.value.monster_spawns.current[i].x < x + const.FORTRESS_WIDTH && data.value.monster_spawns.current[i].y >= y && data.value.monster_spawns.current[i].y < y + const.FORTRESS_HEIGHT
then = [ability.remove.InVault]
}
ability "remove" "InVault" {
list = ability.value.monster_spawns
index = i
}
ability "set" "PrevSpawn" {
target = i
value = i - 1
}
ability "set" "Attempt" {
target = attempts
value = attempts + 1
}
ability "if" "Placed" {
condition = placed
then = [ability.set.FirstChar, ability.for.StampRows]
}
ability "set" "FirstChar" {
target = i
value = 0
}
ability "for" "StampRows" {
counter = ty
from = py
while = ty < py + const.FORTRESS_HEIGHT
next = ty + 1
body = [ability.for.StampColumns]
}
ability "for" "StampColumns" {
counter = tx
from = px
while = tx < px + const.FORTRESS_WIDTH
next = tx + 1
body = [ability.loop.SkipBreaks, ability.set.Char, ability.switch.Stamp, ability.set.NextChar]
}
# .filter(|a| *a != '\r' && *a != '\n'); a .st string holds no '\r'
ability "loop" "SkipBreaks" {
condition = const.FORTRESS[i] == "\n"
body = [ability.set.SkipBreak]
}
ability "set" "SkipBreak" {
target = i
value = i + 1
}
ability "set" "Char" {
target = c
value = const.FORTRESS[i]
}
ability "switch" "Stamp" {
value = c
cases = [
{ value = "M", run = [ability.set.MonsterFloor, ability.add.VaultSpawn] },
{ value = "-", run = [ability.set.VaultFloor] },
{ value = "#", run = [ability.set.VaultWall] },
]
default = [ability.print.Unknown]
}
ability "set" "MonsterFloor" {
target = ability.value.tiles[map_idx(tx, ty)]
value = TileType.Floor
}
ability "add" "VaultSpawn" {
list = ability.value.monster_spawns
value = {
x = tx
y = ty
}
}
ability "set" "VaultFloor" {
target = ability.value.tiles[map_idx(tx, ty)]
value = TileType.Floor
}
ability "set" "VaultWall" {
target = ability.value.tiles[map_idx(tx, ty)]
value = TileType.Wall
}
ability "print" "Unknown" {
message = "No idea what to do with [${c}]"
}
ability "set" "NextChar" {
target = i
value = i + 1
}rooms.st
ability "function" "rooms_architect" {
locals = [{ name = "i", type = Int }, { name = "far", type = Int }]
body = [
ability.call.FillWalls,
ability.call.Rooms,
ability.call.Corridors,
ability.set.Start,
ability.set.RoomsFar,
ability.set.RoomsAmulet,
ability.for.RoomSpawns,
]
}
ability "call" "FillWalls" {
function = ability.function.fill
args = [TileType.Wall]
}
ability "call" "Rooms" {
function = ability.function.build_random_rooms
}
ability "call" "Corridors" {
function = ability.function.build_corridors
}
ability "set" "Start" {
target = ability.value.player_start
value = {
x = (data.value.rooms.current[0].x1 + data.value.rooms.current[0].x2) / 2
y = (data.value.rooms.current[0].y1 + data.value.rooms.current[0].y2) / 2
}
}
ability "set" "RoomsFar" {
target = far
value = find_most_distant()
}
ability "set" "RoomsAmulet" {
target = ability.value.amulet_start
value = {
x = far % const.SCREEN_WIDTH
y = far / const.SCREEN_WIDTH
}
}
ability "for" "RoomSpawns" {
counter = i
from = 1
while = i < length(data.value.rooms.current)
next = i + 1
body = [ability.add.RoomSpawn]
}
ability "add" "RoomSpawn" {
list = ability.value.monster_spawns
value = {
x = (data.value.rooms.current[i].x1 + data.value.rooms.current[i].x2) / 2
y = (data.value.rooms.current[i].y1 + data.value.rooms.current[i].y2) / 2
}
}schedules.st
# each Schedule is a function calling its systems in order
ability "function" "input_systems" {
body = [ability.call.InputPlayerInput, ability.call.InputFov, ability.call.InputMapRender, ability.call.InputEntityRender, ability.call.InputHud]
}
ability "call" "InputPlayerInput" {
function = ability.function.player_input
}
ability "call" "InputMapRender" {
function = ability.function.map_render
}
ability "call" "InputEntityRender" {
function = ability.function.entity_render
}
ability "function" "player_systems" {
body = [ability.call.PlayerCombat, ability.call.PlayerMovement, ability.call.PlayerFov, ability.call.PlayerMapRender, ability.call.PlayerEntityRender, ability.call.PlayerHud, ability.call.PlayerEndTurn]
}
ability "call" "PlayerMovement" {
function = ability.function.movement
}
ability "call" "PlayerCombat" {
function = ability.function.combat
}
ability "call" "PlayerMapRender" {
function = ability.function.map_render
}
ability "call" "PlayerEntityRender" {
function = ability.function.entity_render
}
ability "call" "PlayerEndTurn" {
function = ability.function.end_turn
}
ability "function" "monster_systems" {
body = [ability.call.MonsterRandomMove, ability.call.MonsterChasing, ability.call.MonsterCombat, ability.call.MonsterMovement, ability.call.MonsterFov, ability.call.MonsterMapRender, ability.call.MonsterEntityRender, ability.call.MonsterHud, ability.call.MonsterEndTurn]
}
ability "call" "MonsterRandomMove" {
function = ability.function.random_move
}
ability "call" "MonsterMovement" {
function = ability.function.movement
}
ability "call" "MonsterMapRender" {
function = ability.function.map_render
}
ability "call" "MonsterEntityRender" {
function = ability.function.entity_render
}
ability "call" "MonsterEndTurn" {
function = ability.function.end_turn
}
ability "call" "InputHud" {
function = ability.function.hud
}
ability "call" "PlayerHud" {
function = ability.function.hud
}
ability "call" "MonsterHud" {
function = ability.function.hud
}
ability "call" "MonsterCombat" {
function = ability.function.combat
}
ability "call" "MonsterChasing" {
function = ability.function.chasing
}
ability "call" "InputFov" {
function = ability.function.fov
}
ability "call" "PlayerFov" {
function = ability.function.fov
}
ability "call" "MonsterFov" {
function = ability.function.fov
}spawner.st
ability "function" "spawn_player" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
body = [ability.spawn.Player]
}
ability "spawn" "Player" {
components = {
Player = {}
Point = {
x = x
y = y
}
Render = {
fg = Color.white
bg = Color.black
glyph = "@"
}
Health = {
current = 10
max = 10
}
FieldOfView = {
radius = 8
is_dirty = true
}
}
}
ability "function" "spawn_monster" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
locals = [{ name = "roll", type = Int }, { name = "hp", type = Int }, { name = "name", type = String }, { name = "glyph", type = Char }]
body = [ability.random.Dice, ability.if.Goblin, ability.spawn.Monster]
}
# rng.roll_dice(1, 10)
ability "random" "Dice" {
target = roll
from = 1
to = 11
}
ability "if" "Goblin" {
condition = roll <= 8
then = [ability.set.GoblinHp, ability.set.GoblinName, ability.set.GoblinGlyph]
else = [ability.set.OrcHp, ability.set.OrcName, ability.set.OrcGlyph]
}
ability "set" "GoblinHp" {
target = hp
value = 1
}
ability "set" "GoblinName" {
target = name
value = "Goblin"
}
ability "set" "GoblinGlyph" {
target = glyph
value = "g"
}
ability "set" "OrcHp" {
target = hp
value = 2
}
ability "set" "OrcName" {
target = name
value = "Orc"
}
ability "set" "OrcGlyph" {
target = glyph
value = "o"
}
ability "spawn" "Monster" {
components = {
Enemy = {}
Point = {
x = x
y = y
}
Render = {
fg = Color.white
bg = Color.black
glyph = glyph
}
ChasingPlayer = {}
Health = {
current = hp
max = hp
}
Name = {
name = name
}
FieldOfView = {
radius = 6
is_dirty = true
}
}
}
# map_builder.monster_spawns.iter().for_each(|pos| spawn_entity(...))
ability "function" "spawn_monsters" {
locals = [{ name = "i", type = Int }]
body = [ability.for.Spawns]
}
ability "for" "Spawns" {
counter = i
from = 0
while = i < length(data.value.monster_spawns.current)
next = i + 1
body = [ability.call.Monster]
}
ability "call" "Monster" {
function = ability.function.spawn_entity
args = [data.value.monster_spawns.current[i].x, data.value.monster_spawns.current[i].y]
}
ability "function" "spawn_amulet_of_yala" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
body = [ability.spawn.Amulet]
}
ability "spawn" "Amulet" {
components = {
Item = {}
AmuletOfYala = {}
Point = {
x = x
y = y
}
Render = {
fg = Color.white
bg = Color.black
glyph = "|"
}
Name = {
name = "Amulet of Yala"
}
}
}
ability "function" "spawn_healing_potion" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
body = [ability.spawn.HealingPotion]
}
ability "spawn" "HealingPotion" {
components = {
Item = {}
Point = {
x = x
y = y
}
Render = {
fg = Color.white
bg = Color.black
glyph = "!"
}
Name = {
name = "Healing Potion"
}
ProvidesHealing = {
amount = 6
}
}
}
ability "function" "spawn_magic_mapper" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
body = [ability.spawn.MagicMapper]
}
ability "spawn" "MagicMapper" {
components = {
Item = {}
Point = {
x = x
y = y
}
Render = {
fg = Color.white
bg = Color.black
glyph = "{"
}
Name = {
name = "Dungeon Map"
}
ProvidesDungeonMap = {}
}
}
ability "function" "spawn_entity" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
locals = [{ name = "roll", type = Int }]
body = [ability.random.Entity, ability.switch.Entity]
}
# rng.roll_dice(1, 6)
ability "random" "Entity" {
target = roll
from = 1
to = 7
}
ability "switch" "Entity" {
value = roll
cases = [
{ value = 1, run = [ability.call.HealingPotion] },
{ value = 2, run = [ability.call.MagicMapper] },
]
default = [ability.call.SpawnMonster]
}
ability "call" "HealingPotion" {
function = ability.function.spawn_healing_potion
args = [x, y]
}
ability "call" "MagicMapper" {
function = ability.function.spawn_magic_mapper
args = [x, y]
}
ability "call" "SpawnMonster" {
function = ability.function.spawn_monster
args = [x, y]
}systems.st
ability "function" "player_input" {
locals = [{ name = "delta", type = Point }, { name = "destination", type = Point }, { name = "player", type = Entity }, { name = "enemy", type = Entity }, { name = "hit_something", type = Bool }, { name = "did_something", type = Bool }]
body = [ability.switch.Move, ability.if.Moving]
}
ability "switch" "Move" {
value = data.value.key.current
cases = [
{ value = Key.left, run = [ability.set.Left] },
{ value = Key.right, run = [ability.set.Right] },
{ value = Key.up, run = [ability.set.Up] },
{ value = Key.down, run = [ability.set.Down] },
]
default = [ability.set.Zero]
}
ability "set" "Left" {
target = delta
value = {
x = -1
y = 0
}
}
ability "set" "Right" {
target = delta
value = {
x = 1
y = 0
}
}
ability "set" "Up" {
target = delta
value = {
x = 0
y = -1
}
}
ability "set" "Down" {
target = delta
value = {
x = 0
y = 1
}
}
ability "set" "Zero" {
target = delta
value = {
x = 0
y = 0
}
}
ability "if" "Moving" {
condition = data.value.key.current != Key.none
then = [ability.set.Idle, ability.query.Players, ability.if.Delta, ability.if.Idle, ability.set.PlayerTurn]
}
ability "query" "Players" {
with = [Point, Player]
bind = {
pos = Point
}
entity = player
body = [ability.set.Destination]
}
ability "set" "Destination" {
target = destination
value = {
x = pos.x + delta.x
y = pos.y + delta.y
}
}
ability "if" "Delta" {
condition = delta.x != 0 || delta.y != 0
then = [ability.set.NoHit, ability.query.Targets, ability.if.NoHit]
}
ability "set" "NoHit" {
target = hit_something
value = false
}
ability "query" "Targets" {
with = [Point, Enemy]
bind = {
pos = Point
}
entity = enemy
body = [ability.if.Target]
}
ability "if" "Target" {
condition = pos.x == destination.x && pos.y == destination.y
then = [ability.set.Hit, ability.set.DidAttack, ability.spawn.PlayerAttack]
}
ability "set" "Hit" {
target = hit_something
value = true
}
ability "set" "DidAttack" {
target = did_something
value = true
}
ability "spawn" "PlayerAttack" {
components = {
WantsToAttack = {
attacker = player
victim = enemy
}
}
}
ability "if" "NoHit" {
condition = !hit_something
then = [ability.set.DidMove, ability.spawn.PlayerMove]
}
ability "set" "DidMove" {
target = did_something
value = true
}
ability "spawn" "PlayerMove" {
components = {
WantsToMove = {
entity = player
destination = destination
}
}
}
ability "set" "Idle" {
target = did_something
value = false
}
# waiting a turn heals the player by one
ability "if" "Idle" {
condition = !did_something
then = [ability.query.Heal]
}
ability "query" "Heal" {
with = [Health]
only = player
bind = {
health = Health
}
body = [ability.set.Heal]
}
ability "set" "Heal" {
target = health.current
value = min(health.max, health.current + 1)
}
ability "set" "PlayerTurn" {
target = ability.value.turn_state
value = TurnState.PlayerTurn
}
ability "function" "combat" {
locals = [{ name = "message", type = Entity }, { name = "is_player", type = Bool }]
body = [ability.query.Attacks]
}
ability "query" "Attacks" {
with = [WantsToAttack]
bind = {
attack = WantsToAttack
}
entity = message
body = [ability.set.NotPlayer, ability.query.IsPlayer, ability.query.Victim, ability.despawn.Attack]
}
ability "set" "NotPlayer" {
target = is_player
value = false
}
ability "query" "IsPlayer" {
with = [Player]
only = attack.victim
body = [ability.set.IsPlayer]
}
ability "set" "IsPlayer" {
target = is_player
value = true
}
ability "query" "Victim" {
with = [Health]
only = attack.victim
bind = {
health = Health
}
body = [ability.print.Before, ability.set.Damage, ability.if.Dead, ability.print.After]
}
ability "print" "Before" {
message = "Health before attack: ${health.current}"
}
ability "set" "Damage" {
target = health.current
value = health.current - 1
}
ability "if" "Dead" {
condition = health.current < 1 && !is_player
then = [ability.despawn.Victim]
}
ability "despawn" "Victim" {
entity = attack.victim
}
ability "print" "After" {
message = "Health after attack: ${health.current}"
}
ability "despawn" "Attack" {
entity = message
}
ability "function" "movement" {
locals = [{ name = "message", type = Entity }, { name = "tile", type = Int }]
body = [ability.query.Moves]
}
ability "query" "Moves" {
with = [WantsToMove]
bind = {
want_move = WantsToMove
}
entity = message
body = [ability.if.CanMove, ability.despawn.Message]
}
ability "if" "CanMove" {
condition = can_enter_tile(want_move.destination.x, want_move.destination.y)
then = [ability.query.Mover, ability.query.MovedView, ability.query.MovedPlayer]
}
ability "query" "Mover" {
with = [Point]
only = want_move.entity
bind = {
pos = Point
}
body = [ability.store.Moved]
}
ability "store" "Moved" {
pointer = pos
value = want_move.destination
}
# fov.clone_dirty()
ability "query" "MovedView" {
with = [FieldOfView]
only = want_move.entity
bind = {
view = FieldOfView
}
body = [ability.set.MovedView]
}
ability "set" "MovedView" {
target = view.is_dirty
value = true
}
ability "query" "MovedPlayer" {
with = [Player, FieldOfView]
only = want_move.entity
bind = {
view = FieldOfView
}
body = [ability.call.MoveCamera, ability.for.Reveal]
}
# fov.visible_tiles.iter().for_each(|pos| map.revealed_tiles[...] = true)
ability "for" "Reveal" {
counter = tile
from = 0
while = tile < const.NUM_TILES
next = tile + 1
body = [ability.if.Reveal]
}
ability "if" "Reveal" {
condition = view.visible_tiles[tile]
then = [ability.set.Reveal]
}
ability "set" "Reveal" {
target = ability.value.revealed[tile]
value = true
}
ability "call" "MoveCamera" {
function = ability.function.on_player_move
args = [want_move.destination.x, want_move.destination.y]
}
ability "despawn" "Message" {
entity = message
}
ability "function" "entity_render" {
body = [ability.query.EntityView]
}
ability "query" "EntityView" {
with = [FieldOfView, Player]
bind = {
player_fov = FieldOfView
}
body = [ability.query.Rendered]
}
ability "query" "Rendered" {
with = [Point, Render]
bind = {
pos = Point
render = Render
}
body = [ability.if.InView]
}
ability "if" "InView" {
condition = player_fov.visible_tiles[map_idx(pos.x, pos.y)]
then = [ability.draw.Entity]
}
ability "draw" "Entity" {
x = pos.x - data.value.camera.current.left_x
y = pos.y - data.value.camera.current.top_y
glyph = render.glyph
color = render.fg
background = render.bg
}
ability "function" "random_move" {
locals = [{ name = "roll", type = Int }, { name = "destination", type = Point }, { name = "mover", type = Entity }, { name = "victim", type = Entity }, { name = "attacked", type = Bool }]
body = [ability.query.Movers]
}
ability "query" "Movers" {
with = [Point, MovingRandomly]
bind = {
pos = Point
}
entity = mover
body = [ability.random.Direction, ability.switch.Direction, ability.set.NotAttacked, ability.query.Positions, ability.if.NotAttacked]
}
ability "random" "Direction" {
target = roll
from = 0
to = 4
}
ability "switch" "Direction" {
value = roll
cases = [
{ value = 0, run = [ability.set.WanderLeft] },
{ value = 1, run = [ability.set.WanderRight] },
{ value = 2, run = [ability.set.WanderUp] },
]
default = [ability.set.WanderDown]
}
ability "set" "WanderLeft" {
target = destination
value = {
x = pos.x - 1
y = pos.y
}
}
ability "set" "WanderRight" {
target = destination
value = {
x = pos.x + 1
y = pos.y
}
}
ability "set" "WanderUp" {
target = destination
value = {
x = pos.x
y = pos.y - 1
}
}
ability "set" "WanderDown" {
target = destination
value = {
x = pos.x
y = pos.y + 1
}
}
ability "set" "NotAttacked" {
target = attacked
value = false
}
ability "query" "Positions" {
with = [Point, Health]
bind = {
target_pos = Point
}
entity = victim
body = [ability.if.AtDestination]
}
ability "if" "AtDestination" {
condition = target_pos.x == destination.x && target_pos.y == destination.y
then = [ability.query.VictimIsPlayer]
}
ability "query" "VictimIsPlayer" {
with = [Player]
only = victim
body = [ability.spawn.MonsterAttack, ability.set.Attacked]
}
ability "spawn" "MonsterAttack" {
components = {
WantsToAttack = {
attacker = mover
victim = victim
}
}
}
ability "set" "Attacked" {
target = attacked
value = true
}
ability "if" "NotAttacked" {
condition = !attacked
then = [ability.spawn.Wander]
}
ability "spawn" "Wander" {
components = {
WantsToMove = {
entity = mover
destination = destination
}
}
}
ability "function" "end_turn" {
locals = [{ name = "new_state", type = TurnState }, { name = "amulet_pos", type = Point }]
body = [ability.switch.EndTurn, ability.query.Amulet, ability.query.PlayerHp, ability.set.NewState]
}
ability "switch" "EndTurn" {
value = data.value.turn_state.current
cases = [
{ value = TurnState.AwaitingInput, run = [ability.return.Waiting] },
{ value = TurnState.PlayerTurn, run = [ability.set.MonsterTurn] },
{ value = TurnState.MonsterTurn, run = [ability.set.AwaitingInput] },
]
default = [ability.set.SameState]
}
ability "return" "Waiting" {
}
ability "set" "MonsterTurn" {
target = new_state
value = TurnState.MonsterTurn
}
ability "set" "AwaitingInput" {
target = new_state
value = TurnState.AwaitingInput
}
ability "set" "SameState" {
target = new_state
value = data.value.turn_state.current
}
ability "query" "Amulet" {
with = [Point, AmuletOfYala]
bind = {
pos = Point
}
body = [ability.set.AmuletPos]
}
ability "set" "AmuletPos" {
target = amulet_pos
value = value_at(pos)
}
ability "query" "PlayerHp" {
with = [Health, Point, Player]
bind = {
hp = Health
pos = Point
}
body = [ability.if.Slain, ability.if.Found]
}
ability "if" "Found" {
condition = pos.x == amulet_pos.x && pos.y == amulet_pos.y
then = [ability.set.Victory]
}
ability "set" "Victory" {
target = new_state
value = TurnState.Victory
}
ability "if" "Slain" {
condition = hp.current < 1
then = [ability.set.GameOver]
}
ability "set" "GameOver" {
target = new_state
value = TurnState.GameOver
}
ability "set" "NewState" {
target = ability.value.turn_state
value = new_state
}
ability "function" "hud" {
body = [ability.query.PlayerHealth]
}
ability "query" "PlayerHealth" {
with = [Health, Player]
bind = {
health = Health
}
body = [ability.text.Help, ability.bar.Health, ability.text.Health]
}
ability "text" "Help" {
y = 1
message = "Explore the Dungeon. Cursor keys to move."
}
ability "bar" "Health" {
x = 0
y = 0
width = const.DISPLAY_WIDTH
value = health.current
max = health.max
color = Color.red
}
ability "text" "Health" {
y = 0
message = " Health: ${health.current} / ${health.max} "
background = Color.red
}
ability "function" "chasing" {
locals = [
{ name = "player_pos", type = Point },
{ name = "chaser", type = Entity },
{ name = "victim", type = Entity },
{ name = "exit", type = Int },
{ name = "destination", type = Point },
{ name = "attacked", type = Bool },
]
body = [ability.query.ChaseTarget, ability.call.Dijkstra, ability.query.Chasers]
}
ability "query" "ChaseTarget" {
with = [Point, Player]
bind = {
pos = Point
}
body = [ability.set.ChaseTarget]
}
ability "set" "ChaseTarget" {
target = player_pos
value = value_at(pos)
}
ability "call" "Dijkstra" {
function = ability.function.build_dijkstra
args = [map_idx(player_pos.x, player_pos.y)]
}
ability "query" "Chasers" {
with = [Point, ChasingPlayer, FieldOfView]
bind = {
pos = Point
view = FieldOfView
}
entity = chaser
body = [ability.if.SeesPlayer]
}
# if !fov.visible_tiles.contains(&player_pos) { return; }
ability "if" "SeesPlayer" {
condition = view.visible_tiles[map_idx(player_pos.x, player_pos.y)]
then = [ability.set.Exit, ability.if.HasExit]
}
ability "set" "Exit" {
target = exit
value = find_lowest_exit(map_idx(pos.x, pos.y))
}
ability "if" "HasExit" {
condition = exit >= 0
then = [ability.if.Far, ability.set.ChaseNotAttacked, ability.query.ChaseVictims, ability.if.ChaseMove]
}
# distance2d(pos, player_pos) > 1.2: not orthogonally next to the player
ability "if" "Far" {
condition = (pos.x - player_pos.x) * (pos.x - player_pos.x) + (pos.y - player_pos.y) * (pos.y - player_pos.y) > 1
then = [ability.set.ToExit]
else = [ability.set.ToPlayer]
}
ability "set" "ToExit" {
target = destination
value = {
x = exit % const.SCREEN_WIDTH
y = exit / const.SCREEN_WIDTH
}
}
ability "set" "ToPlayer" {
target = destination
value = player_pos
}
ability "set" "ChaseNotAttacked" {
target = attacked
value = false
}
ability "query" "ChaseVictims" {
with = [Point, Health]
bind = {
target_pos = Point
}
entity = victim
body = [ability.if.ChaseAt]
}
ability "if" "ChaseAt" {
condition = target_pos.x == destination.x && target_pos.y == destination.y
then = [ability.query.ChaseIsPlayer]
}
ability "query" "ChaseIsPlayer" {
with = [Player]
only = victim
body = [ability.spawn.ChaseAttack, ability.set.ChaseAttacked]
}
ability "spawn" "ChaseAttack" {
components = {
WantsToAttack = {
attacker = chaser
victim = victim
}
}
}
ability "set" "ChaseAttacked" {
target = attacked
value = true
}
ability "if" "ChaseMove" {
condition = !attacked
then = [ability.spawn.ChaseMove]
}
ability "spawn" "ChaseMove" {
components = {
WantsToMove = {
entity = chaser
destination = destination
}
}
}themes.st
# trait MapTheme with DungeonTheme and ForestTheme: an enum and one function
ability "enum" "MapTheme" {
values = [DungeonTheme, ForestTheme]
}
ability "function" "tile_to_render" {
params = [{ name = "theme", type = MapTheme }, { name = "tile_type", type = TileType }]
returns = Char
locals = [{ name = "glyph", type = Char }]
body = [ability.switch.Theme]
return = glyph
}
ability "switch" "Theme" {
value = theme
cases = [
{ value = MapTheme.DungeonTheme, run = [ability.switch.DungeonTile] },
{ value = MapTheme.ForestTheme, run = [ability.switch.ForestTile] },
]
}
ability "switch" "DungeonTile" {
value = tile_type
cases = [
{ value = TileType.Floor, run = [ability.set.DungeonFloor] },
{ value = TileType.Wall, run = [ability.set.DungeonWall] },
]
}
ability "set" "DungeonFloor" {
target = glyph
value = "."
}
ability "set" "DungeonWall" {
target = glyph
value = "#"
}
ability "switch" "ForestTile" {
value = tile_type
cases = [
{ value = TileType.Floor, run = [ability.set.ForestFloor] },
{ value = TileType.Wall, run = [ability.set.ForestWall] },
]
}
ability "set" "ForestFloor" {
target = glyph
value = ";"
}
ability "set" "ForestWall" {
target = glyph
value = "\""
}turn_state.st
ability "enum" "TurnState" {
values = [AwaitingInput, PlayerTurn, MonsterTurn, GameOver, Victory]
}Input, plan and generated Rust#
input.txt · key script, one line per frame (11 lines)
input.txt · key script, one line per frame (11 lines)
left
left
upstructop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.function.cellular_architect
+ ability.call.Noise
+ ability.for.Iterations
+ ability.call.Iteration
+ ability.set.FindStart
+ ability.call.CellularSpawns
+ ability.set.CellularStart
+ ability.set.CellularFar
+ ability.set.CellularAmulet
+ ability.function.random_noise_map
+ ability.for.Noise
+ ability.random.Noise
+ ability.if.Noise
+ ability.set.NoiseFloor
+ ability.set.NoiseWall
+ ability.function.count_neighbors
+ ability.set.NoNeighbors
+ ability.for.NeighborRows
+ ability.for.NeighborColumns
+ ability.if.Neighbor
+ ability.set.Neighbor
+ ability.function.iteration
+ ability.for.CloneTiles
+ ability.set.CloneTile
+ ability.for.LifeRows
+ ability.for.LifeColumns
+ ability.set.Neighbors
+ ability.if.Crowded
+ ability.set.LifeWall
+ ability.set.LifeFloor
+ ability.for.KeepTiles
+ ability.set.KeepTile
+ ability.function.find_start
+ ability.set.NoStart
+ ability.for.Closest
+ ability.if.FloorTile
+ ability.set.CentreDistance
+ ability.if.Closer
+ ability.set.Best
+ ability.set.BestD
+ ability.struct.Camera
+ ability.function.on_player_move
+ ability.set.Camera
+ ability.component.Point
+ ability.component.Render
+ ability.component.Player
+ ability.component.Enemy
+ ability.component.MovingRandomly
+ ability.type.Entity
+ ability.component.WantsToMove
+ ability.component.Health
+ ability.component.Name
+ ability.component.WantsToAttack
+ ability.component.ChasingPlayer
+ ability.component.Item
+ ability.component.AmuletOfYala
+ ability.component.FieldOfView
+ ability.component.ProvidesHealing
+ ability.component.ProvidesDungeonMap
+ ability.value.dijkstra
+ ability.value.frontier
+ ability.function.build_dijkstra
+ ability.for.Unreached
+ ability.set.Unreached
+ ability.set.StartDistance
+ ability.set.Head
+ ability.set.Push
+ ability.set.Tail
+ ability.loop.Fill
+ ability.set.Pop
+ ability.set.Next
+ ability.set.FillX
+ ability.set.FillY
+ ability.set.Distance
+ ability.if.Near
+ ability.call.ExitLeft
+ ability.call.ExitRight
+ ability.call.ExitUp
+ ability.call.ExitDown
+ ability.function.reach
+ ability.if.Reach
+ ability.set.Reached
+ ability.set.Queue
+ ability.store.Grow
+ ability.function.find_lowest_exit
+ ability.set.NoExit
+ ability.call.TryLeft
+ ability.call.TryRight
+ ability.call.TryUp
+ ability.call.TryDown
+ ability.function.try_exit
+ ability.if.Better
+ ability.store.Best
+ ability.function.drunkard
+ ability.set.DrunkX
+ ability.set.DrunkY
+ ability.set.NotStaggered
+ ability.loop.Stagger
+ ability.set.Dig
+ ability.random.Stagger
+ ability.switch.Stagger
+ ability.set.StaggerLeft
+ ability.set.StaggerRight
+ ability.set.StaggerUp
+ ability.set.StaggerDown
+ ability.if.OffMap
+ ability.break.OffMap
+ ability.set.Staggered
+ ability.if.TooFar
+ ability.break.TooFar
+ ability.function.count_floor
+ ability.set.NoFloor
+ ability.for.CountFloor
+ ability.if.CountFloor
+ ability.set.CountFloor
+ ability.function.drunkard_architect
+ ability.call.DrunkWalls
+ ability.call.FirstDrunk
+ ability.loop.MoreFloor
+ ability.random.DrunkX
+ ability.random.DrunkY
+ ability.call.NextDrunk
+ ability.call.DrunkDijkstra
+ ability.for.Unreachable
+ ability.if.Unreachable
+ ability.set.Unreachable
+ ability.call.DrunkSpawns
+ ability.set.DrunkStart
+ ability.set.DrunkFar
+ ability.set.DrunkAmulet
+ ability.function.empty_architect
+ ability.call.FillFloors
+ ability.set.EmptyStart
+ ability.set.EmptyFar
+ ability.set.EmptyAmulet
+ ability.for.EmptySpawns
+ ability.random.SpawnX
+ ability.random.SpawnY
+ ability.add.EmptySpawn
+ ability.function.is_opaque
+ ability.function.can_see
+ ability.set.LineX
+ ability.set.LineY
+ ability.set.LineDx
+ ability.set.LineDy
+ ability.set.LineSx
+ ability.set.LineSy
+ ability.set.LineErr
+ ability.set.InRange
+ ability.loop.Line
+ ability.set.E2
+ ability.if.StepX
+ ability.set.ErrX
+ ability.set.MoveX
+ ability.if.StepY
+ ability.set.ErrY
+ ability.set.MoveY
+ ability.if.Blocked
+ ability.set.Blocked
+ ability.function.field_of_view_set
+ ability.for.Unseen
+ ability.set.Unseen
+ ability.for.FovRows
+ ability.for.FovColumns
+ ability.if.Seen
+ ability.set.Seen
+ ability.function.fov
+ ability.query.Views
+ ability.if.Dirty
+ ability.call.ComputeFov
+ ability.set.Clean
+ ability.function.game_over
+ ability.text.QuestEnded
+ ability.text.Slain
+ ability.text.Unclaimed
+ ability.text.TryAgain
+ ability.text.PlayAgain
+ ability.if.PlayAgain
+ ability.call.Reset
+ ability.function.reset_game_state
+ ability.despawn_all.World
+ ability.call.ResetMap
+ ability.call.ResetPlayer
+ ability.call.ResetAmulet
+ ability.call.ResetMonsters
+ ability.call.ResetCamera
+ ability.set.ResetTurn
+ ability.function.victory
+ ability.text.Won
+ ability.text.PutOn
+ ability.text.Saved
+ ability.text.WonAgain
+ ability.if.WonAgain
+ ability.call.ResetWon
+ ability.call.NewMap
+ ability.call.SpawnPlayer
+ ability.call.SpawnAmulet
+ ability.call.SpawnMonsters
+ ability.call.NewCamera
+ ability.game.Dungeon
+ ability.clear.Screen
+ ability.switch.Turn
+ ability.call.InputSystems
+ ability.call.PlayerSystems
+ ability.call.MonsterSystems
+ ability.call.GameOver
+ ability.call.Victory
+ ability.enum.TileType
+ ability.function.map_idx
+ ability.function.new_map
+ ability.for.Fill
+ ability.set.Floor
+ ability.function.map_render
+ ability.query.MapView
+ ability.for.Rows
+ ability.for.Columns
+ ability.if.Visible
+ ability.if.Tint
+ ability.set.Bright
+ ability.set.Dim
+ ability.draw.Tile
+ ability.function.in_bounds
+ ability.function.can_enter_tile
+ ability.function.try_idx
+ ability.set.NoIdx
+ ability.if.Inside
+ ability.set.SomeIdx
+ ability.struct.Rect
+ ability.function.intersect
+ ability.function.fill
+ ability.for.FillAll
+ ability.set.FillTile
+ ability.set.Unrevealed
+ ability.function.build_random_rooms
+ ability.loop.Rooms
+ ability.random.RoomX
+ ability.random.RoomY
+ ability.random.RoomW
+ ability.random.RoomH
+ ability.set.Room
+ ability.set.NoOverlap
+ ability.for.Overlaps
+ ability.if.Intersects
+ ability.set.Overlap
+ ability.if.Free
+ ability.for.RoomRows
+ ability.for.RoomColumns
+ ability.if.OnMap
+ ability.set.Carve
+ ability.add.Room
+ ability.function.apply_vertical_tunnel
+ ability.for.Vertical
+ ability.set.VerticalIdx
+ ability.if.VerticalSome
+ ability.set.VerticalFloor
+ ability.function.apply_horizontal_tunnel
+ ability.for.Horizontal
+ ability.set.HorizontalIdx
+ ability.if.HorizontalSome
+ ability.set.HorizontalFloor
+ ability.function.build_corridors
+ ability.for.Copy
+ ability.add.Copy
+ ability.for.Sort
+ ability.set.Key
+ ability.set.Below
+ ability.loop.Shift
+ ability.set.ShiftUp
+ ability.set.Lower
+ ability.set.Insert
+ ability.for.Connect
+ ability.set.Prev
+ ability.set.New
+ ability.random.Coin
+ ability.if.Coin
+ ability.call.HorizontalFirst
+ ability.call.VerticalSecond
+ ability.call.VerticalFirst
+ ability.call.HorizontalSecond
+ ability.function.find_most_distant
+ ability.call.FromStart
+ ability.set.Far
+ ability.for.Farthest
+ ability.if.Farther
+ ability.set.Farther
+ ability.function.build_map
+ ability.empty.Rooms
+ ability.empty.Sorted
+ ability.empty.Spawns
+ ability.random.Architect
+ ability.switch.Architect
+ ability.call.Drunkard
+ ability.call.RoomsArchitect
+ ability.call.Cellular
+ ability.call.Prefab
+ ability.function.spawn_spots
+ ability.empty.Spawnable
+ ability.for.Spawnable
+ ability.if.Spawnable
+ ability.add.Spawnable
+ ability.for.Picks
+ ability.random.Pick
+ ability.add.Picked
+ ability.remove.Picked
+ ability.random.Theme
+ ability.if.Theme
+ ability.set.DungeonTheme
+ ability.set.ForestTheme
+ ability.function.apply_prefab
+ ability.set.NotPlaced
+ ability.call.PrefabDijkstra
+ ability.set.NoAttempts
+ ability.loop.Attempts
+ ability.random.VaultX
+ ability.random.VaultY
+ ability.set.CannotPlace
+ ability.for.VaultRows
+ ability.for.VaultColumns
+ ability.set.VaultDistance
+ ability.if.Fits
+ ability.set.CanPlace
+ ability.if.CanPlace
+ ability.set.Placed
+ ability.set.PlaceX
+ ability.set.PlaceY
+ ability.set.LastSpawn
+ ability.loop.Retain
+ ability.if.InVault
+ ability.remove.InVault
+ ability.set.PrevSpawn
+ ability.set.Attempt
+ ability.if.Placed
+ ability.set.FirstChar
+ ability.for.StampRows
+ ability.for.StampColumns
+ ability.loop.SkipBreaks
+ ability.set.SkipBreak
+ ability.set.Char
+ ability.switch.Stamp
+ ability.set.MonsterFloor
+ ability.add.VaultSpawn
+ ability.set.VaultFloor
+ ability.set.VaultWall
+ ability.print.Unknown
+ ability.set.NextChar
+ ability.function.rooms_architect
+ ability.call.FillWalls
+ ability.call.Rooms
+ ability.call.Corridors
+ ability.set.Start
+ ability.set.RoomsFar
+ ability.set.RoomsAmulet
+ ability.for.RoomSpawns
+ ability.add.RoomSpawn
+ ability.function.input_systems
+ ability.call.InputPlayerInput
+ ability.call.InputFov
+ ability.call.InputMapRender
+ ability.function.player_systems
+ ability.call.PlayerCombat
+ ability.call.PlayerMovement
+ ability.call.PlayerFov
+ ability.call.PlayerMapRender
+ ability.call.PlayerEntityRender
+ ability.function.monster_systems
+ ability.call.MonsterRandomMove
+ ability.call.MonsterChasing
+ ability.call.MonsterCombat
+ ability.call.MonsterMovement
+ ability.call.MonsterFov
+ ability.call.InputEntityRender
+ ability.call.PlayerHud
+ ability.call.MonsterMapRender
+ ability.call.MonsterEntityRender
+ ability.call.MonsterHud
+ ability.call.InputHud
+ ability.call.PlayerEndTurn
+ ability.call.MonsterEndTurn
+ ability.function.spawn_player
+ ability.spawn.Player
+ ability.function.spawn_monster
+ ability.random.Dice
+ ability.if.Goblin
+ ability.set.GoblinHp
+ ability.set.GoblinName
+ ability.set.GoblinGlyph
+ ability.set.OrcHp
+ ability.set.OrcName
+ ability.set.OrcGlyph
+ ability.spawn.Monster
+ ability.function.spawn_monsters
+ ability.for.Spawns
+ ability.call.Monster
+ ability.function.spawn_amulet_of_yala
+ ability.spawn.Amulet
+ ability.function.spawn_healing_potion
+ ability.spawn.HealingPotion
+ ability.function.spawn_magic_mapper
+ ability.spawn.MagicMapper
+ ability.function.spawn_entity
+ ability.random.Entity
+ ability.switch.Entity
+ ability.call.HealingPotion
+ ability.call.MagicMapper
+ ability.call.SpawnMonster
+ ability.function.player_input
+ ability.switch.Move
+ ability.set.Left
+ ability.set.Right
+ ability.set.Up
+ ability.set.Down
+ ability.set.Zero
+ ability.if.Moving
+ ability.set.Idle
+ ability.set.Destination
+ ability.query.Players
+ ability.set.NoHit
+ ability.query.Targets
+ ability.if.Target
+ ability.set.Hit
+ ability.set.DidAttack
+ ability.spawn.PlayerAttack
+ ability.if.NoHit
+ ability.set.DidMove
+ ability.spawn.PlayerMove
+ ability.if.Delta
+ ability.if.Idle
+ ability.query.Heal
+ ability.set.Heal
+ ability.set.PlayerTurn
+ ability.function.combat
+ ability.query.Attacks
+ ability.set.NotPlayer
+ ability.query.IsPlayer
+ ability.set.IsPlayer
+ ability.query.Victim
+ ability.print.Before
+ ability.set.Damage
+ ability.if.Dead
+ ability.despawn.Victim
+ ability.print.After
+ ability.despawn.Attack
+ ability.function.movement
+ ability.query.Moves
+ ability.if.CanMove
+ ability.query.Mover
+ ability.store.Moved
+ ability.query.MovedView
+ ability.set.MovedView
+ ability.query.MovedPlayer
+ ability.call.MoveCamera
+ ability.if.Reveal
+ ability.set.Reveal
+ ability.for.Reveal
+ ability.despawn.Message
+ ability.function.entity_render
+ ability.query.EntityView
+ ability.query.Rendered
+ ability.if.InView
+ ability.draw.Entity
+ ability.function.random_move
+ ability.query.Movers
+ ability.random.Direction
+ ability.switch.Direction
+ ability.set.WanderLeft
+ ability.set.WanderRight
+ ability.set.WanderUp
+ ability.set.WanderDown
+ ability.set.NotAttacked
+ ability.query.Positions
+ ability.if.AtDestination
+ ability.query.VictimIsPlayer
+ ability.spawn.MonsterAttack
+ ability.set.Attacked
+ ability.if.NotAttacked
+ ability.spawn.Wander
+ ability.function.end_turn
+ ability.switch.EndTurn
+ ability.return.Waiting
+ ability.set.MonsterTurn
+ ability.set.AwaitingInput
+ ability.set.SameState
+ ability.query.Amulet
+ ability.set.AmuletPos
+ ability.query.PlayerHp
+ ability.if.Slain
+ ability.set.Victory
+ ability.if.Found
+ ability.set.GameOver
+ ability.set.NewState
+ ability.function.hud
+ ability.query.PlayerHealth
+ ability.text.Help
+ ability.bar.Health
+ ability.text.Health
+ ability.function.chasing
+ ability.query.ChaseTarget
+ ability.set.ChaseTarget
+ ability.call.Dijkstra
+ ability.query.Chasers
+ ability.if.SeesPlayer
+ ability.set.Exit
+ ability.if.HasExit
+ ability.if.Far
+ ability.set.ToExit
+ ability.set.ToPlayer
+ ability.set.ChaseNotAttacked
+ ability.query.ChaseVictims
+ ability.if.ChaseAt
+ ability.query.ChaseIsPlayer
+ ability.spawn.ChaseAttack
+ ability.set.ChaseAttacked
+ ability.if.ChaseMove
+ ability.spawn.ChaseMove
+ ability.enum.MapTheme
+ ability.function.tile_to_render
+ ability.switch.Theme
+ ability.switch.DungeonTile
+ ability.set.DungeonFloor
+ ability.set.DungeonWall
+ ability.switch.ForestTile
+ ability.set.ForestFloor
+ ability.set.ForestWall
+ ability.enum.TurnState
+ ability.value.camera
+ ability.value.tiles
+ ability.value.player_start
+ ability.value.rooms
+ ability.value.sorted
+ ability.value.key
+ ability.value.turn_state
+ ability.value.amulet_start
+ ability.value.revealed
+ ability.value.monster_spawns
+ ability.value.spawnable_tiles
+ ability.value.new_tiles
+ ability.value.theme
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.rs
To inspect this generated file, select Rust in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd rust-potions # a folder holding the .st files above
structop init
structop plan
structop apply