# HERB OS kernel program (generated from interactive_kernel.herb.json)

type proc.Process
  scope FD_FREE simple fs.FileDescriptor
  scope FD_OPEN simple fs.FileDescriptor
  scope INBOX simple ipc.Message
  scope OUTBOX simple ipc.Message
  scope PROCESSED simple ipc.Message
  scope MEM_FREE simple mem.Page
  scope MEM_USED simple mem.Page
  scope SURFACE slot display.Surface

type proc.Signal

type world.Player
  scope INVENTORY simple world.Tree

type world.TileInfo

type world.Tree

type world.GameSignal

type world.GameCtl

type world.NPC

type fs.FileDescriptor

type input.Char

type input.InputCtl

type input.ShellCtl

type input.KeyBind

type input.TextCmd

type input.TextArg

type input.MechBind

type ipc.Message

type mem.Page

type spawn.PriToken

type spawn.ProgToken

type spawn.SpawnCtl

type display.Surface

type display.DisplayCtl

type display.Legend

type wm.Window

type display.HelpCmd

type editor.Glyph

type editor.EditorCtl

container proc.READY simple proc.Process
container proc.CPU0 slot proc.Process
container proc.BLOCKED simple proc.Process
container proc.TERMINATED simple proc.Process
container proc.TIMER_SIG simple proc.Signal
container proc.KILL_SIG simple proc.Signal
container proc.BLOCK_SIG simple proc.Signal
container proc.UNBLOCK_SIG simple proc.Signal
container proc.BOOST_SIG simple proc.Signal
container proc.ALLOC_SIG simple proc.Signal
container proc.FREE_SIG simple proc.Signal
container proc.OPEN_SIG simple proc.Signal
container proc.CLOSE_SIG simple proc.Signal
container proc.SEND_SIG simple proc.Signal
container proc.RECV_SIG simple proc.Signal
container proc.CLICK_SIG simple proc.Signal
container proc.KEY_SIG simple proc.Signal
container proc.CMD_SIG simple proc.Signal
container proc.SPAWN_SIG simple proc.Signal
container proc.FOCUS_SIG simple proc.Signal
container proc.SIG_DONE simple proc.Signal
container world.PLAYER slot world.Player
container world.TILES simple world.TileInfo
container world.TREES simple world.Tree
container world.TREE_GATHERED simple world.Tree
container world.MOVE_SIG simple world.GameSignal
container world.GATHER_SIG simple world.GameSignal
container world.GAME_SIG_DONE simple world.GameSignal
container world.GAME_STATE slot world.GameCtl
container world.NPCS simple world.NPC
container input.CHAR_POOL simple input.Char
container input.CMDLINE simple input.Char
container input.INPUT_STATE slot input.InputCtl
container input.SHELL_STATE slot input.ShellCtl
container input.KEYBIND simple input.KeyBind
container input.TEXTCMD simple input.TextCmd
container input.TEXTARG simple input.TextArg
container input.MECHBIND simple input.MechBind
container spawn.PRI_POOL simple spawn.PriToken
container spawn.PRI_USED simple spawn.PriToken
container spawn.PROG_POOL simple spawn.ProgToken
container spawn.PROG_USED simple spawn.ProgToken
container spawn.SPAWN_STATE slot spawn.SpawnCtl
container display.VISIBLE simple display.Surface
container display.HIDDEN simple display.Surface
container display.DISPLAY_STATE slot display.DisplayCtl
container display.LEGEND simple display.Legend
container wm.VISIBLE simple wm.Window
container wm.HIDDEN simple wm.Window
container display.HELP_TEXT simple display.HelpCmd
container editor.BUFFER simple input.Char order_key pos
container editor.GLYPHS simple editor.Glyph
container editor.CTL slot editor.EditorCtl
container editor.POOL simple input.Char

move proc.schedule proc.Process from proc.READY to proc.CPU0
move proc.preempt proc.Process from proc.CPU0 to proc.READY
move proc.block_proc proc.Process from proc.CPU0 to proc.BLOCKED
move proc.unblock proc.Process from proc.BLOCKED to proc.READY
move proc.terminate proc.Process from proc.CPU0 to proc.TERMINATED
move proc.consume_signal proc.Signal from proc.TIMER_SIG proc.KILL_SIG proc.BLOCK_SIG proc.UNBLOCK_SIG proc.BOOST_SIG proc.ALLOC_SIG proc.FREE_SIG proc.OPEN_SIG proc.CLOSE_SIG proc.SEND_SIG proc.RECV_SIG proc.CLICK_SIG proc.KEY_SIG proc.CMD_SIG proc.SPAWN_SIG proc.FOCUS_SIG to proc.SIG_DONE
move world.consume_game_sig world.GameSignal from world.MOVE_SIG world.GATHER_SIG to world.GAME_SIG_DONE
move world.gather_resource world.Tree from world.TREES to world.TREE_GATHERED
move fs.open_fd fs.FileDescriptor scoped_from FD_FREE scoped_to FD_OPEN
move fs.close_fd fs.FileDescriptor scoped_from FD_OPEN scoped_to FD_FREE
move input.type_char input.Char from input.CHAR_POOL to input.CMDLINE
move input.erase_char input.Char from input.CMDLINE to input.CHAR_POOL
move ipc.process_msg ipc.Message scoped_from INBOX scoped_to PROCESSED
move mem.alloc_page mem.Page scoped_from MEM_FREE scoped_to MEM_USED
move mem.free_page mem.Page scoped_from MEM_USED scoped_to MEM_FREE
move spawn.assign_pri spawn.PriToken from spawn.PRI_POOL to spawn.PRI_USED
move spawn.return_pri spawn.PriToken from spawn.PRI_USED to spawn.PRI_POOL
move spawn.assign_prog spawn.ProgToken from spawn.PROG_POOL to spawn.PROG_USED
move spawn.return_prog spawn.ProgToken from spawn.PROG_USED to spawn.PROG_POOL
move display.show_surface display.Surface from display.HIDDEN to display.VISIBLE
move display.hide_surface display.Surface from display.VISIBLE to display.HIDDEN
move editor.insert input.Char from editor.POOL to editor.BUFFER
move editor.recycle input.Char from editor.BUFFER to editor.POOL

channel msg_pipe server client ipc.Message

config max_nesting_depth 3

tension proc.schedule_ready priority 10
  match proc in proc.READY select max_by priority
  match cpu empty_in proc.CPU0
  emit move proc.schedule proc to cpu

