From c045e22ee5e7dcab29212db627a16e88a4a48838 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Mon, 28 Aug 2023 18:37:53 -0500 Subject: [PATCH 01/16] Add functions and docs --- apps/openmw/mwlua/types/item.cpp | 4 ++++ files/lua_api/openmw/types.lua | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/apps/openmw/mwlua/types/item.cpp b/apps/openmw/mwlua/types/item.cpp index 2b77b6a7c8..5c99f95237 100644 --- a/apps/openmw/mwlua/types/item.cpp +++ b/apps/openmw/mwlua/types/item.cpp @@ -12,5 +12,9 @@ namespace MWLua = [](const Object& object) { return object.ptr().getCellRef().getEnchantmentCharge(); }; item["setEnchantmentCharge"] = [](const GObject& object, float charge) { object.ptr().getCellRef().setEnchantmentCharge(charge); }; + item["getPickUpSound"] + = [](const Object& object) { return object.ptr().getClass().getUpSoundId(object.ptr()).serializeText(); }; + item["getDropSound"] + = [](const Object& object) { return object.ptr().getClass().getDownSoundId(object.ptr()).serializeText(); }; } } diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 0c4a87563b..6f71e6251a 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -626,6 +626,18 @@ -- @param openmw.core#GameObject object -- @return #boolean +--- +-- Get this item's pick up sound +-- @function [parent=#Item] getPickupSound +-- @param openmw.core#GameObject item +-- @return #string The String ID of the pick up sound for this item. + +--- +-- Get this item's drop sound +-- @function [parent=#Item] getDropSound +-- @param openmw.core#GameObject item +-- @return #string The String ID of the drop sound for this item. + --- -- Get this item's current enchantment charge. -- @function [parent=#Item] getEnchantmentCharge From 3de606b2da871c05b2d670058b70bbb42e933026 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 30 Aug 2023 20:32:52 -0500 Subject: [PATCH 02/16] Add aux_core --- files/data/CMakeLists.txt | 1 + files/data/openmw_aux/core.lua | 132 +++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 files/data/openmw_aux/core.lua diff --git a/files/data/CMakeLists.txt b/files/data/CMakeLists.txt index f52be02451..1f56b0bfe8 100644 --- a/files/data/CMakeLists.txt +++ b/files/data/CMakeLists.txt @@ -59,6 +59,7 @@ set(BUILTIN_DATA_FILES openmw_aux/time.lua openmw_aux/calendar.lua openmw_aux/calendarconfig.lua + openmw_aux/core.lua openmw_aux/ui.lua builtin.omwscripts diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua new file mode 100644 index 0000000000..2f7f96f6f2 --- /dev/null +++ b/files/data/openmw_aux/core.lua @@ -0,0 +1,132 @@ +local types = require('openmw.types') +--- +-- `openmw_aux.core` defines utility functions for objects. +-- Implementation can be found in `resources/vfs/openmw_aux/core.lua`. +-- @module core +-- @usage local auxCore = require('openmw_aux.core') +local aux_core = {} + +function aux_core.getArmorType(item) + local bodyType = -1 + local weight = item.type.record(item).weight + local armorTypes = { light = "Light", medium = "Medium", heavy = "Heavy" } + if (types.Armor.record(item).type == types.Armor.TYPE.RGauntlet) then + bodyType = 4 + elseif (types.Armor.record(item).type == types.Armor.TYPE.LGauntlet) then + bodyType = 4 + elseif (types.Armor.record(item).type == types.Armor.TYPE.Boots) then + bodyType = 1 + elseif (types.Armor.record(item).type == types.Armor.TYPE.Cuirass) then + bodyType = 2 + elseif (types.Armor.record(item).type == types.Armor.TYPE.Greaves) then + bodyType = 3 + elseif (types.Armor.record(item).type == types.Armor.TYPE.Shield) then + bodyType = 3 + elseif (types.Armor.record(item).type == types.Armor.TYPE.LBracer) then + bodyType = 4 + elseif (types.Armor.record(item).type == types.Armor.TYPE.RBracer) then + bodyType = 4 + elseif (types.Armor.record(item).type == types.Armor.TYPE.RPauldron) then + bodyType = 5 + elseif (types.Armor.record(item).type == types.Armor.TYPE.LPauldron) then + bodyType = 5 + elseif (types.Armor.record(item).type == types.Armor.TYPE.Helmet) then + bodyType = 4 + end + if bodyType == 1 then + if weight > 18 then + return armorTypes.heavy + elseif weight > 12 then + return armorTypes.medium + else + return armorTypes.light + end + elseif bodyType == 2 then + if weight > 27 then + return armorTypes.heavy + elseif weight > 18 then + return armorTypes.medium + else + return armorTypes.light + end + elseif bodyType == 3 then + if weight > 13.5 then + return armorTypes.heavy + elseif weight > 9 then + return armorTypes.medium + else + return armorTypes.light + end + elseif bodyType == 4 then + if weight > 4.5 then + return armorTypes.heavy + elseif weight > 3 then + return armorTypes.medium + else + return armorTypes.light + end + elseif bodyType == 5 then + if weight > 9 then + return armorTypes.heavy + elseif weight > 6 then + return armorTypes.medium + else + return armorTypes.light + end + end +end + +local weaponType = types.Weapon.TYPE +local weaponSound = { + [weaponType.BluntOneHand] = "Weapon Blunt", + [weaponType.BluntTwoClose] = "Weapon Blunt", + [weaponType.BluntTwoWide] = "Weapon Blunt", + [weaponType.MarksmanThrown] = "Weapon Blunt", + [weaponType.Arrow] = "Ammo", + [weaponType.Bolt] = "Ammo", + [weaponType.SpearTwoWide] = "Weapon Spear", + [weaponType.MarksmanBow] = "Weapon Bow", + [weaponType.MarksmanCrossbow] = "Weapon Crossbow", + [weaponType.AxeOneHand] = "Weapon Blunt", + [weaponType.AxeTwoHand] = "Weapon Blunt", + [weaponType.ShortBladeOneHand] = "Weapon Shortblade", + [weaponType.LongBladeOneHand] = "Weapon Longblade", + [weaponType.LongBladeTwoHand] = "Weapon Longblade", +} +local goldIds = { gold_001 = true, gold_005 = true, gold_010 = true, gold_025 = true, gold_100 = true } +local function getItemSound(object) + local type = object.type + if object.type.baseType ~= types.Item then + error("Invalid object supplied") + end + local record = object.type.record(object) + local soundName = tostring(type) -- .. " Up" + if type == types.Armor then + soundName = "Armor " .. aux_core.getArmorType(object) + elseif type == types.Clothing then + soundName = "Clothes" + if record.type == types.Clothing.TYPE.Ring then + soundName = "Ring" + end + elseif type == types.Light or type == types.Miscellaneous then + if goldIds[object.recordId] then + soundName = "Gold" + else + soundName = "Misc" + end + elseif type == types.Weapon then + soundName = weaponSound[record.type] + end + return soundName +end +function aux_core.getDropSound(obj) + local soundName = getItemSound(obj) + return string.format("Item %s Down", soundName) +end + +function aux_core.getPickupSound(obj) + local soundName = getItemSound(obj) + return string.format("Item %s Up", soundName) +end + +return aux_core From 976613ab489a438c4a98d86f1a40d348c6d5d2fd Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 30 Aug 2023 20:36:26 -0500 Subject: [PATCH 03/16] Add armor type check --- files/data/openmw_aux/core.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index 2f7f96f6f2..1d9e5cdcb2 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -8,6 +8,9 @@ local aux_core = {} function aux_core.getArmorType(item) local bodyType = -1 + if item.type ~= types.Armor then + error("Not Armor") + end local weight = item.type.record(item).weight local armorTypes = { light = "Light", medium = "Medium", heavy = "Heavy" } if (types.Armor.record(item).type == types.Armor.TYPE.RGauntlet) then From 493be1668b5e5ab8db67b54888d92201e01beb57 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 30 Aug 2023 20:47:29 -0500 Subject: [PATCH 04/16] Redo getArmorType --- files/data/openmw_aux/core.lua | 92 +++++++++++----------------------- 1 file changed, 28 insertions(+), 64 deletions(-) diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index 1d9e5cdcb2..383eec0ddb 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -7,75 +7,39 @@ local types = require('openmw.types') local aux_core = {} function aux_core.getArmorType(item) - local bodyType = -1 if item.type ~= types.Armor then error("Not Armor") end + local armorTypeData = { + [types.Armor.TYPE.Boots] = { bodyType = 1, heavyThreshold = 18, mediumThreshold = 12 }, + [types.Armor.TYPE.Cuirass] = { bodyType = 2, heavyThreshold = 27, mediumThreshold = 18 }, + [types.Armor.TYPE.Greaves] = { bodyType = 3, heavyThreshold = 13.5, mediumThreshold = 9 }, + [types.Armor.TYPE.Shield] = { bodyType = 3, heavyThreshold = 13.5, mediumThreshold = 9 }, + [types.Armor.TYPE.LBracer] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.RBracer] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.RPauldron] = { bodyType = 5, heavyThreshold = 9, mediumThreshold = 6 }, + [types.Armor.TYPE.LPauldron] = { bodyType = 5, heavyThreshold = 9, mediumThreshold = 6 }, + [types.Armor.TYPE.Helmet] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.LGauntlet] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.RGauntlet] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, + } + + + local armorType = types.Armor.record(item).type local weight = item.type.record(item).weight - local armorTypes = { light = "Light", medium = "Medium", heavy = "Heavy" } - if (types.Armor.record(item).type == types.Armor.TYPE.RGauntlet) then - bodyType = 4 - elseif (types.Armor.record(item).type == types.Armor.TYPE.LGauntlet) then - bodyType = 4 - elseif (types.Armor.record(item).type == types.Armor.TYPE.Boots) then - bodyType = 1 - elseif (types.Armor.record(item).type == types.Armor.TYPE.Cuirass) then - bodyType = 2 - elseif (types.Armor.record(item).type == types.Armor.TYPE.Greaves) then - bodyType = 3 - elseif (types.Armor.record(item).type == types.Armor.TYPE.Shield) then - bodyType = 3 - elseif (types.Armor.record(item).type == types.Armor.TYPE.LBracer) then - bodyType = 4 - elseif (types.Armor.record(item).type == types.Armor.TYPE.RBracer) then - bodyType = 4 - elseif (types.Armor.record(item).type == types.Armor.TYPE.RPauldron) then - bodyType = 5 - elseif (types.Armor.record(item).type == types.Armor.TYPE.LPauldron) then - bodyType = 5 - elseif (types.Armor.record(item).type == types.Armor.TYPE.Helmet) then - bodyType = 4 - end - if bodyType == 1 then - if weight > 18 then - return armorTypes.heavy - elseif weight > 12 then - return armorTypes.medium + + local armorData = armorTypeData[armorType] + + if armorData then + if weight > armorData.heavyThreshold then + return "Heavy" + elseif weight > armorData.mediumThreshold then + return "Medium" else - return armorTypes.light - end - elseif bodyType == 2 then - if weight > 27 then - return armorTypes.heavy - elseif weight > 18 then - return armorTypes.medium - else - return armorTypes.light - end - elseif bodyType == 3 then - if weight > 13.5 then - return armorTypes.heavy - elseif weight > 9 then - return armorTypes.medium - else - return armorTypes.light - end - elseif bodyType == 4 then - if weight > 4.5 then - return armorTypes.heavy - elseif weight > 3 then - return armorTypes.medium - else - return armorTypes.light - end - elseif bodyType == 5 then - if weight > 9 then - return armorTypes.heavy - elseif weight > 6 then - return armorTypes.medium - else - return armorTypes.light + return "Light" end + else + error("Unhandled armor type for" .. item.recordId) end end @@ -99,7 +63,7 @@ local weaponSound = { local goldIds = { gold_001 = true, gold_005 = true, gold_010 = true, gold_025 = true, gold_100 = true } local function getItemSound(object) local type = object.type - if object.type.baseType ~= types.Item then + if object.type.baseType ~= types.Item or not object then error("Invalid object supplied") end local record = object.type.record(object) From 6922b6d64d65ce8dc28af296c21090abda6e2506 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 30 Aug 2023 20:50:27 -0500 Subject: [PATCH 05/16] Remove unused variable --- files/data/openmw_aux/core.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index 383eec0ddb..c18f49db4a 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -11,17 +11,17 @@ function aux_core.getArmorType(item) error("Not Armor") end local armorTypeData = { - [types.Armor.TYPE.Boots] = { bodyType = 1, heavyThreshold = 18, mediumThreshold = 12 }, - [types.Armor.TYPE.Cuirass] = { bodyType = 2, heavyThreshold = 27, mediumThreshold = 18 }, - [types.Armor.TYPE.Greaves] = { bodyType = 3, heavyThreshold = 13.5, mediumThreshold = 9 }, - [types.Armor.TYPE.Shield] = { bodyType = 3, heavyThreshold = 13.5, mediumThreshold = 9 }, - [types.Armor.TYPE.LBracer] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.RBracer] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.RPauldron] = { bodyType = 5, heavyThreshold = 9, mediumThreshold = 6 }, - [types.Armor.TYPE.LPauldron] = { bodyType = 5, heavyThreshold = 9, mediumThreshold = 6 }, - [types.Armor.TYPE.Helmet] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.LGauntlet] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.RGauntlet] = { bodyType = 4, heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.Boots] = { heavyThreshold = 18, mediumThreshold = 12 }, + [types.Armor.TYPE.Cuirass] = { heavyThreshold = 27, mediumThreshold = 18 }, + [types.Armor.TYPE.Greaves] = { heavyThreshold = 13.5, mediumThreshold = 9 }, + [types.Armor.TYPE.Shield] = { heavyThreshold = 13.5, mediumThreshold = 9 }, + [types.Armor.TYPE.LBracer] = { heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.RBracer] = { heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.RPauldron] = { heavyThreshold = 9, mediumThreshold = 6 }, + [types.Armor.TYPE.LPauldron] = { heavyThreshold = 9, mediumThreshold = 6 }, + [types.Armor.TYPE.Helmet] = { heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.LGauntlet] = { heavyThreshold = 4.5, mediumThreshold = 3 }, + [types.Armor.TYPE.RGauntlet] = { heavyThreshold = 4.5, mediumThreshold = 3 }, } From 2967b19076fb561a8c5e43d69e9d3e17fb9eea56 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 30 Aug 2023 21:55:27 -0500 Subject: [PATCH 06/16] Use GMSTs, add some docs --- files/data/openmw_aux/core.lua | 64 +++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index c18f49db4a..8ea0d3d88f 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -1,4 +1,5 @@ local types = require('openmw.types') +local core = require('openmw.core') --- -- `openmw_aux.core` defines utility functions for objects. -- Implementation can be found in `resources/vfs/openmw_aux/core.lua`. @@ -6,40 +7,41 @@ local types = require('openmw.types') -- @usage local auxCore = require('openmw_aux.core') local aux_core = {} +--- +-- Checks if the provided armor is Heavy, Medium, or Light +-- @function [parent=#core] getArmorType +-- @param openmw.core#gameObject armor +-- @return #string function aux_core.getArmorType(item) if item.type ~= types.Armor then error("Not Armor") end - local armorTypeData = { - [types.Armor.TYPE.Boots] = { heavyThreshold = 18, mediumThreshold = 12 }, - [types.Armor.TYPE.Cuirass] = { heavyThreshold = 27, mediumThreshold = 18 }, - [types.Armor.TYPE.Greaves] = { heavyThreshold = 13.5, mediumThreshold = 9 }, - [types.Armor.TYPE.Shield] = { heavyThreshold = 13.5, mediumThreshold = 9 }, - [types.Armor.TYPE.LBracer] = { heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.RBracer] = { heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.RPauldron] = { heavyThreshold = 9, mediumThreshold = 6 }, - [types.Armor.TYPE.LPauldron] = { heavyThreshold = 9, mediumThreshold = 6 }, - [types.Armor.TYPE.Helmet] = { heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.LGauntlet] = { heavyThreshold = 4.5, mediumThreshold = 3 }, - [types.Armor.TYPE.RGauntlet] = { heavyThreshold = 4.5, mediumThreshold = 3 }, + local epsilon = 0.0005; + local lightMultiplier = core.getGMST("fLightMaxMod") + epsilon + local medMultiplier = core.getGMST("fMedMaxMod") + epsilon + local armorGMSTs = { + [types.Armor.TYPE.Boots] = "iBootsWeight", + [types.Armor.TYPE.Cuirass] = "iCuirassWeight", + [types.Armor.TYPE.Greaves] = "iGreavesWeight", + [types.Armor.TYPE.Shield] = "iShieldWeight", + [types.Armor.TYPE.LBracer] = "iGauntletWeight", + [types.Armor.TYPE.RBracer] = "iGauntletWeight", + [types.Armor.TYPE.RPauldron] = "iPauldronWeight", + [types.Armor.TYPE.LPauldron] = "iPauldronWeight", + [types.Armor.TYPE.Helmet] = "iHelmWeight", + [types.Armor.TYPE.LGauntlet] = "iGauntletWeight", + [types.Armor.TYPE.RGauntlet] = "iGauntletWeight", } - - local armorType = types.Armor.record(item).type local weight = item.type.record(item).weight + local armorTypeWeight = math.floor(core.getGMST(armorGMSTs[armorType])) - local armorData = armorTypeData[armorType] - - if armorData then - if weight > armorData.heavyThreshold then - return "Heavy" - elseif weight > armorData.mediumThreshold then - return "Medium" - else - return "Light" - end + if weight <= armorTypeWeight * lightMultiplier then + return "Light" + elseif weight <= armorTypeWeight * medMultiplier then + return "Medium" else - error("Unhandled armor type for" .. item.recordId) + return "Heavy" end end @@ -86,11 +88,23 @@ local function getItemSound(object) end return soundName end + + +--- +-- Get the sound that should be played when this item is dropped. +-- @function [parent=#core] getDropSound +-- @param openmw.core#gameObject item +-- @return #string function aux_core.getDropSound(obj) local soundName = getItemSound(obj) return string.format("Item %s Down", soundName) end +--- +-- Get the sound that should be played when this item is picked up. +-- @function [parent=#core] getPickupSound +-- @param openmw.core#gameObject item +-- @return #string function aux_core.getPickupSound(obj) local soundName = getItemSound(obj) return string.format("Item %s Up", soundName) From 5827f1c250beb2d99068586f638139c241b0940d Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 30 Aug 2023 21:58:05 -0500 Subject: [PATCH 07/16] Fix wrong cases --- files/data/openmw_aux/core.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index 8ea0d3d88f..bfb0607aeb 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -10,7 +10,7 @@ local aux_core = {} --- -- Checks if the provided armor is Heavy, Medium, or Light -- @function [parent=#core] getArmorType --- @param openmw.core#gameObject armor +-- @param openmw.core#GameObject armor -- @return #string function aux_core.getArmorType(item) if item.type ~= types.Armor then @@ -93,7 +93,7 @@ end --- -- Get the sound that should be played when this item is dropped. -- @function [parent=#core] getDropSound --- @param openmw.core#gameObject item +-- @param openmw.core#GameObject item -- @return #string function aux_core.getDropSound(obj) local soundName = getItemSound(obj) @@ -103,7 +103,7 @@ end --- -- Get the sound that should be played when this item is picked up. -- @function [parent=#core] getPickupSound --- @param openmw.core#gameObject item +-- @param openmw.core#GameObject item -- @return #string function aux_core.getPickupSound(obj) local soundName = getItemSound(obj) From c73e95063d4d961be1de85fa060f5f80f3372671 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 30 Aug 2023 22:17:31 -0500 Subject: [PATCH 08/16] Finish docs(for now), remove C++ changes --- apps/openmw/mwlua/types/item.cpp | 4 --- docs/source/reference/lua-scripting/api.rst | 1 + .../lua-scripting/openmw_aux_core.rst | 5 ++++ .../lua-scripting/tables/aux_packages.rst | 2 ++ files/data/openmw_aux/core.lua | 29 ++++++++++++------- files/lua_api/openmw/types.lua | 12 -------- 6 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 docs/source/reference/lua-scripting/openmw_aux_core.rst diff --git a/apps/openmw/mwlua/types/item.cpp b/apps/openmw/mwlua/types/item.cpp index e7dfaabcbc..e15be1a2e4 100644 --- a/apps/openmw/mwlua/types/item.cpp +++ b/apps/openmw/mwlua/types/item.cpp @@ -12,10 +12,6 @@ namespace MWLua = [](const Object& object) { return object.ptr().getCellRef().getEnchantmentCharge(); }; item["setEnchantmentCharge"] = [](const GObject& object, float charge) { object.ptr().getCellRef().setEnchantmentCharge(charge); }; - item["getPickUpSound"] - = [](const Object& object) { return object.ptr().getClass().getUpSoundId(object.ptr()).serializeText(); }; - item["getDropSound"] - = [](const Object& object) { return object.ptr().getClass().getDownSoundId(object.ptr()).serializeText(); }; item["isRestocking"] = [](const Object& object) -> bool { return object.ptr().getRefData().getCount(false) < 0; }; } diff --git a/docs/source/reference/lua-scripting/api.rst b/docs/source/reference/lua-scripting/api.rst index 76092fec3f..0cd86a4d23 100644 --- a/docs/source/reference/lua-scripting/api.rst +++ b/docs/source/reference/lua-scripting/api.rst @@ -28,6 +28,7 @@ Lua API reference openmw_aux_util openmw_aux_time openmw_aux_ui + openmw_aux_core interface_activation interface_ai interface_camera diff --git a/docs/source/reference/lua-scripting/openmw_aux_core.rst b/docs/source/reference/lua-scripting/openmw_aux_core.rst new file mode 100644 index 0000000000..49c72e7911 --- /dev/null +++ b/docs/source/reference/lua-scripting/openmw_aux_core.rst @@ -0,0 +1,5 @@ +Package openmw_aux.core +======================= + +.. raw:: html + :file: generated_html/openmw_aux_core.html diff --git a/docs/source/reference/lua-scripting/tables/aux_packages.rst b/docs/source/reference/lua-scripting/tables/aux_packages.rst index 928e5821de..af80f15243 100644 --- a/docs/source/reference/lua-scripting/tables/aux_packages.rst +++ b/docs/source/reference/lua-scripting/tables/aux_packages.rst @@ -9,3 +9,5 @@ +---------------------------------------------------------+--------------------+---------------------------------------------------------------+ |:ref:`openmw_aux.ui ` | by player scripts | | User interface utils | +---------------------------------------------------------+--------------------+---------------------------------------------------------------+ +|:ref:`openmw_aux.core ` | everywhere | | GameObject Utils | ++---------------------------------------------------------+--------------------+---------------------------------------------------------------+ diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index bfb0607aeb..7d908832d4 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -8,14 +8,21 @@ local core = require('openmw.core') local aux_core = {} --- --- Checks if the provided armor is Heavy, Medium, or Light +-- Checks if the provided armor is Heavy, Medium, or Light. Errors if invaid object supplied. -- @function [parent=#core] getArmorType --- @param openmw.core#GameObject armor --- @return #string -function aux_core.getArmorType(item) - if item.type ~= types.Armor then +-- @param openmw.core#GameObject armor Either a gameObject or a armor record. +-- @return #string Heavy, Medium, or Light +function aux_core.getArmorType(armor) + + if armor.type ~= types.Armor and not armor.baseArmor then error("Not Armor") end + local record = nil + if armor.baseArmor then--A record was supplied, not a gameObject + record = armor + else + record = types.Armor.record(armor) + end local epsilon = 0.0005; local lightMultiplier = core.getGMST("fLightMaxMod") + epsilon local medMultiplier = core.getGMST("fMedMaxMod") + epsilon @@ -32,8 +39,8 @@ function aux_core.getArmorType(item) [types.Armor.TYPE.LGauntlet] = "iGauntletWeight", [types.Armor.TYPE.RGauntlet] = "iGauntletWeight", } - local armorType = types.Armor.record(item).type - local weight = item.type.record(item).weight + local armorType = record.type + local weight = record.weight local armorTypeWeight = math.floor(core.getGMST(armorGMSTs[armorType])) if weight <= armorTypeWeight * lightMultiplier then @@ -95,8 +102,8 @@ end -- @function [parent=#core] getDropSound -- @param openmw.core#GameObject item -- @return #string -function aux_core.getDropSound(obj) - local soundName = getItemSound(obj) +function aux_core.getDropSound(item) + local soundName = getItemSound(item) return string.format("Item %s Down", soundName) end @@ -105,8 +112,8 @@ end -- @function [parent=#core] getPickupSound -- @param openmw.core#GameObject item -- @return #string -function aux_core.getPickupSound(obj) - local soundName = getItemSound(obj) +function aux_core.getPickupSound(item) + local soundName = getItemSound(item) return string.format("Item %s Up", soundName) end diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index f37ef0de85..cc8a0365f1 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -626,18 +626,6 @@ -- @param openmw.core#GameObject object -- @return #boolean ---- --- Get this item's pick up sound --- @function [parent=#Item] getPickupSound --- @param openmw.core#GameObject item --- @return #string The String ID of the pick up sound for this item. - ---- --- Get this item's drop sound --- @function [parent=#Item] getDropSound --- @param openmw.core#GameObject item --- @return #string The String ID of the drop sound for this item. - --- -- Get this item's current enchantment charge. -- @function [parent=#Item] getEnchantmentCharge From 0a552c6ad143041befb3dc54a0597c1f595d6fa4 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Mon, 11 Sep 2023 00:05:10 -0500 Subject: [PATCH 09/16] Return Skill, not string, for armor --- files/data/openmw_aux/core.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index 7d908832d4..66de635acc 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -7,11 +7,14 @@ local core = require('openmw.core') -- @usage local auxCore = require('openmw_aux.core') local aux_core = {} +local SKILL = core.SKILL + +local armorSkillString = {[SKILL.Heavyarmor] = "Heavy",[SKILL.Mediumarmor] = "Medium", [SKILL.Lightarmor] = "Light"} --- -- Checks if the provided armor is Heavy, Medium, or Light. Errors if invaid object supplied. -- @function [parent=#core] getArmorType -- @param openmw.core#GameObject armor Either a gameObject or a armor record. --- @return #string Heavy, Medium, or Light +-- @return openmw.core#SKILL The skill for this armor function aux_core.getArmorType(armor) if armor.type ~= types.Armor and not armor.baseArmor then @@ -44,11 +47,11 @@ function aux_core.getArmorType(armor) local armorTypeWeight = math.floor(core.getGMST(armorGMSTs[armorType])) if weight <= armorTypeWeight * lightMultiplier then - return "Light" + return SKILL.Lightarmor elseif weight <= armorTypeWeight * medMultiplier then - return "Medium" + return SKILL.Mediumarmor else - return "Heavy" + return SKILL.Heavyarmor end end @@ -78,7 +81,7 @@ local function getItemSound(object) local record = object.type.record(object) local soundName = tostring(type) -- .. " Up" if type == types.Armor then - soundName = "Armor " .. aux_core.getArmorType(object) + soundName = "Armor " .. armorSkillString[aux_core.getArmorType(object)] elseif type == types.Clothing then soundName = "Clothes" if record.type == types.Clothing.TYPE.Ring then From d44db5faa8a73d55b68a19b70ae4aa4609542898 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Sat, 21 Oct 2023 19:09:13 -0500 Subject: [PATCH 10/16] Remove use of depricated table --- files/data/openmw_aux/core.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/core.lua index 66de635acc..77d486a129 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/core.lua @@ -7,9 +7,9 @@ local core = require('openmw.core') -- @usage local auxCore = require('openmw_aux.core') local aux_core = {} -local SKILL = core.SKILL +local SKILL = types.NPC.stats.skills -local armorSkillString = {[SKILL.Heavyarmor] = "Heavy",[SKILL.Mediumarmor] = "Medium", [SKILL.Lightarmor] = "Light"} +local armorSkillString = {[SKILL.heavyarmor] = "Heavy",[SKILL.mediumarmor] = "Medium", [SKILL.lightarmor] = "Light"} --- -- Checks if the provided armor is Heavy, Medium, or Light. Errors if invaid object supplied. -- @function [parent=#core] getArmorType @@ -47,11 +47,11 @@ function aux_core.getArmorType(armor) local armorTypeWeight = math.floor(core.getGMST(armorGMSTs[armorType])) if weight <= armorTypeWeight * lightMultiplier then - return SKILL.Lightarmor + return SKILL.lightarmor elseif weight <= armorTypeWeight * medMultiplier then - return SKILL.Mediumarmor + return SKILL.mediumarmor else - return SKILL.Heavyarmor + return SKILL.heavyarmor end end From 3741a4f596444eb86ff43c739828bcd437ddf1a3 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Fri, 9 Feb 2024 18:54:01 -0600 Subject: [PATCH 11/16] Use Item instead of Core --- .../{openmw_core.rst => openmw_item.rst} | 2 +- .../lua-scripting/tables/aux_packages.rst | 2 +- files/data/CMakeLists.txt | 2 +- files/data/openmw_aux/{core.lua => item.lua} | 22 +++++++++---------- 4 files changed, 14 insertions(+), 14 deletions(-) rename docs/source/reference/lua-scripting/{openmw_core.rst => openmw_item.rst} (65%) rename files/data/openmw_aux/{core.lua => item.lua} (89%) diff --git a/docs/source/reference/lua-scripting/openmw_core.rst b/docs/source/reference/lua-scripting/openmw_item.rst similarity index 65% rename from docs/source/reference/lua-scripting/openmw_core.rst rename to docs/source/reference/lua-scripting/openmw_item.rst index 2dc3f762b3..9c3ebaf8ef 100644 --- a/docs/source/reference/lua-scripting/openmw_core.rst +++ b/docs/source/reference/lua-scripting/openmw_item.rst @@ -4,4 +4,4 @@ Package openmw.core .. include:: version.rst .. raw:: html - :file: generated_html/openmw_core.html + :file: generated_html/openmw_item.html diff --git a/docs/source/reference/lua-scripting/tables/aux_packages.rst b/docs/source/reference/lua-scripting/tables/aux_packages.rst index af80f15243..32467ffd35 100644 --- a/docs/source/reference/lua-scripting/tables/aux_packages.rst +++ b/docs/source/reference/lua-scripting/tables/aux_packages.rst @@ -9,5 +9,5 @@ +---------------------------------------------------------+--------------------+---------------------------------------------------------------+ |:ref:`openmw_aux.ui ` | by player scripts | | User interface utils | +---------------------------------------------------------+--------------------+---------------------------------------------------------------+ -|:ref:`openmw_aux.core ` | everywhere | | GameObject Utils | +|:ref:`openmw_aux.item ` | everywhere | | Game Item utils | +---------------------------------------------------------+--------------------+---------------------------------------------------------------+ diff --git a/files/data/CMakeLists.txt b/files/data/CMakeLists.txt index 24c3fd003b..c97ccf893e 100644 --- a/files/data/CMakeLists.txt +++ b/files/data/CMakeLists.txt @@ -59,7 +59,7 @@ set(BUILTIN_DATA_FILES openmw_aux/time.lua openmw_aux/calendar.lua openmw_aux/calendarconfig.lua - openmw_aux/core.lua + openmw_aux/item.lua openmw_aux/ui.lua builtin.omwscripts diff --git a/files/data/openmw_aux/core.lua b/files/data/openmw_aux/item.lua similarity index 89% rename from files/data/openmw_aux/core.lua rename to files/data/openmw_aux/item.lua index 77d486a129..94d34ef014 100644 --- a/files/data/openmw_aux/core.lua +++ b/files/data/openmw_aux/item.lua @@ -5,17 +5,17 @@ local core = require('openmw.core') -- Implementation can be found in `resources/vfs/openmw_aux/core.lua`. -- @module core -- @usage local auxCore = require('openmw_aux.core') -local aux_core = {} +local aux_item = {} -local SKILL = types.NPC.stats.skills +local SKILL = core.stats.Skill.records -local armorSkillString = {[SKILL.heavyarmor] = "Heavy",[SKILL.mediumarmor] = "Medium", [SKILL.lightarmor] = "Light"} +local armorSkillString = {[SKILL.heavyarmor.id] = "Heavy",[SKILL.mediumarmor.id] = "Medium", [SKILL.lightarmor.id] = "Light"} --- -- Checks if the provided armor is Heavy, Medium, or Light. Errors if invaid object supplied. -- @function [parent=#core] getArmorType -- @param openmw.core#GameObject armor Either a gameObject or a armor record. -- @return openmw.core#SKILL The skill for this armor -function aux_core.getArmorType(armor) +function aux_item.getArmorType(armor) if armor.type ~= types.Armor and not armor.baseArmor then error("Not Armor") @@ -47,11 +47,11 @@ function aux_core.getArmorType(armor) local armorTypeWeight = math.floor(core.getGMST(armorGMSTs[armorType])) if weight <= armorTypeWeight * lightMultiplier then - return SKILL.lightarmor + return SKILL.lightarmor.id elseif weight <= armorTypeWeight * medMultiplier then - return SKILL.mediumarmor + return SKILL.mediumarmor.id else - return SKILL.heavyarmor + return SKILL.heavyarmor.id end end @@ -81,7 +81,7 @@ local function getItemSound(object) local record = object.type.record(object) local soundName = tostring(type) -- .. " Up" if type == types.Armor then - soundName = "Armor " .. armorSkillString[aux_core.getArmorType(object)] + soundName = "Armor " .. armorSkillString[aux_item.getArmorType(object)] elseif type == types.Clothing then soundName = "Clothes" if record.type == types.Clothing.TYPE.Ring then @@ -105,7 +105,7 @@ end -- @function [parent=#core] getDropSound -- @param openmw.core#GameObject item -- @return #string -function aux_core.getDropSound(item) +function aux_item.getDropSound(item) local soundName = getItemSound(item) return string.format("Item %s Down", soundName) end @@ -115,9 +115,9 @@ end -- @function [parent=#core] getPickupSound -- @param openmw.core#GameObject item -- @return #string -function aux_core.getPickupSound(item) +function aux_item.getPickupSound(item) local soundName = getItemSound(item) return string.format("Item %s Up", soundName) end -return aux_core +return aux_item From f72f81fdd8f0722de637f17e44270cd056e653c2 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Fri, 26 Apr 2024 18:01:02 -0600 Subject: [PATCH 12/16] Use item, not core --- files/data/openmw_aux/item.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/files/data/openmw_aux/item.lua b/files/data/openmw_aux/item.lua index 94d34ef014..11fb14e2b3 100644 --- a/files/data/openmw_aux/item.lua +++ b/files/data/openmw_aux/item.lua @@ -1,10 +1,10 @@ local types = require('openmw.types') local core = require('openmw.core') --- --- `openmw_aux.core` defines utility functions for objects. --- Implementation can be found in `resources/vfs/openmw_aux/core.lua`. --- @module core --- @usage local auxCore = require('openmw_aux.core') +-- `openmw_aux.item` defines utility functions for objects. +-- Implementation can be found in `resources/vfs/openmw_aux/item.lua`. +-- @module item +-- @usage local aux_item = require('openmw_aux.item') local aux_item = {} local SKILL = core.stats.Skill.records @@ -12,9 +12,9 @@ local SKILL = core.stats.Skill.records local armorSkillString = {[SKILL.heavyarmor.id] = "Heavy",[SKILL.mediumarmor.id] = "Medium", [SKILL.lightarmor.id] = "Light"} --- -- Checks if the provided armor is Heavy, Medium, or Light. Errors if invaid object supplied. --- @function [parent=#core] getArmorType +-- @function [parent=#item] getArmorType -- @param openmw.core#GameObject armor Either a gameObject or a armor record. --- @return openmw.core#SKILL The skill for this armor +-- @return #string The skill record ID for this armor function aux_item.getArmorType(armor) if armor.type ~= types.Armor and not armor.baseArmor then @@ -102,7 +102,7 @@ end --- -- Get the sound that should be played when this item is dropped. --- @function [parent=#core] getDropSound +-- @function [parent=#item] getDropSound -- @param openmw.core#GameObject item -- @return #string function aux_item.getDropSound(item) @@ -112,7 +112,7 @@ end --- -- Get the sound that should be played when this item is picked up. --- @function [parent=#core] getPickupSound +-- @function [parent=#item] getPickupSound -- @param openmw.core#GameObject item -- @return #string function aux_item.getPickupSound(item) From 820e51b0b4cb587218e0b3d2de42f0c68f269e1b Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Fri, 26 Apr 2024 18:03:43 -0600 Subject: [PATCH 13/16] Rename functions --- files/data/openmw_aux/item.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/files/data/openmw_aux/item.lua b/files/data/openmw_aux/item.lua index 11fb14e2b3..6d234d377b 100644 --- a/files/data/openmw_aux/item.lua +++ b/files/data/openmw_aux/item.lua @@ -73,30 +73,30 @@ local weaponSound = { [weaponType.LongBladeTwoHand] = "Weapon Longblade", } local goldIds = { gold_001 = true, gold_005 = true, gold_010 = true, gold_025 = true, gold_100 = true } -local function getItemSound(object) +local function getItemSoundId(object,suffix) local type = object.type if object.type.baseType ~= types.Item or not object then error("Invalid object supplied") end local record = object.type.record(object) - local soundName = tostring(type) -- .. " Up" + local soundId = tostring(type) -- .. " Up" if type == types.Armor then - soundName = "Armor " .. armorSkillString[aux_item.getArmorType(object)] + soundId = "Armor " .. armorSkillString[aux_item.getArmorType(object)] elseif type == types.Clothing then - soundName = "Clothes" + soundId = "Clothes" if record.type == types.Clothing.TYPE.Ring then - soundName = "Ring" + soundId = "Ring" end elseif type == types.Light or type == types.Miscellaneous then if goldIds[object.recordId] then - soundName = "Gold" + soundId = "Gold" else - soundName = "Misc" + soundId = "Misc" end elseif type == types.Weapon then - soundName = weaponSound[record.type] + soundId = weaponSound[record.type] end - return soundName + return string.format('item %s %s', soundId, suffix) end @@ -106,8 +106,8 @@ end -- @param openmw.core#GameObject item -- @return #string function aux_item.getDropSound(item) - local soundName = getItemSound(item) - return string.format("Item %s Down", soundName) + local soundName = getItemSoundId(item) + return getItemSoundId(item, "down") end --- @@ -116,8 +116,8 @@ end -- @param openmw.core#GameObject item -- @return #string function aux_item.getPickupSound(item) - local soundName = getItemSound(item) - return string.format("Item %s Up", soundName) + local soundName = getItemSoundId(item) + return getItemSoundId(item, "up") end return aux_item From b33f5ead5ad486e4eff1af9c6ef28b905888105e Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Fri, 26 Apr 2024 20:16:59 -0600 Subject: [PATCH 14/16] Fix error --- files/data/openmw_aux/item.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/data/openmw_aux/item.lua b/files/data/openmw_aux/item.lua index 6d234d377b..7934b6bce4 100644 --- a/files/data/openmw_aux/item.lua +++ b/files/data/openmw_aux/item.lua @@ -106,8 +106,8 @@ end -- @param openmw.core#GameObject item -- @return #string function aux_item.getDropSound(item) - local soundName = getItemSoundId(item) - return getItemSoundId(item, "down") + local itemType = getItemSoundId(item) + return getItemSoundId(itemType, "down") end --- @@ -116,8 +116,8 @@ end -- @param openmw.core#GameObject item -- @return #string function aux_item.getPickupSound(item) - local soundName = getItemSoundId(item) - return getItemSoundId(item, "up") + local itemType = getItemSoundId(item) + return getItemSoundId(itemType, "up") end return aux_item From 6b56ee0a2232c09a6c61344468da263d8a0d9c2e Mon Sep 17 00:00:00 2001 From: SkyHasACat Date: Fri, 4 Jul 2025 15:22:49 -0500 Subject: [PATCH 15/16] Fix item --- docs/source/reference/lua-scripting/openmw_aux_core.rst | 5 ----- docs/source/reference/lua-scripting/openmw_aux_item.rst | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 docs/source/reference/lua-scripting/openmw_aux_core.rst create mode 100644 docs/source/reference/lua-scripting/openmw_aux_item.rst diff --git a/docs/source/reference/lua-scripting/openmw_aux_core.rst b/docs/source/reference/lua-scripting/openmw_aux_core.rst deleted file mode 100644 index 49c72e7911..0000000000 --- a/docs/source/reference/lua-scripting/openmw_aux_core.rst +++ /dev/null @@ -1,5 +0,0 @@ -Package openmw_aux.core -======================= - -.. raw:: html - :file: generated_html/openmw_aux_core.html diff --git a/docs/source/reference/lua-scripting/openmw_aux_item.rst b/docs/source/reference/lua-scripting/openmw_aux_item.rst new file mode 100644 index 0000000000..9dd552c7f5 --- /dev/null +++ b/docs/source/reference/lua-scripting/openmw_aux_item.rst @@ -0,0 +1,5 @@ +Package openmw_aux.item +======================= + +.. raw:: html + :file: generated_html/openmw_aux_item.html From 3546987d68c73f49404cc6ab5d1ebf48309e246d Mon Sep 17 00:00:00 2001 From: SkyHasACat Date: Fri, 4 Jul 2025 15:24:21 -0500 Subject: [PATCH 16/16] Fix wrong file --- .../lua-scripting/{openmw_item.rst => openmw_core.rst} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename docs/source/reference/lua-scripting/{openmw_item.rst => openmw_core.rst} (65%) diff --git a/docs/source/reference/lua-scripting/openmw_item.rst b/docs/source/reference/lua-scripting/openmw_core.rst similarity index 65% rename from docs/source/reference/lua-scripting/openmw_item.rst rename to docs/source/reference/lua-scripting/openmw_core.rst index 9c3ebaf8ef..2dc3f762b3 100644 --- a/docs/source/reference/lua-scripting/openmw_item.rst +++ b/docs/source/reference/lua-scripting/openmw_core.rst @@ -4,4 +4,4 @@ Package openmw.core .. include:: version.rst .. raw:: html - :file: generated_html/openmw_item.html + :file: generated_html/openmw_core.html