diff --git a/apps/openmw/mwlua/types/creature.cpp b/apps/openmw/mwlua/types/creature.cpp index 08c0dd021c..484de9d969 100644 --- a/apps/openmw/mwlua/types/creature.cpp +++ b/apps/openmw/mwlua/types/creature.cpp @@ -1,6 +1,7 @@ #include "types.hpp" #include +#include #include #include #include @@ -48,5 +49,51 @@ namespace MWLua record["soulValue"] = sol::readonly_property([](const ESM::Creature& rec) -> int { return rec.mData.mSoul; }); record["type"] = sol::readonly_property([](const ESM::Creature& rec) -> int { return rec.mData.mType; }); record["baseGold"] = sol::readonly_property([](const ESM::Creature& rec) -> int { return rec.mData.mGold; }); + record["servicesOffered"] = sol::readonly_property([](const ESM::Creature& rec) { + std::vector providedServices; + + int mServices = rec.mAiData.mServices; + if (mServices & ESM::NPC::Spells) + providedServices.push_back("Spells"); + if (mServices & ESM::NPC::Spellmaking) + providedServices.push_back("Spellmaking"); + if (mServices & ESM::NPC::Enchanting) + providedServices.push_back("Enchanting"); + if (mServices & ESM::NPC::Repair) + providedServices.push_back("Repair"); + if (mServices & ESM::NPC::AllItems) + providedServices.push_back("Barter"); + + if (mServices & ESM::NPC::Weapon) + providedServices.push_back("Weapon"); + if (mServices & ESM::NPC::Armor) + providedServices.push_back("Armor"); + if (mServices & ESM::NPC::Clothing) + providedServices.push_back("Clothing"); + if (mServices & ESM::NPC::Books) + providedServices.push_back("Books"); + if (mServices & ESM::NPC::Ingredients) + providedServices.push_back("Ingredients"); + if (mServices & ESM::NPC::Picks) + providedServices.push_back("Picks"); + if (mServices & ESM::NPC::Probes) + providedServices.push_back("Probes"); + if (mServices & ESM::NPC::Lights) + providedServices.push_back("Lights"); + if (mServices & ESM::NPC::Apparatus) + providedServices.push_back("Apparatus"); + if (mServices & ESM::NPC::RepairItem) + providedServices.push_back("RepairItem"); + if (mServices & ESM::NPC::Misc) + providedServices.push_back("Misc"); + if (mServices & ESM::NPC::Potions) + providedServices.push_back("Potions"); + if (mServices & ESM::NPC::MagicItems) + providedServices.push_back("MagicItems"); + if (rec.getTransport().size() > 0) + providedServices.push_back("Travel"); + + return providedServices; + }); } } diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index d1a91cabc9..6d7b62b222 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -3,6 +3,7 @@ #include #include +#include "apps/openmw/mwworld/worldmodel.hpp" #include #include #include @@ -57,6 +58,54 @@ namespace MWLua else throw std::runtime_error("NPC or Player expected"); }; + record["servicesOffered"] = sol::readonly_property([](const ESM::NPC& rec) { + std::vector providedServices; + + int mServices = rec.mAiData.mServices; + if (mServices & ESM::NPC::Spells) + providedServices.push_back("Spells"); + if (mServices & ESM::NPC::Spellmaking) + providedServices.push_back("Spellmaking"); + if (mServices & ESM::NPC::Enchanting) + providedServices.push_back("Enchanting"); + if (mServices & ESM::NPC::Training) + providedServices.push_back("Training"); + if (mServices & ESM::NPC::Repair) + providedServices.push_back("Repair"); + if (mServices & ESM::NPC::AllItems) + providedServices.push_back("Barter"); + + if (mServices & ESM::NPC::Weapon) + providedServices.push_back("Weapon"); + if (mServices & ESM::NPC::Armor) + providedServices.push_back("Armor"); + if (mServices & ESM::NPC::Clothing) + providedServices.push_back("Clothing"); + if (mServices & ESM::NPC::Books) + providedServices.push_back("Books"); + if (mServices & ESM::NPC::Ingredients) + providedServices.push_back("Ingredients"); + if (mServices & ESM::NPC::Picks) + providedServices.push_back("Picks"); + if (mServices & ESM::NPC::Probes) + providedServices.push_back("Probes"); + if (mServices & ESM::NPC::Lights) + providedServices.push_back("Lights"); + if (mServices & ESM::NPC::Apparatus) + providedServices.push_back("Apparatus"); + if (mServices & ESM::NPC::RepairItem) + providedServices.push_back("RepairItem"); + if (mServices & ESM::NPC::Misc) + providedServices.push_back("Misc"); + if (mServices & ESM::NPC::Potions) + providedServices.push_back("Potions"); + if (mServices & ESM::NPC::MagicItems) + providedServices.push_back("MagicItems"); + if (rec.getTransport().size() > 0) + providedServices.push_back("Travel"); + + return providedServices; + }); npc["getDisposition"] = [](const Object& o, const Object& player) -> int { if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr()) diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index ea5368efde..b4b21dcab9 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -701,6 +701,7 @@ -- @field #number soulValue The soul value of the creature record -- @field #number type The @{#Creature.TYPE} of the creature -- @field #number baseGold The base barter gold of the creature +-- @field #list<#string> servicesOffered The services of the creature, in a table. Possible entries are: Spells, Spellmaking, Enchanting, Repair, Barter, Weapon, Armor, Clothing, Books, Ingredients, Picks, Probes, Lights, Apparatus, RepairItems, Misc, Potions, MagicItems, Travel. --- @{#NPC} functions @@ -750,6 +751,7 @@ -- @field #number baseGold The base barter gold of the NPC -- @field #number baseDisposition NPC's starting disposition -- @field #bool isMale The gender setting of the NPC +-- @field #list<#string> servicesOffered The services of the creature, in a table. Possible entries are: Spells, Spellmaking, Enchanting, Training, Repair, Barter, Weapon, Armor, Clothing, Books, Ingredients, Picks, Probes, Lights, Apparatus, RepairItems, Misc, Potions, MagicItems, Travel. --------------------------------------------------------------------------------