diff options
author | Steph Enders <smenders@gmail.com> | 2022-12-17 11:04:20 -0500 |
---|---|---|
committer | Steph Enders <smenders@gmail.com> | 2022-12-17 11:04:20 -0500 |
commit | 8e101f8bfd995321ac08a16fea9a171b549a0ae4 (patch) | |
tree | 61c25c357c24381e653f2dd104463628fe2875e7 /dnglib/algs.lua | |
parent | f710faa0cc8862a8367dbbf89bf8c3cd44790b5d (diff) |
Support doors with keys
Add initial support for doors and keys via pre-defined mappings:
k || d
------
1 -> a
2 -> b
3 -> c
4 -> d
Any key can open any door of its mapping, but is spent once used.
May require additional testing
Diffstat (limited to 'dnglib/algs.lua')
-rw-r--r-- | dnglib/algs.lua | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/dnglib/algs.lua b/dnglib/algs.lua index d2e6252..b5f331f 100644 --- a/dnglib/algs.lua +++ b/dnglib/algs.lua @@ -150,10 +150,12 @@ end ---@param target_pos table [x, y] -- @param enemies list of enemy positions (cannot pass thru enemy) -- @param treasures list of treasure positions (cannot pass thru treasure) +-- @param door_keys list of key positions (cannot pass thru treasure) +-- @param doors list of door positions (cannot pass thru treasure) ---@param map table 2D map array ---@return table best move to target [x, y] --- -local function pathfind(start_pos, target_pos, enemies, treasures, map) +local function pathfind(start_pos, target_pos, enemies, treasures, door_keys, doors, map) local queue = Queue:new() local visit_map = {} @@ -173,7 +175,13 @@ local function pathfind(start_pos, target_pos, enemies, treasures, map) for _, t in ipairs(treasures) do visit_map[t.y][t.x] = MAP_WALL -- use wall value for impass end - + for _, k in ipairs(door_keys) do + visit_map[k.y][k.x] = MAP_WALL -- use wall value for impass + end + for _, d in ipairs(doors) do + visit_map[d.y][d.x] = MAP_WALL -- use wall value for impass + end + -- since we mutate the visit_map let's calc this early if need be local best_effort = best_effort_move(start_pos, target_pos, visit_map) |