Skip to content

Commit 3c77ba6

Browse files
committed
Even more robust no-locked-open policy.
Ref #381 BGforgeNet/Fallout2_Unofficial_Patch#61
1 parent 932039f commit 3c77ba6

3 files changed

Lines changed: 47 additions & 37 deletions

File tree

scripts_src/generic/ziwoddor.ssl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ procedure Damage_Critter;
127127
procedure trap_search_result(variable found_trap, variable who);
128128
procedure real_explosion(variable explosive);
129129
procedure roll_critical;
130-
procedure ensure_no_locked_open;
131130

132131
/*****************************************************************
133132
Local Variables which are saved. All Local Variables need to be
@@ -478,7 +477,7 @@ the player locks it once more.
478477
procedure map_enter_p_proc begin
479478
call ensure_no_locked_open;
480479

481-
/* Set up the door state when the player enters the map */
480+
/* Don't change door state when player is already on the map */
482481
if is_loading_game then return;
483482

484483
// Initial setup runs once per game
@@ -492,37 +491,12 @@ procedure map_enter_p_proc begin
492491
// Some doors, like Rebecca's basement door, have dynamic LOCKED_STATUS. Active when she's alive, inactive when dead.
493492
// Same for Eldrige, etc. They re-lock on re-entering the map.
494493
if (LOCKED_STATUS == STATE_ACTIVE) then begin
495-
if obj_is_open(self_obj) then begin
496-
obj_close(self_obj);
497-
end
498-
obj_lock(self_obj);
494+
call close_and_lock_self;
499495
end else begin
500496
obj_unlock(self_obj);
501497
end
502498
end
503499

504-
/**
505-
* Ensure that we don't have objects "locked open".
506-
* This shouldn't happen, but apparently does.
507-
* If we're entering a map, and the object is "locked open", then close it.
508-
* If we're loading a game, (already on the map) then just unlock.
509-
*/
510-
procedure ensure_no_locked_open begin
511-
// If not "locked open", skip
512-
if not (obj_is_open(self_obj) and obj_is_locked(self_obj)) then return;
513-
514-
// We don't want to close+re-lock the door on simple game load, that makes gameplay inconsistent. So we just unlock.
515-
if is_loading_game then begin
516-
obj_unlock(self_obj);
517-
end else begin
518-
// But if it's map change, close+lock is justified.
519-
// defensive: if the door is "locked open", then unlock first, otherwise close fails
520-
obj_unlock(self_obj);
521-
obj_close(self_obj);
522-
obj_lock(self_obj);
523-
end
524-
end
525-
526500
/**************************************************************************************
527501
This procedure gets called roughly every 30 seconds of real time. It is used to make
528502
sure that the door does not lock on it's own and that the player will be able to get

scripts_src/headers/command.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,4 +1369,39 @@ variable removed_qty;
13691369
)
13701370
#define can_be_gas_poisoned(x) ((x == dude_obj) and not (protected_from_gas(x)))
13711371

1372+
// DOORS //
1373+
/**
1374+
* Ensure that we don't have objects "locked open".
1375+
* This shouldn't happen, but apparently does.
1376+
* If we're entering a map, and the object is "locked open", then close it.
1377+
* If we're loading a game, (already on the map) then just unlock.
1378+
*/
1379+
procedure ensure_no_locked_open begin
1380+
// If not "locked open", skip
1381+
if not (obj_is_open(self_obj) and obj_is_locked(self_obj)) then return;
1382+
1383+
// We don't want to close+re-lock the door on game load, that makes gameplay inconsistent. So we just unlock.
1384+
if is_loading_game then begin
1385+
obj_unlock(self_obj);
1386+
end else begin
1387+
// But if PC enters the map, close+lock is justified.
1388+
// defensive: if the object is "locked open", then unlock first, otherwise close fails
1389+
obj_unlock(self_obj);
1390+
obj_close(self_obj);
1391+
obj_lock(self_obj);
1392+
end
1393+
end
1394+
1395+
/**
1396+
* Optionally closes, then non-optionally locks `self_obj`.
1397+
* So that we don't have objects "locked open".
1398+
*/
1399+
procedure close_and_lock_self begin
1400+
if obj_is_open(self_obj) then begin
1401+
obj_close(self_obj);
1402+
end
1403+
obj_lock(self_obj);
1404+
end
1405+
// END DOORS
1406+
13721407
#endif // COMMAND_H

scripts_src/headers/doors_containers.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,19 +1222,20 @@ the player locks it once more.
12221222
***************************************************************************************/
12231223
#ifndef custom_map_enter_p_proc
12241224
procedure map_enter_p_proc begin
1225+
call ensure_no_locked_open;
1226+
1227+
/* Don't change door state when player is already on the map */
1228+
if is_loading_game then return;
1229+
12251230
/* Set up the door state when the player first enters the map */
12261231
if (local_var(LVAR_Set_Door_Status) == 0) then begin
1227-
set_local_var(LVAR_Set_Door_Status,1);
1228-
set_local_var(LVAR_Locked,LOCKED_STATUS);
1229-
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
1232+
set_local_var(LVAR_Set_Door_Status, 1);
1233+
set_local_var(LVAR_Locked, LOCKED_STATUS);
1234+
set_local_var(LVAR_Trapped, TRAPPED_STATUS);
12301235
end
1236+
12311237
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
1232-
// Ensure that we don't have objects "locked open"
1233-
if obj_is_open(self_obj) then begin
1234-
obj_close(self_obj);
1235-
end
1236-
// Ensure locked status
1237-
obj_lock(self_obj);
1238+
call close_and_lock_self;
12381239
end else begin
12391240
obj_unlock(self_obj);
12401241
end

0 commit comments

Comments
 (0)