Skip to content

Commit 037bffd

Browse files
committed
Fix Rebecca not noticing her backroom door open. Also the guard will check the backroom if he notices the door open, then lock it. Ref BGforgeNet/Fallout2_Restoration_Project#381
1 parent c33edb7 commit 037bffd

8 files changed

Lines changed: 143 additions & 53 deletions

File tree

data/text/english/dialog/dcrebdor.msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
{357}{}{Nice talking to you too... I'll just be heading back over there then.}
4949

5050
# door open
51-
{375}{}{Oh, shit...}
51+
{375}{}{Oh, shit...}

data/text/english/dialog/dcrebecc.msg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,11 @@
253253
# 29. Still 3(From 28)
254254
{580}{}{So, you're a coward too? Figures.}
255255
{581}{}{...}
256+
257+
# 30. Self Initiated: Door tampered with
258+
# Same as dcrebdor: 230-234
259+
{1230}{}{Get away from that right now.}
260+
{1231}{}{Don't touch that again.}
261+
{1232}{}{Back off!}
262+
{1233}{}{Leave that alone.}
263+
{1234}{}{What do you think you're doing?}

scripts_src/den/dcrebdor.ssl

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,37 @@ procedure Node005;
7777
ndebug("guard post state == "+x); \
7878
set_local_var(LVAR_Post_State, x)
7979

80-
#define check_door_open the_door := false; \
81-
if (becky_door_obj != 0) then \
82-
if ((obj_is_open(becky_door_obj)) and (obj_can_see_obj(self_obj, becky_door_obj))) then \
83-
the_door := true
84-
8580
#define wander_tile (17267)
8681

87-
#define set_becky_guard \
88-
if (becky_guard_obj == 0) then begin \
89-
becky_guard_obj := self_obj; \
90-
end else if (tile_distance_objs(self_obj, dude_obj) < tile_distance_objs(becky_guard_obj, dude_obj)) then begin \
91-
becky_guard_obj := self_obj; \
92-
end
82+
/** South East */
83+
#define DIRECTION_SE 2
84+
/** North West */
85+
#define DIRECTION_NW 5
86+
87+
88+
/**
89+
* Door tile
90+
*/
91+
#define TILE_DOOR tile_num(becky_door_obj)
92+
/**
93+
* Tile near basement entry door
94+
*/
95+
#define TILE_NEAR_DOOR tile_num_in_direction(TILE_DOOR, DIRECTION_SE, 1)
96+
/**
97+
* Tile in basement entry room
98+
*/
99+
#define TILE_NEAR_BASEMENT_ENTRY tile_num_in_direction(TILE_DOOR, DIRECTION_NW, 1)
93100

94101
import variable becky_guard_obj;
95102
import variable becky_door_guard_obj;
96103
import variable becky_door_obj;
97104

98105
variable the_door;
106+
/**
107+
* Guard is in the process of closing the door
108+
*/
109+
variable is_closing = false;
110+
99111

100112
/* Imported variables from the Map scripts. These should only be
101113
pointers and variables that need not be saved. If a variable
@@ -107,6 +119,23 @@ procedure start begin
107119
becky_door_guard_obj := self_obj;
108120
end
109121

122+
/**
123+
* obj_can_see_obj doesn't work from home tile so we also check distance.
124+
* @ret {bool} True if the guard "sees" door open, False otherwise.
125+
*/
126+
procedure see_door_open begin
127+
variable door_is_open = false;
128+
if (becky_door_obj != 0) then begin
129+
if (obj_is_open(becky_door_obj)
130+
and (obj_can_see_obj(self_obj, becky_door_obj) or (tile_distance_objs(self_obj, becky_door_obj) < 3))
131+
)
132+
then begin
133+
door_is_open := true;
134+
end
135+
end
136+
return door_is_open;
137+
end
138+
110139
procedure timed_event_p_proc begin
111140
if (fixed_param == timed_event_door_tamper) then begin
112141
call Node003;
@@ -144,20 +173,54 @@ procedure map_exit_p_proc begin
144173
end
145174

146175
procedure critter_p_proc begin
176+
variable i_see_open_door = see_door_open;
177+
// Guard closed the door, can walk back
178+
if is_closing and (not obj_is_open(becky_door_obj)) then begin
179+
is_closing = false;
180+
end
181+
182+
// P1: attack
147183
if (self_can_see_dude) then begin
148-
check_door_open;
149-
if ((hostile) or (the_door)) then begin
184+
if (hostile or (i_see_open_door and (tile_distance_objs(dude_obj, becky_door_obj) < 2))) then begin
150185
self_attack_dude;
151-
end set_becky_guard
186+
end
187+
end
188+
189+
// P2: attack if found in room
190+
if (self_tile == TILE_NEAR_BASEMENT_ENTRY) then begin
191+
if self_can_see_dude and (tile_distance_objs(self_obj, dude_obj) < 2) then begin
192+
// Remember that PC was in restricted area. Helps if PC ran downstairs.
193+
set_hostile;
194+
self_attack_dude;
195+
end else begin
196+
self_walk_to_tile(TILE_NEAR_DOOR);
197+
obj_close(becky_door_obj);
198+
// ^ Close does not happen immediately, so we reset is_closing higher up
199+
obj_lock(becky_door_obj);
200+
end
201+
return;
202+
end
203+
204+
// P3: close door
205+
if (i_see_open_door) then begin
206+
// Guard is in the process of closing the door, skip
207+
if is_closing then begin
208+
return;
209+
end
210+
// Noticed open door, run to check
211+
is_closing = true;
212+
floater(375);
213+
self_run_to_tile_force(TILE_NEAR_BASEMENT_ENTRY);
214+
return; // Next run will trigger attack or door close.
215+
end
216+
217+
// P4: watch PC
218+
if (self_can_see_dude) then begin
219+
set_becky_guard
152220
end else if (anim_busy(self_obj) == false) then begin
221+
// P5: Normal walking around
153222
if (post_state == post_state_done) then begin
154-
check_door_open;
155-
if (the_door) then begin
156-
if (anim_busy(becky_door_obj) == false) then begin
157-
use_obj_on_obj(self_obj, becky_door_obj);
158-
display_mstr(375);
159-
end
160-
end else if (self_tile != local_var(LVAR_Home_Tile)) then begin
223+
if (self_tile != local_var(LVAR_Home_Tile)) then begin
161224
self_walk_to_tile(local_var(LVAR_Home_Tile));
162225
end else if (self_cur_rot != local_var(LVAR_Home_Rotation)) then begin
163226
self_rotate(local_var(LVAR_Home_Rotation));

scripts_src/den/dcrebecc.ssl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ procedure Node029;
117117
/* Local variables which do not need to be saved between map changes. */
118118
variable prev_node;
119119
import variable becky_guard_obj;
120+
import variable becky_obj;
120121

121122
procedure start begin
122123
end
123124

124125
procedure timed_event_p_proc begin
125-
if (fixed_param == timed_event_float) then begin
126-
if (combat_is_initialized == false) then begin
127-
end
126+
if (fixed_param == timed_event_door_tamper) then begin
127+
floater_rand(1230, 1234);
128128
end
129129
end
130130

@@ -137,6 +137,7 @@ procedure map_enter_p_proc begin
137137
set_local_var(LVAR_Home_Rotation, self_cur_rot);
138138
end
139139
end
140+
becky_obj = self_obj;
140141
end
141142

142143
procedure map_exit_p_proc begin

scripts_src/den/dcrebgrd.ssl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ import variable becky_guard_obj;
5151
prepended by LVAR_ */
5252
#define LVAR_Flags (4)
5353

54-
#define set_becky_guard \
55-
if (becky_guard_obj == 0) then begin \
56-
becky_guard_obj := self_obj; \
57-
end else if (tile_distance_objs(self_obj, dude_obj) < tile_distance_objs(becky_guard_obj, dude_obj)) then begin \
58-
becky_guard_obj := self_obj; \
59-
end
60-
6154
/* Imported variables from the Map scripts. These should only be
6255
pointers and variables that need not be saved. If a variable
6356
Needs to be saved, make it a map variable (MVAR_) */

scripts_src/den/didoor.ssl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
*/
44

55
#include "../headers/den.h"
6-
#include "../generic/ziwoddor.ssl"
6+
#include "../generic/ziwoddor.ssl"

scripts_src/den/direbdor.ssl

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Copyright 1998-2003 Interplay Entertainment Corp. All rights reserved.
33
*/
44

5+
#define SCRIPT_REALNAME "direbdor"
6+
57
import variable becky_guard_obj;
68
import variable becky_door_guard_obj;
79
import variable becky_obj;
@@ -11,23 +13,6 @@ variable user_of_door;
1113

1214
#define LOCKED_STATUS ((STATE_ACTIVE * (becky_dead == false)) + (STATE_INACTIVE * becky_dead))
1315

14-
#define send_tamper_to_guard_who_sees \
15-
check_guard := 0; \
16-
if (becky_guard_obj != 0) then begin \
17-
if (obj_can_see_obj(becky_guard_obj, user_of_door)) then begin \
18-
check_guard := becky_guard_obj; \
19-
end \
20-
end else if (becky_obj != 0) then begin \
21-
if (obj_can_see_obj(becky_obj, user_of_door)) then begin \
22-
check_guard := becky_obj; \
23-
end \
24-
end \
25-
if (becky_door_guard_obj != 0) then begin \
26-
if ((obj_can_see_obj(becky_door_guard_obj, user_of_door)) or (check_guard != 0)) then begin \
27-
check_guard := becky_door_guard_obj; \
28-
end \
29-
end
30-
3116
procedure def_use_p_proc;
3217
procedure def_use_skill_on_p_proc;
3318
procedure def_map_update_p_proc;
@@ -62,9 +47,38 @@ end
6247

6348
#include "../den/didoor.ssl"
6449

50+
/**
51+
* Return the critter who's currently watching Becky's backroom door. The critter will issue a warning.
52+
* One of the guards or Becky herself.
53+
* @param {ObjectPtr} door_user Critter using the door, usually PC.
54+
* @ret {ObjectPtr} Guard critter or 0.
55+
*/
56+
procedure get_guard_object(variable door_user) begin
57+
if (becky_door_guard_obj != 0) then begin
58+
if (obj_can_see_obj(becky_door_guard_obj, door_user)) then begin
59+
ndebug("guard = door guard");
60+
return becky_door_guard_obj;
61+
end
62+
end
63+
if (becky_guard_obj != 0) then begin
64+
if (obj_can_see_obj(becky_guard_obj, door_user)) then begin
65+
ndebug("guard = normal guard");
66+
return becky_guard_obj;
67+
end
68+
end
69+
if (becky_obj != 0) then begin
70+
if (obj_can_see_obj(becky_obj, door_user)) then begin
71+
ndebug("guard = Becky");
72+
return becky_obj;
73+
end
74+
end
75+
return 0;
76+
end
77+
6578
procedure test_use_tamper begin
6679
ndebug("test_use_tamper");
67-
send_tamper_to_guard_who_sees
80+
check_guard = get_guard_object(user_of_door);
81+
ndebug("check_guard = " + check_guard);
6882
if (check_guard != 0) then begin
6983
if (user_of_door == dude_obj) then begin
7084
ndebug(" user_of_door == dude_obj");
@@ -82,7 +96,7 @@ end
8296

8397
procedure test_door_open begin
8498
if ((obj_is_open(self_obj) == false) and (obj_is_locked(self_obj) == false)) then begin
85-
send_tamper_to_guard_who_sees
99+
check_guard = get_guard_object(user_of_door);
86100
if (check_guard != 0) then begin
87101
if (user_of_door == dude_obj) then begin
88102
flush_add_timer_event(check_guard, 0, timed_event_attack);
@@ -97,7 +111,7 @@ procedure test_door_open begin
97111
end
98112

99113
procedure test_use_skill_tamper begin
100-
send_tamper_to_guard_who_sees
114+
check_guard = get_guard_object(user_of_door);
101115
ndebug("test_use_skill_tamper");
102116
if (check_guard != 0) then begin
103117
if ((action_being_used == SKILL_LOCKPICK) or (action_being_used == SKILL_TRAPS)) then begin

scripts_src/headers/den.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,17 @@ variable caught_thief;
585585
end \
586586
end
587587

588+
/**
589+
* Set `becky_guard_obj` to current critter if currently unset or closer to PC that current guard obj.
590+
*/
591+
#define set_becky_guard \
592+
if (becky_guard_obj == 0) then begin \
593+
becky_guard_obj := self_obj; \
594+
end else if (tile_distance_objs(self_obj, dude_obj) < tile_distance_objs(becky_guard_obj, dude_obj)) then begin \
595+
becky_guard_obj := self_obj; \
596+
end
597+
598+
588599
// gang war start
589600
#define setup_gang_fight gfade_out(ONE_GAME_SECOND); \
590601
set_gangwar(state_gangwar_in_fight); \

0 commit comments

Comments
 (0)