more PR #1051 - water-vault escape item

When generating an "escape item" inside one of the chests in the
"water-surrounded vault" theme room, make sure that the chest is not
locked if the item is made of glass or crystal.  Otherwise kicking the
chest to get access to its contents might destroy the item.

I imagine that this could be done more cleanly, but after quite a bit
of thrashing about I have something which seems to work.  To test, I
temporarily modified object shuffling to force wand of digging to be
made out of crystal and gave the water-vault a very high generation
frequency.
This commit is contained in:
PatR
2023-07-21 15:00:54 -07:00
parent ca99dfaeeb
commit d99b549bb0
2 changed files with 15 additions and 3 deletions

View File

@@ -634,14 +634,26 @@ xx|.....|xx
-- Guarantee an escape item inside one of the chests, to prevent the hero
-- falling in from above and becoming permanently stuck
-- [cf. generate_way_out_method(sp_lev.c)].
-- If the escape item is made of glass or crystal, make sure that the
-- chest isn't locked so that kicking it to gain access to its contents
-- won't be necessary; otherwise retain lock state from random creation.
-- "pick-axe", "dwarvish mattock" could be included in the list of escape
-- items but don't normally generate in containers.
local escape_items = {
"scroll of teleportation", "ring of teleportation",
"wand of teleportation", "wand of digging"
};
local box = des.object({ id = "chest", coord = chest_spots[1] })
box:addcontent(obj.new(escape_items[math.random(#escape_items)]));
local itm = obj.new(escape_items[math.random(#escape_items)]);
local itmcls = itm:class()
local lckd;
if itmcls[ "material" ] == 19 then -- GLASS==19
lckd = false; -- for glass item, force box to be unlocked
else
lckd = itm.locked; -- else keep random lock state from box's creation
end;
local box = des.object({ id = "chest", coord = chest_spots[1],
locked = lckd });
box:addcontent(itm);
for i = 2, #chest_spots do
des.object({ id = "chest", coord = chest_spots[i] });

View File

@@ -188,6 +188,7 @@ l_obj_objects_to_table(lua_State *L)
if (otyp == -1) {
nhl_error(L, "l_obj_objects_to_table: Wrong args");
/*NOTREACHED*/
return 0;
}
@@ -489,7 +490,6 @@ l_obj_timer_has(lua_State *L)
return 0;
}
/* peek at an object timer. return the turn when timer triggers.
returns 0 if no such timer attached to the object. */
/* local timeout = o:peek_timer("hatch-egg"); */