Skip to content

Commit 2e51884

Browse files
committed
Unify and simplify door/container map_enter_p_proc
Ref BGforgeNet/Fallout2_Unofficial_Patch#61 #381
1 parent 3c77ba6 commit 2e51884

25 files changed

Lines changed: 66 additions & 430 deletions

scripts_src/abbey/abbilbox.ssl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,9 @@ end
6767
the player locks it once more.
6868
***************************************************************************************/
6969
procedure map_enter_p_proc begin
70-
//added by killap
71-
variable tmp;
72-
variable special_item;
73-
//end added
70+
call map_enter_p_proc_vanilla;
7471

75-
/* Set up the door state when the player first enters the map */
7672
abbey_bill_box_obj := self_obj;
77-
if (local_var(LVAR_Set_Door_Status) == 0) then begin
78-
set_local_var(LVAR_Set_Door_Status,1);
79-
set_local_var(LVAR_Locked,LOCKED_STATUS);
80-
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
81-
end
82-
8373
if (unsigned_int_compare(local_var(LVAR_Restock_Time), game_time) < 0) then begin
8474
variable tmp_box := move_quest_items();
8575
check_restock_item(PID_BOTTLE_CAPS, 150, 225, 100)
@@ -102,17 +92,6 @@ procedure map_enter_p_proc begin
10292
call restore_critical_items(tmp_box);
10393
set_local_var(LVAR_Restock_Time, (10 * ONE_GAME_DAY) + game_time);
10494
end
105-
106-
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
107-
// Ensure that we don't have objects "locked open"
108-
if obj_is_open(self_obj) then begin
109-
obj_close(self_obj);
110-
end
111-
// Ensure locked status
112-
obj_lock(self_obj);
113-
end else begin
114-
obj_unlock(self_obj);
115-
end
11695
end
11796

11897

scripts_src/arroyo/aitemdor.ssl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ end
7474
***************************************************************************************/
7575

7676
procedure map_enter_p_proc begin
77-
78-
/* Set up the door state when the player first enters the map */
77+
/* Set up the door state when the player first enters the map */
7978
if (local_var(LVAR_Set_Door_Status) == 0) then begin
8079
set_local_var(LVAR_Set_Door_Status,1);
8180
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
@@ -87,12 +86,7 @@ procedure map_enter_p_proc begin
8786
end
8887

8988
if ( (local_var(LVAR_Locked) == STATE_ACTIVE) and (global_var(GVAR_START_ARROYO_TRIAL) <= TRIAL_NONE) ) then begin //edit by killap - added (global_var(GVAR_START_ARROYO_TRIAL) <= TRIAL_NONE)
90-
// Ensure that we don't have objects "locked open"
91-
if obj_is_open(self_obj) then begin
92-
obj_close(self_obj);
93-
end
94-
// Ensure locked status
95-
obj_lock(self_obj);
89+
call close_and_lock_self;
9690
end else begin
9791
obj_unlock(self_obj);
9892
set_local_var(LVAR_Locked,STATE_INACTIVE); //added by killap

scripts_src/brokhill/hscrldr.ssl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,26 +281,23 @@ end
281281

282282
procedure map_enter_p_proc begin
283283

284-
/* Set up the door state when the player first enters the map */
284+
/* Set up the door state when the player first enters the map */
285285
if (local_var(LVAR_Set_Door_Status) == 0) then begin
286286
set_local_var(LVAR_Set_Door_Status,1);
287287
set_local_var(LVAR_Locked,LOCKED_STATUS);
288288
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
289289
end
290290

291+
// TODO - why?
291292
//added by killap
292293
if ( (obj_is_locked(self_obj)) and (local_var(LVAR_Locked) != STATE_ACTIVE) ) then begin
293294
set_local_var(LVAR_Locked,STATE_ACTIVE);
294295
end
295296
//end added
297+
// end TODO
296298

