Skip to content

Commit f7db75e

Browse files
authored
Merge pull request #376 from phobos2077/feature/random-caverns-mob-counts
Partially refactor cave encounter logic, reduce numbers of critters
2 parents 2f3ac9d + 860bdff commit f7db75e

File tree

7 files changed

+137
-375
lines changed

7 files changed

+137
-375
lines changed

release/mods/upu.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ critters_walk_faster=1
1515
; Can be toggled midgame.
1616
wipe_inventory=0
1717

18+
; Changes random encounter cavern mob spawn logic for more "sane" number of mobs.
19+
; Instead of spawning a group of the same size in every "area" of the map, it leaves about half of the areas empty.
20+
caverns_reduce_mobs=0
21+
1822
[ncr]
1923
; If enabled, NCR => Redding brahmin drive will be repeatable like Duppo says. But if Hal dies, drives end.
2024
repeatable_brahmin_drive=1

scripts_src/headers/cvgenenc.h

Lines changed: 120 additions & 23 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+
#include "../sfall/lib.arrays.h"
6+
57
#ifndef CVGENENC_H
68
#define CVGENENC_H
79
/*
@@ -26,11 +28,20 @@ variable begin
2628
active_encounter_pids := 0;
2729
total_encounter_mobs := 0; //Per area in map
2830

29-
3031
special_theif_encounter := 0;
3132

3233
choose_enc_pid := 0;
3334
choose_enc_sid := 0;
35+
36+
encounter_mobs_min := 0;
37+
encounter_mobs_max := 0;
38+
39+
caverns_reduce_mobs;
40+
end
41+
42+
procedure SetMobCount(variable min, variable max) begin
43+
encounter_mobs_min := min;
44+
encounter_mobs_max := max;
3445
end
3546

3647
procedure Choose_Encounter begin
@@ -43,77 +54,77 @@ procedure Choose_Encounter begin
4354
if (dude_level < 6) then begin
4455
encounter_pid1 := PID_GECKO_SMALL;
4556
encounter_sid1 := SCRIPT_ECGECKO;
46-
total_encounter_mobs := Random(3, 5);
57+
call SetMobCount(3, 5);
4758
end else if (dude_level < 12) then begin
4859
encounter_pid1 := PID_TOUGH_GECKO_SMALL;
4960
encounter_sid1 := SCRIPT_ECGECKO;
50-
total_encounter_mobs := Random(3, 5);
61+
call SetMobCount(3, 5);
5162
end else if (dude_level < 13) then begin
5263
encounter_pid1 := PID_FIRE_GECKO;
5364
encounter_sid1 := SCRIPT_ECGECKO;
54-
total_encounter_mobs := Random(3, 5);
65+
call SetMobCount(3, 5);
5566
end else begin
5667
encounter_pid1 := PID_TOUGH_FIRE_GECKO;
5768
encounter_sid1 := SCRIPT_ECGECKO;
58-
total_encounter_mobs := Random(3, 5);
69+
call SetMobCount(3, 5);
5970
end
6071
end else if (val == 2) then begin
6172
active_encounter_pids := 1;
6273
if (dude_level < 5) then begin
6374
encounter_pid1 := PID_GOLDEN_GECKO;
6475
encounter_sid1 := SCRIPT_ECGECKO;
65-
total_encounter_mobs := Random(3, 5);
76+
call SetMobCount(3, 5);
6677
end else if (dude_level < 12) then begin
6778
encounter_pid1 := PID_TOUGH_GOLDEN_GECKO;
6879
encounter_sid1 := SCRIPT_ECGECKO;
69-
total_encounter_mobs := Random(3, 5);
80+
call SetMobCount(3, 5);
7081
end else if (dude_level < 13) then begin
7182
encounter_pid1 := PID_FIRE_GECKO;
7283
encounter_sid1 := SCRIPT_ECGECKO;
73-
total_encounter_mobs := Random(3, 5);
84+
call SetMobCount(3, 5);
7485
end else begin
7586
encounter_pid1 := PID_TOUGH_FIRE_GECKO;
7687
encounter_sid1 := SCRIPT_ECGECKO;
77-
total_encounter_mobs := Random(3, 5);
88+
call SetMobCount(3, 5);
7889
end
7990
end else if (val == 3) then begin
8091
active_encounter_pids := 1;
8192
encounter_pid1 := PID_SMALL_RADSCORPION;
8293
encounter_sid1 := SCRIPT_ECSCORP;
83-
total_encounter_mobs := Random(3, 5);
94+
call SetMobCount(3, 5);
8495
end else if (val == 4) then begin
8596
active_encounter_pids := 1;
8697
encounter_pid1 := PID_LARGE_RADSCORPION;
8798
encounter_sid1 := SCRIPT_ECSCORP;
88-
total_encounter_mobs := Random(3, 5);
99+
call SetMobCount(3, 5);
89100
end else if (val == 5) then begin
90101
active_encounter_pids := 1;
91102
encounter_pid1 := PID_SMALL_DEATHCLAW;
92103
encounter_sid1 := SCRIPT_ZCLDTHCL;
93-
total_encounter_mobs := Random(3, 5);
104+
call SetMobCount(3, 5);
94105
end else if (val == 6) then begin
95106
active_encounter_pids := 1;
96107
encounter_pid1 := PID_LARGE_DEATHCLAW;
97108
encounter_sid1 := SCRIPT_ZCLDTHCL;
98-
total_encounter_mobs := 5;
109+
call SetMobCount(5, 5);
99110
end else if (val == 7) then begin
100111
active_encounter_pids := 1;
101112
encounter_pid1 := PID_MUTATED_MOLE_RAT;
102113
encounter_sid1 := SCRIPT_ECRAT;
103-
total_encounter_mobs := Random(3, 5);
114+
call SetMobCount(3, 5);
104115
end else if (val == 8) then begin
105116
active_encounter_pids := 1;
106117
encounter_pid1 := PID_MUTATED_PIG_RAT;
107118
encounter_sid1 := SCRIPT_ECRAT;
108-
total_encounter_mobs := Random(4, 5);
119+
call SetMobCount(4, 5);
109120
end else if (val == 9) then begin
110121
active_encounter_pids := 2;
111122
if (dude_level < 5) then begin
112123
encounter_pid1 := PID_GECKO_SMALL;
113124
encounter_pid2 := PID_GOLDEN_GECKO;
114125
encounter_sid1 := SCRIPT_ECGECKO;
115126
encounter_sid2 := SCRIPT_ECGECKO;
116-
total_encounter_mobs := Random(3, 5);
127+
call SetMobCount(3, 5);
117128
end else begin
118129
encounter_pid1 := PID_TOUGH_GECKO_SMALL;
119130
encounter_pid2 := PID_TOUGH_GOLDEN_GECKO;
@@ -128,29 +139,29 @@ procedure Choose_Encounter begin
128139
encounter_pid3 := PID_TOUGH_FIRE_GECKO;
129140
encounter_sid3 := SCRIPT_ECGECKO;
130141
end
131-
total_encounter_mobs := 5;
142+
call SetMobCount(5, 5);
132143
end
133144
end else if (val == 10) then begin
134145
active_encounter_pids := 2;
135146
encounter_pid1 := PID_SMALL_RADSCORPION;
136147
encounter_pid2 := PID_LARGE_RADSCORPION;
137148
encounter_sid1 := SCRIPT_ECSCORP;
138149
encounter_sid2 := SCRIPT_ECSCORP;
139-
total_encounter_mobs := Random(3, 5);
150+
call SetMobCount(3, 5);
140151
end else if (val == 11) then begin
141152
active_encounter_pids := 2;
142153
encounter_pid1 := PID_SMALL_DEATHCLAW;
143154
encounter_pid2 := PID_LARGE_DEATHCLAW;
144155
encounter_sid1 := SCRIPT_ZCLDTHCL;
145156
encounter_sid2 := SCRIPT_ZCLDTHCL;
146-
total_encounter_mobs := 5;
157+
call SetMobCount(5, 5);
147158
end else if (val == 12) then begin
148159
active_encounter_pids := 2;
149160
encounter_pid1 := PID_MUTATED_MOLE_RAT;
150161
encounter_pid1 := PID_MUTATED_PIG_RAT;
151162
encounter_sid1 := SCRIPT_ECRAT;
152163
encounter_sid2 := SCRIPT_ECRAT;
153-
total_encounter_mobs := 5;
164+
call SetMobCount(5, 5);
154165
end else if (val == 13) then begin
155166
if (stat_success(dude_obj, STAT_lu, 0)) then begin
156167
special_theif_encounter := 1;
@@ -160,19 +171,19 @@ procedure Choose_Encounter begin
160171
encounter_pid2 := PID_MYSTERIOUS_STRANGER_FEMALE;
161172
encounter_sid1 := SCRIPT_ECROBBER;
162173
encounter_sid2 := SCRIPT_ECROBBER;
163-
total_encounter_mobs := Random(2, 3);
174+
call SetMobCount(2, 3);
164175
end else if (dude_level < 11) then begin
165176
encounter_pid1 := PID_BOUNTY_MALE_7_12;
166177
encounter_pid2 := PID_BOUNTY_FEMALE_7_12;
167178
encounter_sid1 := SCRIPT_ECROBBER;
168179
encounter_sid2 := SCRIPT_ECROBBER;
169-
total_encounter_mobs := Random(3, 4);
180+
call SetMobCount(3, 4);
170181
end else begin
171182
encounter_pid1 := PID_BOUNTY_MALE_13_18;
172183
encounter_pid2 := PID_BOUNTY_FEMALE_13_18;
173184
encounter_sid1 := SCRIPT_ECROBBER;
174185
encounter_sid2 := SCRIPT_ECROBBER;
175-
total_encounter_mobs := Random(3, 4);
186+
call SetMobCount(3, 4);
176187
end
177188
end
178189
end
@@ -244,4 +255,90 @@ procedure placeCritter(variable pid, variable sid, variable baseTile) begin
244255
end
245256
end
246257

258+
procedure PlaceCritterGroup(variable tile) begin
259+
variable count;
260+
261+
count := random(encounter_mobs_min, encounter_mobs_max)
262+
if caverns_reduce_mobs
263+
else total_encounter_mobs;
264+
while (count > 0) do begin
265+
call Choose_Pid;
266+
call placeCritter(choose_enc_pid, choose_enc_sid, tile);
267+
count -= 1;
268+
end
269+
end
270+
271+
procedure DistributeCritters(variable areaList, variable numActiveAreas) begin
272+
variable i, idx, tile;
273+
274+
caverns_reduce_mobs := upu_msetting(caverns_reduce_mobs);
275+
if (not caverns_reduce_mobs) then begin
276+
numActiveAreas := len_array(areaList);
277+
total_encounter_mobs := random(encounter_mobs_min, encounter_mobs_max);
278+
end else
279+
total_encounter_mobs := -1;
280+
281+
ndebug("total_encounter_mobs = " + total_encounter_mobs + ", areas = " + len_array(areaList) + ", numActive = "+numActiveAreas);
282+
283+
if (numActiveAreas >= len_array(areaList)) then begin
284+
foreach (tile in areaList) begin
285+
call PlaceCritterGroup(tile);
286+
end
287+
end else begin
288+
for (i := 0; i < numActiveAreas and len_array(areaList) > 0; i++) begin
289+
idx := random(0, len_array(areaList) - 1);
290+
tile := areaList[idx];
291+
call array_cut(areaList, idx, 1);
292+
call PlaceCritterGroup(tile);
293+
end
294+
end
295+
end
296+
297+
298+
procedure LoadGenericChests(variable elev, variable tile1, variable tile2, variable tile3) begin
299+
variable obj;
300+
301+
ndebug("Making Chests.");
302+
303+
obj := create_object(PID_CHEST, tile1, elev);
304+
if (obj) then begin
305+
if (Random(1, 2) == 1) then
306+
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, tile1, elev), Random(1, 5));
307+
if (Random(1, 4) == 1) then
308+
if (dude_level > 7) then
309+
add_obj_to_inven(obj, create_object(PID_POWER_FIST, tile1, elev));
310+
else
311+
add_obj_to_inven(obj, create_object(PID_CATTLE_PROD, tile1, elev));
312+
item_caps_adjust(obj, 20 * Random(1, dude_luck));
313+
end
314+
315+
obj := create_object(PID_CHEST, tile2, elev);
316+
if (obj) then begin
317+
if (Random(1, 2) == 1) then
318+
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, tile2, elev), Random(1, 5));
319+
if (Random(1, 4) == 1) then
320+
if (dude_level > 5) then
321+
add_obj_to_inven(obj, create_object(PID_SUPER_SLEDGE, tile2, elev));
322+
else
323+
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, tile2, elev));
324+
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
325+
end
326+
327+
obj := create_object(PID_CHEST, tile3, elev);
328+
if (obj) then begin
329+
if (Random(1, 2) == 1) then
330+
if (dude_level < 7) then
331+
add_mult_objs_to_inven(obj, create_object(PID_FRAG_GRENADE, tile3, elev), Random(1, 5));
332+
else
333+
add_mult_objs_to_inven(obj, create_object(PID_PLASMA_GRENADE, tile3, elev), Random(1, 5));
334+
335+
if (Random(1, 4) == 1) then
336+
if (dude_level > 10) then
337+
add_obj_to_inven(obj, create_object(PID_PLASMA_RIFLE, tile3, elev));
338+
else
339+
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, tile3, elev));
340+
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
341+
end
342+
end
343+
247344
#endif // CVGENENC_H

0 commit comments

Comments
 (0)