From 1c34f85789d0a86f8b7bc0fc028573eb29062b11 Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Thu, 8 Jun 2023 21:36:09 +0200 Subject: [PATCH] Add get_combat_free_move for better mod compatibility --- artifacts/scripting/functions.yml | 6 +++++ artifacts/scripting/headers/command_extra.h | 4 ++++ artifacts/scripting/headers/lib.strings.h | 22 ++++++++++++++----- artifacts/scripting/headers/sfall.h | 1 + artifacts/scripting/sfall function notes.md | 6 +++++ sfall/Modules/Scripting/Handlers/Combat.cpp | 4 ++++ sfall/Modules/Scripting/Handlers/Combat.h | 2 ++ sfall/Modules/Scripting/Handlers/Metarule.cpp | 1 + 8 files changed, 40 insertions(+), 6 deletions(-) diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index d9b84e23..80f927a8 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -1566,12 +1566,18 @@ - __NOTE:__ refer to the description of **ComputeSpray_\*** settings in ddraw.ini for details of the bullet distribution of burst attacks macro: sfall.h + - name: + detail: int get_combat_free_move + doc: Returns current "bonus move" points of a current critter's turn. For NPC's this is always 0, unless changed by set_combat_free_move. + macro: sfall.h + - name: set_combat_free_move detail: void set_combat_free_move(int value) doc: | Allows changing "bonus move" points (yellow lights on the interface bar) that can only be used for movement, not attacking - Can be called from `HOOK_COMBATTURN` at the start of the turn (will not work on `dude_obj`) - Can be called from `HOOK_STDPROCEDURE` with `combat_proc` event (will work on both NPCs and `dude_obj`) + macro: sfall.h - name: Car items: diff --git a/artifacts/scripting/headers/command_extra.h b/artifacts/scripting/headers/command_extra.h index 390c1bc5..db599bff 100644 --- a/artifacts/scripting/headers/command_extra.h +++ b/artifacts/scripting/headers/command_extra.h @@ -1,6 +1,10 @@ #ifndef COMMAND_EXTRA_H #define COMMAND_EXTRA_H +#include "define_lite.h" +#include "define_extra.h" + + #define ammo_caliber(ammoPid) get_proto_data(ammoPid, PROTO_AM_CALIBER) #define obj_name_safe(obj) (obj_name(obj) if obj else "(null)") #define get_active_weapon(critter) critter_inven_obj(critter, (2 - active_hand) if critter == dude_obj else INVEN_TYPE_RIGHT_HAND) diff --git a/artifacts/scripting/headers/lib.strings.h b/artifacts/scripting/headers/lib.strings.h index d2790b9f..dc01884e 100644 --- a/artifacts/scripting/headers/lib.strings.h +++ b/artifacts/scripting/headers/lib.strings.h @@ -9,6 +9,8 @@ #ifndef LIB_STRINGS_H #define LIB_STRINGS_H +#include "sfall.h" + #define is_in_string(str, sub) (string_pos(str, sub) != -1) #define string_starts_with(str, sub) (substr(str, 0, strlen(sub)) == sub) @@ -166,14 +168,22 @@ end * Useful in cunjunction with is_in_array() */ procedure string_split_ints(variable str, variable split) begin - variable i := 0; - variable list; + variable n; + variable list, result, val; + + if (str == "" or typeof(str) != VALTYPE_STR) then + return temp_array_list(0); + list := string_split(str, split); - while (i < len_array(list)) do begin - list[i] := atoi(list[i]); - i++; + result := temp_array_list(0); + foreach (val in list) begin + if val != "" then begin + resize_array(result, n + 1); + result[n] := atoi(val); + n += 1; + end end - return list; + return result; end diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index 99abb225..2ceaa466 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -298,6 +298,7 @@ #define exec_map_update_scripts sfall_func0("exec_map_update_scripts") #define floor2(value) sfall_func1("floor2", value) #define get_can_rest_on_map(map, elev) sfall_func2("get_can_rest_on_map", map, elev) +#define get_combat_free_move sfall_func0("get_combat_free_move") #define get_current_inven_size(obj) sfall_func1("get_current_inven_size", obj) #define get_current_terrain_name sfall_func0("get_terrain_name") #define get_cursor_mode sfall_func0("get_cursor_mode") diff --git a/artifacts/scripting/sfall function notes.md b/artifacts/scripting/sfall function notes.md index adc26146..b238f0cc 100644 --- a/artifacts/scripting/sfall function notes.md +++ b/artifacts/scripting/sfall function notes.md @@ -1077,6 +1077,12 @@ sfall_funcX metarule functions - `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 +---- +##### get_combat_free_move +`int sfall_func0("get_combat_free_move")` + +- Returns current "bonus move" points of a current critter's turn. For NPC's this is always 0, unless changed by set_combat_free_move. + ---- ##### set_combat_free_move `void sfall_func1("set_combat_free_move", int value)` diff --git a/sfall/Modules/Scripting/Handlers/Combat.cpp b/sfall/Modules/Scripting/Handlers/Combat.cpp index b894f942..02bf9ba0 100644 --- a/sfall/Modules/Scripting/Handlers/Combat.cpp +++ b/sfall/Modules/Scripting/Handlers/Combat.cpp @@ -265,6 +265,10 @@ void mf_set_spray_settings(OpcodeContext& ctx) { BurstMods::SetComputeSpraySettings(centerMult, centerDiv, targetMult, targetDiv); } +void mf_get_combat_free_move(OpcodeContext& ctx) { + ctx.setReturn(fo::var::combat_free_move); +} + void mf_set_combat_free_move(OpcodeContext& ctx) { long value = ctx.arg(0).rawValue(); if (value < 0) value = 0; diff --git a/sfall/Modules/Scripting/Handlers/Combat.h b/sfall/Modules/Scripting/Handlers/Combat.h index 9ccee2a6..7ed5aae5 100644 --- a/sfall/Modules/Scripting/Handlers/Combat.h +++ b/sfall/Modules/Scripting/Handlers/Combat.h @@ -58,6 +58,8 @@ void mf_combat_data(OpcodeContext&); void mf_set_spray_settings(OpcodeContext&); +void mf_get_combat_free_move(OpcodeContext&); + void mf_set_combat_free_move(OpcodeContext&); } diff --git a/sfall/Modules/Scripting/Handlers/Metarule.cpp b/sfall/Modules/Scripting/Handlers/Metarule.cpp index dfd3ddc5..899b8fd8 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -83,6 +83,7 @@ static const SfallMetarule metarules[] = { {"exec_map_update_scripts", mf_exec_map_update_scripts, 0, 0}, {"floor2", mf_floor2, 1, 1, 0, {ARG_NUMBER}}, {"get_can_rest_on_map", mf_get_rest_on_map, 2, 2, -1, {ARG_INT, ARG_INT}}, + {"get_combat_free_move", mf_get_combat_free_move, 0, 0}, {"get_current_inven_size", mf_get_current_inven_size, 1, 1, 0, {ARG_OBJECT}}, {"get_cursor_mode", mf_get_cursor_mode, 0, 0}, {"get_flags", mf_get_flags, 1, 1, 0, {ARG_OBJECT}},