From c9034f917b3633c77640efa71d6c6dde72efd8c1 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 17 May 2023 00:14:44 +0800 Subject: [PATCH 1/3] Added "set_spray_settings" function for scriptable burst (#36) * Current implementation works similar to metarule2_explosions. documentation will come later. --- artifacts/scripting/headers/sfall.h | 1 + sfall/Modules/BurstMods.cpp | 36 ++++++++++++++++++- sfall/Modules/BurstMods.h | 2 ++ sfall/Modules/Scripting/Handlers/Combat.cpp | 20 +++++++++++ sfall/Modules/Scripting/Handlers/Combat.h | 2 ++ sfall/Modules/Scripting/Handlers/Metarule.cpp | 1 + 6 files changed, 61 insertions(+), 1 deletion(-) diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index df60b340..73efa8e5 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -373,6 +373,7 @@ #define set_rest_heal_time(time) sfall_func1("set_rest_heal_time", time) #define set_rest_mode(mode) sfall_func1("set_rest_mode", mode) #define set_scr_name(name) sfall_func1("set_scr_name", name) +#define set_spray_settings(ctrMult, ctrDiv, tgtMult, tgtDiv) sfall_func4("set_spray_settings", ctrMult, ctrDiv, tgtMult, tgtDiv) #define set_terrain_name(x, y, name) sfall_func3("set_terrain_name", x, y, name) #define set_town_title(areaID, title) sfall_func2("set_town_title", areaID, title) #define set_unique_id(obj) sfall_func1("set_unique_id", obj) diff --git a/sfall/Modules/BurstMods.cpp b/sfall/Modules/BurstMods.cpp index 0f70466d..3008e78e 100644 --- a/sfall/Modules/BurstMods.cpp +++ b/sfall/Modules/BurstMods.cpp @@ -19,6 +19,7 @@ #include "..\main.h" #include "BurstMods.h" +#include "MainLoopHook.h" namespace sfall { @@ -28,6 +29,14 @@ static long compute_spray_center_div; static long compute_spray_target_mult; static long compute_spray_target_div; +// default values +static long compute_spray_center_mult_def; +static long compute_spray_center_div_def; +static long compute_spray_target_mult_def; +static long compute_spray_target_div_def; + +static bool computeSpraySettingsReset = false; + static long __fastcall ComputeSpray(DWORD* roundsLeftOut, DWORD* roundsRightOut, DWORD totalRounds, DWORD* roundsCenterOut) { // roundsCenter = totalRounds * mult / div long result = totalRounds * compute_spray_center_mult; @@ -65,8 +74,25 @@ static void __declspec(naked) compute_spray_rounds_distribution() { } } +void BurstMods::SetComputeSpraySettings(long centerMult, long centerDiv, long targetMult, long targetDiv) { + compute_spray_center_mult = centerMult; + compute_spray_center_div = centerDiv; + compute_spray_target_mult = targetMult; + compute_spray_target_div = targetDiv; + computeSpraySettingsReset = true; +} + +void ResetComputeSpraySettings() { + if (!computeSpraySettingsReset) return; + compute_spray_center_mult = compute_spray_center_mult_def; + compute_spray_center_div = compute_spray_center_div_def; + compute_spray_target_mult = compute_spray_target_mult_def; + compute_spray_target_div = compute_spray_target_div_def; + computeSpraySettingsReset = false; +} + void BurstMods::init() { - //if (IniReader::GetConfigInt("Misc", "ComputeSprayMod", 0)) { + //if (IniReader::GetConfigInt("Misc", "ComputeSprayMod", 1)) { dlogr("Applying ComputeSpray settings to burst attacks.", DL_INIT); compute_spray_center_mult = IniReader::GetConfigInt("Misc", "ComputeSpray_CenterMult", 1); compute_spray_center_div = IniReader::GetConfigInt("Misc", "ComputeSpray_CenterDiv", 3); @@ -76,6 +102,9 @@ void BurstMods::init() { if (compute_spray_center_mult > compute_spray_center_div) { compute_spray_center_mult = compute_spray_center_div; } + compute_spray_center_mult_def = compute_spray_center_mult; + compute_spray_center_div_def = compute_spray_center_div; + compute_spray_target_mult = IniReader::GetConfigInt("Misc", "ComputeSpray_TargetMult", 1); compute_spray_target_div = IniReader::GetConfigInt("Misc", "ComputeSpray_TargetDiv", 2); if (compute_spray_target_div < 1) { @@ -84,7 +113,12 @@ void BurstMods::init() { if (compute_spray_target_mult > compute_spray_target_div) { compute_spray_target_mult = compute_spray_target_div; } + compute_spray_target_mult_def = compute_spray_target_mult; + compute_spray_target_div_def = compute_spray_target_div; + MakeJump(0x4234F1, compute_spray_rounds_distribution); + // after each combat attack, reset ComputeSpray settings + MainLoopHook::OnAfterCombatAttack() += ResetComputeSpraySettings; //} } diff --git a/sfall/Modules/BurstMods.h b/sfall/Modules/BurstMods.h index 1b2fad7d..948e3772 100644 --- a/sfall/Modules/BurstMods.h +++ b/sfall/Modules/BurstMods.h @@ -27,6 +27,8 @@ class BurstMods : public Module { public: const char* name() { return "BurstMods"; } void init(); + + static void SetComputeSpraySettings(long centerMult, long centerDiv, long targetMult, long targetDiv); }; } diff --git a/sfall/Modules/Scripting/Handlers/Combat.cpp b/sfall/Modules/Scripting/Handlers/Combat.cpp index d9e281dc..3ea04ada 100644 --- a/sfall/Modules/Scripting/Handlers/Combat.cpp +++ b/sfall/Modules/Scripting/Handlers/Combat.cpp @@ -19,6 +19,7 @@ #include "..\..\..\FalloutEngine\AsmMacros.h" #include "..\..\..\FalloutEngine\Fallout2.h" #include "..\..\AI.h" +#include "..\..\BurstMods.h" #include "..\..\Combat.h" #include "..\..\KillCounter.h" @@ -241,5 +242,24 @@ void mf_combat_data(OpcodeContext& ctx) { ctx.setReturn((DWORD)ctd, DataType::INT); } +void mf_set_spray_settings(OpcodeContext& ctx) { + long centerMult = ctx.arg(0).rawValue(), + centerDiv = ctx.arg(1).rawValue(), + targetMult = ctx.arg(2).rawValue(), + targetDiv = ctx.arg(3).rawValue(); + + if (centerDiv < 1) centerDiv = 1; + if (centerMult > centerDiv) { + centerMult = centerDiv; + ctx.printOpcodeError("%s() - Warning: centerMult value is capped at centerDiv.", ctx.getMetaruleName()); + } + if (targetDiv < 1) targetDiv = 1; + if (targetMult > targetDiv) { + targetMult = targetDiv; + ctx.printOpcodeError("%s() - Warning: targetMult value is capped at targetDiv.", ctx.getMetaruleName()); + } + BurstMods::SetComputeSpraySettings(centerMult, centerDiv, targetMult, targetDiv); +} + } } diff --git a/sfall/Modules/Scripting/Handlers/Combat.h b/sfall/Modules/Scripting/Handlers/Combat.h index e480457c..e3cbad0d 100644 --- a/sfall/Modules/Scripting/Handlers/Combat.h +++ b/sfall/Modules/Scripting/Handlers/Combat.h @@ -56,5 +56,7 @@ void mf_attack_is_aimed(OpcodeContext&); void mf_combat_data(OpcodeContext&); +void mf_set_spray_settings(OpcodeContext&); + } } diff --git a/sfall/Modules/Scripting/Handlers/Metarule.cpp b/sfall/Modules/Scripting/Handlers/Metarule.cpp index 8034c37e..0b86fb27 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -125,6 +125,7 @@ static const SfallMetarule metarules[] = { {"outlined_object", mf_outlined_object, 0, 0}, {"real_dude_obj", mf_real_dude_obj, 0, 0}, {"remove_timer_event", mf_remove_timer_event, 0, 1, -1, {ARG_INT}}, + {"set_spray_settings", mf_set_spray_settings, 4, 4, -1, {ARG_INT, ARG_INT, ARG_INT, ARG_INT}}, {"set_can_rest_on_map", mf_set_rest_on_map, 3, 3, -1, {ARG_INT, ARG_INT, ARG_INT}}, {"set_car_intface_art", mf_set_car_intface_art, 1, 1, -1, {ARG_INT}}, {"set_cursor_mode", mf_set_cursor_mode, 1, 1, -1, {ARG_INT}}, From a3cfc481a54b853428adc9e39c8e625a44e1b28f Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Tue, 16 May 2023 18:50:13 +0200 Subject: [PATCH 2/3] Remove postbuild.cmd from git --- sfall/postbuild.cmd | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 sfall/postbuild.cmd diff --git a/sfall/postbuild.cmd b/sfall/postbuild.cmd deleted file mode 100644 index 92f45817..00000000 --- a/sfall/postbuild.cmd +++ /dev/null @@ -1,21 +0,0 @@ -@ECHO OFF - -rem debug, release, etc. -SET type=%1 -rem full path to the compiled DLL -SET target=%2 - -SET destination=C:\Games\Fallout2\ddraw.dll - -SET pdb="%~dpn2.pdb" - -IF EXIST ducible.exe ( - IF EXIST %pdb% ( - ducible %target% %pdb% - ) ELSE ( - ducible %target% - ) -) - -rem echo Copying %target% to %destination% ... -rem copy %target% %destination% \ No newline at end of file From 37e7af2a176bd87b2a1aa28803f6794477c93d88 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 18 May 2023 22:52:00 +0800 Subject: [PATCH 3/3] Added documentation for set_spray_settings --- artifacts/scripting/functions.yml | 12 +++++++++++- artifacts/scripting/sfall function notes.md | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index 8dc233ba..8be1a30c 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -703,7 +703,7 @@ items: - name: metarule2_explosions detail: int metarule2_explosions(int arg1, int arg2) - doc: Was made as a dirty easy hack to allow dynamically change some explosion parameters (ranged attack). All changed parameters are reset to vanilla state automatically after each attack action. + doc: Was made as a dirty easy hack to allow to dynamically change some explosion parameters (ranged attack). All changed parameters are automatically reset to vanilla state after each attack action. opcode: 0x8261 - name: set_attack_explosion_pattern @@ -1556,6 +1556,16 @@ opcode: 0x8192 doc: Should only be used during the target critters turn while in combat. + - name: set_spray_settings + detail: void set_spray_settings(int centerMult, int centerDiv, int targetMult, int targetDiv) + doc: | + Allows to dynamically change the multipilers and divisors for the bullet distribution of burst attacks. All settings are automatically reset to default values (**ComputeSpray_\*** settings in ddraw.ini) after each attack action + - Should be called before the calculation of the bullet distribution (e.g. in `HOOK_TOHIT` or `HOOK_AMMOCOST` with **CheckWeaponAmmoCost=1** in ddraw.ini) + - `centerDiv/targetDiv`: the minimum value of divisor is 1 + - `centerMult/targetMult`: multiplier values are capped at divisor values + - __NOTE:__ refer to the description of **ComputeSpray_\*** settings in ddraw.ini for details of the bullet distribution of burst attacks + macro: sfall.h + - name: Car items: - name: set_car_current_town diff --git a/artifacts/scripting/sfall function notes.md b/artifacts/scripting/sfall function notes.md index 2aabf479..b70c821c 100644 --- a/artifacts/scripting/sfall function notes.md +++ b/artifacts/scripting/sfall function notes.md @@ -261,7 +261,7 @@ FUNCTION REFERENCE ----- ##### `int/array metarule2_explosions(int arg1, int arg2, int arg3)` -- Was made as a dirty easy hack to allow dynamically change some explosion parameters (ranged attack). All changed parameters are reset to vanilla state automatically after each attack action. Following macros are available in **sfall.h**: +- Was made as a dirty easy hack to allow to dynamically change some explosion parameters (ranged attack). All changed parameters are automatically reset to vanilla state after each attack action. Following macros are available in **sfall.h**: ----- ##### `void set_attack_explosion_pattern(x, y)` @@ -569,7 +569,7 @@ sfall_funcX metarule functions #### set_dude_obj `object sfall_func1("set_dude_obj", critter)` - Take control of a given critter -- passing 0 will reset control back to "real" dude +- Passing 0 will reset control back to "real" dude ---- #### real_dude_obj @@ -1063,6 +1063,16 @@ sfall_funcX metarule functions `bool sfall_func1("obj_is_openable", object obj)` - Returns True if the object is openable (i.e. has an opening/closing animation), False otherwise +---- +##### set_spray_settings +`void sfall_func4("set_spray_settings", int centerMult, int centerDiv, int targetMult, int targetDiv)` + +- Allows to dynamically change the multipilers and divisors for the bullet distribution of burst attacks. All settings are automatically reset to default values (**ComputeSpray_\*** settings in ddraw.ini) after each attack action +- Should be called before the calculation of the bullet distribution (e.g. in `HOOK_TOHIT` or `HOOK_AMMOCOST` with **CheckWeaponAmmoCost=1** in ddraw.ini) +- `centerDiv/targetDiv`: the minimum value of divisor is 1 +- `centerMult/targetMult`: multiplier values are capped at divisor values +- __NOTE:__ refer to the description of **ComputeSpray_\*** settings in ddraw.ini for details of the bullet distribution of burst attacks + **** _See other documentation files (arrays.md, hookscripts.md) for related functions reference._