tension proc.timer_tick priority 20
  match sig in proc.TIMER_SIG
  match proc in proc.CPU0 optional
  emit set proc time_slice proc.time_slice - 1
  emit move proc.consume_signal sig to proc.SIG_DONE

tension proc.preempt_expired priority 15
  match proc in proc.CPU0
    where proc.time_slice <= 0
  emit move proc.preempt proc to proc.READY
  emit set proc time_slice 1

tension proc.kill_running priority 25
  match sig in proc.KILL_SIG select first
  match proc in proc.CPU0 select first
  emit move proc.terminate proc to proc.TERMINATED
  emit move proc.consume_signal sig to proc.SIG_DONE

tension proc.block_running priority 25
  match sig in proc.BLOCK_SIG select first
  match proc in proc.CPU0 select first
  emit move proc.block_proc proc to proc.BLOCKED
  emit move proc.consume_signal sig to proc.SIG_DONE

tension proc.unblock_first priority 25
  match sig in proc.UNBLOCK_SIG select first
  match proc in proc.BLOCKED select first
  emit move proc.unblock proc to proc.READY
  emit move proc.consume_signal sig to proc.SIG_DONE

tension proc.boost_running priority 25
  match sig in proc.BOOST_SIG select first
  match proc in proc.CPU0 select first
  emit set proc priority proc.priority + 1
  emit move proc.consume_signal sig to proc.SIG_DONE

tension world.move_north priority 12
  match sig in world.MOVE_SIG select first
    where sig.direction == 0
  match player in world.PLAYER
  match tile in world.TILES select first
    where tile.tile_x == player.tile_x && tile.tile_y == player.tile_y - 1
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == player.tile_x && old_tile.tile_y == player.tile_y
  emit set player tile_y player.tile_y - 1
  emit set old_tile occupied 0
  emit set tile occupied 1
  emit move world.consume_game_sig sig to world.GAME_SIG_DONE

tension world.move_south priority 12
  match sig in world.MOVE_SIG select first
    where sig.direction == 1
  match player in world.PLAYER
  match tile in world.TILES select first
    where tile.tile_x == player.tile_x && tile.tile_y == player.tile_y + 1
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == player.tile_x && old_tile.tile_y == player.tile_y
  emit set player tile_y player.tile_y + 1
  emit set old_tile occupied 0
  emit set tile occupied 1
  emit move world.consume_game_sig sig to world.GAME_SIG_DONE

tension world.move_east priority 12
  match sig in world.MOVE_SIG select first
    where sig.direction == 2
  match player in world.PLAYER
  match tile in world.TILES select first
    where tile.tile_x == player.tile_x + 1 && tile.tile_y == player.tile_y
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == player.tile_x && old_tile.tile_y == player.tile_y
  emit set player tile_x player.tile_x + 1
  emit set old_tile occupied 0
  emit set tile occupied 1
  emit move world.consume_game_sig sig to world.GAME_SIG_DONE

tension world.move_west priority 12
  match sig in world.MOVE_SIG select first
    where sig.direction == 3
  match player in world.PLAYER
  match tile in world.TILES select first
    where tile.tile_x == player.tile_x - 1 && tile.tile_y == player.tile_y
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == player.tile_x && old_tile.tile_y == player.tile_y
  emit set player tile_x player.tile_x - 1
  emit set old_tile occupied 0
  emit set tile occupied 1
  emit move world.consume_game_sig sig to world.GAME_SIG_DONE

tension world.do_gather priority 12
  match sig in world.GATHER_SIG select first
  match player in world.PLAYER
  match tree in world.TREES select first
    where tree.tile_x == player.tile_x && tree.tile_y == player.tile_y
  emit move world.gather_resource tree to world.TREE_GATHERED
  emit set player wood player.wood + 1
  emit move world.consume_game_sig sig to world.GAME_SIG_DONE

tension world.cleanup_move priority 5
  match sig in world.MOVE_SIG select first
  emit move world.consume_game_sig sig to world.GAME_SIG_DONE

tension world.cleanup_gather priority 5
  match sig in world.GATHER_SIG select first
  emit move world.consume_game_sig sig to world.GAME_SIG_DONE

; NPC wander — attempt move north (dir==0)
tension world.npc_wander_n priority 22
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.wander_dir == 0 && npc.moved != 1
  match tile in world.TILES select first
    where tile.tile_x == npc.tile_x && tile.tile_y == npc.tile_y - 1
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == npc.tile_x && old_tile.tile_y == npc.tile_y
  emit set npc tile_y npc.tile_y - 1
  emit set npc wander_dir 1
  emit set npc moved 1
  emit set old_tile occupied 0
  emit set tile occupied 1

; NPC wander — attempt move south (dir==1)
tension world.npc_wander_s priority 22
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.wander_dir == 1 && npc.moved != 1
  match tile in world.TILES select first
    where tile.tile_x == npc.tile_x && tile.tile_y == npc.tile_y + 1
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == npc.tile_x && old_tile.tile_y == npc.tile_y
  emit set npc tile_y npc.tile_y + 1
  emit set npc wander_dir 2
  emit set npc moved 1
  emit set old_tile occupied 0
  emit set tile occupied 1

; NPC wander — attempt move east (dir==2)
tension world.npc_wander_e priority 22
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.wander_dir == 2 && npc.moved != 1
  match tile in world.TILES select first
    where tile.tile_x == npc.tile_x + 1 && tile.tile_y == npc.tile_y
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == npc.tile_x && old_tile.tile_y == npc.tile_y
  emit set npc tile_x npc.tile_x + 1
  emit set npc wander_dir 3
  emit set npc moved 1
  emit set old_tile occupied 0
  emit set tile occupied 1

; NPC wander — attempt move west (dir==3)
tension world.npc_wander_w priority 22
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.wander_dir == 3 && npc.moved != 1
  match tile in world.TILES select first
    where tile.tile_x == npc.tile_x - 1 && tile.tile_y == npc.tile_y
  guard tile.terrain != 2 && tile.terrain != 3 && tile.occupied != 1
  match old_tile in world.TILES select first
    where old_tile.tile_x == npc.tile_x && old_tile.tile_y == npc.tile_y
  emit set npc tile_x npc.tile_x - 1
  emit set npc wander_dir 0
  emit set npc moved 1
  emit set old_tile occupied 0
  emit set tile occupied 1

; NPC wander blocked at dir 0 — try dir 1 next
tension world.npc_blocked_0 priority 21
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.moved != 1 && npc.wander_dir == 0
  emit set npc wander_dir 1
  emit set npc moved 1

; NPC wander blocked at dir 1 — try dir 2 next
tension world.npc_blocked_1 priority 21
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.moved != 1 && npc.wander_dir == 1
  emit set npc wander_dir 2
  emit set npc moved 1

; NPC wander blocked at dir 2 — try dir 3 next
tension world.npc_blocked_2 priority 21
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.moved != 1 && npc.wander_dir == 2
  emit set npc wander_dir 3
  emit set npc moved 1

; NPC wander blocked at dir 3 — try dir 0 next
tension world.npc_blocked_3 priority 21
  match tick in proc.TIMER_SIG select first
  match npc in world.NPCS select first
    where npc.moved != 1 && npc.wander_dir == 3
  emit set npc wander_dir 0
  emit set npc moved 1

; NPC reset moved flag
tension world.npc_reset_moved priority 1
  match npc in world.NPCS select first
    where npc.moved == 1
  emit set npc moved 0

tension fs.do_open priority 12
  match sig in proc.OPEN_SIG
  match proc in proc.CPU0
  match fd in scoped proc FD_FREE select first
  emit move fs.open_fd fd to scoped proc FD_OPEN
  emit move proc.consume_signal sig to proc.SIG_DONE

tension fs.do_close priority 12
  match sig in proc.CLOSE_SIG
  match proc in proc.CPU0
  match fd in scoped proc FD_OPEN select first
  emit move fs.close_fd fd to scoped proc FD_FREE
  emit move proc.consume_signal sig to proc.SIG_DONE

tension input.enter_text priority 25
  match key in proc.KEY_SIG select first
    where key.ascii == 47
  match ctl in input.INPUT_STATE
    where ctl.mode == 0
  emit set ctl mode 1
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.exit_text priority 25
  match key in proc.KEY_SIG select first
    where key.ascii == 27
  match ctl in input.INPUT_STATE
    where ctl.mode == 1
  emit set ctl mode 0
  emit set ctl submitted 2
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.do_submit priority 24
  match key in proc.KEY_SIG select first
    where key.ascii == 10
  match ctl in input.INPUT_STATE
    where ctl.mode == 1
  emit set ctl submitted 1
  emit set ctl mode 0
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.append_char priority 22
  match key in proc.KEY_SIG select first
    where key.ascii >= 32
  match ctl in input.INPUT_STATE
    where ctl.mode == 1
  match ch in input.CHAR_POOL select first
  emit set ch ascii key.ascii
  emit set ch pos count(input.CMDLINE)
  emit move input.type_char ch to input.CMDLINE
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.delete_last priority 22
  match key in proc.KEY_SIG select first
    where key.ascii == 8
  match ctl in input.INPUT_STATE
    where ctl.mode == 1
  match ch in input.CMDLINE select max_by pos
  emit set ch ascii 0
  emit set ch pos 0
  emit move input.erase_char ch to input.CHAR_POOL
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.key_overflow priority 18
  match key in proc.KEY_SIG select first
  match ctl in input.INPUT_STATE
    where ctl.mode == 1
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.clear_char priority 15
  match ctl in input.INPUT_STATE
    where ctl.submitted == 2
  match ch in input.CMDLINE select first
  emit set ch ascii 0
  emit set ch pos 0
  emit move input.erase_char ch to input.CHAR_POOL

tension input.clear_done priority 10
  match ctl in input.INPUT_STATE
    where ctl.submitted == 2
  guard count(input.CMDLINE) == 0
  emit set ctl submitted 0

tension input.key_miss priority 2
  match key in proc.KEY_SIG select first
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.keybind_route priority 23
  match key in proc.KEY_SIG select first
    where key.ascii > 0
  match ctl in input.INPUT_STATE
    where ctl.mode == 0
  match bind in input.KEYBIND select first
    where key.ascii == bind.key
  emit set ctl pending_cmd bind.cmd_id
  emit set ctl pending_arg bind.arg_id
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.mechbind_match priority 23
  match key in proc.KEY_SIG select first
    where key.ascii > 0
  match ctl in input.INPUT_STATE
    where ctl.mode == 0
  match bind in input.MECHBIND select first
    where key.ascii == bind.key
  emit set ctl mech_action bind.action
  emit move proc.consume_signal key to proc.SIG_DONE

tension input.textcmd_match priority 22
  match cmd in proc.CMD_SIG select first
    where cmd.text_key > 0
  match tcmd in input.TEXTCMD select first
    where cmd.text_key == tcmd.text_key
  emit set cmd cmd_id tcmd.cmd_id

tension input.textarg_match priority 21
  match cmd in proc.CMD_SIG select first
    where cmd.arg_key > 0
  match targ in input.TEXTARG select first
    where cmd.arg_key == targ.text_key
  emit set cmd arg_id targ.arg_id

tension input.cleanup_detect priority 3
  match proc in proc.TERMINATED select first
    where proc.protected != 1
  match ctl in input.SHELL_STATE
  emit set ctl cleanup_pending 1

tension input.swap_to_rr priority 20
  match ctl in input.SHELL_STATE
    where ctl.action == 10 && ctl.current_policy == 0
  emit set ctl current_policy 1
  emit set ctl load_policy 1
  emit set ctl action 0

tension input.swap_to_pri priority 20
  match ctl in input.SHELL_STATE
    where ctl.action == 10 && ctl.current_policy == 1
  emit set ctl current_policy 0
  emit set ctl load_policy 2
  emit set ctl action 0

tension ipc.do_send priority 15
  match sig in proc.SEND_SIG
  match proc in proc.CPU0
  match msg in scoped proc OUTBOX select first
  emit send msg_pipe msg
  emit move proc.consume_signal sig to proc.SIG_DONE

tension ipc.do_recv priority 12
  match sig in proc.RECV_SIG
  match proc in proc.CPU0
  match msg in channel msg_pipe
  emit receive msg_pipe msg to scoped proc INBOX
  emit move proc.consume_signal sig to proc.SIG_DONE

tension ipc.react_to_msg priority 8
  match proc in proc.CPU0
  match msg in scoped proc INBOX select first
  emit set proc msgs_received proc.msgs_received + 1
  emit move ipc.process_msg msg to scoped proc PROCESSED

