mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 05:09:43 +00:00
Merge branch 'lua_record_services' into 'master'
add servicesOffered to npc and creature records, returning a table with a string of each service that is offered. See merge request OpenMW/openmw!3395
This commit is contained in:
commit
93aebbe3b4
4 changed files with 58 additions and 0 deletions
52
apps/openmw/mwlua/types/actor.hpp
Normal file
52
apps/openmw/mwlua/types/actor.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef MWLUA_ACTOR_H
|
||||
#define MWLUA_ACTOR_H
|
||||
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include <components/esm/defs.hpp>
|
||||
#include <components/lua/luastate.hpp>
|
||||
|
||||
#include "apps/openmw/mwworld/esmstore.hpp"
|
||||
#include <apps/openmw/mwbase/environment.hpp>
|
||||
#include <apps/openmw/mwbase/world.hpp>
|
||||
#include <components/esm3/loadclas.hpp>
|
||||
#include <components/esm3/loadnpc.hpp>
|
||||
|
||||
#include "../context.hpp"
|
||||
#include "../object.hpp"
|
||||
namespace MWLua
|
||||
{
|
||||
|
||||
template <class T>
|
||||
void addActorServicesBindings(sol::usertype<T>& record, const Context& context)
|
||||
{
|
||||
record["servicesOffered"] = sol::readonly_property([context](const T& rec) -> sol::table {
|
||||
sol::state_view& lua = context.mLua->sol();
|
||||
sol::table providedServices(lua, sol::create);
|
||||
constexpr std::array<std::pair<int, std::string_view>, 19> serviceNames = { { { ESM::NPC::Spells,
|
||||
"Spells" },
|
||||
{ ESM::NPC::Spellmaking, "Spellmaking" }, { ESM::NPC::Enchanting, "Enchanting" },
|
||||
{ ESM::NPC::Training, "Training" }, { ESM::NPC::Repair, "Repair" }, { ESM::NPC::AllItems, "Barter" },
|
||||
{ ESM::NPC::Weapon, "Weapon" }, { ESM::NPC::Armor, "Armor" }, { ESM::NPC::Clothing, "Clothing" },
|
||||
{ ESM::NPC::Books, "Books" }, { ESM::NPC::Ingredients, "Ingredients" }, { ESM::NPC::Picks, "Picks" },
|
||||
{ ESM::NPC::Probes, "Probes" }, { ESM::NPC::Lights, "Lights" }, { ESM::NPC::Apparatus, "Apparatus" },
|
||||
{ ESM::NPC::RepairItem, "RepairItem" }, { ESM::NPC::Misc, "Misc" }, { ESM::NPC::Potions, "Potions" },
|
||||
{ ESM::NPC::MagicItems, "MagicItems" } } };
|
||||
|
||||
int services = rec.mAiData.mServices;
|
||||
if constexpr (std::is_same_v<T, ESM::NPC>)
|
||||
{
|
||||
if (rec.mFlags & ESM::NPC::Autocalc)
|
||||
services
|
||||
= MWBase::Environment::get().getESMStore()->get<ESM::Class>().find(rec.mClass)->mData.mServices;
|
||||
}
|
||||
for (const auto& [flag, name] : serviceNames)
|
||||
{
|
||||
providedServices[name] = (services & flag) != 0;
|
||||
}
|
||||
providedServices["Travel"] = !rec.getTransport().empty();
|
||||
return providedServices;
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif // MWLUA_ACTOR_H
|
|
@ -1,3 +1,4 @@
|
|||
#include "actor.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadcrea.hpp>
|
||||
|
@ -48,5 +49,6 @@ 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; });
|
||||
addActorServicesBindings<ESM::Creature>(record, context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "actor.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadnpc.hpp>
|
||||
|
@ -48,6 +49,7 @@ namespace MWLua
|
|||
= sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHead.serializeText(); });
|
||||
record["isMale"] = sol::readonly_property([](const ESM::NPC& rec) -> bool { return rec.isMale(); });
|
||||
record["baseGold"] = sol::readonly_property([](const ESM::NPC& rec) -> int { return rec.mNpdt.mGold; });
|
||||
addActorServicesBindings<ESM::NPC>(record, context);
|
||||
|
||||
// This function is game-specific, in future we should replace it with something more universal.
|
||||
npc["isWerewolf"] = [](const Object& o) {
|
||||
|
|
|
@ -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. Value is if the service is provided or not, and they are indexed by: Spells, Spellmaking, Enchanting, Training, 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 NPC, in a table. Value is if the service is provided or not, and they are indexed by: Spells, Spellmaking, Enchanting, Training, Repair, Barter, Weapon, Armor, Clothing, Books, Ingredients, Picks, Probes, Lights, Apparatus, RepairItems, Misc, Potions, MagicItems, Travel.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue