diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index d6e6d6dd..806ec29a 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -192,6 +192,7 @@ #define critter_inven_obj2(obj, type) sfall_func2("critter_inven_obj2", obj, type) #define exec_map_update_scripts sfall_func0("exec_map_update_scripts") #define floor2(value) sfall_func1("floor2", value) +#define get_current_inven_size(obj) sfall_func1("get_current_inven_size", obj) #define intface_hide sfall_func0("intface_hide") #define intface_is_hidden sfall_func0("intface_is_hidden") #define intface_redraw sfall_func0("intface_redraw") diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index b16a6464..4b20aeb1 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -385,6 +385,9 @@ Some utility/math functions are available: - works just like vanilla floor function, but returns correct integers for negative values - vanilla floor function works exactly the same as ceil for negative values, much like trunc in C/C++ +> int sfall_func1("get_current_inven_size", object) +- returns the current inventory size of the container or the critter + ------------------------ ------ MORE INFO ------- ------------------------ diff --git a/sfall/Bugs.cpp b/sfall/Bugs.cpp index 25f1acfe..ca981e74 100644 --- a/sfall/Bugs.cpp +++ b/sfall/Bugs.cpp @@ -470,7 +470,7 @@ noArmor: mov esi, [esp + 0x1C + 8]; // weapon test esi, esi; jnz haveWeapon; - cmp ds:[_dialog_target_is_party], esi; // esi = 0 + cmp ds:[_dialog_target_is_party], esi; // esi = 0 jne skip; // This is a party member mov eax, [esp + 0x18 + 8]; // item_weapon test eax, eax; diff --git a/sfall/Inventory.cpp b/sfall/Inventory.cpp index 94a174b0..31da183c 100644 --- a/sfall/Inventory.cpp +++ b/sfall/Inventory.cpp @@ -93,7 +93,7 @@ void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey) { } ///////////////////////////////////////////////////////////////// -static DWORD __stdcall sf_item_total_size(TGameObj* critter) { +DWORD __stdcall sf_item_total_size(TGameObj* critter) { int totalSize; __asm { mov eax, critter; @@ -103,17 +103,17 @@ static DWORD __stdcall sf_item_total_size(TGameObj* critter) { if ((critter->artFID & 0xF000000) == (OBJ_TYPE_CRITTER << 24)) { TGameObj* item = InvenRightHand(critter); - if (item && !(item->flags & 0x2000000)) { + if (item && !(item->flags & 0x2000000)) { // ObjectFlag Right_Hand totalSize += ItemSize(item); } TGameObj* itemL = InvenLeftHand(critter); - if (itemL && item != itemL && !(itemL->flags & 0x1000000)) { + if (itemL && item != itemL && !(itemL->flags & 0x1000000)) { // ObjectFlag Left_Hand totalSize += ItemSize(itemL); } item = InvenWorn(critter); - if (item && !(item->flags & 0x4000000)) { + if (item && !(item->flags & 0x4000000)) { // ObjectFlag Worn totalSize += ItemSize(item); } } diff --git a/sfall/Inventory.h b/sfall/Inventory.h index 117a8ad9..31971b36 100644 --- a/sfall/Inventory.h +++ b/sfall/Inventory.h @@ -19,6 +19,7 @@ #pragma once void _stdcall SetInvenApCost(int a); +DWORD __stdcall sf_item_total_size(TGameObj* critter); void InventoryInit(); void InventoryReset(); void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey); diff --git a/sfall/ScriptOps/MetaruleOp.hpp b/sfall/ScriptOps/MetaruleOp.hpp index 1b400329..957cc08f 100644 --- a/sfall/ScriptOps/MetaruleOp.hpp +++ b/sfall/ScriptOps/MetaruleOp.hpp @@ -103,17 +103,18 @@ static void sf_get_metarule_table() { - minArgs/maxArgs - minimum and maximum number of arguments allowed for this function */ static const SfallMetarule metaruleArray[] = { - {"get_metarule_table", sf_get_metarule_table, 0, 0}, - {"validate_test", sf_test, 2, 5}, - {"spatial_radius", sf_spatial_radius, 1, 1}, {"critter_inven_obj2", sf_critter_inven_obj2, 2, 2}, - {"intface_redraw", sf_intface_redraw, 0, 0}, - {"intface_show", sf_intface_show, 0, 0}, + {"exec_map_update_scripts", sf_exec_map_update_scripts, 0, 0}, + {"floor2", sf_floor2, 1, 1}, + {"get_current_inven_size", sf_get_current_inven_size, 1, 1}, + {"get_metarule_table", sf_get_metarule_table, 0, 0}, {"intface_hide", sf_intface_hide, 0, 0}, {"intface_is_hidden", sf_intface_is_hidden, 0, 0}, - {"exec_map_update_scripts", sf_exec_map_update_scripts, 0, 0}, + {"intface_redraw", sf_intface_redraw, 0, 0}, + {"intface_show", sf_intface_show, 0, 0}, {"set_ini_setting", sf_set_ini_setting, 2, 2}, - {"floor2", sf_floor2, 1, 1}, + {"spatial_radius", sf_spatial_radius, 1, 1}, + {"validate_test", sf_test, 2, 5}, }; static void InitMetaruleTable() { diff --git a/sfall/ScriptOps/ObjectsOps.hpp b/sfall/ScriptOps/ObjectsOps.hpp index 67a50c9b..18927ea3 100644 --- a/sfall/ScriptOps/ObjectsOps.hpp +++ b/sfall/ScriptOps/ObjectsOps.hpp @@ -558,3 +558,12 @@ static void sf_critter_inven_obj2() { opHandler.printOpcodeError("critter_inven_obj2() - invalid type."); } } + +static void sf_get_current_inven_size() { + TGameObj* invenObj = opHandler.arg(0).asObject(); + if (invenObj != nullptr) { + opHandler.setReturn(sf_item_total_size(invenObj), DATATYPE_INT); + } else { + opHandler.setReturn(-1); + } +}