tension mem.do_alloc priority 12
  match sig in proc.ALLOC_SIG
  match proc in proc.CPU0
  match page in scoped proc MEM_FREE select first
  emit move mem.alloc_page page to scoped proc MEM_USED
  emit move proc.consume_signal sig to proc.SIG_DONE

tension mem.do_free priority 12
  match sig in proc.FREE_SIG
  match proc in proc.CPU0
  match page in scoped proc MEM_USED select first
  emit move mem.free_page page to scoped proc MEM_FREE
  emit move proc.consume_signal sig to proc.SIG_DONE

tension spawn.spawn_explicit priority 25
  match sig in proc.SPAWN_SIG select first
    where sig.requested_type > 0
  match ctl in spawn.SPAWN_STATE
  match pri in spawn.PRI_POOL select min_by value
  emit set ctl action 1
  emit set ctl program_type sig.requested_type
  emit set ctl next_priority pri.value
  emit move spawn.assign_pri pri to spawn.PRI_USED
  emit move proc.consume_signal sig to proc.SIG_DONE

tension spawn.spawn_auto priority 24
  match sig in proc.SPAWN_SIG select first
    where sig.requested_type == 0
  match ctl in spawn.SPAWN_STATE
  match pri in spawn.PRI_POOL select min_by value
  match prog in spawn.PROG_POOL select first
  emit set ctl action 1
  emit set ctl program_type prog.type_id
  emit set ctl next_priority pri.value
  emit move spawn.assign_pri pri to spawn.PRI_USED
  emit move spawn.assign_prog prog to spawn.PROG_USED
  emit move proc.consume_signal sig to proc.SIG_DONE

tension spawn.recycle_priorities priority 23
  match empty empty_in spawn.PRI_POOL
  match pri in spawn.PRI_USED select each
  emit move spawn.return_pri pri to spawn.PRI_POOL

tension spawn.recycle_programs priority 22
  match empty empty_in spawn.PROG_POOL
  match prog in spawn.PROG_USED select each
  emit move spawn.return_prog prog to spawn.PROG_POOL

tension display.sync_running priority 5
  match proc in proc.CPU0
  match surf in scoped proc SURFACE
    where surf.state != 1
  emit set surf state 1
  emit set surf border_color 52326
  emit set surf fill_color 1060896

tension display.sync_ready priority 5
  match proc in proc.READY select each
  match surf in scoped proc SURFACE
    where surf.state != 2
  emit set surf state 2
  emit set surf border_color 13412864
  emit set surf fill_color 2629648

tension display.sync_blocked priority 5
  match proc in proc.BLOCKED select each
  match surf in scoped proc SURFACE
    where surf.state != 3
  emit set surf state 3
  emit set surf border_color 13382451
  emit set surf fill_color 2625552

tension display.sync_terminated priority 5
  match proc in proc.TERMINATED select each
  match surf in scoped proc SURFACE
    where surf.state != 4
  emit set surf state 4
  emit set surf border_color 5592405
  emit set surf fill_color 1579032

tension display.click_select_cpu0 priority 4
  match click in proc.CLICK_SIG select first
  match region in display.VISIBLE select first
    where region.region_id == 0
  match proc in proc.CPU0 select first
  guard click.click_x >= region.x && click.click_x < region.x + region.width && ( click.click_y >= region.y && click.click_y < region.y + region.height )
  emit set proc selected 1
  emit move proc.consume_signal click to proc.SIG_DONE

tension display.click_select_ready priority 4
  match click in proc.CLICK_SIG select first
  match region in display.VISIBLE select first
    where region.region_id == 1
  match proc in proc.READY select first
  guard click.click_x >= region.x && click.click_x < region.x + region.width && ( click.click_y >= region.y && click.click_y < region.y + region.height )
  emit set proc selected 1
  emit move proc.consume_signal click to proc.SIG_DONE

tension display.click_select_blocked priority 4
  match click in proc.CLICK_SIG select first
  match region in display.VISIBLE select first
    where region.region_id == 2
  match proc in proc.BLOCKED select first
  guard click.click_x >= region.x && click.click_x < region.x + region.width && ( click.click_y >= region.y && click.click_y < region.y + region.height )
  emit set proc selected 1
  emit move proc.consume_signal click to proc.SIG_DONE

tension display.click_select_terminated priority 4
  match click in proc.CLICK_SIG select first
  match region in display.VISIBLE select first
    where region.region_id == 3
  match proc in proc.TERMINATED select first
  guard click.click_x >= region.x && click.click_x < region.x + region.width && ( click.click_y >= region.y && click.click_y < region.y + region.height )
  emit set proc selected 1
  emit move proc.consume_signal click to proc.SIG_DONE

tension display.click_panel priority 5
  match click in proc.CLICK_SIG select first
  match panel in display.VISIBLE select first
    where panel.kind == 4
  match ctl in input.INPUT_STATE
  guard click.click_x >= panel.x && click.click_x < panel.x + panel.width && ( click.click_y >= panel.y && click.click_y < panel.y + panel.height )
  emit set ctl panel_click 1
  emit move proc.consume_signal click to proc.SIG_DONE

tension display.click_miss priority 3
  match click in proc.CLICK_SIG select first
  emit move proc.consume_signal click to proc.SIG_DONE

; ---- Window focus (Session 91) ----
; Priority 24: highest among click handlers — runs first, consumes FOCUS_SIG
tension wm.focus_on_click priority 24
  match sig in proc.FOCUS_SIG select first
  match win in wm.VISIBLE select each
  guard sig.click_x >= win.x && sig.click_x < win.x + win.width && ( sig.click_y >= win.y && sig.click_y < win.y + win.height )
  emit set win focused 2
  emit move proc.consume_signal sig to proc.SIG_DONE

; Priority 23: clear old focus when new focus (focused==2) exists
tension wm.clear_other_focus priority 23
  match winner in wm.VISIBLE select first
    where winner.focused == 2
  match loser in wm.VISIBLE select each
    where loser.focused == 1
  emit set loser focused 0

; Priority 22: normalize focused 2 → 1 (after clearing is done)
tension wm.normalize_focus priority 22
  match win in wm.VISIBLE select each
    where win.focused == 2
  emit set win focused 1

; Priority 2: catchall — consume unclaimed FOCUS_SIG (clicked empty space)
tension wm.focus_miss priority 2
  match sig in proc.FOCUS_SIG select first
  emit move proc.consume_signal sig to proc.SIG_DONE

