Skip to content

Commit 78b232f

Browse files
committed
Avoid Becca's guard getting stuck and not resetting his routine if the door somehow ended up locked open, ref #381
1 parent cb5adac commit 78b232f

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

scripts_src/den/dcrebdor.ssl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ end
175175
procedure critter_p_proc begin
176176
variable i_see_open_door = see_door_open;
177177
// Guard closed the door, can walk back
178-
if is_closing and (not obj_is_open(becky_door_obj)) then begin
178+
if is_closing and not obj_is_open(becky_door_obj) then begin
179179
is_closing = false;
180180
end
181181

@@ -186,17 +186,24 @@ procedure critter_p_proc begin
186186
end
187187
end
188188

189-
// P2: attack if found in room
189+
// P2: check room. Attack PC if found, else close and lock the door
190190
if (self_tile == TILE_NEAR_BASEMENT_ENTRY) then begin
191191
if self_can_see_dude and (tile_distance_objs(self_obj, dude_obj) < 2) then begin
192192
// Remember that PC was in restricted area. Helps if PC ran downstairs.
193193
set_hostile;
194194
self_attack_dude;
195195
end else begin
196196
self_walk_to_tile(TILE_NEAR_DOOR);
197+
198+
// defensive: if the door is "locked open", then unlock first, otherwise close fails and the guard gets stuck
199+
if (obj_is_locked(becky_door_obj)) then begin
200+
obj_unlock(becky_door_obj);
201+
end
197202
obj_close(becky_door_obj);
198203
// ^ Close does not happen immediately, so we reset is_closing higher up
199204
obj_lock(becky_door_obj);
205+
// After door is closed, move back to home tile and reset
206+
set_post_state(post_state_done);
200207
end
201208
return;
202209
end

scripts_src/generic/ziwoddor.ssl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,6 @@ it through Mapper. After the door has been unlocked, it will remain as such, unl
475475
the player locks it once more.
476476
***************************************************************************************/
477477
procedure map_enter_p_proc begin
478-
/* Set up the door state only when the player enters the map, not on game load */
479-
if (is_loading_game) then return;
480-
481478
if (local_var(LVAR_Set_Door_Status) == 0) then begin
482479
set_local_var(LVAR_Set_Door_Status, 1);
483480
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
@@ -486,11 +483,20 @@ procedure map_enter_p_proc begin
486483
// Locked status: locked
487484
if (LOCKED_STATUS == STATE_ACTIVE) then begin
488485
// Ensure that we don't have objects "locked open"
489-
if obj_is_open(self_obj) then begin
490-
obj_close(self_obj);
486+
// Some doors, like Rebecca's basement door, have dynamic status. Active when she's alive, inactive when dead.
487+
if obj_is_open(self_obj) and obj_is_locked(self_obj) then begin
488+
// We don't want to close+re-lock the door on simple game load, that makes gameplay inconsistent.
489+
// So we just unlock. (This shouldn't happen anyway, defensive code)
490+
if is_loading_game then begin
491+
obj_unlock(self_obj);
492+
end else begin
493+
// But if it's map change, close+lock is justified.
494+
// defensive: if the door is "locked open", then unlock first, otherwise close fails
495+
obj_unlock(self_obj);
496+
obj_close(self_obj);
497+
obj_lock(self_obj);
498+
end
491499
end
492-
// Ensure locked status
493-
obj_lock(self_obj);
494500
end else begin
495501
obj_unlock(self_obj);
496502
end

0 commit comments

Comments
 (0)