Skip to content

Commit 0103a2d

Browse files
committed
Partially refactor cave encounter logic, reduce numbers of critters
1 parent 652ad0e commit 0103a2d

File tree

6 files changed

+86
-352
lines changed

6 files changed

+86
-352
lines changed

scripts_src/headers/cvgenenc.h

Lines changed: 73 additions & 0 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
/*
@@ -244,4 +246,75 @@ procedure placeCritter(variable pid, variable sid, variable baseTile) begin
244246
end
245247
end
246248

249+
procedure PlaceCritterGroup(variable tile) begin
250+
variable count;
251+
252+
count := total_encounter_mobs;
253+
while (count > 0) do begin
254+
call Choose_Pid;
255+
call placeCritter(choose_enc_pid, choose_enc_sid, tile);
256+
count -= 1;
257+
end
258+
end
259+
260+
procedure DistributeCritters(variable areaList, variable numActiveAreas) begin
261+
variable i, idx, tile;
262+
263+
ndebug("total_encounter_mobs = " + total_encounter_mobs + ", areas = " + len_array(areaList) + ", numActive = "+numActiveAreas);
264+
265+
for (i := 0; i < numActiveAreas and len_array(areaList) > 0; i++) begin
266+
idx := random(0, len_array(areaList) - 1);
267+
tile := areaList[idx];
268+
call array_cut(areaList, idx, 1);
269+
call PlaceCritterGroup(tile);
270+
end
271+
end
272+
273+
274+
procedure LoadGenericChests(variable elev, variable tile1, variable tile2, variable tile3) begin
275+
variable obj;
276+
277+
ndebug("Making Chests.");
278+
279+
obj := create_object(PID_CHEST, tile1, elev);
280+
if (obj) then begin
281+
if (Random(1, 2) == 1) then
282+
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, tile1, elev), Random(1, 5));
283+
if (Random(1, 4) == 1) then
284+
if (dude_level > 7) then
285+
add_obj_to_inven(obj, create_object(PID_POWER_FIST, tile1, elev));
286+
else
287+
add_obj_to_inven(obj, create_object(PID_CATTLE_PROD, tile1, elev));
288+
item_caps_adjust(obj, 20 * Random(1, dude_luck));
289+
end
290+
291+
obj := create_object(PID_CHEST, tile2, elev);
292+
if (obj) then begin
293+
if (Random(1, 2) == 1) then
294+
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, tile2, elev), Random(1, 5));
295+
if (Random(1, 4) == 1) then
296+
if (dude_level > 5) then
297+
add_obj_to_inven(obj, create_object(PID_SUPER_SLEDGE, tile2, elev));
298+
else
299+
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, tile2, elev));
300+
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
301+
end
302+
303+
obj := create_object(PID_CHEST, tile3, elev);
304+
if (obj) then begin
305+
if (Random(1, 2) == 1) then
306+
if (dude_level < 7) then
307+
add_mult_objs_to_inven(obj, create_object(PID_FRAG_GRENADE, tile3, elev), Random(1, 5));
308+
else
309+
add_mult_objs_to_inven(obj, create_object(PID_PLASMA_GRENADE, tile3, elev), Random(1, 5));
310+
311+
if (Random(1, 4) == 1) then
312+
if (dude_level > 10) then
313+
add_obj_to_inven(obj, create_object(PID_PLASMA_RIFLE, tile3, elev));
314+
else
315+
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, tile3, elev));
316+
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
317+
end
318+
end
319+
247320
#endif // CVGENENC_H

scripts_src/maps/cave01.ssl

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ procedure map_update_p_proc;
4040
procedure map_exit_p_proc;
4141

4242
procedure LoadCritters;
43-
procedure LoadCritterPos;
4443
procedure LoadChests;
4544

4645
#define AREA_1 12666
@@ -181,114 +180,11 @@ end
181180

182181
procedure LoadCritters begin
183182
call Choose_Encounter;
184-
call LoadCritterPos;
185-
end
186-
187-
procedure LoadCritterPos begin
188-
variable tile;
189-
variable count;
190-
variable obj;
191-
192-
count := total_encounter_mobs;
193-
ndebug("CAVE01: count " + count);
194-
while (count > 0) do begin
195-
call Choose_Pid;
196-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_1);
197-
count -= 1;
198-
end
199-
200-
count := total_encounter_mobs;
201-
while (count > 0) do begin
202-
call Choose_Pid;
203-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_2);
204-
count -= 1;
205-
end
206-
207-
count := total_encounter_mobs;
208-
while (count > 0) do begin
209-
call Choose_Pid;
210-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_3);
211-
count -= 1;
212-
end
213-
214-
count := total_encounter_mobs;
215-
while (count > 0) do begin
216-
call Choose_Pid;
217-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_4);
218-
count -= 1;
219-
end
220-
221-
count := total_encounter_mobs;
222-
while (count > 0) do begin
223-
call Choose_Pid;
224-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_5);
225-
count -= 1;
226-
end
227-
228-
count := total_encounter_mobs;
229-
while (count > 0) do begin
230-
call Choose_Pid;
231-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_6);
232-
count -= 1;
233-
end
234-
235-
count := total_encounter_mobs;
236-
while (count > 0) do begin
237-
call Choose_Pid;
238-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_7);
239-
count -= 1;
240-
end
241-
242-
count := total_encounter_mobs;
243-
while (count > 0) do begin
244-
call Choose_Pid;
245-
call placeCritter(choose_enc_pid, choose_enc_sid, AREA_8);
246-
count -= 1;
247-
end
183+
call DistributeCritters([AREA_1, AREA_2, AREA_3, AREA_4, AREA_5, AREA_6, AREA_7, AREA_8], random(2, 4));
248184
end
249185

250186
procedure LoadChests begin
251187
variable obj;
252188

253-
ndebug("Making Chests.");
254-
255-
obj := create_object(PID_CHEST, CHEST_1, 1);
256-
if (obj) then begin
257-
if (Random(1, 2) == 1) then
258-
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, CHEST_1, 1), Random(1, 5));
259-
if (Random(1, 4) == 1) then
260-
if (dude_level > 7) then
261-
add_obj_to_inven(obj, create_object(PID_POWER_FIST, CHEST_1, 1));
262-
else
263-
add_obj_to_inven(obj, create_object(PID_CATTLE_PROD, CHEST_1, 1));
264-
item_caps_adjust(obj, 20 * Random(1, dude_luck));
265-
end
266-
267-
obj := create_object(PID_CHEST, CHEST_2, 1);
268-
if (obj) then begin
269-
if (Random(1, 2) == 1) then
270-
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, CHEST_2, 1), Random(1, 5));
271-
if (Random(1, 4) == 1) then
272-
if (dude_level > 5) then
273-
add_obj_to_inven(obj, create_object(PID_SUPER_SLEDGE, CHEST_2, 1));
274-
else
275-
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, CHEST_2, 1));
276-
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
277-
end
278-
279-
obj := create_object(PID_CHEST, CHEST_3, 1);
280-
if (obj) then begin
281-
if (Random(1, 2) == 1) then
282-
if (dude_level < 7) then
283-
add_mult_objs_to_inven(obj, create_object(PID_FRAG_GRENADE, CHEST_3, 1), Random(1, 5));
284-
else
285-
add_mult_objs_to_inven(obj, create_object(PID_PLASMA_GRENADE, CHEST_3, 1), Random(1, 5));
286-
287-
if (Random(1, 4) == 1) then
288-
if (dude_level > 10) then
289-
add_obj_to_inven(obj, create_object(PID_PLASMA_RIFLE, CHEST_3, 1));
290-
else
291-
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, CHEST_3, 1));
292-
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
293-
end
189+
call LoadGenericChests(1, CHEST_1, CHEST_2, CHEST_3);
294190
end

scripts_src/maps/cave02.ssl

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ procedure map_update_p_proc;
4242
procedure map_exit_p_proc;
4343

4444
procedure LoadCritters;
45-
procedure LoadCritterPos;
4645
procedure LoadChests;
4746

4847
#define AREA_1 24065
@@ -173,70 +172,11 @@ end
173172

174173
procedure LoadCritters begin
175174
call Choose_Encounter;
176-
call LoadCritterPos;
177-
end
178-
179-
#define AREABLK(area) \
180-
count := total_encounter_mobs; \
181-
while (count > 0) do begin \
182-
call Choose_Pid; \
183-
call placeCritter(choose_enc_pid, choose_enc_sid, area);\
184-
count -= 1; \
185-
end
186-
187-
procedure LoadCritterPos begin
188-
variable tile;
189-
variable count;
190-
variable obj;
191-
192-
AREABLK(AREA_1)
193-
AREABLK(AREA_2)
194-
AREABLK(AREA_3)
195-
AREABLK(AREA_4)
196-
AREABLK(AREA_5)
197-
AREABLK(AREA_6)
175+
call DistributeCritters([AREA_1, AREA_2, AREA_3, AREA_4, AREA_5, AREA_6], random(2, 3));
198176
end
199177

200178
procedure LoadChests begin
201179
variable obj;
202180

203-
obj := create_object(PID_CHEST, CHEST_1, 1);
204-
if (obj) then begin
205-
if (Random(1, 2) == 1) then
206-
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, CHEST_1, 1), Random(1, 5));
207-
if (Random(1, 4) == 1) then
208-
if (dude_level > 7) then
209-
add_obj_to_inven(obj, create_object(PID_POWER_FIST, CHEST_1, 1));
210-
else
211-
add_obj_to_inven(obj, create_object(PID_CATTLE_PROD, CHEST_1, 1));
212-
item_caps_adjust(obj, 20 * Random(1, dude_luck));
213-
end
214-
215-
obj := create_object(PID_CHEST, CHEST_2, 1);
216-
if (obj) then begin
217-
if (Random(1, 2) == 1) then
218-
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, CHEST_2, 1), Random(1, 5));
219-
if (Random(1, 4) == 1) then
220-
if (dude_level > 5) then
221-
add_obj_to_inven(obj, create_object(PID_SUPER_SLEDGE, CHEST_2, 1));
222-
else
223-
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, CHEST_2, 1));
224-
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
225-
end
226-
227-
obj := create_object(PID_CHEST, CHEST_3, 1);
228-
if (obj) then begin
229-
if (Random(1, 2) == 1) then
230-
if (dude_level < 7) then
231-
add_mult_objs_to_inven(obj, create_object(PID_FRAG_GRENADE, CHEST_3, 1), Random(1, 5));
232-
else
233-
add_mult_objs_to_inven(obj, create_object(PID_PLASMA_GRENADE, CHEST_3, 1), Random(1, 5));
234-
235-
if (Random(1, 4) == 1) then
236-
if (dude_level > 10) then
237-
add_obj_to_inven(obj, create_object(PID_PLASMA_RIFLE, CHEST_3, 1));
238-
else
239-
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, CHEST_3, 1));
240-
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
241-
end
181+
call LoadGenericChests(1, CHEST_1, CHEST_2, CHEST_3);
242182
end

scripts_src/maps/cave03.ssl

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ procedure map_update_p_proc;
4242
procedure map_exit_p_proc;
4343

4444
procedure LoadCritters;
45-
procedure LoadCritterPos;
4645
procedure LoadChests;
4746

4847
#define AREA_1 19108
4948
#define AREA_2 19492
5049
#define AREA_3 20692
5150

5251
#define CHEST_1 21675
53-
#define CHEST_2 18092
54-
#define CHEST_3 17908
52+
#define CHEST_2 18294
53+
#define CHEST_3 17910
5554

5655
variable Critter;
5756
variable Critter_Tile;
@@ -170,67 +169,11 @@ end
170169

171170
procedure LoadCritters begin
172171
call Choose_Encounter;
173-
call LoadCritterPos;
174-
end
175-
176-
#define AREABLK(area) \
177-
count := total_encounter_mobs; \
178-
while (count > 0) do begin \
179-
call Choose_Pid; \
180-
call placeCritter(choose_enc_pid, choose_enc_sid, area);\
181-
count -= 1; \
182-
end
183-
184-
procedure LoadCritterPos begin
185-
variable tile;
186-
variable count;
187-
variable obj;
188-
189-
AREABLK(AREA_1)
190-
AREABLK(AREA_2)
191-
AREABLK(AREA_3)
172+
call DistributeCritters([AREA_1, AREA_2, AREA_3], random(1, 2));
192173
end
193174

194175
procedure LoadChests begin
195176
variable obj;
196177

197-
obj := create_object(PID_CHEST, CHEST_1, 1);
198-
if (obj) then begin
199-
if (Random(1, 2) == 1) then
200-
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, CHEST_1, 1), Random(1, 5));
201-
if (Random(1, 4) == 1) then
202-
if (dude_level > 7) then
203-
add_obj_to_inven(obj, create_object(PID_POWER_FIST, CHEST_1, 1));
204-
else
205-
add_obj_to_inven(obj, create_object(PID_CATTLE_PROD, CHEST_1, 1));
206-
item_caps_adjust(obj, 20 * Random(1, dude_luck));
207-
end
208-
209-
obj := create_object(PID_CHEST, CHEST_2, 1);
210-
if (obj) then begin
211-
if (Random(1, 2) == 1) then
212-
add_mult_objs_to_inven(obj, create_object(PID_STIMPAK, CHEST_2, 1), Random(1, 5));
213-
if (Random(1, 4) == 1) then
214-
if (dude_level > 5) then
215-
add_obj_to_inven(obj, create_object(PID_SUPER_SLEDGE, CHEST_2, 1));
216-
else
217-
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, CHEST_2, 1));
218-
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
219-
end
220-
221-
obj := create_object(PID_CHEST, CHEST_3, 1);
222-
if (obj) then begin
223-
if (Random(1, 2) == 1) then
224-
if (dude_level < 7) then
225-
add_mult_objs_to_inven(obj, create_object(PID_FRAG_GRENADE, CHEST_3, 1), Random(1, 5));
226-
else
227-
add_mult_objs_to_inven(obj, create_object(PID_PLASMA_GRENADE, CHEST_3, 1), Random(1, 5));
228-
229-
if (Random(1, 4) == 1) then
230-
if (dude_level > 10) then
231-
add_obj_to_inven(obj, create_object(PID_PLASMA_RIFLE, CHEST_3, 1));
232-
else
233-
add_obj_to_inven(obj, create_object(PID_HUNTING_RIFLE, CHEST_3, 1));
234-
item_caps_adjust(obj, 20 * Random(dude_luck, dude_luck * dude_luck));
235-
end
178+
call LoadGenericChests(1, CHEST_1, CHEST_2, CHEST_3);
236179
end

0 commit comments

Comments
 (0)