tension editor.type_char priority 22
  match key in proc.KEY_SIG select first
    where key.ascii >= 32
  match ctl in input.INPUT_STATE
    where ctl.mode == 2
  match ectl in editor.CTL
  match ch in editor.POOL select first
  emit set ch ascii key.ascii
  emit set ch pos ectl.cursor_pos
  emit move editor.insert ch to editor.BUFFER
  emit set ectl cursor_pos ectl.cursor_pos + 1
  emit move proc.consume_signal key to proc.SIG_DONE

tension editor.type_enter priority 23
  match key in proc.KEY_SIG select first
    where key.ascii == 10
  match ctl in input.INPUT_STATE
    where ctl.mode == 2
  match ectl in editor.CTL
  match ch in editor.POOL select first
  emit set ch ascii 10
  emit set ch pos ectl.cursor_pos
  emit move editor.insert ch to editor.BUFFER
  emit set ectl cursor_pos ectl.cursor_pos + 1
  emit move proc.consume_signal key to proc.SIG_DONE

tension editor.backspace priority 22
  match key in proc.KEY_SIG select first
    where key.ascii == 8
  match ctl in input.INPUT_STATE
    where ctl.mode == 2
  match ectl in editor.CTL
    where ectl.cursor_pos > 0
  match ch in editor.BUFFER select max_by pos
  emit set ch ascii 0
  emit set ch pos 0
  emit move editor.recycle ch to editor.POOL
  emit set ectl cursor_pos ectl.cursor_pos - 1
  emit move proc.consume_signal key to proc.SIG_DONE

tension editor.exit_editor priority 25
  match key in proc.KEY_SIG select first
    where key.ascii == 27
  match ctl in input.INPUT_STATE
    where ctl.mode == 2
  emit set ctl mode 0
  emit move proc.consume_signal key to proc.SIG_DONE

tension editor.key_overflow priority 18
  match key in proc.KEY_SIG select first
  match ctl in input.INPUT_STATE
    where ctl.mode == 2
  emit move proc.consume_signal key to proc.SIG_DONE

flow render_editor
  from editor.BUFFER order_by pos
  into editor.GLYPHS
  seed x 0
  seed y 0
  each char -> glyph
    set glyph.ascii char.ascii
    set glyph.screen_x x
    set glyph.screen_y y
    step x if x > 376 then 0 else x + 8
    step y if x > 376 then y + 16 else y

flow wm.tile_horizontal
  from wm.VISIBLE order_by role
  into wm.VISIBLE
  seed x 0
  seed y 76
  seed idx 0
  seed w 320
  each src -> dst
    set dst.x x
    set dst.y y
    set dst.width w
    set dst.height 362
    step x if idx == 3 then 0 else x + w
    step y if idx == 3 then 438 else y
    step w if idx == 3 then 426 else w
    step idx idx + 1

entity server proc.Process in proc.READY
  prop priority 5
  prop time_slice 1
  prop msgs_received 0
  prop selected 0
  prop protected 0
entity client proc.Process in proc.READY
  prop priority 5
  prop time_slice 1
  prop msgs_received 0
  prop selected 0
  prop protected 0
entity page0_s mem.Page in scoped server MEM_FREE
entity page1_s mem.Page in scoped server MEM_FREE
entity page0_c mem.Page in scoped client MEM_FREE
entity page1_c mem.Page in scoped client MEM_FREE
entity fd0_s fs.FileDescriptor in scoped server FD_FREE
entity fd1_s fs.FileDescriptor in scoped server FD_FREE
entity fd0_c fs.FileDescriptor in scoped client FD_FREE
entity fd1_c fs.FileDescriptor in scoped client FD_FREE
entity surf_server display.Surface in scoped server SURFACE
  prop kind 1
  prop state 0
  prop border_color 0
  prop fill_color 0
entity surf_client display.Surface in scoped client SURFACE
  prop kind 1
  prop state 0
  prop border_color 0
  prop fill_color 0
entity cursor display.Surface in display.VISIBLE
  prop kind 2
  prop x 400
  prop y 300
entity region_cpu0 display.Surface in display.VISIBLE
  prop kind 0
  prop region_id 0
  prop x 8
  prop y 76
  prop width 400
  prop height 300
  prop border_color 52326
  prop fill_color 1060896
entity region_ready display.Surface in display.VISIBLE
  prop kind 0
  prop region_id 1
  prop x 416
  prop y 76
  prop width 400
  prop height 300
  prop border_color 13412864
  prop fill_color 2629648
entity region_blocked display.Surface in display.VISIBLE
  prop kind 0
  prop region_id 2
  prop x 8
  prop y 384
  prop width 400
  prop height 300
  prop border_color 13382451
  prop fill_color 2625552
entity region_term display.Surface in display.VISIBLE
  prop kind 0
  prop region_id 3
  prop x 416
  prop y 384
  prop width 400
  prop height 300
  prop border_color 5592405
  prop fill_color 1579032
entity region_panel display.Surface in display.VISIBLE
  prop kind 4
  prop region_id 4
  prop x 824
  prop y 76
  prop width 448
  prop height 608
entity win_cpu0 wm.Window in wm.VISIBLE
  prop x 8
  prop y 76
  prop width 400
  prop height 300
  prop z_order 0
  prop role 0
  prop focused 0
entity win_ready wm.Window in wm.VISIBLE
  prop x 416
  prop y 76
  prop width 400
  prop height 300
  prop z_order 1
  prop role 1
  prop focused 0
entity win_blocked wm.Window in wm.VISIBLE
  prop x 8
  prop y 384
  prop width 400
  prop height 300
  prop z_order 2
  prop role 2
  prop focused 0
entity win_term wm.Window in wm.VISIBLE
  prop x 416
  prop y 384
  prop width 400
  prop height 300
  prop z_order 3
  prop role 3
  prop focused 0
entity win_tensions wm.Window in wm.VISIBLE
  prop x 824
  prop y 76
  prop width 448
  prop height 608
  prop z_order 4
  prop role 4
  prop focused 0
entity win_editor wm.Window in wm.VISIBLE
  prop x 200
  prop y 76
  prop width 760
  prop height 650
  prop z_order 5
  prop role 5
  prop focused 0
