Skip to content

Commit

Permalink
ammocost_mod: export variable instead of procedure to avoid related i…
Browse files Browse the repository at this point in the history
…ssues

- Exported procs in SSL get executed asynchronously, leading to all kinds of issues
  • Loading branch information
phobos2077 committed Jul 16, 2024
1 parent d4d238c commit 41d92eb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions scripts_src/_pbs_main/gl_ammocost_mod.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ variable

procedure start;

export procedure ammocost_mod_get_cost(variable weaponPid);

procedure ammocost_mod_get_cost(variable weaponPid) begin
return ini_ammocost[weaponPid] or 1;
end
export variable pbs_ammocost_map;

/*
HOOK_AMMOCOST
Expand Down Expand Up @@ -58,5 +54,6 @@ procedure start begin
if (len_array(ini_ammocost) > 0) then begin
register_hook_proc(HOOK_AMMOCOST, ammocost_handler);
end
pbs_ammocost_map = ini_ammocost;
end
end
2 changes: 1 addition & 1 deletion scripts_src/_pbs_main/gl_pbs_ai.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ procedure bestweapon_handler begin

if (weapon1 == 0 or weapon2 == 0
or weapon_type(weapon1) != weapon_type(weapon2)
or item_proto_is_hidden(obj_pid(weapon1)) or item_proto_is_hidden(obj_pid(weapon2))) then return;
or proto_item_is_hidden(obj_pid(weapon1)) or proto_item_is_hidden(obj_pid(weapon2))) then return;

variable
weapon1rank := weapon_rank(critter, weapon1, target),
Expand Down
4 changes: 2 additions & 2 deletions scripts_src/_pbs_main/gl_pbs_random_encounters.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end

export variable pbs_random_encounter_placement;

import procedure ammocost_mod_get_cost(variable weaponPid);
import variable pbs_ammocost_map;

#define weapon_pid_can_burst(pid) (weapon_attack_mode1(pid) == ATTACK_MODE_BURST or weapon_attack_mode2(pid) == ATTACK_MODE_BURST)

Expand All @@ -41,7 +41,7 @@ procedure calc_required_spare_ammo(variable weaponPid) begin

return burstSize * random(2, 4)
if canBurst
else ammocost_mod_get_cost(weaponPid) * random(10, 20);
else (pbs_ammocost_map[weaponPid] or 1) * random(10, 20);
end

procedure ensure_npcs_ammo begin
Expand Down

0 comments on commit 41d92eb

Please sign in to comment.