From ddf28549382932416a6f90e1b9912f4e78c32a55 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 19 May 2023 09:51:58 +0800 Subject: [PATCH] Added "set_spray_settings" function for scriptable burst Added documentation for set_spray_settings. Remove postbuild.cmd from git. --- artifacts/scripting/headers/sfall.h | 1 + artifacts/scripting/sfall function notes.md | 12 ++++++- sfall/Modules/BurstMods.cpp | 34 ++++++++++++++++++- sfall/Modules/BurstMods.h | 4 +++ sfall/Modules/MainLoopHook.cpp | 4 ++- sfall/Modules/Scripting/Handlers/Combat.cpp | 20 +++++++++++ sfall/Modules/Scripting/Handlers/Combat.h | 2 ++ sfall/Modules/Scripting/Handlers/Metarule.cpp | 1 + sfall/postbuild.cmd | 21 ------------ 9 files changed, 75 insertions(+), 24 deletions(-) delete mode 100644 sfall/postbuild.cmd diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index afeeecda..762f4c12 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -362,6 +362,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/artifacts/scripting/sfall function notes.md b/artifacts/scripting/sfall function notes.md index 3c54010b..50a37a26 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)` @@ -1034,6 +1034,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._ diff --git a/sfall/Modules/BurstMods.cpp b/sfall/Modules/BurstMods.cpp index 0f70466d..254cfeed 100644 --- a/sfall/Modules/BurstMods.cpp +++ b/sfall/Modules/BurstMods.cpp @@ -17,6 +17,7 @@ */ #include "..\main.h" +#include "..\FalloutEngine\Fallout2.h" #include "BurstMods.h" @@ -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,6 +113,9 @@ 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); //} } diff --git a/sfall/Modules/BurstMods.h b/sfall/Modules/BurstMods.h index 4aae3b71..b99bd385 100644 --- a/sfall/Modules/BurstMods.h +++ b/sfall/Modules/BurstMods.h @@ -25,6 +25,10 @@ class BurstMods { public: static const char* name() { return "BurstMods"; } static void init(); + + static void SetComputeSpraySettings(long centerMult, long centerDiv, long targetMult, long targetDiv); }; +void ResetComputeSpraySettings(); + } diff --git a/sfall/Modules/MainLoopHook.cpp b/sfall/Modules/MainLoopHook.cpp index e2020b41..1f8a4d28 100644 --- a/sfall/Modules/MainLoopHook.cpp +++ b/sfall/Modules/MainLoopHook.cpp @@ -18,6 +18,7 @@ #include "..\FalloutEngine\Fallout2.h" #include "..\SafeWrite.h" +#include "BurstMods.h" #include "Explosions.h" #include "ScriptExtender.h" @@ -42,7 +43,8 @@ static void __stdcall CombatLoop() { // OnCombatLoop } static void __stdcall AfterCombatAttack() { // OnAfterCombatAttack - ResetExplosionSettings(); // after each combat attack, reset metarule_explosions settings + ResetExplosionSettings(); // after each combat attack, reset metarule_explosions settings + ResetComputeSpraySettings(); // after each combat attack, reset ComputeSpray settings } static void __declspec(naked) MainGameLoopHook() { diff --git a/sfall/Modules/Scripting/Handlers/Combat.cpp b/sfall/Modules/Scripting/Handlers/Combat.cpp index 0b94c0af..67fbb36e 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 41730a90..f76bf0ed 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -122,6 +122,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}}, 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