Skip to content

Commit

Permalink
pbs_ai: replace use of import proc with import var + reused code (closes
Browse files Browse the repository at this point in the history
 #22)

- Because exported procs are async and just asking for trouble
  • Loading branch information
phobos2077 committed Aug 13, 2024
1 parent f9c6656 commit b1903b7
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 75 deletions.
2 changes: 0 additions & 2 deletions docs/todo.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
for 1.0.0:
- finish Big Guns run
- review merchant loot reduction rules
- add warning message if wrong sfall version is used (save version to ini, if it changed and still wrong, show message again)
- add tie-ins to barter "demand" feature, have some trader explain it in dialog (and maybe also boost your barter skill)
- try to make expanded awareness less verbose and distracting


for "future":
Expand Down
80 changes: 80 additions & 0 deletions scripts_src/_pbs_headers/damage_mod.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef DAMAGE_MOD_H
#define DAMAGE_MOD_H

#define DT_MODE_ADD (1)
#define DT_MODE_MULT (2)

#ifdef _DAMAGE_MOD_EXPORT
export variable begin
#else
import variable begin
#endif
ini_dt_mode_positive;
ini_dt_mode_negative;
ini_dt_mult_positive;
ini_dt_mult_negative;
ini_damage_types;
end

variable
last_dtdr;

procedure get_weapon_damage_type_override(variable weapon) begin
variable dmgType, ammoPid;
// First, check override for ammo.
ammoPid := get_weapon_ammo_pid(weapon);
if (ammoPid and ini_damage_types[ammoPid]) then begin
return ini_damage_types[ammoPid] - 1;
end else if (ini_damage_types[obj_pid(weapon)]) then begin // check override for weapon
return ini_damage_types[obj_pid(weapon)] - 1;
end
return -1;
end

procedure calc_dtdr_vanilla_plus(variable targetDT, variable targetDR, variable ammoDR) begin
variable calcDRMod, dtMult, dtMode;

// Use separate mode and multiplier for positive and negative DR Adjust.
if (ammoDR > 0) then begin
dtMode := ini_dt_mode_positive;
dtMult := ini_dt_mult_positive;
end else begin
dtMode := ini_dt_mode_negative;
dtMult := ini_dt_mult_negative;
end
switch dtMode begin
case DT_MODE_ADD: targetDT += 0.1 * ammoDR * dtMult;
case DT_MODE_MULT: targetDT *= 1.0 + 0.01 * ammoDR * dtMult;
end

// No change to DR calculation.
targetDR += ammoDR;

if (not last_dtdr) then
last_dtdr := create_array_list(2);

last_dtdr[0] := math_max(targetDT, 0);
last_dtdr[1] := math_max(math_min(targetDR, 100), 0);
return last_dtdr;
end

procedure calc_effective_dtdr(variable targetDT, variable targetDR, variable ammoDR, variable ctdSource, variable bypassArmor,
variable weaponPerk, variable attackType)
begin
if (bypassArmor) then begin
targetDT := targetDT * 20 / 100;
targetDR := targetDR * 20 / 100;
end else begin
if (weaponPerk == PERK_weapon_penetrate)
or (attackType == ATKTYPE_PALMSTRIKE or attackType == ATKTYPE_PIERCINGSTRIKE
or attackType == ATKTYPE_HOOKKICK or attackType == ATKTYPE_PIERCINGKICK) then
targetDT := targetDT * 20 / 100;

if ctdSource == dude_obj and has_trait(TRAIT_TRAIT, ctdSource, TRAIT_finesse) then
targetDR += 30;
end

return calc_dtdr_vanilla_plus(targetDT, targetDR, ammoDR);
end

#endif // DAMAGE_MOD_H
5 changes: 2 additions & 3 deletions scripts_src/_pbs_main/gl_pbs_ai.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
#include "../_pbs_headers/ecco_ini.h"
#include "../_pbs_headers/ecco_log.h"

#define SCRIPT_REALNAME "pbs_ai"
#include "../_pbs_headers/damage_mod.h"

import procedure calc_effective_dtdr(variable targetDT, variable targetDR, variable ammoDR, variable ctdSource, variable bypass,
variable weaponPerk, variable attackType);
#define SCRIPT_REALNAME "pbs_ai"

variable begin
ini_called_int_req;
Expand Down
74 changes: 4 additions & 70 deletions scripts_src/_pbs_main/gl_pbs_damage_mod.ssl
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,18 @@ procedure combatdamage_handler;
procedure itemdamage_handler;
procedure deathanim2_handler;
procedure check_damage_formula;
procedure get_weapon_damage_type_override(variable weapon);
procedure calc_damage(variable weapon, variable rounds, variable targetDT, variable targetDR, variable rangedBonus,
variable criticalMult, variable difficulty, variable ctdSource, variable flags, variable dmgType, variable weaponPerk, variable attackType);
export procedure calc_effective_dtdr(variable targetDT, variable targetDR, variable ammoDR, variable ctdSource, variable bypass,
variable weaponPerk, variable attackType);
procedure get_ammo_value(variable weapon, variable param);
procedure map_enter_p_proc;

#define _DAMAGE_MOD_EXPORT;
#include "../_pbs_headers/damage_mod.h"

#define INI_SECTION "DAMAGE"

#define debug_verbose(msg) if ini_debug then debug_log(msg)

#define DT_MODE_ADD (1)
#define DT_MODE_MULT (2)

import variable pbs_trap_hold_critters;

variable
Expand All @@ -59,20 +56,14 @@ variable
item_damage_weapon,
item_damage_attacker,
ini_burst_critical_fraction,
ini_dt_mode_positive,
ini_dt_mode_negative,
ini_dt_mult_positive,
ini_dt_mult_negative,
ini_unarmed_weapon_punch_bonus,
ini_knockback_limit,
ini_knockback_div,
ini_knockback_perk_div,
ini_damage_types,
ini_dr_adjust_by_attack_mode,
ini_debug,
living_anatomy_bonus,
pyromaniac_bonus,
last_dtdr;
pyromaniac_bonus;

procedure start begin
if game_loaded then begin
Expand Down Expand Up @@ -334,18 +325,6 @@ procedure combatdamage_handler begin
set_sfall_arg(10, amountKnockback);
end

procedure get_weapon_damage_type_override(variable weapon) begin
variable dmgType, ammoPid;
// First, check override for ammo.
ammoPid := get_weapon_ammo_pid(weapon);
if (ammoPid and ini_damage_types[ammoPid]) then begin
return ini_damage_types[ammoPid] - 1;
end else if (ini_damage_types[obj_pid(weapon)]) then begin // check override for weapon
return ini_damage_types[obj_pid(weapon)] - 1;
end
return -1;
end

/*
Differences from YAAM:
- All calculations are in float and rounded once per bullet using probabilistic rounding.
Expand Down Expand Up @@ -430,51 +409,6 @@ procedure calc_dtdr_yaam(variable targetDT, variable targetDR, variable ammoDR)
end
*/

procedure calc_dtdr_vanilla_plus(variable targetDT, variable targetDR, variable ammoDR) begin
variable calcDRMod, dtMult, dtMode;

// Use separate mode and multiplier for positive and negative DR Adjust.
if (ammoDR > 0) then begin
dtMode := ini_dt_mode_positive;
dtMult := ini_dt_mult_positive;
end else begin
dtMode := ini_dt_mode_negative;
dtMult := ini_dt_mult_negative;
end
switch dtMode begin
case DT_MODE_ADD: targetDT += 0.1 * ammoDR * dtMult;
case DT_MODE_MULT: targetDT *= 1.0 + 0.01 * ammoDR * dtMult;
end

// No change to DR calculation.
targetDR += ammoDR;

if (not last_dtdr) then
last_dtdr := create_array_list(2);

last_dtdr[0] := math_max(targetDT, 0);
last_dtdr[1] := math_max(math_min(targetDR, 100), 0);
return last_dtdr;
end

procedure calc_effective_dtdr(variable targetDT, variable targetDR, variable ammoDR, variable ctdSource, variable bypassArmor,
variable weaponPerk, variable attackType)
begin
if (bypassArmor) then begin
targetDT := targetDT * 20 / 100;
targetDR := targetDR * 20 / 100;
end else begin
if (weaponPerk == PERK_weapon_penetrate)
or (attackType == ATKTYPE_PALMSTRIKE or attackType == ATKTYPE_PIERCINGSTRIKE
or attackType == ATKTYPE_HOOKKICK or attackType == ATKTYPE_PIERCINGKICK) then
targetDT := targetDT * 20 / 100;

if ctdSource == dude_obj and has_trait(TRAIT_TRAIT, ctdSource, TRAIT_finesse) then
targetDR += 30;
end

return calc_dtdr_vanilla_plus(targetDT, targetDR, ammoDR);
end

procedure dude_primary_punch_bonus_damage begin
variable
Expand Down

0 comments on commit b1903b7

Please sign in to comment.