297299
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
298-
// Ensure that we don't have objects "locked open"
299-
if obj_is_open(self_obj) then begin
300-
obj_close(self_obj);
301-
end
302-
// Ensure locked status
303-
obj_lock(self_obj);
300+
call close_and_lock_self;
304301
end else begin
305302
obj_unlock(self_obj);
306303
end

scripts_src/den/diflkbox.ssl

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ end
5656

5757
procedure map_enter_p_proc begin
5858
den_flick_box_obj := self_obj;
59-
/* Set up the locked state when the player first enters the map */
60-
if (local_var(LVAR_Set_Door_Status) == 0) then begin
61-
set_local_var(LVAR_Set_Door_Status,1);
62-
set_local_var(LVAR_Locked,LOCKED_STATUS);
63-
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
64-
end
59+
60+
call map_enter_p_proc_vanilla;
6561

6662
if (unsigned_int_compare(local_var(LVAR_Restock_Time), game_time) < 0) then begin
6763
variable tmp_box := move_quest_items();
@@ -79,18 +75,6 @@ procedure map_enter_p_proc begin
7975
call restore_critical_items(tmp_box);
8076
set_local_var(LVAR_Restock_Time, (random(7,14) * ONE_GAME_DAY) + game_time);
8177
end
82-
83-
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
84-
// Ensure that we don't have objects "locked open"
85-
if obj_is_open(self_obj) then begin
86-
obj_close(self_obj);
87-
end
88-
// Ensure locked status
89-
obj_lock(self_obj);
90-
end else begin
91-
obj_unlock(self_obj);
92-
end
93-
9478
end
9579

9680
/**************************************************************************************

scripts_src/den/direbbok.ssl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ variable the_line;
5454
game_time_advance((11 - dude_iq) * (ONE_GAME_HOUR));
5555
dude_floater(the_line);
5656
gfade_in(ONE_GAME_SECOND);
57-
end
57+
end

scripts_src/generic/ziwoddor.ssl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,10 @@ 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-
call ensure_no_locked_open;
479-
480-
/* Don't change door state when player is already on the map */
478+
/* Don't change state when player is already on the map */
481479
if is_loading_game then return;
482480

483-
// Initial setup runs once per game
481+
/* Set up the state vars when the player first enters the map */
484482
if (local_var(LVAR_Set_Door_Status) == 0) then begin
485483
set_local_var(LVAR_Set_Door_Status, 1);
486484
obj_unlock(self_obj);

scripts_src/headers/command.h

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,33 +1371,14 @@ variable removed_qty;
13711371

13721372
// DOORS //
13731373
/**
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".
1374+
* Ensures that the object is closed and locked.
13981375
*/
13991376
procedure close_and_lock_self begin
14001377
if obj_is_open(self_obj) then begin
1378+
// "Locked open" objects cannot close
1379+
if obj_is_locked(self_obj) then begin
1380+
obj_unlock(self_obj);
1381+
end
14011382
obj_close(self_obj);
14021383
end
14031384
obj_lock(self_obj);

