Added "get_current_inven_size" script function.

This commit is contained in:
NovaRain
2018-09-21 19:27:57 +08:00
parent 1679f7c59d
commit 2e30c86467
7 changed files with 27 additions and 12 deletions
+1
View File
@@ -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")
@@ -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 -------
------------------------
+1 -1
View File
@@ -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;
+4 -4
View File
@@ -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);
}
}
+1
View File
@@ -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);
+8 -7
View File
@@ -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() {
+9
View File
@@ -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);
}
}