@@ -23,14 +23,15 @@ procedure start;
23
23
#include "../_pbs_headers/ecco_ini.h"
24
24
#include "../_pbs_headers/ecco_msg.h"
25
25
26
+ #include "../_pbs_headers/loot_utils.h"
27
+
26
28
variable
27
29
ini_destroy_weapon_percent,
28
30
ini_destroy_weapon_list,
29
31
ini_weapon_drop_chance,
30
32
ini_weapon_drop_dist,
31
33
ini_weapon_drop_dir,
32
- ini_reduce_ammo_percent_min,
33
- ini_reduce_ammo_percent_max,
34
+ ini_reduce_ammo_percent,
34
35
ini_reduce_drugs_percent,
35
36
ini_reduce_drugs_pids;
36
37
@@ -40,7 +41,6 @@ variable destroyed_stats;
40
41
procedure destroy_critter_weapon(variable critter);
41
42
procedure drop_weapons(variable critter);
42
43
procedure reduce_loot(variable critter);
43
- procedure reduce_item_count(variable invenobj, variable item, variable newCount);
44
44
45
45
#define INI_FILE INI_COMBAT
46
46
#define INI_SECTION "CRITTER_LOOT"
@@ -64,7 +64,7 @@ procedure ondeath_handler begin
64
64
return;
65
65
66
66
if (critter and obj_type(critter) == OBJ_TYPE_CRITTER) then begin
67
- if (ini_reduce_ammo_percent_min > 0 or ini_reduce_drugs_percent > 0 or ini_destroy_weapon_percent > 0) then begin
67
+ if (ini_reduce_ammo_percent[1] > 0 or ini_reduce_drugs_percent > 0 or ini_destroy_weapon_percent > 0) then begin
68
68
call reduce_loot(critter);
69
69
end
70
70
if (ini_weapon_drop_chance > 0 and random(1, 100) <= ini_weapon_drop_chance) then begin
@@ -82,8 +82,7 @@ procedure start begin
82
82
load_num_from_ini(weapon_drop_dist, 0, 0, 10);
83
83
load_num_from_ini(weapon_drop_dir, 0, 0, 5);
84
84
85
- load_num_from_ini(reduce_ammo_percent_min, 0, 0, 100);
86
- load_num_from_ini(reduce_ammo_percent_max, ini_reduce_ammo_percent_min, ini_reduce_ammo_percent_min, 100);
85
+ load_range_from_ini(reduce_ammo_percent, 0, 0, 0, 100);
87
86
load_num_from_ini(reduce_drugs_percent, 0, 0, 100);
88
87
load_int_list_from_ini(reduce_drugs_pids);
89
88
@@ -172,67 +171,30 @@ procedure reduce_loot(variable critter) begin
172
171
variable
173
172
item,
174
173
list,
175
- count,
176
- newCount,
177
- packSize,
178
- pid,
179
- removeStats,
180
- weaponStats;
174
+ removeStats;
181
175
182
176
list := inven_as_array(critter);
183
177
removeStats := "";
184
178
foreach item in list begin
185
179
if (item == 0) then
186
180
continue;
187
- pid := obj_pid(item);
188
181
if (obj_item_subtype(item) == item_type_ammo) then begin
189
- if (ini_reduce_ammo_percent_min > 0) then begin
190
- // reduce ammo in measures of individual rounds, not packs
191
- packSize := get_proto_data(pid, PROTO_AM_PACK_SIZE);
192
- count := (obj_is_carrying_obj(critter, item) - 1) * packSize + get_weapon_ammo_count(item);
193
- newCount := round(count * (100 - random(ini_reduce_ammo_percent_min, ini_reduce_ammo_percent_max)) / 100.0);
194
- //display_msg("count: "+count+", pack: "+packSize+", new: "+newCount+" ("+ceil(1.0*newCount / packSize)+")");
195
- call reduce_item_count(critter, item, ceil(1.0*newCount / packSize));
196
- // if number of items reduced, object reference will be different
197
- item := obj_carrying_pid_obj(critter, pid);
198
- if (item and newCount % packSize > 0) then
199
- set_weapon_ammo_count(item, newCount % packSize);
200
-
201
- removeStats += obj_name(item)+" ("+count+" -> "+newCount+"), ";
202
- end
182
+ removeStats += reduce_ammo_in_stack(critter, item, ini_reduce_ammo_percent);
203
183
end
204
184
else if (obj_item_subtype(item) == item_type_drug) then begin
205
- if (ini_reduce_drugs_percent > 0 and is_in_array(pid, ini_reduce_drugs_pids)) then begin
206
- // reduce with probability formula
207
- count := obj_is_carrying_obj(critter, item);
208
- newCount := count * (100 - ini_reduce_drugs_percent) / 100.0;
209
- newCount := floor(newCount) + (random(0, 99) < (newCount - floor(newCount))*100);
210
- call reduce_item_count(critter, item, newCount);
211
- removeStats += obj_name(item)+" ("+count+" -> "+newCount+"), ";
212
- end
185
+ removeStats += reduce_item_in_stack(critter, item, ini_reduce_drugs_pids, ini_reduce_drugs_percent);
213
186
end
214
187
else if (obj_item_subtype(item) == item_type_weapon) then begin
215
- if (ini_destroy_weapon_percent > 0 and is_in_array(pid, ini_destroy_weapon_list)) then
216
- if (try_destroy_weapon(critter, item)) then
188
+ if (ini_destroy_weapon_percent > 0
189
+ and is_in_array(obj_pid(item), ini_destroy_weapon_list)
190
+ and try_destroy_weapon(critter, item)) then
217
191
removeStats += obj_name(item)+", ";
192
+ else
193
+ removeStats += reduce_ammo_in_weapon(item, ini_reduce_ammo_percent);
218
194
end
219
195
end
220
196
if (removeStats != "") then
221
- debug_log("removed loot for "+obj_name(critter)+": "+removeStats);
222
- end
223
-
224
-
225
- procedure reduce_item_count(variable invenobj, variable item, variable newCount) begin
226
- variable count := obj_is_carrying_obj(invenobj, item);
227
- if (newCount >= count) then return;
228
-
229
- count := rm_mult_objs_from_inven(invenobj, item, count - newCount);
230
- destroy_object(item);
197
+ debug_log("Removed loot for "+obj_name(critter)+": "+removeStats);
231
198
end
232
199
233
200
234
-
235
-
236
-
237
-
238
-
0 commit comments