scripts_src/headers/doors_containers.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ procedure Super_Set_Lockpick_Lock;
110110
procedure trap_search_result(variable found_trap, variable who);
111111
procedure real_explosion(variable explosive);
112112
procedure roll_critical;
113+
procedure map_enter_p_proc_vanilla;
113114
/*****************************************************************
114115
Local Variables which are saved. All Local Variables need to be
115116
prepended by LVAR_
@@ -1214,6 +1215,28 @@ on your lockpick and traps skills and perception to notice things.
12141215
end
12151216
#endif
12161217

1218+
/**
1219+
* Standard door/container map_enter_p_proc, full body split for easy reuse in customized scripts
1220+
*/
1221+
procedure map_enter_p_proc_vanilla begin
1222+
/* Don't change state when player is already on the map */
1223+
if is_loading_game then return;
1224+
1225+
/* Set up the state vars when the player first enters the map */
1226+
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);
1230+
end
1231+
1232+
/* Set up the state when the player enters the map */
1233+
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
1234+
call close_and_lock_self;
1235+
end else begin
1236+
obj_unlock(self_obj);
1237+
end
1238+
end
1239+
12171240
/***************************************************************************************
12181241
Whenever the map is first entered, this procedure will be called. The main purpose of
12191242
this procedure is to lock the door from the outset, rather than having to worry about
@@ -1222,25 +1245,10 @@ the player locks it once more.
12221245
***************************************************************************************/
12231246
#ifndef custom_map_enter_p_proc
12241247
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-
1230-
/* Set up the door state when the player first enters the map */
1231-
if (local_var(LVAR_Set_Door_Status) == 0) then begin
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);
1235-
end
1236-
1237-
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
1238-
call close_and_lock_self;
1239-
end else begin
1240-
obj_unlock(self_obj);
1241-
end
1248+
call map_enter_p_proc_vanilla;
12421249
end
12431250
#endif
1251+
12441252
/**************************************************************************************
12451253
This procedure gets called roughly every 30 seconds of real time. It is used to make
12461254
sure that the door does not lock on it's own and that the player will be able to get

scripts_src/klamath/kibbox.ssl

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ end
5454
procedure map_enter_p_proc begin
5555
/* Set up the door state when the player first enters the map */
5656
klam_bucknr_box_obj := self_obj;
57-
if (local_var(LVAR_Set_Door_Status) == 0) then begin
58-
set_local_var(LVAR_Set_Door_Status,1);
59-
set_local_var(LVAR_Locked,LOCKED_STATUS);
60-
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
61-
end
57+
call map_enter_p_proc_vanilla;
6258

6359
if (unsigned_int_compare(local_var(LVAR_Restock_Time), game_time) < 0) then begin
6460
variable tmp_box := move_quest_items();
@@ -82,19 +78,6 @@ procedure map_enter_p_proc begin
8278
call restore_critical_items(tmp_box);
8379
set_local_var(LVAR_Restock_Time, (2 * ONE_GAME_DAY) + game_time);
8480
end
85-
86-
87-
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
88-
// Ensure that we don't have objects "locked open"
89-
if obj_is_open(self_obj) then begin
90-
obj_close(self_obj);
91-
end
92-
// Ensure locked status
93-
obj_lock(self_obj);
94-
end else begin
95-
obj_unlock(self_obj);
96-
end
97-
9881
end
9982

10083
/**************************************************************************************

scripts_src/klamath/kidbox.ssl

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ end
5454
***************************************************************************************/
5555

5656
procedure map_enter_p_proc begin
57-
/* Set up the door state when the player first enters the map */
5857
klam_dunton_box_obj := self_obj;
59-
if (local_var(LVAR_Set_Door_Status) == 0) then begin
60-
set_local_var(LVAR_Set_Door_Status,1);
61-
set_local_var(LVAR_Locked,LOCKED_STATUS);
62-
set_local_var(LVAR_Trapped,TRAPPED_STATUS);
63-
end
58+
59+
call map_enter_p_proc_vanilla;
6460

6561
if (unsigned_int_compare(local_var(LVAR_Restock_Time), game_time) < 0) then begin
6662
variable tmp_box := move_quest_items();
@@ -73,18 +69,6 @@ procedure map_enter_p_proc begin
7369
call restore_critical_items(tmp_box);
7470
set_local_var(LVAR_Restock_Time, (21 * ONE_GAME_DAY) + game_time);
7571
end
76-
77-
if (local_var(LVAR_Locked) == STATE_ACTIVE) then begin
78-
// Ensure that we don't have objects "locked open"
79-
if obj_is_open(self_obj) then begin
80-
obj_close(self_obj);
81-
end
82-
// Ensure locked status
83-
obj_lock(self_obj);
84-
end else begin
85-
obj_unlock(self_obj);
86-
end
87-
8872
end
8973

9074
/**************************************************************************************

0 commit comments

Comments
 (0)