-- base methods for ant's enigma maps -- (c) 2002 Petr Machata/ant_39 -- Licensed under GPL v2.0 or above TRANSPOSE_MAP = 1 NO_TRANSPOSE_MAP = not(TRANSPOSE_MAP) -- each item: -- + face - name of stone/floor/item -- + attr - set of attributes of stone/floor/item function cell_item(it) local n_it = {} n_it.face = (it.face or "") n_it.attr = (it.attr or {}) return n_it end -- each cell -- + stone - if present, the stone shall be added to defined position -- + floor - the same, but for floor -- + item - the same, but for item -- ++ actor - if actor=1 is set at item, set_actor shall be used instead of set_item function cell(structure) local cell = {} cell.tag = (structure.tag or "?") cell.setactor = structure.setactor cell.floor = cell_item(structure.floor or {}) cell.stone = cell_item(structure.stone or {}) cell.item = cell_item(structure.item or {}) return function(x, y) --call parents if (%structure.parent) then for i,parfun in %structure.parent do parfun(x,y) end end --map elements if (%structure.stone) then set_stone(%cell.stone.face, x, y, %cell.stone.attr) end if (%structure.floor) then set_floor(%cell.floor.face, x, y, %cell.floor.attr) end if (%structure.item) then if (%structure.item.actor) then set_actor(%cell.item.face, x+0.5, y+0.5, %cell.item.attr) else set_item(%cell.item.face, x, y, %cell.item.attr) end end end end -- this draws the map to the position [x0,y0] function draw_map(x0, y0, map, swap_coords) for y,str in map do for x = 1,strlen(str) do cell = strchar(strbyte(str,x)) if (swap_coords) then cells[cell](y+y0-1, x+x0-1) else cells[cell](x+x0-1, y+y0-1) end end end end