diff --git a/root/mods/ecco/combat.ini b/root/mods/ecco/combat.ini index e57b120..6fc735b 100644 --- a/root/mods/ecco/combat.ini +++ b/root/mods/ecco/combat.ini @@ -102,7 +102,13 @@ weapon_drop_dist=2 weapon_drop_dir=0 ; % of times critter's weapon will be destroyed on death -destroy_weapon_percent=50 +destroy_weapon_percent=30 + +; pid of junk item to spawn in place of destroyed weapon +destroy_weapon_spawn_junk_pid=98 + +; if weapon is destroyed, it's weight will be multiplied by this value and used as probability to spawn Junk in it's place +destroy_weapon_spawn_junk_chance_mult=4 ; comma-separated list of weapon PIDs that may be destroyed by "destroy_weapon_chance" destroy_weapon_list=5,6,8,9,10,11,12,13,15,16,18,22,23,24,28,94,115,116,118,122,143,160,233,235,242,268,283,287,296,299,300,313,332,350,351,352,353,354,355,385,387,388,389,391,392,394,395,396,397,398,399,400,401,402,403,404,405,406,407,500,522,617,629,630,634,638,639,640,643,644,646,647,648 diff --git a/scripts_src/_pbs_main/gl_pbs_critter_loot.ssl b/scripts_src/_pbs_main/gl_pbs_critter_loot.ssl index c7ff0d0..9b2fdd3 100644 --- a/scripts_src/_pbs_main/gl_pbs_critter_loot.ssl +++ b/scripts_src/_pbs_main/gl_pbs_critter_loot.ssl @@ -28,6 +28,8 @@ procedure start; variable ini_destroy_weapon_percent, ini_destroy_weapon_list, + ini_destroy_weapon_spawn_junk_pid, + ini_destroy_weapon_spawn_junk_chance_mult, ini_weapon_drop_chance, ini_weapon_drop_dist, ini_weapon_drop_dir, @@ -79,6 +81,8 @@ procedure start begin load_num_from_ini(destroy_weapon_percent, 0, 0, 100); load_int_list_from_ini(destroy_weapon_list); + load_num_from_ini_unclamped(destroy_weapon_spawn_junk_pid, 0); + load_num_from_ini(destroy_weapon_spawn_junk_chance_mult, 0.0, 0.0, 100.0); load_num_from_ini(weapon_drop_chance, 0, 0, 100); load_num_from_ini(weapon_drop_dist, 0, 0, 10); load_num_from_ini(weapon_drop_dir, 0, 0, 5); @@ -96,11 +100,28 @@ end #define stats_pack(destroyed, dropped) (((destroyed bwand 0xFFFF) * 0x10000) + (dropped bwand 0xFFFF)) +procedure spawn_junk_from_weapon(variable critter, variable weapon) begin + variable chance := ini_destroy_weapon_spawn_junk_chance_mult, pid := ini_destroy_weapon_spawn_junk_pid; + if (chance <= 0 or pid == 0) then return; + + chance *= proto_data(obj_pid(weapon), it_weight); + if (random(0, 99) < chance) then begin + call add_item_pid(critter, pid); + debug_log("Spawning junk."); + end +end + // Destroy % of dropped weapons deterministically by counting how many was destroyed and dropped. procedure try_destroy_weapon(variable critter, variable weapon) begin if (destroyed_stats == 0) then destroyed_stats := load_create_array_map(ARR_DESTROYED_WEAPONS); + // Reset stats if percent setting was changed. + if (destroyed_stats[-1] != ini_destroy_weapon_percent) then begin + debug_log("destroy_weapon_percent was changed, resetting stats."); + clear_array(destroyed_stats); + destroyed_stats[-1] := ini_destroy_weapon_percent; + end variable pid := obj_pid(weapon), count := obj_is_carrying_obj(critter, weapon), @@ -118,6 +139,7 @@ procedure try_destroy_weapon(variable critter, variable weapon) begin display_msg(string_format(mstr_ecco_combat(200 + is_female(critter)*10 + random(0, 2)), obj_name(critter), obj_name(weapon))); variable toRemove := count / 2 if count > 1 else 1; removed := rm_mult_objs_from_inven(critter, weapon, toRemove); + call spawn_junk_from_weapon(critter, weapon); destroy_object(weapon); destroyedSoFar += toRemove; removed := true;