Skip to content

Commit b85ac21

Browse files
authored
Merge pull request #114 from BGforgeNet/dev/autoclose
Dev/autoclose
2 parents 4664497 + a6eea8c commit b85ac21

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

mods/fo2tweaks.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ improved_grenades=1
1313
molotov_fire=1
1414
; Limit max knockback distance in hexes. -1 is vanilla (unlimited). 0 is no knockback at all. 1 is "up to 1 hex". Etc.
1515
max_knockback=-1
16-
; enable bottomless trunk
16+
; Enable bottomless trunk
1717
trunk_space=0
18-
; automatically open/walk through unlocked doors when not in combat
18+
; Automatically open/walk through unlocked doors when not in combat
19+
; Set to 2 to automatically close the doors then not in combat, too.
1920
autodoors=1
2021
; (virtually) unlimited carry weight
2122
carry_weight=0

source/gl_g_autodoors.ssl

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ procedure start;
66
procedure map_enter_p_proc;
77
procedure set_door_flag(variable state);
88
procedure gamemode_handler;
9+
procedure autoclose;
10+
procedure close_door(variable door);
911

1012
#define PORTAL (0)
1113
#define DOOR_FLAGS (0x24)
14+
15+
/**
16+
* If there's any party member within this distance, door won't autoclose.
17+
*/
18+
#define DOOR_CLOSE_DIST 5
19+
1220
#define set_autodoors "autodoors"
1321
variable only_once = 0;
1422
variable enabled = 0;
1523

1624
procedure start begin
1725
if game_loaded then begin
1826
enabled = fo2tweaks_setting(sec_main, set_autodoors);
19-
if enabled == 1 then begin
27+
if enabled > 0 then begin
2028
register_hook_proc(HOOK_GAMEMODECHANGE, gamemode_handler);
2129
call map_enter_p_proc;
2230
ndebug("initialized");
@@ -25,7 +33,12 @@ procedure start begin
2533
end
2634

2735
procedure map_enter_p_proc begin
28-
if enabled == 1 then call set_door_flag(FLAG_WALKTHRU);
36+
if enabled > 0 then call set_door_flag(FLAG_WALKTHRU);
37+
end
38+
39+
procedure map_update_p_proc begin
40+
if combat_is_initialized then return;
41+
if enabled > 1 then call autoclose;
2942
end
3043

3144
procedure set_door_flag(variable flag) begin
@@ -47,3 +60,26 @@ procedure gamemode_handler begin
4760
ndebug("combat started, disabled walking through doors");
4861
end
4962
end
63+
64+
/**
65+
* Iterate over scenery, call close_door on each door.
66+
*/
67+
procedure autoclose() begin
68+
variable obj;
69+
foreach (obj in list_as_array(LIST_SCENERY)) begin
70+
if is_door(obj) then call close_door(obj);
71+
end
72+
end
73+
74+
/**
75+
* Closes the door, if there are no nearby party members.
76+
*/
77+
procedure close_door(variable door) begin
78+
variable who;
79+
if not (obj_is_open(door)) then return;
80+
if (tile_distance_objs(dude_obj, door) <= DOOR_CLOSE_DIST) then return;
81+
foreach who in party_member_list_critters begin
82+
if (tile_distance_objs(who, door) <= DOOR_CLOSE_DIST) then return;
83+
end
84+
obj_close(door);
85+
end

0 commit comments

Comments
 (0)