From 82893c30f41a40226c83c86c3c649ad5874f1093 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 16 May 2020 21:52:16 +0200 Subject: [PATCH] Store package type id as enum except ESM --- apps/openmw/mwmechanics/actors.cpp | 22 +++---- apps/openmw/mwmechanics/aiactivate.hpp | 2 +- apps/openmw/mwmechanics/aiavoiddoor.cpp | 2 +- apps/openmw/mwmechanics/aiavoiddoor.hpp | 2 +- apps/openmw/mwmechanics/aibreathe.hpp | 2 +- apps/openmw/mwmechanics/aicast.hpp | 2 +- apps/openmw/mwmechanics/aicombat.hpp | 2 +- apps/openmw/mwmechanics/aiescort.hpp | 2 +- apps/openmw/mwmechanics/aiface.hpp | 2 +- apps/openmw/mwmechanics/aifollow.hpp | 2 +- apps/openmw/mwmechanics/aipackage.cpp | 8 +-- apps/openmw/mwmechanics/aipackage.hpp | 27 ++------ apps/openmw/mwmechanics/aipackagetypeid.hpp | 28 ++++++++ apps/openmw/mwmechanics/aipursue.hpp | 2 +- apps/openmw/mwmechanics/aisequence.cpp | 65 ++++++++++--------- apps/openmw/mwmechanics/aisequence.hpp | 13 ++-- apps/openmw/mwmechanics/aitravel.hpp | 4 +- apps/openmw/mwmechanics/aiwander.hpp | 2 +- .../mwmechanics/mechanicsmanagerimp.cpp | 14 ++-- apps/openmw/mwscript/aiextensions.cpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 4 +- 21 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 apps/openmw/mwmechanics/aipackagetypeid.hpp diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index aa5aac80a..b82d08964 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -115,7 +115,7 @@ void adjustCommandedActor (const MWWorld::Ptr& actor) auto it = stats.getAiSequence().begin(); for (; it != stats.getAiSequence().end(); ++it) { - if ((*it)->getTypeId() == MWMechanics::AiPackage::TypeIdFollow && + if ((*it)->getTypeId() == MWMechanics::AiPackageTypeId::Follow && static_cast(it->get())->isCommanded()) { hasCommandPackage = true; @@ -453,7 +453,7 @@ namespace MWMechanics return; const MWMechanics::AiSequence& seq = stats.getAiSequence(); - if (seq.isInCombat() || seq.hasPackage(AiPackage::TypeIdFollow) || seq.hasPackage(AiPackage::TypeIdEscort)) + if (seq.isInCombat() || seq.hasPackage(AiPackageTypeId::Follow) || seq.hasPackage(AiPackageTypeId::Escort)) return; const osg::Vec3f playerPos(getPlayer().getRefData().getPosition().asVec3()); @@ -497,11 +497,11 @@ namespace MWMechanics CreatureStats &stats = actor.getClass().getCreatureStats(actor); const MWMechanics::AiSequence& seq = stats.getAiSequence(); - int packageId = seq.getTypeId(); + const auto packageId = seq.getTypeId(); if (seq.isInCombat() || MWBase::Environment::get().getWorld()->isSwimming(actor) || - (packageId != AiPackage::TypeIdWander && packageId != AiPackage::TypeIdTravel && packageId != -1)) + (packageId != AiPackageTypeId::Wander && packageId != AiPackageTypeId::Travel && packageId != AiPackageTypeId::None)) { actorState.setTurningToPlayer(false); actorState.setGreetingTimer(0); @@ -724,7 +724,7 @@ namespace MWMechanics followerOrEscorter = true; break; } - else if (package->getTypeId() != MWMechanics::AiPackage::TypeIdCombat) + else if (package->getTypeId() != MWMechanics::AiPackageTypeId::Combat) break; } if (!followerOrEscorter) @@ -1259,7 +1259,7 @@ namespace MWMechanics if (!isPlayer && stats.getTimeToStartDrowning() < fHoldBreathTime / 2) { AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence(); - if (seq.getTypeId() != AiPackage::TypeIdBreathe) //Only add it once + if (seq.getTypeId() != AiPackageTypeId::Breathe) //Only add it once seq.stack(AiBreathe(), ptr); } @@ -1410,7 +1410,7 @@ namespace MWMechanics if (player.getClass().getNpcStats(player).isWerewolf()) return; - if (ptr.getClass().isClass(ptr, "Guard") && creatureStats.getAiSequence().getTypeId() != AiPackage::TypeIdPursue && !creatureStats.getAiSequence().isInCombat() + if (ptr.getClass().isClass(ptr, "Guard") && creatureStats.getAiSequence().getTypeId() != AiPackageTypeId::Pursue && !creatureStats.getAiSequence().isInCombat() && creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid).getMagnitude() == 0) { const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); @@ -1773,7 +1773,7 @@ namespace MWMechanics // 3. Player character does not use headtracking in the 1st-person view if (!stats.getKnockedDown() && !stats.getAiSequence().isInCombat() && - !stats.getAiSequence().hasPackage(AiPackage::TypeIdPursue) && + !stats.getAiSequence().hasPackage(AiPackageTypeId::Pursue) && !firstPersonPlayer) { for(PtrActorMap::iterator it(mActors.begin()); it != mActors.end(); ++it) @@ -2276,7 +2276,7 @@ namespace MWMechanics } break; } - else if (package->getTypeId() != AiPackage::TypeIdCombat && package->getTypeId() != AiPackage::TypeIdWander) + else if (package->getTypeId() != AiPackageTypeId::Combat && package->getTypeId() != AiPackageTypeId::Wander) break; } } @@ -2302,7 +2302,7 @@ namespace MWMechanics { if (package->followTargetThroughDoors() && package->getTarget() == actor) list.push_back(iteratedActor); - else if (package->getTypeId() != AiPackage::TypeIdCombat && package->getTypeId() != AiPackage::TypeIdWander) + else if (package->getTypeId() != AiPackageTypeId::Combat && package->getTypeId() != AiPackageTypeId::Wander) break; } } @@ -2368,7 +2368,7 @@ namespace MWMechanics list.push_back(static_cast(package.get())->getFollowIndex()); break; } - else if (package->getTypeId() != AiPackage::TypeIdCombat && package->getTypeId() != AiPackage::TypeIdWander) + else if (package->getTypeId() != AiPackageTypeId::Combat && package->getTypeId() != AiPackageTypeId::Wander) break; } } diff --git a/apps/openmw/mwmechanics/aiactivate.hpp b/apps/openmw/mwmechanics/aiactivate.hpp index b263e74a6..c53744e88 100644 --- a/apps/openmw/mwmechanics/aiactivate.hpp +++ b/apps/openmw/mwmechanics/aiactivate.hpp @@ -30,7 +30,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdActivate; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Activate; } void writeState(ESM::AiSequence::AiSequence& sequence) const final; diff --git a/apps/openmw/mwmechanics/aiavoiddoor.cpp b/apps/openmw/mwmechanics/aiavoiddoor.cpp index d8517c5c9..47f72efce 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.cpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.cpp @@ -63,7 +63,7 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor, CharacterCont for(std::vector::iterator it = actors.begin(); it != actors.end(); ++it) { if(*it != getPlayer()) { //Not the player MWMechanics::AiSequence& seq = it->getClass().getCreatureStats(*it).getAiSequence(); - if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdAvoidDoor) { //Only add it once + if(seq.getTypeId() != MWMechanics::AiPackageTypeId::AvoidDoor) { //Only add it once seq.stack(MWMechanics::AiAvoidDoor(mDoorPtr),*it); } } diff --git a/apps/openmw/mwmechanics/aiavoiddoor.hpp b/apps/openmw/mwmechanics/aiavoiddoor.hpp index 72cde1026..cd0718e2e 100644 --- a/apps/openmw/mwmechanics/aiavoiddoor.hpp +++ b/apps/openmw/mwmechanics/aiavoiddoor.hpp @@ -24,7 +24,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdAvoidDoor; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::AvoidDoor; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/aibreathe.hpp b/apps/openmw/mwmechanics/aibreathe.hpp index 2a04ab2ad..7e9ac69da 100644 --- a/apps/openmw/mwmechanics/aibreathe.hpp +++ b/apps/openmw/mwmechanics/aibreathe.hpp @@ -12,7 +12,7 @@ namespace MWMechanics public: bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdBreathe; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Breathe; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/aicast.hpp b/apps/openmw/mwmechanics/aicast.hpp index 22575c7bc..1175dccd2 100644 --- a/apps/openmw/mwmechanics/aicast.hpp +++ b/apps/openmw/mwmechanics/aicast.hpp @@ -17,7 +17,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdCast; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Cast; } MWWorld::Ptr getTarget() const final; diff --git a/apps/openmw/mwmechanics/aicombat.hpp b/apps/openmw/mwmechanics/aicombat.hpp index ef8782ae1..ff8a0e081 100644 --- a/apps/openmw/mwmechanics/aicombat.hpp +++ b/apps/openmw/mwmechanics/aicombat.hpp @@ -104,7 +104,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdCombat; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Combat; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/aiescort.hpp b/apps/openmw/mwmechanics/aiescort.hpp index 42558bf7c..edfd0ca3f 100644 --- a/apps/openmw/mwmechanics/aiescort.hpp +++ b/apps/openmw/mwmechanics/aiescort.hpp @@ -32,7 +32,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdEscort; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Escort; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/aiface.hpp b/apps/openmw/mwmechanics/aiface.hpp index 3a9a482c0..a5ee67a14 100644 --- a/apps/openmw/mwmechanics/aiface.hpp +++ b/apps/openmw/mwmechanics/aiface.hpp @@ -12,7 +12,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdFace; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Face; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/aifollow.hpp b/apps/openmw/mwmechanics/aifollow.hpp index b4cf88be8..d0c2cec97 100644 --- a/apps/openmw/mwmechanics/aifollow.hpp +++ b/apps/openmw/mwmechanics/aifollow.hpp @@ -55,7 +55,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdFollow; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Follow; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index 66b41db54..01440ca93 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -24,7 +24,7 @@ #include -MWMechanics::AiPackage::AiPackage(TypeId typeId, const Options& options) : +MWMechanics::AiPackage::AiPackage(AiPackageTypeId typeId, const Options& options) : mTypeId(typeId), mOptions(options), mTimer(AI_REACTION_TIME + 1.0f), // to force initial pathbuild @@ -216,7 +216,7 @@ namespace void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor) { // note: AiWander currently does not open doors - if (getTypeId() == TypeIdWander) + if (getTypeId() == AiPackageTypeId::Wander) return; if (mPathFinder.getPathSize() == 0) @@ -391,13 +391,13 @@ DetourNavigator::Flags MWMechanics::AiPackage::getNavigatorFlags(const MWWorld:: const MWWorld::Class& actorClass = actor.getClass(); DetourNavigator::Flags result = DetourNavigator::Flag_none; - if (actorClass.isPureWaterCreature(actor) || (getTypeId() != TypeIdWander && actorClass.canSwim(actor))) + if (actorClass.isPureWaterCreature(actor) || (getTypeId() != AiPackageTypeId::Wander && actorClass.canSwim(actor))) result |= DetourNavigator::Flag_swim; if (actorClass.canWalk(actor)) result |= DetourNavigator::Flag_walk; - if (actorClass.isBipedal(actor) && getTypeId() != TypeIdWander) + if (actorClass.isBipedal(actor) && getTypeId() != AiPackageTypeId::Wander) result |= DetourNavigator::Flag_openDoor; return result; diff --git a/apps/openmw/mwmechanics/aipackage.hpp b/apps/openmw/mwmechanics/aipackage.hpp index c32fb93aa..3078e31fc 100644 --- a/apps/openmw/mwmechanics/aipackage.hpp +++ b/apps/openmw/mwmechanics/aipackage.hpp @@ -8,6 +8,7 @@ #include "pathfinding.hpp" #include "obstacle.hpp" #include "aistate.hpp" +#include "aipackagetypeid.hpp" namespace MWWorld { @@ -35,26 +36,6 @@ namespace MWMechanics class AiPackage { public: - ///Enumerates the various AITypes available - enum TypeId { - TypeIdNone = -1, - TypeIdWander = 0, - TypeIdTravel = 1, - TypeIdEscort = 2, - TypeIdFollow = 3, - TypeIdActivate = 4, - - // These 5 are not really handled as Ai Packages in the MW engine - // For compatibility do *not* return these in the getCurrentAiPackage script function.. - TypeIdCombat = 5, - TypeIdPursue = 6, - TypeIdAvoidDoor = 7, - TypeIdFace = 8, - TypeIdBreathe = 9, - TypeIdInternalTravel = 10, - TypeIdCast = 11 - }; - struct Options { unsigned int mPriority = 0; @@ -79,7 +60,7 @@ namespace MWMechanics } }; - AiPackage(TypeId typeId, const Options& options); + AiPackage(AiPackageTypeId typeId, const Options& options); virtual ~AiPackage() = default; @@ -97,7 +78,7 @@ namespace MWMechanics /// Returns the TypeID of the AiPackage /// \see enum TypeId - TypeId getTypeId() const { return mTypeId; } + AiPackageTypeId getTypeId() const { return mTypeId; } /// Higher number is higher priority (0 being the lowest) unsigned int getPriority() const { return mOptions.mPriority; } @@ -167,7 +148,7 @@ namespace MWMechanics DetourNavigator::Flags getNavigatorFlags(const MWWorld::Ptr& actor) const; - const TypeId mTypeId; + const AiPackageTypeId mTypeId; const Options mOptions; // TODO: all this does not belong here, move into temporary storage diff --git a/apps/openmw/mwmechanics/aipackagetypeid.hpp b/apps/openmw/mwmechanics/aipackagetypeid.hpp new file mode 100644 index 000000000..2b9c4fe9c --- /dev/null +++ b/apps/openmw/mwmechanics/aipackagetypeid.hpp @@ -0,0 +1,28 @@ +#ifndef GAME_MWMECHANICS_AIPACKAGETYPEID_H +#define GAME_MWMECHANICS_AIPACKAGETYPEID_H + +namespace MWMechanics +{ + ///Enumerates the various AITypes available + enum class AiPackageTypeId + { + None = -1, + Wander = 0, + Travel = 1, + Escort = 2, + Follow = 3, + Activate = 4, + + // These 5 are not really handled as Ai Packages in the MW engine + // For compatibility do *not* return these in the getCurrentAiPackage script function.. + Combat = 5, + Pursue = 6, + AvoidDoor = 7, + Face = 8, + Breathe = 9, + InternalTravel = 10, + Cast = 11 + }; +} + +#endif diff --git a/apps/openmw/mwmechanics/aipursue.hpp b/apps/openmw/mwmechanics/aipursue.hpp index 6031f84fb..64465f530 100644 --- a/apps/openmw/mwmechanics/aipursue.hpp +++ b/apps/openmw/mwmechanics/aipursue.hpp @@ -28,7 +28,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdPursue; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Pursue; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 4a23dc788..f747b16f2 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -33,7 +33,7 @@ void AiSequence::copy (const AiSequence& sequence) sequence.mAiState.copy(mAiState); } -AiSequence::AiSequence() : mDone (false), mRepeat(false), mLastAiPackage(-1) {} +AiSequence::AiSequence() : mDone (false), mRepeat(false), mLastAiPackage(AiPackageTypeId::None) {} AiSequence::AiSequence (const AiSequence& sequence) { @@ -61,17 +61,17 @@ AiSequence::~AiSequence() clear(); } -int AiSequence::getTypeId() const +AiPackageTypeId AiSequence::getTypeId() const { if (mPackages.empty()) - return -1; + return AiPackageTypeId::None; return mPackages.front()->getTypeId(); } bool AiSequence::getCombatTarget(MWWorld::Ptr &targetActor) const { - if (getTypeId() != AiPackage::TypeIdCombat) + if (getTypeId() != AiPackageTypeId::Combat) return false; targetActor = mPackages.front()->getTarget(); @@ -83,7 +83,7 @@ bool AiSequence::getCombatTargets(std::vector &targetActors) const { for (auto it = mPackages.begin(); it != mPackages.end(); ++it) { - if ((*it)->getTypeId() == MWMechanics::AiPackage::TypeIdCombat) + if ((*it)->getTypeId() == MWMechanics::AiPackageTypeId::Combat) targetActors.push_back((*it)->getTarget()); } @@ -118,7 +118,7 @@ bool AiSequence::isInCombat() const { for (auto it = mPackages.begin(); it != mPackages.end(); ++it) { - if ((*it)->getTypeId() == AiPackage::TypeIdCombat) + if ((*it)->getTypeId() == AiPackageTypeId::Combat) return true; } return false; @@ -128,7 +128,7 @@ bool AiSequence::isEngagedWithActor() const { for (auto it = mPackages.begin(); it != mPackages.end(); ++it) { - if ((*it)->getTypeId() == AiPackage::TypeIdCombat) + if ((*it)->getTypeId() == AiPackageTypeId::Combat) { MWWorld::Ptr target2 = (*it)->getTarget(); if (!target2.isEmpty() && target2.getClass().isNpc()) @@ -138,7 +138,7 @@ bool AiSequence::isEngagedWithActor() const return false; } -bool AiSequence::hasPackage(int typeId) const +bool AiSequence::hasPackage(AiPackageTypeId typeId) const { for (auto it = mPackages.begin(); it != mPackages.end(); ++it) { @@ -152,7 +152,7 @@ bool AiSequence::isInCombat(const MWWorld::Ptr &actor) const { for (auto it = mPackages.begin(); it != mPackages.end(); ++it) { - if ((*it)->getTypeId() == AiPackage::TypeIdCombat) + if ((*it)->getTypeId() == AiPackageTypeId::Combat) { if ((*it)->getTarget() == actor) return true; @@ -165,7 +165,7 @@ void AiSequence::stopCombat() { for(auto it = mPackages.begin(); it != mPackages.end(); ) { - if ((*it)->getTypeId() == AiPackage::TypeIdCombat) + if ((*it)->getTypeId() == AiPackageTypeId::Combat) { it = mPackages.erase(it); } @@ -178,7 +178,7 @@ void AiSequence::stopPursuit() { for(auto it = mPackages.begin(); it != mPackages.end(); ) { - if ((*it)->getTypeId() == AiPackage::TypeIdPursue) + if ((*it)->getTypeId() == AiPackageTypeId::Pursue) { it = mPackages.erase(it); } @@ -192,10 +192,13 @@ bool AiSequence::isPackageDone() const return mDone; } -bool isActualAiPackage(int packageTypeId) +namespace { - return (packageTypeId >= AiPackage::TypeIdWander && - packageTypeId <= AiPackage::TypeIdActivate); + bool isActualAiPackage(AiPackageTypeId packageTypeId) + { + return (packageTypeId >= AiPackageTypeId::Wander && + packageTypeId <= AiPackageTypeId::Activate); + } } void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& characterController, float duration, bool outOfRange) @@ -204,7 +207,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac { if (mPackages.empty()) { - mLastAiPackage = -1; + mLastAiPackage = AiPackageTypeId::None; return; } @@ -213,12 +216,12 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac if (!package->alwaysActive() && outOfRange) return; - int packageTypeId = package->getTypeId(); + auto packageTypeId = package->getTypeId(); // workaround ai packages not being handled as in the vanilla engine if (isActualAiPackage(packageTypeId)) mLastAiPackage = packageTypeId; // if active package is combat one, choose nearest target - if (packageTypeId == AiPackage::TypeIdCombat) + if (packageTypeId == AiPackageTypeId::Combat) { auto itActualCombat = mPackages.end(); @@ -229,7 +232,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac for (auto it = mPackages.begin(); it != mPackages.end();) { - if ((*it)->getTypeId() != AiPackage::TypeIdCombat) break; + if ((*it)->getTypeId() != AiPackageTypeId::Combat) break; MWWorld::Ptr target = (*it)->getTarget(); @@ -320,16 +323,16 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor, boo // We should return a wandering actor back after combat, casting or pursuit. // The same thing for actors without AI packages. // Also there is no point to stack return packages. - int currentTypeId = getTypeId(); - int newTypeId = package.getTypeId(); - if (currentTypeId <= MWMechanics::AiPackage::TypeIdWander - && !hasPackage(MWMechanics::AiPackage::TypeIdInternalTravel) - && (newTypeId <= MWMechanics::AiPackage::TypeIdCombat - || newTypeId == MWMechanics::AiPackage::TypeIdPursue - || newTypeId == MWMechanics::AiPackage::TypeIdCast)) + const auto currentTypeId = getTypeId(); + const auto newTypeId = package.getTypeId(); + if (currentTypeId <= MWMechanics::AiPackageTypeId::Wander + && !hasPackage(MWMechanics::AiPackageTypeId::InternalTravel) + && (newTypeId <= MWMechanics::AiPackageTypeId::Combat + || newTypeId == MWMechanics::AiPackageTypeId::Pursue + || newTypeId == MWMechanics::AiPackageTypeId::Cast)) { osg::Vec3f dest; - if (currentTypeId == MWMechanics::AiPackage::TypeIdWander) + if (currentTypeId == MWMechanics::AiPackageTypeId::Wander) { dest = getActivePackage().getDestination(actor); } @@ -361,8 +364,8 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor, boo for (auto it = mPackages.begin(); it != mPackages.end(); ++it) { // We should keep current AiCast package, if we try to add a new one. - if ((*it)->getTypeId() == MWMechanics::AiPackage::TypeIdCast && - package.getTypeId() == MWMechanics::AiPackage::TypeIdCast) + if ((*it)->getTypeId() == MWMechanics::AiPackageTypeId::Cast && + package.getTypeId() == MWMechanics::AiPackageTypeId::Cast) { continue; } @@ -444,7 +447,7 @@ void AiSequence::writeState(ESM::AiSequence::AiSequence &sequence) const for (const auto& package : mPackages) package->writeState(sequence); - sequence.mLastAiPackage = mLastAiPackage; + sequence.mLastAiPackage = static_cast(mLastAiPackage); } void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence) @@ -457,7 +460,7 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence) for (std::vector::const_iterator it = sequence.mPackages.begin(); it != sequence.mPackages.end(); ++it) { - if (isActualAiPackage(it->mType)) + if (isActualAiPackage(static_cast(it->mType))) count++; } @@ -520,7 +523,7 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence) mPackages.push_back(std::move(package)); } - mLastAiPackage = sequence.mLastAiPackage; + mLastAiPackage = static_cast(sequence.mLastAiPackage); } void AiSequence::fastForward(const MWWorld::Ptr& actor) diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index 12b837d87..645524d38 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -5,6 +5,7 @@ #include #include "aistate.hpp" +#include "aipackagetypeid.hpp" #include @@ -49,7 +50,7 @@ namespace MWMechanics void copy (const AiSequence& sequence); /// The type of AI package that ran last - int mLastAiPackage; + AiPackageTypeId mLastAiPackage; AiState mAiState; public: @@ -71,14 +72,14 @@ namespace MWMechanics void erase(std::list>::const_iterator package); /// Returns currently executing AiPackage type - /** \see enum AiPackage::TypeId **/ - int getTypeId() const; + /** \see enum class AiPackageTypeId **/ + AiPackageTypeId getTypeId() const; /// Get the typeid of the Ai package that ran last /** NOT the currently "active" Ai package that will be run in the next frame. This difference is important when an Ai package has just finished and been removed. - \see enum AiPackage::TypeId **/ - int getLastRunTypeId() const { return mLastAiPackage; } + \see enum class AiPackageTypeId **/ + AiPackageTypeId getLastRunTypeId() const { return mLastAiPackage; } /// Return true and assign target if combat package is currently active, return false otherwise bool getCombatTarget (MWWorld::Ptr &targetActor) const; @@ -93,7 +94,7 @@ namespace MWMechanics bool isEngagedWithActor () const; /// Does this AI sequence have the given package type? - bool hasPackage(int typeId) const; + bool hasPackage(AiPackageTypeId typeId) const; /// Are we in combat with this particular actor? bool isInCombat (const MWWorld::Ptr& actor) const; diff --git a/apps/openmw/mwmechanics/aitravel.hpp b/apps/openmw/mwmechanics/aitravel.hpp index 3049801cd..0c19572d2 100644 --- a/apps/openmw/mwmechanics/aitravel.hpp +++ b/apps/openmw/mwmechanics/aitravel.hpp @@ -34,7 +34,7 @@ namespace MWMechanics bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdTravel; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Travel; } static constexpr Options makeDefaultOptions() { @@ -60,7 +60,7 @@ namespace MWMechanics explicit AiInternalTravel(const ESM::AiSequence::AiTravel* travel); - static constexpr TypeId getTypeId() { return TypeIdInternalTravel; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::InternalTravel; } std::unique_ptr clone() const final; }; diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index 8171107d9..4138c3dea 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -93,7 +93,7 @@ namespace MWMechanics bool execute(const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) final; - static constexpr TypeId getTypeId() { return TypeIdWander; } + static constexpr AiPackageTypeId getTypeId() { return AiPackageTypeId::Wander; } static constexpr Options makeDefaultOptions() { diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 5f5e7d13b..4150f18f2 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1277,7 +1277,7 @@ namespace MWMechanics { bool reported = false; if (victim.getClass().isClass(victim, "guard") - && !victim.getClass().getCreatureStats(victim).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + && !victim.getClass().getCreatureStats(victim).getAiSequence().hasPackage(AiPackageTypeId::Pursue)) reported = reportCrime(player, victim, type, std::string(), arg); if (!reported) @@ -1300,7 +1300,7 @@ namespace MWMechanics return false; // Player's followers should not attack player, or try to arrest him - if (actor.getClass().getCreatureStats(actor).getAiSequence().hasPackage(AiPackage::TypeIdFollow)) + if (actor.getClass().getCreatureStats(actor).getAiSequence().hasPackage(AiPackageTypeId::Follow)) { if (playerFollowers.find(actor) != playerFollowers.end()) return false; @@ -1417,7 +1417,7 @@ namespace MWMechanics // once the bounty has been paid. actor.getClass().getNpcStats(actor).setCrimeId(id); - if (!actor.getClass().getCreatureStats(actor).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + if (!actor.getClass().getCreatureStats(actor).getAiSequence().hasPackage(AiPackageTypeId::Pursue)) { actor.getClass().getCreatureStats(actor).getAiSequence().stack(AiPursue(player), actor); } @@ -1495,7 +1495,7 @@ namespace MWMechanics { // Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back. // Note: accidental or collateral damage attacks are ignored. - if (!victim.getClass().getCreatureStats(victim).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + if (!victim.getClass().getCreatureStats(victim).getAiSequence().hasPackage(AiPackageTypeId::Pursue)) startCombat(victim, player); // Set the crime ID, which we will use to calm down participants @@ -1541,7 +1541,7 @@ namespace MWMechanics { // Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back. // Note: accidental or collateral damage attacks are ignored. - if (!target.getClass().getCreatureStats(target).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + if (!target.getClass().getCreatureStats(target).getAiSequence().hasPackage(AiPackageTypeId::Pursue)) { // If an actor has OnPCHitMe declared in his script, his Fight = 0 and the attacker is player, // he will attack the player only if we will force him (e.g. via StartCombat console command) @@ -1566,7 +1566,7 @@ namespace MWMechanics const MWMechanics::AiSequence& seq = target.getClass().getCreatureStats(target).getAiSequence(); return target.getClass().isNpc() && !attacker.isEmpty() && !seq.isInCombat(attacker) && !isAggressive(target, attacker) && !seq.isEngagedWithActor() - && !target.getClass().getCreatureStats(target).getAiSequence().hasPackage(AiPackage::TypeIdPursue); + && !target.getClass().getCreatureStats(target).getAiSequence().hasPackage(AiPackageTypeId::Pursue); } void MechanicsManager::actorKilled(const MWWorld::Ptr &victim, const MWWorld::Ptr &attacker) @@ -1702,7 +1702,7 @@ namespace MWMechanics if (iter->first.getClass().isClass(iter->first, "Guard")) { MWMechanics::AiSequence& aiSeq = iter->first.getClass().getCreatureStats(iter->first).getAiSequence(); - if (aiSeq.getTypeId() == MWMechanics::AiPackage::TypeIdPursue) + if (aiSeq.getTypeId() == MWMechanics::AiPackageTypeId::Pursue) { aiSeq.stopPursuit(); aiSeq.stack(MWMechanics::AiCombat(target), ptr); diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index 2918ffa36..2e426701c 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -362,7 +362,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - Interpreter::Type_Integer value = ptr.getClass().getCreatureStats (ptr).getAiSequence().getLastRunTypeId(); + const auto value = static_cast(ptr.getClass().getCreatureStats (ptr).getAiSequence().getLastRunTypeId()); runtime.push (value); } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c51266bab..7d615c22f 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1559,7 +1559,7 @@ namespace MWWorld if(ptr != getPlayerPtr() ) { MWMechanics::AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence(); - if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdAvoidDoor) //Only add it once + if(seq.getTypeId() != MWMechanics::AiPackageTypeId::AvoidDoor) //Only add it once seq.stack(MWMechanics::AiAvoidDoor(door),ptr); } @@ -2948,7 +2948,7 @@ namespace MWWorld { for (const auto& package : stats.getAiSequence()) { - if (package->getTypeId() == MWMechanics::AiPackage::TypeIdCast) + if (package->getTypeId() == MWMechanics::AiPackageTypeId::Cast) { target = package->getTarget(); break;