diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index b6e167ab9e..e542883012 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -5,9 +5,9 @@ #include #include #include +#include -#include "../mwmechanics/actorutil.hpp" -// For MWMechanics::GreetingState +#include "../mwmechanics/greetingstate.hpp" #include "../mwworld/ptr.hpp" diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 9f9666534d..38c55cdd52 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -27,8 +27,8 @@ #include "../mwrender/objects.hpp" #include "../mwrender/renderinginterface.hpp" -#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/npcstats.hpp" +#include "../mwmechanics/inventory.hpp" namespace MWClass { diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 026ef268fe..b587fdf146 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -12,6 +12,12 @@ #include "../mwmechanics/disease.hpp" #include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/difficultyscaling.hpp" +#include "../mwmechanics/npcstats.hpp" +#include "../mwmechanics/combat.hpp" +#include "../mwmechanics/actorutil.hpp" +#include "../mwmechanics/creaturecustomdataresetter.hpp" +#include "../mwmechanics/aisetting.hpp" +#include "../mwmechanics/inventory.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -27,18 +33,14 @@ #include "../mwworld/containerstore.hpp" #include "../mwworld/cellstore.hpp" #include "../mwworld/localscripts.hpp" +#include "../mwworld/inventorystore.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwrender/renderinginterface.hpp" #include "../mwrender/objects.hpp" #include "../mwgui/tooltips.hpp" -#include "../mwworld/inventorystore.hpp" - -#include "../mwmechanics/npcstats.hpp" -#include "../mwmechanics/combat.hpp" -#include "../mwmechanics/actorutil.hpp" - namespace { bool isFlagBitSet(const MWWorld::ConstPtr &ptr, ESM::Creature::Flags bitMask) @@ -117,7 +119,7 @@ namespace MWClass { auto tempData = std::make_unique(); CreatureCustomData* data = tempData.get(); - MWMechanics::CreatureCustomDataResetter resetter(ptr); + MWMechanics::CreatureCustomDataResetter resetter {ptr}; ptr.getRefData().setCustomData(std::move(tempData)); MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp index f22fbaebaa..431f9675b6 100644 --- a/apps/openmw/mwclass/creaturelevlist.cpp +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -7,8 +7,14 @@ #include "../mwworld/cellstore.hpp" #include "../mwworld/customdata.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwworld/manualref.hpp" + #include "../mwmechanics/creaturestats.hpp" +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + namespace MWClass { class CreatureLevListCustomData : public MWWorld::TypedCustomData diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 74de6fb764..5f2ce00690 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -31,6 +34,9 @@ #include "../mwmechanics/difficultyscaling.hpp" #include "../mwmechanics/weapontype.hpp" #include "../mwmechanics/actorutil.hpp" +#include "../mwmechanics/creaturecustomdataresetter.hpp" +#include "../mwmechanics/inventory.hpp" +#include "../mwmechanics/aisetting.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" @@ -40,6 +46,7 @@ #include "../mwworld/customdata.hpp" #include "../mwworld/cellstore.hpp" #include "../mwworld/localscripts.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwrender/objects.hpp" #include "../mwrender/renderinginterface.hpp" @@ -311,7 +318,7 @@ namespace MWClass bool recalculate = false; auto tempData = std::make_unique(); NpcCustomData* data = tempData.get(); - MWMechanics::CreatureCustomDataResetter resetter(ptr); + MWMechanics::CreatureCustomDataResetter resetter {ptr}; ptr.getRefData().setCustomData(std::move(tempData)); MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 618017a7cd..fd4a21cf10 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -16,6 +16,7 @@ #include "../mwmechanics/actorutil.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/esmstore.hpp" #include #include diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 8279da089e..f7cbc30ae1 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -28,6 +28,7 @@ #include "../mwworld/actionequip.hpp" #include "../mwmechanics/npcstats.hpp" +#include "../mwmechanics/actorutil.hpp" #include "itemview.hpp" #include "inventoryitemmodel.hpp" diff --git a/apps/openmw/mwgui/pickpocketitemmodel.cpp b/apps/openmw/mwgui/pickpocketitemmodel.cpp index 2b4d474059..976485c23a 100644 --- a/apps/openmw/mwgui/pickpocketitemmodel.cpp +++ b/apps/openmw/mwgui/pickpocketitemmodel.cpp @@ -12,6 +12,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwbase/world.hpp" namespace MWGui { diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 716fd7a0b5..934936f1ab 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" @@ -11,7 +13,9 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwmechanics/actorutil.hpp" namespace MWGui { diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index 9bfd72adce..4fa6076ec9 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -10,11 +10,16 @@ #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" #include "../mwworld/containerstore.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/store.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwmechanics/spellutil.hpp" +#include "../mwmechanics/actorutil.hpp" #include "tooltips.hpp" #include "class.hpp" diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 0553b5c368..1cdb22d88f 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -16,7 +17,10 @@ #include "../mwworld/actionteleport.hpp" #include "../mwworld/cellstore.hpp" #include "../mwworld/cellutils.hpp" +#include "../mwworld/store.hpp" +#include "../mwworld/esmstore.hpp" +#include "../mwmechanics/actorutil.hpp" namespace MWGui { diff --git a/apps/openmw/mwmechanics/actor.hpp b/apps/openmw/mwmechanics/actor.hpp index 14f21193ea..3a3b0baa67 100644 --- a/apps/openmw/mwmechanics/actor.hpp +++ b/apps/openmw/mwmechanics/actor.hpp @@ -3,8 +3,11 @@ #include -#include "actorutil.hpp" #include "character.hpp" +#include "greetingstate.hpp" + +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" #include diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp index 7b54a98198..ff9face4f3 100644 --- a/apps/openmw/mwmechanics/actors.hpp +++ b/apps/openmw/mwmechanics/actors.hpp @@ -7,7 +7,6 @@ #include #include -#include "actorutil.hpp" #include "actor.hpp" namespace ESM diff --git a/apps/openmw/mwmechanics/actorutil.cpp b/apps/openmw/mwmechanics/actorutil.cpp index 4a587dd662..4e1b7706db 100644 --- a/apps/openmw/mwmechanics/actorutil.cpp +++ b/apps/openmw/mwmechanics/actorutil.cpp @@ -6,6 +6,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" +#include + namespace MWMechanics { MWWorld::Ptr getPlayer() @@ -29,12 +31,4 @@ namespace MWMechanics const MWMechanics::MagicEffects& effects = actor.getClass().getCreatureStats(actor).getMagicEffects(); return effects.get(ESM::MagicEffect::WaterWalking).getMagnitude() > 0; } - - CreatureCustomDataResetter::CreatureCustomDataResetter(const MWWorld::Ptr& ptr) : mPtr(ptr) {} - - CreatureCustomDataResetter::~CreatureCustomDataResetter() - { - if(!mPtr.isEmpty()) - mPtr.getRefData().setCustomData({}); - } } diff --git a/apps/openmw/mwmechanics/actorutil.hpp b/apps/openmw/mwmechanics/actorutil.hpp index 91770ddfec..608e26774e 100644 --- a/apps/openmw/mwmechanics/actorutil.hpp +++ b/apps/openmw/mwmechanics/actorutil.hpp @@ -1,19 +1,6 @@ #ifndef OPENMW_MWMECHANICS_ACTORUTIL_H #define OPENMW_MWMECHANICS_ACTORUTIL_H -#include - -#include -#include -#include - -#include "../mwbase/environment.hpp" -#include "../mwbase/world.hpp" - -#include "../mwworld/esmstore.hpp" - -#include "./creaturestats.hpp" - namespace MWWorld { class Ptr; @@ -21,79 +8,10 @@ namespace MWWorld namespace MWMechanics { - enum GreetingState - { - Greet_None, - Greet_InProgress, - Greet_Done - }; - MWWorld::Ptr getPlayer(); bool isPlayerInCombat(); bool canActorMoveByZAxis(const MWWorld::Ptr& actor); bool hasWaterWalking(const MWWorld::Ptr& actor); - - template - void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) - { - T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(id); - switch(setting) - { - case MWMechanics::CreatureStats::AiSetting::AI_Hello: - copy.mAiData.mHello = value; - break; - case MWMechanics::CreatureStats::AiSetting::AI_Fight: - copy.mAiData.mFight = value; - break; - case MWMechanics::CreatureStats::AiSetting::AI_Flee: - copy.mAiData.mFlee = value; - break; - case MWMechanics::CreatureStats::AiSetting::AI_Alarm: - copy.mAiData.mAlarm = value; - break; - default: - assert(0); - } - MWBase::Environment::get().getWorld()->createOverrideRecord(copy); - } - - template - void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) - { - T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(actorId); - for(auto& it : copy.mInventory.mList) - { - if(Misc::StringUtils::ciEqual(it.mItem, itemId)) - { - int sign = it.mCount < 1 ? -1 : 1; - it.mCount = sign * std::max(it.mCount * sign + amount, 0); - MWBase::Environment::get().getWorld()->createOverrideRecord(copy); - return; - } - } - if(amount > 0) - { - ESM::ContItem cont; - cont.mItem = itemId; - cont.mCount = amount; - copy.mInventory.mList.push_back(cont); - MWBase::Environment::get().getWorld()->createOverrideRecord(copy); - } - } - - template void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value); - template void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value); - template void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount); - template void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount); - template void modifyBaseInventory(const std::string& containerId, const std::string& itemId, int amount); - - struct CreatureCustomDataResetter - { - MWWorld::Ptr mPtr; - - CreatureCustomDataResetter(const MWWorld::Ptr& ptr); - ~CreatureCustomDataResetter(); - }; } #endif diff --git a/apps/openmw/mwmechanics/aisetting.hpp b/apps/openmw/mwmechanics/aisetting.hpp new file mode 100644 index 0000000000..d11769ac6f --- /dev/null +++ b/apps/openmw/mwmechanics/aisetting.hpp @@ -0,0 +1,40 @@ +#ifndef OPENMW_MWMECHANICS_AISETTING_H +#define OPENMW_MWMECHANICS_AISETTING_H + +#include + +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + +#include "../mwworld/esmstore.hpp" + +#include "creaturestats.hpp" + +namespace MWMechanics +{ + template + void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) + { + T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(id); + switch (setting) + { + case MWMechanics::CreatureStats::AiSetting::AI_Hello: + copy.mAiData.mHello = value; + break; + case MWMechanics::CreatureStats::AiSetting::AI_Fight: + copy.mAiData.mFight = value; + break; + case MWMechanics::CreatureStats::AiSetting::AI_Flee: + copy.mAiData.mFlee = value; + break; + case MWMechanics::CreatureStats::AiSetting::AI_Alarm: + copy.mAiData.mAlarm = value; + break; + default: + assert(false); + } + MWBase::Environment::get().getWorld()->createOverrideRecord(copy); + } +} + +#endif diff --git a/apps/openmw/mwmechanics/creaturecustomdataresetter.hpp b/apps/openmw/mwmechanics/creaturecustomdataresetter.hpp new file mode 100644 index 0000000000..667a0b9c45 --- /dev/null +++ b/apps/openmw/mwmechanics/creaturecustomdataresetter.hpp @@ -0,0 +1,20 @@ +#ifndef OPENMW_MWMECHANICS_CREATURECUSTOMDATARESETTER_H +#define OPENMW_MWMECHANICS_CREATURECUSTOMDATARESETTER_H + +#include "../mwworld/ptr.hpp" + +namespace MWMechanics +{ + struct CreatureCustomDataResetter + { + MWWorld::Ptr mPtr; + + ~CreatureCustomDataResetter() + { + if (!mPtr.isEmpty()) + mPtr.getRefData().setCustomData({}); + } + }; +} + +#endif diff --git a/apps/openmw/mwmechanics/greetingstate.hpp b/apps/openmw/mwmechanics/greetingstate.hpp new file mode 100644 index 0000000000..9b37096322 --- /dev/null +++ b/apps/openmw/mwmechanics/greetingstate.hpp @@ -0,0 +1,14 @@ +#ifndef OPENMW_MWMECHANICS_GREETINGSTATE_H +#define OPENMW_MWMECHANICS_GREETINGSTATE_H + +namespace MWMechanics +{ + enum GreetingState + { + Greet_None, + Greet_InProgress, + Greet_Done + }; +} + +#endif diff --git a/apps/openmw/mwmechanics/inventory.hpp b/apps/openmw/mwmechanics/inventory.hpp new file mode 100644 index 0000000000..ddd4b3351a --- /dev/null +++ b/apps/openmw/mwmechanics/inventory.hpp @@ -0,0 +1,42 @@ +#ifndef OPENMW_MWMECHANICS_INVENTORY_H +#define OPENMW_MWMECHANICS_INVENTORY_H + +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + +#include "../mwworld/esmstore.hpp" + +#include +#include + +#include +#include + +namespace MWMechanics +{ + template + void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) + { + T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(actorId); + for (auto& it : copy.mInventory.mList) + { + if (Misc::StringUtils::ciEqual(it.mItem, itemId)) + { + const int sign = it.mCount < 1 ? -1 : 1; + it.mCount = sign * std::max(it.mCount * sign + amount, 0); + MWBase::Environment::get().getWorld()->createOverrideRecord(copy); + return; + } + } + if (amount > 0) + { + ESM::ContItem cont; + cont.mItem = itemId; + cont.mCount = amount; + copy.mInventory.mList.push_back(cont); + MWBase::Environment::get().getWorld()->createOverrideRecord(copy); + } + } +} + +#endif diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index cb8e520384..9bc6f942f0 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -9,11 +9,15 @@ #include #include "components/misc/convert.hpp" #include "components/settings/settings.hpp" + #include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/movement.hpp" #include "../mwrender/bulletdebugdraw.hpp" #include "../mwworld/class.hpp" +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + #include "actor.hpp" #include "contacttestwrapper.h" #include "movementsolver.hpp" diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index cbee0ba07d..449217fa68 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -52,14 +52,18 @@ #include -#include "../mwbase/windowmanager.hpp" #include "../mwworld/cellstore.hpp" #include "../mwworld/class.hpp" #include "../mwworld/groundcoverstore.hpp" + #include "../mwgui/loadingscreen.hpp" #include "../mwgui/postprocessorhud.hpp" + #include "../mwmechanics/actorutil.hpp" + #include "../mwbase/windowmanager.hpp" +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" #include "sky.hpp" #include "effectmanager.hpp" diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 11e9095e2c..bb63ec84cc 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" @@ -26,6 +27,7 @@ #include "../mwworld/containerstore.hpp" #include "../mwworld/inventorystore.hpp" #include "../mwworld/manualref.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/levelledlist.hpp" diff --git a/apps/openmw/mwworld/actionopen.cpp b/apps/openmw/mwworld/actionopen.cpp index 266ea4d95f..61f2f3e30c 100644 --- a/apps/openmw/mwworld/actionopen.cpp +++ b/apps/openmw/mwworld/actionopen.cpp @@ -5,6 +5,7 @@ #include "../mwbase/windowmanager.hpp" #include "../mwmechanics/disease.hpp" +#include "../mwmechanics/actorutil.hpp" namespace MWWorld { diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp index 644e23a521..bbf4952063 100644 --- a/apps/openmw/mwworld/actionteleport.cpp +++ b/apps/openmw/mwworld/actionteleport.cpp @@ -1,5 +1,7 @@ #include "actionteleport.hpp" +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/mechanicsmanager.hpp" diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 14a19c482c..140582c1a8 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -19,6 +20,7 @@ #include "class.hpp" #include "localscripts.hpp" #include "player.hpp" +#include "esmstore.hpp" namespace { diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 1e12d0b1dd..74cab7a461 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -8,6 +8,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" +#include "../mwbase/world.hpp" #include "../mwmechanics/actorutil.hpp" diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index de90c2e52a..628ac60727 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -47,6 +47,7 @@ #include "../mwmechanics/combat.hpp" #include "../mwmechanics/aiavoiddoor.hpp" //Used to tell actors to avoid doors #include "../mwmechanics/summoning.hpp" +#include "../mwmechanics/actorutil.hpp" #include "../mwrender/animation.hpp" #include "../mwrender/npcanimation.hpp"