entity win_game wm.Window in wm.VISIBLE
  prop x 8
  prop y 76
  prop width 500
  prop height 520
  prop z_order 6
  prop role 6
  prop focused 0
entity display_ctl display.DisplayCtl in display.DISPLAY_STATE
  prop max_terminated 3
  prop max_procs_per_region 12
  prop timer_interval 300
  prop buffer_capacity 20
entity leg_new display.Legend in display.LEGEND
  prop order 1
  prop key_text "N"
  prop label_text "ew"
entity leg_kill display.Legend in display.LEGEND
  prop order 2
  prop key_text "K"
  prop label_text "ill"
entity leg_blk display.Legend in display.LEGEND
  prop order 3
  prop key_text "B"
  prop label_text "lk"
entity leg_unblk display.Legend in display.LEGEND
  prop order 4
  prop key_text "U"
  prop label_text "nblk"
entity leg_tmr display.Legend in display.LEGEND
  prop order 5
  prop key_text "T"
  prop label_text "mr"
entity leg_alloc display.Legend in display.LEGEND
  prop order 6
  prop key_text "A"
  prop label_text "loc"
entity leg_open display.Legend in display.LEGEND
  prop order 7
  prop key_text "O"
  prop label_text "pen"
entity leg_free display.Legend in display.LEGEND
  prop order 8
  prop key_text "F"
  prop label_text "ree"
entity leg_close display.Legend in display.LEGEND
  prop order 9
  prop key_text "C"
  prop label_text "lose"
entity leg_msg display.Legend in display.LEGEND
  prop order 10
  prop key_text "M"
  prop label_text "sg"
entity leg_sel display.Legend in display.LEGEND
  prop order 11
  prop key_text "[]"
  prop label_text "sel"
entity leg_dis display.Legend in display.LEGEND
  prop order 12
  prop key_text "D"
  prop label_text "is"
entity leg_swap display.Legend in display.LEGEND
  prop order 13
  prop key_text "S"
  prop label_text "wap"
entity leg_cmd display.Legend in display.LEGEND
  prop order 14
  prop key_text "/"
  prop label_text "Cmd"
entity help_kill display.HelpCmd in display.HELP_TEXT
  prop order 1
  prop cmd_text "kill"
entity help_load display.HelpCmd in display.HELP_TEXT
  prop order 2
  prop cmd_text "load <producer|consumer|worker|beacon>"
entity help_swap display.HelpCmd in display.HELP_TEXT
  prop order 3
  prop cmd_text "swap"
entity help_list display.HelpCmd in display.HELP_TEXT
  prop order 4
  prop cmd_text "list"
entity help_help display.HelpCmd in display.HELP_TEXT
  prop order 5
  prop cmd_text "help"
entity help_block display.HelpCmd in display.HELP_TEXT
  prop order 6
  prop cmd_text "block"
entity help_unblock display.HelpCmd in display.HELP_TEXT
  prop order 7
  prop cmd_text "unblock"
entity help_save display.HelpCmd in display.HELP_TEXT
  prop order 8
  prop cmd_text "save <name> <text>"
entity help_read display.HelpCmd in display.HELP_TEXT
  prop order 9
  prop cmd_text "read <name>"
entity help_files display.HelpCmd in display.HELP_TEXT
  prop order 10
  prop cmd_text "files"
entity input_ctl input.InputCtl in input.INPUT_STATE
  prop mode 0
  prop submitted 0
  prop pending_cmd 0
  prop pending_arg 0
  prop mech_action 0
  prop panel_click 0
entity shell_ctl input.ShellCtl in input.SHELL_STATE
  prop action 0
  prop shell_protected 1
  prop cleanup_pending 0
  prop current_policy 0
  prop load_policy 0
entity spawn_ctl spawn.SpawnCtl in spawn.SPAWN_STATE
  prop action 0
  prop program_type 0
  prop next_priority 0
entity pri_2 spawn.PriToken in spawn.PRI_POOL
  prop value 2
entity pri_4 spawn.PriToken in spawn.PRI_POOL
  prop value 4
entity pri_6 spawn.PriToken in spawn.PRI_POOL
  prop value 6
entity pri_8 spawn.PriToken in spawn.PRI_POOL
  prop value 8
entity pri_10 spawn.PriToken in spawn.PRI_POOL
  prop value 10
entity prog_1 spawn.ProgToken in spawn.PROG_POOL
  prop type_id 1
entity prog_2 spawn.ProgToken in spawn.PROG_POOL
  prop type_id 2
entity bind_k input.KeyBind in input.KEYBIND
  prop key 107
  prop cmd_id 1
  prop arg_id 0
entity bind_b input.KeyBind in input.KEYBIND
  prop key 98
  prop cmd_id 6
  prop arg_id 0
entity bind_u input.KeyBind in input.KEYBIND
  prop key 117
  prop cmd_id 7
  prop arg_id 0
entity bind_s input.KeyBind in input.KEYBIND
  prop key 115
  prop cmd_id 3
  prop arg_id 0
entity bind_n input.KeyBind in input.KEYBIND
  prop key 110
  prop cmd_id 8
  prop arg_id 0
entity tcmd_kill input.TextCmd in input.TEXTCMD
  prop text_key 27497
  prop cmd_id 1
entity tcmd_load input.TextCmd in input.TEXTCMD
  prop text_key 27759
  prop cmd_id 2
entity tcmd_swap input.TextCmd in input.TEXTCMD
  prop text_key 29559
  prop cmd_id 3
entity tcmd_list input.TextCmd in input.TEXTCMD
  prop text_key 27753
  prop cmd_id 4
entity tcmd_help input.TextCmd in input.TEXTCMD
  prop text_key 26725
  prop cmd_id 5
entity tcmd_block input.TextCmd in input.TEXTCMD
  prop text_key 25196
  prop cmd_id 6
entity tcmd_unblock input.TextCmd in input.TEXTCMD
  prop text_key 30062
  prop cmd_id 7
entity tcmd_save input.TextCmd in input.TEXTCMD
  prop text_key 29537
  prop cmd_id 11
entity tcmd_read input.TextCmd in input.TEXTCMD
  prop text_key 29285
  prop cmd_id 12
entity tcmd_files input.TextCmd in input.TEXTCMD
  prop text_key 26217
  prop cmd_id 13
entity targ_producer input.TextArg in input.TEXTARG
  prop text_key 28786
  prop arg_id 1
