diff --git a/apps/openmw/mwclass/actor.hpp b/apps/openmw/mwclass/actor.hpp index f2d080a64f..fca610bc41 100644 --- a/apps/openmw/mwclass/actor.hpp +++ b/apps/openmw/mwclass/actor.hpp @@ -3,7 +3,10 @@ #include "../mwworld/class.hpp" +#include "../mwmechanics/magiceffects.hpp" + #include +#include namespace ESM { diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 620315d0a3..c26b92993c 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -18,6 +18,7 @@ #include "../mwmechanics/creaturecustomdataresetter.hpp" #include "../mwmechanics/aisetting.hpp" #include "../mwmechanics/inventory.hpp" +#include "../mwmechanics/setbaseaisetting.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -143,10 +144,10 @@ namespace MWClass data->mCreatureStats.getAiSequence().fill(ref->mBase->mAiPackage); - data->mCreatureStats.setAiSetting (MWMechanics::CreatureStats::AI_Hello, ref->mBase->mAiData.mHello); - data->mCreatureStats.setAiSetting (MWMechanics::CreatureStats::AI_Fight, ref->mBase->mAiData.mFight); - data->mCreatureStats.setAiSetting (MWMechanics::CreatureStats::AI_Flee, ref->mBase->mAiData.mFlee); - data->mCreatureStats.setAiSetting (MWMechanics::CreatureStats::AI_Alarm, ref->mBase->mAiData.mAlarm); + data->mCreatureStats.setAiSetting(MWMechanics::AiSetting::Hello, ref->mBase->mAiData.mHello); + data->mCreatureStats.setAiSetting(MWMechanics::AiSetting::Fight, ref->mBase->mAiData.mFight); + data->mCreatureStats.setAiSetting(MWMechanics::AiSetting::Flee, ref->mBase->mAiData.mFlee); + data->mCreatureStats.setAiSetting(MWMechanics::AiSetting::Alarm, ref->mBase->mAiData.mAlarm); // Persistent actors with 0 health do not play death animation if (data->mCreatureStats.isDead()) @@ -863,7 +864,7 @@ namespace MWClass scale *= ref->mBase->mScale; } - void Creature::setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) const + void Creature::setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const { MWMechanics::setBaseAISetting(id, setting, value); } diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index bc5d44ad36..a1696d80f0 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -134,7 +134,7 @@ namespace MWClass void adjustScale(const MWWorld::ConstPtr& ptr, osg::Vec3f& scale, bool rendering) const override; /// @param rendering Indicates if the scale to adjust is for the rendering mesh, or for the collision mesh - void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) const override; + void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override; void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const override; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index dbbb5217ce..fc4f655246 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -38,6 +38,7 @@ #include "../mwmechanics/creaturecustomdataresetter.hpp" #include "../mwmechanics/inventory.hpp" #include "../mwmechanics/aisetting.hpp" +#include "../mwmechanics/setbaseaisetting.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" @@ -390,10 +391,10 @@ namespace MWClass data->mNpcStats.getAiSequence().fill(ref->mBase->mAiPackage); - data->mNpcStats.setAiSetting (MWMechanics::CreatureStats::AI_Hello, ref->mBase->mAiData.mHello); - data->mNpcStats.setAiSetting (MWMechanics::CreatureStats::AI_Fight, ref->mBase->mAiData.mFight); - data->mNpcStats.setAiSetting (MWMechanics::CreatureStats::AI_Flee, ref->mBase->mAiData.mFlee); - data->mNpcStats.setAiSetting (MWMechanics::CreatureStats::AI_Alarm, ref->mBase->mAiData.mAlarm); + data->mNpcStats.setAiSetting(MWMechanics::AiSetting::Hello, ref->mBase->mAiData.mHello); + data->mNpcStats.setAiSetting(MWMechanics::AiSetting::Fight, ref->mBase->mAiData.mFight); + data->mNpcStats.setAiSetting(MWMechanics::AiSetting::Flee, ref->mBase->mAiData.mFlee); + data->mNpcStats.setAiSetting(MWMechanics::AiSetting::Alarm, ref->mBase->mAiData.mAlarm); // spells if (!spellsInitialised) @@ -1452,7 +1453,7 @@ namespace MWClass return ref->mBase->getFactionRank(); } - void Npc::setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) const + void Npc::setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const { MWMechanics::setBaseAISetting(id, setting, value); } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index d6ae7cbca5..264612944e 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -162,7 +162,7 @@ namespace MWClass std::string getPrimaryFaction(const MWWorld::ConstPtr &ptr) const override; int getPrimaryFactionRank(const MWWorld::ConstPtr &ptr) const override; - void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) const override; + void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override; void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const override; diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index e90ba79481..b855d75238 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -309,7 +309,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con case SelectWrapper::Function_AiSetting: return mActor.getClass().getCreatureStats (mActor).getAiSetting ( - (MWMechanics::CreatureStats::AiSetting)select.getArgument()).getModified(false); + (MWMechanics::AiSetting)select.getArgument()).getModified(false); case SelectWrapper::Function_PcAttribute: diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 934936f1ab..9651513533 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -16,6 +16,8 @@ #include "../mwworld/esmstore.hpp" #include "../mwmechanics/actorutil.hpp" +#include "../mwmechanics/spells.hpp" +#include "../mwmechanics/creaturestats.hpp" namespace MWGui { diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index c6ee5b5e66..6a8beb63fd 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -22,6 +22,7 @@ #include "../mwmechanics/spellutil.hpp" #include "../mwmechanics/actorutil.hpp" +#include "../mwmechanics/creaturestats.hpp" #include "tooltips.hpp" #include "class.hpp" diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 1cdb22d88f..fcdc5775d1 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -21,6 +21,7 @@ #include "../mwworld/esmstore.hpp" #include "../mwmechanics/actorutil.hpp" +#include "../mwmechanics/creaturestats.hpp" namespace MWGui { diff --git a/apps/openmw/mwlua/localscripts.cpp b/apps/openmw/mwlua/localscripts.cpp index 270379fe6d..4fd9920cb5 100644 --- a/apps/openmw/mwlua/localscripts.cpp +++ b/apps/openmw/mwlua/localscripts.cpp @@ -12,6 +12,7 @@ #include "../mwmechanics/aitravel.hpp" #include "../mwmechanics/aiwander.hpp" #include "../mwmechanics/aipackage.hpp" +#include "../mwmechanics/creaturestats.hpp" #include "luamanagerimp.hpp" diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index 90ce134f24..14da8b098c 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -9,6 +9,8 @@ #include "../mwworld/inventorystore.hpp" #include "../mwworld/player.hpp" +#include "../mwmechanics/creaturestats.hpp" + #include "eventqueue.hpp" #include "luamanagerimp.hpp" #include "types/types.hpp" diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 2a272ef862..0e89b22052 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 99256d1395..a5ab0a6ae6 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -372,7 +372,7 @@ namespace MWMechanics return; const CreatureStats &stats = actor.getClass().getCreatureStats(actor); - if (stats.getAiSetting(CreatureStats::AI_Hello).getModified() == 0) + if (stats.getAiSetting(AiSetting::Hello).getModified() == 0) return; const MWMechanics::AiSequence& seq = stats.getAiSequence(); @@ -463,7 +463,7 @@ namespace MWMechanics static const int iGreetDistanceMultiplier = MWBase::Environment::get().getWorld()->getStore() .get().find("iGreetDistanceMultiplier")->mValue.getInteger(); - const float helloDistance = static_cast(actorStats.getAiSetting(CreatureStats::AI_Hello).getModified() * iGreetDistanceMultiplier); + const float helloDistance = static_cast(actorStats.getAiSetting(AiSetting::Hello).getModified() * iGreetDistanceMultiplier); const auto& playerStats = player.getClass().getCreatureStats(player); int greetingTimer = actorState.getGreetingTimer(); @@ -1089,7 +1089,7 @@ namespace MWMechanics // Reset factors to attack creatureStats.setAttacked(false); creatureStats.setAlarmed(false); - creatureStats.setAiSetting(CreatureStats::AI_Fight, ptr.getClass().getBaseFightRating(ptr)); + creatureStats.setAiSetting(AiSetting::Fight, ptr.getClass().getBaseFightRating(ptr)); // Update witness crime id npcStats.setCrimeId(-1); diff --git a/apps/openmw/mwmechanics/actorutil.cpp b/apps/openmw/mwmechanics/actorutil.cpp index 4e1b7706db..8615af9860 100644 --- a/apps/openmw/mwmechanics/actorutil.cpp +++ b/apps/openmw/mwmechanics/actorutil.cpp @@ -6,6 +6,9 @@ #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" +#include "../mwmechanics/magiceffects.hpp" +#include "../mwmechanics/creaturestats.hpp" + #include namespace MWMechanics diff --git a/apps/openmw/mwmechanics/aicombataction.cpp b/apps/openmw/mwmechanics/aicombataction.cpp index c4d2bf9bec..c2fdf70a72 100644 --- a/apps/openmw/mwmechanics/aicombataction.cpp +++ b/apps/openmw/mwmechanics/aicombataction.cpp @@ -468,7 +468,7 @@ namespace MWMechanics const CreatureStats& stats = actor.getClass().getCreatureStats(actor); const MWWorld::Store& gmst = MWBase::Environment::get().getWorld()->getStore().get(); - int flee = stats.getAiSetting(CreatureStats::AI_Flee).getModified(); + const int flee = stats.getAiSetting(AiSetting::Flee).getModified(); if (flee >= 100) return flee; diff --git a/apps/openmw/mwmechanics/aisetting.hpp b/apps/openmw/mwmechanics/aisetting.hpp index d11769ac6f..3a274722fe 100644 --- a/apps/openmw/mwmechanics/aisetting.hpp +++ b/apps/openmw/mwmechanics/aisetting.hpp @@ -1,40 +1,15 @@ #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) + enum class AiSetting { - 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); - } + Hello = 0, + Fight = 1, + Flee = 2, + Alarm = 3 + }; } #endif diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 2faa6332ec..8369a221db 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -1,6 +1,7 @@ #include "creaturestats.hpp" #include +#include #include #include @@ -99,7 +100,7 @@ namespace MWMechanics Stat CreatureStats::getAiSetting (AiSetting index) const { - return mAiSettings[index]; + return mAiSettings[static_cast>(index)]; } const DynamicStat &CreatureStats::getDynamic(int index) const @@ -212,7 +213,7 @@ namespace MWMechanics void CreatureStats::setAiSetting (AiSetting index, Stat value) { - mAiSettings[index] = value; + mAiSettings[static_cast>(index)] = value; } void CreatureStats::setAiSetting (AiSetting index, int base) diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 8908ed838c..1e6d378df7 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -12,6 +12,7 @@ #include "activespells.hpp" #include "aisequence.hpp" #include "drawstate.hpp" +#include "aisetting.hpp" #include #include @@ -154,13 +155,6 @@ namespace MWMechanics void setLevel(int level); - enum AiSetting - { - AI_Hello = 0, - AI_Fight = 1, - AI_Flee = 2, - AI_Alarm = 3 - }; void setAiSetting (AiSetting index, Stat value); void setAiSetting (AiSetting index, int base); Stat getAiSetting (AiSetting index) const; diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 95842330f8..5e1462912a 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -678,11 +678,11 @@ namespace MWMechanics { float s = floor(r * fPerDieRollMult * fPerTempMult); - int flee = npcStats.getAiSetting(MWMechanics::CreatureStats::AI_Flee).getBase(); - int fight = npcStats.getAiSetting(MWMechanics::CreatureStats::AI_Fight).getBase(); - npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Flee, + const int flee = npcStats.getAiSetting(MWMechanics::AiSetting::Flee).getBase(); + const int fight = npcStats.getAiSetting(MWMechanics::AiSetting::Fight).getBase(); + npcStats.setAiSetting (MWMechanics::AiSetting::Flee, std::clamp(flee + int(std::max(iPerMinChange, s)), 0, 100)); - npcStats.setAiSetting (MWMechanics::CreatureStats::AI_Fight, + npcStats.setAiSetting (MWMechanics::AiSetting::Fight, std::clamp(fight + int(std::min(-iPerMinChange, -s)), 0, 100)); } @@ -719,11 +719,11 @@ namespace MWMechanics if (success) { float s = c * fPerDieRollMult * fPerTempMult; - int flee = npcStats.getAiSetting (CreatureStats::AI_Flee).getBase(); - int fight = npcStats.getAiSetting (CreatureStats::AI_Fight).getBase(); - npcStats.setAiSetting(CreatureStats::AI_Flee, + const int flee = npcStats.getAiSetting(AiSetting::Flee).getBase(); + const int fight = npcStats.getAiSetting(AiSetting::Fight).getBase(); + npcStats.setAiSetting(AiSetting::Flee, std::clamp(flee + std::min(-int(iPerMinChange), int(-s)), 0, 100)); - npcStats.setAiSetting(CreatureStats::AI_Fight, + npcStats.setAiSetting(AiSetting::Fight, std::clamp(fight + std::max(int(iPerMinChange), int(s)), 0, 100)); } x = floor(-c * fPerDieRollMult); @@ -1297,7 +1297,7 @@ namespace MWMechanics continue; // Will the witness report the crime? - if (actor.getClass().getCreatureStats(actor).getAiSetting(CreatureStats::AI_Alarm).getBase() >= 100) + if (actor.getClass().getCreatureStats(actor).getAiSetting(AiSetting::Alarm).getBase() >= 100) { reported = true; @@ -1329,7 +1329,7 @@ namespace MWMechanics { float dispTerm = (actor == victim) ? dispVictim : disp; - float alarmTerm = 0.01f * actor.getClass().getCreatureStats(actor).getAiSetting(CreatureStats::AI_Alarm).getBase(); + float alarmTerm = 0.01f * actor.getClass().getCreatureStats(actor).getAiSetting(AiSetting::Alarm).getBase(); if (type == OT_Pickpocket && alarmTerm <= 0) alarmTerm = 1.0; @@ -1341,7 +1341,7 @@ namespace MWMechanics fightTerm += getFightDistanceBias(actor, player); fightTerm *= alarmTerm; - int observerFightRating = actor.getClass().getCreatureStats(actor).getAiSetting(CreatureStats::AI_Fight).getBase(); + const int observerFightRating = actor.getClass().getCreatureStats(actor).getAiSetting(AiSetting::Fight).getBase(); if (observerFightRating + fightTerm > 100) fightTerm = static_cast(100 - observerFightRating); fightTerm = std::max(0.f, fightTerm); @@ -1353,7 +1353,7 @@ namespace MWMechanics NpcStats& observerStats = actor.getClass().getNpcStats(actor); // Apply aggression value to the base Fight rating, so that the actor can continue fighting // after a Calm spell wears off - observerStats.setAiSetting(CreatureStats::AI_Fight, observerFightRating + static_cast(fightTerm)); + observerStats.setAiSetting(AiSetting::Fight, observerFightRating + static_cast(fightTerm)); observerStats.setBaseDisposition(observerStats.getBaseDisposition() + static_cast(dispTerm)); @@ -1452,7 +1452,7 @@ namespace MWMechanics std::string script = target.getClass().getScript(target); if (!script.empty() && target.getRefData().getLocals().hasVar(script, "onpchitme") && attacker == player) { - int fight = target.getClass().getCreatureStats(target).getAiSetting(CreatureStats::AI_Fight).getModified(); + const int fight = target.getClass().getCreatureStats(target).getAiSetting(AiSetting::Fight).getModified(); peaceful = (fight == 0); } @@ -1736,7 +1736,7 @@ namespace MWMechanics if (ptr.getClass().isNpc()) disposition = getDerivedDisposition(ptr); - int fight = ptr.getClass().getCreatureStats(ptr).getAiSetting(CreatureStats::AI_Fight).getModified() + int fight = ptr.getClass().getCreatureStats(ptr).getAiSetting(AiSetting::Fight).getModified() + static_cast(getFightDistanceBias(ptr, target) + getFightDispositionBias(static_cast(disposition))); if (ptr.getClass().isNpc() && target.getClass().isNpc()) @@ -1851,7 +1851,7 @@ namespace MWMechanics if (MWBase::Environment::get().getWorld()->getLOS(neighbor, actor) && awarenessCheck(actor, neighbor)) { detected = true; - if (neighbor.getClass().getCreatureStats(neighbor).getAiSetting(MWMechanics::CreatureStats::AI_Alarm).getModified() > 0) + if (neighbor.getClass().getCreatureStats(neighbor).getAiSetting(MWMechanics::AiSetting::Alarm).getModified() > 0) { reported = true; break; diff --git a/apps/openmw/mwmechanics/setbaseaisetting.hpp b/apps/openmw/mwmechanics/setbaseaisetting.hpp new file mode 100644 index 0000000000..523161f731 --- /dev/null +++ b/apps/openmw/mwmechanics/setbaseaisetting.hpp @@ -0,0 +1,41 @@ +#ifndef OPENMW_MWMECHANICS_SETBASEAISETTING_H +#define OPENMW_MWMECHANICS_SETBASEAISETTING_H + +#include + +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + +#include "../mwworld/esmstore.hpp" + +#include "aisetting.hpp" +#include "creaturestats.hpp" + +namespace MWMechanics +{ + template + void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) + { + T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(id); + switch (setting) + { + case MWMechanics::AiSetting::Hello: + copy.mAiData.mHello = value; + break; + case MWMechanics::AiSetting::Fight: + copy.mAiData.mFight = value; + break; + case MWMechanics::AiSetting::Flee: + copy.mAiData.mFlee = value; + break; + case MWMechanics::AiSetting::Alarm: + copy.mAiData.mAlarm = value; + break; + default: + assert(false); + } + MWBase::Environment::get().getWorld()->createOverrideRecord(copy); + } +} + +#endif diff --git a/apps/openmw/mwmechanics/spelleffects.cpp b/apps/openmw/mwmechanics/spelleffects.cpp index 8a92dd5b68..a43d19431b 100644 --- a/apps/openmw/mwmechanics/spelleffects.cpp +++ b/apps/openmw/mwmechanics/spelleffects.cpp @@ -40,7 +40,7 @@ namespace return effect.mMinMagnitude + Misc::Rng::rollDice(effect.mMaxMagnitude - effect.mMinMagnitude + 1, prng); } - void modifyAiSetting(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, ESM::MagicEffect::Effects creatureEffect, MWMechanics::CreatureStats::AiSetting setting, float magnitude, bool& invalid) + void modifyAiSetting(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, ESM::MagicEffect::Effects creatureEffect, MWMechanics::AiSetting setting, float magnitude, bool& invalid) { if(target == MWMechanics::getPlayer() || (effect.mEffectId == creatureEffect) == target.getClass().isNpc()) invalid = true; @@ -501,18 +501,18 @@ void applyMagicEffect(const MWWorld::Ptr& target, const MWWorld::Ptr& caster, co else { auto& creatureStats = target.getClass().getCreatureStats(target); - Stat stat = creatureStats.getAiSetting(CreatureStats::AI_Flee); + Stat stat = creatureStats.getAiSetting(AiSetting::Flee); stat.setModifier(static_cast(stat.getModifier() + effect.mMagnitude)); - creatureStats.setAiSetting(CreatureStats::AI_Flee, stat); + creatureStats.setAiSetting(AiSetting::Flee, stat); } break; case ESM::MagicEffect::FrenzyCreature: case ESM::MagicEffect::FrenzyHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::FrenzyCreature, CreatureStats::AI_Fight, effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::FrenzyCreature, AiSetting::Fight, effect.mMagnitude, invalid); break; case ESM::MagicEffect::CalmCreature: case ESM::MagicEffect::CalmHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::CalmCreature, CreatureStats::AI_Fight, -effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::CalmCreature, AiSetting::Fight, -effect.mMagnitude, invalid); if(!invalid && effect.mMagnitude > 0) { auto& creatureStats = target.getClass().getCreatureStats(target); @@ -521,11 +521,11 @@ void applyMagicEffect(const MWWorld::Ptr& target, const MWWorld::Ptr& caster, co break; case ESM::MagicEffect::DemoralizeCreature: case ESM::MagicEffect::DemoralizeHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::DemoralizeCreature, CreatureStats::AI_Flee, effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::DemoralizeCreature, AiSetting::Flee, effect.mMagnitude, invalid); break; case ESM::MagicEffect::RallyCreature: case ESM::MagicEffect::RallyHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::RallyCreature, CreatureStats::AI_Flee, -effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::RallyCreature, AiSetting::Flee, -effect.mMagnitude, invalid); break; case ESM::MagicEffect::SummonScamp: case ESM::MagicEffect::SummonClannfear: @@ -1006,26 +1006,26 @@ void removeMagicEffect(const MWWorld::Ptr& target, ActiveSpells::ActiveSpellPara case ESM::MagicEffect::TurnUndead: { auto& creatureStats = target.getClass().getCreatureStats(target); - Stat stat = creatureStats.getAiSetting(CreatureStats::AI_Flee); + Stat stat = creatureStats.getAiSetting(AiSetting::Flee); stat.setModifier(static_cast(stat.getModifier() - effect.mMagnitude)); - creatureStats.setAiSetting(CreatureStats::AI_Flee, stat); + creatureStats.setAiSetting(AiSetting::Flee, stat); } break; case ESM::MagicEffect::FrenzyCreature: case ESM::MagicEffect::FrenzyHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::FrenzyCreature, CreatureStats::AI_Fight, -effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::FrenzyCreature, AiSetting::Fight, -effect.mMagnitude, invalid); break; case ESM::MagicEffect::CalmCreature: case ESM::MagicEffect::CalmHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::CalmCreature, CreatureStats::AI_Fight, effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::CalmCreature, AiSetting::Fight, effect.mMagnitude, invalid); break; case ESM::MagicEffect::DemoralizeCreature: case ESM::MagicEffect::DemoralizeHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::DemoralizeCreature, CreatureStats::AI_Flee, -effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::DemoralizeCreature, AiSetting::Flee, -effect.mMagnitude, invalid); break; case ESM::MagicEffect::RallyCreature: case ESM::MagicEffect::RallyHumanoid: - modifyAiSetting(target, effect, ESM::MagicEffect::RallyCreature, CreatureStats::AI_Flee, effect.mMagnitude, invalid); + modifyAiSetting(target, effect, ESM::MagicEffect::RallyCreature, AiSetting::Flee, effect.mMagnitude, invalid); break; case ESM::MagicEffect::SummonScamp: case ESM::MagicEffect::SummonClannfear: diff --git a/apps/openmw/mwmechanics/weapontype.cpp b/apps/openmw/mwmechanics/weapontype.cpp index 30f554f80b..6bf5b70fee 100644 --- a/apps/openmw/mwmechanics/weapontype.cpp +++ b/apps/openmw/mwmechanics/weapontype.cpp @@ -1,5 +1,8 @@ #include "weapontype.hpp" +#include "drawstate.hpp" +#include "creaturestats.hpp" + #include "../mwworld/class.hpp" namespace MWMechanics diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index 7497fd15f7..297f40c6a7 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -16,7 +16,10 @@ #include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/movement.hpp" +#include "../mwmechanics/creaturestats.hpp" + #include "../mwrender/bulletdebugdraw.hpp" + #include "../mwworld/class.hpp" #include "../mwbase/environment.hpp" diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index 373a29bc1a..f370f17e1c 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -31,6 +31,8 @@ #include "../mwworld/esmstore.hpp" #include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/weapontype.hpp" +#include "../mwmechanics/drawstate.hpp" +#include "../mwmechanics/creaturestats.hpp" #include "vismask.hpp" diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index 519af584f0..47cddee083 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -255,9 +255,9 @@ namespace MWScript template class OpGetAiSetting : public Interpreter::Opcode0 { - MWMechanics::CreatureStats::AiSetting mIndex; + MWMechanics::AiSetting mIndex; public: - OpGetAiSetting(MWMechanics::CreatureStats::AiSetting index) : mIndex(index) {} + OpGetAiSetting(MWMechanics::AiSetting index) : mIndex(index) {} void execute (Interpreter::Runtime& runtime) override { @@ -272,9 +272,9 @@ namespace MWScript template class OpModAiSetting : public Interpreter::Opcode0 { - MWMechanics::CreatureStats::AiSetting mIndex; + MWMechanics::AiSetting mIndex; public: - OpModAiSetting(MWMechanics::CreatureStats::AiSetting index) : mIndex(index) {} + OpModAiSetting(MWMechanics::AiSetting index) : mIndex(index) {} void execute (Interpreter::Runtime& runtime) override { @@ -294,9 +294,9 @@ namespace MWScript template class OpSetAiSetting : public Interpreter::Opcode0 { - MWMechanics::CreatureStats::AiSetting mIndex; + MWMechanics::AiSetting mIndex; public: - OpSetAiSetting(MWMechanics::CreatureStats::AiSetting index) : mIndex(index) {} + OpSetAiSetting(MWMechanics::AiSetting index) : mIndex(index) {} void execute (Interpreter::Runtime& runtime) override { @@ -586,32 +586,32 @@ namespace MWScript interpreter.installSegment5>(Compiler::Ai::opcodeStopCombatExplicit); interpreter.installSegment5(Compiler::Ai::opcodeToggleAI); - interpreter.installSegment5>(Compiler::Ai::opcodeSetHello, MWMechanics::CreatureStats::AiSetting::AI_Hello); - interpreter.installSegment5>(Compiler::Ai::opcodeSetHelloExplicit, MWMechanics::CreatureStats::AiSetting::AI_Hello); - interpreter.installSegment5>(Compiler::Ai::opcodeSetFight, MWMechanics::CreatureStats::AiSetting::AI_Fight); - interpreter.installSegment5>(Compiler::Ai::opcodeSetFightExplicit, MWMechanics::CreatureStats::AiSetting::AI_Fight); - interpreter.installSegment5>(Compiler::Ai::opcodeSetFlee, MWMechanics::CreatureStats::AiSetting::AI_Flee); - interpreter.installSegment5>(Compiler::Ai::opcodeSetFleeExplicit, MWMechanics::CreatureStats::AiSetting::AI_Flee); - interpreter.installSegment5>(Compiler::Ai::opcodeSetAlarm, MWMechanics::CreatureStats::AiSetting::AI_Alarm); - interpreter.installSegment5>(Compiler::Ai::opcodeSetAlarmExplicit, MWMechanics::CreatureStats::AiSetting::AI_Alarm); + interpreter.installSegment5>(Compiler::Ai::opcodeSetHello, MWMechanics::AiSetting::Hello); + interpreter.installSegment5>(Compiler::Ai::opcodeSetHelloExplicit, MWMechanics::AiSetting::Hello); + interpreter.installSegment5>(Compiler::Ai::opcodeSetFight, MWMechanics::AiSetting::Fight); + interpreter.installSegment5>(Compiler::Ai::opcodeSetFightExplicit, MWMechanics::AiSetting::Fight); + interpreter.installSegment5>(Compiler::Ai::opcodeSetFlee, MWMechanics::AiSetting::Flee); + interpreter.installSegment5>(Compiler::Ai::opcodeSetFleeExplicit, MWMechanics::AiSetting::Flee); + interpreter.installSegment5>(Compiler::Ai::opcodeSetAlarm, MWMechanics::AiSetting::Alarm); + interpreter.installSegment5>(Compiler::Ai::opcodeSetAlarmExplicit, MWMechanics::AiSetting::Alarm); - interpreter.installSegment5>(Compiler::Ai::opcodeModHello, MWMechanics::CreatureStats::AiSetting::AI_Hello); - interpreter.installSegment5>(Compiler::Ai::opcodeModHelloExplicit, MWMechanics::CreatureStats::AiSetting::AI_Hello); - interpreter.installSegment5>(Compiler::Ai::opcodeModFight, MWMechanics::CreatureStats::AiSetting::AI_Fight); - interpreter.installSegment5>(Compiler::Ai::opcodeModFightExplicit, MWMechanics::CreatureStats::AiSetting::AI_Fight); - interpreter.installSegment5>(Compiler::Ai::opcodeModFlee, MWMechanics::CreatureStats::AiSetting::AI_Flee); - interpreter.installSegment5>(Compiler::Ai::opcodeModFleeExplicit, MWMechanics::CreatureStats::AiSetting::AI_Flee); - interpreter.installSegment5>(Compiler::Ai::opcodeModAlarm, MWMechanics::CreatureStats::AiSetting::AI_Alarm); - interpreter.installSegment5>(Compiler::Ai::opcodeModAlarmExplicit, MWMechanics::CreatureStats::AiSetting::AI_Alarm); + interpreter.installSegment5>(Compiler::Ai::opcodeModHello, MWMechanics::AiSetting::Hello); + interpreter.installSegment5>(Compiler::Ai::opcodeModHelloExplicit, MWMechanics::AiSetting::Hello); + interpreter.installSegment5>(Compiler::Ai::opcodeModFight, MWMechanics::AiSetting::Fight); + interpreter.installSegment5>(Compiler::Ai::opcodeModFightExplicit, MWMechanics::AiSetting::Fight); + interpreter.installSegment5>(Compiler::Ai::opcodeModFlee, MWMechanics::AiSetting::Flee); + interpreter.installSegment5>(Compiler::Ai::opcodeModFleeExplicit, MWMechanics::AiSetting::Flee); + interpreter.installSegment5>(Compiler::Ai::opcodeModAlarm, MWMechanics::AiSetting::Alarm); + interpreter.installSegment5>(Compiler::Ai::opcodeModAlarmExplicit, MWMechanics::AiSetting::Alarm); - interpreter.installSegment5>(Compiler::Ai::opcodeGetHello, MWMechanics::CreatureStats::AiSetting::AI_Hello); - interpreter.installSegment5>(Compiler::Ai::opcodeGetHelloExplicit, MWMechanics::CreatureStats::AiSetting::AI_Hello); - interpreter.installSegment5>(Compiler::Ai::opcodeGetFight, MWMechanics::CreatureStats::AiSetting::AI_Fight); - interpreter.installSegment5>(Compiler::Ai::opcodeGetFightExplicit, MWMechanics::CreatureStats::AiSetting::AI_Fight); - interpreter.installSegment5>(Compiler::Ai::opcodeGetFlee, MWMechanics::CreatureStats::AiSetting::AI_Flee); - interpreter.installSegment5>(Compiler::Ai::opcodeGetFleeExplicit, MWMechanics::CreatureStats::AiSetting::AI_Flee); - interpreter.installSegment5>(Compiler::Ai::opcodeGetAlarm, MWMechanics::CreatureStats::AiSetting::AI_Alarm); - interpreter.installSegment5>(Compiler::Ai::opcodeGetAlarmExplicit, MWMechanics::CreatureStats::AiSetting::AI_Alarm); + interpreter.installSegment5>(Compiler::Ai::opcodeGetHello, MWMechanics::AiSetting::Hello); + interpreter.installSegment5>(Compiler::Ai::opcodeGetHelloExplicit, MWMechanics::AiSetting::Hello); + interpreter.installSegment5>(Compiler::Ai::opcodeGetFight, MWMechanics::AiSetting::Fight); + interpreter.installSegment5>(Compiler::Ai::opcodeGetFightExplicit, MWMechanics::AiSetting::Fight); + interpreter.installSegment5>(Compiler::Ai::opcodeGetFlee, MWMechanics::AiSetting::Flee); + interpreter.installSegment5>(Compiler::Ai::opcodeGetFleeExplicit, MWMechanics::AiSetting::Flee); + interpreter.installSegment5>(Compiler::Ai::opcodeGetAlarm, MWMechanics::AiSetting::Alarm); + interpreter.installSegment5>(Compiler::Ai::opcodeGetAlarmExplicit, MWMechanics::AiSetting::Alarm); interpreter.installSegment5>(Compiler::Ai::opcodeFace); interpreter.installSegment5>(Compiler::Ai::opcodeFaceExplicit); diff --git a/apps/openmw/mwscript/controlextensions.cpp b/apps/openmw/mwscript/controlextensions.cpp index 74d2067394..d216474c6d 100644 --- a/apps/openmw/mwscript/controlextensions.cpp +++ b/apps/openmw/mwscript/controlextensions.cpp @@ -14,6 +14,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/ptr.hpp" +#include "../mwmechanics/creaturestats.hpp" + #include "interpretercontext.hpp" #include "ref.hpp" diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index f9b5c53ebd..d43c4bbba1 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -521,7 +521,7 @@ namespace MWWorld return result; } - void Class::setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) const + void Class::setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const { throw std::runtime_error ("class does not have creature stats"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 8b62d21064..f1f4c46df0 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -11,7 +11,8 @@ #include "ptr.hpp" #include "doorstate.hpp" -#include "../mwmechanics/creaturestats.hpp" + +#include "../mwmechanics/aisetting.hpp" namespace ESM { @@ -32,6 +33,7 @@ namespace MWMechanics { class NpcStats; struct Movement; + class CreatureStats; } namespace MWGui @@ -361,7 +363,7 @@ namespace MWWorld virtual osg::Vec4f getEnchantmentColor(const MWWorld::ConstPtr& item) const; - virtual void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value) const; + virtual void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const; virtual void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const; };