From f9443b14682d73ace0e7b4ef352a01d1b1aa761b Mon Sep 17 00:00:00 2001 From: Linus_Probert Date: Fri, 16 Feb 2018 09:10:05 +0100 Subject: [PATCH] Hopefully fixes the "exit under decor" problem for the last time. --- data/maproombuilder.lua | 11 ++++++++--- src/map.h | 1 - src/map_lua.c | 14 +++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/data/maproombuilder.lua b/data/maproombuilder.lua index 16dae90..afe4f54 100644 --- a/data/maproombuilder.lua +++ b/data/maproombuilder.lua @@ -121,12 +121,17 @@ local function repack(data) end local function check_add_decoration(map, x, y, data) - if tile_occupied(map, x, y) then return end + if tile_occupied(map, x, y) then + return false + end add_decoration(map, x, y, repack(data)) + return true end local function check_add_tile(map, x, y, data) - if tile_occupied(map, x, y) then return false end + if tile_occupied(map, x, y) then + return false + end add_tile(map, x, y, repack(data)) return true end @@ -232,7 +237,7 @@ local function add_level_exit(map) while not success do x = random(14) y = random(10) - success = check_add_tile(map, x, y, special.level_exit); + success = check_add_tile(map, x, y, special.level_exit) end end diff --git a/src/map.h b/src/map.h index 49fd93a..450e946 100644 --- a/src/map.h +++ b/src/map.h @@ -24,7 +24,6 @@ typedef struct MapTile_t { typedef struct Room_t { MapTile* tiles[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; - MapTile* secondary_tiles[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; MapTile* decorations[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT]; } Room; diff --git a/src/map_lua.c b/src/map_lua.c index 7e45cae..cdfc4f6 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -153,10 +153,13 @@ int l_tile_occupied(lua_State *L) { Map *map; Room *room; - MapTile *tile; + MapTile *tile, *decor; Position *rPos; int x, y; + bool response = false; + tile = NULL; + decor = NULL; map = luaL_checkmap(L, 1); x = (int) luaL_checkinteger(L, 2); @@ -164,9 +167,14 @@ int l_tile_occupied(lua_State *L) rPos = &map->currentRoom; room = map->rooms[rPos->x][rPos->y]; - tile = room->tiles[x][y]; - lua_pushboolean(L, tile->collider || tile->levelExit); + tile = room->tiles[x][y]; + decor = room->decorations[x][y]; + + response = response || (tile && (tile->collider || tile->levelExit)); + response = response || (decor && (decor->collider || decor->levelExit)); + + lua_pushboolean(L, response); return 1; }