entity targ_consumer input.TextArg in input.TEXTARG
  prop text_key 25455
  prop arg_id 2
entity targ_worker input.TextArg in input.TEXTARG
  prop text_key 30319
  prop arg_id 3
entity targ_beacon input.TextArg in input.TEXTARG
  prop text_key 24933
  prop arg_id 4
entity mech_t input.MechBind in input.MECHBIND
  prop key 116
  prop action 1
entity mech_plus input.MechBind in input.MECHBIND
  prop key 43
  prop action 2
entity mech_eq input.MechBind in input.MECHBIND
  prop key 61
  prop action 2
entity mech_space input.MechBind in input.MECHBIND
  prop key 32
  prop action 3
entity mech_a input.MechBind in input.MECHBIND
  prop key 97
  prop action 4
entity mech_o input.MechBind in input.MECHBIND
  prop key 111
  prop action 5
entity mech_f input.MechBind in input.MECHBIND
  prop key 102
  prop action 6
entity mech_c input.MechBind in input.MECHBIND
  prop key 99
  prop action 7
entity mech_m input.MechBind in input.MECHBIND
  prop key 109
  prop action 8
entity mech_lbr input.MechBind in input.MECHBIND
  prop key 91
  prop action 9
entity mech_rbr input.MechBind in input.MECHBIND
  prop key 93
  prop action 10
entity mech_d input.MechBind in input.MECHBIND
  prop key 100
  prop action 11
entity mech_h input.MechBind in input.MECHBIND
  prop key 104
  prop action 12
entity mech_g input.MechBind in input.MECHBIND
  prop key 103
  prop action 13
entity leg_game display.Legend in display.LEGEND
  prop order 15
  prop key_text "G"
  prop label_text "ame"
entity game_ctl world.GameCtl in world.GAME_STATE
  prop display_mode 0
entity hero world.Player in world.PLAYER
  prop tile_x 3
  prop tile_y 3
  prop hp 10
  prop wood 0
entity T00 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 0
  prop terrain 0
  prop occupied 0
entity T10 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 0
  prop terrain 0
  prop occupied 1
entity T20 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 0
  prop terrain 0
  prop occupied 0
entity T30 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 0
  prop terrain 0
  prop occupied 0
entity T40 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 0
  prop terrain 0
  prop occupied 0
entity T50 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 0
  prop terrain 1
  prop occupied 0
entity T60 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 0
  prop terrain 1
  prop occupied 0
entity T70 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 0
  prop terrain 0
  prop occupied 0
entity T01 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 1
  prop terrain 0
  prop occupied 0
entity T11 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 1
  prop terrain 0
  prop occupied 0
entity T21 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 1
  prop terrain 1
  prop occupied 0
entity T31 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 1
  prop terrain 1
  prop occupied 0
entity T41 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 1
  prop terrain 0
  prop occupied 0
entity T51 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 1
  prop terrain 0
  prop occupied 0
entity T61 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 1
  prop terrain 1
  prop occupied 0
entity T71 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 1
  prop terrain 0
  prop occupied 0
entity T02 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 2
  prop terrain 0
  prop occupied 0
entity T12 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 2
  prop terrain 0
  prop occupied 0
entity T22 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 2
  prop terrain 1
  prop occupied 0
entity T32 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 2
  prop terrain 1
  prop occupied 0
entity T42 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 2
  prop terrain 0
  prop occupied 0
entity T52 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 2
  prop terrain 0
  prop occupied 0
entity T62 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 2
  prop terrain 2
  prop occupied 0
entity T72 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 2
  prop terrain 2
  prop occupied 0
entity T03 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 3
  prop terrain 0
  prop occupied 0
entity T13 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 3
  prop terrain 0
  prop occupied 0
entity T23 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 3
  prop terrain 0
  prop occupied 0
entity T33 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 3
  prop terrain 0
  prop occupied 1
entity T43 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 3
  prop terrain 0
  prop occupied 0
entity T53 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 3
  prop terrain 0
  prop occupied 0
entity T63 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 3
  prop terrain 2
  prop occupied 0
entity T73 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 3
  prop terrain 2
  prop occupied 0
entity T04 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 4
  prop terrain 0
  prop occupied 0
entity T14 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 4
  prop terrain 3
  prop occupied 0
entity T24 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 4
  prop terrain 3
  prop occupied 0
entity T34 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 4
  prop terrain 0
  prop occupied 0
entity T44 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 4
  prop terrain 0
  prop occupied 0
entity T54 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 4
  prop terrain 0
  prop occupied 0
entity T64 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 4
  prop terrain 0
  prop occupied 0
entity T74 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 4
  prop terrain 0
  prop occupied 0
entity T05 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 5
  prop terrain 0
  prop occupied 0
entity T15 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 5
  prop terrain 3
  prop occupied 0
entity T25 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 5
  prop terrain 0
  prop occupied 0
entity T35 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 5
  prop terrain 0
  prop occupied 0
entity T45 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 5
  prop terrain 1
  prop occupied 0
entity T55 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 5
  prop terrain 1
  prop occupied 0
entity T65 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 5
  prop terrain 0
  prop occupied 0
entity T75 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 5
  prop terrain 0
  prop occupied 0
entity T06 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 6
  prop terrain 0
  prop occupied 0
entity T16 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 6
  prop terrain 0
  prop occupied 0
entity T26 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 6
  prop terrain 0
  prop occupied 0
entity T36 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 6
  prop terrain 0
  prop occupied 0
entity T46 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 6
  prop terrain 1
  prop occupied 0
entity T56 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 6
  prop terrain 1
  prop occupied 0
entity T66 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 6
  prop terrain 0
  prop occupied 0
entity T76 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 6
  prop terrain 0
  prop occupied 0
entity T07 world.TileInfo in world.TILES
  prop tile_x 0
  prop tile_y 7
  prop terrain 0
  prop occupied 0
entity T17 world.TileInfo in world.TILES
  prop tile_x 1
  prop tile_y 7
  prop terrain 0
  prop occupied 0
entity T27 world.TileInfo in world.TILES
  prop tile_x 2
  prop tile_y 7
  prop terrain 0
  prop occupied 0
entity T37 world.TileInfo in world.TILES
  prop tile_x 3
  prop tile_y 7
  prop terrain 0
  prop occupied 0
entity T47 world.TileInfo in world.TILES
  prop tile_x 4
  prop tile_y 7
  prop terrain 0
  prop occupied 0
