Skip to content

Commit

Permalink
NPC weapon destruction: reduce % and add spawning junk (closes #6)
Browse files Browse the repository at this point in the history
- Add resetting statistics when destroy % is changed
- Reduce destroy percent (due to new barter price chances)
- Add randomly spawning one junk instead of destroyed weapon based on it's weight
  • Loading branch information
phobos2077 committed Jun 9, 2024
1 parent a6b9976 commit 6f304ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion root/mods/ecco/combat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions scripts_src/_pbs_main/gl_pbs_critter_loot.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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),
Expand All @@ -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;
Expand Down

0 comments on commit 6f304ae

Please sign in to comment.