From c390c024f6bed8a1abbec40a320e1fc39f2f5468 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 21 Aug 2018 12:56:02 +0200 Subject: [PATCH] Fixes #40, Prevent adjecant traps before lvl 4 Made the simplest solution possible here. An A* start algo to check that we didn't block paths seemed overkill. --- data/trapgen.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/data/trapgen.lua b/data/trapgen.lua index 2948d75..8edbd1c 100644 --- a/data/trapgen.lua +++ b/data/trapgen.lua @@ -35,9 +35,25 @@ function module.add_traps_to_room(room) while i < count do local rx = random(13) + 1 local ry = random(9) + 1 - if room_builder.is_tile_avilable(room, rx, ry) then - room.traps[rx][ry] = traps[random(#traps)] - i = i + 1 + if CURRENT_LEVEL < 4 then + if room_builder.is_tile_avilable(room, rx, ry) + and not room.traps[rx+1][ry] + and not room.traps[rx-1][ry] + and not room.traps[rx][ry+1] + and not room.traps[rx][ry-1] + and not room.traps[rx+1][ry+1] + and not room.traps[rx+1][ry-1] + and not room.traps[rx-1][ry+1] + and not room.traps[rx-1][ry-1] + then + room.traps[rx][ry] = traps[random(#traps)] + i = i + 1 + end + else + if room_builder.is_tile_avilable(room, rx, ry) then + room.traps[rx][ry] = traps[random(#traps)] + i = i + 1 + end end end end