entity T57 world.TileInfo in world.TILES
  prop tile_x 5
  prop tile_y 7
  prop terrain 0
  prop occupied 0
entity T67 world.TileInfo in world.TILES
  prop tile_x 6
  prop tile_y 7
  prop terrain 0
  prop occupied 1
entity T77 world.TileInfo in world.TILES
  prop tile_x 7
  prop tile_y 7
  prop terrain 0
  prop occupied 0
entity tree_5_0 world.Tree in world.TREES
  prop tile_x 5
  prop tile_y 0
entity tree_6_0 world.Tree in world.TREES
  prop tile_x 6
  prop tile_y 0
entity tree_2_1 world.Tree in world.TREES
  prop tile_x 2
  prop tile_y 1
entity tree_3_1 world.Tree in world.TREES
  prop tile_x 3
  prop tile_y 1
entity tree_6_1 world.Tree in world.TREES
  prop tile_x 6
  prop tile_y 1
entity tree_2_2 world.Tree in world.TREES
  prop tile_x 2
  prop tile_y 2
entity tree_4_5 world.Tree in world.TREES
  prop tile_x 4
  prop tile_y 5
entity tree_5_5 world.Tree in world.TREES
  prop tile_x 5
  prop tile_y 5
entity tree_4_6 world.Tree in world.TREES
  prop tile_x 4
  prop tile_y 6
entity tree_0_6 world.Tree in world.TREES
  prop tile_x 0
  prop tile_y 6
entity tree_7_4 world.Tree in world.TREES
  prop tile_x 7
  prop tile_y 4
entity tree_3_5 world.Tree in world.TREES
  prop tile_x 3
  prop tile_y 5
entity npc_guard world.NPC in world.NPCS
  prop tile_x 1
  prop tile_y 0
  prop behavior 1
  prop wander_dir 0
  prop moved 0
entity npc_scout world.NPC in world.NPCS
  prop tile_x 6
  prop tile_y 7
  prop behavior 1
  prop wander_dir 2
  prop moved 0
entity c00 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c01 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c02 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c03 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c04 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c05 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c06 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c07 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c08 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c09 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c10 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c11 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c12 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c13 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c14 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c15 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c16 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c17 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c18 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c19 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c20 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c21 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c22 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c23 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c24 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c25 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c26 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c27 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c28 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c29 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c30 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity c31 input.Char in input.CHAR_POOL
  prop ascii 0
  prop pos 0
entity tcmd_edit input.TextCmd in input.TEXTCMD
  prop text_key 25956
  prop cmd_id 14
entity tcmd_esave input.TextCmd in input.TEXTCMD
  prop text_key 25971
  prop cmd_id 15
entity tcmd_eload input.TextCmd in input.TEXTCMD
  prop text_key 25964
  prop cmd_id 16
entity tcmd_ping input.TextCmd in input.TEXTCMD
  prop text_key 28777
  prop cmd_id 17
entity tcmd_udp input.TextCmd in input.TEXTCMD
  prop text_key 30052
  prop cmd_id 18
entity tcmd_dns input.TextCmd in input.TEXTCMD
  prop text_key 25710
  prop cmd_id 19
entity tcmd_connect input.TextCmd in input.TEXTCMD
  prop text_key 25455
  prop cmd_id 20
entity tcmd_http input.TextCmd in input.TEXTCMD
  prop text_key 26740
  prop cmd_id 21
entity tcmd_tile input.TextCmd in input.TEXTCMD
  prop text_key 29801
  prop cmd_id 22
entity help_edit display.HelpCmd in display.HELP_TEXT
  prop order 11
  prop cmd_text "edit"
entity help_esave display.HelpCmd in display.HELP_TEXT
  prop order 12
  prop cmd_text "esave <name>"
entity help_eload display.HelpCmd in display.HELP_TEXT
  prop order 13
  prop cmd_text "eload <name>"
entity help_ping display.HelpCmd in display.HELP_TEXT
  prop order 14
  prop cmd_text "ping"
entity help_udp display.HelpCmd in display.HELP_TEXT
  prop order 15
  prop cmd_text "udp"
entity help_dns display.HelpCmd in display.HELP_TEXT
  prop order 16
  prop cmd_text "dns <domain>"
entity help_connect display.HelpCmd in display.HELP_TEXT
  prop order 17
  prop cmd_text "connect"
entity help_http display.HelpCmd in display.HELP_TEXT
  prop order 18
  prop cmd_text "http"
entity help_tile display.HelpCmd in display.HELP_TEXT
  prop order 19
  prop cmd_text "tile"
entity editor_ctl editor.EditorCtl in editor.CTL
  prop mode 0
  prop cursor_pos 0
  prop dirty 0
  prop buf_len 0
entity ec00 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec01 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec02 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec03 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec04 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec05 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec06 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec07 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec08 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec09 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec10 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec11 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec12 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec13 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec14 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec15 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec16 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec17 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec18 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec19 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec20 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec21 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec22 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec23 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec24 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec25 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec26 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec27 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec28 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec29 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec30 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec31 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec32 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec33 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec34 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec35 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec36 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec37 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec38 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec39 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec40 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec41 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec42 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec43 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec44 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec45 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec46 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec47 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec48 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec49 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec50 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec51 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec52 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec53 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec54 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec55 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec56 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec57 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec58 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec59 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec60 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec61 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec62 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec63 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec64 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec65 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec66 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec67 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec68 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec69 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec70 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec71 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec72 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec73 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec74 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec75 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec76 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec77 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec78 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec79 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec80 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec81 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec82 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec83 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec84 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec85 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec86 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec87 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec88 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec89 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec90 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec91 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec92 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec93 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec94 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec95 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec96 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec97 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec98 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec99 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec100 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec101 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec102 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec103 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec104 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec105 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec106 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec107 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec108 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec109 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec110 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec111 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec112 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec113 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec114 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec115 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec116 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec117 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec118 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec119 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec120 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec121 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec122 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec123 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec124 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec125 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec126 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
entity ec127 input.Char in editor.POOL
  prop ascii 0
  prop pos 0
