diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index f16b99f8eb..c215b46e09 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -163,7 +163,7 @@ void OMW::Engine::executeLocalScripts() MWWorld::LocalScripts& localScripts = mWorld->getLocalScripts(); localScripts.startIteration(); - std::pair script; + std::pair script; while (localScripts.getNext(script)) { MWScript::InterpreterContext interpreterContext(&script.second.getRefData().getLocals(), script.second); diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index 94b85cbe88..d673ad7fb0 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -17,6 +17,7 @@ namespace ESM { class ESMReader; class ESMWriter; + struct RefId; } namespace MWWorld @@ -53,9 +54,9 @@ namespace MWBase virtual bool startDialogue(const MWWorld::Ptr& actor, ResponseCallback* callback) = 0; - virtual bool inJournal(const std::string& topicId, const std::string& infoId) const = 0; + virtual bool inJournal(const ESM::RefId& topicId, const ESM::RefId& infoId) const = 0; - virtual void addTopic(std::string_view topic) = 0; + virtual void addTopic(const ESM::RefId& topic) = 0; virtual void addChoice(std::string_view text, int choice) = 0; virtual const std::vector>& getChoices() const = 0; @@ -64,7 +65,7 @@ namespace MWBase virtual void goodbye() = 0; - virtual void say(const MWWorld::Ptr& actor, const std::string& topic) = 0; + virtual void say(const MWWorld::Ptr& actor, const ESM::RefId& topic) = 0; virtual void keywordSelected(const std::string& keyword, ResponseCallback* callback) = 0; virtual void goodbyeSelected() = 0; @@ -89,7 +90,7 @@ namespace MWBase }; virtual std::list getAvailableTopics() = 0; - virtual int getTopicFlag(const std::string&) const = 0; + virtual int getTopicFlag(const ESM::RefId&) const = 0; virtual bool checkServiceRefused(ResponseCallback* callback, ServiceType service = ServiceType::Any) = 0; @@ -105,12 +106,12 @@ namespace MWBase virtual void readRecord(ESM::ESMReader& reader, uint32_t type) = 0; /// Changes faction1's opinion of faction2 by \a diff. - virtual void modFactionReaction(std::string_view faction1, std::string_view faction2, int diff) = 0; + virtual void modFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2, int diff) = 0; - virtual void setFactionReaction(std::string_view faction1, std::string_view faction2, int absolute) = 0; + virtual void setFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2, int absolute) = 0; /// @return faction1's opinion of faction2 - virtual int getFactionReaction(std::string_view faction1, std::string_view faction2) const = 0; + virtual int getFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2) const = 0; /// Removes the last added topic response for the given actor from the journal virtual void clearInfoActor(const MWWorld::Ptr& actor) const = 0; diff --git a/apps/openmw/mwbase/journal.hpp b/apps/openmw/mwbase/journal.hpp index 9956bcf236..aed5817e98 100644 --- a/apps/openmw/mwbase/journal.hpp +++ b/apps/openmw/mwbase/journal.hpp @@ -37,9 +37,9 @@ namespace MWBase public: typedef std::deque TEntryContainer; typedef TEntryContainer::const_iterator TEntryIter; - typedef std::map TQuestContainer; // topic, quest + typedef std::map TQuestContainer; // topic, quest typedef TQuestContainer::const_iterator TQuestIter; - typedef std::map TTopicContainer; // topic-id, topic-content + typedef std::map TTopicContainer; // topic-id, topic-content typedef TTopicContainer::const_iterator TTopicIter; public: @@ -49,20 +49,20 @@ namespace MWBase virtual ~Journal() {} - virtual void addEntry(const std::string& id, int index, const MWWorld::Ptr& actor) = 0; + virtual void addEntry(const ESM::RefId& id, int index, const MWWorld::Ptr& actor) = 0; ///< Add a journal entry. /// @param actor Used as context for replacing of escape sequences (%name, etc). - virtual void setJournalIndex(const std::string& id, int index) = 0; + virtual void setJournalIndex(const ESM::RefId& id, int index) = 0; ///< Set the journal index without adding an entry. - virtual int getJournalIndex(const std::string& id) const = 0; + virtual int getJournalIndex(const ESM::RefId& id) const = 0; ///< Get the journal index. - virtual void addTopic(const std::string& topicId, const std::string& infoId, const MWWorld::Ptr& actor) = 0; + virtual void addTopic(const ESM::RefId& topicId, const ESM::RefId& infoId, const MWWorld::Ptr& actor) = 0; /// \note topicId must be lowercase - virtual void removeLastAddedTopicResponse(const std::string& topicId, std::string_view actorName) = 0; + virtual void removeLastAddedTopicResponse(const ESM::RefId& topicId, std::string_view actorName) = 0; ///< Removes the last topic response added for the given topicId and actor name. /// \note topicId must be lowercase diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index 8a866a848f..8c4ae278bb 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -21,7 +21,7 @@ namespace osg namespace ESM { struct Class; - + struct RefId; class ESMReader; class ESMWriter; } @@ -69,14 +69,14 @@ namespace MWBase virtual void setPlayerName(const std::string& name) = 0; ///< Set player name. - virtual void setPlayerRace(const std::string& id, bool male, const std::string& head, const std::string& hair) + virtual void setPlayerRace(const ESM::RefId& id, bool male, const ESM::RefId& head, const ESM::RefId& hair) = 0; ///< Set player race. - virtual void setPlayerBirthsign(const std::string& id) = 0; + virtual void setPlayerBirthsign(const ESM::RefId& id) = 0; ///< Set player birthsign. - virtual void setPlayerClass(const std::string& id) = 0; + virtual void setPlayerClass(const ESM::RefId& id) = 0; ///< Set player class to stock class. virtual void setPlayerClass(const ESM::Class& class_) = 0; @@ -98,7 +98,7 @@ namespace MWBase virtual int getDerivedDisposition(const MWWorld::Ptr& ptr, bool clamp = true) = 0; ///< Calculate the diposition of an NPC toward the player. - virtual int countDeaths(const std::string& id) const = 0; + virtual int countDeaths(const ESM::RefId& id) const = 0; ///< Return the number of deaths for actors with the given ID. /// Check if \a observer is potentially aware of \a ptr. Does not do a line of sight check! @@ -128,7 +128,7 @@ namespace MWBase * @return was the crime seen? */ virtual bool commitCrime(const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim, OffenseType type, - const std::string& factionId = "", int arg = 0, bool victimAware = false) + const ESM::RefId& factionId = ESM::RefId::sEmpty, int arg = 0, bool victimAware = false) = 0; /// @return false if the attack was considered a "friendly hit" and forgiven virtual bool actorAttacked(const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker) = 0; @@ -236,7 +236,7 @@ namespace MWBase virtual bool isReadyToBlock(const MWWorld::Ptr& ptr) const = 0; virtual bool isAttackingOrSpell(const MWWorld::Ptr& ptr) const = 0; - virtual void castSpell(const MWWorld::Ptr& ptr, const std::string& spellId, bool manualSpell) = 0; + virtual void castSpell(const MWWorld::Ptr& ptr, const ESM::RefId& spellId, bool manualSpell) = 0; virtual void processChangedSettings(const std::set>& settings) = 0; @@ -255,10 +255,10 @@ namespace MWBase /// List the owners that the player has stolen this item from (the owner can be an NPC or a faction). /// - virtual std::vector> getStolenItemOwners(const std::string& itemid) = 0; + virtual std::vector> getStolenItemOwners(const ESM::RefId& itemid) = 0; /// Has the player stolen this item from the given owner? - virtual bool isItemStolenFrom(const std::string& itemid, const MWWorld::Ptr& ptr) = 0; + virtual bool isItemStolenFrom(const ESM::RefId& itemid, const MWWorld::Ptr& ptr) = 0; virtual bool isBoundItem(const MWWorld::Ptr& item) = 0; virtual bool isAllowedToUse(const MWWorld::Ptr& ptr, const MWWorld::Ptr& target, MWWorld::Ptr& victim) = 0; diff --git a/apps/openmw/mwbase/scriptmanager.hpp b/apps/openmw/mwbase/scriptmanager.hpp index b727de87c2..dfc1a5ff5e 100644 --- a/apps/openmw/mwbase/scriptmanager.hpp +++ b/apps/openmw/mwbase/scriptmanager.hpp @@ -8,6 +8,11 @@ namespace Interpreter class Context; } +namespace ESM +{ + struct RefId; +} + namespace Compiler { class Extensions; @@ -37,10 +42,10 @@ namespace MWBase virtual void clear() = 0; - virtual bool run(std::string_view name, Interpreter::Context& interpreterContext) = 0; + virtual bool run(const ESM::RefId& name, Interpreter::Context& interpreterContext) = 0; ///< Run the script with the given name (compile first, if not compiled yet) - virtual bool compile(std::string_view name) = 0; + virtual bool compile(const ESM::RefId& name) = 0; ///< Compile script with the given namen /// \return Success? @@ -48,7 +53,7 @@ namespace MWBase ///< Compile all scripts /// \return count, success - virtual const Compiler::Locals& getLocals(std::string_view name) = 0; + virtual const Compiler::Locals& getLocals(const ESM::RefId& name) = 0; ///< Return locals for script \a name. virtual MWScript::GlobalScripts& getGlobalScripts() = 0; diff --git a/apps/openmw/mwbase/soundmanager.hpp b/apps/openmw/mwbase/soundmanager.hpp index 4035a89abb..bc539a3c95 100644 --- a/apps/openmw/mwbase/soundmanager.hpp +++ b/apps/openmw/mwbase/soundmanager.hpp @@ -14,6 +14,11 @@ namespace MWWorld class CellStore; } +namespace ESM +{ + struct RefId; +} + namespace MWSound { // Each entry excepts of MaxCount should be used only in one place @@ -146,20 +151,20 @@ namespace MWBase /// returned by \ref playTrack). Only intended to be called by the track /// decoder's read method. - virtual Sound* playSound(std::string_view soundId, float volume, float pitch, Type type = Type::Sfx, + virtual Sound* playSound(const ESM::RefId& soundId, float volume, float pitch, Type type = Type::Sfx, PlayMode mode = PlayMode::Normal, float offset = 0) = 0; ///< Play a sound, independently of 3D-position ///< @param offset Number of seconds into the sound to start playback. - virtual Sound* playSound3D(const MWWorld::ConstPtr& reference, std::string_view soundId, float volume, + virtual Sound* playSound3D(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId, float volume, float pitch, Type type = Type::Sfx, PlayMode mode = PlayMode::Normal, float offset = 0) = 0; ///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless ///< Play_NoTrack is specified. ///< @param offset Number of seconds into the sound to start playback. - virtual Sound* playSound3D(const osg::Vec3f& initialPos, std::string_view soundId, float volume, float pitch, + virtual Sound* playSound3D(const osg::Vec3f& initialPos, const ESM::RefId& soundId, float volume, float pitch, Type type = Type::Sfx, PlayMode mode = PlayMode::Normal, float offset = 0) = 0; ///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using @@ -168,7 +173,7 @@ namespace MWBase virtual void stopSound(Sound* sound) = 0; ///< Stop the given sound from playing - virtual void stopSound3D(const MWWorld::ConstPtr& reference, std::string_view soundId) = 0; + virtual void stopSound3D(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId) = 0; ///< Stop the given object from playing the given sound, virtual void stopSound3D(const MWWorld::ConstPtr& reference) = 0; @@ -177,13 +182,13 @@ namespace MWBase virtual void stopSound(const MWWorld::CellStore* cell) = 0; ///< Stop all sounds for the given cell. - virtual void fadeOutSound3D(const MWWorld::ConstPtr& reference, std::string_view soundId, float duration) = 0; + virtual void fadeOutSound3D(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId, float duration) = 0; ///< Fade out given sound (that is already playing) of given object ///< @param reference Reference to object, whose sound is faded out ///< @param soundId ID of the sound to fade out. ///< @param duration Time until volume reaches 0. - virtual bool getSoundPlaying(const MWWorld::ConstPtr& reference, std::string_view soundId) const = 0; + virtual bool getSoundPlaying(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId) const = 0; ///< Is the given sound currently playing on the given object? /// If you want to check if sound played with playSound is playing, use empty Ptr diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 8b60de6919..2f1de26441 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -14,6 +14,11 @@ #include +namespace ESM +{ + struct RefId; +} + namespace Loading { class Listener; @@ -215,8 +220,8 @@ namespace MWBase /// update activated quick key state (if action executing was delayed for some reason) virtual void updateActivatedQuickKey() = 0; - virtual const std::string& getSelectedSpell() = 0; - virtual void setSelectedSpell(const std::string& spellId, int successChancePercent) = 0; + virtual const ESM::RefId& getSelectedSpell() = 0; + virtual void setSelectedSpell(const ESM::RefId& spellId, int successChancePercent) = 0; virtual void setSelectedEnchantItem(const MWWorld::Ptr& item) = 0; virtual const MWWorld::Ptr& getSelectedEnchantItem() const = 0; virtual void setSelectedWeapon(const MWWorld::Ptr& item) = 0; @@ -268,7 +273,7 @@ namespace MWBase * @param id Identifier for the GMST setting, e.g. "aName" * @param default Default value if the GMST setting cannot be used. */ - virtual std::string_view getGameSettingString(std::string_view id, std::string_view default_) = 0; + virtual std::string_view getGameSettingString(const std::string_view& id, std::string_view default_) = 0; virtual void processChangedSettings(const std::set>& changed) = 0; @@ -345,7 +350,7 @@ namespace MWBase /// Cycle to next or previous weapon virtual void cycleWeapon(bool next) = 0; - virtual void playSound(std::string_view soundId, float volume = 1.f, float pitch = 1.f) = 0; + virtual void playSound(const ESM::RefId& soundId, float volume = 1.f, float pitch = 1.f) = 0; virtual void addCell(MWWorld::CellStore* cell) = 0; virtual void removeCell(MWWorld::CellStore* cell) = 0; diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 15484fc262..b260b1acbc 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -56,6 +56,7 @@ namespace ESM struct CreatureLevList; struct ItemLevList; struct TimeStamp; + struct RefId; } namespace MWPhysics @@ -176,28 +177,28 @@ namespace MWBase virtual char getGlobalVariableType(std::string_view name) const = 0; ///< Return ' ', if there is no global variable with this name. - virtual std::string_view getCellName(const MWWorld::CellStore* cell = nullptr) const = 0; + virtual const std::string& getCellName(const MWWorld::CellStore* cell = nullptr) const = 0; ///< Return name of the cell. /// /// \note If cell==0, the cell the player is currently in will be used instead to /// generate a name. - virtual std::string_view getCellName(const ESM::Cell* cell) const = 0; + virtual const std::string& getCellName(const ESM::Cell* cell) const = 0; virtual void removeRefScript(MWWorld::RefData* ref) = 0; //< Remove the script attached to ref from mLocalScripts - virtual MWWorld::Ptr getPtr(std::string_view name, bool activeOnly) = 0; + virtual MWWorld::Ptr getPtr(const ESM::RefId& name, bool activeOnly) = 0; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells. - virtual MWWorld::Ptr searchPtr(std::string_view name, bool activeOnly, bool searchInContainers = true) = 0; + virtual MWWorld::Ptr searchPtr(const ESM::RefId& name, bool activeOnly, bool searchInContainers = true) = 0; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells. virtual MWWorld::Ptr searchPtrViaActorId(int actorId) = 0; ///< Search is limited to the active cells. - virtual MWWorld::Ptr searchPtrViaRefNum(const std::string& id, const ESM::RefNum& refNum) = 0; + virtual MWWorld::Ptr searchPtrViaRefNum(const ESM::RefId& id, const ESM::RefNum& refNum) = 0; virtual MWWorld::Ptr findContainer(const MWWorld::ConstPtr& ptr) = 0; ///< Return a pointer to a liveCellRef which contains \a ptr. @@ -222,7 +223,7 @@ namespace MWBase virtual bool toggleSky() = 0; ///< \return Resulting mode - virtual void changeWeather(std::string_view region, const unsigned int id) = 0; + virtual void changeWeather(const ESM::RefId& region, const unsigned int id) = 0; virtual int getCurrentWeather() const = 0; @@ -238,7 +239,7 @@ namespace MWBase virtual void setMoonColour(bool red) = 0; - virtual void modRegion(std::string_view regionid, const std::vector& chances) = 0; + virtual void modRegion(const ESM::RefId& regionid, const std::vector& chances) = 0; virtual float getTimeScaleFactor() const = 0; @@ -553,7 +554,7 @@ namespace MWBase virtual void castSpell(const MWWorld::Ptr& actor, bool manualSpell = false) = 0; virtual void launchMagicBolt( - const std::string& spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection, int slot) + const ESM::RefId& spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection, int slot) = 0; virtual void launchProjectile(MWWorld::Ptr& actor, MWWorld::Ptr& projectile, const osg::Vec3f& worldPos, const osg::Quat& orient, MWWorld::Ptr& bow, float speed, float attackStrength) @@ -576,7 +577,7 @@ namespace MWBase /// Teleports \a ptr to the closest reference of \a id (e.g. DivineMarker, PrisonMarker, TempleMarker) /// @note id must be lower case - virtual void teleportToClosestMarker(const MWWorld::Ptr& ptr, std::string_view id) = 0; + virtual void teleportToClosestMarker(const MWWorld::Ptr& ptr, const ESM::RefId& id) = 0; enum DetectionType { @@ -600,7 +601,7 @@ namespace MWBase virtual void goToJail() = 0; /// Spawn a random creature from a levelled list next to the player - virtual void spawnRandomCreature(std::string_view creatureList) = 0; + virtual void spawnRandomCreature(const ESM::RefId& creatureList) = 0; /// Spawn a blood effect for \a ptr at \a worldPosition virtual void spawnBloodEffect(const MWWorld::Ptr& ptr, const osg::Vec3f& worldPosition) = 0; @@ -675,7 +676,7 @@ namespace MWBase virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0; - virtual std::vector getAll(const std::string& id) = 0; + virtual std::vector getAll(const ESM::RefId& id) = 0; virtual Misc::Rng::Generator& getPrng() = 0; diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index e12590b63b..a949cf6996 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -84,7 +84,7 @@ namespace MWClass return ref->mBase->mName; } - std::string_view Activator::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Activator::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -109,7 +109,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; @@ -122,7 +122,7 @@ namespace MWClass { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const ESM::Sound* sound = store.get().searchRandom("WolfActivator", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfActivator"), prng); std::unique_ptr action = std::make_unique("#{sWerewolfRefusal}"); if (sound) @@ -140,12 +140,12 @@ namespace MWClass return MWWorld::Ptr(cell.insert(ref), &cell); } - std::string_view Activator::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const + const ESM::RefId& Activator::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const { const std::string model = getModel(ptr); // Assume it's not empty, since we wouldn't have gotten the soundgen otherwise const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); - std::string_view creatureId; + const ESM::RefId* creatureId = nullptr; const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); for (const ESM::Creature& iter : store.get()) @@ -153,7 +153,7 @@ namespace MWClass if (!iter.mModel.empty() && Misc::StringUtils::ciEqual(model, Misc::ResourceHelpers::correctMeshPath(iter.mModel, vfs))) { - creatureId = !iter.mOriginal.empty() ? iter.mOriginal : iter.mId; + creatureId = !iter.mOriginal.empty() ? &iter.mOriginal : &iter.mId; break; } } @@ -162,14 +162,14 @@ namespace MWClass std::vector fallbacksounds; auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - if (!creatureId.empty()) + if (creatureId && !creatureId->empty()) { std::vector sounds; for (auto sound = store.get().begin(); sound != store.get().end(); ++sound) { if (type == sound->mType && !sound->mCreature.empty() - && (Misc::StringUtils::ciEqual(creatureId, sound->mCreature))) + && (ESM::RefId::ciEqual(*creatureId, sound->mCreature))) sounds.push_back(&*sound); if (type == sound->mType && sound->mCreature.empty()) fallbacksounds.push_back(&*sound); @@ -192,7 +192,7 @@ namespace MWClass return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size(), prng)]->mSound; } - return {}; + return ESM::RefId::sEmpty; } int Activator::getSndGenTypeFromName(std::string_view name) diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index 89478b5e80..7f5f9db5c2 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -35,7 +35,7 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::unique_ptr activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override; @@ -48,7 +48,7 @@ namespace MWClass bool isActivator() const override; - std::string_view getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; + const ESM::RefId& getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; }; } diff --git a/apps/openmw/mwclass/actor.cpp b/apps/openmw/mwclass/actor.cpp index fec405b482..77bfaddf64 100644 --- a/apps/openmw/mwclass/actor.cpp +++ b/apps/openmw/mwclass/actor.cpp @@ -46,13 +46,13 @@ namespace MWClass switch (shield->getClass().getEquipmentSkill(*shield)) { case ESM::Skill::LightArmor: - sndMgr->playSound3D(ptr, "Light Armor Hit", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Light Armor Hit"), 1.0f, 1.0f); break; case ESM::Skill::MediumArmor: - sndMgr->playSound3D(ptr, "Medium Armor Hit", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Medium Armor Hit"), 1.0f, 1.0f); break; case ESM::Skill::HeavyArmor: - sndMgr->playSound3D(ptr, "Heavy Armor Hit", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Heavy Armor Hit"), 1.0f, 1.0f); break; default: return; diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index aab3c2b583..23791f2102 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -45,7 +45,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Apparatus::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -53,7 +53,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Apparatus::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Apparatus::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -67,14 +67,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Apparatus::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Apparatus::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Apparatus Up"; + static const auto sound = ESM::RefId::stringRefId("Item Apparatus Up"); + return sound; } - std::string_view Apparatus::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Apparatus::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Apparatus Down"; + static const auto sound = ESM::RefId::stringRefId("Item Apparatus Down"); + return sound; } const std::string& Apparatus::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -102,7 +104,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index 83036b512d..08e3f57bd2 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -26,7 +26,7 @@ namespace MWClass std::unique_ptr activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override; ///< Generate action for activation - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr int getValue(const MWWorld::ConstPtr& ptr) const override; @@ -35,10 +35,10 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index d118d37cd6..8ec988c52c 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -55,7 +55,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Armor::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -75,7 +75,7 @@ namespace MWClass return ref->mBase->mData.mHealth; } - std::string_view Armor::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Armor::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -176,26 +176,32 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Armor::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Armor::getUpSoundId(const MWWorld::ConstPtr& ptr) const { int es = getEquipmentSkill(ptr); + std::string soundName; if (es == ESM::Skill::LightArmor) - return "Item Armor Light Up"; + soundName = "Item Armor Light Up"; else if (es == ESM::Skill::MediumArmor) - return "Item Armor Medium Up"; + soundName = "Item Armor Medium Up"; else - return "Item Armor Heavy Up"; + soundName = "Item Armor Heavy Up"; + static const ESM::RefId id = ESM::RefId::stringRefId(soundName); + return id; } - std::string_view Armor::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Armor::getDownSoundId(const MWWorld::ConstPtr& ptr) const { int es = getEquipmentSkill(ptr); + std::string soundName; if (es == ESM::Skill::LightArmor) - return "Item Armor Light Down"; + soundName = "Item Armor Light Down"; else if (es == ESM::Skill::MediumArmor) - return "Item Armor Medium Down"; + soundName = "Item Armor Medium Down"; else - return "Item Armor Heavy Down"; + soundName = "Item Armor Heavy Down"; + static const ESM::RefId id = ESM::RefId::stringRefId(soundName); + return id; } const std::string& Armor::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -253,7 +259,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.enchant = ref->mBase->mEnchant; @@ -265,15 +271,15 @@ namespace MWClass return info; } - std::string_view Armor::getEnchantment(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Armor::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); return ref->mBase->mEnchant; } - const std::string& Armor::applyEnchantment( - const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const ESM::RefId& Armor::applyEnchantment( + const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -317,7 +323,7 @@ namespace MWClass if (npc.getClass().isNpc()) { - const std::string& npcRace = npc.get()->mBase->mRace; + const ESM::RefId& npcRace = npc.get()->mBase->mRace; // Beast races cannot equip shoes / boots, or full helms (head part vs hair part) const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(npcRace); diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 86b06715b1..3639df8ba4 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -32,7 +32,7 @@ namespace MWClass int getItemMaxHealth(const MWWorld::ConstPtr& ptr) const override; ///< Return item max health or throw an exception, if class does not have item health - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::pair, bool> getEquipmentSlots(const MWWorld::ConstPtr& ptr) const override; @@ -49,19 +49,19 @@ namespace MWClass int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, + const ESM::RefId& applyEnchantment(const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 6df4585deb..d64aa748d1 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -51,7 +51,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Book::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -60,7 +60,7 @@ namespace MWClass { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const ESM::Sound* sound = store.get().searchRandom("WolfItem", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfItem"), prng); std::unique_ptr action = std::make_unique("#{sWerewolfRefusal}"); if (sound) @@ -72,7 +72,7 @@ namespace MWClass return std::make_unique(ptr); } - std::string_view Book::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Book::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -86,14 +86,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Book::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Book::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Book Up"; + static auto var = ESM::RefId::stringRefId("Item Book Up"); + return var; } - std::string_view Book::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Book::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Book Down"; + static auto var = ESM::RefId::stringRefId("Item Book Down"); + return var; } const std::string& Book::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -121,7 +123,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.enchant = ref->mBase->mEnchant; @@ -131,15 +133,15 @@ namespace MWClass return info; } - std::string_view Book::getEnchantment(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Book::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); return ref->mBase->mEnchant; } - const std::string& Book::applyEnchantment( - const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const ESM::RefId& Book::applyEnchantment( + const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef* ref = ptr.get(); diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 7b9731c9f5..438ccc3dac 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -24,7 +24,7 @@ namespace MWClass std::unique_ptr activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override; ///< Generate action for activation - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; @@ -33,19 +33,19 @@ namespace MWClass int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, + const ESM::RefId& applyEnchantment(const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 6a4353a5b6..c561db2c59 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -50,7 +50,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Clothing::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -58,7 +58,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Clothing::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Clothing::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -118,26 +118,28 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Clothing::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Clothing::getUpSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); - + static ESM::RefId sound; if (ref->mBase->mData.mType == 8) { - return "Item Ring Up"; + sound = ESM::RefId::stringRefId("Item Ring Up"); } - return "Item Clothes Up"; + sound = ESM::RefId::stringRefId("Item Clothes Up"); + return sound; } - std::string_view Clothing::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Clothing::getDownSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); - + static ESM::RefId sound; if (ref->mBase->mData.mType == 8) { - return "Item Ring Down"; + sound = ESM::RefId::stringRefId("Item Ring Down"); } - return "Item Clothes Down"; + sound = ESM::RefId::stringRefId("Item Clothes Down"); + return sound; } const std::string& Clothing::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -165,7 +167,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.enchant = ref->mBase->mEnchant; @@ -177,15 +179,15 @@ namespace MWClass return info; } - std::string_view Clothing::getEnchantment(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Clothing::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); return ref->mBase->mEnchant; } - const std::string& Clothing::applyEnchantment( - const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const ESM::RefId& Clothing::applyEnchantment( + const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -209,7 +211,7 @@ namespace MWClass if (npc.getClass().isNpc()) { - const std::string& npcRace = npc.get()->mBase->mRace; + const ESM::RefId& npcRace = npc.get()->mBase->mRace; // Beast races cannot equip shoes / boots, or full helms (head part vs hair part) const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(npcRace); diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index bd6875b217..b8781d8795 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -24,7 +24,7 @@ namespace MWClass std::unique_ptr activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override; ///< Generate action for activation - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::pair, bool> getEquipmentSlots(const MWWorld::ConstPtr& ptr) const override; @@ -41,19 +41,19 @@ namespace MWClass int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, + const ESM::RefId& applyEnchantment(const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index cd6805ab6c..207ef634dc 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -42,7 +42,7 @@ namespace MWClass unsigned int seed = Misc::Rng::rollDice(std::numeric_limits::max(), prng); // setting ownership not needed, since taking items from a container inherits the // container's owner automatically - mStore.fillNonRandom(container.mInventory, "", seed); + mStore.fillNonRandom(container.mInventory, ESM::RefId::sEmpty, seed); } ContainerCustomData::ContainerCustomData(const ESM::InventoryState& inventory) @@ -143,7 +143,7 @@ namespace MWClass { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const ESM::Sound* sound = store.get().searchRandom("WolfContainer", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfContainer"), prng); std::unique_ptr action = std::make_unique("#{sWerewolfRefusal}"); if (sound) @@ -152,8 +152,8 @@ namespace MWClass return action; } - const std::string_view lockedSound = "LockedChest"; - const std::string_view trapActivationSound = "Disarm Trap Fail"; + const ESM::RefId& lockedSound = ESM::RefId::stringRefId("LockedChest"); + const ESM::RefId& trapActivationSound = ESM::RefId::stringRefId("Disarm Trap Fail"); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player); @@ -163,7 +163,7 @@ namespace MWClass bool hasKey = false; std::string_view keyName; - const std::string& keyId = ptr.getCellRef().getKey(); + const ESM::RefId& keyId = ptr.getCellRef().getKey(); if (!keyId.empty()) { MWWorld::Ptr keyPtr = invStore.search(keyId); @@ -181,8 +181,8 @@ namespace MWClass // using a key disarms the trap if (isTrapped) { - ptr.getCellRef().setTrap(""); - MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Disarm Trap", 1.0f, 1.0f); + ptr.getCellRef().setTrap(ESM::RefId::sEmpty); + MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ESM::RefId::stringRefId("Disarm Trap"), 1.0f, 1.0f); isTrapped = false; } } @@ -220,7 +220,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } MWWorld::ContainerStore& Container::getContainerStore(const MWWorld::Ptr& ptr) const @@ -231,7 +231,7 @@ namespace MWClass return data.mStore; } - std::string_view Container::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Container::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -259,14 +259,14 @@ namespace MWClass text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(lockLevel); else if (lockLevel < 0) text += "\n#{sUnlocked}"; - if (ptr.getCellRef().getTrap() != "") + if (ptr.getCellRef().getTrap() != ESM::RefId::sEmpty) text += "\n#{sTrapped}"; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); - if (Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "stolen_goods")) + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); + if (ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("stolen_goods"))) text += "\nYou can not use evidence chests"; } @@ -293,7 +293,7 @@ namespace MWClass return !(ref->mBase->mFlags & ESM::Container::Organic); } - void Container::modifyBaseInventory(std::string_view containerId, std::string_view itemId, int amount) const + void Container::modifyBaseInventory(const ESM::RefId& containerId, const ESM::RefId& itemId, int amount) const { MWMechanics::modifyBaseInventory(containerId, itemId, amount); } diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 7126de3afa..c3b55f7f6f 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -66,7 +66,7 @@ namespace MWClass MWWorld::ContainerStore& getContainerStore(const MWWorld::Ptr& ptr) const override; ///< Return container store - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr float getCapacity(const MWWorld::Ptr& ptr) const override; @@ -91,7 +91,7 @@ namespace MWClass bool useAnim() const override; - void modifyBaseInventory(std::string_view containerId, std::string_view itemId, int amount) const override; + void modifyBaseInventory(const ESM::RefId& containerId, const ESM::RefId& itemId, int amount) const override; }; } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index e87fe4105e..d6f0e1659a 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -214,7 +214,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } MWMechanics::CreatureStats& Creature::getCreatureStats(const MWWorld::Ptr& ptr) const @@ -401,7 +401,7 @@ namespace MWClass if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer()) { - const std::string& script = ptr.get()->mBase->mScript; + const ESM::RefId& script = ptr.get()->mBase->mScript; /* Set the OnPCHitMe script variable. The script is responsible for clearing it. */ if (!script.empty()) ptr.getRefData().getLocals().setVarByInt(script, "onpchitme", 1); @@ -411,7 +411,7 @@ namespace MWClass { // Missed if (!attacker.isEmpty() && attacker == MWMechanics::getPlayer()) - MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f); + MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ESM::RefId::stringRefId("miss"), 1.0f, 1.0f); return; } @@ -448,7 +448,7 @@ namespace MWClass MWBase::Environment::get().getWorld()->spawnBloodEffect(ptr, hitPosition); } - MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Health Damage", 1.0f, 1.0f); + MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); MWMechanics::DynamicStat health(stats.getHealth()); health.setCurrent(health.getCurrent() - damage); @@ -469,7 +469,7 @@ namespace MWClass { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const ESM::Sound* sound = store.get().searchRandom("WolfCreature", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfCreature"), prng); std::unique_ptr action = std::make_unique("#{sWerewolfRefusal}"); if (sound) @@ -522,7 +522,7 @@ namespace MWClass return isFlagBitSet(ptr, ESM::Creature::Weapon); } - std::string_view Creature::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Creature::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -601,7 +601,7 @@ namespace MWClass std::string text; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); info.text = text; return info; @@ -630,18 +630,18 @@ namespace MWClass return (ref->mBase->mRecordFlags & ESM::FLAG_Persistent) != 0; } - std::string_view Creature::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const + const ESM::RefId& Creature::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const { int type = getSndGenTypeFromName(ptr, name); if (type < 0) - return {}; + return ESM::RefId::sEmpty; std::vector sounds; std::vector fallbacksounds; MWWorld::LiveCellRef* ref = ptr.get(); - const std::string& ourId + const ESM::RefId& ourId = (ref->mBase->mOriginal.empty()) ? ptr.getCellRef().getRefId() : ref->mBase->mOriginal; const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); @@ -649,7 +649,7 @@ namespace MWClass while (sound != store.get().end()) { if (type == sound->mType && !sound->mCreature.empty() - && Misc::StringUtils::ciEqual(ourId, sound->mCreature)) + && ESM::RefId::ciEqual(ourId, sound->mCreature)) sounds.push_back(&*sound); if (type == sound->mType && sound->mCreature.empty()) fallbacksounds.push_back(&*sound); @@ -668,12 +668,12 @@ namespace MWClass && Misc::StringUtils::ciEqual( model, Misc::ResourceHelpers::correctMeshPath(creature.mModel, vfs))) { - const std::string& fallbackId = !creature.mOriginal.empty() ? creature.mOriginal : creature.mId; + const ESM::RefId& fallbackId = !creature.mOriginal.empty() ? creature.mOriginal : creature.mId; sound = store.get().begin(); while (sound != store.get().end()) { if (type == sound->mType && !sound->mCreature.empty() - && Misc::StringUtils::ciEqual(fallbackId, sound->mCreature)) + && ESM::RefId::ciEqual(fallbackId, sound->mCreature)) sounds.push_back(&*sound); ++sound; } @@ -689,7 +689,7 @@ namespace MWClass if (!fallbacksounds.empty()) return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size(), prng)]->mSound; - return {}; + return ESM::RefId::sEmpty; } MWWorld::Ptr Creature::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const @@ -876,7 +876,7 @@ namespace MWClass if (ptr.getRefData().getCount() == 0) { ptr.getRefData().setCount(1); - std::string_view script = getScript(ptr); + const ESM::RefId& script = getScript(ptr); if (!script.empty()) MWBase::Environment::get().getWorld()->getLocalScripts().add(script, ptr); } @@ -905,12 +905,12 @@ namespace MWClass scale *= ref->mBase->mScale; } - void Creature::setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const + void Creature::setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) const { MWMechanics::setBaseAISetting(id, setting, value); } - void Creature::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const + void Creature::modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const { MWMechanics::modifyBaseInventory(actorId, itemId, amount); } diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 9e559a604c..320370db93 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -80,7 +80,7 @@ namespace MWClass bool hasInventoryStore(const MWWorld::Ptr& ptr) const override; - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr float getCapacity(const MWWorld::Ptr& ptr) const override; @@ -97,7 +97,7 @@ namespace MWClass bool isPersistent(const MWWorld::ConstPtr& ptr) const override; - std::string_view getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; + const ESM::RefId& getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; MWMechanics::Movement& getMovementSettings(const MWWorld::Ptr& ptr) const override; ///< Return desired movement. @@ -135,9 +135,9 @@ 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::AiSetting setting, int value) const override; + void setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) const override; - void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const override; + void modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const override; float getWalkSpeed(const MWWorld::Ptr& ptr) const override; diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp index 14ca13719b..a9b7abdc7d 100644 --- a/apps/openmw/mwclass/creaturelevlist.cpp +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -130,7 +130,7 @@ namespace MWClass MWWorld::LiveCellRef* ref = ptr.get(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - std::string_view id = MWMechanics::getLevelledItem(ref->mBase, true, prng); + const ESM::RefId& id = MWMechanics::getLevelledItem(ref->mBase, true, prng); if (!id.empty()) { diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 8a300fc9e8..5469bc95cd 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -104,17 +104,17 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Door::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { MWWorld::LiveCellRef* ref = ptr.get(); - const std::string& openSound = ref->mBase->mOpenSound; - const std::string& closeSound = ref->mBase->mCloseSound; - const std::string_view lockedSound = "LockedDoor"; - const std::string_view trapActivationSound = "Disarm Trap Fail"; + const ESM::RefId& openSound = ref->mBase->mOpenSound; + const ESM::RefId& closeSound = ref->mBase->mCloseSound; + const ESM::RefId lockedSound = ESM::RefId::stringRefId("LockedDoor"); + const ESM::RefId trapActivationSound = ESM::RefId::stringRefId("Disarm Trap Fail"); // FIXME: If NPC activate teleporting door, it can lead to crash due to iterator invalidation in the Actors // update. Make such activation a no-op for now, like how it is in the vanilla game. @@ -148,7 +148,7 @@ namespace MWClass bool isTrapped = !ptr.getCellRef().getTrap().empty(); bool hasKey = false; std::string_view keyName; - const std::string& keyId = ptr.getCellRef().getKey(); + const ESM::RefId& keyId = ptr.getCellRef().getKey(); if (!keyId.empty()) { MWWorld::Ptr keyPtr = invStore.search(keyId); @@ -167,8 +167,8 @@ namespace MWClass // using a key disarms the trap if (isTrapped) { - ptr.getCellRef().setTrap(""); - MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Disarm Trap", 1.0f, 1.0f); + ptr.getCellRef().setTrap(ESM::RefId::sEmpty); + MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ESM::RefId::stringRefId("Disarm Trap"), 1.0f, 1.0f); isTrapped = false; } } @@ -256,7 +256,7 @@ namespace MWClass return true; } - std::string_view Door::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Door::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -290,7 +290,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index dc6be431ed..4226f56b85 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -48,7 +48,7 @@ namespace MWClass bool allowTelekinesis(const MWWorld::ConstPtr& ptr) const override; ///< Return whether this class of object can be activated with telekinesis - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::string getModel(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 575377a0e5..6be431038a 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -48,7 +48,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Ingredient::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -56,7 +56,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Ingredient::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Ingredient::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -74,19 +74,21 @@ namespace MWClass { std::unique_ptr action = std::make_unique(ptr); - action->setSound("Swallow"); + action->setSound(ESM::RefId::stringRefId("Swallow")); return action; } - std::string_view Ingredient::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Ingredient::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Ingredient Up"; + static auto sound = ESM::RefId::stringRefId("Item Ingredient Up"); + return sound; } - std::string_view Ingredient::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Ingredient::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Ingredient Down"; + static auto sound = ESM::RefId::stringRefId("Item Ingredient Down"); + return sound; } const std::string& Ingredient::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -114,7 +116,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 4527c67d98..59e9c2bfc3 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -27,7 +27,7 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr int getValue(const MWWorld::ConstPtr& ptr) const override; @@ -36,10 +36,10 @@ namespace MWClass std::unique_ptr use(const MWWorld::Ptr& ptr, bool force = false) const override; ///< Generate action for using via inventory menu - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index c3ac48ff81..cd833fe609 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -83,7 +83,7 @@ namespace MWClass return {}; const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Light::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -98,7 +98,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Light::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Light::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -124,14 +124,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Light::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Light::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Misc Up"; + static const auto sound = ESM::RefId::stringRefId("Item Misc Up"); + return sound; } - std::string_view Light::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Light::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Misc Down"; + static const auto sound = ESM::RefId::stringRefId("Item Misc Down"); + return sound; } const std::string& Light::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -169,7 +171,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; @@ -237,7 +239,7 @@ namespace MWClass return { 1, {} }; } - std::string_view Light::getSound(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Light::getSound(const MWWorld::ConstPtr& ptr) const { return ptr.get()->mBase->mSound; } diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index 41382df9b0..612d6f9e5e 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -39,7 +39,7 @@ namespace MWClass std::unique_ptr activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override; ///< Generate action for activation - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::pair, bool> getEquipmentSlots(const MWWorld::ConstPtr& ptr) const override; @@ -49,10 +49,10 @@ namespace MWClass int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; @@ -76,7 +76,7 @@ namespace MWClass std::pair canBeEquipped( const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override; - std::string_view getSound(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getSound(const MWWorld::ConstPtr& ptr) const override; }; } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 79b07a8154..e44135d720 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -48,7 +48,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Lockpick::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -56,7 +56,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Lockpick::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Lockpick::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -79,14 +79,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Lockpick::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Lockpick::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Lockpick Up"; + static ESM::RefId sound = ESM::RefId::stringRefId("Item Lockpick Up"); + return sound; } - std::string_view Lockpick::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Lockpick::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Lockpick Down"; + static ESM::RefId sound = ESM::RefId::stringRefId("Item Lockpick Down"); + return sound; } const std::string& Lockpick::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -118,7 +120,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 750549b4e3..a258c80d7a 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -3,6 +3,11 @@ #include "../mwworld/registeredclass.hpp" +namespace ESM +{ + struct RefId; +} + namespace MWClass { class Lockpick : public MWWorld::RegisteredClass @@ -27,7 +32,7 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::pair, bool> getEquipmentSlots(const MWWorld::ConstPtr& ptr) const override; @@ -37,10 +42,10 @@ namespace MWClass int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index c0b9ecdd8f..df63b5c40d 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -35,11 +35,11 @@ namespace MWClass bool Miscellaneous::isGold(const MWWorld::ConstPtr& ptr) const { - return Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_001") - || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_005") - || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_010") - || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_025") - || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "gold_100"); + return ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("gold_001")) + || ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("gold_005")) + || ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("gold_010")) + || ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("gold_025")) + || ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("gold_100")); } void Miscellaneous::insertObjectRendering( @@ -61,7 +61,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Miscellaneous::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -69,7 +69,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Miscellaneous::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Miscellaneous::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -97,7 +97,7 @@ namespace MWClass float soulValue = 0.0001 * pow(soul, 3) + 2 * soul; // for Azura's star add the unfilled value - if (Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "Misc_SoulGem_Azura")) + if (ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("Misc_SoulGem_Azura"))) value += soulValue; else value = soulValue; @@ -110,18 +110,22 @@ namespace MWClass return value; } - std::string_view Miscellaneous::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Miscellaneous::getUpSoundId(const MWWorld::ConstPtr& ptr) const { + static ESM::RefId sound; if (isGold(ptr)) - return "Item Gold Up"; - return "Item Misc Up"; + sound = ESM::RefId::stringRefId("Item Gold Up"); + sound = ESM::RefId::stringRefId("Item Misc Up"); + return sound; } - std::string_view Miscellaneous::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Miscellaneous::getDownSoundId(const MWWorld::ConstPtr& ptr) const { + static ESM::RefId sound; if (isGold(ptr)) - return "Item Gold Down"; - return "Item Misc Down"; + sound = ESM::RefId::stringRefId("Item Gold Down"); + sound = ESM::RefId::stringRefId("Item Misc Down"); + return sound; } const std::string& Miscellaneous::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -161,7 +165,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; @@ -191,7 +195,7 @@ namespace MWClass // Really, I have no idea why moving ref out of conditional // scope causes list::push_back throwing std::bad_alloc - MWWorld::ManualRef newRef(store, base); + MWWorld::ManualRef newRef(store, ESM::RefId::stringRefId(base)); const MWWorld::LiveCellRef* ref = newRef.getPtr().get(); newPtr = MWWorld::Ptr(cell.insert(ref), &cell); @@ -238,7 +242,7 @@ namespace MWClass bool Miscellaneous::isSoulGem(const MWWorld::ConstPtr& ptr) const { - return Misc::StringUtils::ciStartsWith(ptr.getCellRef().getRefId(), "misc_soulgem"); + return Misc::StringUtils::ciStartsWith(ptr.getCellRef().getRefId().getRefIdString(), "misc_soulgem"); } } diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index 1af2b772b8..6fc5f28d36 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -27,16 +27,16 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 0fc66defbd..02e1ba7bc4 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -247,7 +247,7 @@ namespace if (!spellsInitialised) { - std::vector spells = MWMechanics::autoCalcNpcSpells(skills, attributes, race); + std::vector spells = MWMechanics::autoCalcNpcSpells(skills, attributes, race); npcStats.getSpells().addAllToInstance(spells); } } @@ -506,11 +506,11 @@ namespace MWClass for (std::vector::const_iterator it = parts.begin(); it != parts.end(); ++it) { - std::string_view partname = female ? it->mFemale : it->mMale; - if (partname.empty()) - partname = female ? it->mMale : it->mFemale; + const ESM::RefId* partname = female ? &it->mFemale : &it->mMale; + if (partname->empty()) + partname = female ? &it->mMale : &it->mFemale; const ESM::BodyPart* part - = MWBase::Environment::get().getWorld()->getStore().get().search(partname); + = MWBase::Environment::get().getWorld()->getStore().get().search(*partname); if (part && !part->mModel.empty()) models.push_back(Misc::ResourceHelpers::correctMeshPath(part->mModel, vfs)); } @@ -521,7 +521,7 @@ namespace MWClass if (race) { const std::vector& parts - = MWRender::NpcAnimation::getBodyParts(Misc::StringUtils::lowerCase(race->mId), female, false, false); + = MWRender::NpcAnimation::getBodyParts(race->mId, female, false, false); for (std::vector::const_iterator it = parts.begin(); it != parts.end(); ++it) { const ESM::BodyPart* part = *it; @@ -545,7 +545,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } MWMechanics::CreatureStats& Npc::getCreatureStats(const MWWorld::Ptr& ptr) const @@ -687,7 +687,7 @@ namespace MWClass { damage *= store.find("fCombatCriticalStrikeMult")->mValue.getFloat(); MWBase::Environment::get().getWindowManager()->messageBox("#{sTargetCriticalStrike}"); - MWBase::Environment::get().getSoundManager()->playSound3D(victim, "critical damage", 1.0f, 1.0f); + MWBase::Environment::get().getSoundManager()->playSound3D(victim, ESM::RefId::stringRefId("critical damage"), 1.0f, 1.0f); } } @@ -750,7 +750,7 @@ namespace MWClass if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer()) { - std::string_view script = getScript(ptr); + const ESM::RefId& script = getScript(ptr); /* Set the OnPCHitMe script variable. The script is responsible for clearing it. */ if (!script.empty()) ptr.getRefData().getLocals().setVarByInt(script, "onpchitme", 1); @@ -760,7 +760,7 @@ namespace MWClass { // Missed if (!attacker.isEmpty() && attacker == MWMechanics::getPlayer()) - sndMgr->playSound3D(ptr, "miss", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("miss"), 1.0f, 1.0f); return; } @@ -789,7 +789,7 @@ namespace MWClass int chance = store.get().find("iVoiceHitOdds")->mValue.getInteger(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); if (Misc::Rng::roll0to99(prng) < chance) - MWBase::Environment::get().getDialogueManager()->say(ptr, "hit"); + MWBase::Environment::get().getDialogueManager()->say(ptr, ESM::RefId::stringRefId("hit")); // Check for knockdown float agilityTerm @@ -870,13 +870,13 @@ namespace MWClass switch (armor.getClass().getEquipmentSkill(armor)) { case ESM::Skill::LightArmor: - sndMgr->playSound3D(ptr, "Light Armor Hit", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Light Armor Hit"), 1.0f, 1.0f); break; case ESM::Skill::MediumArmor: - sndMgr->playSound3D(ptr, "Medium Armor Hit", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Medium Armor Hit"), 1.0f, 1.0f); break; case ESM::Skill::HeavyArmor: - sndMgr->playSound3D(ptr, "Heavy Armor Hit", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Heavy Armor Hit"), 1.0f, 1.0f); break; } } @@ -892,7 +892,7 @@ namespace MWClass if (damage > 0.0f) { - sndMgr->playSound3D(ptr, "Health Damage", 1.0f, 1.0f); + sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); if (ptr == MWMechanics::getPlayer()) MWBase::Environment::get().getWindowManager()->activateHitOverlay(); if (!attacker.isEmpty()) @@ -933,7 +933,7 @@ namespace MWClass { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const ESM::Sound* sound = store.get().searchRandom("WolfNPC", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfNPC"), prng); std::unique_ptr action = std::make_unique("#{sWerewolfRefusal}"); if (sound) @@ -994,7 +994,7 @@ namespace MWClass return ptr.getRefData().getCustomData()->asNpcCustomData().mInventoryStore; } - std::string_view Npc::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Npc::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -1141,7 +1141,7 @@ namespace MWClass } if (fullHelp) - info.text = MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + info.text = MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); return info; } @@ -1169,7 +1169,7 @@ namespace MWClass { MWBase::Environment::get().getWorld()->breakInvisibility(actor); MWMechanics::CastSpell cast(actor, actor); - const std::string& recordId = consumable.getCellRef().getRefId(); + const ESM::RefId& recordId = consumable.getCellRef().getRefId(); MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor); actor.getClass().getContainerStore(actor).remove(consumable, 1, actor); return cast.cast(recordId); @@ -1287,18 +1287,19 @@ namespace MWClass return npc->mAiData.mServices; } - std::string_view Npc::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const + const ESM::RefId& Npc::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const { + std::string sound; if (name == "left" || name == "right") { MWBase::World* world = MWBase::Environment::get().getWorld(); if (world->isFlying(ptr)) - return {}; + return ESM::RefId::sEmpty; osg::Vec3f pos(ptr.getRefData().getPosition().asVec3()); if (world->isSwimming(ptr)) - return (name == "left") ? "Swim Left" : "Swim Right"; + sound = (name == "left") ? "Swim Left" : "Swim Right"; if (world->isUnderwater(ptr.getCell(), pos) || world->isWalkingOnWater(ptr)) - return (name == "left") ? "FootWaterLeft" : "FootWaterRight"; + sound = (name == "left") ? "FootWaterLeft" : "FootWaterRight"; if (world->isOnGround(ptr)) { if (getNpcStats(ptr).isWerewolf() @@ -1307,46 +1308,52 @@ namespace MWClass int weaponType = ESM::Weapon::None; MWMechanics::getActiveWeapon(ptr, &weaponType); if (weaponType == ESM::Weapon::None) - return {}; + return ESM::RefId::sEmpty; } const MWWorld::InventoryStore& inv = Npc::getInventoryStore(ptr); MWWorld::ConstContainerStoreIterator boots = inv.getSlot(MWWorld::InventoryStore::Slot_Boots); if (boots == inv.end() || boots->getType() != ESM::Armor::sRecordId) - return (name == "left") ? "FootBareLeft" : "FootBareRight"; + sound = (name == "left") ? "FootBareLeft" : "FootBareRight"; switch (boots->getClass().getEquipmentSkill(*boots)) { case ESM::Skill::LightArmor: - return (name == "left") ? "FootLightLeft" : "FootLightRight"; + sound = (name == "left") ? "FootLightLeft" : "FootLightRight"; case ESM::Skill::MediumArmor: - return (name == "left") ? "FootMedLeft" : "FootMedRight"; + sound = (name == "left") ? "FootMedLeft" : "FootMedRight"; case ESM::Skill::HeavyArmor: - return (name == "left") ? "FootHeavyLeft" : "FootHeavyRight"; + sound = (name == "left") ? "FootHeavyLeft" : "FootHeavyRight"; } } - return {}; + return ESM::RefId::sEmpty; } // Morrowind ignores land soundgen for NPCs if (name == "land") - return {}; + return ESM::RefId::sEmpty; if (name == "swimleft") - return "Swim Left"; + sound = "Swim Left"; if (name == "swimright") - return "Swim Right"; + sound = "Swim Right"; // TODO: I have no idea what these are supposed to do for NPCs since they use // voiced dialog for various conditions like health loss and combat taunts. Maybe // only for biped creatures? if (name == "moan") - return {}; + return ESM::RefId::sEmpty; if (name == "roar") - return {}; + return ESM::RefId::sEmpty; if (name == "scream") - return {}; + return ESM::RefId::sEmpty; - throw std::runtime_error("Unexpected soundgen type: " + std::string(name)); + if(sound.empty()) + throw std::runtime_error("Unexpected soundgen type: " + std::string(name)); + else + { + static auto soundId = ESM::RefId::stringRefId(sound); + return soundId; + } } MWWorld::Ptr Npc::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const @@ -1428,7 +1435,7 @@ namespace MWClass bool Npc::isClass(const MWWorld::ConstPtr& ptr, std::string_view className) const { - return Misc::StringUtils::ciEqual(ptr.get()->mBase->mClass, className); + return Misc::StringUtils::ciEqual(ptr.get()->mBase->mClass.getRefIdString(), className); } bool Npc::canSwim(const MWWorld::ConstPtr& ptr) const @@ -1466,7 +1473,7 @@ namespace MWClass if (ptr.getRefData().getCount() == 0) { ptr.getRefData().setCount(1); - std::string_view script = getScript(ptr); + const ESM::RefId& script = getScript(ptr); if (!script.empty()) MWBase::Environment::get().getWorld()->getLocalScripts().add(script, ptr); } @@ -1494,7 +1501,7 @@ namespace MWClass return true; } - std::string_view Npc::getPrimaryFaction(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Npc::getPrimaryFaction(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); return ref->mBase->mFaction; @@ -1502,7 +1509,7 @@ namespace MWClass int Npc::getPrimaryFactionRank(const MWWorld::ConstPtr& ptr) const { - std::string_view factionID = ptr.getClass().getPrimaryFaction(ptr); + const ESM::RefId& factionID = ptr.getClass().getPrimaryFaction(ptr); if (factionID.empty()) return -1; @@ -1519,12 +1526,12 @@ namespace MWClass return ref->mBase->getFactionRank(); } - void Npc::setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const + void Npc::setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) const { MWMechanics::setBaseAISetting(id, setting, value); } - void Npc::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const + void Npc::modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const { MWMechanics::modifyBaseInventory(actorId, itemId, amount); } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 855d236c22..6ae3cc6704 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -91,7 +91,7 @@ namespace MWClass std::unique_ptr activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const override; ///< Generate action for activation - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr float getMaxSpeed(const MWWorld::Ptr& ptr) const override; @@ -130,7 +130,7 @@ namespace MWClass bool isPersistent(const MWWorld::ConstPtr& ptr) const override; - std::string_view getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; + const ESM::RefId& getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; std::string getModel(const MWWorld::ConstPtr& ptr) const override; @@ -161,12 +161,12 @@ namespace MWClass int getBaseFightRating(const MWWorld::ConstPtr& ptr) const override; - std::string_view getPrimaryFaction(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getPrimaryFaction(const MWWorld::ConstPtr& ptr) const override; int getPrimaryFactionRank(const MWWorld::ConstPtr& ptr) const override; - void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override; + void setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) const override; - void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const override; + void modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const override; float getWalkSpeed(const MWWorld::Ptr& ptr) const override; diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 499910bd77..dedf72d2db 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -48,7 +48,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Potion::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -56,7 +56,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Potion::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Potion::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -70,14 +70,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Potion::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Potion::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Potion Up"; + static const auto sound = ESM::RefId::stringRefId("Item Potion Up"); + return sound; } - std::string_view Potion::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Potion::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Potion Down"; + static const auto sound = ESM::RefId::stringRefId("Item Potion Down"); + return sound; } const std::string& Potion::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -114,7 +116,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; @@ -128,7 +130,7 @@ namespace MWClass auto action = std::make_unique(ptr, ref->mBase->mId); - action->setSound("Drink"); + action->setSound(ESM::RefId::stringRefId("Drink")); return action; } diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index 1bff256b0d..30e04a8bc4 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -27,7 +27,7 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr int getValue(const MWWorld::ConstPtr& ptr) const override; @@ -36,10 +36,10 @@ namespace MWClass std::unique_ptr use(const MWWorld::Ptr& ptr, bool force = false) const override; ///< Generate action for using via inventory menu - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 7feda8445e..f0348deebf 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -48,14 +48,14 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Probe::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const { return defaultItemActivate(ptr, actor); } - std::string_view Probe::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Probe::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -78,14 +78,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Probe::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Probe::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Probe Up"; + static const ESM::RefId sound = ESM::RefId::stringRefId("Item Probe Up"); + return sound; } - std::string_view Probe::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Probe::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Probe Down"; + static const ESM::RefId sound = ESM::RefId::stringRefId("Item Probe Down"); + return sound; } const std::string& Probe::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -117,7 +119,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 3325c30e3b..497dbc0120 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -27,7 +27,7 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::pair, bool> getEquipmentSlots(const MWWorld::ConstPtr& ptr) const override; @@ -37,10 +37,10 @@ namespace MWClass int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 899e0f14bd..3756084963 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -46,7 +46,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Repair::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -54,7 +54,7 @@ namespace MWClass return defaultItemActivate(ptr, actor); } - std::string_view Repair::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Repair::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -68,14 +68,16 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Repair::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Repair::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Repair Up"; + static auto val = ESM::RefId::stringRefId("Item Repair Up"); + return val; } - std::string_view Repair::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Repair::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return "Item Repair Down"; + static auto val = ESM::RefId::stringRefId("Item Repair Down"); + return val; } const std::string& Repair::getInventoryIcon(const MWWorld::ConstPtr& ptr) const @@ -119,7 +121,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 02a69fdd0f..35f0b4ba7d 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -27,16 +27,16 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo(const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 9c730953bc..2c3c1db32f 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -54,7 +54,7 @@ namespace MWClass const MWWorld::LiveCellRef* ref = ptr.get(); const std::string& name = ref->mBase->mName; - return !name.empty() ? name : ref->mBase->mId; + return !name.empty() ? name : ref->mBase->mId.getRefIdString(); } std::unique_ptr Weapon::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const @@ -77,7 +77,7 @@ namespace MWClass return ref->mBase->mData.mHealth; } - std::string_view Weapon::getScript(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Weapon::getScript(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); @@ -123,14 +123,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string_view Weapon::getUpSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Weapon::getUpSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); int type = ref->mBase->mData.mType; return MWMechanics::getWeaponType(type)->mSoundIdUp; } - std::string_view Weapon::getDownSoundId(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Weapon::getDownSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); int type = ref->mBase->mData.mType; @@ -243,7 +243,7 @@ namespace MWClass if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getCellRefString(ptr.getCellRef()); - text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script"); + text += MWGui::ToolTips::getMiscString(ref->mBase->mScript.getRefIdString(), "Script"); } info.text = text; @@ -251,15 +251,15 @@ namespace MWClass return info; } - std::string_view Weapon::getEnchantment(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Weapon::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef* ref = ptr.get(); return ref->mBase->mEnchant; } - const std::string& Weapon::applyEnchantment( - const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const ESM::RefId& Weapon::applyEnchantment( + const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef* ref = ptr.get(); diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 9f07f5f6dd..467d860851 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -33,7 +33,7 @@ namespace MWClass int getItemMaxHealth(const MWWorld::ConstPtr& ptr) const override; ///< Return item max health or throw an exception, if class does not have item health - std::string_view getScript(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getScript(const MWWorld::ConstPtr& ptr) const override; ///< Return name of the script attached to ptr std::pair, bool> getEquipmentSlots(const MWWorld::ConstPtr& ptr) const override; @@ -47,19 +47,19 @@ namespace MWClass int getValue(const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; + const ESM::RefId& getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, + const ESM::RefId& applyEnchantment(const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 26e68350de..3e6dbf3c0c 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -74,14 +74,14 @@ namespace MWDialogue mPermanentDispositionChange = 0; } - void DialogueManager::addTopic(std::string_view topic) + void DialogueManager::addTopic(const ESM::RefId& topic) { - mKnownTopics.insert(Misc::StringUtils::lowerCase(topic)); + mKnownTopics.insert(topic); } - std::vector DialogueManager::parseTopicIdsFromText(const std::string& text) + std::vector DialogueManager::parseTopicIdsFromText(const std::string& text) { - std::vector topicIdList; + std::vector topicIdList; std::vector hypertext = HyperTextParser::parseHyperText(text); @@ -99,7 +99,7 @@ namespace MWDialogue topicId = mTranslationDataStorage.topicStandardForm(topicId); } - topicIdList.push_back(topicId); + topicIdList.push_back(ESM::RefId::stringRefId(topicId)); } return topicIdList; @@ -204,7 +204,7 @@ namespace MWDialogue Compiler::Locals locals; - std::string_view actorScript = actor.getClass().getScript(actor); + const ESM::RefId& actorScript = actor.getClass().getScript(actor); if (!actorScript.empty()) { @@ -260,7 +260,7 @@ namespace MWDialogue } } - bool DialogueManager::inJournal(const std::string& topicId, const std::string& infoId) const + bool DialogueManager::inJournal(const ESM::RefId& topicId, const ESM::RefId& infoId) const { const MWDialogue::Topic* topicHistory = nullptr; MWBase::Journal* journal = MWBase::Environment::get().getJournal(); @@ -284,7 +284,7 @@ namespace MWDialogue return false; } - void DialogueManager::executeTopic(const std::string& topic, ResponseCallback* callback) + void DialogueManager::executeTopic(const ESM::RefId& topic, ResponseCallback* callback) { Filter filter(mActor, mChoice, mTalkedTo); @@ -297,26 +297,26 @@ namespace MWDialogue if (info) { - std::string title; + ESM::RefId title; if (dialogue.mType == ESM::Dialogue::Persuasion) { // Determine GMST from dialogue topic. GMSTs are: // sAdmireSuccess, sAdmireFail, sIntimidateSuccess, sIntimidateFail, // sTauntSuccess, sTauntFail, sBribeSuccess, sBribeFail - std::string modifiedTopic = "s" + topic; + std::string modifiedTopic = "s" + topic.getRefIdString(); modifiedTopic.erase(std::remove(modifiedTopic.begin(), modifiedTopic.end(), ' '), modifiedTopic.end()); const MWWorld::Store& gmsts = MWBase::Environment::get().getWorld()->getStore().get(); - title = gmsts.find(modifiedTopic)->mValue.getString(); + title = ESM::RefId::stringRefId(gmsts.find(modifiedTopic)->mValue.getString()); } else title = topic; MWScript::InterpreterContext interpreterContext(&mActor.getRefData().getLocals(), mActor); - callback->addResponse(title, Interpreter::fixDefinesDialog(info->mResponse, interpreterContext)); + callback->addResponse(title.getRefIdString(), Interpreter::fixDefinesDialog(info->mResponse, interpreterContext)); if (dialogue.mType == ESM::Dialogue::Topic) { @@ -328,7 +328,7 @@ namespace MWDialogue if (iter->mId == info->mId) { MWBase::Environment::get().getJournal()->addTopic( - Misc::StringUtils::lowerCase(topic), info->mId, mActor); + topic, info->mId, mActor); break; } } @@ -342,7 +342,7 @@ namespace MWDialogue } } - const ESM::Dialogue* DialogueManager::searchDialogue(const std::string& id) + const ESM::Dialogue* DialogueManager::searchDialogue(const ESM::RefId& id) { return MWBase::Environment::get().getWorld()->getStore().get().search(id); } @@ -367,7 +367,7 @@ namespace MWDialogue if (dialog.mType == ESM::Dialogue::Topic) { const auto* answer = filter.search(dialog, true); - auto topicId = Misc::StringUtils::lowerCase(dialog.mId); + auto topicId = dialog.mId; if (answer != nullptr) { @@ -375,7 +375,7 @@ namespace MWDialogue if (!inJournal(topicId, answer->mId)) { // Does this dialogue contains some actor-specific answer? - if (Misc::StringUtils::ciEqual(answer->mActor, mActor.getCellRef().getRefId())) + if (ESM::RefId::ciEqual(answer->mActor, mActor.getCellRef().getRefId())) topicFlags |= MWBase::DialogueManager::TopicType::Specific; } else @@ -416,7 +416,7 @@ namespace MWDialogue { // does the player know the topic? if (mKnownTopics.count(topic)) - keywordList.push_back(topic); + keywordList.push_back(topic.getRefIdString()); } // sort again, because the previous sort was case-sensitive @@ -424,7 +424,7 @@ namespace MWDialogue return keywordList; } - int DialogueManager::getTopicFlag(const std::string& topicId) const + int DialogueManager::getTopicFlag(const ESM::RefId& topicId) const { auto known = mActorKnownTopics.find(topicId); if (known != mActorKnownTopics.end()) @@ -436,10 +436,10 @@ namespace MWDialogue { if (!mIsInChoice) { - const ESM::Dialogue* dialogue = searchDialogue(keyword); + const ESM::Dialogue* dialogue = searchDialogue(ESM::RefId::stringRefId(keyword)); if (dialogue && dialogue->mType == ESM::Dialogue::Topic) { - executeTopic(keyword, callback); + executeTopic(ESM::RefId::stringRefId(keyword), callback); } } } @@ -502,7 +502,7 @@ namespace MWDialogue if (iter->mId == info->mId) { MWBase::Environment::get().getJournal()->addTopic( - Misc::StringUtils::lowerCase(mLastTopic), info->mId, mActor); + mLastTopic, info->mId, mActor); break; } } @@ -590,7 +590,7 @@ namespace MWDialogue text = "Bribe"; } - executeTopic(text + (success ? " Success" : " Fail"), callback); + executeTopic(ESM::RefId::stringRefId(text + (success ? " Success" : " Fail")), callback); } void DialogueManager::applyBarterDispositionChange(int delta) @@ -612,7 +612,7 @@ namespace MWDialogue const MWWorld::Store& dialogues = MWBase::Environment::get().getWorld()->getStore().get(); - const ESM::Dialogue& dialogue = *dialogues.find("Service Refusal"); + const ESM::Dialogue& dialogue = *dialogues.find(ESM::RefId::stringRefId("Service Refusal")); std::vector infos = filter.list(dialogue, false, false, true); if (!infos.empty()) @@ -635,7 +635,7 @@ namespace MWDialogue return false; } - void DialogueManager::say(const MWWorld::Ptr& actor, const std::string& topic) + void DialogueManager::say(const MWWorld::Ptr& actor, const ESM::RefId& topic) { MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); if (sndMgr->sayActive(actor)) @@ -668,7 +668,7 @@ namespace MWDialogue if (winMgr->getSubtitlesEnabled()) winMgr->messageBox(info->mResponse); if (!info->mSound.empty()) - sndMgr->say(actor, info->mSound); + sndMgr->say(actor, info->mSound.getRefIdString()); if (!info->mResultScript.empty()) executeScript(info->mResultScript, actor); } @@ -702,7 +702,7 @@ namespace MWDialogue ESM::DialogueState state; state.load(reader); - for (std::vector::const_iterator iter(state.mKnownTopics.begin()); + for (std::vector::const_iterator iter(state.mKnownTopics.begin()); iter != state.mKnownTopics.end(); ++iter) if (store.get().search(*iter)) mKnownTopics.insert(*iter); @@ -711,49 +711,40 @@ namespace MWDialogue } } - void DialogueManager::modFactionReaction(std::string_view faction1, std::string_view faction2, int diff) + void DialogueManager::modFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2, int diff) { - std::string fact1 = Misc::StringUtils::lowerCase(faction1); - std::string fact2 = Misc::StringUtils::lowerCase(faction2); - // Make sure the factions exist - MWBase::Environment::get().getWorld()->getStore().get().find(fact1); - MWBase::Environment::get().getWorld()->getStore().get().find(fact2); + MWBase::Environment::get().getWorld()->getStore().get().find(faction1); + MWBase::Environment::get().getWorld()->getStore().get().find(faction2); int newValue = getFactionReaction(faction1, faction2) + diff; - std::map& map = mChangedFactionReaction[fact1]; - map[fact2] = newValue; + auto& map = mChangedFactionReaction[faction1]; + map[faction2] = newValue; } - void DialogueManager::setFactionReaction(std::string_view faction1, std::string_view faction2, int absolute) + void DialogueManager::setFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2, int absolute) { - std::string fact1 = Misc::StringUtils::lowerCase(faction1); - std::string fact2 = Misc::StringUtils::lowerCase(faction2); - // Make sure the factions exist - MWBase::Environment::get().getWorld()->getStore().get().find(fact1); - MWBase::Environment::get().getWorld()->getStore().get().find(fact2); + MWBase::Environment::get().getWorld()->getStore().get().find(faction1); + MWBase::Environment::get().getWorld()->getStore().get().find(faction2); - std::map& map = mChangedFactionReaction[fact1]; - map[fact2] = absolute; + auto& map = mChangedFactionReaction[faction1]; + map[faction2] = absolute; } - int DialogueManager::getFactionReaction(std::string_view faction1, std::string_view faction2) const + int DialogueManager::getFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2) const { - std::string fact1 = Misc::StringUtils::lowerCase(faction1); - std::string fact2 = Misc::StringUtils::lowerCase(faction2); - - ModFactionReactionMap::const_iterator map = mChangedFactionReaction.find(fact1); - if (map != mChangedFactionReaction.end() && map->second.find(fact2) != map->second.end()) - return map->second.at(fact2); + ModFactionReactionMap::const_iterator map = mChangedFactionReaction.find(faction1); + if (map != mChangedFactionReaction.end() && map->second.find(faction2) != map->second.end()) + return map->second.at(faction2); - const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get().find(fact1); + const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get().find(faction1); - std::map::const_iterator it = faction->mReactions.begin(); + auto it = faction->mReactions.begin(); for (; it != faction->mReactions.end(); ++it) { - if (Misc::StringUtils::ciEqual(it->first, fact2)) + if (ESM::RefId::ciEqual(it->first, faction2)) return it->second; } return 0; @@ -764,7 +755,7 @@ namespace MWDialogue if (actor == mActor && !mLastTopic.empty()) { MWBase::Environment::get().getJournal()->removeLastAddedTopicResponse( - Misc::StringUtils::lowerCase(mLastTopic), actor.getClass().getName(actor)); + mLastTopic, actor.getClass().getName(actor)); } } } diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index d75a682768..0c239acf18 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -31,13 +31,13 @@ namespace MWDialogue const ESM::DialInfo* mInfo; }; - std::set mKnownTopics; // Those are the topics the player knows. + std::set mKnownTopics; // Those are the topics the player knows. // Modified faction reactions. > - typedef std::map> ModFactionReactionMap; + typedef std::map> ModFactionReactionMap; ModFactionReactionMap mChangedFactionReaction; - std::map mActorKnownTopics; + std::map mActorKnownTopics; Translation::Storage& mTranslationDataStorage; MWScript::CompilerContext mCompilerContext; @@ -47,7 +47,7 @@ namespace MWDialogue bool mTalkedTo; int mChoice; - std::string mLastTopic; // last topic ID, lowercase + ESM::RefId mLastTopic; // last topic ID, lowercase bool mIsInChoice; bool mGoodbye; @@ -57,7 +57,7 @@ namespace MWDialogue int mCurrentDisposition; int mPermanentDispositionChange; - std::vector parseTopicIdsFromText(const std::string& text); + std::vector parseTopicIdsFromText(const std::string& text); void addTopicsFromText(const std::string& text); void updateActorKnownTopics(); @@ -66,9 +66,9 @@ namespace MWDialogue bool compile(const std::string& cmd, std::vector& code, const MWWorld::Ptr& actor); void executeScript(const std::string& script, const MWWorld::Ptr& actor); - void executeTopic(const std::string& topic, ResponseCallback* callback); + void executeTopic(const ESM::RefId& topic, ResponseCallback* callback); - const ESM::Dialogue* searchDialogue(const std::string& id); + const ESM::Dialogue* searchDialogue(const ESM::RefId& id); void updateOriginalDisposition(); @@ -82,11 +82,11 @@ namespace MWDialogue bool startDialogue(const MWWorld::Ptr& actor, ResponseCallback* callback) override; std::list getAvailableTopics() override; - int getTopicFlag(const std::string& topicId) const override; + int getTopicFlag(const ESM::RefId& topicId) const override; - bool inJournal(const std::string& topicId, const std::string& infoId) const override; + bool inJournal(const ESM::RefId& topicId, const ESM::RefId& infoId) const override; - void addTopic(std::string_view topic) override; + void addTopic(const ESM::RefId& topic) override; void addChoice(std::string_view text, int choice) override; const std::vector>& getChoices() const override; @@ -97,7 +97,7 @@ namespace MWDialogue bool checkServiceRefused(ResponseCallback* callback, ServiceType service = ServiceType::Any) override; - void say(const MWWorld::Ptr& actor, const std::string& topic) override; + void say(const MWWorld::Ptr& actor, const ESM::RefId& topic) override; // calbacks for the GUI void keywordSelected(const std::string& keyword, ResponseCallback* callback) override; @@ -116,12 +116,12 @@ namespace MWDialogue void readRecord(ESM::ESMReader& reader, uint32_t type) override; /// Changes faction1's opinion of faction2 by \a diff. - void modFactionReaction(std::string_view faction1, std::string_view faction2, int diff) override; + void modFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2, int diff) override; - void setFactionReaction(std::string_view faction1, std::string_view faction2, int absolute) override; + void setFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2, int absolute) override; /// @return faction1's opinion of faction2 - int getFactionReaction(std::string_view faction1, std::string_view faction2) const override; + int getFactionReaction(const ESM::RefId& faction1, const ESM::RefId& faction2) const override; /// Removes the last added topic response for the given actor from the journal void clearInfoActor(const MWWorld::Ptr& actor) const override; diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 9e51100da4..b2e2b723fc 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "../mwbase/dialoguemanager.hpp" #include "../mwbase/environment.hpp" @@ -83,7 +84,7 @@ bool MWDialogue::Filter::testActor(const ESM::DialInfo& info) const // actor id if (!info.mActor.empty()) { - if (!Misc::StringUtils::ciEqual(info.mActor, mActor.getCellRef().getRefId())) + if (!ESM::RefId::ciEqual(info.mActor, mActor.getCellRef().getRefId())) return false; } else if (isCreature) @@ -100,7 +101,7 @@ bool MWDialogue::Filter::testActor(const ESM::DialInfo& info) const MWWorld::LiveCellRef* cellRef = mActor.get(); - if (!Misc::StringUtils::ciEqual(info.mRace, cellRef->mBase->mRace)) + if (!ESM::RefId::ciEqual(info.mRace, cellRef->mBase->mRace)) return false; } @@ -112,7 +113,7 @@ bool MWDialogue::Filter::testActor(const ESM::DialInfo& info) const MWWorld::LiveCellRef* cellRef = mActor.get(); - if (!Misc::StringUtils::ciEqual(info.mClass, cellRef->mBase->mClass)) + if (!ESM::RefId::ciEqual(info.mClass, cellRef->mBase->mClass)) return false; } @@ -130,7 +131,7 @@ bool MWDialogue::Filter::testActor(const ESM::DialInfo& info) const if (isCreature) return true; - if (!Misc::StringUtils::ciEqual(mActor.getClass().getPrimaryFaction(mActor), info.mFaction)) + if (!ESM::RefId::ciEqual(mActor.getClass().getPrimaryFaction(mActor), info.mFaction)) return false; // check rank @@ -167,8 +168,8 @@ bool MWDialogue::Filter::testPlayer(const ESM::DialInfo& info) const // check player faction and rank if (!info.mPcFaction.empty()) { - std::map::const_iterator iter - = stats.getFactionRanks().find(Misc::StringUtils::lowerCase(info.mPcFaction)); + std::map::const_iterator iter + = stats.getFactionRanks().find(info.mPcFaction); if (iter == stats.getFactionRanks().end()) return false; @@ -180,8 +181,8 @@ bool MWDialogue::Filter::testPlayer(const ESM::DialInfo& info) const else if (info.mData.mPCrank != -1) { // required PC faction is not specified but PC rank is; use speaker's faction - std::map::const_iterator iter - = stats.getFactionRanks().find(Misc::StringUtils::lowerCase(mActor.getClass().getPrimaryFaction(mActor))); + std::map::const_iterator iter + = stats.getFactionRanks().find(mActor.getClass().getPrimaryFaction(mActor)); if (iter == stats.getFactionRanks().end()) return false; @@ -228,7 +229,7 @@ bool MWDialogue::Filter::testDisposition(const ESM::DialInfo& info, bool invert) bool MWDialogue::Filter::testFunctionLocal(const MWDialogue::SelectWrapper& select) const { - std::string_view scriptName = mActor.getClass().getScript(mActor); + const ESM::RefId& scriptName = mActor.getClass().getScript(mActor); if (scriptName.empty()) return false; // no script @@ -354,18 +355,18 @@ int MWDialogue::Filter::getSelectStructInteger(const SelectWrapper& select) cons { case SelectWrapper::Function_Journal: - return MWBase::Environment::get().getJournal()->getJournalIndex(select.getName()); + return MWBase::Environment::get().getJournal()->getJournalIndex(ESM::RefId::stringRefId(select.getName())); case SelectWrapper::Function_Item: { MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); - return store.count(select.getName()); + return store.count(ESM::RefId::stringRefId(select.getName())); } case SelectWrapper::Function_Dead: - return MWBase::Environment::get().getMechanicsManager()->countDeaths(select.getName()); + return MWBase::Environment::get().getMechanicsManager()->countDeaths(ESM::RefId::stringRefId(select.getName())); case SelectWrapper::Function_Choice: @@ -424,7 +425,7 @@ int MWDialogue::Filter::getSelectStructInteger(const SelectWrapper& select) cons case SelectWrapper::Function_RankRequirement: { - std::string_view faction = mActor.getClass().getPrimaryFaction(mActor); + const ESM::RefId& faction = mActor.getClass().getPrimaryFaction(mActor); if (faction.empty()) return 0; @@ -462,7 +463,7 @@ int MWDialogue::Filter::getSelectStructInteger(const SelectWrapper& select) cons case SelectWrapper::Function_FactionRankDiff: { - std::string_view faction = mActor.getClass().getPrimaryFaction(mActor); + const ESM::RefId& faction = mActor.getClass().getPrimaryFaction(mActor); if (faction.empty()) return 0; @@ -481,7 +482,7 @@ int MWDialogue::Filter::getSelectStructInteger(const SelectWrapper& select) cons { bool low = select.getFunction() == SelectWrapper::Function_RankLow; - std::string_view factionId = mActor.getClass().getPrimaryFaction(mActor); + const ESM::RefId& factionId = mActor.getClass().getPrimaryFaction(mActor); if (factionId.empty()) return 0; @@ -490,7 +491,7 @@ int MWDialogue::Filter::getSelectStructInteger(const SelectWrapper& select) cons MWMechanics::NpcStats& playerStats = player.getClass().getNpcStats(player); - std::map::const_iterator playerFactionIt = playerStats.getFactionRanks().begin(); + std::map::const_iterator playerFactionIt = playerStats.getFactionRanks().begin(); for (; playerFactionIt != playerStats.getFactionRanks().end(); ++playerFactionIt) { int reaction = MWBase::Environment::get().getDialogueManager()->getFactionReaction( @@ -535,19 +536,19 @@ bool MWDialogue::Filter::getSelectStructBoolean(const SelectWrapper& select) con case SelectWrapper::Function_NotId: - return !Misc::StringUtils::ciEqual(mActor.getCellRef().getRefId(), select.getName()); + return !ESM::RefId::ciEqual(mActor.getCellRef().getRefId(), ESM::RefId::stringRefId(select.getName())); case SelectWrapper::Function_NotFaction: - return !Misc::StringUtils::ciEqual(mActor.getClass().getPrimaryFaction(mActor), select.getName()); + return !ESM::RefId::ciEqual(mActor.getClass().getPrimaryFaction(mActor), ESM::RefId::stringRefId(select.getName())); case SelectWrapper::Function_NotClass: - return !Misc::StringUtils::ciEqual(mActor.get()->mBase->mClass, select.getName()); + return !ESM::RefId::ciEqual(mActor.get()->mBase->mClass, ESM::RefId::stringRefId(select.getName())); case SelectWrapper::Function_NotRace: - return !Misc::StringUtils::ciEqual(mActor.get()->mBase->mRace, select.getName()); + return !ESM::RefId::ciEqual(mActor.get()->mBase->mRace, ESM::RefId::stringRefId(select.getName())); case SelectWrapper::Function_NotCell: { @@ -561,7 +562,7 @@ bool MWDialogue::Filter::getSelectStructBoolean(const SelectWrapper& select) con case SelectWrapper::Function_SameRace: - return Misc::StringUtils::ciEqual( + return ESM::RefId::ciEqual( mActor.get()->mBase->mRace, player.get()->mBase->mRace); case SelectWrapper::Function_SameFaction: @@ -587,7 +588,7 @@ bool MWDialogue::Filter::getSelectStructBoolean(const SelectWrapper& select) con case SelectWrapper::Function_PcExpelled: { - std::string_view faction = mActor.getClass().getPrimaryFaction(mActor); + const ESM::RefId& faction = mActor.getClass().getPrimaryFaction(mActor); if (faction.empty()) return false; @@ -634,14 +635,14 @@ bool MWDialogue::Filter::getSelectStructBoolean(const SelectWrapper& select) con } } -int MWDialogue::Filter::getFactionRank(const MWWorld::Ptr& actor, std::string_view factionId) const +int MWDialogue::Filter::getFactionRank(const MWWorld::Ptr& actor, const ESM::RefId& factionId) const { MWMechanics::NpcStats& stats = actor.getClass().getNpcStats(actor); return stats.getFactionRank(factionId); } bool MWDialogue::Filter::hasFactionRankSkillRequirements( - const MWWorld::Ptr& actor, std::string_view factionId, int rank) const + const MWWorld::Ptr& actor, const ESM::RefId& factionId, int rank) const { if (rank < 0 || rank >= 10) throw std::runtime_error("rank index out of range"); @@ -659,7 +660,7 @@ bool MWDialogue::Filter::hasFactionRankSkillRequirements( } bool MWDialogue::Filter::hasFactionRankReputationRequirements( - const MWWorld::Ptr& actor, std::string_view factionId, int rank) const + const MWWorld::Ptr& actor, const ESM::RefId& factionId, int rank) const { if (rank < 0 || rank >= 10) throw std::runtime_error("rank index out of range"); @@ -726,7 +727,7 @@ std::vector MWDialogue::Filter::list( const MWWorld::Store& dialogues = MWBase::Environment::get().getWorld()->getStore().get(); - const ESM::Dialogue& infoRefusalDialogue = *dialogues.find("Info Refusal"); + const ESM::Dialogue& infoRefusalDialogue = *dialogues.find(ESM::RefId::stringRefId("Info Refusal")); for (ESM::Dialogue::InfoContainer::const_iterator iter = infoRefusalDialogue.mInfo.begin(); iter != infoRefusalDialogue.mInfo.end(); ++iter) diff --git a/apps/openmw/mwdialogue/filter.hpp b/apps/openmw/mwdialogue/filter.hpp index 7e384be4bf..c8918b36d1 100644 --- a/apps/openmw/mwdialogue/filter.hpp +++ b/apps/openmw/mwdialogue/filter.hpp @@ -9,6 +9,7 @@ namespace ESM { struct DialInfo; struct Dialogue; + struct RefId; } namespace MWDialogue @@ -43,12 +44,12 @@ namespace MWDialogue bool getSelectStructBoolean(const SelectWrapper& select) const; - int getFactionRank(const MWWorld::Ptr& actor, std::string_view factionId) const; + int getFactionRank(const MWWorld::Ptr& actor, const ESM::RefId& factionId) const; - bool hasFactionRankSkillRequirements(const MWWorld::Ptr& actor, std::string_view factionId, int rank) const; + bool hasFactionRankSkillRequirements(const MWWorld::Ptr& actor, const ESM::RefId& factionId, int rank) const; bool hasFactionRankReputationRequirements( - const MWWorld::Ptr& actor, std::string_view factionId, int rank) const; + const MWWorld::Ptr& actor,const ESM::RefId& factionId, int rank) const; public: Filter(const MWWorld::Ptr& actor, int choice, bool talkedToPlayer); diff --git a/apps/openmw/mwdialogue/journalentry.cpp b/apps/openmw/mwdialogue/journalentry.cpp index 162ca214fe..8095e368a9 100644 --- a/apps/openmw/mwdialogue/journalentry.cpp +++ b/apps/openmw/mwdialogue/journalentry.cpp @@ -15,7 +15,7 @@ namespace MWDialogue { - Entry::Entry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor) + Entry::Entry(const ESM::RefId& topic, const ESM::RefId& infoId, const MWWorld::Ptr& actor) : mInfoId(infoId) { const ESM::Dialogue* dialogue @@ -39,7 +39,7 @@ namespace MWDialogue return; } - throw std::runtime_error("unknown info ID " + mInfoId + " for topic " + std::string(topic)); + throw std::runtime_error("unknown info ID " + mInfoId.getRefIdString() + " for topic " + topic.getRefIdString()); } Entry::Entry(const ESM::JournalEntry& record) @@ -61,7 +61,7 @@ namespace MWDialogue entry.mActorName = mActorName; } - JournalEntry::JournalEntry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor) + JournalEntry::JournalEntry(const ESM::RefId& topic, const ESM::RefId& infoId, const MWWorld::Ptr& actor) : Entry(topic, infoId, actor) , mTopic(topic) { @@ -79,12 +79,12 @@ namespace MWDialogue entry.mTopic = mTopic; } - JournalEntry JournalEntry::makeFromQuest(std::string_view topic, int index) + JournalEntry JournalEntry::makeFromQuest(const ESM::RefId& topic, int index) { return JournalEntry(topic, idFromIndex(topic, index), MWWorld::Ptr()); } - std::string_view JournalEntry::idFromIndex(std::string_view topic, int index) + const ESM::RefId& JournalEntry::idFromIndex(const ESM::RefId& topic, int index) { const ESM::Dialogue* dialogue = MWBase::Environment::get().getWorld()->getStore().get().find(topic); @@ -96,7 +96,7 @@ namespace MWDialogue return iter->mId; } - throw std::runtime_error("unknown journal index for topic " + std::string(topic)); + throw std::runtime_error("unknown journal index for topic " + topic.getRefIdString()); } StampedJournalEntry::StampedJournalEntry() @@ -107,7 +107,7 @@ namespace MWDialogue } StampedJournalEntry::StampedJournalEntry( - std::string_view topic, std::string_view infoId, int day, int month, int dayOfMonth, const MWWorld::Ptr& actor) + const ESM::RefId& topic, const ESM::RefId& infoId, int day, int month, int dayOfMonth, const MWWorld::Ptr& actor) : JournalEntry(topic, infoId, actor) , mDay(day) , mMonth(month) @@ -131,7 +131,7 @@ namespace MWDialogue entry.mDayOfMonth = mDayOfMonth; } - StampedJournalEntry StampedJournalEntry::makeFromQuest(std::string_view topic, int index, const MWWorld::Ptr& actor) + StampedJournalEntry StampedJournalEntry::makeFromQuest(const ESM::RefId& topic, int index, const MWWorld::Ptr& actor) { int day = MWBase::Environment::get().getWorld()->getGlobalInt("dayspassed"); int month = MWBase::Environment::get().getWorld()->getGlobalInt("month"); diff --git a/apps/openmw/mwdialogue/journalentry.hpp b/apps/openmw/mwdialogue/journalentry.hpp index 4573981cb8..3bd9ddf2ba 100644 --- a/apps/openmw/mwdialogue/journalentry.hpp +++ b/apps/openmw/mwdialogue/journalentry.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace ESM { @@ -19,14 +20,14 @@ namespace MWDialogue /// \brief Basic quest/dialogue/topic entry struct Entry { - std::string mInfoId; + ESM::RefId mInfoId; std::string mText; std::string mActorName; // optional Entry() = default; /// actor is optional - Entry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor); + Entry(const ESM::RefId& topic, const ESM::RefId& infoId, const MWWorld::Ptr& actor); Entry(const ESM::JournalEntry& record); @@ -40,19 +41,19 @@ namespace MWDialogue /// Same as entry, but store TopicID struct JournalEntry : public Entry { - std::string mTopic; + ESM::RefId mTopic; JournalEntry() = default; - JournalEntry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor); + JournalEntry(const ESM::RefId& topic, const ESM::RefId& infoId, const MWWorld::Ptr& actor); JournalEntry(const ESM::JournalEntry& record); void write(ESM::JournalEntry& entry) const; - static JournalEntry makeFromQuest(std::string_view topic, int index); + static JournalEntry makeFromQuest(const ESM::RefId& topic, int index); - static std::string_view idFromIndex(std::string_view topic, int index); + static const ESM::RefId& idFromIndex(const ESM::RefId& topic, int index); }; /// \brief A quest entry with a timestamp. @@ -64,14 +65,14 @@ namespace MWDialogue StampedJournalEntry(); - StampedJournalEntry(std::string_view topic, std::string_view infoId, int day, int month, int dayOfMonth, + StampedJournalEntry(const ESM::RefId& topic, const ESM::RefId& infoId, int day, int month, int dayOfMonth, const MWWorld::Ptr& actor); StampedJournalEntry(const ESM::JournalEntry& record); void write(ESM::JournalEntry& entry) const; - static StampedJournalEntry makeFromQuest(std::string_view topic, int index, const MWWorld::Ptr& actor); + static StampedJournalEntry makeFromQuest(const ESM::RefId& topic, int index, const MWWorld::Ptr& actor); }; } diff --git a/apps/openmw/mwdialogue/journalimp.cpp b/apps/openmw/mwdialogue/journalimp.cpp index 6a6348ed58..31ecbe62dd 100644 --- a/apps/openmw/mwdialogue/journalimp.cpp +++ b/apps/openmw/mwdialogue/journalimp.cpp @@ -18,7 +18,7 @@ namespace MWDialogue { - Quest& Journal::getQuest(const std::string& id) + Quest& Journal::getQuest(const ESM::RefId& id) { TQuestContainer::iterator iter = mQuests.find(id); @@ -32,7 +32,7 @@ namespace MWDialogue return iter->second; } - Topic& Journal::getTopic(const std::string& id) + Topic& Journal::getTopic(const ESM::RefId& id) { TTopicContainer::iterator iter = mTopics.find(id); @@ -46,7 +46,7 @@ namespace MWDialogue return iter->second; } - bool Journal::isThere(const std::string& topicId, const std::string& infoId) const + bool Journal::isThere(const ESM::RefId& topicId, const ESM::RefId& infoId) const { if (const ESM::Dialogue* dialogue = MWBase::Environment::get().getWorld()->getStore().get().search(topicId)) @@ -72,10 +72,10 @@ namespace MWDialogue mTopics.clear(); } - void Journal::addEntry(const std::string& id, int index, const MWWorld::Ptr& actor) + void Journal::addEntry(const ESM::RefId& id, int index, const MWWorld::Ptr& actor) { // bail out if we already have heard this... - std::string_view infoId = JournalEntry::idFromIndex(id, index); + const ESM::RefId& infoId = JournalEntry::idFromIndex(id, index); for (TEntryIter i = mJournal.begin(); i != mJournal.end(); ++i) if (i->mTopic == id && i->mInfoId == infoId) { @@ -109,14 +109,14 @@ namespace MWDialogue } } - void Journal::setJournalIndex(const std::string& id, int index) + void Journal::setJournalIndex(const ESM::RefId& id, int index) { Quest& quest = getQuest(id); quest.setIndex(index); } - void Journal::addTopic(const std::string& topicId, const std::string& infoId, const MWWorld::Ptr& actor) + void Journal::addTopic(const ESM::RefId& topicId, const ESM::RefId& infoId, const MWWorld::Ptr& actor) { Topic& topic = getTopic(topicId); @@ -125,7 +125,7 @@ namespace MWDialogue topic.addEntry(entry); } - void Journal::removeLastAddedTopicResponse(const std::string& topicId, std::string_view actorName) + void Journal::removeLastAddedTopicResponse(const ESM::RefId& topicId, std::string_view actorName) { Topic& topic = getTopic(topicId); @@ -135,7 +135,7 @@ namespace MWDialogue mTopics.erase(mTopics.find(topicId)); // All responses removed -> remove topic } - int Journal::getJournalIndex(const std::string& id) const + int Journal::getJournalIndex(const ESM::RefId& id) const { TQuestContainer::const_iterator iter = mQuests.find(id); diff --git a/apps/openmw/mwdialogue/journalimp.hpp b/apps/openmw/mwdialogue/journalimp.hpp index 52d92f333a..a214c6f4ef 100644 --- a/apps/openmw/mwdialogue/journalimp.hpp +++ b/apps/openmw/mwdialogue/journalimp.hpp @@ -15,31 +15,31 @@ namespace MWDialogue TTopicContainer mTopics; private: - Quest& getQuest(const std::string& id); + Quest& getQuest(const ESM::RefId& id); - Topic& getTopic(const std::string& id); + Topic& getTopic(const ESM::RefId& id); - bool isThere(const std::string& topicId, const std::string& infoId = "") const; + bool isThere(const ESM::RefId& topicId, const ESM::RefId& infoId = ESM::RefId::sEmpty) const; public: Journal(); void clear() override; - void addEntry(const std::string& id, int index, const MWWorld::Ptr& actor) override; + void addEntry(const ESM::RefId& id, int index, const MWWorld::Ptr& actor) override; ///< Add a journal entry. /// @param actor Used as context for replacing of escape sequences (%name, etc). - void setJournalIndex(const std::string& id, int index) override; + void setJournalIndex(const ESM::RefId& id, int index) override; ///< Set the journal index without adding an entry. - int getJournalIndex(const std::string& id) const override; + int getJournalIndex(const ESM::RefId& id) const override; ///< Get the journal index. - void addTopic(const std::string& topicId, const std::string& infoId, const MWWorld::Ptr& actor) override; + void addTopic(const ESM::RefId& topicId, const ESM::RefId& infoId, const MWWorld::Ptr& actor) override; /// \note topicId must be lowercase - void removeLastAddedTopicResponse(const std::string& topicId, std::string_view actorName) override; + void removeLastAddedTopicResponse(const ESM::RefId& topicId, std::string_view actorName) override; ///< Removes the last topic response added for the given topicId and actor name. /// \note topicId must be lowercase diff --git a/apps/openmw/mwdialogue/quest.cpp b/apps/openmw/mwdialogue/quest.cpp index ae29b0bca8..fa696c2def 100644 --- a/apps/openmw/mwdialogue/quest.cpp +++ b/apps/openmw/mwdialogue/quest.cpp @@ -18,7 +18,7 @@ namespace MWDialogue { } - Quest::Quest(const std::string& topic) + Quest::Quest(const ESM::RefId& topic) : Topic(topic) , mIndex(0) , mFinished(false) @@ -75,7 +75,7 @@ namespace MWDialogue [&](const auto& info) { return info.mId == entry.mInfoId; }); if (info == dialogue->mInfo.end() || info->mData.mJournalIndex == -1) - throw std::runtime_error("unknown journal entry for topic " + mTopic); + throw std::runtime_error("unknown journal entry for topic " + mTopic.getRefIdString()); if (info->mQuestStatus == ESM::DialInfo::QS_Finished || info->mQuestStatus == ESM::DialInfo::QS_Restart) mFinished = info->mQuestStatus == ESM::DialInfo::QS_Finished; diff --git a/apps/openmw/mwdialogue/quest.hpp b/apps/openmw/mwdialogue/quest.hpp index b1cf178bf5..1976c46792 100644 --- a/apps/openmw/mwdialogue/quest.hpp +++ b/apps/openmw/mwdialogue/quest.hpp @@ -19,7 +19,7 @@ namespace MWDialogue public: Quest(); - Quest(const std::string& topic); + Quest(const ESM::RefId& topic); Quest(const ESM::QuestState& state); diff --git a/apps/openmw/mwdialogue/scripttest.cpp b/apps/openmw/mwdialogue/scripttest.cpp index e993f21d1b..07a303a5b9 100644 --- a/apps/openmw/mwdialogue/scripttest.cpp +++ b/apps/openmw/mwdialogue/scripttest.cpp @@ -42,7 +42,7 @@ namespace Compiler::Locals locals; - std::string_view actorScript = actor.getClass().getScript(actor); + const ESM::RefId& actorScript = actor.getClass().getScript(actor); if (!actorScript.empty()) { // grab local variables from actor's script, if available. diff --git a/apps/openmw/mwdialogue/topic.cpp b/apps/openmw/mwdialogue/topic.cpp index fd6ca7d015..d9caa0a41b 100644 --- a/apps/openmw/mwdialogue/topic.cpp +++ b/apps/openmw/mwdialogue/topic.cpp @@ -9,9 +9,9 @@ namespace MWDialogue { Topic::Topic() {} - Topic::Topic(const std::string& topic) + Topic::Topic(const ESM::RefId& topic) : mTopic(topic) - , mName(MWBase::Environment::get().getWorld()->getStore().get().find(topic)->mId) + , mName(MWBase::Environment::get().getWorld()->getStore().get().find(topic)->mId.getRefIdString()) { } @@ -20,7 +20,7 @@ namespace MWDialogue bool Topic::addEntry(const JournalEntry& entry) { if (entry.mTopic != mTopic) - throw std::runtime_error("topic does not match: " + mTopic); + throw std::runtime_error("topic does not match: " + mTopic.getRefIdString()); // bail out if we already have heard this for (Topic::TEntryIter it = mEntries.begin(); it != mEntries.end(); ++it) @@ -38,7 +38,7 @@ namespace MWDialogue mEntries.push_back(entry); } - std::string Topic::getTopic() const + ESM::RefId Topic::getTopic() const { return mTopic; } diff --git a/apps/openmw/mwdialogue/topic.hpp b/apps/openmw/mwdialogue/topic.hpp index c45992a763..79b59528fa 100644 --- a/apps/openmw/mwdialogue/topic.hpp +++ b/apps/openmw/mwdialogue/topic.hpp @@ -22,14 +22,14 @@ namespace MWDialogue typedef TEntryContainer::const_iterator TEntryIter; protected: - std::string mTopic; + ESM::RefId mTopic; std::string mName; TEntryContainer mEntries; public: Topic(); - Topic(const std::string& topic); + Topic(const ESM::RefId& topic); virtual ~Topic(); @@ -42,7 +42,7 @@ namespace MWDialogue ///< Add entry without checking for redundant entries or modifying the state of the /// topic otherwise - std::string getTopic() const; + ESM::RefId getTopic() const; virtual std::string_view getName() const; diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 238e8c3bc8..54f4e3cc0d 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -126,7 +126,7 @@ namespace MWGui winMgr->messageBox("#{sNotifyMessage6a}"); break; case MWMechanics::Alchemy::Result_Success: - winMgr->playSound("potion success"); + winMgr->playSound(ESM::RefId::stringRefId("potion success")); if (count == 1) winMgr->messageBox("#{sPotionSuccess}"); else @@ -136,7 +136,7 @@ namespace MWGui case MWMechanics::Alchemy::Result_NoEffects: case MWMechanics::Alchemy::Result_RandomFailure: winMgr->messageBox("#{sNotifyMessage8}"); - winMgr->playSound("potion fail"); + winMgr->playSound(ESM::RefId::stringRefId("potion fail")); break; } @@ -301,7 +301,7 @@ namespace MWGui { update(); - std::string_view sound = item.getClass().getUpSoundId(item); + const ESM::RefId& sound = item.getClass().getUpSoundId(item); MWBase::Environment::get().getWindowManager()->playSound(sound); } } diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index 5390705f93..3212b42ecc 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -23,8 +23,8 @@ namespace { - bool sortBirthSigns(const std::pair& left, - const std::pair& right) + bool sortBirthSigns(const std::pair& left, + const std::pair& right) { return left.second->mName.compare(right.second->mName) < 0; } @@ -83,20 +83,20 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mBirthList); // Show the current birthsign by default - const std::string& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); + const auto& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); if (!signId.empty()) setBirthId(signId); } - void BirthDialog::setBirthId(const std::string& birthId) + void BirthDialog::setBirthId(const ESM::RefId& birthId) { mCurrentBirthId = birthId; mBirthList->setIndexSelected(MyGUI::ITEM_NONE); size_t count = mBirthList->getItemCount(); for (size_t i = 0; i < count; ++i) { - if (Misc::StringUtils::ciEqual(*mBirthList->getItemDataAt(i), birthId)) + if (ESM::RefId::ciEqual(ESM::RefId::stringRefId(*mBirthList->getItemDataAt(i)), birthId)) { mBirthList->setIndexSelected(i); break; @@ -133,11 +133,11 @@ namespace MWGui if (_index == MyGUI::ITEM_NONE) return; - const std::string* birthId = mBirthList->getItemDataAt(_index); - if (Misc::StringUtils::ciEqual(mCurrentBirthId, *birthId)) + const ESM::RefId birthId = ESM::RefId::stringRefId(*mBirthList->getItemDataAt(_index)); + if (ESM::RefId::ciEqual(mCurrentBirthId, birthId)) return; - mCurrentBirthId = *birthId; + mCurrentBirthId = birthId; updateSpells(); } @@ -151,7 +151,7 @@ namespace MWGui = MWBase::Environment::get().getWorld()->getStore().get(); // sort by name - std::vector> birthSigns; + std::vector> birthSigns; for (const ESM::BirthSign& sign : signs) { @@ -168,7 +168,7 @@ namespace MWGui mBirthList->setIndexSelected(index); mCurrentBirthId = birthsignPair.first; } - else if (Misc::StringUtils::ciEqual(birthsignPair.first, mCurrentBirthId)) + else if (ESM::RefId::ciEqual(birthsignPair.first, mCurrentBirthId)) { mBirthList->setIndexSelected(index); } @@ -199,13 +199,13 @@ namespace MWGui mBirthImage->setImageTexture(Misc::ResourceHelpers::correctTexturePath( birth->mTexture, MWBase::Environment::get().getResourceSystem()->getVFS())); - std::vector abilities, powers, spells; + std::vector abilities, powers, spells; - std::vector::const_iterator it = birth->mPowers.mList.begin(); - std::vector::const_iterator end = birth->mPowers.mList.end(); + std::vector::const_iterator it = birth->mPowers.mList.begin(); + std::vector::const_iterator end = birth->mPowers.mList.end(); for (; it != end; ++it) { - const std::string& spellId = *it; + const ESM::RefId& spellId = *it; const ESM::Spell* spell = store.get().search(spellId); if (!spell) continue; // Skip spells which cannot be found @@ -225,7 +225,7 @@ namespace MWGui struct { - const std::vector& spells; + const std::vector& spells; const char* label; } categories[3] = { { abilities, "sBirthsignmenu1" }, { powers, "sPowers" }, { spells, "sBirthsignmenu2" } }; @@ -243,7 +243,7 @@ namespace MWGui end = categories[category].spells.end(); for (it = categories[category].spells.begin(); it != end; ++it) { - const std::string& spellId = *it; + const ESM::RefId& spellId = *it; spellWidget = mSpellArea->createWidget("MW_StatName", coord, MyGUI::Align::Default, std::string("Spell") + MyGUI::utility::toString(i)); spellWidget->setSpellId(spellId); diff --git a/apps/openmw/mwgui/birth.hpp b/apps/openmw/mwgui/birth.hpp index edf2db2351..5afc5e16e0 100644 --- a/apps/openmw/mwgui/birth.hpp +++ b/apps/openmw/mwgui/birth.hpp @@ -2,6 +2,7 @@ #define MWGUI_BIRTH_H #include "windowbase.hpp" +#include namespace MWGui { @@ -16,8 +17,8 @@ namespace MWGui GM_Female }; - const std::string& getBirthId() const { return mCurrentBirthId; } - void setBirthId(const std::string& raceId); + const ESM::RefId& getBirthId() const { return mCurrentBirthId; } + void setBirthId(const ESM::RefId& raceId); void setNextButtonShow(bool shown); void onOpen() override; @@ -53,7 +54,7 @@ namespace MWGui MyGUI::ImageBox* mBirthImage; std::vector mSpellItems; - std::string mCurrentBirthId; + ESM::RefId mCurrentBirthId; }; } #endif diff --git a/apps/openmw/mwgui/bookwindow.cpp b/apps/openmw/mwgui/bookwindow.cpp index ee6f12ffb3..498a52c6d4 100644 --- a/apps/openmw/mwgui/bookwindow.cpp +++ b/apps/openmw/mwgui/bookwindow.cpp @@ -131,7 +131,7 @@ namespace MWGui void BookWindow::onTakeButtonClicked(MyGUI::Widget* sender) { - MWBase::Environment::get().getWindowManager()->playSound("Item Book Up"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Book Up")); MWWorld::ActionTake take(mBook); take.execute(MWMechanics::getPlayer()); @@ -191,7 +191,7 @@ namespace MWGui { if ((mCurrentPage + 1) * 2 < mPages.size()) { - MWBase::Environment::get().getWindowManager()->playSound("book page2"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page2")); ++mCurrentPage; @@ -202,7 +202,7 @@ namespace MWGui { if (mCurrentPage > 0) { - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); --mCurrentPage; diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index de71aed1f6..b16d09305f 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -101,7 +101,7 @@ namespace MWGui mPlayerSkillValues.emplace(ESM::Skill::sSkillIds[i], MWMechanics::SkillValue()); } - void CharacterCreation::setValue(const std::string& id, const MWMechanics::AttributeValue& value) + void CharacterCreation::setValue(const ESM::RefId& id, const MWMechanics::AttributeValue& value) { static const char* ids[] = { "AttribVal1", @@ -117,7 +117,7 @@ namespace MWGui for (int i = 0; ids[i]; ++i) { - if (ids[i] == id) + if (ids[i] == id.getRefIdString()) { mPlayerAttributes[static_cast(i)] = value; if (mReviewDialog) @@ -128,19 +128,19 @@ namespace MWGui } } - void CharacterCreation::setValue(const std::string& id, const MWMechanics::DynamicStat& value) + void CharacterCreation::setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) { if (mReviewDialog) { - if (id == "HBar") + if (id.getRefIdString() == "HBar") { mReviewDialog->setHealth(value); } - else if (id == "MBar") + else if (id.getRefIdString() == "MBar") { mReviewDialog->setMagicka(value); } - else if (id == "FBar") + else if (id.getRefIdString() == "FBar") { mReviewDialog->setFatigue(value); } @@ -349,7 +349,7 @@ namespace MWGui { if (mPickClassDialog) { - const std::string& classId = mPickClassDialog->getClassId(); + const ESM::RefId& classId = mPickClassDialog->getClassId(); if (!classId.empty()) MWBase::Environment::get().getMechanicsManager()->setPlayerClass(classId); @@ -551,96 +551,96 @@ namespace MWGui unsigned combat = mGenerateClassSpecializations[0]; unsigned magic = mGenerateClassSpecializations[1]; unsigned stealth = mGenerateClassSpecializations[2]; - + std::string className; if (combat > 7) { - mGenerateClass = "Warrior"; + className = "Warrior"; } else if (magic > 7) { - mGenerateClass = "Mage"; + className = "Mage"; } else if (stealth > 7) { - mGenerateClass = "Thief"; + className = "Thief"; } else { switch (combat) { case 4: - mGenerateClass = "Rogue"; + className = "Rogue"; break; case 5: if (stealth == 3) - mGenerateClass = "Scout"; + className = "Scout"; else - mGenerateClass = "Archer"; + className = "Archer"; break; case 6: if (stealth == 1) - mGenerateClass = "Barbarian"; + className = "Barbarian"; else if (stealth == 3) - mGenerateClass = "Crusader"; + className = "Crusader"; else - mGenerateClass = "Knight"; + className = "Knight"; break; case 7: - mGenerateClass = "Warrior"; + className = "Warrior"; break; default: switch (magic) { case 4: - mGenerateClass = "Spellsword"; + className = "Spellsword"; break; case 5: - mGenerateClass = "Witchhunter"; + className = "Witchhunter"; break; case 6: if (combat == 2) - mGenerateClass = "Sorcerer"; + className = "Sorcerer"; else if (combat == 3) - mGenerateClass = "Healer"; + className = "Healer"; else - mGenerateClass = "Battlemage"; + className = "Battlemage"; break; case 7: - mGenerateClass = "Mage"; + className = "Mage"; break; default: switch (stealth) { case 3: if (magic == 3) - mGenerateClass = "Bard"; // unreachable + className = "Bard"; // unreachable else - mGenerateClass = "Warrior"; + className = "Warrior"; break; case 5: if (magic == 3) - mGenerateClass = "Monk"; + className = "Monk"; else - mGenerateClass = "Pilgrim"; + className = "Pilgrim"; break; case 6: if (magic == 1) - mGenerateClass = "Agent"; + className = "Agent"; else if (magic == 3) - mGenerateClass = "Assassin"; + className = "Assassin"; else - mGenerateClass = "Acrobat"; + className = "Acrobat"; break; case 7: - mGenerateClass = "Thief"; + className = "Thief"; break; default: - mGenerateClass = "Warrior"; + className = "Warrior"; } } } } - + mGenerateClass = ESM::RefId::stringRefId(className); MWBase::Environment::get().getWindowManager()->removeDialog(std::move(mGenerateClassResultDialog)); mGenerateClassResultDialog = std::make_unique(); diff --git a/apps/openmw/mwgui/charactercreation.hpp b/apps/openmw/mwgui/charactercreation.hpp index 3780efbd6b..cd03e2e51d 100644 --- a/apps/openmw/mwgui/charactercreation.hpp +++ b/apps/openmw/mwgui/charactercreation.hpp @@ -46,8 +46,8 @@ namespace MWGui // Show a dialog void spawnDialog(const char id); - void setValue(const std::string& id, const MWMechanics::AttributeValue& value) override; - void setValue(const std::string& id, const MWMechanics::DynamicStat& value) override; + void setValue(const ESM::RefId& id, const MWMechanics::AttributeValue& value) override; + void setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) override; void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::SkillValue& value) override; void configureSkills(const SkillList& major, const SkillList& minor) override; @@ -74,8 +74,8 @@ namespace MWGui // Player data std::string mPlayerName; - std::string mPlayerRaceId; - std::string mPlayerBirthSignId; + ESM::RefId mPlayerRaceId; + ESM::RefId mPlayerBirthSignId; ESM::Class mPlayerClass; // Class generation vars @@ -83,7 +83,7 @@ namespace MWGui ESM::Class::Specialization mGenerateClassResponses[3]; unsigned mGenerateClassSpecializations[3]; // A counter for each specialization which is increased when an // answer is chosen - std::string mGenerateClass; // In order: Combat, Magic, Stealth + ESM::RefId mGenerateClass; // In order: Combat, Magic, Stealth ////Dialog events // Name dialog diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index ec5ec75eef..3a3fafdbe1 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -24,7 +24,7 @@ namespace { - bool sortClasses(const std::pair& left, const std::pair& right) + bool sortClasses(const std::pair& left, const std::pair& right) { return left.second.compare(right.second) < 0; } @@ -58,7 +58,7 @@ namespace MWGui center(); } - void GenerateClassResultDialog::setClassId(const std::string& classId) + void GenerateClassResultDialog::setClassId(const ESM::RefId& classId) { mCurrentClassId = classId; @@ -144,20 +144,20 @@ namespace MWGui // Show the current class by default MWWorld::Ptr player = MWMechanics::getPlayer(); - const std::string& classId = player.get()->mBase->mClass; + const ESM::RefId& classId = player.get()->mBase->mClass; if (!classId.empty()) setClassId(classId); } - void PickClassDialog::setClassId(const std::string& classId) + void PickClassDialog::setClassId(const ESM::RefId& classId) { mCurrentClassId = classId; mClassList->setIndexSelected(MyGUI::ITEM_NONE); size_t count = mClassList->getItemCount(); for (size_t i = 0; i < count; ++i) { - if (Misc::StringUtils::ciEqual(*mClassList->getItemDataAt(i), classId)) + if (ESM::RefId::ciEqual(*mClassList->getItemDataAt(i), classId)) { mClassList->setIndexSelected(i); break; @@ -194,8 +194,8 @@ namespace MWGui if (_index == MyGUI::ITEM_NONE) return; - const std::string* classId = mClassList->getItemDataAt(_index); - if (Misc::StringUtils::ciEqual(mCurrentClassId, *classId)) + const ESM::RefId* classId = mClassList->getItemDataAt(_index); + if (ESM::RefId::ciEqual(mCurrentClassId, *classId)) return; mCurrentClassId = *classId; @@ -210,7 +210,7 @@ namespace MWGui const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); - std::vector> items; // class id, class name + std::vector> items; // class id, class name for (const ESM::Class& classInfo : store.get()) { bool playable = (classInfo.mData.mIsPlayable != 0); @@ -227,14 +227,14 @@ namespace MWGui int index = 0; for (auto& itemPair : items) { - const std::string& id = itemPair.first; + const ESM::RefId& id = itemPair.first; mClassList->addItem(itemPair.second, id); if (mCurrentClassId.empty()) { mCurrentClassId = id; mClassList->setIndexSelected(index); } - else if (Misc::StringUtils::ciEqual(id, mCurrentClassId)) + else if (ESM::RefId::ciEqual(id, mCurrentClassId)) { mClassList->setIndexSelected(index); } @@ -889,14 +889,14 @@ namespace MWGui eventDone(this); } - void setClassImage(MyGUI::ImageBox* imageBox, const std::string& classId) + void setClassImage(MyGUI::ImageBox* imageBox, const ESM::RefId& classId) { const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); std::string classImage - = Misc::ResourceHelpers::correctTexturePath("textures\\levelup\\" + classId + ".dds", vfs); + = Misc::ResourceHelpers::correctTexturePath("textures\\levelup\\" + classId.getRefIdString() + ".dds", vfs); if (!vfs->exists(classImage)) { - Log(Debug::Warning) << "No class image for " << classId << ", falling back to default"; + Log(Debug::Warning) << "No class image for " << classId.getRefIdString() << ", falling back to default"; classImage = "textures\\levelup\\warrior.dds"; } imageBox->setImageTexture(classImage); diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index b88d51b15f..dd66632784 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include "widgets.hpp" @@ -13,7 +14,7 @@ namespace MWGui { - void setClassImage(MyGUI::ImageBox* imageBox, const std::string& classId); + void setClassImage(MyGUI::ImageBox* imageBox, const ESM::RefId& classId); class InfoBoxDialog : public WindowModal { @@ -70,7 +71,7 @@ namespace MWGui public: GenerateClassResultDialog(); - void setClassId(const std::string& classId); + void setClassId(const ESM::RefId& classId); bool exit() override { return false; } @@ -95,7 +96,7 @@ namespace MWGui MyGUI::ImageBox* mClassImage; MyGUI::TextBox* mClassName; - std::string mCurrentClassId; + ESM::RefId mCurrentClassId; }; class PickClassDialog : public WindowModal @@ -103,8 +104,8 @@ namespace MWGui public: PickClassDialog(); - const std::string& getClassId() const { return mCurrentClassId; } - void setClassId(const std::string& classId); + const ESM::RefId& getClassId() const { return mCurrentClassId; } + void setClassId(const ESM::RefId& classId); void setNextButtonShow(bool shown); void onOpen() override; @@ -142,7 +143,7 @@ namespace MWGui Widgets::MWSkillPtr mMajorSkill[5]; Widgets::MWSkillPtr mMinorSkill[5]; - std::string mCurrentClassId; + ESM::RefId mCurrentClassId; }; class SelectSpecializationDialog : public WindowModal diff --git a/apps/openmw/mwgui/companionitemmodel.cpp b/apps/openmw/mwgui/companionitemmodel.cpp index 1f3f7558ed..1172de5897 100644 --- a/apps/openmw/mwgui/companionitemmodel.cpp +++ b/apps/openmw/mwgui/companionitemmodel.cpp @@ -7,7 +7,7 @@ namespace void modifyProfit(const MWWorld::Ptr& actor, int diff) { - std::string_view script = actor.getClass().getScript(actor); + const ESM::RefId& script = actor.getClass().getScript(actor); if (!script.empty()) { int profit = actor.getRefData().getLocals().getIntVar(script, "minimumprofit"); @@ -43,7 +43,7 @@ namespace MWGui bool CompanionItemModel::hasProfit(const MWWorld::Ptr& actor) { - std::string_view script = actor.getClass().getScript(actor); + const ESM::RefId& script = actor.getClass().getScript(actor); if (script.empty()) return false; return actor.getRefData().getLocals().hasVar(script, "minimumprofit"); diff --git a/apps/openmw/mwgui/companionwindow.cpp b/apps/openmw/mwgui/companionwindow.cpp index d8b71b2ee9..5f2bb85606 100644 --- a/apps/openmw/mwgui/companionwindow.cpp +++ b/apps/openmw/mwgui/companionwindow.cpp @@ -25,7 +25,7 @@ namespace int getProfit(const MWWorld::Ptr& actor) { - std::string_view script = actor.getClass().getScript(actor); + const ESM::RefId& script = actor.getClass().getScript(actor); if (!script.empty()) { return actor.getRefData().getLocals().getIntVar(script, "minimumprofit"); diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index 7a89227030..cb8208fd0f 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -105,10 +105,15 @@ namespace MWGui // identifier const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); - + std::vector ids; for (MWWorld::ESMStore::iterator it = store.begin(); it != store.end(); ++it) { - (*it)->listIdentifier(mNames); + (*it)->listIdentifier(ids); + for (auto id : ids) + { + mNames.push_back(id.getRefIdString()); + } + ids.clear(); } // exterior cell names aren't technically identifiers, but since the COC function accepts them, @@ -190,7 +195,7 @@ namespace MWGui Compiler::Locals locals; if (!mPtr.isEmpty()) { - std::string_view script = mPtr.getClass().getScript(mPtr); + const ESM::RefId& script = mPtr.getClass().getScript(mPtr); if (!script.empty()) locals = MWBase::Environment::get().getScriptManager()->getLocals(script); } @@ -529,7 +534,7 @@ namespace MWGui if (!mConsoleMode.empty()) title = mConsoleMode + " " + title; if (!mPtr.isEmpty()) - title.append(" (" + mPtr.getCellRef().getRefId() + ")"); + title.append(" (" + mPtr.getCellRef().getRefId().getRefIdString() + ")"); setTitle(title); } diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index ecfadf3675..578709705d 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -223,7 +223,7 @@ namespace MWGui { // play the sound of the first object MWWorld::Ptr item = mModel->getItem(i).mBase; - std::string_view sound = item.getClass().getUpSoundId(item); + const ESM::RefId& sound = item.getClass().getUpSoundId(item); MWBase::Environment::get().getWindowManager()->playSound(sound); } @@ -261,7 +261,7 @@ namespace MWGui creatureStats.setDeathAnimationFinished(true); MWBase::Environment::get().getMechanicsManager()->notifyDied(ptr); - std::string_view script = ptr.getClass().getScript(ptr); + const ESM::RefId& script = ptr.getClass().getScript(ptr); if (!script.empty() && MWBase::Environment::get().getWorld()->getScriptsEnabled()) { MWScript::InterpreterContext interpreterContext(&ptr.getRefData().getLocals(), ptr); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index a07d261437..f6d0513ac1 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -278,19 +278,19 @@ namespace MWGui void Choice::activated() { - MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); eventChoiceActivated(mChoiceId); } void Topic::activated() { - MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); eventTopicActivated(mTopicId); } void Goodbye::activated() { - MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); eventActivated(); } @@ -791,7 +791,7 @@ namespace MWGui for (const std::string& keyword : mKeywords) { - int flag = MWBase::Environment::get().getDialogueManager()->getTopicFlag(keyword); + int flag = MWBase::Environment::get().getDialogueManager()->getTopicFlag(ESM::RefId::stringRefId(keyword)); MyGUI::Button* button = mTopicsList->getItemWidget(keyword); if (!specialColour.empty() && flag & MWBase::DialogueManager::TopicType::Specific) diff --git a/apps/openmw/mwgui/draganddrop.cpp b/apps/openmw/mwgui/draganddrop.cpp index a8c63337c2..626148c8c3 100644 --- a/apps/openmw/mwgui/draganddrop.cpp +++ b/apps/openmw/mwgui/draganddrop.cpp @@ -63,7 +63,7 @@ namespace MWGui mSourceSortModel = playerFilterModel; } - std::string_view sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase); + const ESM::RefId& sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase); MWBase::Environment::get().getWindowManager()->playSound(sound); if (mSourceSortModel) @@ -95,7 +95,7 @@ namespace MWGui void DragAndDrop::drop(ItemModel* targetModel, ItemView* targetView) { - std::string_view sound = mItem.mBase.getClass().getDownSoundId(mItem.mBase); + const ESM::RefId& sound = mItem.mBase.getClass().getDownSoundId(mItem.mBase); MWBase::Environment::get().getWindowManager()->playSound(sound); // We can't drop a conjured item to the ground; the target container should always be the source container diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index d12f1ce6ab..0fb5e89882 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -364,13 +364,13 @@ namespace MWGui if (result == 1) { - MWBase::Environment::get().getWindowManager()->playSound("enchant success"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("enchant success")); MWBase::Environment::get().getWindowManager()->messageBox("#{sEnchantmentMenu12}"); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Enchanting); } else { - MWBase::Environment::get().getWindowManager()->playSound("enchant fail"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("enchant fail")); MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage34}"); if (!mEnchanting.getGem().isEmpty() && !mEnchanting.getGem().getRefData().getCount()) { diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 0b33668920..ed634158da 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -54,7 +54,7 @@ namespace MWGui dropped = world->placeObject(item.mBase, mLeft, mTop, count); else dropped = world->dropObjectOnGround(world->getPlayerPtr(), item.mBase, count); - dropped.getCellRef().setOwner(""); + dropped.getCellRef().setOwner(ESM::RefId::sEmpty); return dropped; } @@ -181,32 +181,32 @@ namespace MWGui mMainWidget->eventMouseButtonClick.clear(); } - void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat& value) + void HUD::setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) { int current = static_cast(value.getCurrent()); int modified = static_cast(value.getModified()); - + const std::string idString = id.getRefIdString(); // Fatigue can be negative - if (id != "FBar") + if (idString != "FBar") current = std::max(0, current); MyGUI::Widget* w; std::string valStr = MyGUI::utility::toString(current) + " / " + MyGUI::utility::toString(modified); - if (id == "HBar") + if (idString == "HBar") { mHealth->setProgressRange(std::max(0, modified)); mHealth->setProgressPosition(std::max(0, current)); getWidget(w, "HealthFrame"); w->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr); } - else if (id == "MBar") + else if (idString == "MBar") { mMagicka->setProgressRange(std::max(0, modified)); mMagicka->setProgressPosition(std::max(0, current)); getWidget(w, "MagickaFrame"); w->setUserString("Caption_HealthDescription", "#{sMagDesc}\n" + valStr); } - else if (id == "FBar") + else if (idString == "FBar") { mStamina->setProgressRange(std::max(0, modified)); mStamina->setProgressPosition(std::max(0, current)); @@ -393,7 +393,7 @@ namespace MWGui } } - void HUD::setSelectedSpell(const std::string& spellId, int successChancePercent) + void HUD::setSelectedSpell(const ESM::RefId& spellId, int successChancePercent) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); @@ -410,7 +410,7 @@ namespace MWGui mSpellStatus->setProgressPosition(successChancePercent); mSpellBox->setUserString("ToolTipType", "Spell"); - mSpellBox->setUserString("Spell", spellId); + mSpellBox->setUserString("Spell", spellId.getRefIdString()); // use the icon of the first effect const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().get().find( diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index 3285aa307f..eb46e9e44a 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -23,7 +23,7 @@ namespace MWGui public: HUD(CustomMarkerCollection& customMarkers, DragAndDrop* dragAndDrop, MWRender::LocalMap* localMapRender); virtual ~HUD(); - void setValue(const std::string& id, const MWMechanics::DynamicStat& value) override; + void setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) override; /// Set time left for the player to start drowning /// @param time time left to start drowning @@ -39,7 +39,7 @@ namespace MWGui void setEffectVisible(bool visible); void setMinimapVisible(bool visible); - void setSelectedSpell(const std::string& spellId, int successChancePercent); + void setSelectedSpell(const ESM::RefId& spellId, int successChancePercent); void setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent); const MWWorld::Ptr& getSelectedEnchantItem(); void setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 7deb91455c..d939f46ff7 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -250,7 +250,7 @@ namespace MWGui } const ItemStack& item = mTradeModel->getItem(index); - std::string_view sound = item.mBase.getClass().getDownSoundId(item.mBase); + const ESM::RefId& sound = item.mBase.getClass().getDownSoundId(item.mBase); MWWorld::Ptr object = item.mBase; int count = item.mCount; @@ -360,7 +360,7 @@ namespace MWGui { ensureSelectedItemUnequipped(count); const ItemStack& item = mTradeModel->getItem(mSelectedItem); - std::string_view sound = item.mBase.getClass().getUpSoundId(item.mBase); + const ESM::RefId& sound = item.mBase.getClass().getUpSoundId(item.mBase); MWBase::Environment::get().getWindowManager()->playSound(sound); if (item.mType == ItemStack::Type_Barter) @@ -518,7 +518,7 @@ namespace MWGui void InventoryWindow::useItem(const MWWorld::Ptr& ptr, bool force) { - std::string_view script = ptr.getClass().getScript(ptr); + const ESM::RefId& script = ptr.getClass().getScript(ptr); if (!script.empty()) { // Don't try to equip the item if PCSkipEquip is set to 1 @@ -792,7 +792,7 @@ namespace MWGui int incr = next ? 1 : -1; bool found = false; - std::string_view lastId; + ESM::RefId lastId; if (selected != -1) lastId = model.getItem(selected).mBase.getCellRef().getRefId(); ItemModel::ModelIndex cycled = selected; @@ -805,7 +805,7 @@ namespace MWGui // skip different stacks of the same item, or we will get stuck as stacking/unstacking them may change their // relative ordering - if (Misc::StringUtils::ciEqual(lastId, item.getCellRef().getRefId())) + if (ESM::RefId::ciEqual(lastId, item.getCellRef().getRefId())) continue; lastId = item.getCellRef().getRefId(); diff --git a/apps/openmw/mwgui/itemchargeview.cpp b/apps/openmw/mwgui/itemchargeview.cpp index b7dc441b49..aab52173a7 100644 --- a/apps/openmw/mwgui/itemchargeview.cpp +++ b/apps/openmw/mwgui/itemchargeview.cpp @@ -190,7 +190,7 @@ namespace MWGui line.mItemPtr.getClass().getItemMaxHealth(line.mItemPtr)); break; case DisplayMode_EnchantmentCharge: - std::string_view enchId = line.mItemPtr.getClass().getEnchantment(line.mItemPtr); + const ESM::RefId& enchId = line.mItemPtr.getClass().getEnchantment(line.mItemPtr); if (enchId.empty()) break; const ESM::Enchantment* ench diff --git a/apps/openmw/mwgui/jailscreen.cpp b/apps/openmw/mwgui/jailscreen.cpp index 7d791afc08..263780fb21 100644 --- a/apps/openmw/mwgui/jailscreen.cpp +++ b/apps/openmw/mwgui/jailscreen.cpp @@ -58,7 +58,7 @@ namespace MWGui if (mFadeTimeRemaining <= 0) { MWWorld::Ptr player = MWMechanics::getPlayer(); - MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker"); + MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, ESM::RefId::stringRefId("prisonmarker")); MWBase::Environment::get().getWindowManager()->fadeScreenOut( 0.f); // override fade-in caused by cell transition diff --git a/apps/openmw/mwgui/journalviewmodel.cpp b/apps/openmw/mwgui/journalviewmodel.cpp index 80e58a784a..ee3ce77245 100644 --- a/apps/openmw/mwgui/journalviewmodel.cpp +++ b/apps/openmw/mwgui/journalviewmodel.cpp @@ -56,7 +56,7 @@ namespace MWGui MWBase::Journal* journal = MWBase::Environment::get().getJournal(); for (MWBase::Journal::TTopicIter i = journal->topicBegin(); i != journal->topicEnd(); ++i) - mKeywordSearch.seed(i->first, intptr_t(&i->second)); + mKeywordSearch.seed(i->first.getRefIdString(), intptr_t(&i->second)); mKeywordSearchLoaded = true; } @@ -312,7 +312,7 @@ namespace MWGui for (MWBase::Journal::TTopicIter i = journal->topicBegin(); i != journal->topicEnd(); ++i) { - Utf8Stream stream(i->first.c_str()); + Utf8Stream stream(i->first.getRefIdString().c_str()); Utf8Stream::UnicodeChar first = Utf8Stream::toLowerUtf8(stream.peek()); if (first != Utf8Stream::toLowerUtf8(character)) diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index 729e29edf3..506191b18e 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -119,8 +119,8 @@ namespace Gui::MWList* list = getWidget(QuestsList); list->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyQuestClicked); - Gui::MWList* topicsList = getWidget(TopicsList); - topicsList->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyTopicSelected); + //Gui::MWList* topicsList = getWidget(TopicsList); + //topicsList->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyTopicSelected); { MWGui::BookPage::ClickCallback callback; @@ -413,16 +413,16 @@ namespace mOptionsMode = false; mTopicsMode = false; - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); } - void notifyTopicSelected(const std::string& topic, int id) + void notifyTopicSelected(const ESM::RefId& topic, int id) { const MWBase::Journal* journal = MWBase::Environment::get().getJournal(); intptr_t topicId = 0; /// \todo get rid of intptr ids for (MWBase::Journal::TTopicIter i = journal->topicBegin(); i != journal->topicEnd(); ++i) { - if (Misc::StringUtils::ciEqual(i->first, topic)) + if (ESM::RefId::ciEqual(i->first, topic)) topicId = intptr_t(&i->second); } @@ -444,7 +444,7 @@ namespace mOptionsMode = false; - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); } void notifyOptions(MyGUI::Widget* _sender) @@ -472,7 +472,7 @@ namespace assert(mStates.size() > 1); popBook(); - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); } void notifyIndexLinkClicked(MWGui::TypesetBook::InteractiveId index) @@ -493,7 +493,7 @@ namespace list->adjustSize(); - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); } void notifyTopics(MyGUI::Widget* _sender) @@ -508,7 +508,7 @@ namespace setVisible(ShowAllBTN, false); setVisible(ShowActiveBTN, false); - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); } struct AddNamesToList @@ -565,7 +565,7 @@ namespace mModel->visitQuestNames(false, setInactive); } - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); } void notifyShowAll(MyGUI::Widget* _sender) @@ -589,14 +589,14 @@ namespace else { setBookMode(); - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); } } void notifyClose(MyGUI::Widget* _sender) { MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); - winMgr->playSound("book close"); + winMgr->playSound(ESM::RefId::stringRefId("book close")); winMgr->popGuiMode(); } @@ -619,7 +619,7 @@ namespace if (page + 2 < book->pageCount()) { - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); page += 2; updateShowingPages(); @@ -637,7 +637,7 @@ namespace if (page >= 2) { - MWBase::Environment::get().getWindowManager()->playSound("book page"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("book page")); page -= 2; updateShowingPages(); diff --git a/apps/openmw/mwgui/levelupdialog.cpp b/apps/openmw/mwgui/levelupdialog.cpp index 7c41c8865f..2d0c6d372a 100644 --- a/apps/openmw/mwgui/levelupdialog.cpp +++ b/apps/openmw/mwgui/levelupdialog.cpp @@ -134,8 +134,8 @@ namespace MWGui MWMechanics::NpcStats& pcStats = player.getClass().getNpcStats(player); setClassImage(mClassImage, - getLevelupClassImage(pcStats.getSkillIncreasesForSpecialization(0), - pcStats.getSkillIncreasesForSpecialization(1), pcStats.getSkillIncreasesForSpecialization(2))); + ESM::RefId::stringRefId(getLevelupClassImage(pcStats.getSkillIncreasesForSpecialization(0), + pcStats.getSkillIncreasesForSpecialization(1), pcStats.getSkillIncreasesForSpecialization(2)))); int level = creatureStats.getLevel() + 1; mLevelText->setCaptionWithReplacing("#{sLevelUpMenu1} " + MyGUI::utility::toString(level)); diff --git a/apps/openmw/mwgui/mainmenu.cpp b/apps/openmw/mwgui/mainmenu.cpp index 850acf8090..e417a495b6 100644 --- a/apps/openmw/mwgui/mainmenu.cpp +++ b/apps/openmw/mwgui/mainmenu.cpp @@ -89,7 +89,7 @@ namespace MWGui MWBase::WindowManager* winMgr = MWBase::Environment::get().getWindowManager(); const std::string& name = *sender->getUserData(); - winMgr->playSound("Menu Click"); + winMgr->playSound(ESM::RefId::stringRefId("Menu Click")); if (name == "return") { winMgr->removeGuiMode(GM_MainMenu); diff --git a/apps/openmw/mwgui/merchantrepair.cpp b/apps/openmw/mwgui/merchantrepair.cpp index 208127a606..1a728deea5 100644 --- a/apps/openmw/mwgui/merchantrepair.cpp +++ b/apps/openmw/mwgui/merchantrepair.cpp @@ -134,7 +134,7 @@ namespace MWGui player.getClass().getContainerStore(player).restack(item); - MWBase::Environment::get().getWindowManager()->playSound("Repair"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Repair")); player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price, player); diff --git a/apps/openmw/mwgui/pickpocketitemmodel.cpp b/apps/openmw/mwgui/pickpocketitemmodel.cpp index cfa832fd7f..0a9ae43e08 100644 --- a/apps/openmw/mwgui/pickpocketitemmodel.cpp +++ b/apps/openmw/mwgui/pickpocketitemmodel.cpp @@ -100,7 +100,7 @@ namespace MWGui if (pickpocket.finish()) { MWBase::Environment::get().getMechanicsManager()->commitCrime( - player, mActor, MWBase::MechanicsManager::OT_Pickpocket, std::string(), 0, true); + player, mActor, MWBase::MechanicsManager::OT_Pickpocket, ESM::RefId::sEmpty, 0, true); MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container); mPickpocketDetected = true; } @@ -128,7 +128,7 @@ namespace MWGui if (pickpocket.pick(item, count)) { MWBase::Environment::get().getMechanicsManager()->commitCrime( - player, mActor, MWBase::MechanicsManager::OT_Pickpocket, std::string(), 0, true); + player, mActor, MWBase::MechanicsManager::OT_Pickpocket, ESM::RefId::sEmpty, 0, true); MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container); mPickpocketDetected = true; return false; diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 4b7bcb58ff..f7f061b652 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -281,7 +281,7 @@ namespace MWGui mMagicSelectionDialog->setVisible(false); } - void QuickKeysMenu::onAssignMagic(const std::string& spellId) + void QuickKeysMenu::onAssignMagic(const ESM::RefId& spellId) { assert(mSelected); while (mSelected->button->getChildCount()) // Destroy number label @@ -296,7 +296,7 @@ namespace MWGui mSelected->button->setItem(MWWorld::Ptr()); mSelected->button->setUserString("ToolTipType", "Spell"); - mSelected->button->setUserString("Spell", spellId); + mSelected->button->setUserString("Spell", spellId.getRefIdString()); // use the icon of the first effect const ESM::MagicEffect* effect = esmStore.get().find(spell->mEffects.mList.front().mEffectID); @@ -425,7 +425,7 @@ namespace MWGui } else if (key->type == Type_Magic) { - const std::string& spellId = key->id; + const ESM::RefId& spellId = key->id; // Make sure the player still has this spell MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); @@ -516,7 +516,7 @@ namespace MWGui break; } case Type_Magic: - key.mId = button->getUserString("Spell"); + key.mId = ESM::RefId::stringRefId(button->getUserString("Spell")); break; } diff --git a/apps/openmw/mwgui/quickkeysmenu.hpp b/apps/openmw/mwgui/quickkeysmenu.hpp index affffd5bd4..5f82b98d57 100644 --- a/apps/openmw/mwgui/quickkeysmenu.hpp +++ b/apps/openmw/mwgui/quickkeysmenu.hpp @@ -30,7 +30,7 @@ namespace MWGui void onAssignItem(MWWorld::Ptr item); void onAssignItemCancel(); void onAssignMagicItem(MWWorld::Ptr item); - void onAssignMagic(const std::string& spellId); + void onAssignMagic(const ESM::RefId& spellId); void onAssignMagicCancel(); void onOpen() override; void onClose() override; @@ -58,13 +58,13 @@ namespace MWGui int index; ItemWidget* button; QuickKeysMenu::QuickKeyType type; - std::string id; + ESM::RefId id; std::string name; keyData() : index(-1) , button(nullptr) , type(Type_Unassigned) - , id("") + , id(ESM::RefId::sEmpty) , name("") { } diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index e52161d442..de4617f449 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -34,7 +34,7 @@ namespace return index; } - bool sortRaces(const std::pair& left, const std::pair& right) + bool sortRaces(const std::pair& left, const std::pair& right) { return left.second.compare(right.second) < 0; } @@ -165,13 +165,13 @@ namespace MWGui for (unsigned int i = 0; i < mAvailableHeads.size(); ++i) { - if (Misc::StringUtils::ciEqual(mAvailableHeads[i], proto.mHead)) + if (ESM::RefId::ciEqual(mAvailableHeads[i], proto.mHead)) mFaceIndex = i; } for (unsigned int i = 0; i < mAvailableHairs.size(); ++i) { - if (Misc::StringUtils::ciEqual(mAvailableHairs[i], proto.mHair)) + if (ESM::RefId::ciEqual(mAvailableHairs[i], proto.mHair)) mHairIndex = i; } @@ -184,14 +184,14 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mRaceList); } - void RaceDialog::setRaceId(const std::string& raceId) + void RaceDialog::setRaceId(const ESM::RefId& raceId) { mCurrentRaceId = raceId; mRaceList->setIndexSelected(MyGUI::ITEM_NONE); size_t count = mRaceList->getItemCount(); for (size_t i = 0; i < count; ++i) { - if (Misc::StringUtils::ciEqual(*mRaceList->getItemDataAt(i), raceId)) + if (ESM::RefId::ciEqual(ESM::RefId::stringRefId(*mRaceList->getItemDataAt(i)), raceId)) { mRaceList->setIndexSelected(i); break; @@ -292,11 +292,11 @@ namespace MWGui if (_index == MyGUI::ITEM_NONE) return; - const std::string* raceId = mRaceList->getItemDataAt(_index); - if (Misc::StringUtils::ciEqual(mCurrentRaceId, *raceId)) + ESM::RefId raceId = ESM::RefId::stringRefId(*mRaceList->getItemDataAt(_index)); + if (ESM::RefId::ciEqual(mCurrentRaceId, raceId)) return; - mCurrentRaceId = *raceId; + mCurrentRaceId = raceId; recountParts(); @@ -313,7 +313,7 @@ namespace MWGui eventDone(this); } - void RaceDialog::getBodyParts(int part, std::vector& out) + void RaceDialog::getBodyParts(int part, std::vector& out) { out.clear(); const MWWorld::Store& store @@ -321,6 +321,7 @@ namespace MWGui for (const ESM::BodyPart& bodypart : store) { + const std::string& idString = bodypart.mId.getRefIdString(); if (bodypart.mData.mFlags & ESM::BodyPart::BPF_NotPlayable) continue; if (bodypart.mData.mType != ESM::BodyPart::MT_Skin) @@ -329,11 +330,11 @@ namespace MWGui continue; if (mGenderIndex != (bodypart.mData.mFlags & ESM::BodyPart::BPF_Female)) continue; - bool firstPerson = (bodypart.mId.size() >= 3) && bodypart.mId[bodypart.mId.size() - 3] == '1' - && bodypart.mId[bodypart.mId.size() - 2] == 's' && bodypart.mId[bodypart.mId.size() - 1] == 't'; + bool firstPerson = (idString.size() >= 3) && idString[idString.size() - 3] == '1' + && idString[idString.size() - 2] == 's' && idString[idString.size() - 1] == 't'; if (firstPerson) continue; - if (Misc::StringUtils::ciEqual(bodypart.mRace, mCurrentRaceId)) + if (ESM::RefId::ciEqual(bodypart.mRace, mCurrentRaceId)) out.push_back(bodypart.mId); } } @@ -377,7 +378,7 @@ namespace MWGui const MWWorld::Store& races = MWBase::Environment::get().getWorld()->getStore().get(); - std::vector> items; // ID, name + std::vector> items; // ID, name for (const ESM::Race& race : races) { bool playable = race.mData.mFlags & ESM::Race::Playable; @@ -392,7 +393,7 @@ namespace MWGui for (auto& item : items) { mRaceList->addItem(item.second, item.first); - if (Misc::StringUtils::ciEqual(item.first, mCurrentRaceId)) + if (ESM::RefId::ciEqual(item.first, mCurrentRaceId)) mRaceList->setIndexSelected(index); ++index; } @@ -454,13 +455,13 @@ namespace MWGui const ESM::Race* race = store.get().find(mCurrentRaceId); int i = 0; - for (const std::string& spellpower : race->mPowers.mList) + for (const auto& spellpower : race->mPowers.mList) { Widgets::MWSpellPtr spellPowerWidget = mSpellPowerList->createWidget( "MW_StatName", coord, MyGUI::Align::Default, std::string("SpellPower") + MyGUI::utility::toString(i)); spellPowerWidget->setSpellId(spellpower); spellPowerWidget->setUserString("ToolTipType", "Spell"); - spellPowerWidget->setUserString("Spell", spellpower); + spellPowerWidget->setUserString("Spell", spellpower.getRefIdString()); mSpellPowerItems.push_back(spellPowerWidget); diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index 3a6966cb7c..49e41f3084 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -2,7 +2,7 @@ #define MWGUI_RACE_H #include - +#include #include "windowbase.hpp" namespace MWRender @@ -39,10 +39,10 @@ namespace MWGui }; const ESM::NPC& getResult() const; - const std::string& getRaceId() const { return mCurrentRaceId; } + const ESM::RefId& getRaceId() const { return mCurrentRaceId; } Gender getGender() const { return mGenderIndex == 0 ? GM_Male : GM_Female; } - void setRaceId(const std::string& raceId); + void setRaceId(const ESM::RefId& raceId); void setGender(Gender gender) { mGenderIndex = gender == GM_Male ? 0 : 1; } void setNextButtonShow(bool shown); @@ -90,13 +90,13 @@ namespace MWGui void updatePreview(); void recountParts(); - void getBodyParts(int part, std::vector& out); + void getBodyParts(int part, std::vector& out); osg::Group* mParent; Resource::ResourceSystem* mResourceSystem; - std::vector mAvailableHeads; - std::vector mAvailableHairs; + std::vector mAvailableHeads; + std::vector mAvailableHairs; MyGUI::ImageBox* mPreviewImage; MyGUI::ListBox* mRaceList; @@ -110,7 +110,7 @@ namespace MWGui int mGenderIndex, mFaceIndex, mHairIndex; - std::string mCurrentRaceId; + ESM::RefId mCurrentRaceId; float mCurrentAngle; diff --git a/apps/openmw/mwgui/recharge.cpp b/apps/openmw/mwgui/recharge.cpp index 9d2275255b..d00ad79455 100644 --- a/apps/openmw/mwgui/recharge.cpp +++ b/apps/openmw/mwgui/recharge.cpp @@ -68,7 +68,7 @@ namespace MWGui { MWWorld::Ptr gem = *mGemIcon->getUserData(); - const std::string& soul = gem.getCellRef().getSoul(); + const ESM::RefId& soul = gem.getCellRef().getSoul(); const ESM::Creature* creature = MWBase::Environment::get().getWorld()->getStore().get().find(soul); diff --git a/apps/openmw/mwgui/repair.cpp b/apps/openmw/mwgui/repair.cpp index e91435b0d1..dc559f03b0 100644 --- a/apps/openmw/mwgui/repair.cpp +++ b/apps/openmw/mwgui/repair.cpp @@ -57,7 +57,7 @@ namespace MWGui void Repair::setPtr(const MWWorld::Ptr& item) { - MWBase::Environment::get().getWindowManager()->playSound("Item Repair Up"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Repair Up")); mRepair.setTool(item); diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index 541c07287f..60594fbe7b 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -124,7 +124,7 @@ namespace MWGui mNameWidget->setCaption(name); } - void ReviewDialog::setRace(const std::string& raceId) + void ReviewDialog::setRace(const ESM::RefId& raceId) { mRaceId = raceId; @@ -145,7 +145,7 @@ namespace MWGui ToolTips::createClassToolTip(mClassWidget, mKlass); } - void ReviewDialog::setBirthSign(const std::string& signId) + void ReviewDialog::setBirthSign(const ESM::RefId& signId) { mBirthSignId = signId; @@ -315,7 +315,7 @@ namespace MWGui "MW_StatName", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); widget->setSpellId(spell->mId); widget->setUserString("ToolTipType", "Spell"); - widget->setUserString("Spell", spell->mId); + widget->setUserString("Spell", spell->mId.getRefIdString()); widget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel); mSkillWidgets.push_back(widget); @@ -387,7 +387,7 @@ namespace MWGui addSkills(mMiscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); // starting spells - std::vector spells; + std::vector spells; const ESM::Race* race = nullptr; if (!mRaceId.empty()) @@ -401,21 +401,19 @@ namespace MWGui for (int i = 0; i < ESM::Attribute::Length; ++i) attributes[i] = mAttributeWidgets[i]->getAttributeValue().getBase(); - std::vector selectedSpells = MWMechanics::autoCalcPlayerSpells(skills, attributes, race); - for (std::string& spellId : selectedSpells) + std::vector selectedSpells = MWMechanics::autoCalcPlayerSpells(skills, attributes, race); + for (ESM::RefId& spellId : selectedSpells) { - std::string lower = Misc::StringUtils::lowerCase(spellId); - if (std::find(spells.begin(), spells.end(), lower) == spells.end()) - spells.push_back(lower); + if (std::find(spells.begin(), spells.end(), spellId) == spells.end()) + spells.push_back(spellId); } if (race) { - for (const std::string& spellId : race->mPowers.mList) + for (const ESM::RefId& spellId : race->mPowers.mList) { - std::string lower = Misc::StringUtils::lowerCase(spellId); - if (std::find(spells.begin(), spells.end(), lower) == spells.end()) - spells.push_back(lower); + if (std::find(spells.begin(), spells.end(), spellId) == spells.end()) + spells.push_back(spellId); } } @@ -423,11 +421,10 @@ namespace MWGui { const ESM::BirthSign* sign = MWBase::Environment::get().getWorld()->getStore().get().find(mBirthSignId); - for (const std::string& spellId : sign->mPowers.mList) + for (const auto& spellId : sign->mPowers.mList) { - std::string lower = Misc::StringUtils::lowerCase(spellId); - if (std::find(spells.begin(), spells.end(), lower) == spells.end()) - spells.push_back(lower); + if (std::find(spells.begin(), spells.end(), spellId) == spells.end()) + spells.push_back(spellId); } } @@ -435,7 +432,7 @@ namespace MWGui addSeparator(coord1, coord2); addGroup(MWBase::Environment::get().getWindowManager()->getGameSettingString("sTypeAbility", "Abilities"), coord1, coord2); - for (std::string& spellId : spells) + for (auto& spellId : spells) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); if (spell->mData.mType == ESM::Spell::ST_Ability) @@ -445,7 +442,7 @@ namespace MWGui addSeparator(coord1, coord2); addGroup(MWBase::Environment::get().getWindowManager()->getGameSettingString("sTypePower", "Powers"), coord1, coord2); - for (std::string& spellId : spells) + for (auto& spellId : spells) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); if (spell->mData.mType == ESM::Spell::ST_Power) @@ -455,7 +452,7 @@ namespace MWGui addSeparator(coord1, coord2); addGroup(MWBase::Environment::get().getWindowManager()->getGameSettingString("sTypeSpell", "Spells"), coord1, coord2); - for (std::string& spellId : spells) + for (auto& spellId : spells) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); if (spell->mData.mType == ESM::Spell::ST_Spell) diff --git a/apps/openmw/mwgui/review.hpp b/apps/openmw/mwgui/review.hpp index 913c825217..54044a762a 100644 --- a/apps/openmw/mwgui/review.hpp +++ b/apps/openmw/mwgui/review.hpp @@ -4,6 +4,7 @@ #include "widgets.hpp" #include "windowbase.hpp" #include +#include #include namespace ESM @@ -30,9 +31,9 @@ namespace MWGui bool exit() override { return false; } void setPlayerName(const std::string& name); - void setRace(const std::string& raceId); + void setRace(const ESM::RefId& raceId); void setClass(const ESM::Class& class_); - void setBirthSign(const std::string& signId); + void setBirthSign(const ESM::RefId& signId); void setHealth(const MWMechanics::DynamicStat& value); void setMagicka(const MWMechanics::DynamicStat& value); @@ -95,7 +96,8 @@ namespace MWGui SkillList mMajorSkills, mMinorSkills, mMiscSkills; std::map mSkillValues; std::map mSkillWidgetMap; - std::string mName, mRaceId, mBirthSignId; + ESM::RefId mRaceId, mBirthSignId; + std::string mName; ESM::Class mKlass; std::vector mSkillWidgets; //< Skills and other information diff --git a/apps/openmw/mwgui/scrollwindow.cpp b/apps/openmw/mwgui/scrollwindow.cpp index 80151b49d2..70a05403cd 100644 --- a/apps/openmw/mwgui/scrollwindow.cpp +++ b/apps/openmw/mwgui/scrollwindow.cpp @@ -100,7 +100,7 @@ namespace MWGui void ScrollWindow::onTakeButtonClicked(MyGUI::Widget* _sender) { - MWBase::Environment::get().getWindowManager()->playSound("Item Book Up"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Book Up")); MWWorld::ActionTake take(mScroll); take.execute(MWMechanics::getPlayer()); diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 35a9d792e0..b6ec7a083a 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -100,13 +100,13 @@ namespace // 3. item with constant effect comes before items with non-constant effects int leftChargePercent = -1; int rightChargePercent = -1; - leftName = left.mBase.getClass().getEnchantment(left.mBase); - rightName = right.mBase.getClass().getEnchantment(right.mBase); + const ESM::RefId& leftNameEnch = left.mBase.getClass().getEnchantment(left.mBase); + const ESM::RefId& rightNameEnch = right.mBase.getClass().getEnchantment(right.mBase); - if (!leftName.empty()) + if (!leftNameEnch.empty()) { const ESM::Enchantment* ench - = MWBase::Environment::get().getWorld()->getStore().get().search(leftName); + = MWBase::Environment::get().getWorld()->getStore().get().search(leftNameEnch); if (ench) { if (ench->mData.mType == ESM::Enchantment::ConstantEffect) @@ -117,10 +117,10 @@ namespace } } - if (!rightName.empty()) + if (!rightNameEnch.empty()) { const ESM::Enchantment* ench - = MWBase::Environment::get().getWorld()->getStore().get().search(rightName); + = MWBase::Environment::get().getWorld()->getStore().get().search(rightNameEnch); if (ench) { if (ench->mData.mType == ESM::Enchantment::ConstantEffect) @@ -161,8 +161,8 @@ namespace return result > 0; // compare items by Id - leftName = left.mBase.getCellRef().getRefId(); - rightName = right.mBase.getCellRef().getRefId(); + leftName = left.mBase.getCellRef().getRefId().getRefIdString(); + rightName = right.mBase.getCellRef().getRefId().getRefIdString(); result = leftName.compare(rightName); return result < 0; @@ -267,7 +267,7 @@ namespace MWGui if ((mFilter & Filter_OnlyEnchanted) && !(item.mFlags & ItemStack::Flag_Enchanted)) return false; if ((mFilter & Filter_OnlyChargedSoulstones) - && (base.getType() != ESM::Miscellaneous::sRecordId || base.getCellRef().getSoul() == "" + && (base.getType() != ESM::Miscellaneous::sRecordId || base.getCellRef().getSoul() == ESM::RefId::sEmpty || !MWBase::Environment::get().getWorld()->getStore().get().search( base.getCellRef().getSoul()))) return false; @@ -300,7 +300,7 @@ namespace MWGui if (!(item.mFlags & ItemStack::Flag_Enchanted)) return false; - std::string_view enchId = base.getClass().getEnchantment(base); + const ESM::RefId& enchId = base.getClass().getEnchantment(base); const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get().search(enchId); if (!ench) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index bb6586bda4..e871f97b75 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -66,7 +66,7 @@ namespace MWGui toAdd->setSize(mSpellsView->getWidth(), lineHeight); toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel); toAdd->setUserString("ToolTipType", "Spell"); - toAdd->setUserString("Spell", spell.mId); + toAdd->setUserString("Spell", spell.mId.getRefIdString()); toAdd->setUserString("SpellCost", std::to_string(spell.mData.mCost)); toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onSpellButtonClick); mSpellsWidgetMap.insert(std::make_pair(toAdd, spell.mId)); @@ -135,7 +135,7 @@ namespace MWGui mSpellsView->setViewOffset(MyGUI::IntPoint(0, startOffset)); } - bool SpellBuyingWindow::playerHasSpell(const std::string& id) + bool SpellBuyingWindow::playerHasSpell(const ESM::RefId& id) { MWWorld::Ptr player = MWMechanics::getPlayer(); return player.getClass().getCreatureStats(player).getSpells().hasSpell(id); @@ -160,7 +160,7 @@ namespace MWGui setPtr(mPtr, mSpellsView->getViewOffset().top); - MWBase::Environment::get().getWindowManager()->playSound("Item Gold Up"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Gold Up")); } void SpellBuyingWindow::onCancelButtonClicked(MyGUI::Widget* _sender) diff --git a/apps/openmw/mwgui/spellbuyingwindow.hpp b/apps/openmw/mwgui/spellbuyingwindow.hpp index 17c49eb68c..66919e5d33 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.hpp +++ b/apps/openmw/mwgui/spellbuyingwindow.hpp @@ -3,7 +3,7 @@ #include "referenceinterface.hpp" #include "windowbase.hpp" - +#include namespace ESM { struct Spell; @@ -36,7 +36,7 @@ namespace MWGui MyGUI::ScrollView* mSpellsView; - std::map mSpellsWidgetMap; + std::map mSpellsWidgetMap; void onCancelButtonClicked(MyGUI::Widget* _sender); void onSpellButtonClick(MyGUI::Widget* _sender); @@ -49,7 +49,7 @@ namespace MWGui void onReferenceUnavailable() override; - bool playerHasSpell(const std::string& id); + bool playerHasSpell(const ESM::RefId& id); private: static bool sortSpells(const ESM::Spell* left, const ESM::Spell* right); diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index e57246b009..d27c06d2a7 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -414,7 +414,7 @@ namespace MWGui MWMechanics::CreatureStats& npcStats = mPtr.getClass().getCreatureStats(mPtr); npcStats.setGoldPool(npcStats.getGoldPool() + price); - MWBase::Environment::get().getWindowManager()->playSound("Mysticism Hit"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Mysticism Hit")); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->createRecord(mSpell); diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index af428587f7..2fe9ecad2b 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -126,7 +126,7 @@ namespace MWGui for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) { MWWorld::Ptr item = *it; - const std::string_view enchantId = item.getClass().getEnchantment(item); + const ESM::RefId& enchantId = item.getClass().getEnchantment(item); if (enchantId.empty()) continue; const ESM::Enchantment* enchant = esmStore.get().search(enchantId); diff --git a/apps/openmw/mwgui/spellmodel.hpp b/apps/openmw/mwgui/spellmodel.hpp index 888808776f..248c60003f 100644 --- a/apps/openmw/mwgui/spellmodel.hpp +++ b/apps/openmw/mwgui/spellmodel.hpp @@ -19,7 +19,7 @@ namespace MWGui Type mType; std::string mName; std::string mCostColumn; // Cost/chance or Cost/charge - std::string mId; // Item ID or spell ID + ESM::RefId mId; // Item ID or spell ID MWWorld::Ptr mItem; // Only for Type_EnchantedItem int mCount; // Only for Type_EnchantedItem bool mSelected; // Is this the currently selected spell/item (only one can be selected at a time) diff --git a/apps/openmw/mwgui/spellview.cpp b/apps/openmw/mwgui/spellview.cpp index 98469f17e5..9b568800ef 100644 --- a/apps/openmw/mwgui/spellview.cpp +++ b/apps/openmw/mwgui/spellview.cpp @@ -286,7 +286,7 @@ namespace MWGui else { widget->setUserString("ToolTipType", "Spell"); - widget->setUserString("Spell", spell.mId); + widget->setUserString("Spell", spell.mId.getRefIdString()); } widget->setUserString(sSpellModelIndex, MyGUI::utility::toString(index)); diff --git a/apps/openmw/mwgui/spellwindow.cpp b/apps/openmw/mwgui/spellwindow.cpp index 59312a33af..cde693f312 100644 --- a/apps/openmw/mwgui/spellwindow.cpp +++ b/apps/openmw/mwgui/spellwindow.cpp @@ -136,17 +136,17 @@ namespace MWGui updateSpells(); } - void SpellWindow::askDeleteSpell(const std::string& spellId) + void SpellWindow::askDeleteSpell(const ESM::RefId& spellId) { // delete spell, if allowed const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(spellId); MWWorld::Ptr player = MWMechanics::getPlayer(); - const std::string& raceId = player.get()->mBase->mRace; + const ESM::RefId& raceId = player.get()->mBase->mRace; const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(raceId); // can't delete racial spells, birthsign spells or powers bool isInherent = race->mPowers.exists(spell->mId) || spell->mData.mType == ESM::Spell::ST_Power; - const std::string& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); + const ESM::RefId& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); if (!isInherent && !signId.empty()) { const ESM::BirthSign* sign @@ -205,7 +205,7 @@ namespace MWGui askDeleteSpell(spell.mId); } - void SpellWindow::onSpellSelected(const std::string& spellId) + void SpellWindow::onSpellSelected(const ESM::RefId& spellId) { MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::InventoryStore& store = player.getClass().getInventoryStore(player); diff --git a/apps/openmw/mwgui/spellwindow.hpp b/apps/openmw/mwgui/spellwindow.hpp index 7e2e7e267f..69519a47ef 100644 --- a/apps/openmw/mwgui/spellwindow.hpp +++ b/apps/openmw/mwgui/spellwindow.hpp @@ -26,15 +26,15 @@ namespace MWGui protected: MyGUI::Widget* mEffectBox; - std::string mSpellToDelete; + ESM::RefId mSpellToDelete; void onEnchantedItemSelected(MWWorld::Ptr item, bool alreadyEquipped); - void onSpellSelected(const std::string& spellId); + void onSpellSelected(const ESM::RefId& spellId); void onModelIndexSelected(SpellModel::ModelIndex index); void onFilterChanged(MyGUI::EditBox* sender); void onDeleteClicked(MyGUI::Widget* widget); void onDeleteSpellAccept(); - void askDeleteSpell(const std::string& spellId); + void askDeleteSpell(const ESM::RefId& spellId); void onPinToggled() override; void onTitleDoubleClicked() override; diff --git a/apps/openmw/mwgui/statswatcher.cpp b/apps/openmw/mwgui/statswatcher.cpp index 00c9c61ed1..0894b85046 100644 --- a/apps/openmw/mwgui/statswatcher.cpp +++ b/apps/openmw/mwgui/statswatcher.cpp @@ -42,25 +42,25 @@ namespace MWGui if (stats.getAttribute(i) != mWatchedAttributes[i] || mWatchedStatsEmpty) { mWatchedAttributes[i] = stats.getAttribute(i); - setValue("AttribVal" + std::to_string(i + 1), stats.getAttribute(i)); + setValue(ESM::RefId::stringRefId("AttribVal" + std::to_string(i + 1)), stats.getAttribute(i)); } } if (stats.getHealth() != mWatchedHealth || mWatchedStatsEmpty) { - static const std::string hbar("HBar"); + static const ESM::RefId hbar(ESM::RefId::stringRefId("HBar")); mWatchedHealth = stats.getHealth(); setValue(hbar, stats.getHealth()); } if (stats.getMagicka() != mWatchedMagicka || mWatchedStatsEmpty) { - static const std::string mbar("MBar"); + static const ESM::RefId mbar(ESM::RefId::stringRefId("MBar")); mWatchedMagicka = stats.getMagicka(); setValue(mbar, stats.getMagicka()); } if (stats.getFatigue() != mWatchedFatigue || mWatchedStatsEmpty) { - static const std::string fbar("FBar"); + static const ESM::RefId fbar(ESM::RefId::stringRefId("FBar")); mWatchedFatigue = stats.getFatigue(); setValue(fbar, stats.getFatigue()); } @@ -100,7 +100,7 @@ namespace MWGui if (stats.getLevel() != mWatchedLevel || mWatchedStatsEmpty) { mWatchedLevel = stats.getLevel(); - setValue("level", mWatchedLevel); + setValue(ESM::RefId::stringRefId("level"), mWatchedLevel); } if (mWatched.getClass().isNpc()) @@ -110,7 +110,7 @@ namespace MWGui if (watchedRecord->mName != mWatchedName || mWatchedStatsEmpty) { mWatchedName = watchedRecord->mName; - setValue("name", watchedRecord->mName); + setValue(ESM::RefId::stringRefId("name"), watchedRecord->mName); } if (watchedRecord->mRace != mWatchedRace || mWatchedStatsEmpty) @@ -118,7 +118,7 @@ namespace MWGui mWatchedRace = watchedRecord->mRace; const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(watchedRecord->mRace); - setValue("race", race->mName); + setValue(ESM::RefId::stringRefId("race"), race->mName); } if (watchedRecord->mClass != mWatchedClass || mWatchedStatsEmpty) @@ -126,7 +126,7 @@ namespace MWGui mWatchedClass = watchedRecord->mClass; const ESM::Class* cls = MWBase::Environment::get().getWorld()->getStore().get().find(watchedRecord->mClass); - setValue("class", cls->mName); + setValue(ESM::RefId::stringRefId("class"), cls->mName); MWBase::WindowManager::SkillList majorSkills(5); MWBase::WindowManager::SkillList minorSkills(5); @@ -154,7 +154,7 @@ namespace MWGui mListeners.erase(listener); } - void StatsWatcher::setValue(const std::string& id, const MWMechanics::AttributeValue& value) + void StatsWatcher::setValue(const ESM::RefId& id, const MWMechanics::AttributeValue& value) { for (StatsListener* listener : mListeners) listener->setValue(id, value); @@ -168,19 +168,19 @@ namespace MWGui listener->setValue(parSkill, value); } - void StatsWatcher::setValue(const std::string& id, const MWMechanics::DynamicStat& value) + void StatsWatcher::setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) { for (StatsListener* listener : mListeners) listener->setValue(id, value); } - void StatsWatcher::setValue(const std::string& id, const std::string& value) + void StatsWatcher::setValue(const ESM::RefId& id, const std::string& value) { for (StatsListener* listener : mListeners) listener->setValue(id, value); } - void StatsWatcher::setValue(const std::string& id, int value) + void StatsWatcher::setValue(const ESM::RefId& id, int value) { for (StatsListener* listener : mListeners) listener->setValue(id, value); diff --git a/apps/openmw/mwgui/statswatcher.hpp b/apps/openmw/mwgui/statswatcher.hpp index 6262a50565..92da92edae 100644 --- a/apps/openmw/mwgui/statswatcher.hpp +++ b/apps/openmw/mwgui/statswatcher.hpp @@ -16,10 +16,10 @@ namespace MWGui { public: /// Set value for the given ID. - virtual void setValue(const std::string& id, const MWMechanics::AttributeValue& value) {} - virtual void setValue(const std::string& id, const MWMechanics::DynamicStat& value) {} - virtual void setValue(const std::string& id, const std::string& value) {} - virtual void setValue(const std::string& id, int value) {} + virtual void setValue(const ESM::RefId& id, const MWMechanics::AttributeValue& value) {} + virtual void setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) {} + virtual void setValue(const ESM::RefId& id, const std::string& value) {} + virtual void setValue(const ESM::RefId& id, int value) {} virtual void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::SkillValue& value) {} virtual void configureSkills(const std::vector& major, const std::vector& minor) {} }; @@ -36,8 +36,8 @@ namespace MWGui MWMechanics::DynamicStat mWatchedFatigue; std::string mWatchedName; - std::string mWatchedRace; - std::string mWatchedClass; + ESM::RefId mWatchedRace; + ESM::RefId mWatchedClass; int mWatchedLevel; @@ -47,10 +47,10 @@ namespace MWGui std::set mListeners; - void setValue(const std::string& id, const MWMechanics::AttributeValue& value); - void setValue(const std::string& id, const MWMechanics::DynamicStat& value); - void setValue(const std::string& id, const std::string& value); - void setValue(const std::string& id, int value); + void setValue(const ESM::RefId& id, const MWMechanics::AttributeValue& value); + void setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value); + void setValue(const ESM::RefId& id, const std::string& value); + void setValue(const ESM::RefId& id, int value); void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::SkillValue& value); void configureSkills(const std::vector& major, const std::vector& minor); diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index b4d83ad9a7..40327b4da8 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -153,7 +153,7 @@ namespace MWGui mMainWidget->castType()->setCaption(playerName); } - void StatsWindow::setValue(const std::string& id, const MWMechanics::AttributeValue& value) + void StatsWindow::setValue(const ESM::RefId& id, const MWMechanics::AttributeValue& value) { static const char* ids[] = { "AttribVal1", @@ -168,12 +168,12 @@ namespace MWGui }; for (int i = 0; ids[i]; ++i) - if (ids[i] == id) + if (ids[i] == id.getRefIdString()) { - setText(id, std::to_string(static_cast(value.getModified()))); + setText(id.getRefIdString(), std::to_string(static_cast(value.getModified()))); MyGUI::TextBox* box; - getWidget(box, id); + getWidget(box, id.getRefIdString()); if (value.getModified() > value.getBase()) box->_setWidgetState("increased"); @@ -186,50 +186,50 @@ namespace MWGui } } - void StatsWindow::setValue(const std::string& id, const MWMechanics::DynamicStat& value) + void StatsWindow::setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) { int current = static_cast(value.getCurrent()); int modified = static_cast(value.getModified(false)); // Fatigue can be negative - if (id != "FBar") + if (id.getRefIdString() != "FBar") current = std::max(0, current); - setBar(id, id + "T", current, modified); + setBar(id.getRefIdString(), id.getRefIdString() + "T", current, modified); // health, magicka, fatigue tooltip MyGUI::Widget* w; std::string valStr = MyGUI::utility::toString(current) + " / " + MyGUI::utility::toString(modified); - if (id == "HBar") + if (id.getRefIdString() == "HBar") { getWidget(w, "Health"); w->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr); } - else if (id == "MBar") + else if (id.getRefIdString() == "MBar") { getWidget(w, "Magicka"); w->setUserString("Caption_HealthDescription", "#{sMagDesc}\n" + valStr); } - else if (id == "FBar") + else if (id.getRefIdString() == "FBar") { getWidget(w, "Fatigue"); w->setUserString("Caption_HealthDescription", "#{sFatDesc}\n" + valStr); } } - void StatsWindow::setValue(const std::string& id, const std::string& value) + void StatsWindow::setValue(const ESM::RefId& id, const std::string& value) { - if (id == "name") + if (id.getRefIdString() == "name") setPlayerName(value); - else if (id == "race") + else if (id.getRefIdString() == "race") setText("RaceText", value); - else if (id == "class") + else if (id.getRefIdString() == "class") setText("ClassText", value); } - void StatsWindow::setValue(const std::string& id, int value) + void StatsWindow::setValue(const ESM::RefId& id, int value) { - if (id == "level") + if (id.getRefIdString() == "level") { std::ostringstream text; text << value; @@ -376,7 +376,7 @@ namespace MWGui setFactions(PCstats.getFactionRanks()); setExpelled(PCstats.getExpelled()); - const std::string& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); + auto signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); setBirthSign(signId); setReputation(PCstats.getReputation()); @@ -395,7 +395,7 @@ namespace MWGui } } - void StatsWindow::setExpelled(const std::set& expelled) + void StatsWindow::setExpelled(const std::set& expelled) { if (mExpelled != expelled) { @@ -404,7 +404,7 @@ namespace MWGui } } - void StatsWindow::setBirthSign(const std::string& signId) + void StatsWindow::setBirthSign(const ESM::RefId& signId) { if (signId != mBirthSignId) { @@ -591,12 +591,12 @@ namespace MWGui { MWWorld::Ptr playerPtr = MWMechanics::getPlayer(); const MWMechanics::NpcStats& PCstats = playerPtr.getClass().getNpcStats(playerPtr); - const std::set& expelled = PCstats.getExpelled(); + const std::set& expelled = PCstats.getExpelled(); bool firstFaction = true; for (auto& factionPair : mFactions) { - const std::string& factionId = factionPair.first; + const ESM::RefId& factionId = factionPair.first; const ESM::Faction* faction = store.get().find(factionId); if (faction->mData.mIsHidden == 1) continue; diff --git a/apps/openmw/mwgui/statswindow.hpp b/apps/openmw/mwgui/statswindow.hpp index c7d887903d..1a6a6b4930 100644 --- a/apps/openmw/mwgui/statswindow.hpp +++ b/apps/openmw/mwgui/statswindow.hpp @@ -1,6 +1,7 @@ #ifndef MWGUI_STATS_WINDOW_H #define MWGUI_STATS_WINDOW_H +#include #include "statswatcher.hpp" #include "windowpinnablebase.hpp" @@ -9,7 +10,7 @@ namespace MWGui class StatsWindow : public WindowPinnableBase, public NoDrop, public StatsListener { public: - typedef std::map FactionList; + typedef std::map FactionList; typedef std::vector SkillList; @@ -22,10 +23,10 @@ namespace MWGui void setPlayerName(const std::string& playerName); /// Set value for the given ID. - void setValue(const std::string& id, const MWMechanics::AttributeValue& value) override; - void setValue(const std::string& id, const MWMechanics::DynamicStat& value) override; - void setValue(const std::string& id, const std::string& value) override; - void setValue(const std::string& id, int value) override; + void setValue(const ESM::RefId& id, const MWMechanics::AttributeValue& value) override; + void setValue(const ESM::RefId& id, const MWMechanics::DynamicStat& value) override; + void setValue(const ESM::RefId& id, const std::string& value) override; + void setValue(const ESM::RefId& id, int value) override; void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::SkillValue& value) override; void configureSkills(const SkillList& major, const SkillList& minor) override; @@ -55,8 +56,8 @@ namespace MWGui MyGUI::Widget* addItem(const std::string& text, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2); void setFactions(const FactionList& factions); - void setExpelled(const std::set& expelled); - void setBirthSign(const std::string& signId); + void setExpelled(const std::set& expelled); + void setBirthSign(const ESM::RefId& signId); void onWindowResize(MyGUI::Window* window); void onMouseWheel(MyGUI::Widget* _sender, int _rel); @@ -71,10 +72,10 @@ namespace MWGui std::map> mSkillWidgetMap; std::map mFactionWidgetMap; FactionList mFactions; ///< Stores a list of factions and the current rank - std::string mBirthSignId; + ESM::RefId mBirthSignId; int mReputation, mBounty; std::vector mSkillWidgets; //< Skills and other information - std::set mExpelled; + std::set mExpelled; bool mChanged; const int mMinFullWidth; diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index de22f2a38a..757e6b66c1 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -123,7 +123,7 @@ namespace MWGui ToolTipInfo info; info.caption = mFocusObject.getClass().getName(mFocusObject); if (info.caption.empty()) - info.caption = mFocusObject.getCellRef().getRefId(); + info.caption = mFocusObject.getCellRef().getRefId().getRefIdString(); info.icon.clear(); tooltipSize = createToolTip(info, checkOwned()); } @@ -226,7 +226,7 @@ namespace MWGui ToolTipInfo info; const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find( - focus->getUserString("Spell")); + ESM::RefId::stringRefId(focus->getUserString("Spell"))); info.caption = spell->mName; Widgets::SpellEffectList effects; for (const ESM::ENAMstruct& spellEffect : spell->mEffects.mList) @@ -677,7 +677,7 @@ namespace MWGui std::string ToolTips::getSoulString(const MWWorld::CellRef& cellref) { - const std::string& soul = cellref.getSoul(); + const ESM::RefId& soul = cellref.getSoul(); if (soul.empty()) return {}; const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); @@ -685,22 +685,22 @@ namespace MWGui if (!creature) return {}; if (creature->mName.empty()) - return " (" + creature->mId + ")"; + return " (" + creature->mId.getRefIdString() + ")"; return " (" + creature->mName + ")"; } std::string ToolTips::getCellRefString(const MWWorld::CellRef& cellref) { std::string ret; - ret += getMiscString(cellref.getOwner(), "Owner"); - const std::string& factionId = cellref.getFaction(); + ret += getMiscString(cellref.getOwner().getRefIdString(), "Owner"); + const ESM::RefId& factionId = cellref.getFaction(); if (!factionId.empty()) { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Faction* fact = store.get().search(factionId); if (fact != nullptr) { - ret += getMiscString(fact->mName.empty() ? factionId : fact->mName, "Owner Faction"); + ret += getMiscString(fact->mName.empty() ? factionId.getRefIdString() : fact->mName, "Owner Faction"); if (cellref.getFactionRank() >= 0) { int rank = cellref.getFactionRank(); @@ -713,15 +713,15 @@ namespace MWGui } } - std::vector> itemOwners + std::vector> itemOwners = MWBase::Environment::get().getMechanicsManager()->getStolenItemOwners(cellref.getRefId()); - for (std::pair& owner : itemOwners) + for (std::pair& owner : itemOwners) { if (owner.second == std::numeric_limits::max()) - ret += std::string("\nStolen from ") + owner.first; // for legacy (ESS) savegames + ret += std::string("\nStolen from ") + owner.first.getRefIdString(); // for legacy (ESS) savegames else - ret += std::string("\nStolen ") + MyGUI::utility::toString(owner.second) + " from " + owner.first; + ret += std::string("\nStolen ") + MyGUI::utility::toString(owner.second) + " from " + owner.first.getRefIdString(); } ret += getMiscString(cellref.getGlobalVariable(), "Global"); @@ -864,7 +864,7 @@ namespace MWGui widget->setUserString("ToolTipType", "Layout"); } - void ToolTips::createBirthsignToolTip(MyGUI::Widget* widget, const std::string& birthsignId) + void ToolTips::createBirthsignToolTip(MyGUI::Widget* widget, const ESM::RefId& birthsignId) { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); @@ -879,7 +879,7 @@ namespace MWGui std::vector abilities, powers, spells; - for (const std::string& spellId : sign->mPowers.mList) + for (const ESM::RefId& spellId : sign->mPowers.mList) { const ESM::Spell* spell = store.get().search(spellId); if (!spell) diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 1c2c434070..9ed62d4e35 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -33,7 +33,7 @@ namespace MWGui int imageSize; // enchantment (for cloth, armor, weapons) - std::string enchant; + ESM::RefId enchant; int remainingEnchantCharge; // effects (for potions, ingredients) @@ -96,7 +96,7 @@ namespace MWGui static void createSkillToolTip(MyGUI::Widget* widget, int skillId); static void createAttributeToolTip(MyGUI::Widget* widget, int attributeId); static void createSpecializationToolTip(MyGUI::Widget* widget, const std::string& name, int specId); - static void createBirthsignToolTip(MyGUI::Widget* widget, const std::string& birthsignId); + static void createBirthsignToolTip(MyGUI::Widget* widget, const ESM::RefId& birthsignId); static void createRaceToolTip(MyGUI::Widget* widget, const ESM::Race* playerRace); static void createClassToolTip(MyGUI::Widget* widget, const ESM::Class& playerClass); static void createMagicEffectToolTip(MyGUI::Widget* widget, short id); diff --git a/apps/openmw/mwgui/tradeitemmodel.cpp b/apps/openmw/mwgui/tradeitemmodel.cpp index b3202c112a..e68e660f79 100644 --- a/apps/openmw/mwgui/tradeitemmodel.cpp +++ b/apps/openmw/mwgui/tradeitemmodel.cpp @@ -166,7 +166,7 @@ namespace MWGui if (!mMerchant.isEmpty()) { MWWorld::Ptr base = item.mBase; - if (Misc::StringUtils::ciEqual(base.getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) + if (ESM::RefId::ciEqual(base.getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) continue; if (!base.getClass().showsInInventory(base)) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 60e0374ff2..0e36f9466e 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -209,7 +209,7 @@ namespace MWGui void TradeWindow::sellItem(MyGUI::Widget* sender, int count) { const ItemStack& item = mTradeModel->getItem(mItemToSell); - std::string_view sound = item.mBase.getClass().getUpSoundId(item.mBase); + const ESM::RefId& sound = item.mBase.getClass().getUpSoundId(item.mBase); MWBase::Environment::get().getWindowManager()->playSound(sound); TradeItemModel* playerTradeModel @@ -358,7 +358,7 @@ namespace MWGui eventTradeDone(); - MWBase::Environment::get().getWindowManager()->playSound("Item Gold Up"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Gold Up")); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Barter); } diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 541440e016..686cf8f465 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -43,7 +43,7 @@ namespace MWGui mSelect->setCoord(8, mSelect->getTop(), mSelect->getTextSize().width, mSelect->getHeight()); } - void TravelWindow::addDestination(const std::string& name, const ESM::Position& pos, bool interior) + void TravelWindow::addDestination(const ESM::RefId& name, const ESM::Position& pos, bool interior) { int price; @@ -90,11 +90,12 @@ namespace MWGui else toAdd->setUserString("interior", "n"); + std::string nameString = name.getRefIdString(); toAdd->setUserString("price", std::to_string(price)); - toAdd->setCaptionWithReplacing("#{sCell=" + name + "} - " + MyGUI::utility::toString(price) + "#{sgp}"); + toAdd->setCaptionWithReplacing("#{sCell=" + nameString + "} - " + MyGUI::utility::toString(price) + "#{sgp}"); toAdd->setSize(mDestinationsView->getWidth(), lineHeight); toAdd->eventMouseWheel += MyGUI::newDelegate(this, &TravelWindow::onMouseWheel); - toAdd->setUserString("Destination", name); + toAdd->setUserString("Destination", nameString); toAdd->setUserData(pos); toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &TravelWindow::onTravelButtonClick); } @@ -121,7 +122,7 @@ namespace MWGui for (unsigned int i = 0; i < transport.size(); i++) { - std::string cellname = transport[i].mCellName; + ESM::RefId cellname = transport[i].mCellName; bool interior = true; const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); @@ -162,7 +163,7 @@ namespace MWGui if (!mPtr.getCell()->isExterior()) // Interior cell -> mages guild transport - MWBase::Environment::get().getWindowManager()->playSound("mysticism cast"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("mysticism cast")); player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price, player); @@ -172,7 +173,7 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->fadeScreenOut(1); ESM::Position pos = *_sender->getUserData(); - const std::string& cellname = _sender->getUserString("Destination"); + const ESM::RefId& cellname = ESM::RefId::stringRefId(_sender->getUserString("Destination")); bool interior = _sender->getUserString("interior") == "y"; if (mPtr.getCell()->isExterior()) { @@ -196,7 +197,7 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->fadeScreenOut(1); // Teleports any followers, too. - MWWorld::ActionTeleport action(interior ? cellname : std::string_view{}, pos, true); + MWWorld::ActionTeleport action(interior ? cellname.getRefIdString() : "", pos, true); action.execute(player); MWBase::Environment::get().getWindowManager()->fadeScreenOut(0); diff --git a/apps/openmw/mwgui/travelwindow.hpp b/apps/openmw/mwgui/travelwindow.hpp index 75aa7a580f..ff492950f0 100644 --- a/apps/openmw/mwgui/travelwindow.hpp +++ b/apps/openmw/mwgui/travelwindow.hpp @@ -30,7 +30,7 @@ namespace MWGui void onCancelButtonClicked(MyGUI::Widget* _sender); void onTravelButtonClick(MyGUI::Widget* _sender); void onMouseWheel(MyGUI::Widget* _sender, int _rel); - void addDestination(const std::string& name, const ESM::Position& pos, bool interior); + void addDestination(const ESM::RefId& name, const ESM::Position& pos, bool interior); void clearDestinations(); int mCurrentY; diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index 54a78d99bc..49ef0bb4dc 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -200,7 +200,7 @@ namespace MWGui MWWorld::Ptr player = world->getPlayerPtr(); if (mSleeping && player.getCell()->isExterior()) { - const std::string& regionstr = player.getCell()->getCell()->mRegion; + const ESM::RefId& regionstr = player.getCell()->getCell()->mRegion; if (!regionstr.empty()) { const ESM::Region* region = world->getStore().get().find(regionstr); diff --git a/apps/openmw/mwgui/waitdialog.hpp b/apps/openmw/mwgui/waitdialog.hpp index cff0d66bf8..698a066e17 100644 --- a/apps/openmw/mwgui/waitdialog.hpp +++ b/apps/openmw/mwgui/waitdialog.hpp @@ -2,7 +2,7 @@ #define MWGUI_WAIT_DIALOG_H #include "timeadvancer.hpp" - +#include #include "windowbase.hpp" namespace MWGui @@ -59,7 +59,7 @@ namespace MWGui float mFadeTimeRemaining; int mInterruptAt; - std::string mInterruptCreatureList; + ESM::RefId mInterruptCreatureList; WaitDialogProgressBar mProgressBar; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 64c03f6700..3dbd113cd3 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -203,7 +203,7 @@ namespace MWGui::Widgets { } - void MWSpell::setSpellId(const std::string& spellId) + void MWSpell::setSpellId(const ESM::RefId& spellId) { mId = spellId; updateWidgets(); diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index b3b4f2ec82..feec562d7f 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -9,6 +9,7 @@ #include #include +#include namespace MyGUI { @@ -180,7 +181,7 @@ namespace MWGui public: MWSpell(); - void setSpellId(const std::string& id); + void setSpellId(const ESM::RefId& id); /** * @param vector to store the created effect widgets @@ -193,7 +194,7 @@ namespace MWGui void createEffectWidgets( std::vector& effects, MyGUI::Widget* creator, MyGUI::IntCoord& coord, int flags); - const std::string& getSpellId() const { return mId; } + const ESM::RefId& getSpellId() const { return mId; } protected: virtual ~MWSpell(); @@ -203,7 +204,7 @@ namespace MWGui private: void updateWidgets(); - std::string mId; + ESM::RefId mId; MyGUI::TextBox* mSpellNameWidget; }; typedef MWSpell* MWSpellPtr; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index e3ddfaaed3..d3cc605509 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -341,8 +341,8 @@ namespace MWGui bool questList = mResourceSystem->getVFS()->exists("textures/tx_menubook_options_over.dds"); auto journal = JournalWindow::create(JournalViewModel::create(), questList, mEncoding); mGuiModeStates[GM_Journal] = GuiModeState(journal.get()); - mGuiModeStates[GM_Journal].mCloseSound = "book close"; - mGuiModeStates[GM_Journal].mOpenSound = "book open"; + mGuiModeStates[GM_Journal].mCloseSound = ESM::RefId::stringRefId("book close"); + mGuiModeStates[GM_Journal].mOpenSound = ESM::RefId::stringRefId("book open"); mWindows.push_back(std::move(journal)); mMessageBoxManager = std::make_unique( @@ -379,15 +379,15 @@ namespace MWGui mScrollWindow = scrollWindow.get(); mWindows.push_back(std::move(scrollWindow)); mGuiModeStates[GM_Scroll] = GuiModeState(mScrollWindow); - mGuiModeStates[GM_Scroll].mOpenSound = "scroll"; - mGuiModeStates[GM_Scroll].mCloseSound = "scroll"; + mGuiModeStates[GM_Scroll].mOpenSound = ESM::RefId::stringRefId("scroll"); + mGuiModeStates[GM_Scroll].mCloseSound = ESM::RefId::stringRefId("scroll"); auto bookWindow = std::make_unique(); mBookWindow = bookWindow.get(); mWindows.push_back(std::move(bookWindow)); mGuiModeStates[GM_Book] = GuiModeState(mBookWindow); - mGuiModeStates[GM_Book].mOpenSound = "book open"; - mGuiModeStates[GM_Book].mCloseSound = "book close"; + mGuiModeStates[GM_Book].mOpenSound = ESM::RefId::stringRefId("book open"); + mGuiModeStates[GM_Book].mCloseSound = ESM::RefId::stringRefId("book close"); auto countDialog = std::make_unique(); mCountDialog = countDialog.get(); @@ -804,7 +804,7 @@ namespace MWGui return mMessageBoxManager->readPressedButton(); } - std::string_view WindowManager::getGameSettingString(std::string_view id, std::string_view default_) + std::string_view WindowManager::getGameSettingString(const std::string_view& id, std::string_view default_) { const ESM::GameSetting* setting = mStore->get().search(id); @@ -933,7 +933,7 @@ namespace MWGui { mMap->requestMapRender(cell); - std::string name{ MWBase::Environment::get().getWorld()->getCellName(cell) }; + std::string name = MWBase::Environment::get().getWorld()->getCellName(cell) ; mMap->setCellName(name); mHud->setCellName(name); @@ -1330,7 +1330,7 @@ namespace MWGui mJailScreen->goToJail(days); } - void WindowManager::setSelectedSpell(const std::string& spellId, int successChancePercent) + void WindowManager::setSelectedSpell(const ESM::RefId& spellId, int successChancePercent) { mSelectedSpell = spellId; mSelectedEnchantItem = MWWorld::Ptr(); @@ -1791,7 +1791,7 @@ namespace MWGui if (!mSelectedSpell.empty()) { writer.startRecord(ESM::REC_ASPL); - writer.writeHNString("ID__", mSelectedSpell); + writer.writeHNString("ID__", mSelectedSpell.getRefIdString()); writer.endRecord(ESM::REC_ASPL); } @@ -1813,7 +1813,7 @@ namespace MWGui else if (type == ESM::REC_ASPL) { reader.getSubNameIs("ID__"); - std::string spell = reader.getHString(); + ESM::RefId spell = reader.getRefId(); if (mStore->get().search(spell)) mSelectedSpell = spell; } @@ -2139,7 +2139,7 @@ namespace MWGui mInventoryWindow->cycle(next); } - void WindowManager::playSound(std::string_view soundId, float volume, float pitch) + void WindowManager::playSound(const ESM::RefId& soundId, float volume, float pitch) { if (soundId.empty()) return; diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 6ffc617675..abca6ddcab 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -232,8 +232,8 @@ namespace MWGui /// update activated quick key state (if action executing was delayed for some reason) void updateActivatedQuickKey() override; - const std::string& getSelectedSpell() override { return mSelectedSpell; } - void setSelectedSpell(const std::string& spellId, int successChancePercent) override; + const ESM::RefId& getSelectedSpell() override { return mSelectedSpell; } + void setSelectedSpell(const ESM::RefId& spellId, int successChancePercent) override; void setSelectedEnchantItem(const MWWorld::Ptr& item) override; const MWWorld::Ptr& getSelectedEnchantItem() const override; void setSelectedWeapon(const MWWorld::Ptr& item) override; @@ -283,7 +283,7 @@ namespace MWGui * @param id Identifier for the GMST setting, e.g. "aName" * @param default Default value if the GMST setting cannot be used. */ - std::string_view getGameSettingString(std::string_view id, std::string_view default_) override; + std::string_view getGameSettingString(const std::string_view& id, std::string_view default_) override; void processChangedSettings(const Settings::CategorySettingVector& changed) override; @@ -370,7 +370,7 @@ namespace MWGui /// Cycle to next or previous weapon void cycleWeapon(bool next) override; - void playSound(std::string_view soundId, float volume = 1.f, float pitch = 1.f) override; + void playSound(const ESM::RefId& soundId, float volume = 1.f, float pitch = 1.f) override; void addCell(MWWorld::CellStore* cell) override; void removeCell(MWWorld::CellStore* cell) override; @@ -408,7 +408,7 @@ namespace MWGui void trackWindow(Layout* layout, const std::string& name); void onWindowChangeCoord(MyGUI::Window* _sender); - std::string mSelectedSpell; + ESM::RefId mSelectedSpell; MWWorld::Ptr mSelectedEnchantItem; MWWorld::Ptr mSelectedWeapon; @@ -485,8 +485,8 @@ namespace MWGui std::vector mWindows; - std::string mCloseSound; - std::string mOpenSound; + ESM::RefId mCloseSound; + ESM::RefId mOpenSound; }; // Defines the windows that should be shown in a particular GUI mode. std::map mGuiModeStates; diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index 61f912aa0d..c8186408e9 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -206,7 +206,7 @@ namespace MWInput MyGUI::Button* b = MyGUI::InputManager::getInstance().getMouseFocusWidget()->castType(false); if (b && b->getEnabled()) - MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); } mBindingsManager->setPlayerControlsEnabled(!mousePressSuccess); diff --git a/apps/openmw/mwinput/mousemanager.cpp b/apps/openmw/mwinput/mousemanager.cpp index 113d7c07b9..8caed79e21 100644 --- a/apps/openmw/mwinput/mousemanager.cpp +++ b/apps/openmw/mwinput/mousemanager.cpp @@ -166,7 +166,7 @@ namespace MWInput = MyGUI::InputManager::getInstance().getMouseFocusWidget()->castType(false); if (b && b->getEnabled() && id == SDL_BUTTON_LEFT) { - MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Menu Click")); } } MWBase::Environment::get().getWindowManager()->setCursorActive(true); diff --git a/apps/openmw/mwlua/localscripts.cpp b/apps/openmw/mwlua/localscripts.cpp index 1cd1b2359e..e03f0b7826 100644 --- a/apps/openmw/mwlua/localscripts.cpp +++ b/apps/openmw/mwlua/localscripts.cpp @@ -140,14 +140,14 @@ namespace MWLua const MWWorld::Ptr& ptr = self.ptr(); MWMechanics::AiSequence& ai = ptr.getClass().getCreatureStats(ptr).getAiSequence(); // TODO: change AiEscort implementation to accept ptr instead of a non-unique refId. - const std::string& refId = target.ptr().getCellRef().getRefId(); + const ESM::RefId& refId = target.ptr().getCellRef().getRefId(); int gameHoursDuration = static_cast(std::ceil(duration / 3600.0)); const ESM::Cell* esmCell = cell.mStore->getCell(); if (esmCell->isExterior()) ai.stack(MWMechanics::AiEscort(refId, gameHoursDuration, dest.x(), dest.y(), dest.z(), false), ptr); else ai.stack(MWMechanics::AiEscort( - refId, esmCell->mName, gameHoursDuration, dest.x(), dest.y(), dest.z(), false), + refId, ESM::RefId::stringRefId(esmCell->mName), gameHoursDuration, dest.x(), dest.y(), dest.z(), false), ptr); }; selfAPI["_startAiWander"] = [](SelfObject& self, int distance, float duration) { diff --git a/apps/openmw/mwlua/object.cpp b/apps/openmw/mwlua/object.cpp index 9fa1e22072..d54daa7ea8 100644 --- a/apps/openmw/mwlua/object.cpp +++ b/apps/openmw/mwlua/object.cpp @@ -14,7 +14,7 @@ namespace MWLua bool isMarker(const MWWorld::Ptr& ptr) { - return Misc::ResourceHelpers::isHiddenMarker(ptr.getCellRef().getRefId()); + return Misc::ResourceHelpers::isHiddenMarker(ptr.getCellRef().getRefId().getRefIdString()); } std::string ptrToString(const MWWorld::Ptr& ptr) @@ -24,7 +24,7 @@ namespace MWLua res.append(" ("); res.append(getLuaObjectTypeName(ptr)); res.append(", "); - res.append(ptr.getCellRef().getRefId()); + res.append(ptr.getCellRef().getRefId().getRefIdString()); res.append(")"); return res; } diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index c62c1b7b36..b82338c646 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -167,7 +167,7 @@ namespace MWLua { objectT["isValid"] = [](const ObjectT& o) { return o.isValid(); }; objectT["recordId"] = sol::readonly_property( - [](const ObjectT& o) -> std::string { return o.ptr().getCellRef().getRefId(); }); + [](const ObjectT& o) -> ESM::RefId { return o.ptr().getCellRef().getRefId(); }); objectT["cell"] = sol::readonly_property([](const ObjectT& o) -> sol::optional> { const MWWorld::Ptr& ptr = o.ptr(); if (ptr.isInCell()) @@ -335,7 +335,7 @@ namespace MWLua return ObjectList{ list }; }; - inventoryT["countOf"] = [](const InventoryT& inventory, const std::string& recordId) { + inventoryT["countOf"] = [](const InventoryT& inventory, const ESM::RefId& recordId) { const MWWorld::Ptr& ptr = inventory.mObj.ptr(); MWWorld::ContainerStore& store = ptr.getClass().getContainerStore(ptr); return store.count(recordId); diff --git a/apps/openmw/mwlua/types/activator.cpp b/apps/openmw/mwlua/types/activator.cpp index e9f1a8494b..d303d3d18c 100644 --- a/apps/openmw/mwlua/types/activator.cpp +++ b/apps/openmw/mwlua/types/activator.cpp @@ -27,16 +27,16 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); activator["record"] = sol::overload( [](const Object& obj) -> const ESM::Activator* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Activator* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Activator* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Activator"); record[sol::meta_function::to_string] - = [](const ESM::Activator& rec) { return "ESM3_Activator[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mId; }); + = [](const ESM::Activator& rec) { return "ESM3_Activator[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Activator& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); record["mwscript"] - = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mScript; }); + = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mScript.getRefIdString(); }); } } diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 20c32e4a30..395596dd3d 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -55,7 +55,7 @@ namespace MWLua } else { - const std::string& recordId = std::get(item); + const ESM::RefId& recordId = ESM::RefId::stringRefId(std::get(item)); if (old_it != store.end() && old_it->getCellRef().getRefId() == recordId) return true; // already equipped itemPtr = store.search(recordId); diff --git a/apps/openmw/mwlua/types/apparatus.cpp b/apps/openmw/mwlua/types/apparatus.cpp index 6b65b000f1..243bee1d57 100644 --- a/apps/openmw/mwlua/types/apparatus.cpp +++ b/apps/openmw/mwlua/types/apparatus.cpp @@ -34,17 +34,17 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); apparatus["record"] = sol::overload( [](const Object& obj) -> const ESM::Apparatus* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Apparatus* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Apparatus* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Apparatus"); record[sol::meta_function::to_string] - = [](const ESM::Apparatus& rec) { return "ESM3_Apparatus[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mId; }); + = [](const ESM::Apparatus& rec) { return "ESM3_Apparatus[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Apparatus& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); record["mwscript"] - = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mScript; }); + = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["icon"] = sol::readonly_property([vfs](const ESM::Apparatus& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); diff --git a/apps/openmw/mwlua/types/book.cpp b/apps/openmw/mwlua/types/book.cpp index d65e884cad..e24c5ea5bc 100644 --- a/apps/openmw/mwlua/types/book.cpp +++ b/apps/openmw/mwlua/types/book.cpp @@ -35,20 +35,20 @@ namespace MWLua const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); book["record"] = sol::overload([](const Object& obj) -> const ESM::Book* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Book* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Book* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Book"); - record[sol::meta_function::to_string] = [](const ESM::Book& rec) { return "ESM3_Book[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mId; }); + record[sol::meta_function::to_string] = [](const ESM::Book& rec) { return "ESM3_Book[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Book& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); - record["mwscript"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mScript; }); + record["mwscript"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["icon"] = sol::readonly_property([vfs](const ESM::Book& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); record["text"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mText; }); - record["enchant"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mEnchant; }); + record["enchant"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mEnchant.getRefIdString(); }); record["isScroll"] = sol::readonly_property([](const ESM::Book& rec) -> bool { return rec.mData.mIsScroll; }); record["value"] = sol::readonly_property([](const ESM::Book& rec) -> int { return rec.mData.mValue; }); record["weight"] = sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mWeight; }); diff --git a/apps/openmw/mwlua/types/container.cpp b/apps/openmw/mwlua/types/container.cpp index e799535985..e72cfeaca0 100644 --- a/apps/openmw/mwlua/types/container.cpp +++ b/apps/openmw/mwlua/types/container.cpp @@ -52,17 +52,17 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); container["record"] = sol::overload( [](const Object& obj) -> const ESM::Container* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Container* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Container* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Container"); record[sol::meta_function::to_string] - = [](const ESM::Container& rec) -> std::string { return "ESM3_Container[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mId; }); + = [](const ESM::Container& rec) -> std::string { return "ESM3_Container[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Container& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); record["mwscript"] - = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mScript; }); + = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["weight"] = sol::readonly_property([](const ESM::Container& rec) -> float { return rec.mWeight; }); } } diff --git a/apps/openmw/mwlua/types/creature.cpp b/apps/openmw/mwlua/types/creature.cpp index b900286d7c..3a771f7786 100644 --- a/apps/openmw/mwlua/types/creature.cpp +++ b/apps/openmw/mwlua/types/creature.cpp @@ -27,17 +27,17 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); creature["record"] = sol::overload( [](const Object& obj) -> const ESM::Creature* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Creature* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Creature* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Creature"); record[sol::meta_function::to_string] - = [](const ESM::Creature& rec) { return "ESM3_Creature[" + rec.mId + "]"; }; + = [](const ESM::Creature& rec) { return "ESM3_Creature[" + rec.mId.getRefIdString() + "]"; }; record["name"] = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Creature& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); record["mwscript"] - = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mScript; }); + = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["baseCreature"] - = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mOriginal; }); + = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mOriginal.getRefIdString(); }); } } diff --git a/apps/openmw/mwlua/types/door.cpp b/apps/openmw/mwlua/types/door.cpp index 9ddf3b18fc..c3d67d1d1c 100644 --- a/apps/openmw/mwlua/types/door.cpp +++ b/apps/openmw/mwlua/types/door.cpp @@ -48,20 +48,20 @@ namespace MWLua const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); door["record"] = sol::overload([](const Object& obj) -> const ESM::Door* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Door* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Door* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Door"); record[sol::meta_function::to_string] - = [](const ESM::Door& rec) -> std::string { return "ESM3_Door[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mId; }); + = [](const ESM::Door& rec) -> std::string { return "ESM3_Door[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Door& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); - record["mwscript"] = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mScript; }); + record["mwscript"] = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["openSound"] - = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mOpenSound; }); + = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mOpenSound.getRefIdString(); }); record["closeSound"] - = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mCloseSound; }); + = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mCloseSound.getRefIdString(); }); } } diff --git a/apps/openmw/mwlua/types/ingredient.cpp b/apps/openmw/mwlua/types/ingredient.cpp index 5f119fc729..1c7abf468f 100644 --- a/apps/openmw/mwlua/types/ingredient.cpp +++ b/apps/openmw/mwlua/types/ingredient.cpp @@ -26,15 +26,15 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); ingredient["record"] = sol::overload( [](const Object& obj) -> const ESM::Ingredient* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordID) -> const ESM::Ingredient* { return store->find(recordID); }); + [store](const std::string& recordID) -> const ESM::Ingredient* { return store->find(ESM::RefId::stringRefId(recordID)); }); sol::usertype record = context.mLua->sol().new_usertype(("ESM3_Ingredient")); record[sol::meta_function::to_string] - = [](const ESM::Potion& rec) { return "ESM3_Ingredient[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mId; }); + = [](const ESM::Potion& rec) { return "ESM3_Ingredient[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mModel; }); record["mwscript"] - = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mScript; }); + = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["icon"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mIcon; }); record["weight"] = sol::readonly_property([](const ESM::Ingredient& rec) -> float { return rec.mData.mWeight; }); diff --git a/apps/openmw/mwlua/types/lockpick.cpp b/apps/openmw/mwlua/types/lockpick.cpp index 4bc98f4f6e..f8b05648ce 100644 --- a/apps/openmw/mwlua/types/lockpick.cpp +++ b/apps/openmw/mwlua/types/lockpick.cpp @@ -27,17 +27,17 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); lockpick["record"] = sol::overload( [](const Object& obj) -> const ESM::Lockpick* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Lockpick* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Lockpick* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Lockpick"); record[sol::meta_function::to_string] - = [](const ESM::Lockpick& rec) { return "ESM3_Lockpick[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mId; }); + = [](const ESM::Lockpick& rec) { return "ESM3_Lockpick[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Lockpick& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); record["mwscript"] - = sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mScript; }); + = sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["icon"] = sol::readonly_property([vfs](const ESM::Lockpick& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); diff --git a/apps/openmw/mwlua/types/misc.cpp b/apps/openmw/mwlua/types/misc.cpp index cfb2a89ad5..59c5d1387e 100644 --- a/apps/openmw/mwlua/types/misc.cpp +++ b/apps/openmw/mwlua/types/misc.cpp @@ -27,18 +27,18 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); miscellaneous["record"] = sol::overload( [](const Object& obj) -> const ESM::Miscellaneous* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Miscellaneous* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Miscellaneous* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Miscellaneous"); record[sol::meta_function::to_string] - = [](const ESM::Miscellaneous& rec) { return "ESM3_Miscellaneous[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string { return rec.mId; }); + = [](const ESM::Miscellaneous& rec) { return "ESM3_Miscellaneous[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Miscellaneous& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); record["mwscript"] - = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string { return rec.mScript; }); + = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["icon"] = sol::readonly_property([vfs](const ESM::Miscellaneous& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); diff --git a/apps/openmw/mwlua/types/npc.cpp b/apps/openmw/mwlua/types/npc.cpp index 9cbee90e04..83ca094cf7 100644 --- a/apps/openmw/mwlua/types/npc.cpp +++ b/apps/openmw/mwlua/types/npc.cpp @@ -26,14 +26,14 @@ namespace MWLua const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); npc["record"] = sol::overload([](const Object& obj) -> const ESM::NPC* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::NPC* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::NPC* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_NPC"); - record[sol::meta_function::to_string] = [](const ESM::NPC& rec) { return "ESM3_NPC[" + rec.mId + "]"; }; + record[sol::meta_function::to_string] = [](const ESM::NPC& rec) { return "ESM3_NPC[" + rec.mId.getRefIdString() + "]"; }; record["name"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mName; }); - record["race"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mRace; }); - record["class"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mClass; }); - record["mwscript"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mScript; }); - record["hair"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHair; }); - record["head"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHead; }); + record["race"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mRace.getRefIdString(); }); + record["class"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mClass.getRefIdString(); }); + record["mwscript"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mScript.getRefIdString(); }); + record["hair"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHair.getRefIdString(); }); + record["head"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHead.getRefIdString(); }); } } diff --git a/apps/openmw/mwlua/types/potion.cpp b/apps/openmw/mwlua/types/potion.cpp index d0bb1d8779..d1f9f1242c 100644 --- a/apps/openmw/mwlua/types/potion.cpp +++ b/apps/openmw/mwlua/types/potion.cpp @@ -25,12 +25,12 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); potion["record"] = sol::overload([](const Object& obj) -> const ESM::Potion* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Potion* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Potion* { return store->find(ESM::RefId::stringRefId(recordId)); }); auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Potion"); - record[sol::meta_function::to_string] = [](const ESM::Potion& rec) { return "ESM3_Potion[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mId; }); + record[sol::meta_function::to_string] = [](const ESM::Potion& rec) { return "ESM3_Potion[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Potion& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); @@ -38,7 +38,7 @@ namespace MWLua record["icon"] = sol::readonly_property([vfs](const ESM::Potion& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); - record["mwscript"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mScript; }); + record["mwscript"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["weight"] = sol::readonly_property([](const ESM::Potion& rec) -> float { return rec.mData.mWeight; }); record["value"] = sol::readonly_property([](const ESM::Potion& rec) -> int { return rec.mData.mValue; }); } diff --git a/apps/openmw/mwlua/types/probe.cpp b/apps/openmw/mwlua/types/probe.cpp index 77843b76e0..0482cb5c61 100644 --- a/apps/openmw/mwlua/types/probe.cpp +++ b/apps/openmw/mwlua/types/probe.cpp @@ -26,15 +26,15 @@ namespace MWLua const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); probe["record"] = sol::overload([](const Object& obj) -> const ESM::Probe* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Probe* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Probe* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Probe"); - record[sol::meta_function::to_string] = [](const ESM::Probe& rec) { return "ESM3_Probe[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mId; }); + record[sol::meta_function::to_string] = [](const ESM::Probe& rec) { return "ESM3_Probe[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Probe& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); - record["mwscript"] = sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mScript; }); + record["mwscript"] = sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["icon"] = sol::readonly_property([vfs](const ESM::Probe& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); diff --git a/apps/openmw/mwlua/types/repair.cpp b/apps/openmw/mwlua/types/repair.cpp index dbf42707b6..ed13ebbd14 100644 --- a/apps/openmw/mwlua/types/repair.cpp +++ b/apps/openmw/mwlua/types/repair.cpp @@ -27,15 +27,15 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); repair["record"] = sol::overload([](const Object& obj) -> const ESM::Repair* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Repair* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Repair* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Repair"); - record[sol::meta_function::to_string] = [](const ESM::Repair& rec) { return "ESM3_Repair[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mId; }); + record[sol::meta_function::to_string] = [](const ESM::Repair& rec) { return "ESM3_Repair[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Repair& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); }); - record["mwscript"] = sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mScript; }); + record["mwscript"] = sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["icon"] = sol::readonly_property([vfs](const ESM::Repair& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); diff --git a/apps/openmw/mwlua/types/types.cpp b/apps/openmw/mwlua/types/types.cpp index 73f063a777..5a308fa619 100644 --- a/apps/openmw/mwlua/types/types.cpp +++ b/apps/openmw/mwlua/types/types.cpp @@ -65,10 +65,10 @@ namespace MWLua { if (ref == nullptr) throw std::runtime_error("Can't get type name from an empty object."); - const std::string_view id = ref->mRef.getRefId(); - if (id == "player") + const ESM::RefId& id = ref->mRef.getRefId(); + if (id == ESM::RefId::stringRefId("player")) return ESM::REC_INTERNAL_PLAYER; - if (Misc::ResourceHelpers::isHiddenMarker(id)) + if (Misc::ResourceHelpers::isHiddenMarker(id.getRefIdString())) return ESM::REC_INTERNAL_MARKER; return ref->getType(); } diff --git a/apps/openmw/mwlua/types/weapon.cpp b/apps/openmw/mwlua/types/weapon.cpp index 1f3ab35c2c..308a9adc67 100644 --- a/apps/openmw/mwlua/types/weapon.cpp +++ b/apps/openmw/mwlua/types/weapon.cpp @@ -44,11 +44,11 @@ namespace MWLua = &MWBase::Environment::get().getWorld()->getStore().get(); weapon["record"] = sol::overload([](const Object& obj) -> const ESM::Weapon* { return obj.ptr().get()->mBase; }, - [store](const std::string& recordId) -> const ESM::Weapon* { return store->find(recordId); }); + [store](const std::string& recordId) -> const ESM::Weapon* { return store->find(ESM::RefId::stringRefId(recordId)); }); sol::usertype record = context.mLua->sol().new_usertype("ESM3_Weapon"); record[sol::meta_function::to_string] - = [](const ESM::Weapon& rec) -> std::string { return "ESM3_Weapon[" + rec.mId + "]"; }; - record["id"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mId; }); + = [](const ESM::Weapon& rec) -> std::string { return "ESM3_Weapon[" + rec.mId.getRefIdString() + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mId.getRefIdString(); }); record["name"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mName; }); record["model"] = sol::readonly_property([vfs](const ESM::Weapon& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); @@ -56,8 +56,8 @@ namespace MWLua record["icon"] = sol::readonly_property([vfs](const ESM::Weapon& rec) -> std::string { return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs); }); - record["enchant"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mEnchant; }); - record["mwscript"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mScript; }); + record["enchant"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mEnchant.getRefIdString(); }); + record["mwscript"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mScript.getRefIdString(); }); record["isMagical"] = sol::readonly_property( [](const ESM::Weapon& rec) -> bool { return rec.mData.mFlags & ESM::Weapon::Magical; }); record["isSilver"] = sol::readonly_property( diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 9cef5142a8..230da2ef69 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -247,7 +247,7 @@ namespace MWMechanics auto slot = store.getSlot(slotIndex); if (slot == store.end()) continue; - const std::string_view enchantmentId = slot->getClass().getEnchantment(*slot); + const ESM::RefId& enchantmentId = slot->getClass().getEnchantment(*slot); if (enchantmentId.empty()) continue; const ESM::Enchantment* enchantment = world->getStore().get().find(enchantmentId); @@ -325,7 +325,7 @@ namespace MWMechanics if (reflected) { const ESM::Static* reflectStatic - = MWBase::Environment::get().getWorld()->getStore().get().find("VFX_Reflect"); + = MWBase::Environment::get().getWorld()->getStore().get().find(ESM::RefId::stringRefId("VFX_Reflect")); MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(ptr); if (animation && !reflectStatic->mModel.empty()) { @@ -416,10 +416,10 @@ namespace MWMechanics return mSpells.end(); } - bool ActiveSpells::isSpellActive(std::string_view id) const + bool ActiveSpells::isSpellActive(const ESM::RefId& id) const { return std::find_if(mSpells.begin(), mSpells.end(), [&](const auto& spell) { - return Misc::StringUtils::ciEqual(spell.mId, id); + return ESM::RefId::ciEqual(spell.mId, id); }) != mSpells.end(); } @@ -518,7 +518,7 @@ namespace MWMechanics return removedCurrentSpell; } - void ActiveSpells::removeEffects(const MWWorld::Ptr& ptr, std::string_view id) + void ActiveSpells::removeEffects(const MWWorld::Ptr& ptr, const ESM::RefId& id) { purge([=](const ActiveSpellParams& params) { return params.mId == id; }, ptr); } diff --git a/apps/openmw/mwmechanics/activespells.hpp b/apps/openmw/mwmechanics/activespells.hpp index 38445a0a7f..b70d45634c 100644 --- a/apps/openmw/mwmechanics/activespells.hpp +++ b/apps/openmw/mwmechanics/activespells.hpp @@ -33,7 +33,7 @@ namespace MWMechanics using ActiveEffect = ESM::ActiveEffect; class ActiveSpellParams { - std::string mId; + ESM::RefId mId; std::vector mEffects; std::string mDisplayName; int mCasterActorId; @@ -58,7 +58,7 @@ namespace MWMechanics public: ActiveSpellParams(const CastSpell& cast, const MWWorld::Ptr& caster); - const std::string& getId() const { return mId; } + const ESM::RefId& getId() const { return mId; } const std::vector& getEffects() const { return mEffects; } std::vector& getEffects() { return mEffects; } @@ -127,7 +127,7 @@ namespace MWMechanics void addSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor); /// Removes the active effects from this spell/potion/.. with \a id - void removeEffects(const MWWorld::Ptr& ptr, std::string_view id); + void removeEffects(const MWWorld::Ptr& ptr, const ESM::RefId& id); /// Remove all active effects with this effect id void purgeEffect(const MWWorld::Ptr& ptr, short effectId); @@ -141,7 +141,7 @@ namespace MWMechanics /// Remove all spells void clear(const MWWorld::Ptr& ptr); - bool isSpellActive(std::string_view id) const; + bool isSpellActive(const ESM::RefId& id) const; ///< case insensitive void skipWorsenings(double hours); diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 11df481c5e..c5eab906b4 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -208,7 +208,7 @@ namespace if (caster == MWMechanics::getPlayer()) MWBase::Environment::get().getWindowManager()->messageBox("#{sSoultrapSuccess}"); - const ESM::Static* const fx = world->getStore().get().search("VFX_Soul_Trap"); + const ESM::Static* const fx = world->getStore().get().search(ESM::RefId::stringRefId("VFX_Soul_Trap")); if (fx != nullptr) { const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); @@ -217,7 +217,7 @@ namespace } MWBase::Environment::get().getSoundManager()->playSound3D( - creature.getRefData().getPosition().asVec3(), "conjuration hit", 1.f, 1.f); + creature.getRefData().getPosition().asVec3(), ESM::RefId::stringRefId("conjuration hit"), 1.f, 1.f); return; // remove to get vanilla behaviour } } @@ -411,7 +411,7 @@ namespace MWMechanics = world->getStore().get().find("fVoiceIdleOdds")->mValue.getFloat(); if (Misc::Rng::rollProbability(world->getPrng()) * 10000.f < fVoiceIdleOdds * delta && world->getLOS(getPlayer(), actor)) - MWBase::Environment::get().getDialogueManager()->say(actor, "idle"); + MWBase::Environment::get().getDialogueManager()->say(actor, ESM::RefId::stringRefId("idle")); } void Actors::updateMovementSpeed(const MWWorld::Ptr& actor) const @@ -505,7 +505,7 @@ namespace MWMechanics if (greetingTimer >= GREETING_SHOULD_START) { greetingState = Greet_InProgress; - MWBase::Environment::get().getDialogueManager()->say(actor, "hello"); + MWBase::Environment::get().getDialogueManager()->say(actor, ESM::RefId::stringRefId("hello")); greetingTimer = 0; } } @@ -973,8 +973,9 @@ namespace MWMechanics // Play a drowning sound MWBase::SoundManager* sndmgr = MWBase::Environment::get().getSoundManager(); - if (!sndmgr->getSoundPlaying(ptr, "drown")) - sndmgr->playSound3D(ptr, "drown", 1.0f, 1.0f); + auto soundDrown = ESM::RefId::stringRefId("drown"); + if (!sndmgr->getSoundPlaying(ptr, soundDrown)) + sndmgr->playSound3D(ptr, soundDrown, 1.0f, 1.0f); if (isPlayer) MWBase::Environment::get().getWindowManager()->activateHitOverlay(false); @@ -1073,7 +1074,7 @@ namespace MWMechanics // ...But, only the player makes a sound. if (isPlayer) MWBase::Environment::get().getSoundManager()->playSound( - "torch out", 1.0, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv); + ESM::RefId::stringRefId("torch out"), 1.0, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv); } } } @@ -1240,7 +1241,7 @@ namespace MWMechanics } } - void Actors::castSpell(const MWWorld::Ptr& ptr, const std::string& spellId, bool manualSpell) const + void Actors::castSpell(const MWWorld::Ptr& ptr, const ESM::RefId& spellId, bool manualSpell) const { const auto iter = mIndex.find(ptr.mRef); if (iter != mIndex.end()) @@ -1752,7 +1753,7 @@ namespace MWMechanics { actor.getClass().getCreatureStats(actor).notifyDied(); - ++mDeathCount[Misc::StringUtils::lowerCase(actor.getCellRef().getRefId())]; + ++mDeathCount[actor.getCellRef().getRefId()]; } void Actors::resurrect(const MWWorld::Ptr& ptr) const @@ -1786,7 +1787,7 @@ namespace MWMechanics // Play dying words // Note: It's not known whether the soundgen tags scream, roar, and moan are reliable // for NPCs since some of the npc death animation files are missing them. - MWBase::Environment::get().getDialogueManager()->say(actor.getPtr(), "hit"); + MWBase::Environment::get().getDialogueManager()->say(actor.getPtr(), ESM::RefId::stringRefId("hit")); // Apply soultrap if (actor.getPtr().getType() == ESM::Creature::sRecordId) @@ -1833,7 +1834,7 @@ namespace MWMechanics MWBase::Environment::get().getWorld()->deleteObject(ptr); const ESM::Static* fx - = MWBase::Environment::get().getWorld()->getStore().get().search("VFX_Summon_End"); + = MWBase::Environment::get().getWorld()->getStore().get().search(ESM::RefId::stringRefId("VFX_Summon_End")); if (fx) { const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); @@ -2002,7 +2003,7 @@ namespace MWMechanics return static_cast(std::ceil(std::max(1.f, std::max(healthHours, magickaHours)))); } - int Actors::countDeaths(const std::string& id) const + int Actors::countDeaths(const ESM::RefId& id) const { const auto iter = mDeathCount.find(id); if (iter != mDeathCount.end()) @@ -2270,7 +2271,7 @@ namespace MWMechanics writer.startRecord(ESM::REC_DCOU); for (const auto& [id, count] : mDeathCount) { - writer.writeHNString("ID__", id); + writer.writeHNString("ID__", id.getRefIdString()); writer.writeHNT("COUN", count); } writer.endRecord(ESM::REC_DCOU); @@ -2282,7 +2283,7 @@ namespace MWMechanics { while (reader.isNextSub("ID__")) { - std::string id = reader.getHString(); + ESM::RefId id = reader.getRefId(); int count; reader.getHNT(count, "COUN"); if (MWBase::Environment::get().getWorld()->getStore().find(id)) diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp index f9ce7eb3cc..2a57843bcf 100644 --- a/apps/openmw/mwmechanics/actors.hpp +++ b/apps/openmw/mwmechanics/actors.hpp @@ -71,7 +71,7 @@ namespace MWMechanics void resurrect(const MWWorld::Ptr& ptr) const; - void castSpell(const MWWorld::Ptr& ptr, const std::string& spellId, bool manualSpell = false) const; + void castSpell(const MWWorld::Ptr& ptr, const ESM::RefId& spellId, bool manualSpell = false) const; void updateActor(const MWWorld::Ptr& old, const MWWorld::Ptr& ptr) const; ///< Updates an actor with a new Ptr @@ -111,7 +111,7 @@ namespace MWMechanics void fastForwardAi() const; ///< Simulate the passing of time - int countDeaths(const std::string& id) const; + int countDeaths(const ESM::RefId& id) const; ///< Return the number of deaths for actors with the given ID. bool isAttackPreparing(const MWWorld::Ptr& ptr) const; @@ -177,7 +177,7 @@ namespace MWMechanics Battle }; - std::map mDeathCount; + std::map mDeathCount; std::list mActors; std::map::iterator> mIndex; float mTimerDisposeSummonsCorpses; diff --git a/apps/openmw/mwmechanics/aiactivate.cpp b/apps/openmw/mwmechanics/aiactivate.cpp index 43dcb33a7a..5c47813d6d 100644 --- a/apps/openmw/mwmechanics/aiactivate.cpp +++ b/apps/openmw/mwmechanics/aiactivate.cpp @@ -13,7 +13,7 @@ namespace MWMechanics { - AiActivate::AiActivate(std::string_view objectId, bool repeat) + AiActivate::AiActivate(const ESM::RefId& objectId, bool repeat) : TypedAiPackage(repeat) , mObjectId(objectId) { diff --git a/apps/openmw/mwmechanics/aiactivate.hpp b/apps/openmw/mwmechanics/aiactivate.hpp index 01b469f3aa..3d0f6d8b8a 100644 --- a/apps/openmw/mwmechanics/aiactivate.hpp +++ b/apps/openmw/mwmechanics/aiactivate.hpp @@ -2,7 +2,7 @@ #define GAME_MWMECHANICS_AIACTIVATE_H #include "typedaipackage.hpp" - +#include #include #include @@ -23,7 +23,7 @@ namespace MWMechanics public: /// Constructor /** \param objectId Reference to object to activate **/ - explicit AiActivate(std::string_view objectId, bool repeat); + explicit AiActivate(const ESM::RefId& objectId, bool repeat); explicit AiActivate(const ESM::AiSequence::AiActivate* activate); @@ -35,7 +35,7 @@ namespace MWMechanics void writeState(ESM::AiSequence::AiSequence& sequence) const override; private: - const std::string mObjectId; + const ESM::RefId mObjectId; }; } #endif // GAME_MWMECHANICS_AIACTIVATE_H diff --git a/apps/openmw/mwmechanics/aicast.cpp b/apps/openmw/mwmechanics/aicast.cpp index 9170ee9b57..2b8582d261 100644 --- a/apps/openmw/mwmechanics/aicast.cpp +++ b/apps/openmw/mwmechanics/aicast.cpp @@ -15,7 +15,7 @@ namespace MWMechanics { namespace { - float getInitialDistance(const std::string& spellId) + float getInitialDistance(const ESM::RefId& spellId) { ActionSpell action = ActionSpell(spellId); bool isRanged; @@ -24,7 +24,7 @@ namespace MWMechanics } } -MWMechanics::AiCast::AiCast(const std::string& targetId, const std::string& spellId, bool manualSpell) +MWMechanics::AiCast::AiCast(const ESM::RefId& targetId, const ESM::RefId& spellId, bool manualSpell) : mTargetId(targetId) , mSpellId(spellId) , mCasting(false) diff --git a/apps/openmw/mwmechanics/aicast.hpp b/apps/openmw/mwmechanics/aicast.hpp index e3ab224d7d..435458cc0f 100644 --- a/apps/openmw/mwmechanics/aicast.hpp +++ b/apps/openmw/mwmechanics/aicast.hpp @@ -2,6 +2,7 @@ #define GAME_MWMECHANICS_AICAST_H #include "typedaipackage.hpp" +#include namespace MWWorld { @@ -14,7 +15,7 @@ namespace MWMechanics class AiCast final : public TypedAiPackage { public: - AiCast(const std::string& targetId, const std::string& spellId, bool manualSpell = false); + AiCast(const ESM::RefId& targetId, const ESM::RefId& spellId, bool manualSpell = false); bool execute(const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) override; @@ -33,8 +34,8 @@ namespace MWMechanics } private: - const std::string mTargetId; - const std::string mSpellId; + const ESM::RefId mTargetId; + const ESM::RefId mSpellId; bool mCasting; const bool mManual; const float mDistance; diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 4cf3f3ac6c..58dcc29bbd 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -222,7 +222,7 @@ namespace MWMechanics if (currentAction->isFleeing()) { storage.startFleeing(); - MWBase::Environment::get().getDialogueManager()->say(actor, "flee"); + MWBase::Environment::get().getDialogueManager()->say(actor, ESM::RefId::stringRefId("flee")); return false; } else @@ -316,7 +316,7 @@ namespace MWMechanics currentAction = std::make_unique(); actionCooldown = currentAction->getActionCooldown(); storage.startFleeing(); - MWBase::Environment::get().getDialogueManager()->say(actor, "flee"); + MWBase::Environment::get().getDialogueManager()->say(actor, ESM::RefId::stringRefId("flee")); } } else @@ -662,7 +662,7 @@ namespace MWMechanics = store.get().find("iVoiceAttackOdds")->mValue.getInteger(); if (Misc::Rng::roll0to99(prng) < iVoiceAttackOdds) { - MWBase::Environment::get().getDialogueManager()->say(actor, "attack"); + MWBase::Environment::get().getDialogueManager()->say(actor, ESM::RefId::stringRefId("attack")); } mAttackCooldown = std::min(baseDelay + 0.01 * Misc::Rng::roll0to99(prng), baseDelay + 0.9); } diff --git a/apps/openmw/mwmechanics/aicombataction.cpp b/apps/openmw/mwmechanics/aicombataction.cpp index 1d73a77059..566aa4e991 100644 --- a/apps/openmw/mwmechanics/aicombataction.cpp +++ b/apps/openmw/mwmechanics/aicombataction.cpp @@ -73,7 +73,7 @@ namespace MWMechanics void ActionEnchantedItem::prepare(const MWWorld::Ptr& actor) { - actor.getClass().getCreatureStats(actor).getSpells().setSelectedSpell(std::string()); + actor.getClass().getCreatureStats(actor).getSpells().setSelectedSpell(ESM::RefId::sEmpty); actor.getClass().getInventoryStore(actor).setSelectedEnchantItem(mItem); actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Spell); } @@ -325,7 +325,7 @@ namespace MWMechanics const MWWorld::Store& gmst = MWBase::Environment::get().getWorld()->getStore().get(); - const std::string& selectedSpellId = stats.getSpells().getSelectedSpell(); + const ESM::RefId& selectedSpellId = stats.getSpells().getSelectedSpell(); MWWorld::Ptr selectedEnchItem; MWWorld::Ptr activeWeapon, activeAmmo; @@ -373,7 +373,7 @@ namespace MWMechanics } else if (!selectedEnchItem.isEmpty()) { - std::string_view enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem); + const ESM::RefId& enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem); if (!enchId.empty()) { const ESM::Enchantment* ench diff --git a/apps/openmw/mwmechanics/aicombataction.hpp b/apps/openmw/mwmechanics/aicombataction.hpp index e6b87064e5..9b91dfd5b6 100644 --- a/apps/openmw/mwmechanics/aicombataction.hpp +++ b/apps/openmw/mwmechanics/aicombataction.hpp @@ -34,11 +34,11 @@ namespace MWMechanics class ActionSpell : public Action { public: - ActionSpell(const std::string& spellId) + ActionSpell(const ESM::RefId& spellId) : mSpellId(spellId) { } - std::string mSpellId; + ESM::RefId mSpellId; /// Sets the given spell as selected on the actor's spell list. void prepare(const MWWorld::Ptr& actor) override; diff --git a/apps/openmw/mwmechanics/aiescort.cpp b/apps/openmw/mwmechanics/aiescort.cpp index 33eb48b58e..4b98d5eebb 100644 --- a/apps/openmw/mwmechanics/aiescort.cpp +++ b/apps/openmw/mwmechanics/aiescort.cpp @@ -20,7 +20,7 @@ namespace MWMechanics { - AiEscort::AiEscort(std::string_view actorId, int duration, float x, float y, float z, bool repeat) + AiEscort::AiEscort(const ESM::RefId& actorId, int duration, float x, float y, float z, bool repeat) : TypedAiPackage(repeat) , mX(x) , mY(y) @@ -30,11 +30,11 @@ namespace MWMechanics , mCellX(std::numeric_limits::max()) , mCellY(std::numeric_limits::max()) { - mTargetActorRefId = std::string(actorId); + mTargetActorRefId = actorId; } AiEscort::AiEscort( - std::string_view actorId, std::string_view cellId, int duration, float x, float y, float z, bool repeat) + const ESM::RefId& actorId, const ESM::RefId& cellId, int duration, float x, float y, float z, bool repeat) : TypedAiPackage(repeat) , mCellId(cellId) , mX(x) @@ -45,7 +45,7 @@ namespace MWMechanics , mCellX(std::numeric_limits::max()) , mCellY(std::numeric_limits::max()) { - mTargetActorRefId = std::string(actorId); + mTargetActorRefId = actorId; } AiEscort::AiEscort(const ESM::AiSequence::AiEscort* escort) @@ -78,7 +78,7 @@ namespace MWMechanics } } - if (!mCellId.empty() && mCellId != actor.getCell()->getCell()->getCellId().mWorldspace) + if (!mCellId.empty() && mCellId.getRefIdString() != actor.getCell()->getCell()->getCellId().mWorldspace) return false; // Not in the correct cell, pause and rely on the player to go back through a teleport door actor.getClass().getCreatureStats(actor).setDrawState(DrawState::Nothing); diff --git a/apps/openmw/mwmechanics/aiescort.hpp b/apps/openmw/mwmechanics/aiescort.hpp index 32a14131df..ee5cfddbde 100644 --- a/apps/openmw/mwmechanics/aiescort.hpp +++ b/apps/openmw/mwmechanics/aiescort.hpp @@ -23,12 +23,12 @@ namespace MWMechanics /// Implementation of AiEscort /** The Actor will escort the specified actor to the world position x, y, z until they reach their position, or they run out of time \implement AiEscort **/ - AiEscort(std::string_view actorId, int duration, float x, float y, float z, bool repeat); + AiEscort(const ESM::RefId& actorId, int duration, float x, float y, float z, bool repeat); /// Implementation of AiEscortCell /** The Actor will escort the specified actor to the cell position x, y, z until they reach their position, or they run out of time \implement AiEscortCell **/ AiEscort( - std::string_view actorId, std::string_view cellId, int duration, float x, float y, float z, bool repeat); + const ESM::RefId& actorId, const ESM::RefId& cellId, int duration, float x, float y, float z, bool repeat); AiEscort(const ESM::AiSequence::AiEscort* escort); @@ -52,7 +52,7 @@ namespace MWMechanics osg::Vec3f getDestination() const override { return osg::Vec3f(mX, mY, mZ); } private: - const std::string mCellId; + const ESM::RefId mCellId; const float mX; const float mY; const float mZ; diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index fbce10bebf..a2cf383ab8 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -27,7 +27,7 @@ namespace MWMechanics { int AiFollow::mFollowIndexCounter = 0; - AiFollow::AiFollow(std::string_view actorId, float duration, float x, float y, float z, bool repeat) + AiFollow::AiFollow(const ESM::RefId& actorId, float duration, float x, float y, float z, bool repeat) : TypedAiPackage(repeat) , mAlwaysFollow(false) , mDuration(duration) @@ -35,15 +35,15 @@ namespace MWMechanics , mX(x) , mY(y) , mZ(z) - , mCellId("") + , mCellId(ESM::RefId::sEmpty) , mActive(false) , mFollowIndex(mFollowIndexCounter++) { - mTargetActorRefId = std::string(actorId); + mTargetActorRefId = actorId; } AiFollow::AiFollow( - std::string_view actorId, std::string_view cellId, float duration, float x, float y, float z, bool repeat) + const ESM::RefId& actorId, const ESM::RefId& cellId, float duration, float x, float y, float z, bool repeat) : TypedAiPackage(repeat) , mAlwaysFollow(false) , mDuration(duration) @@ -55,7 +55,7 @@ namespace MWMechanics , mActive(false) , mFollowIndex(mFollowIndexCounter++) { - mTargetActorRefId = std::string(actorId); + mTargetActorRefId = actorId; } AiFollow::AiFollow(const MWWorld::Ptr& actor, bool commanded) @@ -66,7 +66,7 @@ namespace MWMechanics , mX(0) , mY(0) , mZ(0) - , mCellId("") + , mCellId(ESM::RefId::sEmpty) , mActive(false) , mFollowIndex(mFollowIndexCounter++) { @@ -169,13 +169,13 @@ namespace MWMechanics { if (actor.getCell()->isExterior()) // Outside? { - if (mCellId == "") // No cell to travel to + if (mCellId == ESM::RefId::sEmpty) // No cell to travel to { mRemainingDuration = mDuration; return true; } } - else if (mCellId == actor.getCell()->getCell()->mName) // Cell to travel to + else if (mCellId.getRefIdString() == actor.getCell()->getCell()->mName) // Cell to travel to { mRemainingDuration = mDuration; return true; @@ -221,7 +221,7 @@ namespace MWMechanics return false; } - std::string AiFollow::getFollowedActor() + ESM::RefId AiFollow::getFollowedActor() { return mTargetActorRefId; } diff --git a/apps/openmw/mwmechanics/aifollow.hpp b/apps/openmw/mwmechanics/aifollow.hpp index 6f20336efa..5f57c11e9c 100644 --- a/apps/openmw/mwmechanics/aifollow.hpp +++ b/apps/openmw/mwmechanics/aifollow.hpp @@ -42,10 +42,10 @@ namespace MWMechanics { public: /// Follow Actor for duration or until you arrive at a world position - AiFollow(std::string_view actorId, float duration, float x, float y, float z, bool repeat); + AiFollow(const ESM::RefId& actorId, float duration, float x, float y, float z, bool repeat); /// Follow Actor for duration or until you arrive at a position in a cell AiFollow( - std::string_view actorId, std::string_view cellId, float duration, float x, float y, float z, bool repeat); + const ESM::RefId& actorId, const ESM::RefId& cellId, float duration, float x, float y, float z, bool repeat); /// Follow Actor indefinitively AiFollow(const MWWorld::Ptr& actor, bool commanded = false); @@ -66,7 +66,7 @@ namespace MWMechanics } /// Returns the actor being followed - std::string getFollowedActor(); + ESM::RefId getFollowedActor(); void writeState(ESM::AiSequence::AiSequence& sequence) const override; @@ -94,7 +94,7 @@ namespace MWMechanics const float mX; const float mY; const float mZ; - const std::string mCellId; + const ESM::RefId mCellId; bool mActive; // have we spotted the target? const int mFollowIndex; diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index 689a3b0a95..25ba126ee8 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -49,7 +49,7 @@ MWMechanics::AiPackage::AiPackage(AiPackageTypeId typeId, const Options& options : mTypeId(typeId) , mOptions(options) , mReaction(MWBase::Environment::get().getWorld()->getPrng()) - , mTargetActorRefId("") + , mTargetActorRefId(ESM::RefId::sEmpty) , mTargetActorId(-1) , mCachedTarget() , mRotateOnTheRunChecks(0) @@ -308,7 +308,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor) return; } - const std::string& keyId = door.getCellRef().getKey(); + const ESM::RefId& keyId = door.getCellRef().getKey(); if (keyId.empty()) return; diff --git a/apps/openmw/mwmechanics/aipackage.hpp b/apps/openmw/mwmechanics/aipackage.hpp index be46315203..16f477dae7 100644 --- a/apps/openmw/mwmechanics/aipackage.hpp +++ b/apps/openmw/mwmechanics/aipackage.hpp @@ -160,7 +160,7 @@ namespace MWMechanics AiReactionTimer mReaction; - std::string mTargetActorRefId; + ESM::RefId mTargetActorRefId; mutable int mTargetActorId; mutable MWWorld::Ptr mCachedTarget; diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 1cd499dc7e..160b7b2f75 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -456,7 +456,7 @@ namespace MWMechanics { ESM::AITarget data = esmPackage.mTarget; package = std::make_unique( - data.mId.toStringView(), data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); + ESM::RefId::stringRefId(data.mId.toStringView()), data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); } else if (esmPackage.mType == ESM::AI_Travel) { @@ -466,13 +466,13 @@ namespace MWMechanics else if (esmPackage.mType == ESM::AI_Activate) { ESM::AIActivate data = esmPackage.mActivate; - package = std::make_unique(data.mName.toStringView(), data.mShouldRepeat != 0); + package = std::make_unique(ESM::RefId::stringRefId(data.mName.toStringView()), data.mShouldRepeat != 0); } else // if (esmPackage.mType == ESM::AI_Follow) { ESM::AITarget data = esmPackage.mTarget; package = std::make_unique( - data.mId.toStringView(), data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); + ESM::RefId::stringRefId(data.mId.toStringView()), data.mDuration, data.mX, data.mY, data.mZ, data.mShouldRepeat != 0); } onPackageAdded(*package); diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index fe2d1861ae..4f9c5b20ae 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -449,7 +449,7 @@ int MWMechanics::Alchemy::addIngredient(const MWWorld::Ptr& ingredient) for (TIngredientsIterator iter(mIngredients.begin()); iter != mIngredients.end(); ++iter) if (!iter->isEmpty() - && Misc::StringUtils::ciEqual(ingredient.getCellRef().getRefId(), iter->getCellRef().getRefId())) + && ESM::RefId::ciEqual(ingredient.getCellRef().getRefId(), iter->getCellRef().getRefId())) return -1; mIngredients[slot] = ingredient; diff --git a/apps/openmw/mwmechanics/autocalcspell.cpp b/apps/openmw/mwmechanics/autocalcspell.cpp index 72398e456d..ec386c0add 100644 --- a/apps/openmw/mwmechanics/autocalcspell.cpp +++ b/apps/openmw/mwmechanics/autocalcspell.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -23,11 +24,10 @@ namespace MWMechanics int mLimit; bool mReachedLimit; int mMinCost; - std::string mWeakestSpell; + ESM::RefId mWeakestSpell; }; - std::vector autoCalcNpcSpells( - const int* actorSkills, const int* actorAttributes, const ESM::Race* race) + std::vector autoCalcNpcSpells(const int* actorSkills, const int* actorAttributes, const ESM::Race* race) { const MWWorld::Store& gmst = MWBase::Environment::get().getWorld()->getStore().get(); @@ -60,7 +60,7 @@ namespace MWMechanics schoolCaps[i] = caps; } - std::vector selectedSpells; + std::vector selectedSpells; const MWWorld::Store& spells = MWBase::Environment::get().getWorld()->getStore().get(); @@ -100,13 +100,13 @@ namespace MWMechanics if (cap.mReachedLimit) { - std::vector::iterator found + auto found = std::find(selectedSpells.begin(), selectedSpells.end(), cap.mWeakestSpell); if (found != selectedSpells.end()) selectedSpells.erase(found); cap.mMinCost = std::numeric_limits::max(); - for (const std::string& testSpellName : selectedSpells) + for (const ESM::RefId& testSpellName : selectedSpells) { const ESM::Spell* testSpell = spells.find(testSpellName); int testSpellCost = MWMechanics::calcSpellCost(*testSpell); @@ -148,8 +148,7 @@ namespace MWMechanics return selectedSpells; } - std::vector autoCalcPlayerSpells( - const int* actorSkills, const int* actorAttributes, const ESM::Race* race) + std::vector autoCalcPlayerSpells(const int* actorSkills, const int* actorAttributes, const ESM::Race* race) { const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); @@ -161,7 +160,7 @@ namespace MWMechanics const ESM::Spell* weakestSpell = nullptr; int minCost = std::numeric_limits::max(); - std::vector selectedSpells; + std::vector selectedSpells; const MWWorld::Store& spells = esmStore.get(); for (const ESM::Spell& spell : spells) @@ -193,13 +192,13 @@ namespace MWMechanics if (reachedLimit) { - std::vector::iterator it + std::vector::iterator it = std::find(selectedSpells.begin(), selectedSpells.end(), weakestSpell->mId); if (it != selectedSpells.end()) selectedSpells.erase(it); minCost = std::numeric_limits::max(); - for (const std::string& testSpellName : selectedSpells) + for (const ESM::RefId& testSpellName : selectedSpells) { const ESM::Spell* testSpell = esmStore.get().find(testSpellName); int testSpellCost = MWMechanics::calcSpellCost(*testSpell); diff --git a/apps/openmw/mwmechanics/autocalcspell.hpp b/apps/openmw/mwmechanics/autocalcspell.hpp index 444077f3fe..d5bbdf1b54 100644 --- a/apps/openmw/mwmechanics/autocalcspell.hpp +++ b/apps/openmw/mwmechanics/autocalcspell.hpp @@ -3,7 +3,7 @@ #include #include - +#include namespace ESM { struct Spell; @@ -16,10 +16,10 @@ namespace MWMechanics /// Contains algorithm for calculating an NPC's spells based on stats /// @note We might want to move this code to a component later, so the editor can use it for preview purposes - std::vector autoCalcNpcSpells( + std::vector autoCalcNpcSpells( const int* actorSkills, const int* actorAttributes, const ESM::Race* race); - std::vector autoCalcPlayerSpells( + std::vector autoCalcPlayerSpells( const int* actorSkills, const int* actorAttributes, const ESM::Race* race); // Helpers diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index fe88ec2dba..229c912a51 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -999,7 +999,7 @@ namespace MWMechanics if (evt.substr(0, 7) == "sound: ") { MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - sndMgr->playSound3D(mPtr, evt.substr(7), 1.0f, 1.0f); + sndMgr->playSound3D(mPtr, ESM::RefId::stringRefId(evt.substr(7)), 1.0f, 1.0f); return; } @@ -1029,7 +1029,7 @@ namespace MWMechanics } } - std::string_view sound = charClass.getSoundIdFromSndGen(mPtr, soundgen); + auto sound = charClass.getSoundIdFromSndGen(mPtr, soundgen); if (!sound.empty()) { MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); @@ -1234,7 +1234,7 @@ namespace MWMechanics const bool isWerewolf = cls.isNpc() && cls.getNpcStats(mPtr).isWerewolf(); - std::string_view downSoundId; + const ESM::RefId* downSoundId = nullptr; bool weaponChanged = false; bool ammunition = true; float weapSpeed = 1.f; @@ -1250,11 +1250,11 @@ namespace MWMechanics { newWeapon = *weapon; if (isRealWeapon(mWeaponType)) - downSoundId = newWeapon.getClass().getDownSoundId(newWeapon); + downSoundId = &newWeapon.getClass().getDownSoundId(newWeapon); } // weapon->HtH switch: weapon is empty already, so we need to take sound from previous weapon else if (!mWeapon.isEmpty() && weaptype == ESM::Weapon::HandToHand && mWeaponType != ESM::Weapon::Spell) - downSoundId = mWeapon.getClass().getDownSoundId(mWeapon); + downSoundId = &mWeapon.getClass().getDownSoundId(mWeapon); if (mWeapon != newWeapon) { @@ -1354,9 +1354,9 @@ namespace MWMechanics mAnimation->showWeapons(false); } - if (!downSoundId.empty()) + if (downSoundId && !downSoundId->empty()) { - sndMgr->playSound3D(mPtr, downSoundId, 1.0f, 1.0f); + sndMgr->playSound3D(mPtr, *downSoundId, 1.0f, 1.0f); } } @@ -1410,7 +1410,7 @@ namespace MWMechanics if (!mWeapon.isEmpty() && mWeaponType != ESM::Weapon::HandToHand && isRealWeapon(weaptype)) { - std::string_view upSoundId = mWeapon.getClass().getUpSoundId(mWeapon); + const ESM::RefId& upSoundId = mWeapon.getClass().getUpSoundId(mWeapon); if (!upSoundId.empty()) sndMgr->playSound3D(mPtr, upSoundId, 1.0f, 1.0f); } @@ -1420,7 +1420,7 @@ namespace MWMechanics if (isWerewolf) { const MWWorld::ESMStore& store = world->getStore(); - const ESM::Sound* sound = store.get().searchRandom("WolfEquip", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfEquip"), prng); if (sound) { sndMgr->playSound3D(mPtr, sound->mId, 1.0f, 1.0f); @@ -1442,13 +1442,14 @@ namespace MWMechanics if (isWerewolf) { + const static ESM::RefId wolfRun = ESM::RefId::stringRefId("WorldRun"); if (isRunning() && !world->isSwimming(mPtr) && mWeaponType == ESM::Weapon::None) { - if (!sndMgr->getSoundPlaying(mPtr, "WolfRun")) - sndMgr->playSound3D(mPtr, "WolfRun", 1.0f, 1.0f, MWSound::Type::Sfx, MWSound::PlayMode::Loop); + if (!sndMgr->getSoundPlaying(mPtr, wolfRun)) + sndMgr->playSound3D(mPtr, wolfRun, 1.0f, 1.0f, MWSound::Type::Sfx, MWSound::PlayMode::Loop); } else - sndMgr->stopSound3D(mPtr, "WolfRun"); + sndMgr->stopSound3D(mPtr, wolfRun); } // Combat for actors with persistent animations obviously will be buggy @@ -1483,11 +1484,11 @@ namespace MWMechanics // For the player, set the spell we want to cast // This has to be done at the start of the casting animation, // *not* when selecting a spell in the GUI (otherwise you could change the spell mid-animation) - const std::string& selectedSpell + const ESM::RefId& selectedSpell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); stats.getSpells().setSelectedSpell(selectedSpell); } - std::string_view spellid = stats.getSpells().getSelectedSpell(); + const ESM::RefId* spellid = &stats.getSpells().getSelectedSpell(); bool isMagicItem = false; // Play hand VFX and allow castSpell use (assuming an animation is going to be played) if @@ -1497,13 +1498,13 @@ namespace MWMechanics spellCastResult = world->startSpellCast(mPtr); mCanCast = spellCastResult == MWWorld::SpellCastState::Success; - if (spellid.empty() && cls.hasInventoryStore(mPtr)) + if (spellid->empty() && cls.hasInventoryStore(mPtr)) { MWWorld::InventoryStore& inv = cls.getInventoryStore(mPtr); if (inv.getSelectedEnchantItem() != inv.end()) { const MWWorld::Ptr& enchantItem = *inv.getSelectedEnchantItem(); - spellid = enchantItem.getClass().getEnchantment(enchantItem); + spellid = &enchantItem.getClass().getEnchantment(enchantItem); isMagicItem = true; } } @@ -1522,7 +1523,7 @@ namespace MWMechanics } // Play the spellcasting animation/VFX if the spellcasting was successful or failed due to // insufficient magicka. Used up powers are exempt from this from some reason. - else if (!spellid.empty() && spellCastResult != MWWorld::SpellCastState::PowerAlreadyUsed) + else if (!spellid->empty() && spellCastResult != MWWorld::SpellCastState::PowerAlreadyUsed) { world->breakInvisibility(mPtr); MWMechanics::CastSpell cast(mPtr, {}, false, mCastingManualSpell); @@ -1531,13 +1532,13 @@ namespace MWMechanics const MWWorld::ESMStore& store = world->getStore(); if (isMagicItem) { - const ESM::Enchantment* enchantment = store.get().find(spellid); + const ESM::Enchantment* enchantment = store.get().find(*spellid); effects = &enchantment->mEffects.mList; cast.playSpellCastingEffects(enchantment); } else { - const ESM::Spell* spell = store.get().find(spellid); + const ESM::Spell* spell = store.get().find(*spellid); effects = &spell->mEffects.mList; cast.playSpellCastingEffects(spell); } @@ -1546,7 +1547,7 @@ namespace MWMechanics const ESM::MagicEffect* effect = store.get().find( effects->back().mEffectID); // use last effect of list for color of VFX_Hands - const ESM::Static* castStatic = world->getStore().get().find("VFX_Hands"); + const ESM::Static* castStatic = world->getStore().get().find(ESM::RefId::stringRefId("VFX_Hands")); const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); @@ -1683,7 +1684,7 @@ namespace MWMechanics if (!resultMessage.empty()) MWBase::Environment::get().getWindowManager()->messageBox(resultMessage); if (!resultSound.empty()) - sndMgr->playSound3D(target, resultSound, 1.0f, 1.0f); + sndMgr->playSound3D(target, ESM::RefId::stringRefId(resultSound), 1.0f, 1.0f); } } else @@ -2038,18 +2039,19 @@ namespace MWMechanics } } - if (!godmode) - { - // reduce fatigue - float fatigueLoss = 0.f; - static const float fFatigueRunBase = gmst.find("fFatigueRunBase")->mValue.getFloat(); - static const float fFatigueRunMult = gmst.find("fFatigueRunMult")->mValue.getFloat(); - static const float fFatigueSwimWalkBase = gmst.find("fFatigueSwimWalkBase")->mValue.getFloat(); - static const float fFatigueSwimRunBase = gmst.find("fFatigueSwimRunBase")->mValue.getFloat(); - static const float fFatigueSwimWalkMult = gmst.find("fFatigueSwimWalkMult")->mValue.getFloat(); - static const float fFatigueSwimRunMult = gmst.find("fFatigueSwimRunMult")->mValue.getFloat(); - static const float fFatigueSneakBase = gmst.find("fFatigueSneakBase")->mValue.getFloat(); - static const float fFatigueSneakMult = gmst.find("fFatigueSneakMult")->mValue.getFloat(); + if (!godmode) + { + // reduce fatigue + const MWWorld::Store& gmst = world->getStore().get(); + float fatigueLoss = 0; + static const float fFatigueRunBase = gmst.find(ESM::RefId::stringRefId("fFatigueRunBase"))->mValue.getFloat(); + static const float fFatigueRunMult = gmst.find(ESM::RefId::stringRefId("fFatigueRunMult"))->mValue.getFloat(); + static const float fFatigueSwimWalkBase = gmst.find(ESM::RefId::stringRefId("fFatigueSwimWalkBase"))->mValue.getFloat(); + static const float fFatigueSwimRunBase = gmst.find(ESM::RefId::stringRefId("fFatigueSwimRunBase"))->mValue.getFloat(); + static const float fFatigueSwimWalkMult = gmst.find(ESM::RefId::stringRefId("fFatigueSwimWalkMult"))->mValue.getFloat(); + static const float fFatigueSwimRunMult = gmst.find(ESM::RefId::stringRefId("fFatigueSwimRunMult"))->mValue.getFloat(); + static const float fFatigueSneakBase = gmst.find(ESM::RefId::stringRefId("fFatigueSneakBase"))->mValue.getFloat(); + static const float fFatigueSneakMult = gmst.find(ESM::RefId::stringRefId("fFatigueSneakMult"))->mValue.getFloat(); if (cls.getEncumbrance(mPtr) <= cls.getCapacity(mPtr)) { @@ -2135,7 +2137,7 @@ namespace MWMechanics float realHealthLost = healthLost * (1.0f - 0.25f * fatigueTerm); health.setCurrent(health.getCurrent() - realHealthLost); cls.getCreatureStats(mPtr).setHealth(health); - sndMgr->playSound3D(mPtr, "Health Damage", 1.0f, 1.0f); + sndMgr->playSound3D(mPtr, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); if (isPlayer) MWBase::Environment::get().getWindowManager()->activateHitOverlay(); } @@ -2783,7 +2785,7 @@ namespace MWMechanics mPtr.getClass().getCreatureStats(mPtr).setAttackingOrSpell(attackingOrSpell); } - void CharacterController::castSpell(const std::string& spellId, bool manualSpell) + void CharacterController::castSpell(const ESM::RefId& spellId, bool manualSpell) { setAttackingOrSpell(true); mCastingManualSpell = manualSpell; @@ -2843,7 +2845,8 @@ namespace MWMechanics void CharacterController::playSwishSound() const { - std::string_view soundId = "Weapon Swish"; + static ESM::RefId weaponSwish = ESM::RefId::stringRefId("Weapon Swish"); + const ESM::RefId* soundId = &weaponSwish; float volume = 0.98f + mAttackStrength * 0.02f; float pitch = 0.75f + mAttackStrength * 0.4f; @@ -2852,13 +2855,13 @@ namespace MWMechanics { MWBase::World* world = MWBase::Environment::get().getWorld(); const MWWorld::ESMStore& store = world->getStore(); - const ESM::Sound* sound = store.get().searchRandom("WolfSwing", world->getPrng()); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfSwing"), world->getPrng()); if (sound) - soundId = sound->mId; + soundId = &sound->mId; } - if (!soundId.empty()) - MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, soundId, volume, pitch); + if (!soundId->empty()) + MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, *soundId, volume, pitch); } void CharacterController::updateHeadTracking(float duration) diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index a375b8b8cf..8f79d845bc 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -297,7 +297,7 @@ namespace MWMechanics bool isAttackingOrSpell() const; void setVisibility(float visibility) const; - void castSpell(const std::string& spellId, bool manualSpell = false); + void castSpell(const ESM::RefId& spellId, bool manualSpell = false); void setAIAttackType(std::string_view attackType); static std::string_view getRandomAttackType(); diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index f7cac36e74..edb04bd6ab 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -44,7 +44,7 @@ namespace MWMechanics bool applyOnStrikeEnchantment(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, const MWWorld::Ptr& object, const osg::Vec3f& hitPosition, const bool fromProjectile) { - std::string_view enchantmentName = !object.isEmpty() ? object.getClass().getEnchantment(object) : ""; + const ESM::RefId& enchantmentName = !object.isEmpty() ? object.getClass().getEnchantment(object) : ESM::RefId::sEmpty; if (!enchantmentName.empty()) { const ESM::Enchantment* enchantment @@ -268,7 +268,7 @@ namespace MWMechanics static const float fCombatKODamageMult = gmst.find("fCombatKODamageMult")->mValue.getFloat(); damage *= fCombatKODamageMult; if (!knockedDown) - MWBase::Environment::get().getSoundManager()->playSound3D(victim, "critical damage", 1.0f, 1.0f); + MWBase::Environment::get().getSoundManager()->playSound3D(victim, ESM::RefId::stringRefId("critical damage"), 1.0f, 1.0f); } } @@ -382,7 +382,7 @@ namespace MWMechanics health.setCurrent(health.getCurrent() - x); attackerStats.setHealth(health); - MWBase::Environment::get().getSoundManager()->playSound3D(attacker, "Health Damage", 1.0f, 1.0f); + MWBase::Environment::get().getSoundManager()->playSound3D(attacker, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); } } @@ -493,12 +493,12 @@ namespace MWMechanics if (isWerewolf) { auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const ESM::Sound* sound = store.get().searchRandom("WolfHit", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfHit"), prng); if (sound) sndMgr->playSound3D(victim, sound->mId, 1.0f, 1.0f); } else if (!healthdmg) - sndMgr->playSound3D(victim, "Hand To Hand Hit", 1.0f, 1.0f); + sndMgr->playSound3D(victim, ESM::RefId::stringRefId("Hand To Hand Hit"), 1.0f, 1.0f); } void applyFatigueLoss(const MWWorld::Ptr& attacker, const MWWorld::Ptr& weapon, float attackStrength) diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 931d0a3206..bb1c09accb 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -364,7 +364,7 @@ namespace MWMechanics return evasion; } - void CreatureStats::setLastHitObject(const std::string& objectid) + void CreatureStats::setLastHitObject(const ESM::RefId& objectid) { mLastHitObject = objectid; } @@ -374,12 +374,12 @@ namespace MWMechanics mLastHitObject.clear(); } - const std::string& CreatureStats::getLastHitObject() const + const ESM::RefId& CreatureStats::getLastHitObject() const { return mLastHitObject; } - void CreatureStats::setLastHitAttemptObject(const std::string& objectid) + void CreatureStats::setLastHitAttemptObject(const ESM::RefId& objectid) { mLastHitAttemptObject = objectid; } @@ -389,7 +389,7 @@ namespace MWMechanics mLastHitAttemptObject.clear(); } - const std::string& CreatureStats::getLastHitAttemptObject() const + const ESM::RefId& CreatureStats::getLastHitAttemptObject() const { return mLastHitAttemptObject; } diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 35fdbbf4dc..0ded000469 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -15,6 +15,7 @@ #include "stat.hpp" #include +#include #include namespace ESM @@ -63,8 +64,8 @@ namespace MWMechanics float mFallHeight; - std::string mLastHitObject; // The last object to hit this actor - std::string mLastHitAttemptObject; // The last object to attempt to hit this actor + ESM::RefId mLastHitObject; // The last object to hit this actor + ESM::RefId mLastHitAttemptObject; // The last object to attempt to hit this actor // For merchants: the last time items were restocked and gold pool refilled. MWWorld::TimeStamp mLastRestock; @@ -249,12 +250,12 @@ namespace MWMechanics /// Like getMovementFlag, but also takes into account if the flag is Forced bool getStance(Stance flag) const; - void setLastHitObject(const std::string& objectid); + void setLastHitObject(const ESM::RefId& objectid); void clearLastHitObject(); - const std::string& getLastHitObject() const; - void setLastHitAttemptObject(const std::string& objectid); + const ESM::RefId& getLastHitObject() const; + void setLastHitAttemptObject(const ESM::RefId& objectid); void clearLastHitAttemptObject(); - const std::string& getLastHitAttemptObject() const; + const ESM::RefId& getLastHitAttemptObject() const; void setHitAttemptActorId(const int actorId); int getHitAttemptActorId() const; diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index b9c12a6097..798b66e235 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -73,8 +73,9 @@ namespace MWMechanics store.remove(mSoulGemPtr, 1, player); // Exception for Azura Star, new one will be added after enchanting - if (Misc::StringUtils::ciEqual(mSoulGemPtr.get()->mBase->mId, "Misc_SoulGem_Azura")) - store.add("Misc_SoulGem_Azura", 1, player); + auto azurasStarId = ESM::RefId::stringRefId("Misc_SoulGem_Azura"); + if (ESM::RefId::ciEqual(mSoulGemPtr.get()->mBase->mId, azurasStarId)) + store.add(azurasStarId, 1, player); if (mSelfEnchanting) { @@ -100,7 +101,7 @@ namespace MWMechanics enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord(enchantment); // Apply the enchantment - const std::string& newItemId + const ESM::RefId& newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); // Add the new item to player inventory and remove the old one @@ -299,7 +300,7 @@ namespace MWMechanics const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); if (soulEmpty()) return 0; - if (mSoulGemPtr.getCellRef().getSoul() == "") + if (mSoulGemPtr.getCellRef().getSoul() == ESM::RefId::sEmpty) return 0; const ESM::Creature* soul = store.get().search(mSoulGemPtr.getCellRef().getSoul()); if (soul) diff --git a/apps/openmw/mwmechanics/inventory.hpp b/apps/openmw/mwmechanics/inventory.hpp index 6c7fe2d3a6..178eb6d54a 100644 --- a/apps/openmw/mwmechanics/inventory.hpp +++ b/apps/openmw/mwmechanics/inventory.hpp @@ -15,12 +15,12 @@ namespace MWMechanics { template - void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) + void modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& 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)) + if (ESM::RefId::ciEqual(it.mItem, itemId)) { const int sign = it.mCount < 1 ? -1 : 1; it.mCount = sign * std::max(it.mCount * sign + amount, 0); diff --git a/apps/openmw/mwmechanics/levelledlist.hpp b/apps/openmw/mwmechanics/levelledlist.hpp index 9911c06820..f9ad488607 100644 --- a/apps/openmw/mwmechanics/levelledlist.hpp +++ b/apps/openmw/mwmechanics/levelledlist.hpp @@ -20,7 +20,7 @@ namespace MWMechanics { /// @return ID of resulting item, or empty if none - inline std::string_view getLevelledItem( + inline const ESM::RefId& getLevelledItem( const ESM::LevelledListBase* levItem, bool creature, Misc::Rng::Generator& prng) { const std::vector& items = levItem->mList; @@ -29,9 +29,9 @@ namespace MWMechanics int playerLevel = player.getClass().getCreatureStats(player).getLevel(); if (Misc::Rng::roll0to99(prng) < levItem->mChanceNone) - return {}; + return ESM::RefId::sEmpty; - std::vector candidates; + std::vector candidates; int highestLevel = 0; for (const auto& levelledItem : items) { @@ -44,26 +44,26 @@ namespace MWMechanics if (creature) allLevels = levItem->mFlags & ESM::CreatureLevList::AllLevels; - std::pair highest = { -1, {} }; + std::pair highest = { -1, {} }; for (const auto& levelledItem : items) { if (playerLevel >= levelledItem.mLevel && (allLevels || levelledItem.mLevel == highestLevel)) { - candidates.push_back(levelledItem.mId); + candidates.push_back(&levelledItem.mId); if (levelledItem.mLevel >= highest.first) - highest = std::make_pair(levelledItem.mLevel, levelledItem.mId); + highest = std::make_pair(levelledItem.mLevel, &levelledItem.mId); } } if (candidates.empty()) - return {}; - std::string_view item = candidates[Misc::Rng::rollDice(candidates.size(), prng)]; + return ESM::RefId::sEmpty; + const ESM::RefId& item = *candidates[Misc::Rng::rollDice(candidates.size(), prng)]; // Vanilla doesn't fail on nonexistent items in levelled lists if (!MWBase::Environment::get().getWorld()->getStore().find(item)) { Log(Debug::Warning) << "Warning: ignoring nonexistent item '" << item << "' in levelled list '" << levItem->mId << "'"; - return {}; + return ESM::RefId::sEmpty; } // Is this another levelled item or a real item? diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 81ae2917d6..ea12a2af93 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -82,15 +83,15 @@ namespace { const MWWorld::CellRef& cellref = target.getCellRef(); - const std::string& owner = cellref.getOwner(); - bool isOwned = !owner.empty() && owner != "player"; + const ESM::RefId& owner = cellref.getOwner(); + bool isOwned = !owner.empty() && owner != ESM::RefId::stringRefId("player"); - const std::string& faction = cellref.getFaction(); + const ESM::RefId& faction = cellref.getFaction(); bool isFactionOwned = false; if (!faction.empty() && ptr.getClass().isNpc()) { - const std::map& factions = ptr.getClass().getNpcStats(ptr).getFactionRanks(); - auto found = factions.find(Misc::StringUtils::lowerCase(faction)); + const std::map& factions = ptr.getClass().getNpcStats(ptr).getFactionRanks(); + auto found = factions.find(faction); if (found == factions.end() || found->second < cellref.getFactionRank()) isFactionOwned = true; } @@ -168,20 +169,20 @@ namespace MWMechanics npcStats.getSkill(i).setBase(5 + bonus); } - for (const std::string& power : race->mPowers.mList) + for (const ESM::RefId& power : race->mPowers.mList) { creatureStats.getSpells().add(power); } } // birthsign - const std::string& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); + const ESM::RefId& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); if (!signId.empty()) { const ESM::BirthSign* sign = esmStore.get().find(signId); - for (const std::string& power : sign->mPowers.mList) + for (const ESM::RefId& power : sign->mPowers.mList) { creatureStats.getSpells().add(power); } @@ -247,9 +248,9 @@ namespace MWMechanics attributes[i] = npcStats.getAttribute(i).getBase(); npcStats.updateHealth(); - std::vector selectedSpells = autoCalcPlayerSpells(skills, attributes, race); + std::vector selectedSpells = autoCalcPlayerSpells(skills, attributes, race); - for (const std::string& spell : selectedSpells) + for (const ESM::RefId& spell : selectedSpells) creatureStats.getSpells().add(spell); // forced update and current value adjustments @@ -287,7 +288,7 @@ namespace MWMechanics mObjects.addObject(ptr); } - void MechanicsManager::castSpell(const MWWorld::Ptr& ptr, const std::string& spellId, bool manualSpell) + void MechanicsManager::castSpell(const MWWorld::Ptr& ptr, const ESM::RefId& spellId, bool manualSpell) { if (ptr.getClass().isActor()) mActors.castSpell(ptr, spellId, manualSpell); @@ -333,7 +334,7 @@ namespace MWMechanics winMgr->setSelectedEnchantItem(*enchantItem); else { - const std::string& spell = winMgr->getSelectedSpell(); + const ESM::RefId& spell = winMgr->getSelectedSpell(); if (!spell.empty()) winMgr->setSelectedSpell(spell, int(MWMechanics::getSpellSuccessChance(spell, ptr))); else @@ -444,7 +445,7 @@ namespace MWMechanics } void MechanicsManager::setPlayerRace( - const std::string& race, bool male, const std::string& head, const std::string& hair) + const ESM::RefId& race, bool male, const ESM::RefId& head, const ESM::RefId& hair) { MWBase::World* world = MWBase::Environment::get().getWorld(); @@ -462,14 +463,14 @@ namespace MWMechanics mUpdatePlayer = true; } - void MechanicsManager::setPlayerBirthsign(const std::string& id) + void MechanicsManager::setPlayerBirthsign(const ESM::RefId& id) { MWBase::Environment::get().getWorld()->getPlayer().setBirthSign(id); buildPlayer(); mUpdatePlayer = true; } - void MechanicsManager::setPlayerClass(const std::string& id) + void MechanicsManager::setPlayerClass(const ESM::RefId& id) { MWBase::World* world = MWBase::Environment::get().getWorld(); @@ -512,7 +513,7 @@ namespace MWMechanics const MWWorld::Store& gmst = MWBase::Environment::get().getWorld()->getStore().get(); static const float fDispRaceMod = gmst.find("fDispRaceMod")->mValue.getFloat(); - if (Misc::StringUtils::ciEqual(npc->mBase->mRace, player->mBase->mRace)) + if (ESM::RefId::ciEqual(npc->mBase->mRace, player->mBase->mRace)) x += fDispRaceMod; static const float fDispPersonalityMult = gmst.find("fDispPersonalityMult")->mValue.getFloat(); @@ -522,7 +523,7 @@ namespace MWMechanics float reaction = 0; int rank = 0; - std::string npcFaction = Misc::StringUtils::lowerCase(ptr.getClass().getPrimaryFaction(ptr)); + ESM::RefId npcFaction = ptr.getClass().getPrimaryFaction(ptr); if (playerStats.getFactionRanks().find(npcFaction) != playerStats.getFactionRanks().end()) { @@ -537,10 +538,10 @@ namespace MWMechanics } else if (!npcFaction.empty()) { - std::map::const_iterator playerFactionIt = playerStats.getFactionRanks().begin(); + auto playerFactionIt = playerStats.getFactionRanks().begin(); for (; playerFactionIt != playerStats.getFactionRanks().end(); ++playerFactionIt) { - const std::string& itFaction = playerFactionIt->first; + const ESM::RefId& itFaction = playerFactionIt->first; // Ignore the faction, if a player was expelled from it. if (playerStats.getExpelled(itFaction)) @@ -612,7 +613,7 @@ namespace MWMechanics return std::max(1, offerPrice); } - int MechanicsManager::countDeaths(const std::string& id) const + int MechanicsManager::countDeaths(const ESM::RefId& id) const { return mActors.countDeaths(id); } @@ -839,7 +840,7 @@ namespace MWMechanics bool MechanicsManager::isBoundItem(const MWWorld::Ptr& item) { - static std::set boundItemIDCache; + static std::set boundItemIDCache; // If this is empty then we haven't executed the GMST cache logic yet; or there isn't any sMagicBound* GMST's // for some reason @@ -852,20 +853,19 @@ namespace MWMechanics for (const ESM::GameSetting& currentSetting : gameSettings) { // Don't bother checking this GMST if it's not a sMagicBound* one. - if (!Misc::StringUtils::ciStartsWith(currentSetting.mId, "smagicbound")) + if (!Misc::StringUtils::ciStartsWith(currentSetting.mId.getRefIdString(), "smagicbound")) continue; // All sMagicBound* GMST's should be of type string std::string currentGMSTValue = currentSetting.mValue.getString(); Misc::StringUtils::lowerCaseInPlace(currentGMSTValue); - boundItemIDCache.insert(currentGMSTValue); + boundItemIDCache.insert(ESM::RefId::stringRefId(currentGMSTValue)); } } // Perform bound item check and assign the Flag_Bound bit if it passes - std::string tempItemID = item.getCellRef().getRefId(); - Misc::StringUtils::lowerCaseInPlace(tempItemID); + ESM::RefId tempItemID = item.getCellRef().getRefId(); if (boundItemIDCache.count(tempItemID) != 0) return true; @@ -891,7 +891,7 @@ namespace MWMechanics return true; // TODO: implement a better check to check if target is owned bed - if (target.getClass().isActivator() && target.getClass().getScript(target).compare(0, 3, "Bed") != 0) + if (target.getClass().isActivator() && target.getClass().getScript(target).getRefIdString().compare(0, 3, "Bed") != 0) return true; if (target.getClass().isNpc()) @@ -913,7 +913,7 @@ namespace MWMechanics return false; // A special case for evidence chest - we should not allow to take items even if it is technically permitted - return !Misc::StringUtils::ciEqual(cellref.getRefId(), "stolen_goods"); + return !ESM::RefId::ciEqual(cellref.getRefId(), ESM::RefId::stringRefId("stolen_goods")); } bool MechanicsManager::sleepInBed(const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed) @@ -957,10 +957,10 @@ namespace MWMechanics } } - std::vector> MechanicsManager::getStolenItemOwners(const std::string& itemid) + std::vector> MechanicsManager::getStolenItemOwners(const ESM::RefId& itemid) { - std::vector> result; - StolenItemsMap::const_iterator it = mStolenItems.find(Misc::StringUtils::lowerCase(itemid)); + std::vector> result; + StolenItemsMap::const_iterator it = mStolenItems.find(itemid); if (it == mStolenItems.end()) return result; else @@ -972,23 +972,23 @@ namespace MWMechanics } } - bool MechanicsManager::isItemStolenFrom(const std::string& itemid, const MWWorld::Ptr& ptr) + bool MechanicsManager::isItemStolenFrom(const ESM::RefId& itemid, const MWWorld::Ptr& ptr) { - StolenItemsMap::const_iterator it = mStolenItems.find(Misc::StringUtils::lowerCase(itemid)); + StolenItemsMap::const_iterator it = mStolenItems.find(itemid); if (it == mStolenItems.end()) return false; const OwnerMap& owners = it->second; - const std::string& ownerid = ptr.getCellRef().getRefId(); - OwnerMap::const_iterator ownerFound = owners.find(std::make_pair(Misc::StringUtils::lowerCase(ownerid), false)); + const ESM::RefId& ownerid = ptr.getCellRef().getRefId(); + OwnerMap::const_iterator ownerFound = owners.find(std::make_pair(ownerid, false)); if (ownerFound != owners.end()) return true; - const std::string_view factionid = ptr.getClass().getPrimaryFaction(ptr); + const ESM::RefId& factionid = ptr.getClass().getPrimaryFaction(ptr); if (!factionid.empty()) { OwnerMap::const_iterator factionOwnerFound - = owners.find(std::make_pair(Misc::StringUtils::lowerCase(factionid), true)); + = owners.find(std::make_pair(factionid, true)); return factionOwnerFound != owners.end(); } @@ -1001,7 +1001,7 @@ namespace MWMechanics if (player != getPlayer()) return; - const std::string itemId = Misc::StringUtils::lowerCase(item.getCellRef().getRefId()); + const ESM::RefId& itemId = item.getCellRef().getRefId(); StolenItemsMap::iterator stolenIt = mStolenItems.find(itemId); if (stolenIt == mStolenItems.end()) @@ -1011,16 +1011,14 @@ namespace MWMechanics owner.first = victim.getCellRef().getRefId(); owner.second = false; - const std::string_view victimFaction = victim.getClass().getPrimaryFaction(victim); + const ESM::RefId& victimFaction = victim.getClass().getPrimaryFaction(victim); if (!victimFaction.empty() - && Misc::StringUtils::ciEqual(item.getCellRef().getFaction(), victimFaction)) // Is the item faction-owned? + && ESM::RefId::ciEqual(item.getCellRef().getFaction(), victimFaction)) // Is the item faction-owned? { owner.first = victimFaction; owner.second = true; } - Misc::StringUtils::lowerCaseInPlace(owner.first); - // decrease count of stolen items int toRemove = std::min(count, mStolenItems[itemId][owner]); mStolenItems[itemId][owner] -= toRemove; @@ -1049,7 +1047,7 @@ namespace MWMechanics for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { StolenItemsMap::iterator stolenIt - = mStolenItems.find(Misc::StringUtils::lowerCase(it->getCellRef().getRefId())); + = mStolenItems.find(it->getCellRef().getRefId()); if (stolenIt == mStolenItems.end()) continue; OwnerMap& owners = stolenIt->second; @@ -1120,21 +1118,19 @@ namespace MWMechanics } } - Misc::StringUtils::lowerCaseInPlace(owner.first); - - if (!Misc::StringUtils::ciEqual(item.getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) + if (!ESM::RefId::ciEqual(item.getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) { if (victim.isEmpty() || (victim.getClass().isActor() && victim.getRefData().getCount() > 0 && !victim.getClass().getCreatureStats(victim).isDead())) - mStolenItems[Misc::StringUtils::lowerCase(item.getCellRef().getRefId())][owner] += count; + mStolenItems[item.getCellRef().getRefId()][owner] += count; } if (alarm) commitCrime(ptr, victim, OT_Theft, ownerCellRef->getFaction(), item.getClass().getValue(item) * count); } bool MechanicsManager::commitCrime(const MWWorld::Ptr& player, const MWWorld::Ptr& victim, OffenseType type, - const std::string& factionId, int arg, bool victimAware) + const ESM::RefId& factionId, int arg, bool victimAware) { // NOTE: victim may be empty @@ -1175,7 +1171,7 @@ namespace MWMechanics { // NPC will complain about theft even if he will do nothing about it if (type == OT_Theft || type == OT_Pickpocket) - MWBase::Environment::get().getDialogueManager()->say(neighbor, "thief"); + MWBase::Environment::get().getDialogueManager()->say(neighbor, ESM::RefId::stringRefId("thief")); crimeSeen = true; } @@ -1188,7 +1184,7 @@ namespace MWMechanics bool reported = false; if (victim.getClass().isClass(victim, "guard") && !victim.getClass().getCreatureStats(victim).getAiSequence().hasPackage(AiPackageTypeId::Pursue)) - reported = reportCrime(player, victim, type, std::string(), arg); + reported = reportCrime(player, victim, type, ESM::RefId::sEmpty, arg); if (!reported) startCombat(victim, @@ -1221,7 +1217,7 @@ namespace MWMechanics } bool MechanicsManager::reportCrime( - const MWWorld::Ptr& player, const MWWorld::Ptr& victim, OffenseType type, const std::string& factionId, int arg) + const MWWorld::Ptr& player, const MWWorld::Ptr& victim, OffenseType type, const ESM::RefId& factionId, int arg) { const MWWorld::Store& store = MWBase::Environment::get().getWorld()->getStore().get(); @@ -1313,7 +1309,7 @@ namespace MWMechanics reported = true; if (type == OT_Trespassing) - MWBase::Environment::get().getDialogueManager()->say(actor, "intruder"); + MWBase::Environment::get().getDialogueManager()->say(actor, ESM::RefId::stringRefId("intruder")); } } @@ -1387,18 +1383,18 @@ namespace MWMechanics // If committing a crime against a faction member, expell from the faction if (!victim.isEmpty() && victim.getClass().isNpc()) { - std::string_view factionID = victim.getClass().getPrimaryFaction(victim); + const ESM::RefId& factionID = victim.getClass().getPrimaryFaction(victim); - const std::map& playerRanks = player.getClass().getNpcStats(player).getFactionRanks(); - if (playerRanks.find(Misc::StringUtils::lowerCase(factionID)) != playerRanks.end()) + const std::map& playerRanks = player.getClass().getNpcStats(player).getFactionRanks(); + if (playerRanks.find(factionID) != playerRanks.end()) { player.getClass().getNpcStats(player).expell(factionID); } } else if (!factionId.empty()) { - const std::map& playerRanks = player.getClass().getNpcStats(player).getFactionRanks(); - if (playerRanks.find(Misc::StringUtils::lowerCase(factionId)) != playerRanks.end()) + const std::map& playerRanks = player.getClass().getNpcStats(player).getFactionRanks(); + if (playerRanks.find(factionId) != playerRanks.end()) { player.getClass().getNpcStats(player).expell(factionId); } @@ -1439,7 +1435,7 @@ namespace MWMechanics if (statsTarget.getFriendlyHits() < 4) { - MWBase::Environment::get().getDialogueManager()->say(target, "hit"); + MWBase::Environment::get().getDialogueManager()->say(target, ESM::RefId::stringRefId("hit")); return false; } } @@ -1461,7 +1457,7 @@ namespace MWMechanics // 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) bool peaceful = false; - std::string_view script = target.getClass().getScript(target); + const ESM::RefId& script = target.getClass().getScript(target); if (!script.empty() && target.getRefData().getLocals().hasVar(script, "onpchitme") && attacker == player) { @@ -1613,7 +1609,7 @@ namespace MWMechanics { // We don't care about dialogue filters since the target is invalid. // We still want to play the combat taunt. - MWBase::Environment::get().getDialogueManager()->say(ptr, "attack"); + MWBase::Environment::get().getDialogueManager()->say(ptr, ESM::RefId::stringRefId("attack")); return; } @@ -1651,7 +1647,7 @@ namespace MWMechanics } // Must be done after the target is set up, so that CreatureTargetted dialogue filter works properly - MWBase::Environment::get().getDialogueManager()->say(ptr, "attack"); + MWBase::Environment::get().getDialogueManager()->say(ptr, ESM::RefId::stringRefId("attack")); } void MechanicsManager::stopCombat(const MWWorld::Ptr& actor) @@ -1788,8 +1784,7 @@ namespace MWMechanics || (target == getPlayer() && MWBase::Environment::get().getWorld()->getGlobalInt("pcknownwerewolf"))) { const ESM::GameSetting* iWerewolfFightMod - = MWBase::Environment::get().getWorld()->getStore().get().find( - "iWerewolfFightMod"); + = MWBase::Environment::get().getWorld()->getStore().get().find("iWerewolfFightMod"); fight += iWerewolfFightMod->mValue.getInteger(); } } @@ -1843,12 +1838,12 @@ namespace MWMechanics if (werewolf) { inv.unequipAll(actor); - inv.equip(MWWorld::InventoryStore::Slot_Robe, inv.ContainerStore::add("werewolfrobe", 1, actor), actor); + inv.equip(MWWorld::InventoryStore::Slot_Robe, inv.ContainerStore::add(ESM::RefId::stringRefId("werewolfrobe"), 1, actor), actor); } else { inv.unequipSlot(MWWorld::InventoryStore::Slot_Robe, actor); - inv.ContainerStore::remove("werewolfrobe", 1, actor); + inv.ContainerStore::remove(ESM::RefId::stringRefId("werewolfrobe"), 1, actor); } if (actor == player->getPlayer()) diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index f821319476..4dbd80391e 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -28,9 +28,9 @@ namespace MWMechanics Objects mObjects; Actors mActors; - typedef std::pair Owner; // < Owner id, bool isFaction > + typedef std::pair Owner; // < Owner id, bool isFaction > typedef std::map OwnerMap; // < Owner, number of stolen items with this id from this owner > - typedef std::map StolenItemsMap; + typedef std::map StolenItemsMap; StolenItemsMap mStolenItems; public: @@ -61,13 +61,13 @@ namespace MWMechanics void setPlayerName(const std::string& name) override; ///< Set player name. - void setPlayerRace(const std::string& id, bool male, const std::string& head, const std::string& hair) override; + void setPlayerRace(const ESM::RefId& id, bool male, const ESM::RefId& head, const ESM::RefId& hair) override; ///< Set player race. - void setPlayerBirthsign(const std::string& id) override; + void setPlayerBirthsign(const ESM::RefId& id) override; ///< Set player birthsign. - void setPlayerClass(const std::string& id) override; + void setPlayerClass(const ESM::RefId& id) override; ///< Set player class to stock class. void setPlayerClass(const ESM::Class& class_) override; @@ -89,7 +89,7 @@ namespace MWMechanics int getDerivedDisposition(const MWWorld::Ptr& ptr, bool clamp = true) override; ///< Calculate the diposition of an NPC toward the player. - int countDeaths(const std::string& id) const override; + int countDeaths(const ESM::RefId& id) const override; ///< Return the number of deaths for actors with the given ID. void getPersuasionDispositionChange( @@ -112,7 +112,7 @@ namespace MWMechanics * @return was the crime seen? */ bool commitCrime(const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim, OffenseType type, - const std::string& factionId = "", int arg = 0, bool victimAware = false) override; + const ESM::RefId& factionId = ESM::RefId::sEmpty, int arg = 0, bool victimAware = false) override; /// @return false if the attack was considered a "friendly hit" and forgiven bool actorAttacked(const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker) override; @@ -189,7 +189,7 @@ namespace MWMechanics /// Is \a ptr casting spell or using weapon now? bool isAttackingOrSpell(const MWWorld::Ptr& ptr) const override; - void castSpell(const MWWorld::Ptr& ptr, const std::string& spellId, bool manualSpell = false) override; + void castSpell(const MWWorld::Ptr& ptr, const ESM::RefId& spellId, bool manualSpell = false) override; void processChangedSettings(const Settings::CategorySettingVector& settings) override; @@ -205,10 +205,10 @@ namespace MWMechanics /// List the owners that the player has stolen this item from (the owner can be an NPC or a faction). /// - std::vector> getStolenItemOwners(const std::string& itemid) override; + std::vector> getStolenItemOwners(const ESM::RefId& itemid) override; /// Has the player stolen this item from the given owner? - bool isItemStolenFrom(const std::string& itemid, const MWWorld::Ptr& ptr) override; + bool isItemStolenFrom(const ESM::RefId& itemid, const MWWorld::Ptr& ptr) override; bool isBoundItem(const MWWorld::Ptr& item) override; @@ -240,7 +240,7 @@ namespace MWMechanics const MWWorld::Ptr& actor, const MWWorld::Ptr& victim, std::set& playerFollowers); bool reportCrime(const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim, OffenseType type, - const std::string& factionId, int arg = 0); + const ESM::RefId& factionId, int arg = 0); }; } diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 2f08019617..3106960ed3 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -64,88 +64,83 @@ void MWMechanics::NpcStats::setSkill(int index, const MWMechanics::SkillValue& v mSkill[index] = value; } -const std::map& MWMechanics::NpcStats::getFactionRanks() const +const std::map& MWMechanics::NpcStats::getFactionRanks() const { return mFactionRank; } -int MWMechanics::NpcStats::getFactionRank(std::string_view faction) const +int MWMechanics::NpcStats::getFactionRank(const ESM::RefId& faction) const { - const std::string lower = Misc::StringUtils::lowerCase(faction); - std::map::const_iterator it = mFactionRank.find(lower); + auto it = mFactionRank.find(faction); if (it != mFactionRank.end()) return it->second; return -1; } -void MWMechanics::NpcStats::raiseRank(std::string_view faction) +void MWMechanics::NpcStats::raiseRank(const ESM::RefId& faction) { - const std::string lower = Misc::StringUtils::lowerCase(faction); - std::map::iterator it = mFactionRank.find(lower); + auto it = mFactionRank.find(faction); if (it != mFactionRank.end()) { // Does the next rank exist? const ESM::Faction* factionPtr - = MWBase::Environment::get().getWorld()->getStore().get().find(lower); + = MWBase::Environment::get().getWorld()->getStore().get().find(faction); if (it->second + 1 < 10 && !factionPtr->mRanks[it->second + 1].empty()) it->second += 1; } } -void MWMechanics::NpcStats::lowerRank(std::string_view faction) +void MWMechanics::NpcStats::lowerRank(const ESM::RefId& faction) { - const std::string lower = Misc::StringUtils::lowerCase(faction); - std::map::iterator it = mFactionRank.find(lower); + auto it = mFactionRank.find(faction); if (it != mFactionRank.end()) { it->second = it->second - 1; if (it->second < 0) { mFactionRank.erase(it); - mExpelled.erase(lower); + mExpelled.erase(faction); } } } -void MWMechanics::NpcStats::joinFaction(std::string_view faction) +void MWMechanics::NpcStats::joinFaction(const ESM::RefId& faction) { - const std::string lower = Misc::StringUtils::lowerCase(faction); - std::map::iterator it = mFactionRank.find(lower); + auto it = mFactionRank.find(faction); if (it == mFactionRank.end()) - mFactionRank[lower] = 0; + mFactionRank[faction] = 0; } -bool MWMechanics::NpcStats::getExpelled(std::string_view factionID) const +bool MWMechanics::NpcStats::getExpelled(const ESM::RefId& factionID) const { - return mExpelled.find(Misc::StringUtils::lowerCase(factionID)) != mExpelled.end(); + return mExpelled.find(factionID) != mExpelled.end(); } -void MWMechanics::NpcStats::expell(std::string_view factionID) +void MWMechanics::NpcStats::expell(const ESM::RefId& factionID) { - std::string lower = Misc::StringUtils::lowerCase(factionID); - if (mExpelled.find(lower) == mExpelled.end()) + if (mExpelled.find(factionID) == mExpelled.end()) { std::string message = "#{sExpelledMessage}"; message += MWBase::Environment::get().getWorld()->getStore().get().find(factionID)->mName; MWBase::Environment::get().getWindowManager()->messageBox(message); - mExpelled.insert(lower); + mExpelled.insert(factionID); } } -void MWMechanics::NpcStats::clearExpelled(std::string_view factionID) +void MWMechanics::NpcStats::clearExpelled(const ESM::RefId& factionID) { - mExpelled.erase(Misc::StringUtils::lowerCase(factionID)); + mExpelled.erase(factionID); } -bool MWMechanics::NpcStats::isInFaction(std::string_view faction) const +bool MWMechanics::NpcStats::isInFaction(const ESM::RefId& faction) const { - return (mFactionRank.find(Misc::StringUtils::lowerCase(faction)) != mFactionRank.end()); + return (mFactionRank.find(faction) != mFactionRank.end()); } -int MWMechanics::NpcStats::getFactionReputation(std::string_view faction) const +int MWMechanics::NpcStats::getFactionReputation(const ESM::RefId& faction) const { - std::map::const_iterator iter = mFactionReputation.find(Misc::StringUtils::lowerCase(faction)); + auto iter = mFactionReputation.find(faction); if (iter == mFactionReputation.end()) return 0; @@ -153,9 +148,9 @@ int MWMechanics::NpcStats::getFactionReputation(std::string_view faction) const return iter->second; } -void MWMechanics::NpcStats::setFactionReputation(std::string_view faction, int value) +void MWMechanics::NpcStats::setFactionReputation(const ESM::RefId& faction, int value) { - mFactionReputation[Misc::StringUtils::lowerCase(faction)] = value; + mFactionReputation[faction] = value; } float MWMechanics::NpcStats::getSkillProgressRequirement(int skillIndex, const ESM::Class& class_) const @@ -264,7 +259,7 @@ void MWMechanics::NpcStats::increaseSkill( // Play sound & skill progress notification /// \todo check if character is the player, if levelling is ever implemented for NPCs - MWBase::Environment::get().getWindowManager()->playSound("skillraise"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("skillraise")); std::string message{ MWBase::Environment::get().getWindowManager()->getGameSettingString("sNotifyMessage39", {}) }; message = Misc::StringUtils::format( @@ -351,12 +346,12 @@ int MWMechanics::NpcStats::getSkillIncreasesForSpecialization(int spec) const return mSpecIncreases[spec]; } -void MWMechanics::NpcStats::flagAsUsed(const std::string& id) +void MWMechanics::NpcStats::flagAsUsed(const ESM::RefId& id) { mUsedIds.insert(id); } -bool MWMechanics::NpcStats::hasBeenUsed(const std::string& id) const +bool MWMechanics::NpcStats::hasBeenUsed(const ESM::RefId& id) const { return mUsedIds.find(id) != mUsedIds.end(); } @@ -392,7 +387,7 @@ void MWMechanics::NpcStats::setCrimeId(int id) mCrimeId = id; } -bool MWMechanics::NpcStats::hasSkillsForRank(std::string_view factionId, int rank) const +bool MWMechanics::NpcStats::hasSkillsForRank(const ESM::RefId& factionId, int rank) const { if (rank < 0 || rank >= 10) throw std::runtime_error("rank index out of range"); @@ -481,7 +476,7 @@ void MWMechanics::NpcStats::writeState(ESM::CreatureStats& state) const void MWMechanics::NpcStats::writeState(ESM::NpcStats& state) const { - for (std::map::const_iterator iter(mFactionRank.begin()); iter != mFactionRank.end(); ++iter) + for (std::map::const_iterator iter(mFactionRank.begin()); iter != mFactionRank.end(); ++iter) state.mFactions[iter->first].mRank = iter->second; state.mDisposition = mDisposition; @@ -495,10 +490,10 @@ void MWMechanics::NpcStats::writeState(ESM::NpcStats& state) const state.mBounty = mBounty; - for (std::set::const_iterator iter(mExpelled.begin()); iter != mExpelled.end(); ++iter) + for (auto iter(mExpelled.begin()); iter != mExpelled.end(); ++iter) state.mFactions[*iter].mExpelled = true; - for (std::map::const_iterator iter(mFactionReputation.begin()); iter != mFactionReputation.end(); + for (auto iter(mFactionReputation.begin()); iter != mFactionReputation.end(); ++iter) state.mFactions[iter->first].mReputation = iter->second; @@ -525,7 +520,7 @@ void MWMechanics::NpcStats::readState(const ESM::NpcStats& state) { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); - for (std::map::const_iterator iter(state.mFactions.begin()); + for (auto iter(state.mFactions.begin()); iter != state.mFactions.end(); ++iter) if (store.get().search(iter->first)) { @@ -536,7 +531,7 @@ void MWMechanics::NpcStats::readState(const ESM::NpcStats& state) mFactionRank[iter->first] = iter->second.mRank; if (iter->second.mReputation) - mFactionReputation[Misc::StringUtils::lowerCase(iter->first)] = iter->second.mReputation; + mFactionReputation[iter->first] = iter->second.mReputation; } mDisposition = state.mDisposition; @@ -558,7 +553,7 @@ void MWMechanics::NpcStats::readState(const ESM::NpcStats& state) for (int i = 0; i < 3; ++i) mSpecIncreases[i] = state.mSpecIncreases[i]; - for (std::vector::const_iterator iter(state.mUsedIds.begin()); iter != state.mUsedIds.end(); ++iter) + for (auto iter(state.mUsedIds.begin()); iter != state.mUsedIds.end(); ++iter) if (store.find(*iter)) mUsedIds.insert(*iter); diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index 6b8e73d615..5294cd54c0 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -5,7 +5,7 @@ #include #include #include - +#include #include "creaturestats.hpp" namespace ESM @@ -31,14 +31,14 @@ namespace MWMechanics int mWerewolfKills; /// Used only for the player and for NPC's with ranks, modified by scripts; other NPCs have maximum one faction /// defined in their NPC record - std::map mFactionRank; - std::set mExpelled; - std::map mFactionReputation; + std::map mFactionRank; + std::set mExpelled; + std::map mFactionReputation; int mLevelProgress; // 0-10 std::vector mSkillIncreases; // number of skill increases for each attribute (resets after leveling up) std::vector mSpecIncreases; // number of skill increases for each specialization (accumulates throughout // the entire game) - std::set mUsedIds; + std::set mUsedIds; // --------------------------------------------------------------------------- /// Countdown to getting damage while underwater @@ -62,22 +62,22 @@ namespace MWMechanics SkillValue& getSkill(int index); void setSkill(int index, const SkillValue& value); - int getFactionRank(std::string_view faction) const; - const std::map& getFactionRanks() const; + int getFactionRank(const ESM::RefId& faction) const; + const std::map& getFactionRanks() const; /// Increase the rank in this faction by 1, if such a rank exists. - void raiseRank(std::string_view faction); + void raiseRank(const ESM::RefId& faction); /// Lower the rank in this faction by 1, if such a rank exists. - void lowerRank(std::string_view faction); + void lowerRank(const ESM::RefId& faction); /// Join this faction, setting the initial rank to 0. - void joinFaction(std::string_view faction); + void joinFaction(const ESM::RefId& faction); - const std::set& getExpelled() const { return mExpelled; } - bool getExpelled(std::string_view factionID) const; - void expell(std::string_view factionID); - void clearExpelled(std::string_view factionID); + const std::set& getExpelled() const { return mExpelled; } + bool getExpelled(const ESM::RefId& factionID) const; + void expell(const ESM::RefId& factionID); + void clearExpelled(const ESM::RefId& factionID); - bool isInFaction(std::string_view faction) const; + bool isInFaction(const ESM::RefId& faction) const; float getSkillProgressRequirement(int skillIndex, const ESM::Class& class_) const; @@ -98,21 +98,21 @@ namespace MWMechanics ///< Calculate health based on endurance and strength. /// Called at character creation. - void flagAsUsed(const std::string& id); + void flagAsUsed(const ESM::RefId& id); ///< @note Id must be lower-case - bool hasBeenUsed(const std::string& id) const; + bool hasBeenUsed(const ESM::RefId& id) const; ///< @note Id must be lower-case int getBounty() const; void setBounty(int bounty); - int getFactionReputation(std::string_view faction) const; + int getFactionReputation(const ESM::RefId& faction) const; - void setFactionReputation(std::string_view faction, int value); + void setFactionReputation(const ESM::RefId& faction, int value); - bool hasSkillsForRank(std::string_view factionId, int rank) const; + bool hasSkillsForRank(const ESM::RefId& factionId, int rank) const; bool isWerewolf() const; diff --git a/apps/openmw/mwmechanics/recharge.cpp b/apps/openmw/mwmechanics/recharge.cpp index 707edb0930..d07b11b074 100644 --- a/apps/openmw/mwmechanics/recharge.cpp +++ b/apps/openmw/mwmechanics/recharge.cpp @@ -61,7 +61,7 @@ namespace MWMechanics int roll = Misc::Rng::roll0to99(prng); if (roll < x) { - const std::string& soul = gem.getCellRef().getSoul(); + const ESM::RefId& soul = gem.getCellRef().getSoul(); const ESM::Creature* creature = MWBase::Environment::get().getWorld()->getStore().get().find(soul); @@ -73,13 +73,13 @@ namespace MWMechanics item.getCellRef().setEnchantmentCharge(std::min( item.getCellRef().getEnchantmentCharge() + restored, static_cast(enchantment->mData.mCharge))); - MWBase::Environment::get().getWindowManager()->playSound("Enchant Success"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Enchant Success")); player.getClass().getContainerStore(player).restack(item); } else { - MWBase::Environment::get().getWindowManager()->playSound("Enchant Fail"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Enchant Fail")); } player.getClass().skillUsageSucceeded(player, ESM::Skill::Enchant, 0); @@ -97,9 +97,10 @@ namespace MWMechanics MWBase::Environment::get().getWindowManager()->messageBox(message); + ESM::RefId soulGemAzura = ESM::RefId::stringRefId("Misc_SoulGem_Azura"); // special case: readd Azura's Star - if (Misc::StringUtils::ciEqual(gem.get()->mBase->mId, "Misc_SoulGem_Azura")) - player.getClass().getContainerStore(player).add("Misc_SoulGem_Azura", 1, player); + if (ESM::RefId::ciEqual(gem.get()->mBase->mId, soulGemAzura)) + player.getClass().getContainerStore(player).add(soulGemAzura, 1, player); } return true; diff --git a/apps/openmw/mwmechanics/repair.cpp b/apps/openmw/mwmechanics/repair.cpp index 42e2fcfe9a..3d02bd6bb0 100644 --- a/apps/openmw/mwmechanics/repair.cpp +++ b/apps/openmw/mwmechanics/repair.cpp @@ -64,19 +64,19 @@ namespace MWMechanics MWWorld::ContainerStoreIterator stacked = player.getClass().getContainerStore(player).restack(itemToRepair); // set the OnPCRepair variable on the item's script - std::string_view script = stacked->getClass().getScript(itemToRepair); + const ESM::RefId& script = stacked->getClass().getScript(itemToRepair); if (!script.empty()) stacked->getRefData().getLocals().setVarByInt(script, "onpcrepair", 1); // increase skill player.getClass().skillUsageSucceeded(player, ESM::Skill::Armorer, 0); - MWBase::Environment::get().getWindowManager()->playSound("Repair"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Repair")); MWBase::Environment::get().getWindowManager()->messageBox("#{sRepairSuccess}"); } else { - MWBase::Environment::get().getWindowManager()->playSound("Repair Fail"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Repair Fail")); MWBase::Environment::get().getWindowManager()->messageBox("#{sRepairFailed}"); } @@ -100,11 +100,11 @@ namespace MWMechanics // try to find a new tool of the same ID for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter) { - if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), mTool.getCellRef().getRefId())) + if (ESM::RefId::ciEqual(iter->getCellRef().getRefId(), mTool.getCellRef().getRefId())) { mTool = *iter; - MWBase::Environment::get().getWindowManager()->playSound("Item Repair Up"); + MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("Item Repair Up")); break; } diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index e42a7829f8..e061d18e18 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -112,7 +112,7 @@ namespace MWMechanics auto& prng = MWBase::Environment::get().getWorld()->getPrng(); if (Misc::Rng::roll0to99(prng) <= x) { - trap.getCellRef().setTrap(""); + trap.getCellRef().setTrap(ESM::RefId::sEmpty); resultSound = "Disarm Trap"; resultMessage = "#{sTrapSuccess}"; diff --git a/apps/openmw/mwmechanics/setbaseaisetting.hpp b/apps/openmw/mwmechanics/setbaseaisetting.hpp index ff63ee09fd..6e2b34b71d 100644 --- a/apps/openmw/mwmechanics/setbaseaisetting.hpp +++ b/apps/openmw/mwmechanics/setbaseaisetting.hpp @@ -13,7 +13,7 @@ namespace MWMechanics { template - void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) + void setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) { T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(id); switch (setting) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index dfeb153555..9a6a908727 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -67,7 +67,7 @@ namespace MWMechanics if (!effect->mArea.empty()) areaStatic = world->getStore().get().find(effect->mArea); else - areaStatic = world->getStore().get().find("VFX_DefaultArea"); + areaStatic = world->getStore().get().find(ESM::RefId::stringRefId("VFX_DefaultArea")); const std::string& texture = effect->mParticle; @@ -90,7 +90,7 @@ namespace MWMechanics if (!effect->mAreaSound.empty()) sndMgr->playSound3D(mHitPosition, effect->mAreaSound, 1.0f, 1.0f); else - sndMgr->playSound3D(mHitPosition, schools[effect->mData.mSchool] + " area", 1.0f, 1.0f); + sndMgr->playSound3D(mHitPosition, ESM::RefId::stringRefId(schools[effect->mData.mSchool] + " area"), 1.0f, 1.0f); } // Get the actors in range of the effect std::vector objects; @@ -275,7 +275,7 @@ namespace MWMechanics } } - bool CastSpell::cast(const std::string& id) + bool CastSpell::cast(const ESM::RefId& id) { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); if (const auto spell = store.get().search(id)) @@ -292,7 +292,7 @@ namespace MWMechanics bool CastSpell::cast(const MWWorld::Ptr& item, int slot, bool launchProjectile) { - std::string_view enchantmentName = item.getClass().getEnchantment(item); + const ESM::RefId& enchantmentName = item.getClass().getEnchantment(item); if (enchantmentName.empty()) throw std::runtime_error("can't cast an item without an enchantment"); @@ -342,7 +342,7 @@ namespace MWMechanics static const std::string schools[] = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - sndMgr->playSound3D(mCaster, "Spell Failure " + schools[school], 1.0f, 1.0f); + sndMgr->playSound3D(mCaster, ESM::RefId::stringRefId("Spell Failure " + schools[school]), 1.0f, 1.0f); } return false; } @@ -429,7 +429,7 @@ namespace MWMechanics = { "alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration" }; MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - sndMgr->playSound3D(mCaster, "Spell Failure " + schools[school], 1.0f, 1.0f); + sndMgr->playSound3D(mCaster, ESM::RefId::stringRefId("Spell Failure " + schools[school]), 1.0f, 1.0f); return false; } } @@ -543,7 +543,7 @@ namespace MWMechanics if (!effect->mCasting.empty()) castStatic = store.get().find(effect->mCasting); else - castStatic = store.get().find("VFX_DefaultCast"); + castStatic = store.get().find(ESM::RefId::stringRefId("VFX_DefaultCast")); // check if the effect was already added if (std::find(addedEffects.begin(), addedEffects.end(), @@ -600,7 +600,7 @@ namespace MWMechanics if (!effect->mCastSound.empty()) sndMgr->playSound3D(mCaster, effect->mCastSound, 1.0f, 1.0f); else - sndMgr->playSound3D(mCaster, schools[effect->mData.mSchool] + " cast", 1.0f, 1.0f); + sndMgr->playSound3D(mCaster, ESM::RefId::stringRefId(schools[effect->mData.mSchool] + " cast"), 1.0f, 1.0f); } } @@ -615,7 +615,7 @@ namespace MWMechanics if (!magicEffect.mHitSound.empty()) sndMgr->playSound3D(target, magicEffect.mHitSound, 1.0f, 1.0f); else - sndMgr->playSound3D(target, schools[magicEffect.mData.mSchool] + " hit", 1.0f, 1.0f); + sndMgr->playSound3D(target, ESM::RefId::stringRefId(schools[magicEffect.mData.mSchool] + " hit"), 1.0f, 1.0f); } // Add VFX @@ -623,7 +623,7 @@ namespace MWMechanics if (!magicEffect.mHit.empty()) castStatic = MWBase::Environment::get().getWorld()->getStore().get().find(magicEffect.mHit); else - castStatic = MWBase::Environment::get().getWorld()->getStore().get().find("VFX_DefaultHit"); + castStatic = MWBase::Environment::get().getWorld()->getStore().get().find(ESM::RefId::stringRefId("VFX_DefaultHit")); bool loop = (magicEffect.mData.mFlags & ESM::MagicEffect::ContinuousVfx) != 0; MWRender::Animation* anim = MWBase::Environment::get().getWorld()->getAnimation(target); diff --git a/apps/openmw/mwmechanics/spellcasting.hpp b/apps/openmw/mwmechanics/spellcasting.hpp index fee460f448..adad2de0e3 100644 --- a/apps/openmw/mwmechanics/spellcasting.hpp +++ b/apps/openmw/mwmechanics/spellcasting.hpp @@ -34,7 +34,7 @@ namespace MWMechanics void launchMagicBolt() const; public: - std::string mId; // ID of spell, potion, item etc + ESM::RefId mId; // ID of spell, potion, item etc std::string mSourceName; // Display name for spell, potion, etc osg::Vec3f mHitPosition{ 0, 0, 0 }; // Used for spawning area orb bool mAlwaysSucceed{ @@ -62,7 +62,7 @@ namespace MWMechanics bool cast(const ESM::Potion* potion); /// @note Auto detects if spell, ingredient or potion - bool cast(const std::string& id); + bool cast(const ESM::RefId& id); void playSpellCastingEffects(const ESM::Enchantment* enchantment) const; diff --git a/apps/openmw/mwmechanics/spelleffects.cpp b/apps/openmw/mwmechanics/spelleffects.cpp index df8f1f4c64..d8b9453e00 100644 --- a/apps/openmw/mwmechanics/spelleffects.cpp +++ b/apps/openmw/mwmechanics/spelleffects.cpp @@ -170,7 +170,7 @@ namespace return -1; } - void addBoundItem(const std::string& itemId, const MWWorld::Ptr& actor) + void addBoundItem(const ESM::RefId& itemId, const MWWorld::Ptr& actor) { MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor); MWWorld::Ptr boundPtr = *store.MWWorld::ContainerStore::add(itemId, 1, actor); @@ -203,11 +203,11 @@ namespace player.setPreviousItem(itemId, prevItem->getCellRef().getRefId()); } - void removeBoundItem(const std::string& itemId, const MWWorld::Ptr& actor) + void removeBoundItem(const ESM::RefId& itemId, const MWWorld::Ptr& actor) { MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor); auto item = std::find_if(store.begin(), store.end(), - [&](const auto& it) { return Misc::StringUtils::ciEqual(it.getCellRef().getRefId(), itemId); }); + [&](const auto& it) { return ESM::RefId::ciEqual(it.getCellRef().getRefId(), itemId); }); if (item == store.end()) return; int slot = getBoundItemSlot(*item); @@ -215,7 +215,7 @@ namespace auto currentItem = store.getSlot(slot); bool wasEquipped - = currentItem != store.end() && Misc::StringUtils::ciEqual(currentItem->getCellRef().getRefId(), itemId); + = currentItem != store.end() && ESM::RefId::ciEqual(currentItem->getCellRef().getRefId(), itemId); if (wasEquipped) store.remove(*currentItem, 1, actor); @@ -247,7 +247,7 @@ namespace } MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer(); - std::string prevItemId = player.getPreviousItem(itemId); + ESM::RefId prevItemId = player.getPreviousItem(itemId); player.erasePreviousItem(itemId); if (!prevItemId.empty() && wasEquipped) @@ -276,10 +276,10 @@ namespace return false; } - void absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target) + void absorbSpell(const ESM::RefId& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target) { const auto& esmStore = MWBase::Environment::get().getWorld()->getStore(); - const ESM::Static* absorbStatic = esmStore.get().find("VFX_Absorb"); + const ESM::Static* absorbStatic = esmStore.get().find(ESM::RefId::stringRefId("VFX_Absorb")); MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(target); if (animation && !absorbStatic->mModel.empty()) { @@ -452,12 +452,12 @@ namespace MWMechanics { std::string_view marker = (effect.mEffectId == ESM::MagicEffect::DivineIntervention) ? "divinemarker" : "templemarker"; - world->teleportToClosestMarker(target, marker); + world->teleportToClosestMarker(target, ESM::RefId::stringRefId(marker)); if (!caster.isEmpty()) { MWRender::Animation* anim = world->getAnimation(caster); anim->removeEffect(effect.mEffectId); - const ESM::Static* fx = world->getStore().get().search("VFX_Summon_end"); + const ESM::Static* fx = world->getStore().get().search(ESM::RefId::stringRefId("VFX_Summon_end")); if (fx) { const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); @@ -487,10 +487,10 @@ namespace MWMechanics world->getPlayer().getMarkedPosition(markedCell, markedPosition); if (markedCell) { - std::string_view dest; + ESM::RefId dest; if (!markedCell->isExterior()) - dest = markedCell->getCell()->mName; - MWWorld::ActionTeleport action(dest, markedPosition, false); + dest = ESM::RefId::stringRefId(markedCell->getCell()->mName); + MWWorld::ActionTeleport action(dest.getRefIdString(), markedPosition, false); action.execute(target); if (!caster.isEmpty()) { @@ -566,7 +566,7 @@ namespace MWMechanics float volume = std::clamp( (magnitudes.get(effect.mEffectId).getModifier() + effect.mMagnitude) / 100.f, 0.f, 1.f); MWBase::Environment::get().getSoundManager()->playSound3D( - target, "magic sound", volume, 1.f, MWSound::Type::Sfx, MWSound::PlayMode::LoopNoEnv); + target, ESM::RefId::stringRefId("magic sound"), volume, 1.f, MWSound::Type::Sfx, MWSound::PlayMode::LoopNoEnv); } break; case ESM::MagicEffect::SummonScamp: @@ -602,8 +602,8 @@ namespace MWMechanics invalid = true; break; } - addBoundItem( - world->getStore().get().find("sMagicBoundRightGauntletID")->mValue.getString(), + addBoundItem(ESM::RefId::stringRefId( + world->getStore().get().find("sMagicBoundRightGauntletID")->mValue.getString()), target); // left gauntlet added below [[fallthrough]]; @@ -622,7 +622,7 @@ namespace MWMechanics else { const std::string& item = sBoundItemsMap.at(effect.mEffectId); - addBoundItem(world->getStore().get().find(item)->mValue.getString(), target); + addBoundItem(ESM::RefId::stringRefId(world->getStore().get().find(item)->mValue.getString()), target); } break; case ESM::MagicEffect::FireDamage: @@ -946,7 +946,7 @@ namespace MWMechanics { if (target.getCellRef().getLockLevel() > 0) { - MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock", 1.f, 1.f); + MWBase::Environment::get().getSoundManager()->playSound3D(target, ESM::RefId::stringRefId("Open Lock"), 1.f, 1.f); if (caster == getPlayer()) MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicOpenSuccess}"); @@ -955,7 +955,7 @@ namespace MWMechanics } else { - MWBase::Environment::get().getSoundManager()->playSound3D(target, "Open Lock Fail", 1.f, 1.f); + MWBase::Environment::get().getSoundManager()->playSound3D(target, ESM::RefId::stringRefId("Open Lock Fail"), 1.f, 1.f); } } else @@ -1105,7 +1105,7 @@ namespace MWMechanics break; case ESM::MagicEffect::Sound: if (magnitudes.get(effect.mEffectId).getModifier() <= 0.f && target == getPlayer()) - MWBase::Environment::get().getSoundManager()->stopSound3D(target, "magic sound"); + MWBase::Environment::get().getSoundManager()->stopSound3D(target, ESM::RefId::stringRefId("magic sound")); break; case ESM::MagicEffect::SummonScamp: case ESM::MagicEffect::SummonClannfear: @@ -1146,7 +1146,7 @@ namespace MWMechanics break; case ESM::MagicEffect::BoundGloves: removeBoundItem( - world->getStore().get().find("sMagicBoundRightGauntletID")->mValue.getString(), + ESM::RefId::stringRefId(world->getStore().get().find("sMagicBoundRightGauntletID")->mValue.getString()), target); [[fallthrough]]; case ESM::MagicEffect::BoundDagger: @@ -1161,7 +1161,7 @@ namespace MWMechanics case ESM::MagicEffect::BoundShield: { const std::string& item = sBoundItemsMap.at(effect.mEffectId); - removeBoundItem(world->getStore().get().find(item)->mValue.getString(), target); + removeBoundItem(ESM::RefId::stringRefId(world->getStore().get().find(item)->mValue.getString()), target); } break; case ESM::MagicEffect::DrainHealth: diff --git a/apps/openmw/mwmechanics/spelllist.cpp b/apps/openmw/mwmechanics/spelllist.cpp index 6da7a4e11b..0a9ee0a366 100644 --- a/apps/openmw/mwmechanics/spelllist.cpp +++ b/apps/openmw/mwmechanics/spelllist.cpp @@ -16,13 +16,13 @@ namespace { template - const std::vector getSpellList(std::string_view id) + const std::vector getSpellList(const ESM::RefId& id) { return MWBase::Environment::get().getWorld()->getStore().get().find(id)->mSpells.mList; } template - bool withBaseRecord(std::string_view id, const std::function&)>& function) + bool withBaseRecord(const ESM::RefId& id, const std::function&)>& function) { T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(id); bool changed = function(copy.mSpells.mList); @@ -34,13 +34,13 @@ namespace namespace MWMechanics { - SpellList::SpellList(const std::string& id, int type) + SpellList::SpellList(const ESM::RefId& id, int type) : mId(id) , mType(type) { } - bool SpellList::withBaseRecord(const std::function&)>& function) + bool SpellList::withBaseRecord(const std::function&)>& function) { switch (mType) { @@ -49,11 +49,11 @@ namespace MWMechanics case ESM::REC_NPC_: return ::withBaseRecord(mId, function); default: - throw std::logic_error("failed to update base record for " + mId); + throw std::logic_error("failed to update base record for " + mId.getRefIdString()); } } - const std::vector SpellList::getSpells() const + const std::vector SpellList::getSpells() const { switch (mType) { @@ -62,11 +62,11 @@ namespace MWMechanics case ESM::REC_NPC_: return getSpellList(mId); default: - throw std::logic_error("failed to get spell list for " + mId); + throw std::logic_error("failed to get spell list for " + mId.getRefIdString()); } } - const ESM::Spell* SpellList::getSpell(std::string_view id) + const ESM::Spell* SpellList::getSpell(const ESM::RefId& id) { return MWBase::Environment::get().getWorld()->getStore().get().find(id); } @@ -77,7 +77,7 @@ namespace MWMechanics bool changed = withBaseRecord([&](auto& spells) { for (const auto& it : spells) { - if (Misc::StringUtils::ciEqual(id, it)) + if (ESM::RefId::ciEqual(id, it)) return false; } spells.push_back(id); @@ -96,7 +96,7 @@ namespace MWMechanics bool changed = withBaseRecord([&](auto& spells) { for (auto it = spells.begin(); it != spells.end(); it++) { - if (Misc::StringUtils::ciEqual(id, *it)) + if (ESM::RefId::ciEqual(id, *it)) { spells.erase(it); return true; @@ -111,11 +111,11 @@ namespace MWMechanics } } - void SpellList::removeAll(const std::vector& ids) + void SpellList::removeAll(const std::vector& ids) { bool changed = withBaseRecord([&](auto& spells) { const auto it = std::remove_if(spells.begin(), spells.end(), [&](const auto& spell) { - const auto isSpell = [&](const auto& id) { return Misc::StringUtils::ciEqual(spell, id); }; + const auto isSpell = [&](const auto& id) { return ESM::RefId::ciEqual(spell, id); }; return ids.end() != std::find_if(ids.begin(), ids.end(), isSpell); }); if (it == spells.end()) diff --git a/apps/openmw/mwmechanics/spelllist.hpp b/apps/openmw/mwmechanics/spelllist.hpp index 383b9dddd6..49e40f0e79 100644 --- a/apps/openmw/mwmechanics/spelllist.hpp +++ b/apps/openmw/mwmechanics/spelllist.hpp @@ -30,24 +30,24 @@ namespace MWMechanics /// saving and loading the game might reapply the cured disease depending on which instance was cured. class SpellList { - const std::string mId; + ESM::RefId mId; const int mType; std::vector mListeners; - bool withBaseRecord(const std::function&)>& function); + bool withBaseRecord(const std::function&)>& function); public: - SpellList(const std::string& id, int type); + SpellList(const ESM::RefId& id, int type); /// Get spell from ID, throws exception if not found - static const ESM::Spell* getSpell(std::string_view id); + static const ESM::Spell* getSpell(const ESM::RefId& id); void add(const ESM::Spell* spell); ///< Adding a spell that is already listed in *this is a no-op. void remove(const ESM::Spell* spell); - void removeAll(const std::vector& spells); + void removeAll(const std::vector& spells); void clear(); ///< Remove all spells of all types. @@ -58,7 +58,7 @@ namespace MWMechanics void updateListener(Spells* before, Spells* after); - const std::vector getSpells() const; + const std::vector getSpells() const; }; } diff --git a/apps/openmw/mwmechanics/spellpriority.cpp b/apps/openmw/mwmechanics/spellpriority.cpp index 2eb076f24d..3994957b88 100644 --- a/apps/openmw/mwmechanics/spellpriority.cpp +++ b/apps/openmw/mwmechanics/spellpriority.cpp @@ -59,7 +59,7 @@ namespace return toCure; } - float getSpellDuration(const MWWorld::Ptr& actor, const std::string& spellId) + float getSpellDuration(const MWWorld::Ptr& actor, const ESM::RefId& spellId) { float duration = 0; const MWMechanics::ActiveSpells& activeSpells = actor.getClass().getCreatureStats(actor).getActiveSpells(); @@ -78,12 +78,12 @@ namespace return duration; } - bool isSpellActive(const MWWorld::Ptr& caster, const MWWorld::Ptr& target, const std::string& id) + bool isSpellActive(const MWWorld::Ptr& caster, const MWWorld::Ptr& target, const ESM::RefId& id) { int actorId = caster.getClass().getCreatureStats(caster).getActorId(); const auto& active = target.getClass().getCreatureStats(target).getActiveSpells(); return std::find_if(active.begin(), active.end(), [&](const auto& spell) { - return spell.getCasterActorId() == actorId && Misc::StringUtils::ciEqual(spell.getId(), id); + return spell.getCasterActorId() == actorId && ESM::RefId::ciEqual(spell.getId(), id); }) != active.end(); } } @@ -126,7 +126,7 @@ namespace MWMechanics // Don't make use of racial bonus spells, like MW. Can be made optional later if (actor.getClass().isNpc()) { - const std::string& raceid = actor.get()->mBase->mRace; + const ESM::RefId& raceid = actor.get()->mBase->mRace; const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(raceid); if (race->mPowers.exists(spell->mId)) return 0.f; @@ -371,7 +371,7 @@ namespace MWMechanics if (actor.getClass().isNpc()) { // Beast races can't wear helmets or boots - const std::string& raceid = actor.get()->mBase->mRace; + const ESM::RefId& raceid = actor.get()->mBase->mRace; const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(raceid); if (race->mData.mFlags & ESM::Race::Beast) diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index a0ea241fb9..0afadb1d24 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -50,7 +50,7 @@ namespace MWMechanics return mSpells.end(); } - bool Spells::hasSpell(std::string_view spell) const + bool Spells::hasSpell(const ESM::RefId& spell) const { return hasSpell(SpellList::getSpell(spell)); } @@ -65,7 +65,7 @@ namespace MWMechanics mSpellList->add(spell); } - void Spells::add(std::string_view spellId) + void Spells::add(const ESM::RefId& spellId) { add(SpellList::getSpell(spellId)); } @@ -76,13 +76,13 @@ namespace MWMechanics mSpells.emplace_back(spell); } - void Spells::remove(std::string_view spellId) + void Spells::remove(const ESM::RefId& spellId) { const auto spell = SpellList::getSpell(spellId); removeSpell(spell); mSpellList->remove(spell); - if (spellId == mSelectedSpell) + if (ESM::RefId::ciEqual(spellId, mSelectedSpell)) mSelectedSpell.clear(); } @@ -105,12 +105,12 @@ namespace MWMechanics mSpellList->clear(); } - void Spells::setSelectedSpell(const std::string& spellId) + void Spells::setSelectedSpell(const ESM::RefId& spellId) { mSelectedSpell = spellId; } - const std::string& Spells::getSelectedSpell() const + const ESM::RefId& Spells::getSelectedSpell() const { return mSelectedSpell; } @@ -134,7 +134,7 @@ namespace MWMechanics void Spells::purge(const SpellFilter& filter) { - std::vector purged; + std::vector purged; for (auto iter = mSpells.begin(); iter != mSpells.end();) { const ESM::Spell* spell = *iter; @@ -205,7 +205,7 @@ namespace MWMechanics { const auto& baseSpells = mSpellList->getSpells(); - for (const std::string& id : state.mSpells) + for (const ESM::RefId& id : state.mSpells) { // Discard spells that are no longer available due to changed content files const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(id); @@ -218,14 +218,14 @@ namespace MWMechanics } } // Add spells from the base record - for (const std::string& id : baseSpells) + for (const ESM::RefId& id : baseSpells) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(id); if (spell) addSpell(spell); } - for (std::map::const_iterator it = state.mUsedPowers.begin(); + for (auto it = state.mUsedPowers.begin(); it != state.mUsedPowers.end(); ++it) { const ESM::Spell* spell @@ -237,7 +237,7 @@ namespace MWMechanics // Permanent effects are used only to keep the custom magnitude of corprus spells effects (after cure too), and // only in old saves. Convert data to the new approach. - for (std::map>::const_iterator it + for (auto it = state.mPermanentSpellEffects.begin(); it != state.mPermanentSpellEffects.end(); ++it) { @@ -293,7 +293,7 @@ namespace MWMechanics state.mUsedPowers[it.first->mId] = it.second.toEsm(); } - bool Spells::setSpells(const std::string& actorId) + bool Spells::setSpells(const ESM::RefId& actorId) { bool result; std::tie(mSpellList, result) = MWBase::Environment::get().getWorld()->getStore().getSpellList(actorId); @@ -302,9 +302,9 @@ namespace MWMechanics return result; } - void Spells::addAllToInstance(const std::vector& spells) + void Spells::addAllToInstance(const std::vector& spells) { - for (const std::string& id : spells) + for (const ESM::RefId& id : spells) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(id); if (spell) diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 4248e6de95..e268b50f0d 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -31,7 +31,7 @@ namespace MWMechanics std::vector mSpells; // Note: this is the spell that's about to be cast, *not* the spell selected in the GUI (which may be different) - std::string mSelectedSpell; + ESM::RefId mSelectedSpell; std::vector> mUsedPowers; @@ -69,26 +69,26 @@ namespace MWMechanics std::vector::const_iterator end() const; - bool hasSpell(std::string_view spell) const; + bool hasSpell(const ESM::RefId& spell) const; bool hasSpell(const ESM::Spell* spell) const; - void add(std::string_view spell); + void add(const ESM::RefId& spell); ///< Adding a spell that is already listed in *this is a no-op. void add(const ESM::Spell* spell); ///< Adding a spell that is already listed in *this is a no-op. - void remove(std::string_view spell); + void remove(const ESM::RefId& spell); ///< If the spell to be removed is the selected spell, the selected spell will be changed to /// no spell (empty string). void clear(bool modifyBase = false); ///< Remove all spells of al types. - void setSelectedSpell(const std::string& spellId); + void setSelectedSpell(const ESM::RefId& spellId); ///< This function does not verify, if the spell is available. - const std::string& getSelectedSpell() const; + const ESM::RefId& getSelectedSpell() const; ///< May return an empty string. bool hasCommonDisease() const; @@ -98,9 +98,9 @@ namespace MWMechanics void readState(const ESM::SpellState& state, CreatureStats* creatureStats); void writeState(ESM::SpellState& state) const; - bool setSpells(const std::string& id); + bool setSpells(const ESM::RefId& id); - void addAllToInstance(const std::vector& spells); + void addAllToInstance(const std::vector& spells); }; } diff --git a/apps/openmw/mwmechanics/spellutil.cpp b/apps/openmw/mwmechanics/spellutil.cpp index 08c2085986..a15aa9790c 100644 --- a/apps/openmw/mwmechanics/spellutil.cpp +++ b/apps/openmw/mwmechanics/spellutil.cpp @@ -181,14 +181,14 @@ namespace MWMechanics } float getSpellSuccessChance( - const std::string& spellId, const MWWorld::Ptr& actor, int* effectiveSchool, bool cap, bool checkMagicka) + const ESM::RefId& spellId, const MWWorld::Ptr& actor, int* effectiveSchool, bool cap, bool checkMagicka) { if (const auto spell = MWBase::Environment::get().getWorld()->getStore().get().search(spellId)) return getSpellSuccessChance(spell, actor, effectiveSchool, cap, checkMagicka); return 0.f; } - int getSpellSchool(const std::string& spellId, const MWWorld::Ptr& actor) + int getSpellSchool(const ESM::RefId& spellId, const MWWorld::Ptr& actor) { int school = 0; getSpellSuccessChance(spellId, actor, &school); @@ -207,7 +207,7 @@ namespace MWMechanics return spell->mData.mType == ESM::Spell::ST_Spell && !(spell->mData.mFlags & ESM::Spell::F_Always); } - bool spellIncreasesSkill(const std::string& spellId) + bool spellIncreasesSkill(const ESM::RefId& spellId) { const auto spell = MWBase::Environment::get().getWorld()->getStore().get().search(spellId); return spell && spellIncreasesSkill(spell); diff --git a/apps/openmw/mwmechanics/spellutil.hpp b/apps/openmw/mwmechanics/spellutil.hpp index 457782d7be..40b1ea0ff0 100644 --- a/apps/openmw/mwmechanics/spellutil.hpp +++ b/apps/openmw/mwmechanics/spellutil.hpp @@ -43,15 +43,15 @@ namespace MWMechanics float calcSpellBaseSuccessChance(const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool); float getSpellSuccessChance(const ESM::Spell* spell, const MWWorld::Ptr& actor, int* effectiveSchool = nullptr, bool cap = true, bool checkMagicka = true); - float getSpellSuccessChance(const std::string& spellId, const MWWorld::Ptr& actor, int* effectiveSchool = nullptr, + float getSpellSuccessChance(const ESM::RefId& spellId, const MWWorld::Ptr& actor, int* effectiveSchool = nullptr, bool cap = true, bool checkMagicka = true); - int getSpellSchool(const std::string& spellId, const MWWorld::Ptr& actor); + int getSpellSchool(const ESM::RefId& spellId, const MWWorld::Ptr& actor); int getSpellSchool(const ESM::Spell* spell, const MWWorld::Ptr& actor); /// Get whether or not the given spell contributes to skill progress. bool spellIncreasesSkill(const ESM::Spell* spell); - bool spellIncreasesSkill(const std::string& spellId); + bool spellIncreasesSkill(const ESM::RefId& spellId); } #endif diff --git a/apps/openmw/mwmechanics/summoning.cpp b/apps/openmw/mwmechanics/summoning.cpp index 7bc7344012..5a4dfd7808 100644 --- a/apps/openmw/mwmechanics/summoning.cpp +++ b/apps/openmw/mwmechanics/summoning.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "../mwbase/environment.hpp" @@ -28,7 +29,7 @@ namespace MWMechanics || (effectId >= ESM::MagicEffect::SummonFabricant && effectId <= ESM::MagicEffect::SummonCreature05)); } - std::string_view getSummonedCreature(int effectId) + const ESM::RefId& getSummonedCreature(int effectId) { static const std::map summonMap{ { ESM::MagicEffect::SummonAncestralGhost, "sMagicAncestralGhostID" }, @@ -57,18 +58,21 @@ namespace MWMechanics auto it = summonMap.find(effectId); if (it != summonMap.end()) - return MWBase::Environment::get() - .getWorld() - ->getStore() - .get() - .find(it->second) - ->mValue.getString(); - return {}; + { + static ESM::RefId val = ESM::RefId::stringRefId(MWBase::Environment::get() + .getWorld() + ->getStore() + .get() + .find(it->second) + ->mValue.getString()); + return val; + } + return ESM::RefId::sEmpty; } int summonCreature(int effectId, const MWWorld::Ptr& summoner) { - std::string_view creatureID = getSummonedCreature(effectId); + const ESM::RefId& creatureID = getSummonedCreature(effectId); int creatureActorId = -1; if (!creatureID.empty()) { @@ -90,7 +94,7 @@ namespace MWMechanics MWRender::Animation* anim = world->getAnimation(placed); if (anim) { - const ESM::Static* fx = world->getStore().get().search("VFX_Summon_Start"); + const ESM::Static* fx = world->getStore().get().search(ESM::RefId::stringRefId("VFX_Summon_Start")); if (fx) { const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); diff --git a/apps/openmw/mwmechanics/summoning.hpp b/apps/openmw/mwmechanics/summoning.hpp index 2fb2eac693..f042d5a20a 100644 --- a/apps/openmw/mwmechanics/summoning.hpp +++ b/apps/openmw/mwmechanics/summoning.hpp @@ -3,7 +3,10 @@ #include #include - +namespace ESM +{ + struct RefId; +} namespace MWWorld { class Ptr; @@ -13,7 +16,7 @@ namespace MWMechanics { bool isSummoningEffect(int effectId); - std::string_view getSummonedCreature(int effectId); + const ESM::RefId& getSummonedCreature(int effectId); void purgeSummonEffect(const MWWorld::Ptr& summoner, const std::pair& summon); diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index 676dfb5082..b2b34f1741 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -118,15 +118,15 @@ namespace MWRender if (part.mPart != ESM::PRT_Shield) continue; - std::string_view bodypartName; + const ESM::RefId* bodypartName = nullptr; if (female && !part.mFemale.empty()) - bodypartName = part.mFemale; + bodypartName = &part.mFemale; else if (!part.mMale.empty()) - bodypartName = part.mMale; + bodypartName = &part.mMale; - if (!bodypartName.empty()) + if (bodypartName && !bodypartName->empty()) { - const ESM::BodyPart* bodypart = partStore.search(bodypartName); + const ESM::BodyPart* bodypart = partStore.search(*bodypartName); if (bodypart == nullptr || bodypart->mData.mType != ESM::BodyPart::MT_Armor) return std::string(); if (!bodypart->mModel.empty()) diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index 73c86add29..330289212e 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -543,7 +543,7 @@ namespace MWRender void RaceSelectionPreview::setPrototype(const ESM::NPC& proto) { mBase = proto; - mBase.mId = "player"; + mBase.mId = ESM::RefId::stringRefId("player"); rebuild(); } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index a83d0bf3dd..818929818f 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -47,11 +47,11 @@ namespace { - std::string getVampireHead(const std::string& race, bool female, const VFS::Manager& vfs) + std::string getVampireHead(const ESM::RefId& race, bool female, const VFS::Manager& vfs) { - static std::map, const ESM::BodyPart*> sVampireMapping; + static std::map, const ESM::BodyPart*> sVampireMapping; - std::pair thisCombination = std::make_pair(race, int(female)); + std::pair thisCombination = std::make_pair(race, int(female)); if (sVampireMapping.find(thisCombination) == sVampireMapping.end()) { @@ -66,7 +66,7 @@ namespace continue; if (female != (bodypart.mData.mFlags & ESM::BodyPart::BPF_Female)) continue; - if (!Misc::StringUtils::ciEqual(bodypart.mRace, race)) + if (!ESM::RefId::ciEqual(bodypart.mRace, race)) continue; sVampireMapping[thisCombination] = &bodypart; } @@ -467,8 +467,8 @@ namespace MWRender mHeadModel.clear(); mHairModel.clear(); - std::string_view headName = isWerewolf ? std::string_view{ "WerewolfHead" } : mNpc->mHead; - std::string_view hairName = isWerewolf ? std::string_view{ "WerewolfHair" } : mNpc->mHair; + const ESM::RefId& headName = isWerewolf ? ESM::RefId::stringRefId("WerewolfHead") : mNpc->mHead; + const ESM::RefId& hairName = isWerewolf ? ESM::RefId::stringRefId("WerewolfHair") : mNpc->mHair; if (!headName.empty()) { @@ -519,7 +519,7 @@ namespace MWRender addAnimSource(smodel, smodel); - if (!isWerewolf && Misc::StringUtils::lowerCase(mNpc->mRace).find("argonian") != std::string::npos) + if (!isWerewolf && Misc::StringUtils::lowerCase(mNpc->mRace.getRefIdString()).find("argonian") != std::string::npos) addAnimSource("meshes\\xargonian_swimkna.nif", smodel); } else @@ -665,7 +665,7 @@ namespace MWRender showCarriedLeft(mShowCarriedLeft); bool isWerewolf = (getNpcType() == Type_Werewolf); - std::string race = (isWerewolf ? "werewolf" : Misc::StringUtils::lowerCase(mNpc->mRace)); + ESM::RefId race = (isWerewolf ? ESM::RefId::stringRefId("werewolf") : mNpc->mRace); const std::vector& parts = getBodyParts(race, !mNpc->isMale(), mViewMode == VM_FirstPerson, isWerewolf); @@ -756,7 +756,8 @@ namespace MWRender bool NpcAnimation::isFirstPersonPart(const ESM::BodyPart* bodypart) { - return bodypart->mId.size() >= 3 && bodypart->mId.substr(bodypart->mId.size() - 3, 3) == "1st"; + const auto partName = bodypart->mId.getRefIdString(); + return partName.size() >= 3 && partName.substr(partName.size() - 3, 3) == "1st"; } bool NpcAnimation::isFemalePart(const ESM::BodyPart* bodypart) @@ -881,7 +882,7 @@ namespace MWRender const ESM::BodyPart* bodypart = nullptr; if (!mNpc->isMale() && !part.mFemale.empty()) { - bodypart = partStore.search(part.mFemale + ext); + bodypart = partStore.search(ESM::RefId::stringRefId(part.mFemale.getRefIdString() + ext)); if (!bodypart && mViewMode == VM_FirstPerson) { bodypart = partStore.search(part.mFemale); @@ -897,7 +898,7 @@ namespace MWRender } if (!bodypart && !part.mMale.empty()) { - bodypart = partStore.search(part.mMale + ext); + bodypart = partStore.search(ESM::RefId::stringRefId(part.mMale.getRefIdString() + ext)); if (!bodypart && mViewMode == VM_FirstPerson) { bodypart = partStore.search(part.mMale); @@ -1159,11 +1160,11 @@ namespace MWRender } // Remember body parts so we only have to search through the store once for each race/gender/viewmode combination - typedef std::map, std::vector> RaceMapping; + typedef std::map, std::vector> RaceMapping; static RaceMapping sRaceMapping; const std::vector& NpcAnimation::getBodyParts( - const std::string& race, bool female, bool firstPerson, bool werewolf) + const ESM::RefId& race, bool female, bool firstPerson, bool werewolf) { static const int Flag_FirstPerson = 1 << 1; static const int Flag_Female = 1 << 0; @@ -1208,7 +1209,7 @@ namespace MWRender if (bodypart.mData.mType != ESM::BodyPart::MT_Skin) continue; - if (!Misc::StringUtils::ciEqual(bodypart.mRace, race)) + if (!ESM::RefId::ciEqual(bodypart.mRace, race)) continue; bool partFirstPerson = isFirstPersonPart(&bodypart); diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index bb7b889c1e..5468e785d9 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -176,7 +176,7 @@ namespace MWRender /// @note This is a fixed size list, one list item for each ESM::PartReferenceType, may contain nullptr body /// parts. static const std::vector& getBodyParts( - const std::string& raceId, bool female, bool firstperson, bool werewolf); + const ESM::RefId& raceId, bool female, bool firstperson, bool werewolf); }; } diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index 3e2278f520..421cac3c10 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -61,7 +61,7 @@ namespace MWRender } } - std::string getModel(int type, const std::string& id, const MWWorld::ESMStore& store) + std::string getModel(int type, const ESM::RefId& id, const MWWorld::ESMStore& store) { switch (type) { @@ -508,7 +508,6 @@ namespace MWRender != cell->mMovedRefs.end()) continue; - Misc::StringUtils::lowerCaseInPlace(ref.mRefID); int type = store.findStatic(ref.mRefID); if (!typeFilter(type, size >= 2)) continue; @@ -532,7 +531,6 @@ namespace MWRender refs.erase(ref.mRefNum); continue; } - Misc::StringUtils::lowerCaseInPlace(ref.mRefID); int type = store.findStatic(ref.mRefID); if (!typeFilter(type, size >= 2)) continue; @@ -601,7 +599,7 @@ namespace MWRender continue; } - if (Misc::ResourceHelpers::isHiddenMarker(ref.mRefID)) + if (Misc::ResourceHelpers::isHiddenMarker(ref.mRefID.getRefIdString())) continue; int type = store.findStatic(ref.mRefID); diff --git a/apps/openmw/mwrender/skyutil.hpp b/apps/openmw/mwrender/skyutil.hpp index 84e88c8379..8808d10a89 100644 --- a/apps/openmw/mwrender/skyutil.hpp +++ b/apps/openmw/mwrender/skyutil.hpp @@ -12,6 +12,7 @@ #include #include +#include namespace Resource { @@ -63,7 +64,7 @@ namespace MWRender bool mIsStorm; - std::string mAmbientLoopSoundID; + ESM::RefId mAmbientLoopSoundID; float mAmbientSoundVolume; std::string mParticleEffect; diff --git a/apps/openmw/mwrender/weaponanimation.cpp b/apps/openmw/mwrender/weaponanimation.cpp index 63f1b5ad47..a356545ce5 100644 --- a/apps/openmw/mwrender/weaponanimation.cpp +++ b/apps/openmw/mwrender/weaponanimation.cpp @@ -69,7 +69,7 @@ namespace MWRender ESM::WeaponType::Class weapclass = MWMechanics::getWeaponType(type)->mWeaponClass; if (weapclass == ESM::WeaponType::Thrown) { - std::string_view soundid = weaponSlot->getClass().getUpSoundId(*weaponSlot); + auto soundid = weaponSlot->getClass().getUpSoundId(*weaponSlot); if (!soundid.empty()) { MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index ea1062e1b2..56a349f7ef 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -43,7 +43,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId objectID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); // The value of the reset argument doesn't actually matter @@ -100,7 +100,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -138,10 +138,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId cellID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -329,7 +329,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -355,7 +355,7 @@ namespace MWScript MWMechanics::AiFollow followPackage(actorID, duration, x, y, z, repeat); ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(followPackage, ptr); - Log(Debug::Info) << "AiFollow: " << actorID << ", " << x << ", " << y << ", " << z << ", " << duration; + Log(Debug::Info) << "AiFollow: " << actorID.getRefIdString() << ", " << x << ", " << y << ", " << z << ", " << duration; } }; @@ -367,10 +367,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId cellID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -395,7 +395,7 @@ namespace MWScript MWMechanics::AiFollow followPackage(actorID, cellID, duration, x, y, z, repeat); ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(followPackage, ptr); - Log(Debug::Info) << "AiFollow: " << actorID << ", " << x << ", " << y << ", " << z << ", " << duration; + Log(Debug::Info) << "AiFollow: " << actorID.getRefIdString() << ", " << x << ", " << y << ", " << z << ", " << duration; } }; @@ -429,7 +429,7 @@ namespace MWScript { MWWorld::Ptr observer = R()(runtime, false); // required=false - std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false); @@ -451,7 +451,7 @@ namespace MWScript MWWorld::Ptr source = R()(runtime); - std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWWorld::Ptr dest = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false); @@ -471,7 +471,7 @@ namespace MWScript void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr actor = R()(runtime); - std::string_view testedTargetId = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId testedTargetId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); bool targetsAreEqual = false; @@ -484,7 +484,7 @@ namespace MWScript if (!targetPtr.isEmpty() && targetPtr.getCellRef().getRefId() == testedTargetId) targetsAreEqual = true; } - else if (testedTargetId == "player") // Currently the player ID is hardcoded + else if (testedTargetId == ESM::RefId::stringRefId("player")) // Currently the player ID is hardcoded { MWBase::MechanicsManager* mechMgr = MWBase::Environment::get().getMechanicsManager(); bool greeting = mechMgr->getGreetingState(actor) == MWMechanics::Greet_InProgress; @@ -503,7 +503,7 @@ namespace MWScript void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr actor = R()(runtime); - std::string_view targetID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId targetID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetID, true, false); diff --git a/apps/openmw/mwscript/compilercontext.cpp b/apps/openmw/mwscript/compilercontext.cpp index 01f2ea73be..9a0fc39312 100644 --- a/apps/openmw/mwscript/compilercontext.cpp +++ b/apps/openmw/mwscript/compilercontext.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/scriptmanager.hpp" @@ -49,34 +50,34 @@ namespace MWScript return MWBase::Environment::get().getWorld()->getGlobalVariableType(name); } - std::pair CompilerContext::getMemberType(const std::string& name, const std::string& id) const + std::pair CompilerContext::getMemberType(const std::string& name, const ESM::RefId& id) const { - std::string_view script; + const ESM::RefId* script = nullptr; bool reference = false; if (const ESM::Script* scriptRecord = MWBase::Environment::get().getWorld()->getStore().get().search(id)) { - script = scriptRecord->mId; + script = &scriptRecord->mId; } else { MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id); - script = ref.getPtr().getClass().getScript(ref.getPtr()); + script = &ref.getPtr().getClass().getScript(ref.getPtr()); reference = true; } char type = ' '; - if (!script.empty()) - type = MWBase::Environment::get().getScriptManager()->getLocals(script).getType( + if (script && !script->empty()) + type = MWBase::Environment::get().getScriptManager()->getLocals(*script).getType( Misc::StringUtils::lowerCase(name)); return std::make_pair(type, reference); } - bool CompilerContext::isId(const std::string& name) const + bool CompilerContext::isId(const ESM::RefId& name) const { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwscript/compilercontext.hpp b/apps/openmw/mwscript/compilercontext.hpp index 7b77f74a40..1c11ed8877 100644 --- a/apps/openmw/mwscript/compilercontext.hpp +++ b/apps/openmw/mwscript/compilercontext.hpp @@ -3,6 +3,11 @@ #include +namespace ESM +{ + struct RefId; +} + namespace MWScript { class CompilerContext : public Compiler::Context @@ -27,13 +32,13 @@ namespace MWScript /// 'l: long, 's': short, 'f': float, ' ': does not exist. char getGlobalType(const std::string& name) const override; - std::pair getMemberType(const std::string& name, const std::string& id) const override; + std::pair getMemberType(const std::string& name, const ESM::RefId& id) const override; ///< Return type of member variable \a name in script \a id or in script of reference of /// \a id /// \return first: 'l: long, 's': short, 'f': float, ' ': does not exist. /// second: true: script of reference - bool isId(const std::string& name) const override; + bool isId(const ESM::RefId& name) const override; ///< Does \a name match an ID, that can be referenced? }; } diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 925cba1502..7024058ed0 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -66,7 +66,7 @@ namespace else { auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - std::string_view itemId + const ESM::RefId& itemId = MWMechanics::getLevelledItem(itemPtr.get()->mBase, false, prng); if (itemId.empty()) return; @@ -91,7 +91,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer count = runtime[0].mInteger; @@ -104,9 +104,9 @@ namespace MWScript if (count == 0) return; - if (::Misc::StringUtils::ciEqual(item, "gold_005") || ::Misc::StringUtils::ciEqual(item, "gold_010") - || ::Misc::StringUtils::ciEqual(item, "gold_025") || ::Misc::StringUtils::ciEqual(item, "gold_100")) - item = "gold_001"; + if (ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_005")) || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_010")) + || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_025")) || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_100"))) + item = ESM::RefId::stringRefId("gold_001"); // Check if "item" can be placed in a container MWWorld::ManualRef manualRef(MWBase::Environment::get().getWorld()->getStore(), item, 1); @@ -188,12 +188,12 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - if (::Misc::StringUtils::ciEqual(item, "gold_005") || ::Misc::StringUtils::ciEqual(item, "gold_010") - || ::Misc::StringUtils::ciEqual(item, "gold_025") || ::Misc::StringUtils::ciEqual(item, "gold_100")) - item = "gold_001"; + if (ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_005")) || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_010")) + || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_025")) || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_100"))) + item = ESM::RefId::stringRefId("gold_001"); MWWorld::ContainerStore& store = ptr.getClass().getContainerStore(ptr); @@ -209,7 +209,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer count = runtime[0].mInteger; @@ -222,9 +222,9 @@ namespace MWScript if (count == 0) return; - if (::Misc::StringUtils::ciEqual(item, "gold_005") || ::Misc::StringUtils::ciEqual(item, "gold_010") - || ::Misc::StringUtils::ciEqual(item, "gold_025") || ::Misc::StringUtils::ciEqual(item, "gold_100")) - item = "gold_001"; + if (ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_005")) || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_010")) + || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_025")) || ESM::RefId::ciEqual(item, ESM::RefId::stringRefId("gold_100"))) + item = ESM::RefId::stringRefId("gold_001"); // Explicit calls to non-unique actors affect the base record if (!R::implicit && ptr.getClass().isActor() @@ -260,7 +260,7 @@ namespace MWScript std::string_view itemName; for (MWWorld::ConstContainerStoreIterator iter(store.cbegin()); iter != store.cend(); ++iter) { - if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item)) + if (ESM::RefId::ciEqual(iter->getCellRef().getRefId(), item)) { itemName = iter->getClass().getName(*iter); break; @@ -299,7 +299,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore(ptr); @@ -309,10 +309,10 @@ namespace MWScript // With soul gems we prefer filled ones. for (auto it = invStore.begin(); it != invStore.end(); ++it) { - if (Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item)) + if (ESM::RefId::ciEqual(it->getCellRef().getRefId(), item)) { found = it; - const std::string& soul = it->getCellRef().getSoul(); + const ESM::RefId& soul = it->getCellRef().getSoul(); if (!it->getClass().isSoulGem(*it) || (!soul.empty() && store.get().search(soul))) break; @@ -418,14 +418,14 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore(ptr); for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot) { MWWorld::ConstContainerStoreIterator it = invStore.getSlot(slot); - if (it != invStore.end() && ::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item)) + if (it != invStore.end() && ESM::RefId::ciEqual(it->getCellRef().getRefId(), item)) { runtime.push(1); return; @@ -443,7 +443,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int count = 0; @@ -452,7 +452,7 @@ namespace MWScript = invStore.cbegin(MWWorld::ContainerStore::Type_Miscellaneous); it != invStore.cend(); ++it) { - if (::Misc::StringUtils::ciEqual(it->getCellRef().getSoul(), name)) + if (ESM::RefId::ciEqual(it->getCellRef().getSoul(), name)) count += it->getRefData().getCount(); } runtime.push(count); diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index 415a8f6d8b..857f3c5edf 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -33,7 +33,7 @@ namespace MWScript if (ptr.isEmpty()) ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - std::string quest{ runtime.getStringLiteral(runtime[0].mInteger) }; + ESM::RefId quest = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer index = runtime[0].mInteger; @@ -57,7 +57,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string quest{ runtime.getStringLiteral(runtime[0].mInteger) }; + ESM::RefId quest = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer index = runtime[0].mInteger; @@ -72,7 +72,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string quest{ runtime.getStringLiteral(runtime[0].mInteger) }; + ESM::RefId quest = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int index = MWBase::Environment::get().getJournal()->getJournalIndex(quest); @@ -86,7 +86,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view topic = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId topic = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWBase::Environment::get().getDialogueManager()->addTopic(topic); @@ -207,10 +207,10 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view faction1 = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId faction1 = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId faction2 = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int modReaction = runtime[0].mInteger; @@ -225,10 +225,10 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view faction1 = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId faction1 = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId faction2 = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); runtime.push(MWBase::Environment::get().getDialogueManager()->getFactionReaction(faction1, faction2)); @@ -240,10 +240,10 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view faction1 = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId faction1 = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId faction2 = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int newValue = runtime[0].mInteger; diff --git a/apps/openmw/mwscript/globalscripts.cpp b/apps/openmw/mwscript/globalscripts.cpp index f081229b75..78a823f74f 100644 --- a/apps/openmw/mwscript/globalscripts.cpp +++ b/apps/openmw/mwscript/globalscripts.cpp @@ -37,7 +37,7 @@ namespace return script; } - ESM::GlobalScript operator()(const std::pair& pair) const + ESM::GlobalScript operator()(const std::pair& pair) const { ESM::GlobalScript script; script.mTargetId = pair.second; @@ -51,14 +51,14 @@ namespace { const MWWorld::Ptr* operator()(const MWWorld::Ptr& ptr) const { return &ptr; } - const MWWorld::Ptr* operator()(const std::pair& pair) const { return nullptr; } + const MWWorld::Ptr* operator()(const std::pair& pair) const { return nullptr; } }; struct PtrResolvingVisitor { MWWorld::Ptr operator()(const MWWorld::Ptr& ptr) const { return ptr; } - MWWorld::Ptr operator()(const std::pair& pair) const + MWWorld::Ptr operator()(const std::pair& pair) const { if (pair.second.empty()) return MWWorld::Ptr(); @@ -80,19 +80,19 @@ namespace bool operator()(const MWWorld::Ptr& ptr) const { return ptr == mPtr; } - bool operator()(const std::pair& pair) const { return false; } + bool operator()(const std::pair& pair) const { return false; } }; struct IdGettingVisitor { - std::string_view operator()(const MWWorld::Ptr& ptr) const + const ESM::RefId& operator()(const MWWorld::Ptr& ptr) const { if (ptr.isEmpty()) - return {}; + return ESM::RefId::sEmpty; return ptr.mRef->mRef.getRefId(); } - std::string_view operator()(const std::pair& pair) const { return pair.second; } + const ESM::RefId& operator()(const std::pair& pair) const { return pair.second; } }; } @@ -115,7 +115,7 @@ namespace MWScript return ptr; } - std::string_view GlobalScriptDesc::getId() const + const ESM::RefId& GlobalScriptDesc::getId() const { return std::visit(IdGettingVisitor{}, mTarget); } @@ -125,21 +125,20 @@ namespace MWScript { } - void GlobalScripts::addScript(std::string_view name, const MWWorld::Ptr& target) + void GlobalScripts::addScript(const ESM::RefId& name, const MWWorld::Ptr& target) { - std::string lowerName = ::Misc::StringUtils::lowerCase(name); - const auto iter = mScripts.find(lowerName); + const auto iter = mScripts.find(name); if (iter == mScripts.end()) { - if (const ESM::Script* script = mStore.get().search(lowerName)) + if (const ESM::Script* script = mStore.get().search(name)) { auto desc = std::make_shared(); MWWorld::Ptr ptr = target; desc->mTarget = ptr; desc->mRunning = true; desc->mLocals.configure(*script); - mScripts.insert(std::make_pair(lowerName, desc)); + mScripts.insert(std::make_pair(name, desc)); } else { @@ -154,17 +153,17 @@ namespace MWScript } } - void GlobalScripts::removeScript(std::string_view name) + void GlobalScripts::removeScript(const ESM::RefId& name) { - const auto iter = mScripts.find(::Misc::StringUtils::lowerCase(name)); + const auto iter = mScripts.find(name); if (iter != mScripts.end()) iter->second->mRunning = false; } - bool GlobalScripts::isRunning(std::string_view name) const + bool GlobalScripts::isRunning(const ESM::RefId& name) const { - const auto iter = mScripts.find(::Misc::StringUtils::lowerCase(name)); + const auto iter = mScripts.find(name); if (iter == mScripts.end()) return false; @@ -193,9 +192,9 @@ namespace MWScript void GlobalScripts::addStartup() { // make list of global scripts to be added - std::vector scripts; + std::vector scripts; - scripts.emplace_back("main"); + scripts.emplace_back(ESM::RefId::stringRefId("main")); for (MWWorld::Store::iterator iter = mStore.get().begin(); iter != mStore.get().end(); ++iter) @@ -204,7 +203,7 @@ namespace MWScript } // add scripts - for (std::vector::const_iterator iter(scripts.begin()); iter != scripts.end(); ++iter) + for (auto iter(scripts.begin()); iter != scripts.end(); ++iter) { try { @@ -293,7 +292,7 @@ namespace MWScript return false; } - Locals& GlobalScripts::getLocals(std::string_view name) + Locals& GlobalScripts::getLocals(const ESM::RefId& name) { auto iter = mScripts.find(name); @@ -310,7 +309,7 @@ namespace MWScript return iter->second->mLocals; } - const Locals* GlobalScripts::getLocalsIfPresent(std::string_view name) const + const Locals* GlobalScripts::getLocalsIfPresent(const ESM::RefId& name) const { auto iter = mScripts.find(name); if (iter == mScripts.end()) diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index 7839580090..455913df17 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -11,6 +11,7 @@ #include #include +#include #include "locals.hpp" @@ -39,7 +40,7 @@ namespace MWScript { bool mRunning; Locals mLocals; - std::variant> mTarget; // Used to start targeted script + std::variant> mTarget; // Used to start targeted script GlobalScriptDesc(); @@ -47,24 +48,23 @@ namespace MWScript MWWorld::Ptr getPtr(); // Resolves mTarget to a Ptr and caches the (potentially empty) result - std::string_view getId() const; // Returns the target's ID -- if any + const ESM::RefId& getId() const; // Returns the target's ID -- if any }; class GlobalScripts { const MWWorld::ESMStore& mStore; - std::unordered_map, ::Misc::StringUtils::CiHash, - ::Misc::StringUtils::CiEqual> + std::unordered_map> mScripts; public: GlobalScripts(const MWWorld::ESMStore& store); - void addScript(std::string_view name, const MWWorld::Ptr& target = MWWorld::Ptr()); + void addScript(const ESM::RefId& name, const MWWorld::Ptr& target = MWWorld::Ptr()); - void removeScript(std::string_view name); + void removeScript(const ESM::RefId& name); - bool isRunning(std::string_view name) const; + bool isRunning(const ESM::RefId& name) const; void run(); ///< run all active global scripts @@ -83,11 +83,11 @@ namespace MWScript /// /// \return Known type? - Locals& getLocals(std::string_view name); + Locals& getLocals(const ESM::RefId& name); ///< If the script \a name has not been added as a global script yet, it is added /// automatically, but is not set to running state. - const Locals* getLocalsIfPresent(std::string_view name) const; + const Locals* getLocalsIfPresent(const ESM::RefId& name) const; void updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated); ///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell. diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index f07de289a7..8e23121410 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -26,7 +26,7 @@ namespace MWScript { - const MWWorld::Ptr InterpreterContext::getReferenceImp(std::string_view id, bool activeOnly, bool doThrow) const + const MWWorld::Ptr InterpreterContext::getReferenceImp(const ESM::RefId& id, bool activeOnly, bool doThrow) const { if (!id.empty()) { @@ -44,7 +44,7 @@ namespace MWScript } } - const Locals& InterpreterContext::getMemberLocals(std::string_view& id, bool global) const + const Locals& InterpreterContext::getMemberLocals(ESM::RefId& id, bool global) const { if (global) { @@ -62,7 +62,7 @@ namespace MWScript } } - Locals& InterpreterContext::getMemberLocals(std::string_view& id, bool global) + Locals& InterpreterContext::getMemberLocals(ESM::RefId& id, bool global) { if (global) { @@ -85,7 +85,7 @@ namespace MWScript { } - int InterpreterContext::findLocalVariableIndex(std::string_view scriptId, std::string_view name, char type) const + int InterpreterContext::findLocalVariableIndex(const ESM::RefId& scriptId, std::string_view name, char type) const { int index = MWBase::Environment::get().getScriptManager()->getLocals(scriptId).searchIndex(type, name); @@ -133,13 +133,13 @@ namespace MWScript mGlobalScriptDesc = globalScriptDesc; } - std::string_view InterpreterContext::getTarget() const + const ESM::RefId& InterpreterContext::getTarget() const { if (!mReference.isEmpty()) return mReference.mRef->mRef.getRefId(); else if (mGlobalScriptDesc) return mGlobalScriptDesc->getId(); - return {}; + return ESM::RefId::sEmpty; } int InterpreterContext::getLocalShort(int index) const @@ -239,7 +239,7 @@ namespace MWScript std::vector ids; for (const auto& globalVariable : globals) { - ids.emplace_back(globalVariable.mId); + ids.emplace_back(globalVariable.mId.getRefIdString()); } return ids; @@ -312,7 +312,7 @@ namespace MWScript std::string_view InterpreterContext::getNPCRank() const { const MWWorld::Ptr& ptr = getReferenceImp(); - std::string_view faction = ptr.getClass().getPrimaryFaction(ptr); + const ESM::RefId& faction = ptr.getClass().getPrimaryFaction(ptr); if (faction.empty()) throw std::runtime_error("getNPCRank(): NPC is not in a faction"); @@ -335,14 +335,14 @@ namespace MWScript std::string_view InterpreterContext::getPCRace() const { MWBase::World* world = MWBase::Environment::get().getWorld(); - const std::string& race = world->getPlayerPtr().get()->mBase->mRace; + const ESM::RefId& race = world->getPlayerPtr().get()->mBase->mRace; return world->getStore().get().find(race)->mName; } std::string_view InterpreterContext::getPCClass() const { MWBase::World* world = MWBase::Environment::get().getWorld(); - const std::string& class_ = world->getPlayerPtr().get()->mBase->mClass; + const ESM::RefId& class_ = world->getPlayerPtr().get()->mBase->mClass; return world->getStore().get().find(class_)->mName; } @@ -351,12 +351,12 @@ namespace MWScript MWBase::World* world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - std::string_view factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); + const ESM::RefId& factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); if (factionId.empty()) throw std::runtime_error("getPCRank(): NPC is not in a faction"); - const std::map& ranks = player.getClass().getNpcStats(player).getFactionRanks(); - std::map::const_iterator it = ranks.find(Misc::StringUtils::lowerCase(factionId)); + const auto& ranks = player.getClass().getNpcStats(player).getFactionRanks(); + auto it = ranks.find(factionId); int rank = -1; if (it != ranks.end()) rank = it->second; @@ -380,12 +380,12 @@ namespace MWScript MWBase::World* world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); - std::string_view factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); + const ESM::RefId& factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); if (factionId.empty()) throw std::runtime_error("getPCNextRank(): NPC is not in a faction"); - const std::map& ranks = player.getClass().getNpcStats(player).getFactionRanks(); - std::map::const_iterator it = ranks.find(Misc::StringUtils::lowerCase(factionId)); + const auto& ranks = player.getClass().getNpcStats(player).getFactionRanks(); + auto it = ranks.find(factionId); int rank = -1; if (it != ranks.end()) rank = it->second; @@ -428,42 +428,42 @@ namespace MWScript } } - int InterpreterContext::getMemberShort(std::string_view id, std::string_view name, bool global) const + int InterpreterContext::getMemberShort(ESM::RefId id, std::string_view name, bool global) const { const Locals& locals = getMemberLocals(id, global); return locals.mShorts[findLocalVariableIndex(id, name, 's')]; } - int InterpreterContext::getMemberLong(std::string_view id, std::string_view name, bool global) const + int InterpreterContext::getMemberLong(ESM::RefId id, std::string_view name, bool global) const { const Locals& locals = getMemberLocals(id, global); return locals.mLongs[findLocalVariableIndex(id, name, 'l')]; } - float InterpreterContext::getMemberFloat(std::string_view id, std::string_view name, bool global) const + float InterpreterContext::getMemberFloat(ESM::RefId id, std::string_view name, bool global) const { const Locals& locals = getMemberLocals(id, global); return locals.mFloats[findLocalVariableIndex(id, name, 'f')]; } - void InterpreterContext::setMemberShort(std::string_view id, std::string_view name, int value, bool global) + void InterpreterContext::setMemberShort(ESM::RefId id, std::string_view name, int value, bool global) { Locals& locals = getMemberLocals(id, global); locals.mShorts[findLocalVariableIndex(id, name, 's')] = value; } - void InterpreterContext::setMemberLong(std::string_view id, std::string_view name, int value, bool global) + void InterpreterContext::setMemberLong(ESM::RefId id, std::string_view name, int value, bool global) { Locals& locals = getMemberLocals(id, global); locals.mLongs[findLocalVariableIndex(id, name, 'l')] = value; } - void InterpreterContext::setMemberFloat(std::string_view id, std::string_view name, float value, bool global) + void InterpreterContext::setMemberFloat(ESM::RefId id, std::string_view name, float value, bool global) { Locals& locals = getMemberLocals(id, global); diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 89b8f626c0..31297ec24b 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -5,6 +5,7 @@ #include #include +#include #include "globalscripts.hpp" @@ -29,16 +30,16 @@ namespace MWScript /// If \a id is empty, a reference the script is run from is returned or in case /// of a non-local script the reference derived from the target ID. const MWWorld::Ptr getReferenceImp( - std::string_view id = {}, bool activeOnly = false, bool doThrow = true) const; + const ESM::RefId& id = ESM::RefId::sEmpty, bool activeOnly = false, bool doThrow = true) const; - const Locals& getMemberLocals(std::string_view& id, bool global) const; + const Locals& getMemberLocals(ESM::RefId& id, bool global) const; ///< \a id is changed to the respective script ID, if \a id wasn't a script ID before - Locals& getMemberLocals(std::string_view& id, bool global); + Locals& getMemberLocals(ESM::RefId& id, bool global); ///< \a id is changed to the respective script ID, if \a id wasn't a script ID before /// Throws an exception if local variable can't be found. - int findLocalVariableIndex(std::string_view scriptId, std::string_view name, char type) const; + int findLocalVariableIndex(const ESM::RefId& scriptId, std::string_view name, char type) const; public: InterpreterContext(std::shared_ptr globalScriptDesc); @@ -46,7 +47,7 @@ namespace MWScript InterpreterContext(MWScript::Locals* locals, const MWWorld::Ptr& reference); ///< The ownership of \a locals is not transferred. 0-pointer allowed. - std::string_view getTarget() const override; + const ESM::RefId& getTarget() const override; int getLocalShort(int index) const override; @@ -112,17 +113,17 @@ namespace MWScript void executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor); ///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled. - int getMemberShort(std::string_view id, std::string_view name, bool global) const override; + int getMemberShort(ESM::RefId id, std::string_view name, bool global) const override; - int getMemberLong(std::string_view id, std::string_view name, bool global) const override; + int getMemberLong(ESM::RefId id, std::string_view name, bool global) const override; - float getMemberFloat(std::string_view id, std::string_view name, bool global) const override; + float getMemberFloat(ESM::RefId id, std::string_view name, bool global) const override; - void setMemberShort(std::string_view id, std::string_view name, int value, bool global) override; + void setMemberShort(ESM::RefId id, std::string_view name, int value, bool global) override; - void setMemberLong(std::string_view id, std::string_view name, int value, bool global) override; + void setMemberLong(ESM::RefId id, std::string_view name, int value, bool global) override; - void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) override; + void setMemberFloat(ESM::RefId id, std::string_view name, float value, bool global) override; MWWorld::Ptr getReference(bool required = true) const; ///< Reference, that the script is running from (can be empty) diff --git a/apps/openmw/mwscript/locals.cpp b/apps/openmw/mwscript/locals.cpp index a89d1a3057..0f2d184b5d 100644 --- a/apps/openmw/mwscript/locals.cpp +++ b/apps/openmw/mwscript/locals.cpp @@ -15,7 +15,7 @@ namespace MWScript { - void Locals::ensure(std::string_view scriptName) + void Locals::ensure(const ESM::RefId& scriptName) { if (!mInitialised) { @@ -65,7 +65,7 @@ namespace MWScript return (mShorts.empty() && mLongs.empty() && mFloats.empty()); } - bool Locals::hasVar(std::string_view script, std::string_view var) + bool Locals::hasVar(const ESM::RefId& script, std::string_view var) { ensure(script); @@ -74,7 +74,7 @@ namespace MWScript return (index != -1); } - int Locals::getIntVar(std::string_view script, std::string_view var) + int Locals::getIntVar(const ESM::RefId& script, std::string_view var) { ensure(script); @@ -100,7 +100,7 @@ namespace MWScript return 0; } - float Locals::getFloatVar(std::string_view script, std::string_view var) + float Locals::getFloatVar(ESM::RefId& script, std::string_view var) { ensure(script); @@ -126,7 +126,7 @@ namespace MWScript return 0; } - bool Locals::setVarByInt(std::string_view script, std::string_view var, int val) + bool Locals::setVarByInt(const ESM::RefId& script, std::string_view var, int val) { ensure(script); @@ -154,7 +154,7 @@ namespace MWScript return false; } - bool Locals::write(ESM::Locals& locals, std::string_view script) const + bool Locals::write(ESM::Locals& locals, const ESM::RefId& script) const { if (!mInitialised) return false; @@ -207,7 +207,7 @@ namespace MWScript return true; } - void Locals::read(const ESM::Locals& locals, std::string_view script) + void Locals::read(const ESM::Locals& locals, const ESM::RefId& script) { ensure(script); diff --git a/apps/openmw/mwscript/locals.hpp b/apps/openmw/mwscript/locals.hpp index dfb8e32fac..211b7c2fa3 100644 --- a/apps/openmw/mwscript/locals.hpp +++ b/apps/openmw/mwscript/locals.hpp @@ -11,6 +11,7 @@ namespace ESM { class Script; struct Locals; + struct RefId; } namespace MWScript @@ -19,7 +20,7 @@ namespace MWScript { bool mInitialised; - void ensure(std::string_view scriptName); + void ensure(const ESM::RefId& scriptName); public: std::vector mShorts; @@ -39,33 +40,33 @@ namespace MWScript /// @note var needs to be in lowercase /// /// \note Locals will be automatically configured first, if necessary - bool setVarByInt(std::string_view script, std::string_view var, int val); + bool setVarByInt(const ESM::RefId& script, std::string_view var, int val); /// \note Locals will be automatically configured first, if necessary // // \note If it can not be determined if the variable exists, the error will be // ignored and false will be returned. - bool hasVar(std::string_view script, std::string_view var); + bool hasVar(const ESM::RefId& script, std::string_view var); /// if var does not exist, returns 0 /// @note var needs to be in lowercase /// /// \note Locals will be automatically configured first, if necessary - int getIntVar(std::string_view script, std::string_view var); + int getIntVar(const ESM::RefId& script, std::string_view var); /// if var does not exist, returns 0 /// @note var needs to be in lowercase /// /// \note Locals will be automatically configured first, if necessary - float getFloatVar(std::string_view script, std::string_view var); + float getFloatVar(ESM::RefId& script, std::string_view var); /// \note If locals have not been configured yet, no data is written. /// /// \return Locals written? - bool write(ESM::Locals& locals, std::string_view script) const; + bool write(ESM::Locals& locals, const ESM::RefId& script) const; /// \note Locals will be automatically configured first, if necessary - void read(const ESM::Locals& locals, std::string_view script); + void read(const ESM::Locals& locals, const ESM::RefId& script); }; } diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index aab205063b..da88dac501 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -75,7 +75,7 @@ namespace { - void addToLevList(ESM::LevelledListBase* list, std::string_view itemId, int level) + void addToLevList(ESM::LevelledListBase* list, const ESM::RefId& itemId, int level) { for (auto& levelItem : list->mList) { @@ -89,7 +89,7 @@ namespace list->mList.push_back(item); } - void removeFromLevList(ESM::LevelledListBase* list, std::string_view itemId, int level) + void removeFromLevList(ESM::LevelledListBase* list, const ESM::RefId& itemId, int level) { // level of -1 removes all items with that itemId for (std::vector::iterator it = list->mList.begin(); it != list->mList.end();) @@ -99,7 +99,7 @@ namespace ++it; continue; } - if (Misc::StringUtils::ciEqual(itemId, it->mId)) + if (ESM::RefId::ciEqual(itemId, it->mId)) it = list->mList.erase(it); else ++it; @@ -144,7 +144,7 @@ namespace MWScript void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr target = R()(runtime, false); - std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript(name, target); } @@ -155,7 +155,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); runtime.push(MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning(name)); } @@ -166,7 +166,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWBase::Environment::get().getScriptManager()->getGlobalScripts().removeScript(name); } @@ -567,10 +567,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view creature = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId creature = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view gem = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId gem = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); if (!ptr.getClass().hasInventoryStore(ptr)) @@ -599,7 +599,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view soul = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId soul = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); // throw away additional arguments @@ -612,7 +612,7 @@ namespace MWScript MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr); for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it) { - if (::Misc::StringUtils::ciEqual(it->getCellRef().getSoul(), soul)) + if (ESM::RefId::ciEqual(it->getCellRef().getSoul(), soul)) { store.remove(*it, 1, ptr); return; @@ -630,7 +630,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer amount = runtime[0].mInteger; @@ -655,7 +655,7 @@ namespace MWScript for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot) { MWWorld::ConstContainerStoreIterator it = store.getSlot(slot); - if (it != store.end() && ::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item)) + if (it != store.end() && ESM::RefId::ciEqual(it->getCellRef().getRefId(), item)) { numNotEquipped -= it->getRefData().getCount(); } @@ -664,7 +664,7 @@ namespace MWScript for (int slot = 0; slot < MWWorld::InventoryStore::Slots && amount > numNotEquipped; ++slot) { MWWorld::ContainerStoreIterator it = store.getSlot(slot); - if (it != store.end() && ::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item)) + if (it != store.end() && ESM::RefId::ciEqual(it->getCellRef().getRefId(), item)) { int numToRemove = std::min(amount - numNotEquipped, it->getRefData().getCount()); store.unequipItemQuantity(*it, ptr, numToRemove); @@ -674,13 +674,13 @@ namespace MWScript for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter) { - if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item) + if (ESM::RefId::ciEqual(iter->getCellRef().getRefId(), item) && !store.isEquipped(*iter)) { int removed = store.remove(*iter, amount, ptr); MWWorld::Ptr dropped = MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, removed); - dropped.getCellRef().setOwner(""); + dropped.getCellRef().setOwner(ESM::RefId::sEmpty); amount -= removed; @@ -720,7 +720,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - std::string_view soul = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId soul = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); if (!ptr.getClass().hasInventoryStore(ptr)) @@ -730,7 +730,7 @@ namespace MWScript for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter) { - if (::Misc::StringUtils::ciEqual(iter->getCellRef().getSoul(), soul)) + if (ESM::RefId::ciEqual(iter->getCellRef().getSoul(), soul)) { MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, 1); store.remove(*iter, 1, ptr); @@ -796,7 +796,7 @@ namespace MWScript void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); if (!ptr.getClass().isActor()) @@ -949,11 +949,11 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId objectID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); - bool hit = ::Misc::StringUtils::ciEqual(objectID, stats.getLastHitObject()); + bool hit = ESM::RefId::ciEqual(objectID, stats.getLastHitObject()); runtime.push(hit); if (hit) stats.clearLastHitObject(); @@ -968,11 +968,11 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId objectID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); - bool hit = ::Misc::StringUtils::ciEqual(objectID, stats.getLastHitAttemptObject()); + bool hit = ESM::RefId::ciEqual(objectID, stats.getLastHitAttemptObject()); runtime.push(hit); if (hit) stats.clearLastHitAttemptObject(); @@ -1015,13 +1015,13 @@ namespace MWScript if (!ptr.isEmpty()) { - std::string_view script = ptr.getClass().getScript(ptr); + ESM::RefId script = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); if (!script.empty()) { const Compiler::Locals& locals = MWBase::Environment::get().getScriptManager()->getLocals(script); char type = locals.getType(var); - std::string refId = ptr.getCellRef().getRefId(); + std::string refId = ptr.getCellRef().getRefId().getRefIdString(); if (refId.find(' ') != std::string::npos) refId = '"' + refId + '"'; switch (type) @@ -1069,7 +1069,7 @@ namespace MWScript { std::stringstream str; - std::string_view script = ptr.getClass().getScript(ptr); + const ESM::RefId& script = ptr.getClass().getScript(ptr); if (script.empty()) str << ptr.getCellRef().getRefId() << " does not have a script."; else @@ -1188,10 +1188,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId spellId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string targetId = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral(runtime[0].mInteger)); + ESM::RefId targetId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); const ESM::Spell* spell @@ -1199,7 +1199,7 @@ namespace MWScript if (!spell) { runtime.getContext().report( - "spellcasting failed: cannot find spell \"" + std::string(spellId) + "\""); + "spellcasting failed: cannot find spell \"" + spellId.getRefIdString() + "\""); return; } @@ -1239,7 +1239,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId spellId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); const ESM::Spell* spell @@ -1247,7 +1247,7 @@ namespace MWScript if (!spell) { runtime.getContext().report( - "spellcasting failed: cannot find spell \"" + std::string(spellId) + "\""); + "spellcasting failed: cannot find spell \"" + spellId.getRefIdString() + "\""); return; } @@ -1410,9 +1410,9 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& levId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& creatureId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); @@ -1429,9 +1429,9 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& levId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& creatureId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); @@ -1448,9 +1448,9 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& levId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& itemId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); @@ -1467,9 +1467,9 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& levId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId& itemId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); diff --git a/apps/openmw/mwscript/ref.cpp b/apps/openmw/mwscript/ref.cpp index c61eb64780..af6b205d37 100644 --- a/apps/openmw/mwscript/ref.cpp +++ b/apps/openmw/mwscript/ref.cpp @@ -9,7 +9,7 @@ MWWorld::Ptr MWScript::ExplicitRef::operator()(Interpreter::Runtime& runtime, bool required, bool activeOnly) const { - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); if (required) diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index f17b1a1c50..9108fd8581 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -8,6 +8,7 @@ #include #include +#include #include @@ -41,14 +42,14 @@ namespace MWScript std::sort(mScriptBlacklist.begin(), mScriptBlacklist.end()); } - bool ScriptManager::compile(std::string_view name) + bool ScriptManager::compile(const ESM::RefId& name) { mParser.reset(); mErrorHandler.reset(); if (const ESM::Script* script = mStore.get().find(name)) { - mErrorHandler.setContext(script->mId); + mErrorHandler.setContext(script->mId.getRefIdString()); bool Success = true; try @@ -91,7 +92,7 @@ namespace MWScript return false; } - bool ScriptManager::run(std::string_view name, Interpreter::Context& interpreterContext) + bool ScriptManager::run(const ESM::RefId& name, Interpreter::Context& interpreterContext) { // compile script auto iter = mScripts.find(name); @@ -111,7 +112,7 @@ namespace MWScript } // execute script - std::string target = Misc::StringUtils::lowerCase(interpreterContext.getTarget()); + auto target = interpreterContext.getTarget(); if (!iter->second.mByteCode.empty() && iter->second.mInactive.find(target) == iter->second.mInactive.end()) try { @@ -155,7 +156,7 @@ namespace MWScript for (auto& script : mStore.get()) { if (!std::binary_search( - mScriptBlacklist.begin(), mScriptBlacklist.end(), Misc::StringUtils::lowerCase(script.mId))) + mScriptBlacklist.begin(), mScriptBlacklist.end(), Misc::StringUtils::lowerCase(script.mId.getRefIdString()))) { ++count; @@ -167,7 +168,7 @@ namespace MWScript return std::make_pair(count, success); } - const Compiler::Locals& ScriptManager::getLocals(std::string_view name) + const Compiler::Locals& ScriptManager::getLocals(const ESM::RefId& name) { { auto iter = mScripts.find(name); @@ -187,7 +188,7 @@ namespace MWScript { Compiler::Locals locals; - const Compiler::ContextOverride override(mErrorHandler, std::string{ name } + "[local variables]"); + const Compiler::ContextOverride override(mErrorHandler, std::string{ name.getRefIdString() } + "[local variables]"); std::istringstream stream(script->mScriptText); Compiler::QuickFileParser parser(mErrorHandler, mCompilerContext, locals); @@ -212,7 +213,7 @@ namespace MWScript return iter->second; } - throw std::logic_error("script " + std::string{ name } + " does not exist"); + throw std::logic_error("script " + std::string{ name.getRefIdString() } + " does not exist"); } GlobalScripts& ScriptManager::getGlobalScripts() diff --git a/apps/openmw/mwscript/scriptmanagerimp.hpp b/apps/openmw/mwscript/scriptmanagerimp.hpp index 7355edf240..961b62f014 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.hpp +++ b/apps/openmw/mwscript/scriptmanagerimp.hpp @@ -11,6 +11,8 @@ #include #include +#include + #include "../mwbase/scriptmanager.hpp" #include "globalscripts.hpp" @@ -46,7 +48,7 @@ namespace MWScript { std::vector mByteCode; Compiler::Locals mLocals; - std::set mInactive; + std::set mInactive; CompiledScript(const std::vector& code, const Compiler::Locals& locals) : mByteCode(code) @@ -55,10 +57,10 @@ namespace MWScript } }; - std::unordered_map + std::unordered_map mScripts; GlobalScripts mGlobalScripts; - std::unordered_map + std::unordered_map mOtherLocals; std::vector mScriptBlacklist; @@ -68,10 +70,10 @@ namespace MWScript void clear() override; - bool run(std::string_view name, Interpreter::Context& interpreterContext) override; + bool run(const ESM::RefId& name, Interpreter::Context& interpreterContext) override; ///< Run the script with the given name (compile first, if not compiled yet) - bool compile(std::string_view name) override; + bool compile(const ESM::RefId& name) override; ///< Compile script with the given namen /// \return Success? @@ -79,7 +81,7 @@ namespace MWScript ///< Compile all scripts /// \return count, success - const Compiler::Locals& getLocals(std::string_view name) override; + const Compiler::Locals& getLocals(const ESM::RefId& name) override; ///< Return locals for script \a name. GlobalScripts& getGlobalScripts() override; diff --git a/apps/openmw/mwscript/skyextensions.cpp b/apps/openmw/mwscript/skyextensions.cpp index 26cb1fabca..84d2ca532b 100644 --- a/apps/openmw/mwscript/skyextensions.cpp +++ b/apps/openmw/mwscript/skyextensions.cpp @@ -81,7 +81,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view region{ runtime.getStringLiteral(runtime[0].mInteger) }; + ESM::RefId region = ESM::RefId::stringRefId( runtime.getStringLiteral(runtime[0].mInteger) ); runtime.pop(); Interpreter::Type_Integer id = runtime[0].mInteger; @@ -92,7 +92,7 @@ namespace MWScript if (reg) MWBase::Environment::get().getWorld()->changeWeather(region, id); else - runtime.getContext().report("Warning: Region \"" + std::string(region) + "\" was not found"); + runtime.getContext().report("Warning: Region \"" + region.getRefIdString() + "\" was not found"); } }; @@ -113,7 +113,7 @@ namespace MWScript arg0--; } - MWBase::Environment::get().getWorld()->modRegion(region, chances); + MWBase::Environment::get().getWorld()->modRegion(ESM::RefId::stringRefId(region), chances); } }; diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index 8ea1e89a23..957331d2cb 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -74,7 +74,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId sound = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWBase::Environment::get().getSoundManager()->playSound( @@ -87,7 +87,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId sound = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Float volume = runtime[0].mFloat; @@ -109,7 +109,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId sound = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, 1.0, 1.0, MWSound::Type::Sfx, @@ -125,7 +125,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId sound = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Float volume = runtime[0].mFloat; @@ -147,7 +147,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId sound = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWBase::Environment::get().getSoundManager()->stopSound3D(ptr, sound); @@ -166,7 +166,7 @@ namespace MWScript runtime.pop(); bool ret = MWBase::Environment::get().getSoundManager()->getSoundPlaying( - ptr, runtime.getStringLiteral(index)); + ptr, ESM::RefId::stringRefId(runtime.getStringLiteral(index))); // GetSoundPlaying called on an equipped item should also look for sounds played by the equipping actor. if (!ret && ptr.getContainerStore()) @@ -177,7 +177,7 @@ namespace MWScript && cont.getClass().getInventoryStore(cont).isEquipped(ptr)) { ret = MWBase::Environment::get().getSoundManager()->getSoundPlaying( - cont, runtime.getStringLiteral(index)); + cont, ESM::RefId::stringRefId(runtime.getStringLiteral(index))); } } diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index b80a7b40f1..a071aadba0 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -33,9 +33,9 @@ namespace { - std::string_view getDialogueActorFaction(const MWWorld::ConstPtr& actor) + const ESM::RefId& getDialogueActorFaction(const MWWorld::ConstPtr& actor) { - std::string_view factionId = actor.getClass().getPrimaryFaction(actor); + const ESM::RefId& factionId = actor.getClass().getPrimaryFaction(actor); if (factionId.empty()) throw std::runtime_error("failed to determine dialogue actors faction (because actor is factionless)"); @@ -255,7 +255,7 @@ namespace MWScript runtime.pop(); // workaround broken endgame scripts that kill dagoth ur - if (!R::implicit && ::Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), "dagoth_ur_1")) + if (!R::implicit && ESM::RefId::ciEqual(ptr.getCellRef().getRefId(), ESM::RefId::stringRefId("dagoth_ur_1"))) { runtime.push(peek); @@ -460,7 +460,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(id); @@ -486,7 +486,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); @@ -509,7 +509,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view spellid = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId spellid = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); ptr.getClass().getCreatureStats(ptr).getActiveSpells().removeEffects(ptr, spellid); @@ -540,7 +540,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer value = 0; @@ -560,7 +560,7 @@ namespace MWScript { MWWorld::ConstPtr actor = R()(runtime, false); - std::string_view factionID; + ESM::RefId factionID; if (arg0 == 0) { @@ -568,7 +568,7 @@ namespace MWScript } else { - factionID = runtime.getStringLiteral(runtime[0].mInteger); + factionID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } // Make sure this faction exists @@ -590,7 +590,7 @@ namespace MWScript { MWWorld::ConstPtr actor = R()(runtime, false); - std::string_view factionID; + ESM::RefId factionID; if (arg0 == 0) { @@ -598,7 +598,7 @@ namespace MWScript } else { - factionID = runtime.getStringLiteral(runtime[0].mInteger); + factionID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } // Make sure this faction exists @@ -627,7 +627,7 @@ namespace MWScript { MWWorld::ConstPtr actor = R()(runtime, false); - std::string_view factionID; + ESM::RefId factionID; if (arg0 == 0) { @@ -635,7 +635,7 @@ namespace MWScript } else { - factionID = runtime.getStringLiteral(runtime[0].mInteger); + factionID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } // Make sure this faction exists @@ -657,10 +657,10 @@ namespace MWScript { MWWorld::ConstPtr ptr = R()(runtime, false); - std::string_view factionID; + ESM::RefId factionID; if (arg0 > 0) { - factionID = runtime.getStringLiteral(runtime[0].mInteger); + factionID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } else @@ -737,7 +737,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string id{ runtime.getStringLiteral(runtime[0].mInteger) }; + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime[0].mInteger = MWBase::Environment::get().getMechanicsManager()->countDeaths(id); } }; @@ -750,11 +750,11 @@ namespace MWScript { MWWorld::ConstPtr ptr = R()(runtime, false); - std::string_view factionId; + ESM::RefId factionId; if (arg0 == 1) { - factionId = runtime.getStringLiteral(runtime[0].mInteger); + factionId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } else @@ -781,11 +781,11 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - std::string_view factionId; + ESM::RefId factionId; if (arg0 == 1) { - factionId = runtime.getStringLiteral(runtime[0].mInteger); + factionId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } else @@ -812,11 +812,11 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - std::string_view factionId; + ESM::RefId factionId; if (arg0 == 1) { - factionId = runtime.getStringLiteral(runtime[0].mInteger); + factionId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } else @@ -865,12 +865,12 @@ namespace MWScript { MWWorld::ConstPtr ptr = R()(runtime); - std::string_view race = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId race = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); - const std::string& npcRace = ptr.get()->mBase->mRace; + const ESM::RefId& npcRace = ptr.get()->mBase->mRace; - runtime.push(::Misc::StringUtils::ciEqual(race, npcRace)); + runtime.push(ESM::RefId::ciEqual(race, npcRace)); } }; @@ -893,10 +893,10 @@ namespace MWScript { MWWorld::ConstPtr ptr = R()(runtime, false); - std::string_view factionID; + ESM::RefId factionID; if (arg0 > 0) { - factionID = runtime.getStringLiteral(runtime[0].mInteger); + factionID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } else @@ -923,10 +923,10 @@ namespace MWScript { MWWorld::ConstPtr ptr = R()(runtime, false); - std::string_view factionID; + ESM::RefId factionID; if (arg0 > 0) { - factionID = runtime.getStringLiteral(runtime[0].mInteger); + factionID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } else @@ -949,10 +949,10 @@ namespace MWScript { MWWorld::ConstPtr ptr = R()(runtime, false); - std::string_view factionID; + ESM::RefId factionID; if (arg0 > 0) { - factionID = runtime.getStringLiteral(runtime[0].mInteger); + factionID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); } else @@ -973,7 +973,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view factionID = ptr.getClass().getPrimaryFaction(ptr); + ESM::RefId factionID = ptr.getClass().getPrimaryFaction(ptr); if (factionID.empty()) return; @@ -1007,7 +1007,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string_view factionID = ptr.getClass().getPrimaryFaction(ptr); + ESM::RefId factionID = ptr.getClass().getPrimaryFaction(ptr); if (factionID.empty()) return; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 1dc84022df..0768cfaf5b 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -45,7 +45,7 @@ namespace MWScript void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr from = R()(runtime, !R::implicit); - std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId name = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); if (from.isEmpty()) @@ -66,7 +66,7 @@ namespace MWScript else { std::string error - = "Failed to find the container of object '" + from.getCellRef().getRefId() + "'"; + = "Failed to find the container of object '" + from.getCellRef().getRefId().getRefIdString() + "'"; runtime.getContext().report(error); Log(Debug::Error) << error; runtime.push(0.f); @@ -77,7 +77,7 @@ namespace MWScript const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->searchPtr(name, false); if (to.isEmpty()) { - std::string error = "Failed to find an instance of object '" + std::string(name) + "'"; + std::string error = "Failed to find an instance of object '" + name.getRefIdString() + "'"; runtime.getContext().report(error); Log(Debug::Error) << error; runtime.push(0.f); @@ -502,7 +502,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); + const ESM::RefId itemID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); @@ -554,7 +554,7 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId itemID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Float x = runtime[0].mFloat; @@ -602,7 +602,7 @@ namespace MWScript { MWWorld::Ptr actor = pc ? MWMechanics::getPlayer() : R()(runtime); - std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); + ESM::RefId itemID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer count = runtime[0].mInteger; diff --git a/apps/openmw/mwsound/regionsoundselector.cpp b/apps/openmw/mwsound/regionsoundselector.cpp index fd5f6f521c..ba876c4fe7 100644 --- a/apps/openmw/mwsound/regionsoundselector.cpp +++ b/apps/openmw/mwsound/regionsoundselector.cpp @@ -26,8 +26,8 @@ namespace MWSound { } - std::optional RegionSoundSelector::getNextRandom( - float duration, const std::string& regionName, const MWBase::World& world) + std::optional RegionSoundSelector::getNextRandom( + float duration, const ESM::RefId& regionName, const MWBase::World& world) { mTimePassed += duration; diff --git a/apps/openmw/mwsound/regionsoundselector.hpp b/apps/openmw/mwsound/regionsoundselector.hpp index 586c3b07ea..e1fa688471 100644 --- a/apps/openmw/mwsound/regionsoundselector.hpp +++ b/apps/openmw/mwsound/regionsoundselector.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace MWBase { @@ -14,15 +15,15 @@ namespace MWSound class RegionSoundSelector { public: - std::optional getNextRandom( - float duration, const std::string& regionName, const MWBase::World& world); + std::optional getNextRandom( + float duration, const ESM::RefId& regionName, const MWBase::World& world); RegionSoundSelector(); private: float mTimeToNextEnvSound = 0.0f; int mSumChance = 0; - std::string mLastRegionName; + ESM::RefId mLastRegionName; float mTimePassed = 0.0; float mMinTimeBetweenSounds; float mMaxTimeBetweenSounds; diff --git a/apps/openmw/mwsound/sound_buffer.cpp b/apps/openmw/mwsound/sound_buffer.cpp index 0a1058f16e..db24b3c45d 100644 --- a/apps/openmw/mwsound/sound_buffer.cpp +++ b/apps/openmw/mwsound/sound_buffer.cpp @@ -52,7 +52,7 @@ namespace MWSound clear(); } - Sound_Buffer* SoundBufferPool::lookup(const std::string& soundId) const + Sound_Buffer* SoundBufferPool::lookup(const ESM::RefId& soundId) const { const auto it = mBufferNameMap.find(soundId); if (it != mBufferNameMap.end()) @@ -64,12 +64,12 @@ namespace MWSound return nullptr; } - Sound_Buffer* SoundBufferPool::load(const std::string& soundId) + Sound_Buffer* SoundBufferPool::load(const ESM::RefId& soundId) { if (mBufferNameMap.empty()) { for (const ESM::Sound& sound : MWBase::Environment::get().getWorld()->getStore().get()) - insertSound(Misc::StringUtils::lowerCase(sound.mId), sound); + insertSound(sound.mId, sound); } Sound_Buffer* sfx; @@ -117,7 +117,7 @@ namespace MWSound mUnusedBuffers.clear(); } - Sound_Buffer* SoundBufferPool::insertSound(const std::string& soundId, const ESM::Sound& sound) + Sound_Buffer* SoundBufferPool::insertSound(const ESM::RefId& soundId, const ESM::Sound& sound) { static const AudioParams audioParams = makeAudioParams(*MWBase::Environment::get().getWorld()); diff --git a/apps/openmw/mwsound/sound_buffer.hpp b/apps/openmw/mwsound/sound_buffer.hpp index 1b9960eded..ca201954a4 100644 --- a/apps/openmw/mwsound/sound_buffer.hpp +++ b/apps/openmw/mwsound/sound_buffer.hpp @@ -7,6 +7,7 @@ #include #include "sound_output.hpp" +#include namespace ESM { @@ -66,11 +67,11 @@ namespace MWSound /// Lookup a soundId for its sound data (resource name, local volume, /// minRange, and maxRange) - Sound_Buffer* lookup(const std::string& soundId) const; + Sound_Buffer* lookup(const ESM::RefId& soundId) const; /// Lookup a soundId for its sound data (resource name, local volume, /// minRange, and maxRange), and ensure it's ready for use. - Sound_Buffer* load(const std::string& soundId); + Sound_Buffer* load(const ESM::RefId& soundId); void use(Sound_Buffer& sfx) { @@ -94,14 +95,14 @@ namespace MWSound const VFS::Manager* const mVfs; Sound_Output* mOutput; std::deque mSoundBuffers; - std::unordered_map mBufferNameMap; + std::unordered_map mBufferNameMap; std::size_t mBufferCacheMax; std::size_t mBufferCacheMin; std::size_t mBufferCacheSize = 0; // NOTE: unused buffers are stored in front-newest order. std::deque mUnusedBuffers; - inline Sound_Buffer* insertSound(const std::string& soundId, const ESM::Sound& sound); + inline Sound_Buffer* insertSound(const ESM::RefId& soundId, const ESM::Sound& sound); inline void unloadUnused(); }; diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index c19908b255..7f14eb7aa9 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -46,9 +46,9 @@ namespace MWSound settings.mNearWaterIndoorTolerance = Fallback::Map::getFloat("Water_NearWaterIndoorTolerance"); settings.mNearWaterOutdoorTolerance = Fallback::Map::getFloat("Water_NearWaterOutdoorTolerance"); settings.mNearWaterIndoorID - = Misc::StringUtils::lowerCase(Fallback::Map::getString("Water_NearWaterIndoorID")); + = ESM::RefId::stringRefId(Fallback::Map::getString("Water_NearWaterIndoorID")); settings.mNearWaterOutdoorID - = Misc::StringUtils::lowerCase(Fallback::Map::getString("Water_NearWaterOutdoorID")); + = ESM::RefId::stringRefId(Fallback::Map::getString("Water_NearWaterOutdoorID")); return settings; } @@ -496,12 +496,12 @@ namespace MWSound } Sound* SoundManager::playSound( - std::string_view soundId, float volume, float pitch, Type type, PlayMode mode, float offset) + const ESM::RefId& soundId, float volume, float pitch, Type type, PlayMode mode, float offset) { if (!mOutput->isInitialized()) return nullptr; - Sound_Buffer* sfx = mSoundBuffers.load(Misc::StringUtils::lowerCase(soundId)); + Sound_Buffer* sfx = mSoundBuffers.load(soundId); if (!sfx) return nullptr; @@ -526,7 +526,7 @@ namespace MWSound return result; } - Sound* SoundManager::playSound3D(const MWWorld::ConstPtr& ptr, std::string_view soundId, float volume, float pitch, + Sound* SoundManager::playSound3D(const MWWorld::ConstPtr& ptr, const ESM::RefId& soundId, float volume, float pitch, Type type, PlayMode mode, float offset) { if (!mOutput->isInitialized()) @@ -538,7 +538,7 @@ namespace MWSound return nullptr; // Look up the sound in the ESM data - Sound_Buffer* sfx = mSoundBuffers.load(Misc::StringUtils::lowerCase(soundId)); + Sound_Buffer* sfx = mSoundBuffers.load(soundId); if (!sfx) return nullptr; @@ -587,14 +587,14 @@ namespace MWSound return result; } - Sound* SoundManager::playSound3D(const osg::Vec3f& initialPos, std::string_view soundId, float volume, float pitch, + Sound* SoundManager::playSound3D(const osg::Vec3f& initialPos, const ESM::RefId& soundId, float volume, float pitch, Type type, PlayMode mode, float offset) { if (!mOutput->isInitialized()) return nullptr; // Look up the sound in the ESM data - Sound_Buffer* sfx = mSoundBuffers.load(Misc::StringUtils::lowerCase(soundId)); + Sound_Buffer* sfx = mSoundBuffers.load(soundId); if (!sfx) return nullptr; @@ -641,12 +641,12 @@ namespace MWSound } } - void SoundManager::stopSound3D(const MWWorld::ConstPtr& ptr, std::string_view soundId) + void SoundManager::stopSound3D(const MWWorld::ConstPtr& ptr, const ESM::RefId& soundId) { if (!mOutput->isInitialized()) return; - Sound_Buffer* sfx = mSoundBuffers.lookup(Misc::StringUtils::lowerCase(soundId)); + Sound_Buffer* sfx = mSoundBuffers.lookup(soundId); if (!sfx) return; @@ -693,12 +693,12 @@ namespace MWSound } } - void SoundManager::fadeOutSound3D(const MWWorld::ConstPtr& ptr, std::string_view soundId, float duration) + void SoundManager::fadeOutSound3D(const MWWorld::ConstPtr& ptr, const ESM::RefId& soundId, float duration) { SoundMap::iterator snditer = mActiveSounds.find(ptr.mRef); if (snditer != mActiveSounds.end()) { - Sound_Buffer* sfx = mSoundBuffers.lookup(Misc::StringUtils::lowerCase(soundId)); + Sound_Buffer* sfx = mSoundBuffers.lookup(soundId); if (sfx == nullptr) return; for (SoundBufferRefPair& sndbuf : snditer->second.mList) @@ -709,12 +709,12 @@ namespace MWSound } } - bool SoundManager::getSoundPlaying(const MWWorld::ConstPtr& ptr, std::string_view soundId) const + bool SoundManager::getSoundPlaying(const MWWorld::ConstPtr& ptr, const ESM::RefId& soundId) const { SoundMap::const_iterator snditer = mActiveSounds.find(ptr.mRef); if (snditer != mActiveSounds.end()) { - Sound_Buffer* sfx = mSoundBuffers.lookup(Misc::StringUtils::lowerCase(soundId)); + Sound_Buffer* sfx = mSoundBuffers.lookup(soundId); return std::find_if(snditer->second.mList.cbegin(), snditer->second.mList.cend(), [this, sfx](const SoundBufferRefPair& snd) -> bool { return snd.second == sfx && mOutput->isSoundPlaying(snd.first.get()); @@ -1006,7 +1006,7 @@ namespace MWSound { // Play underwater sound (after updating sounds) if (!mUnderwaterSound) - mUnderwaterSound = playSound("Underwater", 1.0f, 1.0f, Type::Sfx, PlayMode::LoopNoEnv); + mUnderwaterSound = playSound(ESM::RefId::stringRefId("Underwater"), 1.0f, 1.0f, Type::Sfx, PlayMode::LoopNoEnv); } mOutput->finishUpdate(); } diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 64ff8117fb..60c1bec632 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -211,18 +211,18 @@ namespace MWSound /// returned by \ref playTrack). Only intended to be called by the track /// decoder's read method. - Sound* playSound(std::string_view soundId, float volume, float pitch, Type type = Type::Sfx, + Sound* playSound(const ESM::RefId& soundId, float volume, float pitch, Type type = Type::Sfx, PlayMode mode = PlayMode::Normal, float offset = 0) override; ///< Play a sound, independently of 3D-position ///< @param offset Number of seconds into the sound to start playback. - Sound* playSound3D(const MWWorld::ConstPtr& reference, std::string_view soundId, float volume, float pitch, + Sound* playSound3D(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId, float volume, float pitch, Type type = Type::Sfx, PlayMode mode = PlayMode::Normal, float offset = 0) override; ///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless ///< Play_NoTrack is specified. ///< @param offset Number of seconds into the sound to start playback. - Sound* playSound3D(const osg::Vec3f& initialPos, std::string_view soundId, float volume, float pitch, Type type, + Sound* playSound3D(const osg::Vec3f& initialPos, const ESM::RefId& soundId, float volume, float pitch, Type type, PlayMode mode, float offset = 0) override; ///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using ///< Sound::setPosition. @@ -232,7 +232,7 @@ namespace MWSound ///< Stop the given sound from playing /// @note no-op if \a sound is null - void stopSound3D(const MWWorld::ConstPtr& reference, std::string_view soundId) override; + void stopSound3D(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId) override; ///< Stop the given object from playing the given sound, void stopSound3D(const MWWorld::ConstPtr& reference) override; @@ -241,13 +241,13 @@ namespace MWSound void stopSound(const MWWorld::CellStore* cell) override; ///< Stop all sounds for the given cell. - void fadeOutSound3D(const MWWorld::ConstPtr& reference, std::string_view soundId, float duration) override; + void fadeOutSound3D(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId, float duration) override; ///< Fade out given sound (that is already playing) of given object ///< @param reference Reference to object, whose sound is faded out ///< @param soundId ID of the sound to fade out. ///< @param duration Time until volume reaches 0. - bool getSoundPlaying(const MWWorld::ConstPtr& reference, std::string_view soundId) const override; + bool getSoundPlaying(const MWWorld::ConstPtr& reference, const ESM::RefId& soundId) const override; ///< Is the given sound currently playing on the given object? void pauseSounds(MWSound::BlockerType blocker, int types = int(Type::Mask)) override; diff --git a/apps/openmw/mwsound/watersoundupdater.hpp b/apps/openmw/mwsound/watersoundupdater.hpp index 3994cb4af5..68ab54cf52 100644 --- a/apps/openmw/mwsound/watersoundupdater.hpp +++ b/apps/openmw/mwsound/watersoundupdater.hpp @@ -2,6 +2,7 @@ #define GAME_SOUND_WATERSOUNDUPDATER_H #include +#include "components/esm/refid.hpp" namespace MWBase { @@ -21,13 +22,13 @@ namespace MWSound int mNearWaterPoints; float mNearWaterIndoorTolerance; float mNearWaterOutdoorTolerance; - std::string mNearWaterIndoorID; - std::string mNearWaterOutdoorID; + ESM::RefId mNearWaterIndoorID; + ESM::RefId mNearWaterOutdoorID; }; struct WaterSoundUpdate { - std::string mId; + ESM::RefId mId; float mVolume; }; diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 51a7c1f68a..6f5c63d3a8 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -216,13 +216,13 @@ void MWState::StateManager::saveGame(const std::string& description, const Slot* profile.mPlayerName = player.get()->mBase->mName; profile.mPlayerLevel = player.getClass().getNpcStats(player).getLevel(); - const std::string& classId = player.get()->mBase->mClass; + const ESM::RefId& classId = player.get()->mBase->mClass; if (world.getStore().get().isDynamic(classId)) profile.mPlayerClassName = world.getStore().get().find(classId)->mName; else profile.mPlayerClassId = classId; - profile.mPlayerCell = world.getCellName(); + profile.mPlayerCell = ESM::RefId::stringRefId(world.getCellName()); profile.mInGameTime = world.getEpochTimeStamp(); profile.mTimePlayed = mTimePlayed; profile.mDescription = description; diff --git a/apps/openmw/mwworld/action.cpp b/apps/openmw/mwworld/action.cpp index ce73039ca5..474a4d0e84 100644 --- a/apps/openmw/mwworld/action.cpp +++ b/apps/openmw/mwworld/action.cpp @@ -58,7 +58,7 @@ void MWWorld::Action::execute(const Ptr& actor, bool noSound) executeImp(actor); } -void MWWorld::Action::setSound(std::string_view id) +void MWWorld::Action::setSound(const ESM::RefId& id) { mSoundId = id; } diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp index 01e036c0ba..56c8fd8b5b 100644 --- a/apps/openmw/mwworld/action.hpp +++ b/apps/openmw/mwworld/action.hpp @@ -11,7 +11,7 @@ namespace MWWorld /// \brief Abstract base for actions class Action { - std::string mSoundId; + ESM::RefId mSoundId; bool mKeepSound; float mSoundOffset; Ptr mTarget; @@ -38,7 +38,7 @@ namespace MWWorld void execute(const Ptr& actor, bool noSound = false); - void setSound(std::string_view id); + void setSound(const ESM::RefId& id); void setSoundOffset(float offset); }; } diff --git a/apps/openmw/mwworld/actionapply.cpp b/apps/openmw/mwworld/actionapply.cpp index fd33322a4a..17c4474727 100644 --- a/apps/openmw/mwworld/actionapply.cpp +++ b/apps/openmw/mwworld/actionapply.cpp @@ -6,7 +6,7 @@ namespace MWWorld { - ActionApply::ActionApply(const Ptr& object, const std::string& id) + ActionApply::ActionApply(const Ptr& object, const ESM::RefId& id) : Action(false, object) , mId(id) { @@ -17,7 +17,7 @@ namespace MWWorld actor.getClass().consume(getTarget(), actor); } - ActionApplyWithSkill::ActionApplyWithSkill(const Ptr& object, const std::string& id, int skillIndex, int usageType) + ActionApplyWithSkill::ActionApplyWithSkill(const Ptr& object, const ESM::RefId& id, int skillIndex, int usageType) : Action(false, object) , mId(id) , mSkillIndex(skillIndex) diff --git a/apps/openmw/mwworld/actionapply.hpp b/apps/openmw/mwworld/actionapply.hpp index 02862bd3f3..34990c39a5 100644 --- a/apps/openmw/mwworld/actionapply.hpp +++ b/apps/openmw/mwworld/actionapply.hpp @@ -2,31 +2,31 @@ #define GAME_MWWORLD_ACTIONAPPLY_H #include - +#include #include "action.hpp" namespace MWWorld { class ActionApply : public Action { - std::string mId; + ESM::RefId mId; void executeImp(const Ptr& actor) override; public: - ActionApply(const Ptr& object, const std::string& id); + ActionApply(const Ptr& object, const ESM::RefId& id); }; class ActionApplyWithSkill : public Action { - std::string mId; + ESM::RefId mId; int mSkillIndex; int mUsageType; void executeImp(const Ptr& actor) override; public: - ActionApplyWithSkill(const Ptr& object, const std::string& id, int skillIndex, int usageType); + ActionApplyWithSkill(const Ptr& object, const ESM::RefId& id, int skillIndex, int usageType); }; } diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp index 666811936d..0edcd77ae9 100644 --- a/apps/openmw/mwworld/actionequip.cpp +++ b/apps/openmw/mwworld/actionequip.cpp @@ -62,7 +62,7 @@ namespace MWWorld } if (it == invStore.end()) - throw std::runtime_error("ActionEquip can't find item " + object.getCellRef().getRefId()); + throw std::runtime_error("ActionEquip can't find item " + object.getCellRef().getRefId().getRefIdString()); // equip the item in the first free slot std::vector::const_iterator slot = slots_.first.begin(); diff --git a/apps/openmw/mwworld/actionharvest.cpp b/apps/openmw/mwworld/actionharvest.cpp index e14bd43aac..20f88e83e4 100644 --- a/apps/openmw/mwworld/actionharvest.cpp +++ b/apps/openmw/mwworld/actionharvest.cpp @@ -19,7 +19,7 @@ namespace MWWorld ActionHarvest::ActionHarvest(const MWWorld::Ptr& container) : Action(true, container) { - setSound("Item Ingredient Up"); + setSound(ESM::RefId::stringRefId("Item Ingredient Up")); } void ActionHarvest::executeImp(const MWWorld::Ptr& actor) diff --git a/apps/openmw/mwworld/actionsoulgem.cpp b/apps/openmw/mwworld/actionsoulgem.cpp index 187f399e09..e0daf00f1a 100644 --- a/apps/openmw/mwworld/actionsoulgem.cpp +++ b/apps/openmw/mwworld/actionsoulgem.cpp @@ -31,7 +31,7 @@ namespace MWWorld } const auto& target = getTarget(); - const std::string& targetSoul = target.getCellRef().getSoul(); + const ESM::RefId& targetSoul = target.getCellRef().getSoul(); if (targetSoul.empty()) { diff --git a/apps/openmw/mwworld/actionteleport.cpp b/apps/openmw/mwworld/actionteleport.cpp index 613fa631a6..195eaff43d 100644 --- a/apps/openmw/mwworld/actionteleport.cpp +++ b/apps/openmw/mwworld/actionteleport.cpp @@ -77,7 +77,7 @@ namespace MWWorld { MWWorld::Ptr follower = *it; - std::string_view script = follower.getClass().getScript(follower); + const ESM::RefId& script = follower.getClass().getScript(follower); if (!includeHostiles && follower.getClass().getCreatureStats(follower).getAiSequence().isInCombat(actor)) continue; diff --git a/apps/openmw/mwworld/actiontrap.cpp b/apps/openmw/mwworld/actiontrap.cpp index e7dd0d98f9..518f9b87f6 100644 --- a/apps/openmw/mwworld/actiontrap.cpp +++ b/apps/openmw/mwworld/actiontrap.cpp @@ -31,6 +31,6 @@ namespace MWWorld cast.mHitPosition = actorPosition; cast.cast(mSpellId); } - mTrapSource.getCellRef().setTrap(""); + mTrapSource.getCellRef().setTrap(ESM::RefId::sEmpty); } } diff --git a/apps/openmw/mwworld/actiontrap.hpp b/apps/openmw/mwworld/actiontrap.hpp index 6119856708..02200db6bf 100644 --- a/apps/openmw/mwworld/actiontrap.hpp +++ b/apps/openmw/mwworld/actiontrap.hpp @@ -9,7 +9,7 @@ namespace MWWorld { class ActionTrap : public Action { - std::string mSpellId; + ESM::RefId mSpellId; MWWorld::Ptr mTrapSource; void executeImp(const Ptr& actor) override; @@ -17,7 +17,7 @@ namespace MWWorld public: /// @param spellId /// @param trapSource - ActionTrap(const std::string& spellId, const Ptr& trapSource) + ActionTrap(const ESM::RefId& spellId, const Ptr& trapSource) : Action(false, trapSource) , mSpellId(spellId) , mTrapSource(trapSource) diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index b18e4b5a66..d0395916ed 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -127,7 +127,7 @@ namespace MWWorld } } - void CellRef::setOwner(const std::string& owner) + void CellRef::setOwner(const ESM::RefId& owner) { if (owner != mCellRef.mOwner) { @@ -136,7 +136,7 @@ namespace MWWorld } } - void CellRef::setSoul(std::string_view soul) + void CellRef::setSoul(const ESM::RefId& soul) { if (soul != mCellRef.mSoul) { @@ -145,7 +145,7 @@ namespace MWWorld } } - void CellRef::setFaction(const std::string& faction) + void CellRef::setFaction(const ESM::RefId& faction) { if (faction != mCellRef.mFaction) { @@ -176,7 +176,7 @@ namespace MWWorld setLockLevel(-abs(mCellRef.mLockLevel)); // Makes lockLevel negative } - void CellRef::setTrap(const std::string& trap) + void CellRef::setTrap(const ESM::RefId& trap) { if (trap != mCellRef.mTrap) { diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp index e8fa03a093..d21eb218eb 100644 --- a/apps/openmw/mwworld/cellref.hpp +++ b/apps/openmw/mwworld/cellref.hpp @@ -37,7 +37,7 @@ namespace MWWorld bool hasContentFile() const { return mCellRef.mRefNum.hasContentFile(); } // Id of object being referenced - const std::string& getRefId() const { return mCellRef.mRefID; } + const ESM::RefId& getRefId() const { return mCellRef.mRefID; } // For doors - true if this door teleports to somewhere else, false // if it should open through animation. @@ -76,8 +76,8 @@ namespace MWWorld void applyChargeRemainderToBeSubtracted(float chargeRemainder); // Stores remainders and applies if > 1 // The NPC that owns this object (and will get angry if you steal it) - const std::string& getOwner() const { return mCellRef.mOwner; } - void setOwner(const std::string& owner); + const ESM::RefId& getOwner() const { return mCellRef.mOwner; } + void setOwner(const ESM::RefId&owner); // Name of a global variable. If the global variable is set to '1', using the object is temporarily allowed // even if it has an Owner field. @@ -87,13 +87,13 @@ namespace MWWorld void resetGlobalVariable(); // ID of creature trapped in this soul gem - const std::string& getSoul() const { return mCellRef.mSoul; } - void setSoul(std::string_view soul); + const ESM::RefId& getSoul() const { return mCellRef.mSoul; } + void setSoul(const ESM::RefId& soul); // The faction that owns this object (and will get angry if // you take it and are not a faction member) - const std::string& getFaction() const { return mCellRef.mFaction; } - void setFaction(const std::string& faction); + const ESM::RefId& getFaction() const { return mCellRef.mFaction; } + void setFaction(const ESM::RefId& faction); // PC faction rank required to use the item. Sometimes is -1, which means "any rank". void setFactionRank(int factionRank); @@ -107,9 +107,9 @@ namespace MWWorld void lock(int lockLevel); void unlock(); // Key and trap ID names, if any - const std::string& getKey() const { return mCellRef.mKey; } - const std::string& getTrap() const { return mCellRef.mTrap; } - void setTrap(const std::string& trap); + const ESM::RefId& getKey() const { return mCellRef.mKey; } + const ESM::RefId& getTrap() const { return mCellRef.mTrap; } + void setTrap(const ESM::RefId& trap); // This is 5 for Gold_005 references, 100 for Gold_100 and so on. int getGoldValue() const { return mCellRef.mGoldValue; } diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index a93377bca4..4cdbfc9a4e 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -90,9 +90,9 @@ namespace }; template - MWWorld::Ptr searchInContainerList(MWWorld::CellRefList& containerList, std::string_view id) + MWWorld::Ptr searchInContainerList(MWWorld::CellRefList& containerList, const ESM::RefId& id) { - for (typename MWWorld::CellRefList::List::iterator iter(containerList.mList.begin()); + for (auto iter(containerList.mList.begin()); iter != containerList.mList.end(); ++iter) { MWWorld::Ptr container(&*iter, nullptr); @@ -169,7 +169,7 @@ namespace { for (auto& item : state.mInventory.mItems) { - if (item.mCount > 0 && Misc::StringUtils::ciEqual(baseItem.mItem, item.mRef.mRefID)) + if (item.mCount > 0 && ESM::RefId::ciEqual(baseItem.mItem, item.mRef.mRefID)) item.mCount = -item.mCount; } } @@ -526,7 +526,7 @@ namespace MWWorld return mState; } - const std::vector& CellStore::getPreloadedIds() const + const std::vector& CellStore::getPreloadedIds() const { return mIds; } @@ -536,7 +536,7 @@ namespace MWWorld return mHasState; } - bool CellStore::hasId(std::string_view id) const + bool CellStore::hasId(const ESM::RefId& id) const { if (mState == State_Unloaded) return false; @@ -551,7 +551,8 @@ namespace MWWorld struct SearchVisitor { PtrType mFound; - std::string_view mIdToFind; + const ESM::RefId& mIdToFind; + SearchVisitor(const ESM::RefId& id) : mIdToFind(id) {} bool operator()(const PtrType& ptr) { if (ptr.getCellRef().getRefId() == mIdToFind) @@ -563,18 +564,16 @@ namespace MWWorld } }; - Ptr CellStore::search(std::string_view id) + Ptr CellStore::search(const ESM::RefId& id) { - SearchVisitor searchVisitor; - searchVisitor.mIdToFind = id; + SearchVisitor searchVisitor(id); forEach(searchVisitor); return searchVisitor.mFound; } - ConstPtr CellStore::searchConst(std::string_view id) const + ConstPtr CellStore::searchConst(const ESM::RefId& id) const { - SearchVisitor searchVisitor; - searchVisitor.mIdToFind = id; + SearchVisitor searchVisitor(id); forEachConst(searchVisitor); return searchVisitor.mFound; } @@ -708,7 +707,6 @@ namespace MWWorld continue; } - Misc::StringUtils::lowerCaseInPlace(ref.mRefID); mIds.push_back(std::move(ref.mRefID)); } } @@ -723,7 +721,7 @@ namespace MWWorld for (const auto& [ref, deleted] : mCell->mLeasedRefs) { if (!deleted) - mIds.push_back(Misc::StringUtils::lowerCase(ref.mRefID)); + mIds.push_back(ref.mRefID); } std::sort(mIds.begin(), mIds.end()); @@ -736,7 +734,7 @@ namespace MWWorld if (mCell->mContextList.empty()) return; // this is a dynamically generated cell -> skipping. - std::map refNumToID; // used to detect refID modifications + std::map refNumToID; // used to detect refID modifications // Load references from all plugins that do something with this cell. for (size_t i = 0; i < mCell->mContextList.size(); i++) @@ -802,7 +800,7 @@ namespace MWWorld return (mCell->mData.mFlags & ESM::Cell::QuasiEx) != 0; } - Ptr CellStore::searchInContainer(std::string_view id) + Ptr CellStore::searchInContainer(const ESM::RefId& id) { bool oldState = mHasState; @@ -822,13 +820,11 @@ namespace MWWorld return Ptr(); } - void CellStore::loadRef(ESM::CellRef& ref, bool deleted, std::map& refNumToID) + void CellStore::loadRef(ESM::CellRef& ref, bool deleted, std::map& refNumToID) { - Misc::StringUtils::lowerCaseInPlace(ref.mRefID); - const MWWorld::ESMStore& store = mStore; - std::map::iterator it = refNumToID.find(ref.mRefNum); + auto it = refNumToID.find(ref.mRefNum); if (it != refNumToID.end()) { if (it->second != ref.mRefID) @@ -858,13 +854,13 @@ namespace MWWorld } else { - Log(Debug::Error) << "Cell reference '" + ref.mRefID + "' not found!"; + Log(Debug::Error) << "Cell reference '" + ref.mRefID.getRefIdString() + "' not found!"; return; } if (!handledType) { - Log(Debug::Error) << "Error: Ignoring reference '" << ref.mRefID << "' of unhandled type"; + Log(Debug::Error) << "Error: Ignoring reference '" << ref.mRefID.getRefIdString() << "' of unhandled type"; return; } @@ -1200,7 +1196,7 @@ namespace MWWorld void MWWorld::CellStore::checkItem(const Ptr& ptr) { - std::string_view enchantmentId = ptr.getClass().getEnchantment(ptr); + const ESM::RefId& enchantmentId = ptr.getClass().getEnchantment(ptr); if (enchantmentId.empty()) return; diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index dc0d6140c3..c59a06f150 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -15,6 +15,7 @@ #include "livecellref.hpp" #include +#include #include #include "ptr.hpp" @@ -87,7 +88,7 @@ namespace MWWorld const ESM::Cell* mCell; State mState; bool mHasState; - std::vector mIds; + std::vector mIds; float mWaterLevel; MWWorld::TimeStamp mLastRespawn; @@ -187,24 +188,24 @@ namespace MWWorld State getState() const; - const std::vector& getPreloadedIds() const; + const std::vector& getPreloadedIds() const; ///< Get Ids of objects in this cell, only valid in State_Preloaded bool hasState() const; ///< Does this cell have state that needs to be stored in a saved game file? - bool hasId(std::string_view id) const; + bool hasId(const ESM::RefId& id) const; ///< May return true for deleted IDs when in preload state. Will return false, if cell is /// unloaded. /// @note Will not account for moved references which may exist in Loaded state. Use search() instead if the /// cell is loaded. - Ptr search(std::string_view id); + Ptr search(const ESM::RefId& id); ///< Will return an empty Ptr if cell is not loaded. Does not check references in /// containers. /// @note Triggers CellStore hasState flag. - ConstPtr searchConst(std::string_view id) const; + ConstPtr searchConst(const ESM::RefId& id) const; ///< Will return an empty Ptr if cell is not loaded. Does not check references in /// containers. /// @note Does not trigger CellStore hasState flag. @@ -335,7 +336,7 @@ namespace MWWorld bool isQuasiExterior() const; - Ptr searchInContainer(std::string_view id); + Ptr searchInContainer(const ESM::RefId& id); void loadState(const ESM::CellState& state); @@ -371,7 +372,7 @@ namespace MWWorld void loadRefs(); - void loadRef(ESM::CellRef& ref, bool deleted, std::map& refNumToID); + void loadRef(ESM::CellRef& ref, bool deleted, std::map& refNumToID); ///< Make case-adjustments to \a ref and insert it into the respective container. /// /// Invalid \a ref objects are silently dropped. diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 0798d72e11..49bdc65168 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -167,9 +167,9 @@ namespace MWWorld return -1; } - std::string_view Class::getScript(const ConstPtr& ptr) const + const ESM::RefId& Class::getScript(const ConstPtr& ptr) const { - return {}; + return ESM::RefId::sEmpty; } float Class::getMaxSpeed(const Ptr& ptr) const @@ -263,17 +263,17 @@ namespace MWWorld getClasses().emplace(instance.getType(), &instance); } - std::string_view Class::getUpSoundId(const ConstPtr& ptr) const + const ESM::RefId& Class::getUpSoundId(const ConstPtr& ptr) const { throw std::runtime_error("class does not have an up sound"); } - std::string_view Class::getDownSoundId(const ConstPtr& ptr) const + const ESM::RefId& Class::getDownSoundId(const ConstPtr& ptr) const { throw std::runtime_error("class does not have an down sound"); } - std::string_view Class::getSoundIdFromSndGen(const Ptr& ptr, std::string_view type) const + const ESM::RefId& Class::getSoundIdFromSndGen(const Ptr& ptr, std::string_view type) const { throw std::runtime_error("class does not support soundgen look up"); } @@ -293,7 +293,7 @@ namespace MWWorld // NOTE: Don't show WerewolfRobe objects in the inventory, or allow them to be taken. // Vanilla likely uses a hack like this since there's no other way to prevent it from // being shown or taken. - return (ptr.getCellRef().getRefId() != "werewolfrobe"); + return (ptr.getCellRef().getRefId() != ESM::RefId::stringRefId("werewolfrobe")); } bool Class::hasToolTip(const ConstPtr& ptr) const @@ -301,9 +301,9 @@ namespace MWWorld return true; } - std::string_view Class::getEnchantment(const ConstPtr& ptr) const + const ESM::RefId& Class::getEnchantment(const ConstPtr& ptr) const { - return {}; + return ESM::RefId::sEmpty; } void Class::adjustScale(const MWWorld::ConstPtr& ptr, osg::Vec3f& scale, bool rendering) const {} @@ -325,8 +325,8 @@ namespace MWWorld models.push_back(model); } - const std::string& Class::applyEnchantment( - const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const ESM::RefId& Class::applyEnchantment( + const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const { throw std::runtime_error("class can't be enchanted"); } @@ -347,7 +347,7 @@ namespace MWWorld { const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); auto& prng = MWBase::Environment::get().getWorld()->getPrng(); - const ESM::Sound* sound = store.get().searchRandom("WolfItem", prng); + const ESM::Sound* sound = store.get().searchRandom(ESM::RefId::stringRefId("WolfItem"), prng); std::unique_ptr action = std::make_unique("#{sWerewolfRefusal}"); if (sound) @@ -471,9 +471,9 @@ namespace MWWorld return encumbrance / capacity; } - std::string_view Class::getSound(const MWWorld::ConstPtr&) const + const ESM::RefId& Class::getSound(const MWWorld::ConstPtr&) const { - return {}; + return ESM::RefId::sEmpty; } int Class::getBaseFightRating(const ConstPtr& ptr) const @@ -481,9 +481,9 @@ namespace MWWorld throw std::runtime_error("class does not support fight rating"); } - std::string_view Class::getPrimaryFaction(const MWWorld::ConstPtr& ptr) const + const ESM::RefId& Class::getPrimaryFaction(const MWWorld::ConstPtr& ptr) const { - return {}; + return ESM::RefId::sEmpty; } int Class::getPrimaryFactionRank(const MWWorld::ConstPtr& ptr) const { @@ -498,7 +498,7 @@ namespace MWWorld osg::Vec4f Class::getEnchantmentColor(const MWWorld::ConstPtr& item) const { osg::Vec4f result(1, 1, 1, 1); - std::string_view enchantmentName = item.getClass().getEnchantment(item); + const ESM::RefId& enchantmentName = item.getClass().getEnchantment(item); if (enchantmentName.empty()) return result; @@ -521,12 +521,12 @@ namespace MWWorld return result; } - void Class::setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const + void Class::setBaseAISetting(const ESM::RefId&, MWMechanics::AiSetting setting, int value) const { throw std::runtime_error("class does not have creature stats"); } - void Class::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const + void Class::modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const { throw std::runtime_error("class does not have an inventory store"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index a48cf90e4b..c933b3c251 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -13,6 +13,7 @@ #include "ptr.hpp" #include "../mwmechanics/aisetting.hpp" +#include namespace ESM { @@ -178,7 +179,7 @@ namespace MWWorld ///< Returns the remaining duration of the object, such as an equippable light /// source. (default implementation: -1, i.e. infinite) - virtual std::string_view getScript(const ConstPtr& ptr) const; + virtual const ESM::RefId& getScript(const ConstPtr& ptr) const; ///< Return name of the script attached to ptr (default implementation: return an empty /// string). @@ -243,15 +244,15 @@ namespace MWWorld /// /// (default implementation: return false) - virtual std::string_view getUpSoundId(const ConstPtr& ptr) const; + virtual const ESM::RefId& getUpSoundId(const ConstPtr& ptr) const; ///< Return the up sound ID of \a ptr or throw an exception, if class does not support ID retrieval /// (default implementation: throw an exception) - virtual std::string_view getDownSoundId(const ConstPtr& ptr) const; + virtual const ESM::RefId& getDownSoundId(const ConstPtr& ptr) const; ///< Return the down sound ID of \a ptr or throw an exception, if class does not support ID retrieval /// (default implementation: throw an exception) - virtual std::string_view getSoundIdFromSndGen(const Ptr& ptr, std::string_view type) const; + virtual const ESM::RefId& getSoundIdFromSndGen(const Ptr& ptr, std::string_view type) const; ///< Returns the sound ID for \a ptr of the given soundgen \a type. virtual float getArmorRating(const MWWorld::Ptr& ptr) const; @@ -260,7 +261,7 @@ namespace MWWorld virtual const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const; ///< Return name of inventory icon. - virtual std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const; + virtual const ESM::RefId& getEnchantment(const MWWorld::ConstPtr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string /// (default implementation: return empty string) @@ -284,8 +285,8 @@ namespace MWWorld ///< Get a list of models to preload that this object may use (directly or indirectly). default implementation: ///< list getModel(). - virtual const std::string& applyEnchantment( - const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + virtual const ESM::RefId& applyEnchantment( + const MWWorld::ConstPtr& ptr, const ESM::RefId& enchId, int enchCharge, const std::string& newName) const; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. virtual std::pair canBeEquipped( @@ -355,11 +356,11 @@ namespace MWWorld virtual void respawn(const MWWorld::Ptr& ptr) const {} /// Returns sound id - virtual std::string_view getSound(const MWWorld::ConstPtr& ptr) const; + virtual const ESM::RefId& getSound(const MWWorld::ConstPtr& ptr) const; virtual int getBaseFightRating(const MWWorld::ConstPtr& ptr) const; - virtual std::string_view getPrimaryFaction(const MWWorld::ConstPtr& ptr) const; + virtual const ESM::RefId& getPrimaryFaction(const MWWorld::ConstPtr& ptr) const; virtual int getPrimaryFactionRank(const MWWorld::ConstPtr& ptr) const; /// Get the effective armor rating, factoring in the actor's skills, for the given armor. @@ -367,9 +368,9 @@ namespace MWWorld virtual osg::Vec4f getEnchantmentColor(const MWWorld::ConstPtr& item) const; - virtual void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const; + virtual void setBaseAISetting(const ESM::RefId& id, MWMechanics::AiSetting setting, int value) const; - virtual void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const; + virtual void modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) const; }; } diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 36e214d7f3..e21817ab80 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -30,7 +30,7 @@ namespace auto& scripts = MWBase::Environment::get().getWorld()->getLocalScripts(); for (const auto&& ptr : store) { - std::string_view script = ptr.getClass().getScript(ptr); + auto script = ptr.getClass().getScript(ptr); if (!script.empty()) { MWWorld::Ptr item = ptr; @@ -55,13 +55,13 @@ namespace } template - MWWorld::Ptr searchId(MWWorld::CellRefList& list, std::string_view id, MWWorld::ContainerStore* store) + MWWorld::Ptr searchId(MWWorld::CellRefList& list, const ESM::RefId& id, MWWorld::ContainerStore* store) { store->resolve(); for (MWWorld::LiveCellRef& liveCellRef : list.mList) { - if (Misc::StringUtils::ciEqual(liveCellRef.mBase->mId, id) && liveCellRef.mData.getCount()) + if (ESM::RefId::ciEqual(liveCellRef.mBase->mId, id) && liveCellRef.mData.getCount()) { MWWorld::Ptr ptr(&liveCellRef, nullptr); ptr.setContainerStore(store); @@ -137,7 +137,7 @@ void MWWorld::ContainerStore::storeStates( } } -const std::string_view MWWorld::ContainerStore::sGoldId = "gold_001"; +const ESM::RefId MWWorld::ContainerStore::sGoldId = ESM::RefId::stringRefId("gold_001"); MWWorld::ContainerStore::ContainerStore() : mListener(nullptr) @@ -183,11 +183,11 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end() return ContainerStoreIterator(this); } -int MWWorld::ContainerStore::count(std::string_view id) const +int MWWorld::ContainerStore::count(const ESM::RefId& id) const { int total = 0; for (const auto&& iter : *this) - if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefId(), id)) + if (ESM::RefId::ciEqual(iter.getCellRef().getRefId(), id)) total += iter.getRefData().getCount(); return total; } @@ -208,7 +208,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::unstack(const Ptr& ptr, if (ptr.getRefData().getCount() <= count) return end(); MWWorld::ContainerStoreIterator it = addNewStack(ptr, subtractItems(ptr.getRefData().getCount(false), count)); - std::string_view script = it->getClass().getScript(*it); + const ESM::RefId& script = it->getClass().getScript(*it); if (!script.empty()) MWBase::Environment::get().getWorld()->getLocalScripts().add(script, *it); @@ -252,7 +252,7 @@ bool MWWorld::ContainerStore::stacks(const ConstPtr& ptr1, const ConstPtr& ptr2) const MWWorld::Class& cls1 = ptr1.getClass(); const MWWorld::Class& cls2 = ptr2.getClass(); - if (!Misc::StringUtils::ciEqual(ptr1.getCellRef().getRefId(), ptr2.getCellRef().getRefId())) + if (!ESM::RefId::ciEqual(ptr1.getCellRef().getRefId(), ptr2.getCellRef().getRefId())) return false; // If it has an enchantment, don't stack when some of the charge is already used @@ -285,7 +285,7 @@ bool MWWorld::ContainerStore::stacks(const ConstPtr& ptr1, const ConstPtr& ptr2) && cls2.getItemHealth(ptr2) == cls2.getItemMaxHealth(ptr2))); } -MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(std::string_view id, int count, const Ptr& actorPtr) +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(const ESM::RefId& id, int count, const Ptr& actorPtr) { MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id, count); return add(ref.getPtr(), count, actorPtr); @@ -314,16 +314,16 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add( item.getCellRef().setPosition(pos); // We do not need to store owners for items in container stores - we do not use it anyway. - item.getCellRef().setOwner(""); + item.getCellRef().setOwner(ESM::RefId::sEmpty); item.getCellRef().resetGlobalVariable(); - item.getCellRef().setFaction(""); + item.getCellRef().setFaction(ESM::RefId::sEmpty); item.getCellRef().setFactionRank(-2); // must reset the RefNum on the copied item, so that the RefNum on the original item stays unique // maybe we should do this in the copy constructor instead? item.getCellRef().unsetRefNum(); // destroy link to content file - std::string_view script = item.getClass().getScript(item); + const ESM::RefId& script = item.getClass().getScript(item); if (!script.empty()) { if (actorPtr == player) @@ -372,7 +372,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImp(const Ptr& ptr, for (MWWorld::ContainerStoreIterator iter(begin(type)); iter != end(); ++iter) { - if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) + if (ESM::RefId::ciEqual(iter->getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId)) { iter->getRefData().setCount(addItems(iter->getRefData().getCount(false), realCount)); flagAsModified(); @@ -485,7 +485,7 @@ void MWWorld::ContainerStore::updateRechargingItems() mRechargingItems.clear(); for (ContainerStoreIterator it = begin(); it != end(); ++it) { - std::string_view enchantmentId = it->getClass().getEnchantment(*it); + auto enchantmentId = it->getClass().getEnchantment(*it); if (!enchantmentId.empty()) { const ESM::Enchantment* enchantment @@ -505,14 +505,14 @@ void MWWorld::ContainerStore::updateRechargingItems() } int MWWorld::ContainerStore::remove( - std::string_view itemId, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst) + const ESM::RefId& itemId, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst) { if (resolveFirst) resolve(); int toRemove = count; for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter) - if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId)) + if (ESM::RefId::ciEqual(iter->getCellRef().getRefId(), itemId)) toRemove -= remove(*iter, toRemove, actor, equipReplacement, resolveFirst); flagAsModified(); @@ -564,12 +564,11 @@ int MWWorld::ContainerStore::remove( } void MWWorld::ContainerStore::fill( - const ESM::InventoryList& items, const std::string& owner, Misc::Rng::Generator& prng) + const ESM::InventoryList& items, const ESM::RefId& owner, Misc::Rng::Generator& prng) { for (const ESM::ContItem& iter : items.mList) { - std::string id = Misc::StringUtils::lowerCase(iter.mItem); - addInitialItem(id, owner, iter.mCount, &prng); + addInitialItem(iter.mItem, owner, iter.mCount, &prng); } flagAsModified(); @@ -577,13 +576,12 @@ void MWWorld::ContainerStore::fill( } void MWWorld::ContainerStore::fillNonRandom( - const ESM::InventoryList& items, const std::string& owner, unsigned int seed) + const ESM::InventoryList& items, const ESM::RefId& owner, unsigned int seed) { mSeed = seed; for (const ESM::ContItem& iter : items.mList) { - std::string id = Misc::StringUtils::lowerCase(iter.mItem); - addInitialItem(id, owner, iter.mCount, nullptr); + addInitialItem(iter.mItem, owner, iter.mCount, nullptr); } flagAsModified(); @@ -591,7 +589,7 @@ void MWWorld::ContainerStore::fillNonRandom( } void MWWorld::ContainerStore::addInitialItem( - std::string_view id, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel) + const ESM::RefId& id, const ESM::RefId& owner, int count, Misc::Rng::Generator* prng, bool topLevel) { if (count == 0) return; // Don't restock with nothing. @@ -616,7 +614,7 @@ void MWWorld::ContainerStore::addInitialItem( } void MWWorld::ContainerStore::addInitialItemImp( - const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel) + const MWWorld::Ptr& ptr, const ESM::RefId& owner, int count, Misc::Rng::Generator* prng, bool topLevel) { if (ptr.getType() == ESM::ItemLevList::sRecordId) { @@ -632,7 +630,7 @@ void MWWorld::ContainerStore::addInitialItemImp( } else { - std::string_view itemId = MWMechanics::getLevelledItem(ptr.get()->mBase, false, *prng); + auto itemId = MWMechanics::getLevelledItem(ptr.get()->mBase, false, *prng); if (itemId.empty()) return; addInitialItem(itemId, owner, count, prng, false); @@ -672,7 +670,7 @@ void MWWorld::ContainerStore::resolve() for (const auto&& ptr : *this) ptr.getRefData().setCount(0); Misc::Rng::Generator prng{ mSeed }; - fill(mPtr.get()->mBase->mInventory, "", prng); + fill(mPtr.get()->mBase->mInventory, ESM::RefId::sEmpty, prng); addScripts(*this, mPtr.mCell); } mModified = true; @@ -693,7 +691,7 @@ MWWorld::ResolutionHandle MWWorld::ContainerStore::resolveTemporarily() for (const auto&& ptr : *this) ptr.getRefData().setCount(0); Misc::Rng::Generator prng{ mSeed }; - fill(mPtr.get()->mBase->mInventory, "", prng); + fill(mPtr.get()->mBase->mInventory, ESM::RefId::sEmpty, prng); addScripts(*this, mPtr.mCell); } return { listener }; @@ -708,7 +706,7 @@ void MWWorld::ContainerStore::unresolve() { for (const auto&& ptr : *this) ptr.getRefData().setCount(0); - fillNonRandom(mPtr.get()->mBase->mInventory, "", mSeed); + fillNonRandom(mPtr.get()->mBase->mInventory, ESM::RefId::sEmpty, mSeed); addScripts(*this, mPtr.mCell); mResolved = false; } @@ -780,18 +778,18 @@ int MWWorld::ContainerStore::getType(const ConstPtr& ptr) if (ptr.getType() == ESM::Weapon::sRecordId) return Type_Weapon; - throw std::runtime_error("Object '" + ptr.getCellRef().getRefId() + "' of type " + throw std::runtime_error("Object '" + ptr.getCellRef().getRefId().getRefIdString() + "' of type " + std::string(ptr.getTypeDescription()) + " can not be placed into a container"); } -MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const std::string& id) +MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const ESM::RefId& id) { MWWorld::Ptr item; int itemHealth = 1; for (auto&& iter : *this) { int iterHealth = iter.getClass().hasItemHealth(iter) ? iter.getClass().getItemHealth(iter) : 1; - if (Misc::StringUtils::ciEqual(iter.getCellRef().getRefId(), id)) + if (ESM::RefId::ciEqual(iter.getCellRef().getRefId(), id)) { // Prefer the stack with the lowest remaining uses // Try to get item with zero durability only if there are no other items found @@ -806,7 +804,7 @@ MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const std::string& id) return item; } -MWWorld::Ptr MWWorld::ContainerStore::search(std::string_view id) +MWWorld::Ptr MWWorld::ContainerStore::search(const ESM::RefId& id) { resolve(); { diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 486993c308..a8f825f19d 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -97,7 +97,7 @@ namespace MWWorld static constexpr int Type_All = 0xffff; - static const std::string_view sGoldId; + static const ESM::RefId sGoldId; protected: ContainerStoreListener* mListener; @@ -133,8 +133,8 @@ namespace MWWorld ContainerStoreIterator addImp(const Ptr& ptr, int count, bool markModified = true); void addInitialItem( - std::string_view id, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel = true); - void addInitialItemImp(const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Generator* prng, + const ESM::RefId& id, const ESM::RefId& owner, int count, Misc::Rng::Generator* prng, bool topLevel = true); + void addInitialItemImp(const MWWorld::Ptr& ptr, const ESM::RefId& owner, int count, Misc::Rng::Generator* prng, bool topLevel = true); template @@ -184,11 +184,11 @@ namespace MWWorld /// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to /// the newly inserted item. - ContainerStoreIterator add(std::string_view id, int count, const Ptr& actorPtr); + ContainerStoreIterator add(const ESM::RefId& id, int count, const Ptr& actorPtr); ///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true) int remove( - std::string_view itemId, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true); + const ESM::RefId& itemId, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true); ///< Remove \a count item(s) designated by \a itemId from this container. /// /// @return the number of items actually removed @@ -213,7 +213,7 @@ namespace MWWorld /// If a compatible stack is found, the item's count is added to that stack, then the original is deleted. /// @return If the item was stacked, return the stack, otherwise return the old (untouched) item. - int count(std::string_view id) const; + int count(const ESM::RefId& id) const; ///< @return How many items with refID \a id are in this container? ContainerStoreListener* getContListener() const; @@ -234,10 +234,10 @@ namespace MWWorld virtual bool stacks(const ConstPtr& ptr1, const ConstPtr& ptr2) const; ///< @return true if the two specified objects can stack with each other - void fill(const ESM::InventoryList& items, const std::string& owner, Misc::Rng::Generator& seed); + void fill(const ESM::InventoryList& items, const ESM::RefId& owner, Misc::Rng::Generator& seed); ///< Insert items into *this. - void fillNonRandom(const ESM::InventoryList& items, const std::string& owner, unsigned int seed); + void fillNonRandom(const ESM::InventoryList& items, const ESM::RefId& owner, unsigned int seed); ///< Insert items into *this, excluding leveled items virtual void clear(); @@ -250,10 +250,10 @@ namespace MWWorld ///< This function throws an exception, if ptr does not point to an object, that can be /// put into a container. - Ptr findReplacement(const std::string& id); + Ptr findReplacement(const ESM::RefId& id); ///< Returns replacement for object with given id. Prefer used items (with low durability left). - Ptr search(std::string_view id); + Ptr search(const ESM::RefId& id); virtual void writeState(ESM::InventoryState& state) const; diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 520b60abf6..06a111ebef 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -34,8 +34,8 @@ namespace constexpr std::size_t deletedRefID = std::numeric_limits::max(); - void readRefs(const ESM::Cell& cell, std::vector& refs, std::vector& refIDs, - std::set& keyIDs, ESM::ReadersCache& readers) + void readRefs(const ESM::Cell& cell, std::vector& refs, std::vector& refIDs, + std::set& keyIDs, ESM::ReadersCache& readers) { // TODO: we have many similar copies of this code. for (size_t i = 0; i < cell.mContextList.size(); i++) @@ -74,7 +74,7 @@ namespace } } - const std::string& getDefaultClass(const MWWorld::Store& classes) + const ESM::RefId& getDefaultClass(const MWWorld::Store& classes) { auto it = classes.begin(); if (it != classes.end()) @@ -84,10 +84,10 @@ namespace std::vector getNPCsToReplace(const MWWorld::Store& factions, const MWWorld::Store& classes, - const std::unordered_map& npcs) + const std::unordered_map& npcs) { // Cache first class from store - we will use it if current class is not found - const std::string& defaultCls = getDefaultClass(classes); + const ESM::RefId& defaultCls = getDefaultClass(classes); // Validate NPCs for non-existing class and faction. // We will replace invalid entries by fixed ones @@ -98,7 +98,7 @@ namespace ESM::NPC npc = npcIter.second; bool changed = false; - const std::string& npcFaction = npc.mFaction; + const ESM::RefId& npcFaction = npc.mFaction; if (!npcFaction.empty()) { const ESM::Faction* fact = factions.search(npcFaction); @@ -112,7 +112,7 @@ namespace } } - const std::string& npcClass = npc.mClass; + const ESM::RefId& npcClass = npc.mClass; const ESM::Class* cls = classes.search(npcClass); if (!cls) { @@ -148,7 +148,7 @@ namespace namespace MWWorld { - using IDMap = std::unordered_map; + using IDMap = std::unordered_map; struct ESMStoreImp { @@ -183,7 +183,7 @@ namespace MWWorld } }; - int ESMStore::find(const std::string_view id) const + int ESMStore::find(const ESM::RefId& id) const { IDMap::const_iterator it = mStoreImp->mIds.find(id); if (it == mStoreImp->mIds.end()) @@ -193,7 +193,7 @@ namespace MWWorld return it->second; } - int ESMStore::findStatic(const std::string_view id) const + int ESMStore::findStatic(const ESM::RefId& id) const { IDMap::const_iterator it = mStoreImp->mStaticIds.find(id); if (it == mStoreImp->mStaticIds.end()) @@ -339,7 +339,7 @@ namespace MWWorld } } - void ESMStore::setIdType(const std::string& id, ESM::RecNameInts type) + void ESMStore::setIdType(const ESM::RefId& id, ESM::RecNameInts type) { mStoreImp->mIds[id] = type; } @@ -384,18 +384,17 @@ namespace MWWorld if (isCacheableRecord(storeIt->first)) { - std::vector identifiers; + std::vector identifiers; storeIt->second->listIdentifier(identifiers); - for (std::vector::const_iterator record = identifiers.begin(); record != identifiers.end(); - ++record) - mStoreImp->mIds[*record] = storeIt->first; + for (auto& record : identifiers) + mStoreImp->mIds[record] = storeIt->first; } } if (mStoreImp->mStaticIds.empty()) for (const auto& [k, v] : mStoreImp->mIds) - mStoreImp->mStaticIds.emplace(Misc::StringUtils::lowerCase(k), v); + mStoreImp->mStaticIds.emplace(k, v); getWritable().setUp(); getWritable().setUp(); @@ -417,8 +416,8 @@ namespace MWWorld if (!mRefCount.empty()) return; std::vector refs; - std::vector refIDs; - std::set keyIDs; + std::set keyIDs; + std::vector refIDs; Store Cells = get(); for (auto it = Cells.intBegin(); it != Cells.intEnd(); ++it) readRefs(*it, refs, refIDs, keyIDs, readers); @@ -430,9 +429,9 @@ namespace MWWorld const auto incrementRefCount = [&](const Ref& value) { if (value.mRefID != deletedRefID) { - std::string& refId = refIDs[value.mRefID]; + ESM::RefId& refId = refIDs[value.mRefID]; // We manually lower case IDs here for the time being to improve performance. - Misc::StringUtils::lowerCaseInPlace(refId); + Misc::StringUtils::lowerCaseInPlace(refId.getRefIdString()); ++mRefCount[std::move(refId)]; } }; @@ -446,10 +445,9 @@ namespace MWWorld } } - int ESMStore::getRefCount(std::string_view id) const + int ESMStore::getRefCount(const ESM::RefId& id) const { - const std::string lowerId = Misc::StringUtils::lowerCase(id); - auto it = mRefCount.find(lowerId); + auto it = mRefCount.find(id); if (it == mRefCount.end()) return 0; return it->second; @@ -537,7 +535,7 @@ namespace MWWorld void ESMStore::movePlayerRecord() { auto& npcs = getWritable(); - auto player = npcs.find("player"); + auto player = npcs.find(ESM::RefId::stringRefId("player")); npcs.insert(*player); } @@ -654,13 +652,13 @@ namespace MWWorld { setUp(); - const ESM::NPC* player = get().find("player"); + const ESM::NPC* player = get().find(ESM::RefId::stringRefId("player")); if (!get().find(player->mRace) || !get().find(player->mClass)) throw std::runtime_error("Invalid player record (race or class unavailable"); } - std::pair, bool> ESMStore::getSpellList(const std::string& id) const + std::pair, bool> ESMStore::getSpellList(const ESM::RefId& id) const { auto result = mSpellListCache.find(id); std::shared_ptr ptr; @@ -690,14 +688,14 @@ namespace MWWorld { auto& npcs = getWritable(); - if (Misc::StringUtils::ciEqual(npc.mId, "player")) + if (ESM::RefId::ciEqual(npc.mId, ESM::RefId::stringRefId("player"))) { return npcs.insert(npc); } - const std::string id = "$dynamic" + std::to_string(mDynamicCount++); + const ESM::RefId id = ESM::RefId::stringRefId("$dynamic" + std::to_string(mDynamicCount++)); if (npcs.search(id) != nullptr) { - const std::string msg = "Try to override existing record '" + id + "'"; + const std::string msg = "Try to override existing record '" + id.getRefIdString() + "'"; throw std::runtime_error(msg); } ESM::NPC record = npc; diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index a4a714af91..883316abc9 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -105,15 +106,14 @@ namespace MWWorld std::unique_ptr mStoreImp; - std::unordered_map mRefCount; + std::unordered_map mRefCount; std::vector mStores; std::vector mDynamicStores; unsigned int mDynamicCount; - mutable std::unordered_map, Misc::StringUtils::CiHash, - Misc::StringUtils::CiEqual> + mutable std::unordered_map> mSpellListCache; template @@ -130,7 +130,7 @@ namespace MWWorld template void removeMissingObjects(Store& store); - void setIdType(const std::string& id, ESM::RecNameInts type); + void setIdType(const ESM::RefId& id, ESM::RecNameInts type); using LuaContent = std::variant; // path to an omwscripts file @@ -148,9 +148,9 @@ namespace MWWorld iterator end() const { return mDynamicStores.end(); } /// Look up the given ID in 'all'. Returns 0 if not found. - int find(const std::string_view id) const; + int find(const ESM::RefId& id) const; - int findStatic(const std::string_view id) const; + int findStatic(const ESM::RefId& id) const; ESMStore(); ~ESMStore(); @@ -174,12 +174,12 @@ namespace MWWorld template const T* insert(const T& x) { - const std::string id = "$dynamic" + std::to_string(mDynamicCount++); + const ESM::RefId id = ESM::RefId::stringRefId("$dynamic" + std::to_string(mDynamicCount++)); Store& store = getWritable(); if (store.search(id) != nullptr) { - const std::string msg = "Try to override existing record '" + id + "'"; + const std::string msg = "Try to override existing record '" + id.getRefIdString() + "'"; throw std::runtime_error(msg); } T record = x; @@ -214,7 +214,7 @@ namespace MWWorld Store& store = getWritable(); if (store.search(x.mId) != nullptr) { - const std::string msg = "Try to override existing record '" + x.mId + "'"; + const std::string msg = "Try to override existing record '" + x.mId.getRefIdString() + "'"; throw std::runtime_error(msg); } @@ -242,11 +242,11 @@ namespace MWWorld void checkPlayer(); /// @return The number of instances defined in the base files. Excludes changes from the save file. - int getRefCount(std::string_view id) const; + int getRefCount(const ESM::RefId& id) const; /// Actors with the same ID share spells, abilities, etc. /// @return The shared spell list to use for this actor and whether or not it has already been initialized. - std::pair, bool> getSpellList(const std::string& id) const; + std::pair, bool> getSpellList(const ESM::RefId& id) const; }; template <> const ESM::Cell* ESMStore::insert(const ESM::Cell& cell); diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index 485d03b071..691cb8d6ce 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -38,7 +38,7 @@ namespace MWWorld for (const ESM::Global& esmGlobal : globals) { - mVariables.insert(std::make_pair(Misc::StringUtils::lowerCase(esmGlobal.mId), esmGlobal)); + mVariables.insert(std::make_pair(esmGlobal.mId.getRefIdString(), esmGlobal)); } } @@ -98,9 +98,8 @@ namespace MWWorld // This readRecord() method is used when reading a saved game. // Deleted globals can't appear there, so isDeleted will be ignored here. global.load(reader, isDeleted); - Misc::StringUtils::lowerCaseInPlace(global.mId); - Collection::iterator iter = mVariables.find(global.mId); + Collection::iterator iter = mVariables.find(global.mId.getRefIdString()); if (iter != mVariables.end()) iter->second = global; diff --git a/apps/openmw/mwworld/groundcoverstore.cpp b/apps/openmw/mwworld/groundcoverstore.cpp index acf7fa7915..6c7ab295b6 100644 --- a/apps/openmw/mwworld/groundcoverstore.cpp +++ b/apps/openmw/mwworld/groundcoverstore.cpp @@ -31,22 +31,20 @@ namespace MWWorld static constexpr std::string_view prefix = "grass\\"; for (const ESM::Static& stat : statics) { - std::string id = Misc::StringUtils::lowerCase(stat.mId); std::string model = Misc::StringUtils::lowerCase(stat.mModel); std::replace(model.begin(), model.end(), '/', '\\'); if (model.compare(0, prefix.size(), prefix) != 0) continue; - mMeshCache[id] = Misc::ResourceHelpers::correctMeshPath(model, vfs); + mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model, vfs); } for (const ESM::Static& stat : content.mStatics) { - std::string id = Misc::StringUtils::lowerCase(stat.mId); std::string model = Misc::StringUtils::lowerCase(stat.mModel); std::replace(model.begin(), model.end(), '/', '\\'); if (model.compare(0, prefix.size(), prefix) != 0) continue; - mMeshCache[id] = Misc::ResourceHelpers::correctMeshPath(model, vfs); + mMeshCache[stat.mId] = Misc::ResourceHelpers::correctMeshPath(model, vfs); } for (const ESM::Cell& cell : content.mCells) @@ -58,10 +56,9 @@ namespace MWWorld } } - std::string GroundcoverStore::getGroundcoverModel(const std::string& id) const + std::string GroundcoverStore::getGroundcoverModel(const ESM::RefId& id) const { - std::string idLower = Misc::StringUtils::lowerCase(id); - auto search = mMeshCache.find(idLower); + auto search = mMeshCache.find(id); if (search == mMeshCache.end()) return std::string(); diff --git a/apps/openmw/mwworld/groundcoverstore.hpp b/apps/openmw/mwworld/groundcoverstore.hpp index 55cc232b50..bc55bc4274 100644 --- a/apps/openmw/mwworld/groundcoverstore.hpp +++ b/apps/openmw/mwworld/groundcoverstore.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace ESM { @@ -35,7 +36,7 @@ namespace MWWorld class GroundcoverStore { private: - std::map mMeshCache; + std::map mMeshCache; std::map, std::vector> mCellContexts; public: @@ -43,7 +44,7 @@ namespace MWWorld const std::vector& groundcoverFiles, ToUTF8::Utf8Encoder* encoder, Loading::Listener* listener); - std::string getGroundcoverModel(const std::string& id) const; + std::string getGroundcoverModel(const ESM::RefId& id) const; void initCell(ESM::Cell& cell, int cellX, int cellY) const; }; } diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index bcaf4aec04..9c66f6c8b0 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -653,7 +653,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot( if (actor == MWMechanics::getPlayer()) { // Unset OnPCEquip Variable on item's script, if it has a script with that variable declared - std::string_view script = it->getClass().getScript(*it); + const ESM::RefId& script = it->getClass().getScript(*it); if (!script.empty()) (*it).getRefData().getLocals().setVarByInt(script, "onpcequip", 0); } diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index 9a6ec1d66f..66e31be635 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -31,7 +31,7 @@ void MWWorld::LiveCellRefBase::loadImp(const ESM::ObjectState& state) if (state.mHasLocals) { - std::string_view scriptId = mClass->getScript(ptr); + const ESM::RefId& scriptId = mClass->getScript(ptr); // Make sure we still have a script. It could have been coming from a content file that is no longer active. if (!scriptId.empty()) { @@ -58,7 +58,7 @@ void MWWorld::LiveCellRefBase::loadImp(const ESM::ObjectState& state) && !MWBase::Environment::get().getWorld()->getStore().get().search(mRef.getSoul())) { Log(Debug::Warning) << "Soul '" << mRef.getSoul() << "' not found, removing the soul from soul gem"; - mRef.setSoul(std::string()); + mRef.setSoul(ESM::RefId::sEmpty); } MWBase::Environment::get().getLuaManager()->loadLocalScripts(ptr, state.mLuaScripts); diff --git a/apps/openmw/mwworld/localscripts.cpp b/apps/openmw/mwworld/localscripts.cpp index 297ef3fa2b..c1a6c21866 100644 --- a/apps/openmw/mwworld/localscripts.cpp +++ b/apps/openmw/mwworld/localscripts.cpp @@ -27,7 +27,7 @@ namespace if (ptr.getRefData().isDeleted()) return true; - std::string_view script = ptr.getClass().getScript(ptr); + const ESM::RefId& script = ptr.getClass().getScript(ptr); if (!script.empty()) mScripts.add(script, ptr); @@ -54,7 +54,7 @@ namespace MWWorld::ContainerStore& container = containerPtr.getClass().getContainerStore(containerPtr); for (const auto& ptr : container) { - std::string_view script = ptr.getClass().getScript(ptr); + const ESM::RefId& script = ptr.getClass().getScript(ptr); if (!script.empty()) { MWWorld::Ptr item = ptr; @@ -79,18 +79,18 @@ void MWWorld::LocalScripts::startIteration() mIter = mScripts.begin(); } -bool MWWorld::LocalScripts::getNext(std::pair& script) +bool MWWorld::LocalScripts::getNext(std::pair& script) { if (mIter != mScripts.end()) { - std::list>::iterator iter = mIter++; + auto iter = mIter++; script = *iter; return true; } return false; } -void MWWorld::LocalScripts::add(std::string_view scriptName, const Ptr& ptr) +void MWWorld::LocalScripts::add(const ESM::RefId& scriptName, const Ptr& ptr) { if (const ESM::Script* script = mStore.get().search(scriptName)) { @@ -98,7 +98,7 @@ void MWWorld::LocalScripts::add(std::string_view scriptName, const Ptr& ptr) { ptr.getRefData().setLocals(*script); - for (std::list>::iterator iter = mScripts.begin(); iter != mScripts.end(); + for (auto iter = mScripts.begin(); iter != mScripts.end(); ++iter) if (iter->second == ptr) { @@ -137,7 +137,7 @@ void MWWorld::LocalScripts::clear() void MWWorld::LocalScripts::clearCell(CellStore* cell) { - std::list>::iterator iter = mScripts.begin(); + auto iter = mScripts.begin(); while (iter != mScripts.end()) { @@ -155,7 +155,7 @@ void MWWorld::LocalScripts::clearCell(CellStore* cell) void MWWorld::LocalScripts::remove(RefData* ref) { - for (std::list>::iterator iter = mScripts.begin(); iter != mScripts.end(); ++iter) + for (auto iter = mScripts.begin(); iter != mScripts.end(); ++iter) if (&(iter->second.getRefData()) == ref) { if (iter == mIter) @@ -168,7 +168,7 @@ void MWWorld::LocalScripts::remove(RefData* ref) void MWWorld::LocalScripts::remove(const Ptr& ptr) { - for (std::list>::iterator iter = mScripts.begin(); iter != mScripts.end(); ++iter) + for (auto iter = mScripts.begin(); iter != mScripts.end(); ++iter) if (iter->second == ptr) { if (iter == mIter) diff --git a/apps/openmw/mwworld/localscripts.hpp b/apps/openmw/mwworld/localscripts.hpp index 0266d921f6..4bd2abeb84 100644 --- a/apps/openmw/mwworld/localscripts.hpp +++ b/apps/openmw/mwworld/localscripts.hpp @@ -15,8 +15,8 @@ namespace MWWorld /// \brief List of active local scripts class LocalScripts { - std::list> mScripts; - std::list>::iterator mIter; + std::list> mScripts; + std::list>::iterator mIter; const MWWorld::ESMStore& mStore; public: @@ -25,11 +25,11 @@ namespace MWWorld void startIteration(); ///< Set the iterator to the begin of the script list. - bool getNext(std::pair& script); + bool getNext(std::pair& script); ///< Get next local script /// @return Did we get a script? - void add(std::string_view scriptName, const Ptr& ptr); + void add(const ESM::RefId& scriptName, const Ptr& ptr); ///< Add script to collection of active local scripts. void addCell(CellStore* cell); diff --git a/apps/openmw/mwworld/magiceffects.cpp b/apps/openmw/mwworld/magiceffects.cpp index b1ea8e5a0e..a343934b0d 100644 --- a/apps/openmw/mwworld/magiceffects.cpp +++ b/apps/openmw/mwworld/magiceffects.cpp @@ -18,7 +18,7 @@ namespace { template - void getEnchantedItem(const std::string& id, std::string& enchantment, std::string& itemName) + void getEnchantedItem(const ESM::RefId& id, ESM::RefId& enchantment, std::string& itemName) { const T* item = MWBase::Environment::get().getWorld()->getStore().get().search(id); if (item) @@ -105,7 +105,7 @@ namespace MWWorld } creatureStats.mActiveSpells.mSpells.emplace_back(params); } - std::multimap equippedItems; + std::multimap equippedItems; for (std::size_t i = 0; i < inventory.mItems.size(); ++i) { const ESM::ObjectState& item = inventory.mItems[i]; @@ -115,7 +115,7 @@ namespace MWWorld } for (const auto& [id, oldMagnitudes] : inventory.mPermanentMagicEffectMagnitudes) { - std::string eId; + ESM::RefId eId; std::string name; switch (store.find(id)) { diff --git a/apps/openmw/mwworld/manualref.cpp b/apps/openmw/mwworld/manualref.cpp index 89c8c91051..7a6daff9d1 100644 --- a/apps/openmw/mwworld/manualref.cpp +++ b/apps/openmw/mwworld/manualref.cpp @@ -7,7 +7,7 @@ namespace { template - void create(const MWWorld::Store& list, const std::string& name, std::any& refValue, MWWorld::Ptr& ptrValue) + void create(const MWWorld::Store& list, const ESM::RefId& name, std::any& refValue, MWWorld::Ptr& ptrValue) { const T* base = list.find(name); @@ -22,80 +22,79 @@ namespace } } -MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, std::string_view name, const int count) +MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store,const ESM::RefId& name, const int count) { - std::string lowerName = Misc::StringUtils::lowerCase(name); - switch (store.find(lowerName)) + switch (store.find(name)) { case ESM::REC_ACTI: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_ALCH: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_APPA: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_ARMO: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_BOOK: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_CLOT: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_CONT: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_CREA: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_DOOR: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_INGR: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_LEVC: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_LEVI: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_LIGH: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_LOCK: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_MISC: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_NPC_: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_PROB: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_REPA: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_STAT: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_WEAP: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case ESM::REC_BODY: - create(store.get(), lowerName, mRef, mPtr); + create(store.get(), name, mRef, mPtr); break; case 0: - throw std::logic_error("failed to create manual cell ref for " + lowerName + " (unknown ID)"); + throw std::logic_error("failed to create manual cell ref for " + name.getRefIdString() + " (unknown ID)"); default: - throw std::logic_error("failed to create manual cell ref for " + lowerName + " (unknown type)"); + throw std::logic_error("failed to create manual cell ref for " + name.getRefIdString() + " (unknown type)"); } mPtr.getRefData().setCount(count); diff --git a/apps/openmw/mwworld/manualref.hpp b/apps/openmw/mwworld/manualref.hpp index 7f056bb681..ccf57499ca 100644 --- a/apps/openmw/mwworld/manualref.hpp +++ b/apps/openmw/mwworld/manualref.hpp @@ -17,7 +17,7 @@ namespace MWWorld ManualRef& operator=(const ManualRef&); public: - ManualRef(const MWWorld::ESMStore& store, std::string_view name, const int count = 1); + ManualRef(const MWWorld::ESMStore& store,const ESM::RefId& name, const int count = 1); const Ptr& getPtr() const { return mPtr; } }; diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 2aed081d91..ff79ae44eb 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -49,7 +49,7 @@ namespace MWWorld { ESM::CellRef cellRef; cellRef.blank(); - cellRef.mRefID = "player"; + cellRef.mRefID = ESM::RefId::stringRefId("player"); mPlayer = LiveCellRef(cellRef, player); ESM::Position playerPos = mPlayer.mData.getPosition(); @@ -147,12 +147,12 @@ namespace MWWorld return ptr; } - void Player::setBirthSign(const std::string& sign) + void Player::setBirthSign(const ESM::RefId& sign) { mSign = sign; } - const std::string& Player::getBirthSign() const + const ESM::RefId& Player::getBirthSign() const { return mSign; } @@ -461,7 +461,7 @@ namespace MWWorld // interior cell -> need to check if it exists (exterior cell will be // generated on the fly) - if (!world.getStore().get().search(player.mMarkedCell.mWorldspace)) + if (!world.getStore().get().search(ESM::RefId::stringRefId(player.mMarkedCell.mWorldspace))) player.mHasMark = false; // drop mark silently } @@ -501,22 +501,22 @@ namespace MWWorld return mPaidCrimeId; } - void Player::setPreviousItem(const std::string& boundItemId, const std::string& previousItemId) + void Player::setPreviousItem(const ESM::RefId& boundItemId, const ESM::RefId& previousItemId) { mPreviousItems[boundItemId] = previousItemId; } - std::string Player::getPreviousItem(const std::string& boundItemId) + ESM::RefId Player::getPreviousItem(const ESM::RefId& boundItemId) { return mPreviousItems[boundItemId]; } - void Player::erasePreviousItem(const std::string& boundItemId) + void Player::erasePreviousItem(const ESM::RefId& boundItemId) { mPreviousItems.erase(boundItemId); } - void Player::setSelectedSpell(const std::string& spellId) + void Player::setSelectedSpell(const ESM::RefId& spellId) { Ptr player = getPlayer(); InventoryStore& store = player.getClass().getInventoryStore(player); diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index ea8c53bc19..d701b9e359 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -8,6 +8,7 @@ #include "../mwmechanics/drawstate.hpp" #include +#include #include #include @@ -32,7 +33,7 @@ namespace MWWorld { LiveCellRef mPlayer; MWWorld::CellStore* mCellStore; - std::string mSign; + ESM::RefId mSign; osg::Vec3f mLastKnownExteriorPosition; @@ -47,7 +48,7 @@ namespace MWWorld int mCurrentCrimeId; // the id assigned witnesses int mPaidCrimeId; // the last id paid off (0 bounty) - typedef std::map PreviousItems; // previous equipped items, needed for bound spells + typedef std::map PreviousItems; // previous equipped items, needed for bound spells PreviousItems mPreviousItems; // Saved stats prior to becoming a werewolf @@ -80,8 +81,8 @@ namespace MWWorld MWWorld::Ptr getPlayer(); MWWorld::ConstPtr getConstPlayer() const; - void setBirthSign(const std::string& sign); - const std::string& getBirthSign() const; + void setBirthSign(const ESM::RefId& sign); + const ESM::RefId& getBirthSign() const; void setDrawState(MWMechanics::DrawState state); MWMechanics::DrawState getDrawState(); /// \todo constness @@ -127,11 +128,11 @@ namespace MWWorld void recordCrimeId(); // record the paid crime id when bounty is 0 int getCrimeId() const; // get the last paid crime id - void setPreviousItem(const std::string& boundItemId, const std::string& previousItemId); - std::string getPreviousItem(const std::string& boundItemId); - void erasePreviousItem(const std::string& boundItemId); + void setPreviousItem(const ESM::RefId& boundItemId, const ESM::RefId& previousItemId); + ESM::RefId getPreviousItem(const ESM::RefId& boundItemId); + void erasePreviousItem(const ESM::RefId& boundItemId); - void setSelectedSpell(const std::string& spellId); + void setSelectedSpell(const ESM::RefId& spellId); void update(); }; diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 6292fa3234..de768496b4 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -56,8 +56,8 @@ namespace { - ESM::EffectList getMagicBoltData(std::vector& projectileIDs, std::set& sounds, - float& speed, std::string& texture, std::string& sourceName, const std::string& id) + ESM::EffectList getMagicBoltData(std::vector& projectileIDs, std::set& sounds, + float& speed, std::string& texture, std::string& sourceName, const ESM::RefId& id) { const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); const ESM::EffectList* effects; @@ -93,7 +93,7 @@ namespace continue; if (magicEffect->mBolt.empty()) - projectileIDs.emplace_back("VFX_DefaultBolt"); + projectileIDs.emplace_back(ESM::RefId::stringRefId("VFX_DefaultBolt")); else projectileIDs.push_back(magicEffect->mBolt); @@ -102,7 +102,7 @@ namespace if (!magicEffect->mBoltSound.empty()) sounds.emplace(magicEffect->mBoltSound); else - sounds.emplace(schools[magicEffect->mData.mSchool] + " bolt"); + sounds.emplace(ESM::RefId::stringRefId(schools[magicEffect->mData.mSchool] + " bolt")); projectileEffects.mList.push_back(*iter); } @@ -121,8 +121,8 @@ namespace if (projectileEffects.mList.size() > 1) // insert a VFX_Multiple projectile if there are multiple projectile effects { - const std::string ID = "VFX_Multiple" + std::to_string(effects->mList.size()); - std::vector::iterator it; + const ESM::RefId ID = ESM::RefId::stringRefId("VFX_Multiple" + std::to_string(effects->mList.size())); + std::vector::iterator it; it = projectileIDs.begin(); it = projectileIDs.insert(it, ID); } @@ -267,7 +267,7 @@ namespace MWWorld } void ProjectileManager::launchMagicBolt( - const std::string& spellId, const Ptr& caster, const osg::Vec3f& fallbackDirection, int slot) + const ESM::RefId& spellId, const Ptr& caster, const osg::Vec3f& fallbackDirection, int slot) { osg::Vec3f pos = caster.getRefData().getPosition().asVec3(); if (caster.getClass().isActor()) @@ -321,7 +321,7 @@ namespace MWWorld createModel(state, model, pos, orient, true, true, lightDiffuseColor, texture); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - for (const std::string& soundid : state.mSoundIds) + for (const auto& soundid : state.mSoundIds) { MWBase::Sound* sound = sndMgr->playSound3D(pos, soundid, 1.0f, 1.0f, MWSound::Type::Sfx, MWSound::PlayMode::Loop); @@ -544,7 +544,7 @@ namespace MWWorld MWWorld::InventoryStore& inv = caster.getClass().getInventoryStore(caster); MWWorld::ContainerStoreIterator invIt = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); if (invIt != inv.end() - && Misc::StringUtils::ciEqual(invIt->getCellRef().getRefId(), projectileState.mBowId)) + && ESM::RefId::ciEqual(invIt->getCellRef().getRefId(), projectileState.mBowId)) bow = *invIt; } if (projectile->getHitWater()) @@ -768,7 +768,7 @@ namespace MWWorld state.mProjectileId = mPhysics->addProjectile(state.getCaster(), osg::Vec3f(esm.mPosition), model, true); MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager(); - for (const std::string& soundid : state.mSoundIds) + for (const auto& soundid : state.mSoundIds) { MWBase::Sound* sound = sndMgr->playSound3D( esm.mPosition, soundid, 1.0f, 1.0f, MWSound::Type::Sfx, MWSound::PlayMode::Loop); diff --git a/apps/openmw/mwworld/projectilemanager.hpp b/apps/openmw/mwworld/projectilemanager.hpp index 602d254046..3e9d70893a 100644 --- a/apps/openmw/mwworld/projectilemanager.hpp +++ b/apps/openmw/mwworld/projectilemanager.hpp @@ -50,7 +50,7 @@ namespace MWWorld /// If caster is an actor, the actor's facing orientation is used. Otherwise fallbackDirection is used. void launchMagicBolt( - const std::string& spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection, int slot); + const ESM::RefId& spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection, int slot); void launchProjectile(const MWWorld::Ptr& actor, const MWWorld::ConstPtr& projectile, const osg::Vec3f& pos, const osg::Quat& orient, const MWWorld::Ptr& bow, float speed, float attackStrength); @@ -90,17 +90,17 @@ namespace MWWorld MWWorld::Ptr getCaster(); // MW-ids of a magic projectile - std::vector mIdMagic; + std::vector mIdMagic; // MW-id of an arrow projectile - std::string mIdArrow; + ESM::RefId mIdArrow; bool mToDelete; }; struct MagicBoltState : public State { - std::string mSpellId; + ESM::RefId mSpellId; // Name of item to display as effect source in magic menu (in case we casted an enchantment) std::string mSourceName; @@ -111,13 +111,13 @@ namespace MWWorld int mSlot; std::vector mSounds; - std::set mSoundIds; + std::set mSoundIds; }; struct ProjectileState : public State { // RefID of the bow or crossbow the actor was using when this projectile was fired (may be empty) - std::string mBowId; + ESM::RefId mBowId; osg::Vec3f mVelocity; float mAttackStrength; diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index ac9a035a6d..ffc5af7ff9 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -120,7 +120,7 @@ namespace MWWorld } } - void RefData::write(ESM::ObjectState& objectState, std::string_view scriptId) const + void RefData::write(ESM::ObjectState& objectState, const ESM::RefId& scriptId) const { objectState.mHasLocals = mLocals.write(objectState.mLocals, scriptId); diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 194e307a2a..ef4b8f6f87 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -2,6 +2,7 @@ #define GAME_MWWORLD_REFDATA_H #include +#include #include #include "../mwscript/locals.hpp" @@ -85,7 +86,7 @@ namespace MWWorld ~RefData(); - void write(ESM::ObjectState& objectState, std::string_view scriptId = {}) const; + void write(ESM::ObjectState& objectState,const ESM::RefId& scriptId = ESM::RefId::sEmpty) const; ///< Ignores custom data (not enough context available here to /// perform this operations). diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 8d5672f7ce..f99f01e4d2 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -92,7 +92,7 @@ namespace std::string getModel(const MWWorld::Ptr& ptr, const VFS::Manager* vfs) { - if (Misc::ResourceHelpers::isHiddenMarker(ptr.getCellRef().getRefId())) + if (Misc::ResourceHelpers::isHiddenMarker(ptr.getCellRef().getRefId().getRefIdString())) return {}; bool useAnim = ptr.getClass().useAnim(); std::string model = ptr.getClass().getModel(ptr); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 19fa792d8b..c36e2d4258 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -17,7 +17,7 @@ namespace { // TODO: Switch to C++23 to get a working version of std::unordered_map::erase template - bool eraseFromMap(T& map, std::string_view value) + bool eraseFromMap(T& map, const ESM::RefId& value) { auto it = map.find(value); if (it != map.end()) @@ -31,7 +31,7 @@ namespace namespace MWWorld { - RecordId::RecordId(const std::string& id, bool isDeleted) + RecordId::RecordId(const ESM::RefId& id, bool isDeleted) : mId(id) , mIsDeleted(isDeleted) { @@ -96,18 +96,18 @@ namespace MWWorld template class IndexedStore; template - Store::Store() + TypedDynamicStore::TypedDynamicStore() { } template - Store::Store(const Store& orig) + TypedDynamicStore::TypedDynamicStore(const TypedDynamicStore& orig) : mStatic(orig.mStatic) { } template - void Store::clearDynamic() + void TypedDynamicStore::clearDynamic() { // remove the dynamic part of mShared assert(mShared.size() >= mStatic.size()); @@ -116,7 +116,7 @@ namespace MWWorld } template - const T* Store::search(std::string_view id) const + const T* TypedDynamicStore::search(const ESM::RefId& id) const { typename Dynamic::const_iterator dit = mDynamic.find(id); if (dit != mDynamic.end()) @@ -129,7 +129,7 @@ namespace MWWorld return nullptr; } template - const T* Store::searchStatic(std::string_view id) const + const T* TypedDynamicStore::searchStatic(const ESM::RefId& id) const { typename Static::const_iterator it = mStatic.find(id); if (it != mStatic.end()) @@ -139,23 +139,23 @@ namespace MWWorld } template - bool Store::isDynamic(std::string_view id) const + bool TypedDynamicStore::isDynamic(const ESM::RefId& id) const { typename Dynamic::const_iterator dit = mDynamic.find(id); return (dit != mDynamic.end()); } template - const T* Store::searchRandom(std::string_view id, Misc::Rng::Generator& prng) const + const T* TypedDynamicStore::searchRandom(const ESM::RefId& id, Misc::Rng::Generator& prng) const { std::vector results; std::copy_if(mShared.begin(), mShared.end(), std::back_inserter(results), - [&id](const T* item) { return Misc::StringUtils::ciStartsWith(item->mId, id); }); + [&id](const T* item) { return Misc::StringUtils::ciStartsWith(item->mId.getRefIdString(), id.getRefIdString()); }); if (!results.empty()) return results[Misc::Rng::rollDice(results.size(), prng)]; return nullptr; } template - const T* Store::find(std::string_view id) const + const T* TypedDynamicStore::find(const ESM::RefId& id) const { const T* ptr = search(id); if (ptr == nullptr) @@ -167,14 +167,12 @@ namespace MWWorld return ptr; } template - RecordId Store::load(ESM::ESMReader& esm) + RecordId TypedDynamicStore::load(ESM::ESMReader& esm) { T record; bool isDeleted = false; record.load(esm, isDeleted); - Misc::StringUtils::lowerCaseInPlace( - record.mId); // TODO: remove this line once we have ported our remaining code base to lowercase on lookup std::pair inserted = mStatic.insert_or_assign(record.mId, record); if (inserted.second) @@ -183,34 +181,34 @@ namespace MWWorld return RecordId(record.mId, isDeleted); } template - void Store::setUp() + void TypedDynamicStore::setUp() { } template - typename Store::iterator Store::begin() const + typename TypedDynamicStore::iterator TypedDynamicStore::begin() const { return mShared.begin(); } template - typename Store::iterator Store::end() const + typename TypedDynamicStore::iterator TypedDynamicStore::end() const { return mShared.end(); } template - size_t Store::getSize() const + size_t TypedDynamicStore::getSize() const { return mShared.size(); } template - int Store::getDynamicSize() const + int TypedDynamicStore::getDynamicSize() const { return mDynamic.size(); } template - void Store::listIdentifier(std::vector& list) const + void TypedDynamicStore::listIdentifier(std::vector& list) const { list.reserve(list.size() + getSize()); typename std::vector::const_iterator it = mShared.begin(); @@ -220,7 +218,7 @@ namespace MWWorld } } template - T* Store::insert(const T& item, bool overrideOnly) + T* TypedDynamicStore::insert(const T& item, bool overrideOnly) { if (overrideOnly) { @@ -235,7 +233,7 @@ namespace MWWorld return ptr; } template - T* Store::insertStatic(const T& item) + T* TypedDynamicStore::insertStatic(const T& item) { std::pair result = mStatic.insert_or_assign(item.mId, item); T* ptr = &result.first->second; @@ -244,7 +242,7 @@ namespace MWWorld return ptr; } template - bool Store::eraseStatic(std::string_view id) + bool TypedDynamicStore::eraseStatic(const ESM::RefId& id) { typename Static::iterator it = mStatic.find(id); @@ -256,7 +254,7 @@ namespace MWWorld while (sharedIter != mShared.end() && sharedIter != end) { - if (Misc::StringUtils::ciEqual((*sharedIter)->mId, id)) + if (ESM::RefId::ciEqual((*sharedIter)->mId, id)) { mShared.erase(sharedIter); break; @@ -270,7 +268,7 @@ namespace MWWorld } template - bool Store::erase(std::string_view id) + bool TypedDynamicStore::erase(const ESM::RefId& id) { if (!eraseFromMap(mDynamic, id)) return false; @@ -285,12 +283,12 @@ namespace MWWorld return true; } template - bool Store::erase(const T& item) + bool TypedDynamicStore::erase(const T& item) { return erase(item.mId); } template - void Store::write(ESM::ESMWriter& writer, Loading::Listener& progress) const + void TypedDynamicStore::write(ESM::ESMWriter& writer, Loading::Listener& progress) const { for (typename Dynamic::const_iterator iter(mDynamic.begin()); iter != mDynamic.end(); ++iter) { @@ -300,7 +298,7 @@ namespace MWWorld } } template - RecordId Store::read(ESM::ESMReader& reader, bool overrideOnly) + RecordId TypedDynamicStore::read(ESM::ESMReader& reader, bool overrideOnly) { T record; bool isDeleted = false; @@ -361,7 +359,7 @@ namespace MWWorld ESM::LandTexture* tex = const_cast(search(lt.mIndex, i)); if (tex) { - if (Misc::StringUtils::ciEqual(tex->mId, lt.mId)) + if (ESM::RefId::ciEqual(tex->mId, lt.mId)) tex->mTexture = lt.mTexture; } } @@ -437,7 +435,7 @@ namespace MWWorld else mStatic.insert(it, std::move(land)); - return RecordId("", isDeleted); + return RecordId(ESM::RefId::stringRefId(""), isDeleted); } void Store::setUp() { @@ -457,7 +455,7 @@ namespace MWWorld { return search(cell.getGridX(), cell.getGridY()); } - return search(cell.mName); + return search(ESM::RefId::stringRefId(cell.mName)); } // this method *must* be called right after esm3.loadCell() @@ -499,7 +497,7 @@ namespace MWWorld esm.restoreContext(ctx); } - const ESM::Cell* Store::search(std::string_view id) const + const ESM::Cell* Store::search(const ESM::RefId& id) const { DynamicInt::const_iterator it = mInt.find(id); if (it != mInt.end()) @@ -560,12 +558,12 @@ namespace MWWorld return &mExt.insert(std::make_pair(key, newCell)).first->second; } - const ESM::Cell* Store::find(std::string_view id) const + const ESM::Cell* Store::find(const ESM::RefId& id) const { const ESM::Cell* ptr = search(id); if (ptr == nullptr) { - const std::string msg = "Cell '" + std::string(id) + "' not found"; + const std::string msg = "Cell '" + id.getRefIdString() + "' not found"; throw std::runtime_error(msg); } return ptr; @@ -615,7 +613,7 @@ namespace MWWorld if (cell.mData.mFlags & ESM::Cell::Interior) { // Store interior cell by name, try to merge with existing parent data. - ESM::Cell* oldcell = const_cast(search(cell.mName)); + ESM::Cell* oldcell = const_cast(search(ESM::RefId::stringRefId(cell.mName))); if (oldcell) { // merge new cell into old cell @@ -630,7 +628,7 @@ namespace MWWorld // spawn a new cell cell.loadCell(esm, true); - mInt[cell.mName] = cell; + mInt[ESM::RefId::stringRefId(cell.mName)] = cell; } } else @@ -695,7 +693,7 @@ namespace MWWorld } } - return RecordId(cell.mName, isDeleted); + return RecordId(ESM::RefId::stringRefId(cell.mName), isDeleted); } Store::iterator Store::intBegin() const { @@ -713,12 +711,12 @@ namespace MWWorld { return iterator(mSharedExt.end()); } - const ESM::Cell* Store::searchExtByName(std::string_view id) const + const ESM::Cell* Store::searchExtByName(const ESM::RefId& id) const { const ESM::Cell* cell = nullptr; for (const ESM::Cell* sharedCell : mSharedExt) { - if (Misc::StringUtils::ciEqual(sharedCell->mName, id)) + if (ESM::RefId::ciEqual(ESM::RefId::stringRefId(sharedCell->mName), id)) { if (cell == nullptr || (sharedCell->mData.mX > cell->mData.mX) || (sharedCell->mData.mX == cell->mData.mX && sharedCell->mData.mY > cell->mData.mY)) @@ -729,12 +727,12 @@ namespace MWWorld } return cell; } - const ESM::Cell* Store::searchExtByRegion(std::string_view id) const + const ESM::Cell* Store::searchExtByRegion(const ESM::RefId& id) const { const ESM::Cell* cell = nullptr; for (const ESM::Cell* sharedCell : mSharedExt) { - if (Misc::StringUtils::ciEqual(sharedCell->mRegion, id)) + if (ESM::RefId::ciEqual(sharedCell->mRegion, id)) { if (cell == nullptr || (sharedCell->mData.mX > cell->mData.mX) || (sharedCell->mData.mX == cell->mData.mX && sharedCell->mData.mY > cell->mData.mY)) @@ -757,13 +755,13 @@ namespace MWWorld { return mSharedInt.size(); } - void Store::listIdentifier(std::vector& list) const + void Store::listIdentifier(std::vector& list) const { list.reserve(list.size() + mSharedInt.size()); for (const ESM::Cell* sharedCell : mSharedInt) { - list.push_back(sharedCell->mName); + list.push_back(ESM::RefId::stringRefId(sharedCell->mName)); } } ESM::Cell* Store::insert(const ESM::Cell& cell) @@ -785,7 +783,7 @@ namespace MWWorld else { // duplicate insertions are avoided by search(ESM::Cell &) - DynamicInt::iterator result = mDynamicInt.emplace(cell.mName, cell).first; + DynamicInt::iterator result = mDynamicInt.emplace(ESM::RefId::stringRefId(cell.mName), cell).first; mSharedInt.push_back(&result->second); return &result->second; } @@ -796,9 +794,9 @@ namespace MWWorld { return erase(cell.getGridX(), cell.getGridY()); } - return erase(cell.mName); + return erase(ESM::RefId::stringRefId(cell.mName)); } - bool Store::erase(std::string_view id) + bool Store::erase(const ESM::RefId& id) { DynamicInt::iterator it = mDynamicInt.find(id); @@ -880,7 +878,7 @@ namespace MWWorld mExt.erase(it); } - return RecordId("", isDeleted); + return RecordId(ESM::RefId::sEmpty, isDeleted); } // Try to overwrite existing record @@ -898,7 +896,7 @@ namespace MWWorld ret.first->second = pathgrid; } - return RecordId("", isDeleted); + return RecordId(ESM::RefId::sEmpty, isDeleted); } size_t Store::getSize() const { @@ -912,7 +910,7 @@ namespace MWWorld return &(it->second); return nullptr; } - const ESM::Pathgrid* Store::search(std::string_view name) const + const ESM::Pathgrid* Store::search(const ESM::RefId& name) const { Interior::const_iterator it = mInt.find(name); if (it != mInt.end()) @@ -929,12 +927,12 @@ namespace MWWorld } return pathgrid; } - const ESM::Pathgrid* Store::find(std::string_view name) const + const ESM::Pathgrid* Store::find(const ESM::RefId& name) const { const ESM::Pathgrid* pathgrid = search(name); if (!pathgrid) { - const std::string msg = "Pathgrid in cell '" + std::string(name) + "' not found"; + const std::string msg = "Pathgrid in cell '" + name.getRefIdString() + "' not found"; throw std::runtime_error(msg); } return pathgrid; @@ -944,14 +942,14 @@ namespace MWWorld if (!(cell.mData.mFlags & ESM::Cell::Interior)) return search(cell.mData.mX, cell.mData.mY); else - return search(cell.mName); + return search(ESM::RefId::stringRefId(cell.mName)); } const ESM::Pathgrid* Store::find(const ESM::Cell& cell) const { if (!(cell.mData.mFlags & ESM::Cell::Interior)) return find(cell.mData.mX, cell.mData.mY); else - return find(cell.mName); + return find(ESM::RefId::stringRefId(cell.mName)); } // Skill @@ -962,6 +960,21 @@ namespace MWWorld // Magic effect //========================================================================= + const ESM::GameSetting* Store::search(const ESM::RefId& id) const + { + return TypedDynamicStore::search(id); + } + + const ESM::GameSetting* Store::find(std::string_view id) const + { + return TypedDynamicStore::find(ESM::RefId::stringRefId(id)); + } + + const ESM::GameSetting* Store::search(std::string_view id) const + { + return TypedDynamicStore::search(ESM::RefId::stringRefId(id));; + } + Store::Store() {} // Attribute @@ -1041,7 +1054,7 @@ namespace MWWorld mKeywordSearchModFlag = true; } - const ESM::Dialogue* Store::search(std::string_view id) const + const ESM::Dialogue* Store::search(const ESM::RefId& id) const { typename Static::const_iterator it = mStatic.find(id); if (it != mStatic.end()) @@ -1050,7 +1063,7 @@ namespace MWWorld return nullptr; } - const ESM::Dialogue* Store::find(std::string_view id) const + const ESM::Dialogue* Store::find(const ESM::RefId& id) const { const ESM::Dialogue* ptr = search(id); if (ptr == nullptr) @@ -1102,7 +1115,7 @@ namespace MWWorld return RecordId(dialogue.mId, isDeleted); } - bool Store::eraseStatic(std::string_view id) + bool Store::eraseStatic(const ESM::RefId& id) { if (eraseFromMap(mStatic, id)) mKeywordSearchModFlag = true; @@ -1110,7 +1123,7 @@ namespace MWWorld return true; } - void Store::listIdentifier(std::vector& list) const + void Store::listIdentifier(std::vector& list) const { list.reserve(list.size() + getSize()); for (const auto& dialogue : mShared) @@ -1126,7 +1139,7 @@ namespace MWWorld std::vector keywordList; keywordList.reserve(getSize()); for (const auto& it : *this) - keywordList.push_back(Misc::StringUtils::lowerCase(it.mId)); + keywordList.push_back(Misc::StringUtils::lowerCase(it.mId.getRefIdString())); sort(keywordList.begin(), keywordList.end()); for (const auto& it : keywordList) @@ -1139,45 +1152,45 @@ namespace MWWorld } } -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; // template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; // template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; // template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; // template class MWWorld::Store; // template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; // template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; // template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; // template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; -template class MWWorld::Store; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 59ffd9f098..d3a78f81e7 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include #include @@ -37,10 +40,10 @@ namespace MWWorld { struct RecordId { - std::string mId; + ESM::RefId mId; bool mIsDeleted; - RecordId(const std::string& id = {}, bool isDeleted = false); + RecordId(const ESM::RefId& id = {}, bool isDeleted = false); }; class StoreBase @@ -56,13 +59,13 @@ namespace MWWorld /// List identifiers of records contained in this Store (case-smashed). No-op for Stores that don't use string /// IDs. - virtual void listIdentifier(std::vector& list) const {} + virtual void listIdentifier(std::vector& list) const {} virtual size_t getSize() const = 0; virtual int getDynamicSize() const { return 0; } virtual RecordId load(ESM::ESMReader& esm) = 0; - virtual bool eraseStatic(std::string_view id) { return false; } + virtual bool eraseStatic(const ESM::RefId& id) { return false; } virtual void clearDynamic() {} virtual void write(ESM::ESMWriter& writer, Loading::Listener& progress) const {} @@ -165,22 +168,22 @@ namespace MWWorld class ESMStore; template - class Store : public DynamicStore + class TypedDynamicStore : public DynamicStore { - typedef std::unordered_map Static; + typedef std::unordered_map Static; Static mStatic; /// @par mShared usually preserves the record order as it came from the content files (this /// is relevant for the spell autocalc code and selection order /// for heads/hairs in the character creation) std::vector mShared; - typedef std::unordered_map Dynamic; + typedef std::unordered_map Dynamic; Dynamic mDynamic; friend class ESMStore; public: - Store(); - Store(const Store& orig); + TypedDynamicStore(); + TypedDynamicStore(const TypedDynamicStore& orig); typedef SharedIterator iterator; @@ -188,19 +191,19 @@ namespace MWWorld void clearDynamic() override; void setUp() override; - const T* search(std::string_view id) const; - const T* searchStatic(std::string_view id) const; + const T* search(const ESM::RefId& id) const; + const T* searchStatic(const ESM::RefId& id) const; /** * Does the record with this ID come from the dynamic store? */ - bool isDynamic(std::string_view id) const; + bool isDynamic(const ESM::RefId& id) const; /** Returns a random record that starts with the named ID, or nullptr if not found. */ - const T* searchRandom(std::string_view id, Misc::Rng::Generator& prng) const; + const T* searchRandom(const ESM::RefId& id, Misc::Rng::Generator& prng) const; // calls `search` and throws an exception if not found - const T* find(std::string_view id) const; + const T* find(const ESM::RefId& id) const; iterator begin() const; iterator end() const; @@ -209,13 +212,13 @@ namespace MWWorld int getDynamicSize() const override; /// @note The record identifiers are listed in the order that the records were defined by the content files. - void listIdentifier(std::vector& list) const override; + void listIdentifier(std::vector& list) const override; T* insert(const T& item, bool overrideOnly = false); T* insertStatic(const T& item); - bool eraseStatic(std::string_view id) override; - bool erase(std::string_view id); + bool eraseStatic(const ESM::RefId& id) override; + bool erase(const ESM::RefId& id); bool erase(const T& item); RecordId load(ESM::ESMReader& esm) override; @@ -223,6 +226,12 @@ namespace MWWorld RecordId read(ESM::ESMReader& reader, bool overrideOnly = false) override; }; + template + class Store : public TypedDynamicStore + { + + }; + template <> class Store : public DynamicStore { @@ -251,6 +260,15 @@ namespace MWWorld iterator end(size_t plugin) const; }; + template <> + class Store : public TypedDynamicStore + { + public: + const ESM::GameSetting* search(const ESM::RefId& id) const; + + const ESM::GameSetting* find(const std::string_view id) const; + const ESM::GameSetting* search(const std::string_view id) const; + }; template <> class Store : public DynamicStore { @@ -315,7 +333,7 @@ namespace MWWorld } }; - typedef std::unordered_map + typedef std::unordered_map DynamicInt; typedef std::map, ESM::Cell, DynamicExtCmp> DynamicExt; @@ -334,12 +352,12 @@ namespace MWWorld public: typedef SharedIterator iterator; - const ESM::Cell* search(std::string_view id) const; + const ESM::Cell* search(const ESM::RefId& id) const; const ESM::Cell* search(int x, int y) const; const ESM::Cell* searchStatic(int x, int y) const; const ESM::Cell* searchOrCreate(int x, int y); - const ESM::Cell* find(std::string_view id) const; + const ESM::Cell* find(const ESM::RefId& id) const; const ESM::Cell* find(int x, int y) const; void clearDynamic() override; @@ -353,21 +371,21 @@ namespace MWWorld iterator extEnd() const; // Return the northernmost cell in the easternmost column. - const ESM::Cell* searchExtByName(std::string_view id) const; + const ESM::Cell* searchExtByName(const ESM::RefId& id) const; // Return the northernmost cell in the easternmost column. - const ESM::Cell* searchExtByRegion(std::string_view id) const; + const ESM::Cell* searchExtByRegion(const ESM::RefId& id) const; size_t getSize() const override; size_t getExtSize() const; size_t getIntSize() const; - void listIdentifier(std::vector& list) const override; + void listIdentifier(std::vector& list) const override; ESM::Cell* insert(const ESM::Cell& cell); bool erase(const ESM::Cell& cell); - bool erase(std::string_view id); + bool erase(const ESM::RefId& id); bool erase(int x, int y); }; @@ -376,7 +394,7 @@ namespace MWWorld class Store : public DynamicStore { private: - typedef std::unordered_map + typedef std::unordered_map Interior; typedef std::map, ESM::Pathgrid> Exterior; @@ -395,9 +413,9 @@ namespace MWWorld void setUp() override; const ESM::Pathgrid* search(int x, int y) const; - const ESM::Pathgrid* search(std::string_view name) const; + const ESM::Pathgrid* search(const ESM::RefId& name) const; const ESM::Pathgrid* find(int x, int y) const; - const ESM::Pathgrid* find(std::string_view name) const; + const ESM::Pathgrid* find(const ESM::RefId& name) const; const ESM::Pathgrid* search(const ESM::Cell& cell) const; const ESM::Pathgrid* find(const ESM::Cell& cell) const; }; @@ -467,7 +485,7 @@ namespace MWWorld template <> class Store : public DynamicStore { - typedef std::unordered_map + typedef std::unordered_map Static; Static mStatic; /// @par mShared usually preserves the record order as it came from the content files (this @@ -486,19 +504,19 @@ namespace MWWorld void setUp() override; - const ESM::Dialogue* search(std::string_view id) const; - const ESM::Dialogue* find(std::string_view id) const; + const ESM::Dialogue* search(const ESM::RefId& id) const; + const ESM::Dialogue* find(const ESM::RefId& id) const; iterator begin() const; iterator end() const; size_t getSize() const override; - bool eraseStatic(std::string_view id) override; + bool eraseStatic(const ESM::RefId& id) override; RecordId load(ESM::ESMReader& esm) override; - void listIdentifier(std::vector& list) const override; + void listIdentifier(std::vector& list) const override; const MWDialogue::KeywordSearch& getDialogIdKeywordSearch() const; }; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 237cfa742d..c96b0651da 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -185,10 +185,10 @@ namespace MWWorld { mDL.FogFactor = dlFactor; mDL.FogOffset = dlOffset; - mThunderSoundID[0] = Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_0"); - mThunderSoundID[1] = Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_1"); - mThunderSoundID[2] = Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_2"); - mThunderSoundID[3] = Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_3"); + mThunderSoundID[0] = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_0")); + mThunderSoundID[1] = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_1")); + mThunderSoundID[2] = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_2")); + mThunderSoundID[3] = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_3")); // TODO: support weathers that have both "Ambient Loop Sound ID" and "Rain Loop Sound ID", need to play both // sounds at the same time. @@ -196,14 +196,14 @@ namespace MWWorld if (!mRainEffect.empty()) // NOTE: in vanilla, the weathers with rain seem to be hardcoded; changing // Using_Precip has no effect { - mAmbientLoopSoundID = Fallback::Map::getString("Weather_" + name + "_Rain_Loop_Sound_ID"); + mAmbientLoopSoundID = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Rain_Loop_Sound_ID")); if (mAmbientLoopSoundID.empty()) // default to "rain" if not set - mAmbientLoopSoundID = "rain"; + mAmbientLoopSoundID = ESM::RefId::stringRefId("rain"); } else - mAmbientLoopSoundID = Fallback::Map::getString("Weather_" + name + "_Ambient_Loop_Sound_ID"); + mAmbientLoopSoundID = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Ambient_Loop_Sound_ID")); - if (Misc::StringUtils::ciEqual(mAmbientLoopSoundID, "None")) + if (ESM::RefId::ciEqual(mAmbientLoopSoundID, ESM::RefId::stringRefId("None"))) mAmbientLoopSoundID.clear(); } @@ -609,8 +609,7 @@ namespace MWWorld Store::iterator it = store.get().begin(); for (; it != store.get().end(); ++it) { - std::string regionID = Misc::StringUtils::lowerCase(it->mId); - mRegions.insert(std::make_pair(regionID, RegionWeather(*it))); + mRegions.insert(std::make_pair(it->mId, RegionWeather(*it))); } forceWeather(0); @@ -621,7 +620,7 @@ namespace MWWorld stopSounds(); } - void WeatherManager::changeWeather(std::string_view regionID, const unsigned int weatherID) + void WeatherManager::changeWeather(const ESM::RefId& regionID, const unsigned int weatherID) { // In Morrowind, this seems to have the following behavior, when applied to the current region: // - When there is no transition in progress, start transitioning to the new weather. @@ -634,8 +633,7 @@ namespace MWWorld if (weatherID < mWeatherSettings.size()) { - std::string lowerCaseRegionID = Misc::StringUtils::lowerCase(regionID); - std::map::iterator it = mRegions.find(lowerCaseRegionID); + auto it = mRegions.find(regionID); if (it != mRegions.end()) { it->second.setWeather(weatherID); @@ -644,7 +642,7 @@ namespace MWWorld } } - void WeatherManager::modRegion(std::string_view regionID, const std::vector& chances) + void WeatherManager::modRegion(const ESM::RefId& regionID, const std::vector& chances) { // Sets the region's probability for various weather patterns. Note that this appears to be saved permanently. // In Morrowind, this seems to have the following behavior when applied to the current region: @@ -654,8 +652,7 @@ namespace MWWorld // - If the region no longer supports the current weather, and there is a transition in progress, queue a // transition to a new supported weather type. - std::string lowerCaseRegionID = Misc::StringUtils::lowerCase(regionID); - std::map::iterator it = mRegions.find(lowerCaseRegionID); + auto it = mRegions.find(regionID); if (it != mRegions.end()) { it->second.setChances(chances); @@ -663,12 +660,12 @@ namespace MWWorld } } - void WeatherManager::playerTeleported(const std::string& playerRegion, bool isExterior) + void WeatherManager::playerTeleported(const ESM::RefId& playerRegion, bool isExterior) { // If the player teleports to an outdoors cell in a new region (for instance, by travelling), the weather needs // to be changed immediately, and any transitions for the previous region discarded. { - std::map::iterator it = mRegions.find(playerRegion); + auto it = mRegions.find(playerRegion); if (it != mRegions.end() && playerRegion != mCurrentRegion) { mCurrentRegion = playerRegion; @@ -700,10 +697,9 @@ namespace MWWorld if (!paused || mFastForward) { // Add new transitions when either the player's current external region changes. - std::string playerRegion = Misc::StringUtils::lowerCase(player.getCell()->getCell()->mRegion); - if (updateWeatherTime() || updateWeatherRegion(playerRegion)) + if (updateWeatherTime() || updateWeatherRegion(player.getCell()->getCell()->mRegion)) { - std::map::iterator it = mRegions.find(mCurrentRegion); + auto it = mRegions.find(mCurrentRegion); if (it != mRegions.end()) { addWeatherTransition(it->second.getWeather()); @@ -903,7 +899,7 @@ namespace MWWorld state.mNextWeather = mNextWeather; state.mQueuedWeather = mQueuedWeather; - std::map::iterator it = mRegions.begin(); + auto it = mRegions.begin(); for (; it != mRegions.end(); ++it) { state.mRegions.insert(std::make_pair(it->first, it->second)); @@ -942,10 +938,10 @@ namespace MWWorld mRegions.clear(); importRegions(); - for (std::map::iterator it = state.mRegions.begin(); + for (auto it = state.mRegions.begin(); it != state.mRegions.end(); ++it) { - std::map::iterator found = mRegions.find(it->first); + auto found = mRegions.find(it->first); if (found != mRegions.end()) { found->second = RegionWeather(it->second); @@ -985,18 +981,17 @@ namespace MWWorld { for (const ESM::Region& region : mStore.get()) { - std::string regionID = Misc::StringUtils::lowerCase(region.mId); - mRegions.insert(std::make_pair(regionID, RegionWeather(region))); + mRegions.insert(std::make_pair(region.mId, RegionWeather(region))); } } - inline void WeatherManager::regionalWeatherChanged(const std::string& regionID, RegionWeather& region) + inline void WeatherManager::regionalWeatherChanged(const ESM::RefId& regionID, RegionWeather& region) { // If the region is current, then add a weather transition for it. MWWorld::ConstPtr player = MWMechanics::getPlayer(); if (player.isInCell()) { - if (Misc::StringUtils::ciEqual(regionID, mCurrentRegion)) + if (ESM::RefId::ciEqual(regionID, mCurrentRegion)) { addWeatherTransition(region.getWeather()); } @@ -1010,7 +1005,7 @@ namespace MWWorld if (mWeatherUpdateTime <= 0.0f) { // Expire all regional weather, so that any call to getWeather() will return a new weather ID. - std::map::iterator it = mRegions.begin(); + auto it = mRegions.begin(); for (; it != mRegions.end(); ++it) { it->second.setWeather(invalidWeatherID); @@ -1024,7 +1019,7 @@ namespace MWWorld return false; } - inline bool WeatherManager::updateWeatherRegion(const std::string& playerRegion) + inline bool WeatherManager::updateWeatherRegion(const ESM::RefId& playerRegion) { if (!playerRegion.empty() && playerRegion != mCurrentRegion) { diff --git a/apps/openmw/mwworld/weather.hpp b/apps/openmw/mwworld/weather.hpp index 21fad8ea2b..4ca88ad84b 100644 --- a/apps/openmw/mwworld/weather.hpp +++ b/apps/openmw/mwworld/weather.hpp @@ -8,6 +8,7 @@ #include #include +#include #include "../mwbase/soundmanager.hpp" @@ -157,7 +158,7 @@ namespace MWWorld // Sound effect // This is used for Blight, Ashstorm and Blizzard (Bloodmoon) - std::string mAmbientLoopSoundID; + ESM::RefId mAmbientLoopSoundID; // Is this an ash storm / blight storm? If so, the following will happen: // - The particles and clouds will be oriented so they appear to come from the Red Mountain. @@ -210,7 +211,7 @@ namespace MWWorld // non-zero values. float mThunderFrequency; float mThunderThreshold; - std::string mThunderSoundID[4]; + ESM::RefId mThunderSoundID[4]; float mFlashDecrement; float mFlashBrightness; @@ -284,9 +285,9 @@ namespace MWWorld * @param region that should be changed * @param ID of the weather setting to shift to */ - void changeWeather(std::string_view regionID, const unsigned int weatherID); - void modRegion(std::string_view regionID, const std::vector& chances); - void playerTeleported(const std::string& playerRegion, bool isExterior); + void changeWeather(const ESM::RefId& regionID, const unsigned int weatherID); + void modRegion(const ESM::RefId& regionID, const std::vector& chances); + void playerTeleported(const ESM::RefId& playerRegion, bool isExterior); /** * Per-frame update @@ -356,7 +357,7 @@ namespace MWWorld bool mPrecipitation; osg::Vec3f mStormDirection; - std::string mCurrentRegion; + ESM::RefId mCurrentRegion; float mTimePassed; bool mFastForward; float mWeatherUpdateTime; @@ -365,20 +366,20 @@ namespace MWWorld int mCurrentWeather; int mNextWeather; int mQueuedWeather; - std::map mRegions; + std::map mRegions; MWRender::WeatherResult mResult; MWBase::Sound* mAmbientSound; - std::string mPlayingSoundID; + ESM::RefId mPlayingSoundID; void addWeather( const std::string& name, float dlFactor, float dlOffset, const std::string& particleEffect = ""); void importRegions(); - void regionalWeatherChanged(const std::string& regionID, RegionWeather& region); + void regionalWeatherChanged(const ESM::RefId& regionID, RegionWeather& region); bool updateWeatherTime(); - bool updateWeatherRegion(const std::string& playerRegion); + bool updateWeatherRegion(const ESM::RefId& playerRegion); void updateWeatherTransitions(const float elapsedRealSeconds); void forceWeather(const int weatherID); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 8800199e48..89a43f5b98 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -325,7 +325,7 @@ namespace MWWorld mPlayer->clear(); mPlayer->setCell(nullptr); mPlayer->getPlayer().getRefData() = RefData(); - mPlayer->set(mStore.get().find("player")); + mPlayer->set(mStore.get().find(ESM::RefId::stringRefId("player"))); } mWorldModel.clear(); @@ -480,7 +480,7 @@ namespace MWWorld if (!mStore.get().search(params.first)) { ESM::GameSetting record; - record.mId = params.first; + record.mId = ESM::RefId::stringRefId(params.first); record.mValue = params.second; record.mRecordFlags = 0; mStore.insertStatic(record); @@ -508,10 +508,10 @@ namespace MWWorld for (const auto& params : globals) { - if (!mStore.get().search(params.first)) + if (!mStore.get().search(ESM::RefId::stringRefId(params.first))) { ESM::Global record; - record.mId = params.first; + record.mId = ESM::RefId::stringRefId(params.first); record.mValue = params.second; record.mRecordFlags = 0; mStore.insertStatic(record); @@ -528,10 +528,10 @@ namespace MWWorld for (const auto& params : statics) { - if (!mStore.get().search(params.first)) + if (!mStore.get().search(ESM::RefId::stringRefId(params.first))) { ESM::Static record; - record.mId = params.first; + record.mId = ESM::RefId::stringRefId(params.first); record.mModel = params.second; record.mRecordFlags = 0; mStore.insertStatic(record); @@ -543,10 +543,10 @@ namespace MWWorld for (const auto& params : doors) { - if (!mStore.get().search(params.first)) + if (!mStore.get().search(ESM::RefId::stringRefId(params.first))) { ESM::Door record; - record.mId = params.first; + record.mId = ESM::RefId::stringRefId(params.first); record.mModel = params.second; record.mRecordFlags = 0; mStore.insertStatic(record); @@ -568,15 +568,15 @@ namespace MWWorld const ESM::Cell* World::getExterior(std::string_view cellName) const { // first try named cells - const ESM::Cell* cell = mStore.get().searchExtByName(cellName); + const ESM::Cell* cell = mStore.get().searchExtByName(ESM::RefId::stringRefId(cellName)); if (cell) return cell; // treat "Wilderness" like an empty string - static const std::string defaultName + const std::string defaultName = mStore.get().find("sDefaultCellname")->mValue.getString(); if (Misc::StringUtils::ciEqual(cellName, defaultName)) { - cell = mStore.get().searchExtByName(""); + cell = mStore.get().searchExtByName(ESM::RefId::stringRefId("")); if (cell) return cell; } @@ -656,14 +656,14 @@ namespace MWWorld return mCurrentDate->getMonthName(month); } - std::string_view World::getCellName(const MWWorld::CellStore* cell) const + const std::string& World::getCellName(const MWWorld::CellStore* cell) const { if (!cell) cell = mWorldScene->getCurrentCell(); return getCellName(cell->getCell()); } - std::string_view World::getCellName(const ESM::Cell* cell) const + const std::string& World::getCellName(const ESM::Cell* cell) const { if (cell) { @@ -681,22 +681,21 @@ namespace MWWorld mLocalScripts.remove(ref); } - Ptr World::searchPtr(std::string_view name, bool activeOnly, bool searchInContainers) + Ptr World::searchPtr(const ESM::RefId& name, bool activeOnly, bool searchInContainers) { Ptr ret; // the player is always in an active cell. - if (name == "player") + if (name == ESM::RefId::stringRefId("player")) { return mPlayer->getPlayer(); } - std::string lowerCaseName = Misc::StringUtils::lowerCase(name); for (CellStore* cellstore : mWorldScene->getActiveCells()) { // TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is // in) - Ptr ptr = mWorldModel.getPtr(lowerCaseName, *cellstore, false); + Ptr ptr = mWorldModel.getPtr(name, *cellstore, false); if (!ptr.isEmpty()) return ptr; @@ -704,7 +703,7 @@ namespace MWWorld if (!activeOnly) { - ret = mWorldModel.getPtr(lowerCaseName); + ret = mWorldModel.getPtr(name); if (!ret.isEmpty()) return ret; } @@ -713,23 +712,23 @@ namespace MWWorld { for (CellStore* cellstore : mWorldScene->getActiveCells()) { - Ptr ptr = cellstore->searchInContainer(lowerCaseName); + Ptr ptr = cellstore->searchInContainer(name); if (!ptr.isEmpty()) return ptr; } } - Ptr ptr = mPlayer->getPlayer().getClass().getContainerStore(mPlayer->getPlayer()).search(lowerCaseName); + Ptr ptr = mPlayer->getPlayer().getClass().getContainerStore(mPlayer->getPlayer()).search(name); return ptr; } - Ptr World::getPtr(std::string_view name, bool activeOnly) + Ptr World::getPtr(const ESM::RefId& name, bool activeOnly) { Ptr ret = searchPtr(name, activeOnly); if (!ret.isEmpty()) return ret; - std::string error = "failed to find an instance of object '" + std::string(name) + "'"; + std::string error = "failed to find an instance of object '" + name.getRefIdString() + "'"; if (activeOnly) error += " in active cells"; throw std::runtime_error(error); @@ -744,7 +743,7 @@ namespace MWWorld return mWorldScene->searchPtrViaActorId(actorId); } - Ptr World::searchPtrViaRefNum(const std::string& id, const ESM::RefNum& refNum) + Ptr World::searchPtrViaRefNum(const ESM::RefId& id, const ESM::RefNum& refNum) { return mWorldModel.getPtr(id, refNum); } @@ -804,7 +803,7 @@ namespace MWWorld MWWorld::ContainerStore& container = reference.getClass().getContainerStore(reference); for (MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it) { - std::string_view script = it->getClass().getScript(*it); + auto script = it->getClass().getScript(*it); if (!script.empty()) { MWWorld::Ptr item = *it; @@ -832,7 +831,7 @@ namespace MWWorld if (reference.getCellRef().getRefNum().hasContentFile()) { - int type = mStore.find(Misc::StringUtils::lowerCase(reference.getCellRef().getRefId())); + int type = mStore.find(reference.getCellRef().getRefId()); if (mRendering->pagingEnableObject(type, reference, true)) mWorldScene->reloadTerrain(); } @@ -847,7 +846,7 @@ namespace MWWorld MWWorld::ContainerStore& container = reference.getClass().getContainerStore(reference); for (MWWorld::ContainerStoreIterator it = container.begin(); it != container.end(); ++it) { - std::string_view script = it->getClass().getScript(*it); + auto script = it->getClass().getScript(*it); if (!script.empty()) { MWWorld::Ptr item = *it; @@ -874,7 +873,7 @@ namespace MWWorld if (reference.getCellRef().getRefNum().hasContentFile()) { - int type = mStore.find(Misc::StringUtils::lowerCase(reference.getCellRef().getRefId())); + int type = mStore.find(reference.getCellRef().getRefId()); if (mRendering->pagingEnableObject(type, reference, false)) mWorldScene->reloadTerrain(); } @@ -1131,7 +1130,7 @@ namespace MWWorld && ptr.getRefData().isEnabled()) { mWorldScene->addObjectToScene(ptr); - std::string_view script = ptr.getClass().getScript(ptr); + auto script = ptr.getClass().getScript(ptr); if (!script.empty()) mLocalScripts.add(script, ptr); addContainerScripts(ptr, ptr.getCell()); @@ -1155,11 +1154,11 @@ namespace MWWorld if (!isPlayer && !currCell) throw std::runtime_error( - "Can not move actor \"" + ptr.getCellRef().getRefId() + "\" to another cell: current cell is nullptr"); + "Can not move actor \"" + ptr.getCellRef().getRefId().getRefIdString() + "\" to another cell: current cell is nullptr"); if (!newCell) throw std::runtime_error( - "Can not move actor \"" + ptr.getCellRef().getRefId() + "\" to another cell: new cell is nullptr"); + "Can not move actor \"" + ptr.getCellRef().getRefId().getRefIdString() + "\" to another cell: new cell is nullptr"); if (currCell != newCell) { @@ -1169,7 +1168,7 @@ namespace MWWorld { if (!newCell->isExterior()) { - changeToInteriorCell(Misc::StringUtils::lowerCase(newCell->getCell()->mName), pos, false); + changeToInteriorCell(newCell->getCell()->mName, pos, false); removeContainerScripts(getPlayerPtr()); } else @@ -1192,7 +1191,7 @@ namespace MWWorld if (newPtr.getRefData().isEnabled()) mWorldScene->addObjectToScene(newPtr); - std::string_view script = newPtr.getClass().getScript(newPtr); + auto script = newPtr.getClass().getScript(newPtr); if (!script.empty()) { mLocalScripts.add(script, newPtr); @@ -1222,7 +1221,7 @@ namespace MWWorld MWBase::MechanicsManager* mechMgr = MWBase::Environment::get().getMechanicsManager(); mechMgr->updateCell(ptr, newPtr); - std::string_view script = ptr.getClass().getScript(ptr); + auto script = ptr.getClass().getScript(ptr); if (!script.empty()) { mLocalScripts.remove(ptr); @@ -1625,14 +1624,14 @@ namespace MWWorld if (state == MWWorld::DoorState::Opening) { - const std::string& openSound = ref->mOpenSound; + const ESM::RefId& openSound = ref->mOpenSound; if (!openSound.empty() && MWBase::Environment::get().getSoundManager()->getSoundPlaying(door, openSound)) MWBase::Environment::get().getSoundManager()->stopSound3D(door, openSound); } else if (state == MWWorld::DoorState::Closing) { - const std::string& closeSound = ref->mCloseSound; + const ESM::RefId& closeSound = ref->mCloseSound; if (!closeSound.empty() && MWBase::Environment::get().getSoundManager()->getSoundPlaying(door, closeSound)) MWBase::Environment::get().getSoundManager()->stopSound3D(door, closeSound); @@ -1760,13 +1759,13 @@ namespace MWWorld { bool update = false; - if (Misc::StringUtils::ciEqual(record.mId, "player")) + if (ESM::RefId::ciEqual(record.mId, ESM::RefId::stringRefId("player"))) { const ESM::NPC* player = mPlayer->getPlayer().get()->mBase; - update = record.isMale() != player->isMale() || !Misc::StringUtils::ciEqual(record.mRace, player->mRace) - || !Misc::StringUtils::ciEqual(record.mHead, player->mHead) - || !Misc::StringUtils::ciEqual(record.mHair, player->mHair); + update = record.isMale() != player->isMale() || !ESM::RefId::ciEqual(record.mRace, player->mRace) + || !ESM::RefId::ciEqual(record.mHead, player->mHead) + || !ESM::RefId::ciEqual(record.mHair, player->mHair); } const ESM::NPC* ret = mStore.insert(record); if (update) @@ -1862,7 +1861,7 @@ namespace MWWorld void World::preloadSpells() { - const std::string& selectedSpell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); + const ESM::RefId& selectedSpell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); if (!selectedSpell.empty()) { const ESM::Spell* spell = mStore.get().search(selectedSpell); @@ -1873,7 +1872,7 @@ namespace MWWorld = MWBase::Environment::get().getWindowManager()->getSelectedEnchantItem(); if (!selectedEnchantItem.isEmpty()) { - std::string_view enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem); + const ESM::RefId& enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem); if (!enchantId.empty()) { const ESM::Enchantment* ench = mStore.get().search(enchantId); @@ -1884,7 +1883,7 @@ namespace MWWorld const MWWorld::Ptr& selectedWeapon = MWBase::Environment::get().getWindowManager()->getSelectedWeapon(); if (!selectedWeapon.isEmpty()) { - std::string_view enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon); + const ESM::RefId& enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon); if (!enchantId.empty()) { const ESM::Enchantment* ench = mStore.get().search(enchantId); @@ -2043,19 +2042,19 @@ namespace MWWorld return mWeatherManager->getNightDayMode(); } - void World::changeWeather(std::string_view region, const unsigned int id) + void World::changeWeather(const ESM::RefId& region, const unsigned int id) { mWeatherManager->changeWeather(region, id); } - void World::modRegion(std::string_view regionid, const std::vector& chances) + void World::modRegion(const ESM::RefId& regionid, const std::vector& chances) { mWeatherManager->modRegion(regionid, chances); } osg::Vec2f World::getNorthVector(const CellStore* cell) { - MWWorld::ConstPtr northmarker = cell->searchConst("northmarker"); + MWWorld::ConstPtr northmarker = cell->searchConst(ESM::RefId::stringRefId("northmarker")); if (northmarker.isEmpty()) return osg::Vec2f(0, 1); @@ -2139,7 +2138,7 @@ namespace MWWorld void World::PCDropped(const Ptr& item) { - std::string_view script = item.getClass().getScript(item); + auto script = item.getClass().getScript(item); // Set OnPCDrop Variable on item's script, if it has a script with that variable declared if (!script.empty()) @@ -2216,7 +2215,7 @@ namespace MWWorld { mWorldScene->addObjectToScene(dropped); } - std::string_view script = dropped.getClass().getScript(dropped); + auto script = dropped.getClass().getScript(dropped); if (!script.empty()) { mLocalScripts.add(script, dropped); @@ -2437,7 +2436,7 @@ namespace MWWorld void World::setupPlayer() { - const ESM::NPC* player = mStore.get().find("player"); + const ESM::NPC* player = mStore.get().find(ESM::RefId::stringRefId("player")); if (!mPlayer) mPlayer = std::make_unique(player); else @@ -2635,8 +2634,9 @@ namespace MWWorld if (actor == getPlayerPtr()) MWBase::Environment::get().getWindowManager()->activateHitOverlay(false); - if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor, "Health Damage")) - MWBase::Environment::get().getSoundManager()->playSound3D(actor, "Health Damage", 1.0f, 1.0f); + auto healthDamage = ESM::RefId::stringRefId("Health Damage"); + if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor,healthDamage)) + MWBase::Environment::get().getSoundManager()->playSound3D(actor, healthDamage, 1.0f, 1.0f); } } } @@ -2668,8 +2668,9 @@ namespace MWWorld if (actor == getPlayerPtr()) MWBase::Environment::get().getWindowManager()->activateHitOverlay(false); - if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor, "Health Damage")) - MWBase::Environment::get().getSoundManager()->playSound3D(actor, "Health Damage", 1.0f, 1.0f); + auto healthDamage = ESM::RefId::stringRefId("Health Damage"); + if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor, healthDamage )) + MWBase::Environment::get().getSoundManager()->playSound3D(actor, healthDamage, 1.0f, 1.0f); } } } @@ -2718,7 +2719,7 @@ namespace MWWorld if (ptr.getClass().getCapacity(ptr) <= 0.f) return true; - if (Misc::StringUtils::ciEqual(ptr.getCellRef().getOwner(), mOwner.getCellRef().getRefId())) + if (ESM::RefId::ciEqual(ptr.getCellRef().getOwner(), mOwner.getCellRef().getRefId())) mOut.push_back(ptr); return true; @@ -2740,7 +2741,7 @@ namespace MWWorld { cellstore->forEach([&](const auto& ptr) { if (ptr.getRefData().getBaseNode() - && Misc::StringUtils::ciEqual(ptr.getCellRef().getOwner(), npc.getCellRef().getRefId())) + && ESM::RefId::ciEqual(ptr.getCellRef().getOwner(), npc.getCellRef().getRefId())) out.push_back(ptr); return true; }); @@ -2864,12 +2865,13 @@ namespace MWWorld const ESM::Cell* ext = getExterior(name); if (!ext) { - size_t comma = name.find(','); + std::string cellName = std::string(name); + size_t comma = cellName.find(','); if (comma != std::string::npos) { int x, y; - std::from_chars_result xResult = std::from_chars(name.data(), name.data() + comma, x); - std::from_chars_result yResult = std::from_chars(name.data() + comma + 1, name.data() + name.size(), y); + std::from_chars_result xResult = std::from_chars(cellName.data(), cellName.data() + comma, x); + std::from_chars_result yResult = std::from_chars(cellName.data() + comma + 1, cellName.data() + cellName.size(), y); if (xResult.ec == std::errc::result_out_of_range || yResult.ec == std::errc::result_out_of_range) throw std::runtime_error("Cell coordinates out of range."); else if (xResult.ec == std::errc{} && yResult.ec == std::errc{}) @@ -2998,7 +3000,7 @@ namespace MWWorld MWWorld::SpellCastState result = MWWorld::SpellCastState::Success; bool isPlayer = (actor == getPlayerPtr()); - const std::string& selectedSpell = stats.getSpells().getSelectedSpell(); + const ESM::RefId& selectedSpell = stats.getSpells().getSelectedSpell(); if (!selectedSpell.empty()) { @@ -3135,7 +3137,7 @@ namespace MWWorld } } - const std::string& selectedSpell = stats.getSpells().getSelectedSpell(); + const ESM::RefId& selectedSpell = stats.getSpells().getSelectedSpell(); MWMechanics::CastSpell cast(actor, target, false, manualSpell); cast.mHitPosition = hitPosition; @@ -3201,7 +3203,7 @@ namespace MWWorld } void World::launchMagicBolt( - const std::string& spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection, int slot) + const ESM::RefId& spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection, int slot) { mProjectileManager->launchMagicBolt(spellId, caster, fallbackDirection, slot); } @@ -3290,7 +3292,7 @@ namespace MWWorld { currentCells = nextCells; nextCells.clear(); - for (const std::string& currentCell : currentCells) + for (const auto& currentCell : currentCells) { MWWorld::CellStore* next = mWorldModel.getInterior(currentCell); if (!next) @@ -3324,7 +3326,7 @@ namespace MWWorld return false; } - MWWorld::ConstPtr World::getClosestMarker(const MWWorld::ConstPtr& ptr, std::string_view id) + MWWorld::ConstPtr World::getClosestMarker(const MWWorld::ConstPtr& ptr, const ESM::RefId& id) { if (ptr.getCell()->isExterior()) { @@ -3344,7 +3346,7 @@ namespace MWWorld { currentCells = nextCells; nextCells.clear(); - for (const std::string& cell : currentCells) + for (const auto& cell : currentCells) { MWWorld::CellStore* next = mWorldModel.getInterior(cell); checkedCells.insert(cell); @@ -3370,7 +3372,7 @@ namespace MWWorld } else { - const std::string& dest = ref.mRef.getDestCell(); + const auto& dest = ref.mRef.getDestCell(); if (!checkedCells.count(dest) && !currentCells.count(dest)) nextCells.insert(dest); } @@ -3380,7 +3382,7 @@ namespace MWWorld return MWWorld::Ptr(); } - MWWorld::ConstPtr World::getClosestMarkerFromExteriorPosition(const osg::Vec3f& worldPos, std::string_view id) + MWWorld::ConstPtr World::getClosestMarkerFromExteriorPosition(const osg::Vec3f& worldPos, const ESM::RefId& id) { MWWorld::ConstPtr closestMarker; float closestDistance = std::numeric_limits::max(); @@ -3422,7 +3424,7 @@ namespace MWWorld mWorldModel.recharge(duration); } - void World::teleportToClosestMarker(const MWWorld::Ptr& ptr, std::string_view id) + void World::teleportToClosestMarker(const MWWorld::Ptr& ptr, const ESM::RefId& id) { MWWorld::ConstPtr closestMarker = getClosestMarker(ptr, id); @@ -3432,7 +3434,7 @@ namespace MWWorld return; } - std::string_view cellName; + std::string cellName; if (!closestMarker.mCell->isExterior()) cellName = closestMarker.mCell->getCell()->mName; @@ -3447,7 +3449,7 @@ namespace MWWorld { mPlayer->setTeleported(false); - const std::string playerRegion = Misc::StringUtils::lowerCase(getPlayerPtr().getCell()->getCell()->mRegion); + const ESM::RefId& playerRegion = getPlayerPtr().getCell()->getCell()->mRegion; mWeatherManager->playerTeleported(playerRegion, isExterior); } @@ -3632,7 +3634,7 @@ namespace MWWorld void World::confiscateStolenItems(const Ptr& ptr) { - MWWorld::ConstPtr prisonMarker = getClosestMarker(ptr, "prisonmarker"); + MWWorld::ConstPtr prisonMarker = getClosestMarker(ptr, ESM::RefId::stringRefId("prisonmarker")); if (prisonMarker.isEmpty()) { Log(Debug::Warning) << "Failed to confiscate items: no closest prison marker found."; @@ -3651,7 +3653,7 @@ namespace MWWorld return; } - MWWorld::Ptr closestChest = prison->search("stolen_goods"); + MWWorld::Ptr closestChest = prison->search(ESM::RefId::stringRefId("stolen_goods")); if (!closestChest.isEmpty()) // Found a close chest { MWBase::Environment::get().getMechanicsManager()->confiscateStolenItems(ptr, closestChest); @@ -3740,7 +3742,7 @@ namespace MWWorld return file; } - void World::spawnRandomCreature(std::string_view creatureList) + void World::spawnRandomCreature(const ESM::RefId& creatureList) { const ESM::CreatureLevList* list = mStore.get().find(creatureList); @@ -3749,7 +3751,7 @@ namespace MWWorld for (int i = 0; i < numCreatures; ++i) { - std::string_view selectedCreature = MWMechanics::getLevelledItem(list, true, mPrng); + const ESM::RefId& selectedCreature = MWMechanics::getLevelledItem(list, true, mPrng); if (selectedCreature.empty()) continue; @@ -3849,7 +3851,7 @@ namespace MWWorld return mPhysics->getHitDistance(weaponPos, target) - halfExtents.y(); } - void preload(MWWorld::Scene* scene, const ESMStore& store, std::string_view obj) + void preload(MWWorld::Scene* scene, const ESMStore& store, const ESM::RefId& obj) { if (obj.empty()) return; @@ -3873,7 +3875,7 @@ namespace MWWorld if (MWMechanics::isSummoningEffect(effectInfo.mEffectID)) { - preload(mWorldScene.get(), mStore, "VFX_Summon_Start"); + preload(mWorldScene.get(), mStore, ESM::RefId::stringRefId("VFX_Summon_Start")); preload(mWorldScene.get(), mStore, MWMechanics::getSummonedCreature(effectInfo.mEffectID)); } @@ -3957,7 +3959,7 @@ namespace MWWorld mRendering->skySetDate(currentDate.mDay, currentDate.mMonth); } - std::vector World::getAll(const std::string& id) + std::vector World::getAll(const ESM::RefId& id) { return mWorldModel.getAll(id); } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index d68b17d37e..ee3bd26b54 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -45,6 +45,7 @@ namespace SceneUtil namespace ESM { struct Position; + struct RefId; } namespace Files @@ -184,8 +185,8 @@ namespace MWWorld float feetToGameUnits(float feet); float getActivationDistancePlusTelekinesis(); - MWWorld::ConstPtr getClosestMarker(const MWWorld::ConstPtr& ptr, std::string_view id); - MWWorld::ConstPtr getClosestMarkerFromExteriorPosition(const osg::Vec3f& worldPos, std::string_view id); + MWWorld::ConstPtr getClosestMarker(const MWWorld::ConstPtr& ptr, const ESM::RefId& id); + MWWorld::ConstPtr getClosestMarkerFromExteriorPosition(const osg::Vec3f& worldPos, const ESM::RefId& id); public: WorldModel& getWorldModel() { return mWorldModel; } @@ -266,28 +267,28 @@ namespace MWWorld char getGlobalVariableType(std::string_view name) const override; ///< Return ' ', if there is no global variable with this name. - std::string_view getCellName(const MWWorld::CellStore* cell = nullptr) const override; + const std::string& getCellName(const MWWorld::CellStore* cell = nullptr) const override; ///< Return name of the cell. /// /// \note If cell==0, the cell the player is currently in will be used instead to /// generate a name. - std::string_view getCellName(const ESM::Cell* cell) const override; + const std::string& getCellName(const ESM::Cell* cell) const override; void removeRefScript(MWWorld::RefData* ref) override; //< Remove the script attached to ref from mLocalScripts - Ptr getPtr(std::string_view name, bool activeOnly) override; + Ptr getPtr(const ESM::RefId& name, bool activeOnly) override; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells. - Ptr searchPtr(std::string_view name, bool activeOnly, bool searchInContainers = false) override; + Ptr searchPtr(const ESM::RefId& name, bool activeOnly, bool searchInContainers = false) override; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do not search inactive cells. Ptr searchPtrViaActorId(int actorId) override; ///< Search is limited to the active cells. - Ptr searchPtrViaRefNum(const std::string& id, const ESM::RefNum& refNum) override; + Ptr searchPtrViaRefNum(const ESM::RefId& id, const ESM::RefNum& refNum) override; MWWorld::Ptr findContainer(const MWWorld::ConstPtr& ptr) override; ///< Return a pointer to a liveCellRef which contains \a ptr. @@ -319,7 +320,7 @@ namespace MWWorld bool toggleSky() override; ///< \return Resulting mode - void changeWeather(std::string_view region, const unsigned int id) override; + void changeWeather(const ESM::RefId& region, const unsigned int id) override; int getCurrentWeather() const override; @@ -335,7 +336,7 @@ namespace MWWorld void setMoonColour(bool red) override; - void modRegion(std::string_view regionid, const std::vector& chances) override; + void modRegion(const ESM::RefId& regionid, const std::vector& chances) override; float getTimeScaleFactor() const override; @@ -646,7 +647,7 @@ namespace MWWorld */ void castSpell(const MWWorld::Ptr& actor, bool manualSpell = false) override; - void launchMagicBolt(const std::string& spellId, const MWWorld::Ptr& caster, + void launchMagicBolt(const ESM::RefId& spellId, const MWWorld::Ptr& caster, const osg::Vec3f& fallbackDirection, int slot) override; void launchProjectile(MWWorld::Ptr& actor, MWWorld::Ptr& projectile, const osg::Vec3f& worldPos, const osg::Quat& orient, MWWorld::Ptr& bow, float speed, float attackStrength) override; @@ -667,7 +668,7 @@ namespace MWWorld /// Teleports \a ptr to the closest reference of \a id (e.g. DivineMarker, PrisonMarker, TempleMarker) /// @note id must be lower case - void teleportToClosestMarker(const MWWorld::Ptr& ptr, std::string_view id) override; + void teleportToClosestMarker(const MWWorld::Ptr& ptr, const ESM::RefId& id) override; /// List all references (filtered by \a type) detected by \a ptr. The range /// is determined by the current magnitude of the "Detect X" magic effect belonging to \a type. @@ -685,7 +686,7 @@ namespace MWWorld void goToJail() override; /// Spawn a random creature from a levelled list next to the player - void spawnRandomCreature(std::string_view creatureList) override; + void spawnRandomCreature(const ESM::RefId& creatureList) override; /// Spawn a blood effect for \a ptr at \a worldPosition void spawnBloodEffect(const MWWorld::Ptr& ptr, const osg::Vec3f& worldPosition) override; @@ -752,7 +753,7 @@ namespace MWWorld void reportStats(unsigned int frameNumber, osg::Stats& stats) const override; - std::vector getAll(const std::string& id) override; + std::vector getAll(const ESM::RefId& id) override; Misc::Rng::Generator& getPrng() override; diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 2da2d76c8f..df26abe14a 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -18,7 +18,7 @@ namespace { template - bool forEachInStore(const std::string& id, Visitor&& visitor, std::map& cellStore) + bool forEachInStore(const ESM::RefId& id, Visitor&& visitor, std::map& cellStore) { for (auto& cell : cellStore) { @@ -62,11 +62,10 @@ MWWorld::CellStore* MWWorld::WorldModel::getCellStore(const ESM::Cell* cell) { if (cell->mData.mFlags & ESM::Cell::Interior) { - std::string lowerName(Misc::StringUtils::lowerCase(cell->mName)); - std::map::iterator result = mInteriors.find(lowerName); + auto result = mInteriors.find(cell->mName); if (result == mInteriors.end()) - result = mInteriors.emplace(std::move(lowerName), CellStore(cell, mStore, mReaders)).first; + result = mInteriors.emplace(std::move(cell->mName), CellStore(cell, mStore, mReaders)).first; return &result->second; } @@ -88,11 +87,11 @@ void MWWorld::WorldModel::clear() { mInteriors.clear(); mExteriors.clear(); - std::fill(mIdCache.begin(), mIdCache.end(), std::make_pair("", (MWWorld::CellStore*)nullptr)); + std::fill(mIdCache.begin(), mIdCache.end(), std::make_pair(ESM::RefId::sEmpty, (MWWorld::CellStore*)nullptr)); mIdCacheIndex = 0; } -MWWorld::Ptr MWWorld::WorldModel::getPtrAndCache(std::string_view name, CellStore& cellStore) +MWWorld::Ptr MWWorld::WorldModel::getPtrAndCache(const ESM::RefId& name, CellStore& cellStore) { Ptr ptr = getPtr(name, cellStore); @@ -130,7 +129,7 @@ MWWorld::WorldModel::WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCach , mIdCacheIndex(0) { int cacheSize = std::clamp(Settings::Manager::getInt("pointers cache size", "Cells"), 40, 1000); - mIdCache = IdCache(cacheSize, std::pair("", (CellStore*)nullptr)); + mIdCache = IdCache(cacheSize, std::pair(ESM::RefId::sEmpty, (CellStore*)nullptr)); } MWWorld::CellStore* MWWorld::WorldModel::getExterior(int x, int y) @@ -172,14 +171,13 @@ MWWorld::CellStore* MWWorld::WorldModel::getExterior(int x, int y) MWWorld::CellStore* MWWorld::WorldModel::getInterior(std::string_view name) { - std::string lowerName = Misc::StringUtils::lowerCase(name); - std::map::iterator result = mInteriors.find(lowerName); + auto result = mInteriors.find(std::string(name)); if (result == mInteriors.end()) { - const ESM::Cell* cell = mStore.get().find(lowerName); + const ESM::Cell* cell = mStore.get().find(ESM::RefId::stringRefId(name)); - result = mInteriors.emplace(std::move(lowerName), CellStore(cell, mStore, mReaders)).first; + result = mInteriors.emplace(std::move(name), CellStore(cell, mStore, mReaders)).first; } if (result->second.getState() != CellStore::State_Loaded) @@ -224,7 +222,7 @@ MWWorld::CellStore* MWWorld::WorldModel::getCell(const ESM::CellId& id) return getInterior(id.mWorldspace); } -MWWorld::Ptr MWWorld::WorldModel::getPtr(std::string_view name, CellStore& cell, bool searchInContainers) +MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name, CellStore& cell, bool searchInContainers) { if (cell.getState() == CellStore::State_Unloaded) cell.preload(); @@ -250,7 +248,7 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(std::string_view name, CellStore& cell, return Ptr(); } -MWWorld::Ptr MWWorld::WorldModel::getPtr(const std::string& name) +MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name) { // First check the cache for (IdCache::iterator iter(mIdCache.begin()); iter != mIdCache.end(); ++iter) @@ -272,7 +270,7 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(const std::string& name) return ptr; } - for (std::map::iterator iter = mInteriors.begin(); iter != mInteriors.end(); ++iter) + for (auto iter = mInteriors.begin(); iter != mInteriors.end(); ++iter) { Ptr ptr = getPtrAndCache(name, iter->second); if (!ptr.isEmpty()) @@ -307,7 +305,7 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(const std::string& name) return Ptr(); } -MWWorld::Ptr MWWorld::WorldModel::getPtr(const std::string& id, const ESM::RefNum& refNum) +MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& id, const ESM::RefNum& refNum) { for (auto& pair : mInteriors) { @@ -324,7 +322,7 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(const std::string& id, const ESM::RefNu return Ptr(); } -MWWorld::Ptr MWWorld::WorldModel::getPtr(CellStore& cellStore, const std::string& id, const ESM::RefNum& refNum) +MWWorld::Ptr MWWorld::WorldModel::getPtr(CellStore& cellStore, const ESM::RefId& id, const ESM::RefNum& refNum) { if (cellStore.getState() == CellStore::State_Unloaded) cellStore.preload(); @@ -338,7 +336,7 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(CellStore& cellStore, const std::string return cellStore.searchViaRefNum(refNum); } -void MWWorld::WorldModel::getExteriorPtrs(std::string_view name, std::vector& out) +void MWWorld::WorldModel::getExteriorPtrs(const ESM::RefId& name, std::vector& out) { const MWWorld::Store& cells = mStore.get(); for (MWWorld::Store::iterator iter = cells.extBegin(); iter != cells.extEnd(); ++iter) @@ -352,7 +350,7 @@ void MWWorld::WorldModel::getExteriorPtrs(std::string_view name, std::vector& out) +void MWWorld::WorldModel::getInteriorPtrs(const ESM::RefId& name, std::vector& out) { const MWWorld::Store& cells = mStore.get(); for (MWWorld::Store::iterator iter = cells.intBegin(); iter != cells.intEnd(); ++iter) @@ -366,7 +364,7 @@ void MWWorld::WorldModel::getInteriorPtrs(const std::string& name, std::vector MWWorld::WorldModel::getAll(const std::string& id) +std::vector MWWorld::WorldModel::getAll(const ESM::RefId& id) { PtrCollector visitor; if (forEachInStore(id, visitor, mInteriors)) @@ -378,7 +376,7 @@ int MWWorld::WorldModel::countSavedGameRecords() const { int count = 0; - for (std::map::const_iterator iter(mInteriors.begin()); iter != mInteriors.end(); ++iter) + for (auto iter(mInteriors.begin()); iter != mInteriors.end(); ++iter) if (iter->second.hasState()) ++count; @@ -399,7 +397,7 @@ void MWWorld::WorldModel::write(ESM::ESMWriter& writer, Loading::Listener& progr progress.increaseProgress(); } - for (std::map::iterator iter(mInteriors.begin()); iter != mInteriors.end(); ++iter) + for (auto iter(mInteriors.begin()); iter != mInteriors.end(); ++iter) if (iter->second.hasState()) { writeCell(writer, iter->second); diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index ce36cbd9e1..96907639bf 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -29,7 +29,7 @@ namespace MWWorld /// \brief Cell container class WorldModel { - typedef std::vector> IdCache; + typedef std::vector> IdCache; const MWWorld::ESMStore& mStore; ESM::ReadersCache& mReaders; mutable std::map mInteriors; @@ -42,9 +42,9 @@ namespace MWWorld CellStore* getCellStore(const ESM::Cell* cell); - Ptr getPtrAndCache(std::string_view name, CellStore& cellStore); + Ptr getPtrAndCache(const ESM::RefId& name, CellStore& cellStore); - Ptr getPtr(CellStore& cellStore, const std::string& id, const ESM::RefNum& refNum); + Ptr getPtr(CellStore& cellStore, const ESM::RefId& id, const ESM::RefNum& refNum); void writeCell(ESM::ESMWriter& writer, CellStore& cell) const; @@ -59,14 +59,14 @@ namespace MWWorld CellStore* getCell(const ESM::CellId& id); - Ptr getPtr(std::string_view name, CellStore& cellStore, bool searchInContainers = false); + Ptr getPtr(const ESM::RefId& name, CellStore& cellStore, bool searchInContainers = false); ///< \param searchInContainers Only affect loaded cells. /// @note name must be lower case /// @note name must be lower case - Ptr getPtr(const std::string& name); + Ptr getPtr(const ESM::RefId& name); - Ptr getPtr(const std::string& id, const ESM::RefNum& refNum); + Ptr getPtr(const ESM::RefId& id, const ESM::RefNum& refNum); void rest(double hours); void recharge(float duration); @@ -74,14 +74,14 @@ namespace MWWorld /// Get all Ptrs referencing \a name in exterior cells /// @note Due to the current implementation of getPtr this only supports one Ptr per cell. /// @note name must be lower case - void getExteriorPtrs(std::string_view name, std::vector& out); + void getExteriorPtrs(const ESM::RefId& name, std::vector& out); /// Get all Ptrs referencing \a name in interior cells /// @note Due to the current implementation of getPtr this only supports one Ptr per cell. /// @note name must be lower case - void getInteriorPtrs(const std::string& name, std::vector& out); + void getInteriorPtrs(const ESM::RefId& name, std::vector& out); - std::vector getAll(const std::string& id); + std::vector getAll(const ESM::RefId& id); int countSavedGameRecords() const; diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index de49416a3c..243ea5841c 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -80,7 +80,7 @@ add_component_dir (to_utf8 to_utf8 ) -add_component_dir(esm attr common defs esmcommon records util luascripts format) +add_component_dir(esm attr common defs esmcommon records util luascripts format refid) add_component_dir(fx pass technique lexer widgets stateupdater) diff --git a/components/compiler/context.hpp b/components/compiler/context.hpp index b9b0aa477b..ab600b10dd 100644 --- a/components/compiler/context.hpp +++ b/components/compiler/context.hpp @@ -2,6 +2,10 @@ #define COMPILER_CONTEXT_H_INCLUDED #include +namespace ESM +{ + struct RefId; +} namespace Compiler { @@ -29,13 +33,13 @@ namespace Compiler virtual char getGlobalType(const std::string& name) const = 0; ///< 'l: long, 's': short, 'f': float, ' ': does not exist. - virtual std::pair getMemberType(const std::string& name, const std::string& id) const = 0; + virtual std::pair getMemberType(const std::string& name, const ESM::RefId& id) const = 0; ///< Return type of member variable \a name in script \a id or in script of reference of /// \a id /// \return first: 'l: long, 's': short, 'f': float, ' ': does not exist. /// second: true: script of reference - virtual bool isId(const std::string& name) const = 0; + virtual bool isId(const ESM::RefId& name) const = 0; ///< Does \a name match an ID, that can be referenced? }; } diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index dddd487c9d..90d070992d 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "context.hpp" #include "discardparser.hpp" @@ -204,13 +205,13 @@ namespace Compiler mMemberOp = false; std::string name2 = Misc::StringUtils::lowerCase(name); - std::string id = Misc::StringUtils::lowerCase(mExplicit); + auto id = ESM::RefId::stringRefId(mExplicit); std::pair type = getContext().getMemberType(name2, id); if (type.first != ' ') { - Generator::fetchMember(mCode, mLiterals, type.first, name2, id, !type.second); + Generator::fetchMember(mCode, mLiterals, type.first, name2, id.getRefIdString(), !type.second); mNextOperand = false; mExplicit.clear(); @@ -302,31 +303,30 @@ namespace Compiler { start(); - std::string name2 = Misc::StringUtils::lowerCase(name); - char type = mLocals.getType(name2); + char type = mLocals.getType(name); if (type != ' ') { - Generator::fetchLocal(mCode, type, mLocals.getIndex(name2)); + Generator::fetchLocal(mCode, type, mLocals.getIndex(name)); mNextOperand = false; mOperands.push_back(type == 'f' ? 'f' : 'l'); return true; } - type = getContext().getGlobalType(name2); + type = getContext().getGlobalType(name); if (type != ' ') { - Generator::fetchGlobal(mCode, mLiterals, type, name2); + Generator::fetchGlobal(mCode, mLiterals, type, name); mNextOperand = false; mOperands.push_back(type == 'f' ? 'f' : 'l'); return true; } - if (mExplicit.empty() && getContext().isId(name2)) + if (mExplicit.empty() && getContext().isId(ESM::RefId::stringRefId(name))) { - mExplicit = name2; + mExplicit = name; return true; } @@ -334,7 +334,7 @@ namespace Compiler // Convert the string to a number even if it's impossible and use it as a number literal. // Can't use stof/atof or to_string out of locale concerns. float number; - std::stringstream stream(name2); + std::stringstream stream(name); stream >> number; stream.str(std::string()); stream.clear(); diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 8a6074303c..36490fadf6 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "context.hpp" #include "declarationparser.hpp" @@ -126,7 +127,7 @@ namespace Compiler if (mState == SetMemberVarState) { mMemberName = Misc::StringUtils::lowerCase(name); - std::pair type = getContext().getMemberType(mMemberName, mName); + std::pair type = getContext().getMemberType(mMemberName, ESM::RefId::stringRefId(mName)); if (type.first != ' ') { @@ -169,7 +170,7 @@ namespace Compiler return true; } - if (mState == BeginState && getContext().isId(name)) + if (mState == BeginState && getContext().isId(ESM::RefId::stringRefId(name))) { mState = PotentialExplicitState; mExplicit = Misc::StringUtils::lowerCase(name); @@ -224,7 +225,7 @@ namespace Compiler if (mState == SetMemberVarState) { mMemberName = loc.mLiteral; - std::pair type = getContext().getMemberType(mMemberName, mName); + std::pair type = getContext().getMemberType(mMemberName, ESM::RefId::stringRefId(mName)); if (type.first != ' ') { diff --git a/components/compiler/streamerrorhandler.cpp b/components/compiler/streamerrorhandler.cpp index e72eb6fdb1..b198cf05d1 100644 --- a/components/compiler/streamerrorhandler.cpp +++ b/components/compiler/streamerrorhandler.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "tokenloc.hpp" diff --git a/components/esm/luascripts.cpp b/components/esm/luascripts.cpp index f37fcae5c6..55a4b8c423 100644 --- a/components/esm/luascripts.cpp +++ b/components/esm/luascripts.cpp @@ -74,9 +74,11 @@ void ESM::LuaScriptsCfg::load(ESMReader& esm) esm.getSubHeader(); script.mRecords.emplace_back(); ESM::LuaScriptCfg::PerRecordCfg& recordCfg = script.mRecords.back(); - recordCfg.mRecordId.resize(esm.getSubSize() - 1); + std::string recordIdString; + recordIdString.resize(esm.getSubSize() - 1); recordCfg.mAttach = readBool(esm); - esm.getExact(recordCfg.mRecordId.data(), static_cast(recordCfg.mRecordId.size())); + esm.getExact(recordIdString.data(), static_cast(recordIdString.size())); + recordCfg.mRecordId = ESM::RefId::stringRefId(recordIdString); recordCfg.mInitializationData = loadLuaBinaryData(esm); } while (esm.isNextSub("LUAI")) @@ -142,7 +144,7 @@ void ESM::LuaScriptsCfg::save(ESMWriter& esm) const { esm.startSubRecord("LUAR"); esm.writeT(recordCfg.mAttach ? 1 : 0); - esm.write(recordCfg.mRecordId.data(), recordCfg.mRecordId.size()); + esm.write(recordCfg.mRecordId.getRefIdString().data(), recordCfg.mRecordId.getRefIdString().size()); esm.endRecord("LUAR"); saveLuaBinaryData(esm, recordCfg.mInitializationData); } diff --git a/components/esm/luascripts.hpp b/components/esm/luascripts.hpp index 06ca5a65e5..219376afc9 100644 --- a/components/esm/luascripts.hpp +++ b/components/esm/luascripts.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace ESM { @@ -32,7 +33,7 @@ namespace ESM struct PerRecordCfg { bool mAttach; // true - attach, false - don't attach (overrides previous attach) - std::string mRecordId; + ESM::RefId mRecordId; // Initialization data for this specific record. If empty than LuaScriptCfg::mInitializationData is used. std::string mInitializationData; }; diff --git a/components/esm/refid.cpp b/components/esm/refid.cpp new file mode 100644 index 0000000000..99b80f465f --- /dev/null +++ b/components/esm/refid.cpp @@ -0,0 +1,42 @@ +#include "refid.hpp" + +#include + +#include "components/misc/strings/algorithm.hpp" + +bool ESM::RefId::ciEqual(const RefId & left, const RefId & right) +{ + return Misc::StringUtils::ciEqual(left.mId, right.mId); +} + +namespace ESM +{ + std::ostream& operator<<(std::ostream& os, const ESM::RefId& refId) + { + os << refId.getRefIdString(); + return os; + } +} + +ESM::RefId ESM::RefId::stringRefId(const std::string_view & id) +{ + RefId newRefId; + newRefId.mId = Misc::StringUtils::lowerCase(id); + return newRefId; +} + +const ESM::RefId ESM::RefId::sEmpty = ESM::RefId::stringRefId(""); + +//template<> +//std::size_t std::hash::operator()(const ESM::RefId& k) const +//{ +// using std::size_t; +// using std::hash; +// using std::string; +// +// // Compute individual hash values for first, +// // second and third and combine them using XOR +// // and bit shifting: +// +// return hash()(k.getRefIdString()); +//} diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp new file mode 100644 index 0000000000..116ff17574 --- /dev/null +++ b/components/esm/refid.hpp @@ -0,0 +1,60 @@ +#ifndef OPENMW_COMPONENTS_ESM_REFID_HPP +#define OPENMW_COMPONENTS_ESM_REFID_HPP +#include +#include +#include + +namespace ESM +{ + struct RefId + { + const static RefId sEmpty; + void clear() { mId.clear(); } + bool empty() const { return mId.empty(); } + void swap(RefId& rhs) { mId.swap(rhs.mId); } + bool operator==(const RefId& rhs) const { return mId == rhs.mId; } + void operator=(const RefId& rhs) { mId = rhs.mId; } + bool operator <(const RefId& rhs) const + { + return mId < rhs.mId; + } + bool operator >(const RefId& rhs) const + { + return mId > rhs.mId; + } + + friend std::ostream& operator<<(std::ostream& os, const RefId& dt); + + static RefId stringRefId( + const std::string_view& id); // This makes it very visible the places where I had to convert from string to Refid + + std::string& getRefIdString() { return mId; } // Same thing + const std::string& getRefIdString() const { return mId; } // Same thing + + static bool ciEqual(const RefId& left, const RefId& right); + + private: + std::string mId; + }; +} + +namespace std { + + template <> + struct hash + { + std::size_t operator()(const ESM::RefId& k) const + { + using std::size_t; + using std::hash; + using std::string; + + // Compute individual hash values for first, + // second and third and combine them using XOR + // and bit shifting: + + return hash()(k.getRefIdString()); + } + }; +} +#endif diff --git a/components/esm3/activespells.cpp b/components/esm3/activespells.cpp index c2453ea399..67ca0fade8 100644 --- a/components/esm3/activespells.cpp +++ b/components/esm3/activespells.cpp @@ -11,7 +11,7 @@ namespace ESM { for (const auto& params : spells) { - esm.writeHNString(tag, params.mId); + esm.writeHNString(tag, params.mId.getRefIdString()); esm.writeHNT("CAST", params.mCasterActorId); esm.writeHNString("DISP", params.mDisplayName); @@ -47,7 +47,7 @@ namespace ESM while (esm.isNextSub(tag)) { ActiveSpells::ActiveSpellParams params; - params.mId = esm.getHString(); + params.mId = esm.getRefId(); esm.getHNT(params.mCasterActorId, "CAST"); params.mDisplayName = esm.getHNString("DISP"); params.mItem.unset(); diff --git a/components/esm3/activespells.hpp b/components/esm3/activespells.hpp index 4b7e2bf72d..5e04144d6f 100644 --- a/components/esm3/activespells.hpp +++ b/components/esm3/activespells.hpp @@ -3,6 +3,7 @@ #include "cellref.hpp" #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include #include @@ -51,7 +52,7 @@ namespace ESM struct ActiveSpellParams { - std::string mId; + RefId mId; std::vector mEffects; std::string mDisplayName; int mCasterActorId; diff --git a/components/esm3/aisequence.cpp b/components/esm3/aisequence.cpp index 2fc00e2fb9..69b639f0e8 100644 --- a/components/esm3/aisequence.cpp +++ b/components/esm3/aisequence.cpp @@ -50,11 +50,11 @@ namespace ESM void AiEscort::load(ESMReader& esm) { esm.getHNT(mData, "DATA"); - mTargetId = esm.getHNString("TARG"); + mTargetId = ESM::RefId::stringRefId(esm.getHNString("TARG")); mTargetActorId = -1; esm.getHNOT(mTargetActorId, "TAID"); esm.getHNT(mRemainingDuration, "DURA"); - mCellId = esm.getHNOString("CELL"); + mCellId = ESM::RefId::stringRefId(esm.getHNOString("CELL")); mRepeat = false; esm.getHNOT(mRepeat, "REPT"); if (esm.getFormat() < 18) @@ -70,11 +70,11 @@ namespace ESM void AiEscort::save(ESMWriter& esm) const { esm.writeHNT("DATA", mData); - esm.writeHNString("TARG", mTargetId); + esm.writeHNString("TARG", mTargetId.getRefIdString()); esm.writeHNT("TAID", mTargetActorId); esm.writeHNT("DURA", mRemainingDuration); if (!mCellId.empty()) - esm.writeHNString("CELL", mCellId); + esm.writeHNString("CELL", mCellId.getRefIdString()); if (mRepeat) esm.writeHNT("REPT", mRepeat); } @@ -82,11 +82,11 @@ namespace ESM void AiFollow::load(ESMReader& esm) { esm.getHNT(mData, "DATA"); - mTargetId = esm.getHNString("TARG"); + mTargetId = ESM::RefId::stringRefId(esm.getHNString("TARG")); mTargetActorId = -1; esm.getHNOT(mTargetActorId, "TAID"); esm.getHNT(mRemainingDuration, "DURA"); - mCellId = esm.getHNOString("CELL"); + mCellId = ESM::RefId::stringRefId(esm.getHNOString("CELL")); esm.getHNT(mAlwaysFollow, "ALWY"); mCommanded = false; esm.getHNOT(mCommanded, "CMND"); @@ -107,11 +107,11 @@ namespace ESM void AiFollow::save(ESMWriter& esm) const { esm.writeHNT("DATA", mData); - esm.writeHNString("TARG", mTargetId); + esm.writeHNString("TARG", mTargetId.getRefIdString()); esm.writeHNT("TAID", mTargetActorId); esm.writeHNT("DURA", mRemainingDuration); if (!mCellId.empty()) - esm.writeHNString("CELL", mCellId); + esm.writeHNString("CELL", mCellId.getRefIdString()); esm.writeHNT("ALWY", mAlwaysFollow); esm.writeHNT("CMND", mCommanded); if (mActive) @@ -122,14 +122,14 @@ namespace ESM void AiActivate::load(ESMReader& esm) { - mTargetId = esm.getHNString("TARG"); + mTargetId = ESM::RefId::stringRefId(esm.getHNString("TARG")); mRepeat = false; esm.getHNOT(mRepeat, "REPT"); } void AiActivate::save(ESMWriter& esm) const { - esm.writeHNString("TARG", mTargetId); + esm.writeHNString("TARG", mTargetId.getRefIdString()); if (mRepeat) esm.writeHNT("REPT", mRepeat); } diff --git a/components/esm3/aisequence.hpp b/components/esm3/aisequence.hpp index 9c4af0c971..24ee63e18c 100644 --- a/components/esm3/aisequence.hpp +++ b/components/esm3/aisequence.hpp @@ -6,7 +6,7 @@ #include #include "components/esm/defs.hpp" - +#include "components/esm/refid.hpp" #include "components/esm/util.hpp" namespace ESM @@ -91,8 +91,8 @@ namespace ESM AiEscortData mData; int mTargetActorId; - std::string mTargetId; - std::string mCellId; + ESM::RefId mTargetId; + ESM::RefId mCellId; float mRemainingDuration; bool mRepeat; @@ -105,8 +105,8 @@ namespace ESM AiEscortData mData; int mTargetActorId; - std::string mTargetId; - std::string mCellId; + ESM::RefId mTargetId; + ESM::RefId mCellId; float mRemainingDuration; bool mAlwaysFollow; @@ -121,7 +121,7 @@ namespace ESM struct AiActivate : AiPackage { - std::string mTargetId; + ESM::RefId mTargetId; bool mRepeat; void load(ESMReader& esm); diff --git a/components/esm3/cellid.hpp b/components/esm3/cellid.hpp index 12479dc2c6..15780c26e9 100644 --- a/components/esm3/cellid.hpp +++ b/components/esm3/cellid.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_CELLID_H #include +#include namespace ESM { diff --git a/components/esm3/cellref.cpp b/components/esm3/cellref.cpp index 63c85b6def..bf7ae77142 100644 --- a/components/esm3/cellref.cpp +++ b/components/esm3/cellref.cpp @@ -25,7 +25,7 @@ namespace ESM { cellRef.blank(); cellRef.mRefNum.load(esm, wideRefNum); - cellRef.mRefID = esm.getHNOString("NAME"); + cellRef.mRefID = ESM::RefId::stringRefId(esm.getHNOString("NAME")); if (cellRef.mRefID.empty()) Log(Debug::Warning) << "Warning: got CellRef with empty RefId in " << esm.getName() << " 0x" @@ -41,6 +41,14 @@ namespace ESM template void loadDataImpl(ESMReader& esm, bool& isDeleted, CellRef& cellRef) { + const auto getRefIdOrSkip = [&](ESM::RefId refId) + { + if constexpr (load) + refId = esm.getRefId(); + else + esm.skipHString(); + }; + const auto getHStringOrSkip = [&](std::string& value) { if constexpr (load) value = esm.getHString(); @@ -73,16 +81,16 @@ namespace ESM cellRef.mScale = std::clamp(cellRef.mScale, 0.5f, 2.0f); break; case fourCC("ANAM"): - getHStringOrSkip(cellRef.mOwner); + getRefIdOrSkip(cellRef.mOwner); break; case fourCC("BNAM"): getHStringOrSkip(cellRef.mGlobalVariable); break; case fourCC("XSOL"): - getHStringOrSkip(cellRef.mSoul); + getRefIdOrSkip(cellRef.mSoul); break; case fourCC("CNAM"): - getHStringOrSkip(cellRef.mFaction); + getRefIdOrSkip(cellRef.mFaction); break; case fourCC("INDX"): getHTOrSkip(cellRef.mFactionRank); @@ -108,10 +116,10 @@ namespace ESM getHTOrSkip(cellRef.mLockLevel); break; case fourCC("KNAM"): - getHStringOrSkip(cellRef.mKey); + getRefIdOrSkip(cellRef.mKey); break; case fourCC("TNAM"): - getHStringOrSkip(cellRef.mTrap); + getRefIdOrSkip(cellRef.mTrap); break; case fourCC("DATA"): if constexpr (load) @@ -188,7 +196,7 @@ namespace ESM { mRefNum.save(esm, wideRefNum); - esm.writeHNCString("NAME", mRefID); + esm.writeHNCString("NAME", mRefID.getRefIdString()); if (isDeleted) { @@ -202,14 +210,14 @@ namespace ESM } if (!inInventory) - esm.writeHNOCString("ANAM", mOwner); + esm.writeHNOCString("ANAM", mOwner.getRefIdString()); esm.writeHNOCString("BNAM", mGlobalVariable); - esm.writeHNOCString("XSOL", mSoul); + esm.writeHNOCString("XSOL", mSoul.getRefIdString()); if (!inInventory) { - esm.writeHNOCString("CNAM", mFaction); + esm.writeHNOCString("CNAM", mFaction.getRefIdString()); if (mFactionRank != -2) { esm.writeHNT("INDX", mFactionRank); @@ -238,8 +246,8 @@ namespace ESM if (!inInventory) { - esm.writeHNOCString("KNAM", mKey); - esm.writeHNOCString("TNAM", mTrap); + esm.writeHNOCString("KNAM", mKey.getRefIdString()); + esm.writeHNOCString("TNAM", mTrap.getRefIdString()); } if (mReferenceBlocked != -1) diff --git a/components/esm3/cellref.hpp b/components/esm3/cellref.hpp index cbff8a20e9..2d6026b44a 100644 --- a/components/esm3/cellref.hpp +++ b/components/esm3/cellref.hpp @@ -6,6 +6,7 @@ #include "components/esm/defs.hpp" #include "components/esm/esmcommon.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -42,12 +43,12 @@ namespace ESM // Note: Currently unused for items in containers RefNum mRefNum; - std::string mRefID; // ID of object being referenced + ESM::RefId mRefID; // ID of object being referenced float mScale; // Scale applied to mesh // The NPC that owns this object (and will get angry if you steal it) - std::string mOwner; + ESM::RefId mOwner; // Name of a global variable. If the global variable is set to '1', using the object is temporarily allowed // even if it has an Owner field. @@ -55,11 +56,11 @@ namespace ESM std::string mGlobalVariable; // ID of creature trapped in this soul gem - std::string mSoul; + ESM::RefId mSoul; // The faction that owns this object (and will get angry if // you take it and are not a faction member) - std::string mFaction; + ESM::RefId mFaction; // PC faction rank required to use the item. Sometimes is -1, which means "any rank". int mFactionRank; @@ -93,7 +94,7 @@ namespace ESM // Lock level for doors and containers int mLockLevel; - std::string mKey, mTrap; // Key and trap ID names, if any + ESM::RefId mKey, mTrap; // Key and trap ID names, if any // This corresponds to the "Reference Blocked" checkbox in the construction set, // which prevents editing that reference. diff --git a/components/esm3/creaturestats.cpp b/components/esm3/creaturestats.cpp index 32433f6702..a6eb2245ca 100644 --- a/components/esm3/creaturestats.cpp +++ b/components/esm3/creaturestats.cpp @@ -87,9 +87,9 @@ namespace ESM mFallHeight = 0; esm.getHNOT(mFallHeight, "FALL"); - mLastHitObject = esm.getHNOString("LHIT"); + mLastHitObject = ESM::RefId::stringRefId(esm.getHNOString("LHIT")); - mLastHitAttemptObject = esm.getHNOString("LHAT"); + mLastHitAttemptObject = ESM::RefId::stringRefId(esm.getHNOString("LHAT")); if (esm.getFormat() < 8) esm.getHNOT(mRecalcDynamicStats, "CALC"); @@ -121,7 +121,7 @@ namespace ESM { int magicEffect; esm.getHT(magicEffect); - std::string source = esm.getHNOString("SOUR"); + ESM::RefId source = ESM::RefId::stringRefId(esm.getHNOString("SOUR")); int effectIndex = -1; esm.getHNOT(effectIndex, "EIND"); int actorId; @@ -160,7 +160,7 @@ namespace ESM while (esm.isNextSub("CORP")) { - std::string id = esm.getHString(); + ESM::RefId id = esm.getRefId(); CorprusStats stats; esm.getHNT(stats.mWorsenings, "WORS"); @@ -229,10 +229,10 @@ namespace ESM esm.writeHNT("FALL", mFallHeight); if (!mLastHitObject.empty()) - esm.writeHNString("LHIT", mLastHitObject); + esm.writeHNString("LHIT", mLastHitObject.getRefIdString()); if (!mLastHitAttemptObject.empty()) - esm.writeHNString("LHAT", mLastHitAttemptObject); + esm.writeHNString("LHAT", mLastHitAttemptObject.getRefIdString()); if (mDrawState) esm.writeHNT("DRAW", mDrawState); diff --git a/components/esm3/creaturestats.hpp b/components/esm3/creaturestats.hpp index b0cd56470f..1a9f087e39 100644 --- a/components/esm3/creaturestats.hpp +++ b/components/esm3/creaturestats.hpp @@ -12,6 +12,7 @@ #include "activespells.hpp" #include "aisequence.hpp" #include "components/esm/attr.hpp" +#include "components/esm/refid.hpp" #include "magiceffects.hpp" #include "spellstate.hpp" @@ -78,8 +79,8 @@ namespace ESM bool mBlock; unsigned int mMovementFlags; float mFallHeight; - std::string mLastHitObject; - std::string mLastHitAttemptObject; + ESM::RefId mLastHitObject; + ESM::RefId mLastHitAttemptObject; bool mRecalcDynamicStats; int mDrawState; signed char mDeathAnimation; @@ -87,7 +88,7 @@ namespace ESM int mLevel; bool mMissingACDT; - std::map mCorprusSpells; + std::map mCorprusSpells; SpellState mSpells; ActiveSpells mActiveSpells; diff --git a/components/esm3/debugprofile.cpp b/components/esm3/debugprofile.cpp index ad5551206a..241df1e743 100644 --- a/components/esm3/debugprofile.cpp +++ b/components/esm3/debugprofile.cpp @@ -17,7 +17,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); break; case fourCC("DESC"): mDescription = esm.getHString(); @@ -41,7 +41,7 @@ namespace ESM void DebugProfile::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/debugprofile.hpp b/components/esm3/debugprofile.hpp index 5d1dcae0b3..9f13598ce0 100644 --- a/components/esm3/debugprofile.hpp +++ b/components/esm3/debugprofile.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -22,7 +23,7 @@ namespace ESM }; unsigned int mRecordFlags; - std::string mId; + RefId mId; std::string mDescription; diff --git a/components/esm3/dialoguestate.cpp b/components/esm3/dialoguestate.cpp index 60bd12fae0..52b66ab3fa 100644 --- a/components/esm3/dialoguestate.cpp +++ b/components/esm3/dialoguestate.cpp @@ -9,15 +9,15 @@ namespace ESM void DialogueState::load(ESMReader& esm) { while (esm.isNextSub("TOPI")) - mKnownTopics.push_back(esm.getHString()); + mKnownTopics.push_back(esm.getRefId()); while (esm.isNextSub("FACT")) { - std::string faction = esm.getHString(); + ESM::RefId faction = esm.getRefId(); while (esm.isNextSub("REA2")) { - std::string faction2 = esm.getHString(); + ESM::RefId faction2 = esm.getRefId(); int reaction; esm.getHNT(reaction, "INTV"); mChangedFactionReaction[faction][faction2] = reaction; @@ -35,20 +35,20 @@ namespace ESM void DialogueState::save(ESMWriter& esm) const { - for (std::vector::const_iterator iter(mKnownTopics.begin()); iter != mKnownTopics.end(); ++iter) + for (auto iter(mKnownTopics.begin()); iter != mKnownTopics.end(); ++iter) { - esm.writeHNString("TOPI", *iter); + esm.writeHNString("TOPI", iter->getRefIdString()); } - for (std::map>::const_iterator iter = mChangedFactionReaction.begin(); + for (auto iter = mChangedFactionReaction.begin(); iter != mChangedFactionReaction.end(); ++iter) { - esm.writeHNString("FACT", iter->first); + esm.writeHNString("FACT", iter->first.getRefIdString()); - for (std::map::const_iterator reactIter = iter->second.begin(); + for (auto reactIter = iter->second.begin(); reactIter != iter->second.end(); ++reactIter) { - esm.writeHNString("REA2", reactIter->first); + esm.writeHNString("REA2", reactIter->first.getRefIdString()); esm.writeHNT("INTV", reactIter->second); } } diff --git a/components/esm3/dialoguestate.hpp b/components/esm3/dialoguestate.hpp index d2e912cbcd..704ebc806f 100644 --- a/components/esm3/dialoguestate.hpp +++ b/components/esm3/dialoguestate.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace ESM { @@ -15,10 +16,10 @@ namespace ESM struct DialogueState { // must be lower case topic IDs - std::vector mKnownTopics; + std::vector mKnownTopics; // must be lower case faction IDs - std::map> mChangedFactionReaction; + std::map> mChangedFactionReaction; void load(ESMReader& esm); void save(ESMWriter& esm) const; diff --git a/components/esm3/esmreader.cpp b/components/esm3/esmreader.cpp index 3db414bf19..6765a2f486 100644 --- a/components/esm3/esmreader.cpp +++ b/components/esm3/esmreader.cpp @@ -157,6 +157,8 @@ namespace ESM return getString(mCtx.leftSub); } + RefId ESMReader::getRefId() { return ESM::RefId::stringRefId(getHString()); } + void ESMReader::skipHString() { getSubHeader(); diff --git a/components/esm3/esmreader.hpp b/components/esm3/esmreader.hpp index a430736728..7898bbd1d2 100644 --- a/components/esm3/esmreader.hpp +++ b/components/esm3/esmreader.hpp @@ -10,6 +10,7 @@ #include #include "components/esm/esmcommon.hpp" +#include "components/esm/refid.hpp" #include "loadtes3.hpp" namespace ESM @@ -172,6 +173,7 @@ namespace ESM // Read a string, including the sub-record header (but not the name) std::string getHString(); + RefId getRefId(); void skipHString(); diff --git a/components/esm3/filter.cpp b/components/esm3/filter.cpp index e3c2a15b43..c7caf28260 100644 --- a/components/esm3/filter.cpp +++ b/components/esm3/filter.cpp @@ -18,7 +18,7 @@ namespace ESM switch (name) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); break; case fourCC("FILT"): mFilter = esm.getHString(); @@ -39,7 +39,7 @@ namespace ESM void Filter::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/filter.hpp b/components/esm3/filter.hpp index d6710739c3..f340d046d1 100644 --- a/components/esm3/filter.hpp +++ b/components/esm3/filter.hpp @@ -2,6 +2,8 @@ #define COMPONENTS_ESM_FILTER_H #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" + #include namespace ESM @@ -14,7 +16,7 @@ namespace ESM constexpr static RecNameInts sRecordId = REC_FILT; unsigned int mRecordFlags; - std::string mId; + RefId mId; std::string mDescription; diff --git a/components/esm3/globalscript.cpp b/components/esm3/globalscript.cpp index 800a739437..acdc3a9a7d 100644 --- a/components/esm3/globalscript.cpp +++ b/components/esm3/globalscript.cpp @@ -8,7 +8,7 @@ namespace ESM void GlobalScript::load(ESMReader& esm) { - mId = esm.getHNString("NAME"); + mId = ESM::RefId::stringRefId(esm.getHNString("NAME")); mLocals.load(esm); @@ -16,14 +16,14 @@ namespace ESM esm.getHNOT(mRunning, "RUN_"); mTargetRef.unset(); - mTargetId = esm.getHNOString("TARG"); + mTargetId = ESM::RefId::stringRefId(esm.getHNOString("TARG")); if (esm.peekNextSub("FRMR")) mTargetRef.load(esm, true, "FRMR"); } void GlobalScript::save(ESMWriter& esm) const { - esm.writeHNString("NAME", mId); + esm.writeHNString("NAME", mId.getRefIdString()); mLocals.save(esm); @@ -32,7 +32,7 @@ namespace ESM if (!mTargetId.empty()) { - esm.writeHNOString("TARG", mTargetId); + esm.writeHNOString("TARG", mTargetId.getRefIdString()); if (mTargetRef.isSet()) mTargetRef.save(esm, true, "FRMR"); } diff --git a/components/esm3/globalscript.hpp b/components/esm3/globalscript.hpp index e595e61195..1ee7d1a089 100644 --- a/components/esm3/globalscript.hpp +++ b/components/esm3/globalscript.hpp @@ -3,6 +3,7 @@ #include "cellref.hpp" #include "locals.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -13,10 +14,10 @@ namespace ESM struct GlobalScript { - std::string mId; /// \note must be lowercase + RefId mId; /// \note must be lowercase Locals mLocals; int mRunning; - std::string mTargetId; // for targeted scripts + RefId mTargetId; // for targeted scripts RefNum mTargetRef; void load(ESMReader& esm); diff --git a/components/esm3/inventorystate.cpp b/components/esm3/inventorystate.cpp index 000fbde997..c8a9b1bba6 100644 --- a/components/esm3/inventorystate.cpp +++ b/components/esm3/inventorystate.cpp @@ -57,7 +57,7 @@ namespace ESM while (esm.isNextSub("LEVM")) { // Get its name - std::string id = esm.getHString(); + ESM::RefId id = esm.getRefId(); int count; std::string parentGroup; // Then get its count @@ -71,7 +71,7 @@ namespace ESM while (esm.isNextSub("MAGI")) { - std::string id = esm.getHString(); + ESM::RefId id = esm.getRefId(); std::vector> params; while (esm.isNextSub("RAND")) @@ -116,11 +116,11 @@ namespace ESM // This turns items from that map into negative quantities for (const auto& entry : mLevelledItemMap) { - const std::string& id = entry.first.first; + const ESM::RefId& id = entry.first.first; const int count = entry.second; for (auto& item : mItems) { - if (item.mCount == count && Misc::StringUtils::ciEqual(id, item.mRef.mRefID)) + if (item.mCount == count && ESM::RefId::ciEqual(id, item.mRef.mRefID)) item.mCount = -count; } } @@ -138,10 +138,10 @@ namespace ESM } } - for (std::map, int>::const_iterator it = mLevelledItemMap.begin(); + for (auto it = mLevelledItemMap.begin(); it != mLevelledItemMap.end(); ++it) { - esm.writeHNString("LEVM", it->first.first); + esm.writeHNString("LEVM", it->first.first.getRefIdString()); esm.writeHNT("COUN", it->second); esm.writeHNString("LGRP", it->first.second); } @@ -149,7 +149,7 @@ namespace ESM for (TEffectMagnitudes::const_iterator it = mPermanentMagicEffectMagnitudes.begin(); it != mPermanentMagicEffectMagnitudes.end(); ++it) { - esm.writeHNString("MAGI", it->first); + esm.writeHNString("MAGI", it->first.getRefIdString()); const std::vector>& params = it->second; for (std::vector>::const_iterator pIt = params.begin(); pIt != params.end(); ++pIt) diff --git a/components/esm3/inventorystate.hpp b/components/esm3/inventorystate.hpp index 0a15357260..a0fd948951 100644 --- a/components/esm3/inventorystate.hpp +++ b/components/esm3/inventorystate.hpp @@ -4,6 +4,7 @@ #include #include "objectstate.hpp" +#include namespace ESM { @@ -20,9 +21,9 @@ namespace ESM // std::map mEquipmentSlots; - std::map, int> mLevelledItemMap; + std::map, int> mLevelledItemMap; - typedef std::map>> TEffectMagnitudes; + typedef std::map>> TEffectMagnitudes; TEffectMagnitudes mPermanentMagicEffectMagnitudes; int mSelectedEnchantItem; // For inventories only diff --git a/components/esm3/journalentry.cpp b/components/esm3/journalentry.cpp index d47f212143..159e2624c4 100644 --- a/components/esm3/journalentry.cpp +++ b/components/esm3/journalentry.cpp @@ -9,8 +9,8 @@ namespace ESM void JournalEntry::load(ESMReader& esm) { esm.getHNOT(mType, "JETY"); - mTopic = esm.getHNString("YETO"); - mInfo = esm.getHNString("YEIN"); + mTopic = ESM::RefId::stringRefId(esm.getHNString("YETO")); + mInfo = ESM::RefId::stringRefId(esm.getHNString("YEIN")); mText = esm.getHNString("TEXT"); if (mType == Type_Journal) @@ -26,8 +26,8 @@ namespace ESM void JournalEntry::save(ESMWriter& esm) const { esm.writeHNT("JETY", mType); - esm.writeHNString("YETO", mTopic); - esm.writeHNString("YEIN", mInfo); + esm.writeHNString("YETO", mTopic.getRefIdString()); + esm.writeHNString("YEIN", mInfo.getRefIdString()); esm.writeHNString("TEXT", mText); if (mType == Type_Journal) diff --git a/components/esm3/journalentry.hpp b/components/esm3/journalentry.hpp index a2d16bd0f3..a9a5f32530 100644 --- a/components/esm3/journalentry.hpp +++ b/components/esm3/journalentry.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_JOURNALENTRY_H #include +#include namespace ESM { @@ -20,8 +21,8 @@ namespace ESM }; int mType; - std::string mTopic; - std::string mInfo; + ESM::RefId mTopic; + ESM::RefId mInfo; std::string mText; std::string mActorName; // Could also be Actor ID to allow switching of localisation, but since mText is // plaintext anyway... diff --git a/components/esm3/loadacti.cpp b/components/esm3/loadacti.cpp index dd28130b0c..86c7f87c5a 100644 --- a/components/esm3/loadacti.cpp +++ b/components/esm3/loadacti.cpp @@ -17,7 +17,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -27,7 +27,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case SREC_DELE: esm.skipHSub(); @@ -44,7 +44,7 @@ namespace ESM } void Activator::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -54,7 +54,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); } void Activator::blank() diff --git a/components/esm3/loadacti.hpp b/components/esm3/loadacti.hpp index 958e18310f..be5b282934 100644 --- a/components/esm3/loadacti.hpp +++ b/components/esm3/loadacti.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_ACTI_H #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include namespace ESM @@ -18,7 +19,8 @@ namespace ESM static std::string_view getRecordType() { return "Activator"; } unsigned int mRecordFlags; - std::string mId, mName, mScript, mModel; + RefId mId, mScript; + std::string mName, mModel; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadalch.cpp b/components/esm3/loadalch.cpp index d2dae35ee4..91d857798c 100644 --- a/components/esm3/loadalch.cpp +++ b/components/esm3/loadalch.cpp @@ -20,7 +20,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -30,7 +30,7 @@ namespace ESM mIcon = esm.getHString(); break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("FNAM"): mName = esm.getHString(); @@ -59,7 +59,7 @@ namespace ESM } void Potion::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -69,7 +69,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("TEXT", mIcon); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("FNAM", mName); esm.writeHNT("ALDT", mData, 12); mEffects.save(esm); diff --git a/components/esm3/loadalch.hpp b/components/esm3/loadalch.hpp index 3905a6f49b..d1defa204c 100644 --- a/components/esm3/loadalch.hpp +++ b/components/esm3/loadalch.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "effectlist.hpp" namespace ESM @@ -32,7 +33,8 @@ namespace ESM ALDTstruct mData; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mScript; + RefId mId, mScript; + std::string mName, mModel, mIcon; EffectList mEffects; void load(ESMReader& esm, bool& isDeleted); diff --git a/components/esm3/loadappa.cpp b/components/esm3/loadappa.cpp index 4b33dc6aeb..6b231a91a3 100644 --- a/components/esm3/loadappa.cpp +++ b/components/esm3/loadappa.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -32,7 +32,7 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); @@ -55,7 +55,7 @@ namespace ESM void Apparatus::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -66,7 +66,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNCString("FNAM", mName); esm.writeHNT("AADT", mData, 16); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNCString("ITEX", mIcon); } diff --git a/components/esm3/loadappa.hpp b/components/esm3/loadappa.hpp index 5aa529597f..d19fc0f1a0 100644 --- a/components/esm3/loadappa.hpp +++ b/components/esm3/loadappa.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -40,7 +41,8 @@ namespace ESM AADTstruct mData; unsigned int mRecordFlags; - std::string mId, mModel, mIcon, mScript, mName; + RefId mId, mScript; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadarmo.cpp b/components/esm3/loadarmo.cpp index babb9d2189..4139988e6d 100644 --- a/components/esm3/loadarmo.cpp +++ b/components/esm3/loadarmo.cpp @@ -10,8 +10,8 @@ namespace ESM { PartReference pr; esm.getHT(pr.mPart); // The INDX byte - pr.mMale = esm.getHNOString("BNAM"); - pr.mFemale = esm.getHNOString("CNAM"); + pr.mMale = ESM::RefId::stringRefId(esm.getHNOString("BNAM")); + pr.mFemale = ESM::RefId::stringRefId(esm.getHNOString("CNAM")); mParts.push_back(pr); } @@ -29,8 +29,8 @@ namespace ESM for (std::vector::const_iterator it = mParts.begin(); it != mParts.end(); ++it) { esm.writeHNT("INDX", it->mPart); - esm.writeHNOString("BNAM", it->mMale); - esm.writeHNOString("CNAM", it->mFemale); + esm.writeHNOString("BNAM", it->mMale.getRefIdString()); + esm.writeHNOString("CNAM", it->mFemale.getRefIdString()); } } @@ -49,7 +49,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -63,13 +63,13 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); break; case fourCC("ENAM"): - mEnchant = esm.getHString(); + mEnchant = esm.getRefId(); break; case fourCC("INDX"): mParts.add(esm); @@ -92,7 +92,7 @@ namespace ESM void Armor::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -102,11 +102,11 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNT("AODT", mData, 24); esm.writeHNOCString("ITEX", mIcon); mParts.save(esm); - esm.writeHNOCString("ENAM", mEnchant); + esm.writeHNOCString("ENAM", mEnchant.getRefIdString()); } void Armor::blank() diff --git a/components/esm3/loadarmo.hpp b/components/esm3/loadarmo.hpp index 84f37eb2e0..40b931bd61 100644 --- a/components/esm3/loadarmo.hpp +++ b/components/esm3/loadarmo.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -49,7 +50,7 @@ namespace ESM struct PartReference { unsigned char mPart; // possible values [0, 26] - std::string mMale, mFemale; + RefId mMale, mFemale; }; // A list of references to body parts @@ -98,7 +99,8 @@ namespace ESM PartReferenceList mParts; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mScript, mEnchant; + RefId mId, mScript, mEnchant; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadbody.cpp b/components/esm3/loadbody.cpp index 6ae084be1f..68c19fc161 100644 --- a/components/esm3/loadbody.cpp +++ b/components/esm3/loadbody.cpp @@ -18,14 +18,14 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): mModel = esm.getHString(); break; case fourCC("FNAM"): - mRace = esm.getHString(); + mRace = esm.getRefId(); break; case fourCC("BYDT"): esm.getHTSized<4>(mData); @@ -49,7 +49,7 @@ namespace ESM void BodyPart::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -58,7 +58,7 @@ namespace ESM } esm.writeHNCString("MODL", mModel); - esm.writeHNOCString("FNAM", mRace); + esm.writeHNOCString("FNAM", mRace.getRefIdString()); esm.writeHNT("BYDT", mData, 4); } diff --git a/components/esm3/loadbody.hpp b/components/esm3/loadbody.hpp index 2f146a05c1..d0ee5488af 100644 --- a/components/esm3/loadbody.hpp +++ b/components/esm3/loadbody.hpp @@ -2,6 +2,8 @@ #define OPENMW_ESM_BODY_H #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" + #include namespace ESM @@ -61,7 +63,8 @@ namespace ESM BYDTstruct mData; unsigned int mRecordFlags; - std::string mId, mModel, mRace; + RefId mId, mRace; + std::string mModel; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadbook.cpp b/components/esm3/loadbook.cpp index 18400b3829..62b9e26806 100644 --- a/components/esm3/loadbook.cpp +++ b/components/esm3/loadbook.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -32,13 +32,13 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); break; case fourCC("ENAM"): - mEnchant = esm.getHString(); + mEnchant = esm.getRefId(); break; case fourCC("TEXT"): mText = esm.getHString(); @@ -60,7 +60,7 @@ namespace ESM } void Book::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -71,10 +71,10 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("BKDT", mData, 20); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); esm.writeHNOString("TEXT", mText); - esm.writeHNOCString("ENAM", mEnchant); + esm.writeHNOCString("ENAM", mEnchant.getRefIdString()); } void Book::blank() diff --git a/components/esm3/loadbook.hpp b/components/esm3/loadbook.hpp index b02759b8f0..b4505fc8e7 100644 --- a/components/esm3/loadbook.hpp +++ b/components/esm3/loadbook.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_BOOK_H #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include namespace ESM @@ -27,10 +28,11 @@ namespace ESM }; BKDTstruct mData; - std::string mName, mModel, mIcon, mScript, mEnchant, mText; + std::string mName, mModel, mIcon, mText; unsigned int mRecordFlags; - std::string mId; - + RefId mId; + RefId mScript, mEnchant; + void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadbsgn.cpp b/components/esm3/loadbsgn.cpp index 516625f9da..8d09ced793 100644 --- a/components/esm3/loadbsgn.cpp +++ b/components/esm3/loadbsgn.cpp @@ -19,7 +19,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("FNAM"): @@ -50,7 +50,7 @@ namespace ESM void BirthSign::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/loadbsgn.hpp b/components/esm3/loadbsgn.hpp index edb0b6adf0..8fbe20c774 100644 --- a/components/esm3/loadbsgn.hpp +++ b/components/esm3/loadbsgn.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "spelllist.hpp" namespace ESM @@ -20,7 +21,8 @@ namespace ESM static std::string_view getRecordType() { return "BirthSign"; } unsigned int mRecordFlags; - std::string mId, mName, mDescription, mTexture; + RefId mId; + std::string mName, mDescription, mTexture; // List of powers and abilities that come with this birth sign. SpellList mPowers; diff --git a/components/esm3/loadcell.cpp b/components/esm3/loadcell.cpp index f82190d78d..9e2d813621 100644 --- a/components/esm3/loadcell.cpp +++ b/components/esm3/loadcell.cpp @@ -142,7 +142,7 @@ namespace ESM mHasAmbi = true; break; case fourCC("RGNN"): - mRegion = esm.getHString(); + mRegion = esm.getRefId(); break; case fourCC("NAM5"): esm.getHT(mMapColor); @@ -195,7 +195,7 @@ namespace ESM } if (mData.mFlags & QuasiEx) - esm.writeHNOCString("RGNN", mRegion); + esm.writeHNOCString("RGNN", mRegion.getRefIdString()); else { // Try to avoid saving ambient lighting information when it's unnecessary. @@ -206,7 +206,7 @@ namespace ESM } else { - esm.writeHNOCString("RGNN", mRegion); + esm.writeHNOCString("RGNN", mRegion.getRefIdString()); if (mMapColor != 0) esm.writeHNT("NAM5", mMapColor); } @@ -232,7 +232,7 @@ namespace ESM if (!mName.empty()) return mName + ' ' + cellGrid; // FIXME: should use sDefaultCellname GMST instead, but it's not available in this scope - std::string region = !mRegion.empty() ? mRegion : "Wilderness"; + std::string region = !mRegion.empty() ? mRegion.getRefIdString() : "Wilderness"; return region + ' ' + cellGrid; } diff --git a/components/esm3/loadcell.hpp b/components/esm3/loadcell.hpp index 4ba10b93e2..3cf1834dfa 100644 --- a/components/esm3/loadcell.hpp +++ b/components/esm3/loadcell.hpp @@ -9,6 +9,7 @@ #include "cellref.hpp" #include "components/esm/defs.hpp" #include "components/esm/esmcommon.hpp" +#include "components/esm/refid.hpp" namespace MWWorld { @@ -101,7 +102,7 @@ namespace ESM Cell() : mName("") - , mRegion("") + , mRegion(ESM::RefId()) , mHasAmbi(true) , mWater(0) , mWaterInt(false) @@ -115,7 +116,7 @@ namespace ESM std::string mName; // Optional region name for exterior and quasi-exterior cells. - std::string mRegion; + RefId mRegion; std::vector mContextList; // File position; multiple positions for multiple plugin support DATAstruct mData; diff --git a/components/esm3/loadclas.cpp b/components/esm3/loadclas.cpp index e74ecdf018..5863434564 100644 --- a/components/esm3/loadclas.cpp +++ b/components/esm3/loadclas.cpp @@ -42,7 +42,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("FNAM"): @@ -74,7 +74,7 @@ namespace ESM } void Class::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/loadclas.hpp b/components/esm3/loadclas.hpp index 51b9cf1f27..90dd86a17f 100644 --- a/components/esm3/loadclas.hpp +++ b/components/esm3/loadclas.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -47,7 +48,8 @@ namespace ESM }; // 60 bytes unsigned int mRecordFlags; - std::string mId, mName, mDescription; + std::string mName, mDescription; + RefId mId; CLDTstruct mData; void load(ESMReader& esm, bool& isDeleted); diff --git a/components/esm3/loadclot.cpp b/components/esm3/loadclot.cpp index c69c92c301..00f8cb2e20 100644 --- a/components/esm3/loadclot.cpp +++ b/components/esm3/loadclot.cpp @@ -20,7 +20,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -34,13 +34,13 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); break; case fourCC("ENAM"): - mEnchant = esm.getHString(); + mEnchant = esm.getRefId(); break; case fourCC("INDX"): mParts.add(esm); @@ -63,7 +63,7 @@ namespace ESM void Clothing::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -75,12 +75,12 @@ namespace ESM esm.writeHNOCString("FNAM", mName); esm.writeHNT("CTDT", mData, 12); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); mParts.save(esm); - esm.writeHNOCString("ENAM", mEnchant); + esm.writeHNOCString("ENAM", mEnchant.getRefIdString()); } void Clothing::blank() diff --git a/components/esm3/loadclot.hpp b/components/esm3/loadclot.hpp index b6e84c5017..44ebc37575 100644 --- a/components/esm3/loadclot.hpp +++ b/components/esm3/loadclot.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "loadarmo.hpp" namespace ESM @@ -49,7 +50,8 @@ namespace ESM PartReferenceList mParts; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mEnchant, mScript; + RefId mId, mEnchant, mScript; + std::string mModel, mIcon, mName; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadcont.cpp b/components/esm3/loadcont.cpp index a9ef424509..b648310fde 100644 --- a/components/esm3/loadcont.cpp +++ b/components/esm3/loadcont.cpp @@ -12,7 +12,7 @@ namespace ESM esm.getSubHeader(); ContItem ci; esm.getT(ci.mCount); - ci.mItem.assign(esm.getString(32)); + ci.mItem = ESM::RefId::stringRefId(esm.getString(32)); mList.push_back(ci); } @@ -22,7 +22,7 @@ namespace ESM { esm.startSubRecord("NPCO"); esm.writeT(it->mCount); - esm.writeFixedSizeString(it->mItem, 32); + esm.writeFixedSizeString(it->mItem.getRefIdString(), 32); esm.endRecord("NPCO"); } } @@ -43,7 +43,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -65,7 +65,7 @@ namespace ESM hasFlags = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("NPCO"): mInventory.add(esm); @@ -90,7 +90,7 @@ namespace ESM void Container::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -103,7 +103,7 @@ namespace ESM esm.writeHNT("CNDT", mWeight, 4); esm.writeHNT("FLAG", mFlags, 4); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); mInventory.save(esm); } diff --git a/components/esm3/loadcont.hpp b/components/esm3/loadcont.hpp index 8c51d39b78..3921821da0 100644 --- a/components/esm3/loadcont.hpp +++ b/components/esm3/loadcont.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -19,7 +20,7 @@ namespace ESM struct ContItem { int mCount{ 0 }; - std::string mItem; + ESM::RefId mItem; }; /// InventoryList, NPCO subrecord @@ -48,7 +49,8 @@ namespace ESM }; unsigned int mRecordFlags; - std::string mId, mName, mModel, mScript; + RefId mId, mScript; + std::string mName, mModel; float mWeight; // Not sure, might be max total weight allowed? int mFlags; diff --git a/components/esm3/loadcrea.cpp b/components/esm3/loadcrea.cpp index ac78b8f23a..f9e317e7dd 100644 --- a/components/esm3/loadcrea.cpp +++ b/components/esm3/loadcrea.cpp @@ -32,20 +32,20 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): mModel = esm.getHString(); break; case fourCC("CNAM"): - mOriginal = esm.getHString(); + mOriginal = esm.getRefId(); break; case fourCC("FNAM"): mName = esm.getHString(); break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("NPDT"): esm.getHTSized<96>(mData); @@ -108,7 +108,7 @@ namespace ESM void Creature::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -117,9 +117,9 @@ namespace ESM } esm.writeHNCString("MODL", mModel); - esm.writeHNOCString("CNAM", mOriginal); + esm.writeHNOCString("CNAM", mOriginal.getRefIdString()); esm.writeHNOCString("FNAM", mName); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNT("NPDT", mData, 96); esm.writeHNT("FLAG", ((mBloodType << 10) + mFlags)); if (mScale != 1.0) diff --git a/components/esm3/loadcrea.hpp b/components/esm3/loadcrea.hpp index 9636ba48de..42e5007328 100644 --- a/components/esm3/loadcrea.hpp +++ b/components/esm3/loadcrea.hpp @@ -9,6 +9,7 @@ #include "transport.hpp" #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -75,8 +76,10 @@ namespace ESM float mScale; unsigned int mRecordFlags; - std::string mId, mModel, mName, mScript; - std::string mOriginal; // Base creature that this is a modification of + RefId mId, mScript; + std::string mModel; + std::string mName; + ESM::RefId mOriginal; // Base creature that this is a modification of InventoryList mInventory; SpellList mSpells; diff --git a/components/esm3/loaddial.cpp b/components/esm3/loaddial.cpp index 5aa8a29b09..48ca6a659f 100644 --- a/components/esm3/loaddial.cpp +++ b/components/esm3/loaddial.cpp @@ -14,7 +14,7 @@ namespace ESM void Dialogue::loadId(ESMReader& esm) { - mId = esm.getHNString("NAME"); + mId = ESM::RefId::stringRefId(esm.getHNString("NAME")); } void Dialogue::loadData(ESMReader& esm, bool& isDeleted) @@ -54,7 +54,7 @@ namespace ESM void Dialogue::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { esm.writeHNString("DELE", "", 3); diff --git a/components/esm3/loaddial.hpp b/components/esm3/loaddial.hpp index dda6954d7b..3983f483c9 100644 --- a/components/esm3/loaddial.hpp +++ b/components/esm3/loaddial.hpp @@ -6,6 +6,8 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" + #include "loadinfo.hpp" namespace ESM @@ -35,13 +37,13 @@ namespace ESM Unknown = -1 // Used for deleted dialogues }; - std::string mId; + RefId mId; signed char mType; typedef std::list InfoContainer; // Parameters: Info ID, (Info iterator, Deleted flag) - typedef std::map> LookupMap; + typedef std::map> LookupMap; InfoContainer mInfo; diff --git a/components/esm3/loaddoor.cpp b/components/esm3/loaddoor.cpp index 61ed687975..1d3e49383a 100644 --- a/components/esm3/loaddoor.cpp +++ b/components/esm3/loaddoor.cpp @@ -17,7 +17,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -27,13 +27,13 @@ namespace ESM mName = esm.getHString(); break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("SNAM"): - mOpenSound = esm.getHString(); + mOpenSound = esm.getRefId(); break; case fourCC("ANAM"): - mCloseSound = esm.getHString(); + mCloseSound = esm.getRefId(); break; case SREC_DELE: esm.skipHSub(); @@ -51,7 +51,7 @@ namespace ESM void Door::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -61,9 +61,9 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNOCString("SCRI", mScript); - esm.writeHNOCString("SNAM", mOpenSound); - esm.writeHNOCString("ANAM", mCloseSound); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); + esm.writeHNOCString("SNAM", mOpenSound.getRefIdString()); + esm.writeHNOCString("ANAM", mCloseSound.getRefIdString()); } void Door::blank() diff --git a/components/esm3/loaddoor.hpp b/components/esm3/loaddoor.hpp index c61eaadc78..dc5c8bc035 100644 --- a/components/esm3/loaddoor.hpp +++ b/components/esm3/loaddoor.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -19,7 +20,8 @@ namespace ESM static std::string_view getRecordType() { return "Door"; } unsigned int mRecordFlags; - std::string mId, mName, mModel, mScript, mOpenSound, mCloseSound; + RefId mId, mScript, mOpenSound, mCloseSound; + std::string mName, mModel; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadench.cpp b/components/esm3/loadench.cpp index 9a3eaa556b..fa839e8848 100644 --- a/components/esm3/loadench.cpp +++ b/components/esm3/loadench.cpp @@ -19,7 +19,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("ENDT"): @@ -47,7 +47,7 @@ namespace ESM void Enchantment::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/loadench.hpp b/components/esm3/loadench.hpp index f5d8cef80b..4103f91ceb 100644 --- a/components/esm3/loadench.hpp +++ b/components/esm3/loadench.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "effectlist.hpp" namespace ESM @@ -45,7 +46,7 @@ namespace ESM }; unsigned int mRecordFlags; - std::string mId; + RefId mId; ENDTstruct mData; EffectList mEffects; diff --git a/components/esm3/loadfact.cpp b/components/esm3/loadfact.cpp index f951a1a3e3..08bbb8769a 100644 --- a/components/esm3/loadfact.cpp +++ b/components/esm3/loadfact.cpp @@ -41,7 +41,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("FNAM"): @@ -60,7 +60,7 @@ namespace ESM break; case fourCC("ANAM"): { - std::string faction = esm.getHString(); + ESM::RefId faction = esm.getRefId(); int reaction; esm.getHNT(reaction, "INTV"); mReactions[faction] = reaction; @@ -84,7 +84,7 @@ namespace ESM void Faction::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -104,9 +104,9 @@ namespace ESM esm.writeHNT("FADT", mData, 240); - for (std::map::const_iterator it = mReactions.begin(); it != mReactions.end(); ++it) + for (auto it = mReactions.begin(); it != mReactions.end(); ++it) { - esm.writeHNString("ANAM", it->first); + esm.writeHNString("ANAM", it->first.getRefIdString()); esm.writeHNT("INTV", it->second); } } diff --git a/components/esm3/loadfact.hpp b/components/esm3/loadfact.hpp index 78f779564b..5383b7a57f 100644 --- a/components/esm3/loadfact.hpp +++ b/components/esm3/loadfact.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -38,7 +39,8 @@ namespace ESM static std::string_view getRecordType() { return "Faction"; } unsigned int mRecordFlags; - std::string mId, mName; + std::string mName; + RefId mId; struct FADTstruct { @@ -62,7 +64,7 @@ namespace ESM FADTstruct mData; // - std::map mReactions; + std::map mReactions; // Name of faction ranks (may be empty for NPC factions) std::string mRanks[10]; diff --git a/components/esm3/loadglob.cpp b/components/esm3/loadglob.cpp index 6ca1101cd9..99278d2546 100644 --- a/components/esm3/loadglob.cpp +++ b/components/esm3/loadglob.cpp @@ -10,7 +10,7 @@ namespace ESM isDeleted = false; mRecordFlags = esm.getRecordFlags(); - mId = esm.getHNString("NAME"); + mId = ESM::RefId::stringRefId(esm.getHNString("NAME")); if (esm.isNextSub("DELE")) { @@ -25,7 +25,7 @@ namespace ESM void Global::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/loadglob.hpp b/components/esm3/loadglob.hpp index f36d22c394..eed53a5f7b 100644 --- a/components/esm3/loadglob.hpp +++ b/components/esm3/loadglob.hpp @@ -6,6 +6,7 @@ #include "variant.hpp" #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -25,7 +26,7 @@ namespace ESM static std::string_view getRecordType() { return "Global"; } unsigned int mRecordFlags; - std::string mId; + ESM::RefId mId; Variant mValue; void load(ESMReader& esm, bool& isDeleted); diff --git a/components/esm3/loadgmst.cpp b/components/esm3/loadgmst.cpp index 727f1ff90f..9ad9c2dda7 100644 --- a/components/esm3/loadgmst.cpp +++ b/components/esm3/loadgmst.cpp @@ -10,13 +10,13 @@ namespace ESM isDeleted = false; // GameSetting record can't be deleted now (may be changed in the future) mRecordFlags = esm.getRecordFlags(); - mId = esm.getHNString("NAME"); + mId = ESM::RefId::stringRefId(esm.getHNString("NAME")); mValue.read(esm, Variant::Format_Gmst); } void GameSetting::save(ESMWriter& esm, bool /*isDeleted*/) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); mValue.write(esm, Variant::Format_Gmst); } diff --git a/components/esm3/loadgmst.hpp b/components/esm3/loadgmst.hpp index 68046ad421..72d30b9ea9 100644 --- a/components/esm3/loadgmst.hpp +++ b/components/esm3/loadgmst.hpp @@ -6,6 +6,7 @@ #include "variant.hpp" #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -26,7 +27,7 @@ namespace ESM static std::string_view getRecordType() { return "GameSetting"; } unsigned int mRecordFlags; - std::string mId; + RefId mId; Variant mValue; diff --git a/components/esm3/loadinfo.cpp b/components/esm3/loadinfo.cpp index 3581f0e314..36a6dd241e 100644 --- a/components/esm3/loadinfo.cpp +++ b/components/esm3/loadinfo.cpp @@ -7,15 +7,15 @@ namespace ESM { void DialInfo::load(ESMReader& esm, bool& isDeleted) { - mId = esm.getHNString("INAM"); + mId = ESM::RefId::stringRefId(esm.getHNString("INAM")); isDeleted = false; mQuestStatus = QS_None; mFactionLess = false; - mPrev = esm.getHNString("PNAM"); - mNext = esm.getHNString("NNAM"); + mPrev = ESM::RefId::stringRefId(esm.getHNString("PNAM")); + mNext = ESM::RefId::stringRefId(esm.getHNString("NNAM")); while (esm.hasMoreSubs()) { @@ -26,31 +26,31 @@ namespace ESM esm.getHTSized<12>(mData); break; case fourCC("ONAM"): - mActor = esm.getHString(); + mActor = esm.getRefId(); break; case fourCC("RNAM"): - mRace = esm.getHString(); + mRace = esm.getRefId(); break; case fourCC("CNAM"): - mClass = esm.getHString(); + mClass = esm.getRefId(); break; case fourCC("FNAM"): { - mFaction = esm.getHString(); - if (mFaction == "FFFF") + mFaction = esm.getRefId(); + if (mFaction.getRefIdString() == "FFFF") { mFactionLess = true; } break; } case fourCC("ANAM"): - mCell = esm.getHString(); + mCell = esm.getRefId(); break; case fourCC("DNAM"): - mPcFaction = esm.getHString(); + mPcFaction = esm.getRefId(); break; case fourCC("SNAM"): - mSound = esm.getHString(); + mSound = esm.getRefId(); break; case SREC_NAME: mResponse = esm.getHString(); @@ -91,9 +91,9 @@ namespace ESM void DialInfo::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("INAM", mId); - esm.writeHNCString("PNAM", mPrev); - esm.writeHNCString("NNAM", mNext); + esm.writeHNCString("INAM", mId.getRefIdString()); + esm.writeHNCString("PNAM", mPrev.getRefIdString()); + esm.writeHNCString("NNAM", mNext.getRefIdString()); if (isDeleted) { @@ -102,13 +102,13 @@ namespace ESM } esm.writeHNT("DATA", mData, 12); - esm.writeHNOCString("ONAM", mActor); - esm.writeHNOCString("RNAM", mRace); - esm.writeHNOCString("CNAM", mClass); - esm.writeHNOCString("FNAM", mFaction); - esm.writeHNOCString("ANAM", mCell); - esm.writeHNOCString("DNAM", mPcFaction); - esm.writeHNOCString("SNAM", mSound); + esm.writeHNOCString("ONAM", mActor.getRefIdString()); + esm.writeHNOCString("RNAM", mRace.getRefIdString()); + esm.writeHNOCString("CNAM", mClass.getRefIdString()); + esm.writeHNOCString("FNAM", mFaction.getRefIdString()); + esm.writeHNOCString("ANAM", mCell.getRefIdString()); + esm.writeHNOCString("DNAM", mPcFaction.getRefIdString()); + esm.writeHNOCString("SNAM", mSound.getRefIdString()); esm.writeHNOString("NAME", mResponse); for (std::vector::const_iterator it = mSelects.begin(); it != mSelects.end(); ++it) diff --git a/components/esm3/loadinfo.hpp b/components/esm3/loadinfo.hpp index 2c82e6ed34..c50a327145 100644 --- a/components/esm3/loadinfo.hpp +++ b/components/esm3/loadinfo.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "variant.hpp" namespace ESM @@ -68,14 +69,14 @@ namespace ESM std::vector mSelects; // Id of this, previous and next INFO items - std::string mId, mPrev, mNext; + RefId mId, mPrev, mNext; // Various references used in determining when to select this item. - std::string mActor, mRace, mClass, mFaction, mPcFaction, mCell; + RefId mActor, mRace, mClass, mFaction, mPcFaction, mCell; // Sound and text associated with this item - std::string mSound, mResponse; - + RefId mSound; + std::string mResponse; // Result script (uncompiled) to run whenever this dialog item is // selected std::string mResultScript; diff --git a/components/esm3/loadingr.cpp b/components/esm3/loadingr.cpp index ca1525048a..11101fb51d 100644 --- a/components/esm3/loadingr.cpp +++ b/components/esm3/loadingr.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -32,7 +32,7 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); @@ -72,7 +72,7 @@ namespace ESM void Ingredient::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -83,7 +83,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("IRDT", mData, 56); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadingr.hpp b/components/esm3/loadingr.hpp index af30da0356..d6b1b18c32 100644 --- a/components/esm3/loadingr.hpp +++ b/components/esm3/loadingr.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -33,7 +34,8 @@ namespace ESM IRDTstruct mData; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mScript; + RefId mId, mScript; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadlevlist.cpp b/components/esm3/loadlevlist.cpp index cadf340890..56b1d32562 100644 --- a/components/esm3/loadlevlist.cpp +++ b/components/esm3/loadlevlist.cpp @@ -19,7 +19,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("DATA"): @@ -43,7 +43,7 @@ namespace ESM for (size_t i = 0; i < mList.size(); i++) { LevelItem& li = mList[i]; - li.mId = esm.getHNString(recName); + li.mId = ESM::RefId::stringRefId(esm.getHNString(recName)); esm.getHNT(li.mLevel, "INTV"); } @@ -77,7 +77,7 @@ namespace ESM void LevelledListBase::save(ESMWriter& esm, NAME recName, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -91,7 +91,7 @@ namespace ESM for (std::vector::const_iterator it = mList.begin(); it != mList.end(); ++it) { - esm.writeHNCString(recName, it->mId); + esm.writeHNCString(recName, it->mId.getRefIdString()); esm.writeHNT("INTV", it->mLevel); } } diff --git a/components/esm3/loadlevlist.hpp b/components/esm3/loadlevlist.hpp index 10bcf58c6b..b4406e3f64 100644 --- a/components/esm3/loadlevlist.hpp +++ b/components/esm3/loadlevlist.hpp @@ -6,6 +6,7 @@ #include #include +#include "components/esm/refid.hpp" namespace ESM { @@ -26,11 +27,11 @@ namespace ESM int mFlags; unsigned char mChanceNone; // Chance that none are selected (0-100) unsigned int mRecordFlags; - std::string mId; + RefId mId; struct LevelItem { - std::string mId; + RefId mId; short mLevel; }; diff --git a/components/esm3/loadligh.cpp b/components/esm3/loadligh.cpp index feeccca4fd..510b51dd7f 100644 --- a/components/esm3/loadligh.cpp +++ b/components/esm3/loadligh.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -35,10 +35,10 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("SNAM"): - mSound = esm.getHString(); + mSound = esm.getRefId(); break; case SREC_DELE: esm.skipHSub(); @@ -57,7 +57,7 @@ namespace ESM } void Light::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -69,8 +69,8 @@ namespace ESM esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("ITEX", mIcon); esm.writeHNT("LHDT", mData, 24); - esm.writeHNOCString("SCRI", mScript); - esm.writeHNOCString("SNAM", mSound); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); + esm.writeHNOCString("SNAM", mSound.getRefIdString()); } void Light::blank() diff --git a/components/esm3/loadligh.hpp b/components/esm3/loadligh.hpp index 71d004ed4f..7ee24d26fc 100644 --- a/components/esm3/loadligh.hpp +++ b/components/esm3/loadligh.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -50,7 +51,8 @@ namespace ESM LHDTstruct mData; unsigned int mRecordFlags; - std::string mSound, mScript, mModel, mIcon, mName, mId; + std::string mModel, mIcon, mName; + ESM::RefId mId, mSound, mScript; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadlock.cpp b/components/esm3/loadlock.cpp index ecd31f9489..cdec3ff925 100644 --- a/components/esm3/loadlock.cpp +++ b/components/esm3/loadlock.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -32,7 +32,7 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); @@ -55,7 +55,7 @@ namespace ESM void Lockpick::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -67,7 +67,7 @@ namespace ESM esm.writeHNOCString("FNAM", mName); esm.writeHNT("LKDT", mData, 16); - esm.writeHNOString("SCRI", mScript); + esm.writeHNOString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadlock.hpp b/components/esm3/loadlock.hpp index e0235d0044..1b94fd61bb 100644 --- a/components/esm3/loadlock.hpp +++ b/components/esm3/loadlock.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -29,7 +30,8 @@ namespace ESM Data mData; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mScript; + RefId mId, mScript; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadltex.cpp b/components/esm3/loadltex.cpp index df5ae5ca32..a8e0a575c2 100644 --- a/components/esm3/loadltex.cpp +++ b/components/esm3/loadltex.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("INTV"): @@ -45,7 +45,7 @@ namespace ESM } void LandTexture::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); esm.writeHNT("INTV", mIndex); esm.writeHNCString("DATA", mTexture); diff --git a/components/esm3/loadltex.hpp b/components/esm3/loadltex.hpp index 7da22f2b45..e6dc2de73e 100644 --- a/components/esm3/loadltex.hpp +++ b/components/esm3/loadltex.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -26,7 +27,8 @@ namespace ESM static std::string_view getRecordType() { return "LandTexture"; } // mId is merely a user friendly name for the texture in the editor. - std::string mId, mTexture; + std::string mTexture; + RefId mId; int mIndex; void load(ESMReader& esm, bool& isDeleted); diff --git a/components/esm3/loadmgef.cpp b/components/esm3/loadmgef.cpp index b3a3c09bae..47bc868bb4 100644 --- a/components/esm3/loadmgef.cpp +++ b/components/esm3/loadmgef.cpp @@ -186,7 +186,7 @@ namespace ESM esm.getHNT(mIndex, "INDX"); - mId = indexToId(mIndex); + mId = ESM::RefId::stringRefId(indexToId(mIndex)); esm.getHNTSized<36>(mData, "MEDT"); if (esm.getFormat() == 0) @@ -211,28 +211,28 @@ namespace ESM mParticle = esm.getHString(); break; case fourCC("BSND"): - mBoltSound = esm.getHString(); + mBoltSound = esm.getRefId(); break; case fourCC("CSND"): - mCastSound = esm.getHString(); + mCastSound = esm.getRefId(); break; case fourCC("HSND"): - mHitSound = esm.getHString(); + mHitSound = esm.getRefId(); break; case fourCC("ASND"): - mAreaSound = esm.getHString(); + mAreaSound = esm.getRefId(); break; case fourCC("CVFX"): - mCasting = esm.getHString(); + mCasting = esm.getRefId(); break; case fourCC("BVFX"): - mBolt = esm.getHString(); + mBolt = esm.getRefId(); break; case fourCC("HVFX"): - mHit = esm.getHString(); + mHit = esm.getRefId(); break; case fourCC("AVFX"): - mArea = esm.getHString(); + mArea = esm.getRefId(); break; case fourCC("DESC"): mDescription = esm.getHString(); @@ -250,15 +250,15 @@ namespace ESM esm.writeHNOCString("ITEX", mIcon); esm.writeHNOCString("PTEX", mParticle); - esm.writeHNOCString("BSND", mBoltSound); - esm.writeHNOCString("CSND", mCastSound); - esm.writeHNOCString("HSND", mHitSound); - esm.writeHNOCString("ASND", mAreaSound); - - esm.writeHNOCString("CVFX", mCasting); - esm.writeHNOCString("BVFX", mBolt); - esm.writeHNOCString("HVFX", mHit); - esm.writeHNOCString("AVFX", mArea); + esm.writeHNOCString("BSND", mBoltSound.getRefIdString()); + esm.writeHNOCString("CSND", mCastSound.getRefIdString()); + esm.writeHNOCString("HSND", mHitSound.getRefIdString()); + esm.writeHNOCString("ASND", mAreaSound.getRefIdString()); + + esm.writeHNOCString("CVFX", mCasting.getRefIdString()); + esm.writeHNOCString("BVFX", mBolt.getRefIdString()); + esm.writeHNOCString("HVFX", mHit.getRefIdString()); + esm.writeHNOCString("AVFX", mArea.getRefIdString()); esm.writeHNOString("DESC", mDescription); } diff --git a/components/esm3/loadmgef.hpp b/components/esm3/loadmgef.hpp index e5c2eb3543..6210e3fadc 100644 --- a/components/esm3/loadmgef.hpp +++ b/components/esm3/loadmgef.hpp @@ -6,6 +6,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -21,7 +22,7 @@ namespace ESM static std::string_view getRecordType() { return "MagicEffect"; } unsigned int mRecordFlags; - std::string mId; + RefId mId; enum Flags { @@ -93,9 +94,9 @@ namespace ESM MEDTstruct mData; std::string mIcon, mParticle; // Textures - std::string mCasting, mHit, mArea; // Static - std::string mBolt; // Weapon - std::string mCastSound, mBoltSound, mHitSound, mAreaSound; // Sounds + ESM::RefId mCasting, mHit, mArea; // Static + ESM::RefId mBolt; // Weapon + ESM::RefId mCastSound, mBoltSound, mHitSound, mAreaSound; // Sounds std::string mDescription; // Index of this magical effect. Corresponds to one of the diff --git a/components/esm3/loadmisc.cpp b/components/esm3/loadmisc.cpp index 74022b2e99..49bd18ecca 100644 --- a/components/esm3/loadmisc.cpp +++ b/components/esm3/loadmisc.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -32,7 +32,7 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); @@ -55,7 +55,7 @@ namespace ESM void Miscellaneous::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -66,7 +66,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("MCDT", mData, 12); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadmisc.hpp b/components/esm3/loadmisc.hpp index ddd0561c6b..9c46b7494e 100644 --- a/components/esm3/loadmisc.hpp +++ b/components/esm3/loadmisc.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -38,7 +39,8 @@ namespace ESM MCDTstruct mData; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mScript; + RefId mId, mScript; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadnpc.cpp b/components/esm3/loadnpc.cpp index 74a9d53e8b..2788c77d04 100644 --- a/components/esm3/loadnpc.cpp +++ b/components/esm3/loadnpc.cpp @@ -26,7 +26,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -36,22 +36,22 @@ namespace ESM mName = esm.getHString(); break; case fourCC("RNAM"): - mRace = esm.getHString(); + mRace = esm.getRefId(); break; case fourCC("CNAM"): - mClass = esm.getHString(); + mClass = esm.getRefId(); break; case fourCC("ANAM"): - mFaction = esm.getHString(); + mFaction = esm.getRefId(); break; case fourCC("BNAM"): - mHead = esm.getHString(); + mHead = esm.getRefId(); break; case fourCC("KNAM"): - mHair = esm.getHString(); + mHair = esm.getRefId(); break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("NPDT"): hasNpdt = true; @@ -127,7 +127,7 @@ namespace ESM } void NPC::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -137,12 +137,12 @@ namespace ESM esm.writeHNOCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNCString("RNAM", mRace); - esm.writeHNCString("CNAM", mClass); - esm.writeHNCString("ANAM", mFaction); - esm.writeHNCString("BNAM", mHead); - esm.writeHNCString("KNAM", mHair); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNCString("RNAM", mRace.getRefIdString()); + esm.writeHNCString("CNAM", mClass.getRefIdString()); + esm.writeHNCString("ANAM", mFaction.getRefIdString()); + esm.writeHNCString("BNAM", mHead.getRefIdString()); + esm.writeHNCString("KNAM", mHair.getRefIdString()); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); if (mNpdtType == NPC_DEFAULT) { diff --git a/components/esm3/loadnpc.hpp b/components/esm3/loadnpc.hpp index 414629b82b..6c90e80994 100644 --- a/components/esm3/loadnpc.hpp +++ b/components/esm3/loadnpc.hpp @@ -6,6 +6,7 @@ #include "aipackage.hpp" #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "loadcont.hpp" #include "loadskil.hpp" #include "spelllist.hpp" @@ -124,10 +125,11 @@ namespace ESM AIPackageList mAiPackage; unsigned int mRecordFlags; - std::string mId, mName, mModel, mRace, mClass, mFaction, mScript; + RefId mId, mRace, mClass, mFaction, mScript; + std::string mModel, mName; // body parts - std::string mHair, mHead; + RefId mHair, mHead; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadpgrd.cpp b/components/esm3/loadpgrd.cpp index 8e301dc500..aac9b866d8 100644 --- a/components/esm3/loadpgrd.cpp +++ b/components/esm3/loadpgrd.cpp @@ -51,7 +51,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mCell = esm.getHString(); + mCell = esm.getRefId(); break; case fourCC("DATA"): esm.getHTSized<12>(mData); @@ -154,7 +154,7 @@ namespace ESM } // Save - esm.writeHNCString("NAME", mCell); + esm.writeHNCString("NAME", mCell.getRefIdString()); esm.writeHNT("DATA", mData, 12); if (isDeleted) diff --git a/components/esm3/loadpgrd.hpp b/components/esm3/loadpgrd.hpp index 59cdb99ed8..9609b32c0e 100644 --- a/components/esm3/loadpgrd.hpp +++ b/components/esm3/loadpgrd.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -55,7 +56,7 @@ namespace ESM int mV0, mV1; // index of points connected with this edge }; // 8 bytes - std::string mCell; // Cell name + ESM::RefId mCell; // Cell name DATAstruct mData; typedef std::vector PointList; diff --git a/components/esm3/loadprob.cpp b/components/esm3/loadprob.cpp index 430fc5ec38..00f782b41b 100644 --- a/components/esm3/loadprob.cpp +++ b/components/esm3/loadprob.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -32,7 +32,7 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); @@ -55,7 +55,7 @@ namespace ESM void Probe::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -67,7 +67,7 @@ namespace ESM esm.writeHNOCString("FNAM", mName); esm.writeHNT("PBDT", mData, 16); - esm.writeHNOString("SCRI", mScript); + esm.writeHNOString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadprob.hpp b/components/esm3/loadprob.hpp index 08c1dbd7f3..328c1eaecd 100644 --- a/components/esm3/loadprob.hpp +++ b/components/esm3/loadprob.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -29,7 +30,8 @@ namespace ESM Data mData; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mScript; + RefId mId, mScript; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadrace.cpp b/components/esm3/loadrace.cpp index 0deff3b9c3..f57ffc24ea 100644 --- a/components/esm3/loadrace.cpp +++ b/components/esm3/loadrace.cpp @@ -30,7 +30,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("FNAM"): @@ -62,7 +62,7 @@ namespace ESM } void Race::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/loadrace.hpp b/components/esm3/loadrace.hpp index 3dba09d128..36dce54cce 100644 --- a/components/esm3/loadrace.hpp +++ b/components/esm3/loadrace.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "spelllist.hpp" namespace ESM @@ -68,7 +69,8 @@ namespace ESM RADTstruct mData; unsigned int mRecordFlags; - std::string mId, mName, mDescription; + std::string mName, mDescription; + RefId mId; SpellList mPowers; void load(ESMReader& esm, bool& isDeleted); diff --git a/components/esm3/loadregn.cpp b/components/esm3/loadregn.cpp index bd1c00e8c4..361119d562 100644 --- a/components/esm3/loadregn.cpp +++ b/components/esm3/loadregn.cpp @@ -17,7 +17,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("FNAM"): @@ -44,7 +44,7 @@ namespace ESM break; } case fourCC("BNAM"): - mSleepList = esm.getHString(); + mSleepList = esm.getRefId(); break; case fourCC("CNAM"): esm.getHT(mMapColor); @@ -53,7 +53,7 @@ namespace ESM { esm.getSubHeader(); SoundRef sr; - sr.mSound.assign(esm.getString(32)); + sr.mSound = ESM::RefId::stringRefId(esm.getString(32)); esm.getT(sr.mChance); mSoundList.push_back(sr); break; @@ -74,7 +74,7 @@ namespace ESM void Region::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -89,13 +89,13 @@ namespace ESM else esm.writeHNT("WEAT", mData); - esm.writeHNOCString("BNAM", mSleepList); + esm.writeHNOCString("BNAM", mSleepList.getRefIdString()); esm.writeHNT("CNAM", mMapColor); for (std::vector::const_iterator it = mSoundList.begin(); it != mSoundList.end(); ++it) { esm.startSubRecord("SNAM"); - esm.writeFixedSizeString(it->mSound, 32); + esm.writeFixedSizeString(it->mSound.getRefIdString(), 32); esm.writeT(it->mChance); esm.endRecord("SNAM"); } diff --git a/components/esm3/loadregn.hpp b/components/esm3/loadregn.hpp index 159b79fa24..00c5546e2f 100644 --- a/components/esm3/loadregn.hpp +++ b/components/esm3/loadregn.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -35,7 +36,7 @@ namespace ESM // Reference to a sound that is played randomly in this region struct SoundRef { - std::string mSound; + ESM::RefId mSound; unsigned char mChance; }; @@ -45,7 +46,8 @@ namespace ESM unsigned int mRecordFlags; // sleepList refers to a leveled list of creatures you can meet if // you sleep outside in this region. - std::string mId, mName, mSleepList; + RefId mId, mSleepList; + std::string mName; std::vector mSoundList; diff --git a/components/esm3/loadrepa.cpp b/components/esm3/loadrepa.cpp index 93343e3e98..76b7fde15a 100644 --- a/components/esm3/loadrepa.cpp +++ b/components/esm3/loadrepa.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -32,7 +32,7 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); @@ -55,7 +55,7 @@ namespace ESM void Repair::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -67,7 +67,7 @@ namespace ESM esm.writeHNOCString("FNAM", mName); esm.writeHNT("RIDT", mData, 16); - esm.writeHNOString("SCRI", mScript); + esm.writeHNOString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadrepa.hpp b/components/esm3/loadrepa.hpp index 4bc350bc61..63f0a2959d 100644 --- a/components/esm3/loadrepa.hpp +++ b/components/esm3/loadrepa.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -29,7 +30,8 @@ namespace ESM Data mData; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mScript; + RefId mId, mScript; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadscpt.cpp b/components/esm3/loadscpt.cpp index 365db2cd69..531441fd20 100644 --- a/components/esm3/loadscpt.cpp +++ b/components/esm3/loadscpt.cpp @@ -98,7 +98,7 @@ namespace ESM case fourCC("SCHD"): { esm.getSubHeader(); - mId = esm.getString(32); + mId = ESM::RefId::stringRefId(esm.getString(32)); esm.getT(mData); hasHeader = true; @@ -152,7 +152,7 @@ namespace ESM varNameString.append(*it); esm.startSubRecord("SCHD"); - esm.writeFixedSizeString(mId, 32); + esm.writeFixedSizeString(mId.getRefIdString(), 32); esm.writeT(mData, 20); esm.endRecord("SCHD"); @@ -188,11 +188,11 @@ namespace ESM mVarNames.clear(); mScriptData.clear(); - - if (mId.find("::") != std::string::npos) - mScriptText = "Begin \"" + mId + "\"\n\nEnd " + mId + "\n"; + std::string stringId = mId.getRefIdString(); + if (stringId.find("::") != std::string::npos) + mScriptText = "Begin \"" + stringId + "\"\n\nEnd " + stringId + "\n"; else - mScriptText = "Begin " + mId + "\n\nEnd " + mId + "\n"; + mScriptText = "Begin " + stringId + "\n\nEnd " + stringId + "\n"; } } diff --git a/components/esm3/loadscpt.hpp b/components/esm3/loadscpt.hpp index 33b50676f3..f0fab766cf 100644 --- a/components/esm3/loadscpt.hpp +++ b/components/esm3/loadscpt.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -37,7 +38,7 @@ namespace ESM }; unsigned int mRecordFlags; - std::string mId; + RefId mId; SCHDstruct mData; diff --git a/components/esm3/loadskil.cpp b/components/esm3/loadskil.cpp index b38d131811..e80b3576af 100644 --- a/components/esm3/loadskil.cpp +++ b/components/esm3/loadskil.cpp @@ -133,7 +133,7 @@ namespace ESM // create an ID from the index and the name (only used in the editor and likely to change in the // future) - mId = indexToId(mIndex); + mId = ESM::RefId::stringRefId(indexToId(mIndex)); } void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const diff --git a/components/esm3/loadskil.hpp b/components/esm3/loadskil.hpp index 0db629d51c..99a800871d 100644 --- a/components/esm3/loadskil.hpp +++ b/components/esm3/loadskil.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -25,7 +26,7 @@ namespace ESM static std::string_view getRecordType() { return "Skill"; } unsigned int mRecordFlags; - std::string mId; + RefId mId; struct SKDTstruct { diff --git a/components/esm3/loadsndg.cpp b/components/esm3/loadsndg.cpp index 29f010a42a..515a9abb9e 100644 --- a/components/esm3/loadsndg.cpp +++ b/components/esm3/loadsndg.cpp @@ -19,7 +19,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("DATA"): @@ -27,10 +27,10 @@ namespace ESM hasData = true; break; case fourCC("CNAM"): - mCreature = esm.getHString(); + mCreature = esm.getRefId(); break; case fourCC("SNAM"): - mSound = esm.getHString(); + mSound = esm.getRefId(); break; case SREC_DELE: esm.skipHSub(); @@ -49,7 +49,7 @@ namespace ESM } void SoundGenerator::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -58,8 +58,8 @@ namespace ESM } esm.writeHNT("DATA", mType, 4); - esm.writeHNOCString("CNAM", mCreature); - esm.writeHNOCString("SNAM", mSound); + esm.writeHNOCString("CNAM", mCreature.getRefIdString()); + esm.writeHNOCString("SNAM", mSound.getRefIdString()); } void SoundGenerator::blank() diff --git a/components/esm3/loadsndg.hpp b/components/esm3/loadsndg.hpp index dad6a47550..fff4b98439 100644 --- a/components/esm3/loadsndg.hpp +++ b/components/esm3/loadsndg.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -38,7 +39,7 @@ namespace ESM int mType; unsigned int mRecordFlags; - std::string mId, mCreature, mSound; + RefId mId, mCreature, mSound; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadsoun.cpp b/components/esm3/loadsoun.cpp index 9a223fe41c..99743a8f42 100644 --- a/components/esm3/loadsoun.cpp +++ b/components/esm3/loadsoun.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("FNAM"): @@ -46,7 +46,7 @@ namespace ESM void Sound::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/loadsoun.hpp b/components/esm3/loadsoun.hpp index 5c82a9eb2e..0da915b0f1 100644 --- a/components/esm3/loadsoun.hpp +++ b/components/esm3/loadsoun.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -25,7 +26,8 @@ namespace ESM SOUNstruct mData; unsigned int mRecordFlags; - std::string mId, mSound; + std::string mSound; + RefId mId; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadspel.cpp b/components/esm3/loadspel.cpp index c1f52e5e1a..ede06c0591 100644 --- a/components/esm3/loadspel.cpp +++ b/components/esm3/loadspel.cpp @@ -20,7 +20,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("FNAM"): @@ -53,7 +53,7 @@ namespace ESM void Spell::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { diff --git a/components/esm3/loadspel.hpp b/components/esm3/loadspel.hpp index 6467b0983f..50ed65d3de 100644 --- a/components/esm3/loadspel.hpp +++ b/components/esm3/loadspel.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" #include "effectlist.hpp" namespace ESM @@ -45,7 +46,8 @@ namespace ESM SPDTstruct mData; unsigned int mRecordFlags; - std::string mId, mName; + std::string mName; + RefId mId; EffectList mEffects; void load(ESMReader& esm, bool& isDeleted); diff --git a/components/esm3/loadsscr.cpp b/components/esm3/loadsscr.cpp index 7098e664cb..c911c71bee 100644 --- a/components/esm3/loadsscr.cpp +++ b/components/esm3/loadsscr.cpp @@ -18,7 +18,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("DATA"): @@ -42,7 +42,7 @@ namespace ESM } void StartScript::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { esm.writeHNString("DELE", "", 3); diff --git a/components/esm3/loadsscr.hpp b/components/esm3/loadsscr.hpp index 375d7ce889..6c9163e4e6 100644 --- a/components/esm3/loadsscr.hpp +++ b/components/esm3/loadsscr.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -28,7 +29,7 @@ namespace ESM std::string mData; unsigned int mRecordFlags; - std::string mId; + RefId mId; // Load a record and add it to the list void load(ESMReader& esm, bool& isDeleted); diff --git a/components/esm3/loadstat.cpp b/components/esm3/loadstat.cpp index d793200b00..cbac768267 100644 --- a/components/esm3/loadstat.cpp +++ b/components/esm3/loadstat.cpp @@ -19,7 +19,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -40,7 +40,7 @@ namespace ESM } void Static::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { esm.writeHNString("DELE", "", 3); diff --git a/components/esm3/loadstat.hpp b/components/esm3/loadstat.hpp index 16b21e6f75..c12628cf80 100644 --- a/components/esm3/loadstat.hpp +++ b/components/esm3/loadstat.hpp @@ -4,6 +4,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -31,8 +32,9 @@ namespace ESM static std::string_view getRecordType() { return "Static"; } unsigned int mRecordFlags; - std::string mId, mModel; - + RefId mId; + std::string mModel; + void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; diff --git a/components/esm3/loadweap.cpp b/components/esm3/loadweap.cpp index 8f74eeee69..5080fa8bcd 100644 --- a/components/esm3/loadweap.cpp +++ b/components/esm3/loadweap.cpp @@ -19,7 +19,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case SREC_NAME: - mId = esm.getHString(); + mId = esm.getRefId(); hasName = true; break; case fourCC("MODL"): @@ -33,13 +33,13 @@ namespace ESM hasData = true; break; case fourCC("SCRI"): - mScript = esm.getHString(); + mScript = esm.getRefId(); break; case fourCC("ITEX"): mIcon = esm.getHString(); break; case fourCC("ENAM"): - mEnchant = esm.getHString(); + mEnchant = esm.getRefId(); break; case SREC_DELE: esm.skipHSub(); @@ -57,7 +57,7 @@ namespace ESM } void Weapon::save(ESMWriter& esm, bool isDeleted) const { - esm.writeHNCString("NAME", mId); + esm.writeHNCString("NAME", mId.getRefIdString()); if (isDeleted) { @@ -68,9 +68,9 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("WPDT", mData, 32); - esm.writeHNOCString("SCRI", mScript); + esm.writeHNOCString("SCRI", mScript.getRefIdString()); esm.writeHNOCString("ITEX", mIcon); - esm.writeHNOCString("ENAM", mEnchant); + esm.writeHNOCString("ENAM", mEnchant.getRefIdString()); } void Weapon::blank() diff --git a/components/esm3/loadweap.hpp b/components/esm3/loadweap.hpp index 2d1acb3f78..2b2eec4a40 100644 --- a/components/esm3/loadweap.hpp +++ b/components/esm3/loadweap.hpp @@ -4,6 +4,7 @@ #include #include "loadskil.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -75,7 +76,8 @@ namespace ESM WPDTstruct mData; unsigned int mRecordFlags; - std::string mId, mName, mModel, mIcon, mEnchant, mScript; + RefId mId, mEnchant, mScript; + std::string mName, mModel, mIcon; void load(ESMReader& esm, bool& isDeleted); void save(ESMWriter& esm, bool isDeleted = false) const; @@ -103,8 +105,8 @@ namespace ESM // std::string mDisplayName; // TODO: will be needed later for editor std::string mShortGroup; std::string mLongGroup; - std::string mSoundIdDown; - std::string mSoundIdUp; + ESM::RefId mSoundIdDown; + ESM::RefId mSoundIdUp; std::string mAttachBone; std::string mSheathingBone; Skill::SkillEnum mSkill; @@ -116,8 +118,8 @@ namespace ESM std::string sheathingBone, Skill::SkillEnum skill, Class weaponClass, int ammoType, int flags) : mShortGroup(std::move(shortGroup)) , mLongGroup(std::move(longGroup)) - , mSoundIdDown(soundId + " Down") - , mSoundIdUp(soundId + " Up") + , mSoundIdDown(ESM::RefId::stringRefId(soundId + " Down")) + , mSoundIdUp(ESM::RefId::stringRefId(soundId + " Up")) , mAttachBone(std::move(attachBone)) , mSheathingBone(std::move(sheathingBone)) , mSkill(skill) diff --git a/components/esm3/magiceffects.hpp b/components/esm3/magiceffects.hpp index 3789ebf991..d0b6c6787b 100644 --- a/components/esm3/magiceffects.hpp +++ b/components/esm3/magiceffects.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace ESM { @@ -21,7 +22,7 @@ namespace ESM struct SummonKey { - SummonKey(int effectId, const std::string& sourceId, int index) + SummonKey(int effectId, const ESM::RefId& sourceId, int index) : mEffectId(effectId) , mSourceId(sourceId) , mEffectIndex(index) @@ -49,7 +50,7 @@ namespace ESM } int mEffectId; - std::string mSourceId; + ESM::RefId mSourceId; int mEffectIndex; }; } diff --git a/components/esm3/npcstats.cpp b/components/esm3/npcstats.cpp index 455a1d77f4..c3736523a7 100644 --- a/components/esm3/npcstats.cpp +++ b/components/esm3/npcstats.cpp @@ -19,7 +19,7 @@ namespace ESM { while (esm.isNextSub("FACT")) { - std::string id = esm.getHString(); + ESM::RefId id = esm.getRefId(); Faction faction; @@ -113,7 +113,7 @@ namespace ESM esm.getHNOT(mSpecIncreases, "SPEC"); while (esm.isNextSub("USED")) - mUsedIds.push_back(esm.getHString()); + mUsedIds.push_back(esm.getRefId()); mTimeToStartDrowning = 0; esm.getHNOT(mTimeToStartDrowning, "DRTI"); @@ -132,9 +132,9 @@ namespace ESM void NpcStats::save(ESMWriter& esm) const { - for (std::map::const_iterator iter(mFactions.begin()); iter != mFactions.end(); ++iter) + for (auto iter(mFactions.begin()); iter != mFactions.end(); ++iter) { - esm.writeHNString("FACT", iter->first); + esm.writeHNString("FACT", iter->first.getRefIdString()); if (iter->second.mExpelled) { @@ -185,8 +185,8 @@ namespace ESM if (mSpecIncreases[0] != 0 || mSpecIncreases[1] != 0 || mSpecIncreases[2] != 0) esm.writeHNT("SPEC", mSpecIncreases); - for (std::vector::const_iterator iter(mUsedIds.begin()); iter != mUsedIds.end(); ++iter) - esm.writeHNString("USED", *iter); + for (auto iter(mUsedIds.begin()); iter != mUsedIds.end(); ++iter) + esm.writeHNString("USED", iter->getRefIdString()); if (mTimeToStartDrowning) esm.writeHNT("DRTI", mTimeToStartDrowning); diff --git a/components/esm3/npcstats.hpp b/components/esm3/npcstats.hpp index f18cb31513..4bf53cde3d 100644 --- a/components/esm3/npcstats.hpp +++ b/components/esm3/npcstats.hpp @@ -4,7 +4,7 @@ #include #include #include - +#include #include "statstate.hpp" namespace ESM @@ -29,7 +29,7 @@ namespace ESM bool mWerewolfDeprecatedData; - std::map mFactions; // lower case IDs + std::map mFactions; // lower case IDs int mDisposition; StatState mSkills[27]; int mBounty; @@ -38,7 +38,7 @@ namespace ESM int mLevelProgress; int mSkillIncrease[8]; int mSpecIncreases[3]; - std::vector mUsedIds; // lower case IDs + std::vector mUsedIds; // lower case IDs float mTimeToStartDrowning; int mCrimeId; diff --git a/components/esm3/player.cpp b/components/esm3/player.cpp index f75ded51d7..fa4c5ae8ac 100644 --- a/components/esm3/player.cpp +++ b/components/esm3/player.cpp @@ -28,7 +28,7 @@ namespace ESM if (esm.isNextSub("AMOV")) esm.skipHSub(); - mBirthsign = esm.getHNString("SIGN"); + mBirthsign = ESM::RefId::stringRefId(esm.getHNString("SIGN")); mCurrentCrimeId = -1; esm.getHNOT(mCurrentCrimeId, "CURD"); @@ -38,8 +38,8 @@ namespace ESM bool checkPrevItems = true; while (checkPrevItems) { - std::string boundItemId = esm.getHNOString("BOUN"); - std::string prevItemId = esm.getHNOString("PREV"); + ESM::RefId boundItemId = ESM::RefId::stringRefId(esm.getHNOString("BOUN")); + ESM::RefId prevItemId = ESM::RefId::stringRefId(esm.getHNOString("PREV")); if (!boundItemId.empty()) mPreviousItems[boundItemId] = prevItemId; @@ -101,15 +101,15 @@ namespace ESM mMarkedCell.save(esm); } - esm.writeHNString("SIGN", mBirthsign); + esm.writeHNString("SIGN", mBirthsign.getRefIdString()); esm.writeHNT("CURD", mCurrentCrimeId); esm.writeHNT("PAYD", mPaidCrimeId); for (PreviousItems::const_iterator it = mPreviousItems.begin(); it != mPreviousItems.end(); ++it) { - esm.writeHNString("BOUN", it->first); - esm.writeHNString("PREV", it->second); + esm.writeHNString("BOUN", it->first.getRefIdString()); + esm.writeHNString("PREV", it->second.getRefIdString()); } esm.writeHNT("WWAT", mSaveAttributes); diff --git a/components/esm3/player.hpp b/components/esm3/player.hpp index 391ae6525b..82ce5e25df 100644 --- a/components/esm3/player.hpp +++ b/components/esm3/player.hpp @@ -26,7 +26,7 @@ namespace ESM bool mSetWerewolfAcrobatics; Position mMarkedPosition; CellId mMarkedCell; - std::string mBirthsign; + ESM::RefId mBirthsign; int mCurrentCrimeId; int mPaidCrimeId; @@ -34,7 +34,7 @@ namespace ESM float mSaveAttributes[Attribute::Length]; float mSaveSkills[Skill::Length]; - typedef std::map PreviousItems; // previous equipped items, needed for bound spells + typedef std::map PreviousItems; // previous equipped items, needed for bound spells PreviousItems mPreviousItems; void load(ESMReader& esm); diff --git a/components/esm3/projectilestate.cpp b/components/esm3/projectilestate.cpp index 41451ac495..2f40b384c2 100644 --- a/components/esm3/projectilestate.cpp +++ b/components/esm3/projectilestate.cpp @@ -8,7 +8,7 @@ namespace ESM void BaseProjectileState::save(ESMWriter& esm) const { - esm.writeHNString("ID__", mId); + esm.writeHNString("ID__", mId.getRefIdString()); esm.writeHNT("VEC3", mPosition); esm.writeHNT("QUAT", mOrientation); esm.writeHNT("ACTO", mActorId); @@ -16,7 +16,7 @@ namespace ESM void BaseProjectileState::load(ESMReader& esm) { - mId = esm.getHNString("ID__"); + mId = ESM::RefId::stringRefId(esm.getHNString("ID__")); esm.getHNT(mPosition, "VEC3"); esm.getHNT(mOrientation, "QUAT"); esm.getHNT(mActorId, "ACTO"); @@ -26,7 +26,7 @@ namespace ESM { BaseProjectileState::save(esm); - esm.writeHNString("SPEL", mSpellId); + esm.writeHNString("SPEL", mSpellId.getRefIdString()); esm.writeHNT("SPED", mSpeed); esm.writeHNT("SLOT", mSlot); } @@ -35,7 +35,7 @@ namespace ESM { BaseProjectileState::load(esm); - mSpellId = esm.getHNString("SPEL"); + mSpellId = ESM::RefId::stringRefId(esm.getHNString("SPEL")); if (esm.isNextSub("SRCN")) // for backwards compatibility esm.skipHSub(); EffectList().load(esm); // for backwards compatibility @@ -54,7 +54,7 @@ namespace ESM { BaseProjectileState::save(esm); - esm.writeHNString("BOW_", mBowId); + esm.writeHNString("BOW_", mBowId.getRefIdString()); esm.writeHNT("VEL_", mVelocity); esm.writeHNT("STR_", mAttackStrength); } @@ -63,7 +63,7 @@ namespace ESM { BaseProjectileState::load(esm); - mBowId = esm.getHNString("BOW_"); + mBowId = ESM::RefId::stringRefId(esm.getHNString("BOW_")); esm.getHNT(mVelocity, "VEL_"); mAttackStrength = 1.f; diff --git a/components/esm3/projectilestate.hpp b/components/esm3/projectilestate.hpp index 97e8f2c327..9c61e687ea 100644 --- a/components/esm3/projectilestate.hpp +++ b/components/esm3/projectilestate.hpp @@ -9,6 +9,7 @@ #include "effectlist.hpp" #include "components/esm/util.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -17,7 +18,7 @@ namespace ESM struct BaseProjectileState { - std::string mId; + RefId mId; Vector3 mPosition; Quaternion mOrientation; @@ -30,7 +31,7 @@ namespace ESM struct MagicBoltState : public BaseProjectileState { - std::string mSpellId; + RefId mSpellId; float mSpeed; int mSlot; @@ -40,7 +41,7 @@ namespace ESM struct ProjectileState : public BaseProjectileState { - std::string mBowId; + RefId mBowId; Vector3 mVelocity; float mAttackStrength; diff --git a/components/esm3/queststate.cpp b/components/esm3/queststate.cpp index 0d39c59b32..33f5bfb35e 100644 --- a/components/esm3/queststate.cpp +++ b/components/esm3/queststate.cpp @@ -8,14 +8,14 @@ namespace ESM void QuestState::load(ESMReader& esm) { - mTopic = esm.getHNString("YETO"); + mTopic = ESM::RefId::stringRefId(esm.getHNString("YETO")); esm.getHNOT(mState, "QSTA"); esm.getHNOT(mFinished, "QFIN"); } void QuestState::save(ESMWriter& esm) const { - esm.writeHNString("YETO", mTopic); + esm.writeHNString("YETO", mTopic.getRefIdString()); esm.writeHNT("QSTA", mState); esm.writeHNT("QFIN", mFinished); } diff --git a/components/esm3/queststate.hpp b/components/esm3/queststate.hpp index 31c932e206..78182fc95d 100644 --- a/components/esm3/queststate.hpp +++ b/components/esm3/queststate.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_QUESTSTATE_H #include +#include namespace ESM { @@ -12,7 +13,7 @@ namespace ESM struct QuestState { - std::string mTopic; // lower case id + ESM::RefId mTopic; // lower case id int mState; unsigned char mFinished; diff --git a/components/esm3/quickkeys.cpp b/components/esm3/quickkeys.cpp index 275320bd2b..f1003ccc56 100644 --- a/components/esm3/quickkeys.cpp +++ b/components/esm3/quickkeys.cpp @@ -20,7 +20,7 @@ namespace ESM QuickKey key; key.mType = keyType; - key.mId = id; + key.mId = ESM::RefId::stringRefId(id); mKeys.push_back(key); @@ -34,7 +34,7 @@ namespace ESM for (std::vector::const_iterator it = mKeys.begin(); it != mKeys.end(); ++it) { esm.writeHNT("TYPE", it->mType); - esm.writeHNString("ID__", it->mId); + esm.writeHNString("ID__", it->mId.getRefIdString()); } } diff --git a/components/esm3/quickkeys.hpp b/components/esm3/quickkeys.hpp index 0952f9d39f..ddc29c0e3c 100644 --- a/components/esm3/quickkeys.hpp +++ b/components/esm3/quickkeys.hpp @@ -3,6 +3,7 @@ #include #include +#include "components/esm/refid.hpp" namespace ESM { @@ -14,7 +15,7 @@ namespace ESM struct QuickKey { int mType; - std::string mId; // Spell or Item ID + RefId mId; // Spell or Item ID }; std::vector mKeys; diff --git a/components/esm3/savedgame.cpp b/components/esm3/savedgame.cpp index 9251bbb15a..09620258bc 100644 --- a/components/esm3/savedgame.cpp +++ b/components/esm3/savedgame.cpp @@ -13,10 +13,10 @@ namespace ESM mPlayerName = esm.getHNString("PLNA"); esm.getHNOT(mPlayerLevel, "PLLE"); - mPlayerClassId = esm.getHNOString("PLCL"); + mPlayerClassId = ESM::RefId::stringRefId(esm.getHNOString("PLCL")); mPlayerClassName = esm.getHNOString("PLCN"); - mPlayerCell = esm.getHNString("PLCE"); + mPlayerCell = ESM::RefId::stringRefId(esm.getHNString("PLCE")); esm.getHNTSized<16>(mInGameTime, "TSTM"); esm.getHNT(mTimePlayed, "TIME"); mDescription = esm.getHNString("DESC"); @@ -36,11 +36,11 @@ namespace ESM esm.writeHNT("PLLE", mPlayerLevel); if (!mPlayerClassId.empty()) - esm.writeHNString("PLCL", mPlayerClassId); + esm.writeHNString("PLCL", mPlayerClassId.getRefIdString()); else esm.writeHNString("PLCN", mPlayerClassName); - esm.writeHNString("PLCE", mPlayerCell); + esm.writeHNString("PLCE", mPlayerCell.getRefIdString()); esm.writeHNT("TSTM", mInGameTime, 16); esm.writeHNT("TIME", mTimePlayed); esm.writeHNString("DESC", mDescription); diff --git a/components/esm3/savedgame.hpp b/components/esm3/savedgame.hpp index 282ce07bb9..a252523c68 100644 --- a/components/esm3/savedgame.hpp +++ b/components/esm3/savedgame.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -24,12 +25,12 @@ namespace ESM int mPlayerLevel; // ID of class - std::string mPlayerClassId; + ESM::RefId mPlayerClassId; // Name of the class. When using a custom class, the ID is not really meaningful prior // to loading the savegame, so the name is stored separately. std::string mPlayerClassName; - std::string mPlayerCell; + ESM::RefId mPlayerCell; EpochTimeStamp mInGameTime; double mTimePlayed; std::string mDescription; diff --git a/components/esm3/spelllist.cpp b/components/esm3/spelllist.cpp index 00da33244b..a2625fc7b3 100644 --- a/components/esm3/spelllist.cpp +++ b/components/esm3/spelllist.cpp @@ -10,21 +10,21 @@ namespace ESM void SpellList::add(ESMReader& esm) { - mList.push_back(esm.getHString()); + mList.push_back(esm.getRefId()); } void SpellList::save(ESMWriter& esm) const { - for (std::vector::const_iterator it = mList.begin(); it != mList.end(); ++it) + for (auto it = mList.begin(); it != mList.end(); ++it) { - esm.writeHNString("NPCS", *it, 32); + esm.writeHNString("NPCS", it->getRefIdString(), 32); } } - bool SpellList::exists(const std::string& spell) const + bool SpellList::exists(const ESM::RefId& spell) const { - for (std::vector::const_iterator it = mList.begin(); it != mList.end(); ++it) - if (Misc::StringUtils::ciEqual(*it, spell)) + for (auto it = mList.begin(); it != mList.end(); ++it) + if (ESM::RefId::ciEqual(*it, spell)) return true; return false; } diff --git a/components/esm3/spelllist.hpp b/components/esm3/spelllist.hpp index 12d487f3b8..3d9bf5174b 100644 --- a/components/esm3/spelllist.hpp +++ b/components/esm3/spelllist.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace ESM { @@ -15,10 +16,10 @@ namespace ESM */ struct SpellList { - std::vector mList; + std::vector mList; /// Is this spell ID in mList? - bool exists(const std::string& spell) const; + bool exists(const ESM::RefId& spell) const; /// Load one spell, assumes the subrecord name was already read void add(ESMReader& esm); diff --git a/components/esm3/spellstate.cpp b/components/esm3/spellstate.cpp index 0108c85d14..c1991c5d74 100644 --- a/components/esm3/spellstate.cpp +++ b/components/esm3/spellstate.cpp @@ -12,7 +12,7 @@ namespace ESM { while (esm.isNextSub("SPEL")) { - std::string id = esm.getHString(); + ESM::RefId id = esm.getRefId(); SpellParams state; while (esm.isNextSub("INDX")) @@ -40,13 +40,13 @@ namespace ESM else { while (esm.isNextSub("SPEL")) - mSpells.emplace_back(esm.getHString()); + mSpells.emplace_back(esm.getRefId()); } // Obsolete while (esm.isNextSub("PERM")) { - std::string spellId = esm.getHString(); + ESM::RefId spellId = esm.getRefId(); std::vector permEffectList; while (true) @@ -75,7 +75,7 @@ namespace ESM // Obsolete while (esm.isNextSub("CORP")) { - std::string id = esm.getHString(); + ESM::RefId id = esm.getRefId(); CorprusStats stats; esm.getHNT(stats.mWorsenings, "WORS"); @@ -86,29 +86,29 @@ namespace ESM while (esm.isNextSub("USED")) { - std::string id = esm.getHString(); + ESM::RefId id = esm.getRefId(); TimeStamp time; esm.getHNT(time, "TIME"); mUsedPowers[id] = time; } - mSelectedSpell = esm.getHNOString("SLCT"); + mSelectedSpell = ESM::RefId::stringRefId(esm.getHNOString("SLCT")); } void SpellState::save(ESMWriter& esm) const { - for (const std::string& spell : mSpells) - esm.writeHNString("SPEL", spell); + for (const ESM::RefId& spell : mSpells) + esm.writeHNString("SPEL", spell.getRefIdString()); - for (std::map::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it) + for (auto it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it) { - esm.writeHNString("USED", it->first); + esm.writeHNString("USED", it->first.getRefIdString()); esm.writeHNT("TIME", it->second); } if (!mSelectedSpell.empty()) - esm.writeHNString("SLCT", mSelectedSpell); + esm.writeHNString("SLCT", mSelectedSpell.getRefIdString()); } } diff --git a/components/esm3/spellstate.hpp b/components/esm3/spellstate.hpp index bf7fa12f39..39462f039f 100644 --- a/components/esm3/spellstate.hpp +++ b/components/esm3/spellstate.hpp @@ -7,11 +7,13 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { class ESMReader; class ESMWriter; + struct RefId; // NOTE: spell ids must be lower case struct SpellState @@ -34,16 +36,16 @@ namespace ESM std::map mEffectRands; // std::set mPurgedEffects; // indices of purged effects }; - std::vector mSpells; + std::vector mSpells; // FIXME: obsolete, used only for old saves - std::map mSpellParams; - std::map> mPermanentSpellEffects; - std::map mCorprusSpells; + std::map mSpellParams; + std::map> mPermanentSpellEffects; + std::map mCorprusSpells; - std::map mUsedPowers; + std::map mUsedPowers; - std::string mSelectedSpell; + ESM::RefId mSelectedSpell; void load(ESMReader& esm); void save(ESMWriter& esm) const; diff --git a/components/esm3/stolenitems.cpp b/components/esm3/stolenitems.cpp index 658902247c..42d3d28b04 100644 --- a/components/esm3/stolenitems.cpp +++ b/components/esm3/stolenitems.cpp @@ -10,14 +10,14 @@ namespace ESM { for (StolenItemsMap::const_iterator it = mStolenItems.begin(); it != mStolenItems.end(); ++it) { - esm.writeHNString("NAME", it->first); - for (std::map, int>::const_iterator ownerIt = it->second.begin(); + esm.writeHNString("NAME", it->first.getRefIdString()); + for (auto ownerIt = it->second.begin(); ownerIt != it->second.end(); ++ownerIt) { if (ownerIt->first.second) - esm.writeHNString("FNAM", ownerIt->first.first); + esm.writeHNString("FNAM", ownerIt->first.first.getRefIdString()); else - esm.writeHNString("ONAM", ownerIt->first.first); + esm.writeHNString("ONAM", ownerIt->first.first.getRefIdString()); esm.writeHNT("COUN", ownerIt->second); } } @@ -27,13 +27,13 @@ namespace ESM { while (esm.isNextSub("NAME")) { - std::string itemid = esm.getHString(); + ESM::RefId itemid = esm.getRefId(); - std::map, int> ownerMap; + std::map, int> ownerMap; while (esm.isNextSub("FNAM") || esm.isNextSub("ONAM")) { const bool isFaction = (esm.retSubName() == "FNAM"); - std::string owner = esm.getHString(); + ESM::RefId owner = esm.getRefId(); int count; esm.getHNT(count, "COUN"); ownerMap.emplace(std::make_pair(std::move(owner), isFaction), count); diff --git a/components/esm3/stolenitems.hpp b/components/esm3/stolenitems.hpp index 94c4d9af85..14e5860fc7 100644 --- a/components/esm3/stolenitems.hpp +++ b/components/esm3/stolenitems.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace ESM { @@ -12,7 +13,7 @@ namespace ESM // format 0, saved games only struct StolenItems { - typedef std::map, int>> StolenItemsMap; + typedef std::map, int>> StolenItemsMap; StolenItemsMap mStolenItems; void load(ESMReader& esm); diff --git a/components/esm3/transport.cpp b/components/esm3/transport.cpp index 9270219fa5..850edb1170 100644 --- a/components/esm3/transport.cpp +++ b/components/esm3/transport.cpp @@ -18,7 +18,7 @@ namespace ESM } else if (esm.retSubName().toInt() == fourCC("DNAM")) { - const std::string name = esm.getHString(); + const ESM::RefId name = esm.getRefId(); if (mList.empty()) Log(Debug::Warning) << "Encountered DNAM record without DODT record, skipped."; else @@ -32,7 +32,7 @@ namespace ESM for (DestIter it = mList.begin(); it != mList.end(); ++it) { esm.writeHNT("DODT", it->mPos, sizeof(it->mPos)); - esm.writeHNOCString("DNAM", it->mCellName); + esm.writeHNOCString("DNAM", it->mCellName.getRefIdString()); } } diff --git a/components/esm3/transport.hpp b/components/esm3/transport.hpp index 555504c994..2e70a98e11 100644 --- a/components/esm3/transport.hpp +++ b/components/esm3/transport.hpp @@ -5,6 +5,7 @@ #include #include "components/esm/defs.hpp" +#include "components/esm/refid.hpp" namespace ESM { @@ -19,7 +20,7 @@ namespace ESM struct Dest { Position mPos; - std::string mCellName; + ESM::RefId mCellName; }; std::vector mList; diff --git a/components/esm3/weatherstate.cpp b/components/esm3/weatherstate.cpp index 390259161b..3d4b13a66e 100644 --- a/components/esm3/weatherstate.cpp +++ b/components/esm3/weatherstate.cpp @@ -25,7 +25,7 @@ namespace ESM { void WeatherState::load(ESMReader& esm) { - mCurrentRegion = esm.getHNString(currentRegionRecord); + mCurrentRegion = ESM::RefId::stringRefId(esm.getHNString(currentRegionRecord)); esm.getHNT(mTimePassed, timePassedRecord); esm.getHNT(mFastForward, fastForwardRecord); esm.getHNT(mWeatherUpdateTime, weatherUpdateTimeRecord); @@ -36,7 +36,7 @@ namespace ESM while (esm.isNextSub(regionNameRecord)) { - std::string regionID = esm.getHString(); + ESM::RefId regionID = esm.getRefId(); RegionWeatherState region; esm.getHNT(region.mWeather, regionWeatherRecord); while (esm.isNextSub(regionChanceRecord)) @@ -52,7 +52,7 @@ namespace ESM void WeatherState::save(ESMWriter& esm) const { - esm.writeHNCString(currentRegionRecord, mCurrentRegion); + esm.writeHNCString(currentRegionRecord, mCurrentRegion.getRefIdString()); esm.writeHNT(timePassedRecord, mTimePassed); esm.writeHNT(fastForwardRecord, mFastForward); esm.writeHNT(weatherUpdateTimeRecord, mWeatherUpdateTime); @@ -61,10 +61,10 @@ namespace ESM esm.writeHNT(nextWeatherRecord, mNextWeather); esm.writeHNT(queuedWeatherRecord, mQueuedWeather); - std::map::const_iterator it = mRegions.begin(); + auto it = mRegions.begin(); for (; it != mRegions.end(); ++it) { - esm.writeHNCString(regionNameRecord, it->first.c_str()); + esm.writeHNCString(regionNameRecord, it->first.getRefIdString().c_str()); esm.writeHNT(regionWeatherRecord, it->second.mWeather); for (size_t i = 0; i < it->second.mChances.size(); ++i) { diff --git a/components/esm3/weatherstate.hpp b/components/esm3/weatherstate.hpp index e2416ef5d5..9e352a3500 100644 --- a/components/esm3/weatherstate.hpp +++ b/components/esm3/weatherstate.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace ESM { @@ -18,7 +19,7 @@ namespace ESM struct WeatherState { - std::string mCurrentRegion; + ESM::RefId mCurrentRegion; float mTimePassed; bool mFastForward; float mWeatherUpdateTime; @@ -26,7 +27,7 @@ namespace ESM int mCurrentWeather; int mNextWeather; int mQueuedWeather; - std::map mRegions; + std::map mRegions; void load(ESMReader& esm); void save(ESMWriter& esm) const; diff --git a/components/esmloader/esmdata.cpp b/components/esmloader/esmdata.cpp index e03605f13f..c7dabfdf1c 100644 --- a/components/esmloader/esmdata.cpp +++ b/components/esmloader/esmdata.cpp @@ -33,7 +33,7 @@ namespace EsmLoader } template - auto withStatic(std::string_view refId, const std::vector& values, F&& f) + auto withStatic(const ESM::RefId& refId, const std::vector& values, F&& f) { const auto it = std::lower_bound(values.begin(), values.end(), refId, LessById{}); @@ -44,7 +44,7 @@ namespace EsmLoader } template - auto withStatic(std::string_view refId, ESM::RecNameInts type, const EsmData& content, F&& f) + auto withStatic(const ESM::RefId& refId, ESM::RecNameInts type, const EsmData& content, F&& f) { switch (type) { @@ -66,17 +66,16 @@ namespace EsmLoader EsmData::~EsmData() {} - std::string_view getModel(const EsmData& content, std::string_view refId, ESM::RecNameInts type) + std::string_view getModel(const EsmData& content, const ESM::RefId& refId, ESM::RecNameInts type) { return withStatic(refId, type, content, [](const auto& v) { return std::string_view(v.mModel); }); } - ESM::Variant getGameSetting(const std::vector& records, std::string_view id) + ESM::Variant getGameSetting(const std::vector& records, const ESM::RefId& id) { - const std::string lower = Misc::StringUtils::lowerCase(id); - auto it = std::lower_bound(records.begin(), records.end(), lower, LessById{}); - if (it == records.end() || it->mId != lower) - throw std::runtime_error("Game settings \"" + std::string(id) + "\" is not found"); + auto it = std::lower_bound(records.begin(), records.end(), id, LessById{}); + if (it == records.end() || it->mId != id) + throw std::runtime_error("Game settings \"" + id.getRefIdString() + "\" is not found"); return it->mValue; } } diff --git a/components/esmloader/esmdata.hpp b/components/esmloader/esmdata.hpp index afdcc1748d..556291d3a8 100644 --- a/components/esmloader/esmdata.hpp +++ b/components/esmloader/esmdata.hpp @@ -2,7 +2,7 @@ #define OPENMW_COMPONENTS_ESMLOADER_ESMDATA_H #include - +#include #include #include @@ -16,13 +16,14 @@ namespace ESM struct Land; struct Static; class Variant; + struct RefId; } namespace EsmLoader { struct RefIdWithType { - std::string_view mId; + ESM::RefId mId; ESM::RecNameInts mType; }; @@ -44,9 +45,9 @@ namespace EsmLoader ~EsmData(); }; - std::string_view getModel(const EsmData& content, std::string_view refId, ESM::RecNameInts type); + std::string_view getModel(const EsmData& content, const ESM::RefId& refId, ESM::RecNameInts type); - ESM::Variant getGameSetting(const std::vector& records, std::string_view id); + ESM::Variant getGameSetting(const std::vector& records, const ESM::RefId& id); } #endif diff --git a/components/esmloader/lessbyid.hpp b/components/esmloader/lessbyid.hpp index da835c9e39..4fc866264d 100644 --- a/components/esmloader/lessbyid.hpp +++ b/components/esmloader/lessbyid.hpp @@ -2,6 +2,7 @@ #define OPENMW_COMPONENTS_CONTENT_LESSBYID_H #include +#include namespace EsmLoader { @@ -14,7 +15,7 @@ namespace EsmLoader } template - bool operator()(const T& lhs, std::string_view rhs) const + bool operator()(const T& lhs, const ESM::RefId& rhs) const { return lhs.mId < rhs; } diff --git a/components/esmloader/load.cpp b/components/esmloader/load.cpp index ab5129e0f6..adb14efd02 100644 --- a/components/esmloader/load.cpp +++ b/components/esmloader/load.cpp @@ -82,8 +82,8 @@ namespace EsmLoader T record; bool deleted = false; record.load(reader, deleted); - Misc::StringUtils::lowerCaseInPlace(record.mId); - if (Misc::ResourceHelpers::isHiddenMarker(record.mId)) + Misc::StringUtils::lowerCaseInPlace(record.mId.getRefIdString()); + if (Misc::ResourceHelpers::isHiddenMarker(record.mId.getRefIdString())) return; records.emplace_back(deleted, std::move(record)); } diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index f5910e0b1b..3bffdd642d 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace Interpreter { @@ -12,7 +13,7 @@ namespace Interpreter public: virtual ~Context() {} - virtual std::string_view getTarget() const = 0; + virtual const ESM::RefId& getTarget() const = 0; virtual int getLocalShort(int index) const = 0; @@ -78,17 +79,17 @@ namespace Interpreter virtual std::string_view getCurrentCellName() const = 0; - virtual int getMemberShort(std::string_view id, std::string_view name, bool global) const = 0; + virtual int getMemberShort(ESM::RefId id, std::string_view name, bool global) const = 0; - virtual int getMemberLong(std::string_view id, std::string_view name, bool global) const = 0; + virtual int getMemberLong(ESM::RefId id, std::string_view name, bool global) const = 0; - virtual float getMemberFloat(std::string_view id, std::string_view name, bool global) const = 0; + virtual float getMemberFloat(ESM::RefId id, std::string_view name, bool global) const = 0; - virtual void setMemberShort(std::string_view id, std::string_view name, int value, bool global) = 0; + virtual void setMemberShort(ESM::RefId id, std::string_view name, int value, bool global) = 0; - virtual void setMemberLong(std::string_view id, std::string_view name, int value, bool global) = 0; + virtual void setMemberLong(ESM::RefId id, std::string_view name, int value, bool global) = 0; - virtual void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) = 0; + virtual void setMemberFloat(ESM::RefId id, std::string_view name, float value, bool global) = 0; }; } diff --git a/components/interpreter/defines.cpp b/components/interpreter/defines.cpp index 0fd0157425..5d8e0df0da 100644 --- a/components/interpreter/defines.cpp +++ b/components/interpreter/defines.cpp @@ -213,7 +213,11 @@ namespace Interpreter /* if list of globals is empty, grab it and sort it by descending string length */ if (globals.empty()) { - globals = context.getGlobals(); + auto globalIds = context.getGlobals(); + for (auto id : globalIds) + { + globals.push_back(id); + } sort(globals.begin(), globals.end(), longerStr); } diff --git a/components/interpreter/localopcodes.hpp b/components/interpreter/localopcodes.hpp index 8422858934..6319f28210 100644 --- a/components/interpreter/localopcodes.hpp +++ b/components/interpreter/localopcodes.hpp @@ -200,7 +200,7 @@ namespace Interpreter { Type_Integer data = runtime[0].mInteger; Type_Integer index = runtime[1].mInteger; - std::string_view id = runtime.getStringLiteral(index); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(index)); index = runtime[2].mInteger; std::string_view variable = runtime.getStringLiteral(index); @@ -220,7 +220,7 @@ namespace Interpreter { Type_Integer data = runtime[0].mInteger; Type_Integer index = runtime[1].mInteger; - std::string_view id = runtime.getStringLiteral(index); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(index)); index = runtime[2].mInteger; std::string_view variable = runtime.getStringLiteral(index); @@ -240,7 +240,7 @@ namespace Interpreter { Type_Float data = runtime[0].mFloat; Type_Integer index = runtime[1].mInteger; - std::string_view id = runtime.getStringLiteral(index); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(index)); index = runtime[2].mInteger; std::string_view variable = runtime.getStringLiteral(index); @@ -259,7 +259,7 @@ namespace Interpreter void execute(Runtime& runtime) override { Type_Integer index = runtime[0].mInteger; - std::string_view id = runtime.getStringLiteral(index); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(index)); index = runtime[1].mInteger; std::string_view variable = runtime.getStringLiteral(index); runtime.pop(); @@ -276,7 +276,7 @@ namespace Interpreter void execute(Runtime& runtime) override { Type_Integer index = runtime[0].mInteger; - std::string_view id = runtime.getStringLiteral(index); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(index)); index = runtime[1].mInteger; std::string_view variable = runtime.getStringLiteral(index); runtime.pop(); @@ -293,7 +293,7 @@ namespace Interpreter void execute(Runtime& runtime) override { Type_Integer index = runtime[0].mInteger; - std::string_view id = runtime.getStringLiteral(index); + ESM::RefId id = ESM::RefId::stringRefId(runtime.getStringLiteral(index)); index = runtime[1].mInteger; std::string_view variable = runtime.getStringLiteral(index); runtime.pop(); diff --git a/components/lua/configuration.cpp b/components/lua/configuration.cpp index 6826cc3197..85c0cb6724 100644 --- a/components/lua/configuration.cpp +++ b/components/lua/configuration.cpp @@ -134,7 +134,7 @@ namespace LuaUtil } ScriptIdsWithInitializationData ScriptsConfiguration::getLocalConf( - uint32_t type, std::string_view recordId, ESM::RefNum refnum) const + uint32_t type, const ESM::RefId& recordId, ESM::RefNum refnum) const { ScriptIdsWithInitializationData res; auto typeIt = mScriptsPerType.find(type); diff --git a/components/lua/configuration.hpp b/components/lua/configuration.hpp index ba9778f4bb..3a2df8e43d 100644 --- a/components/lua/configuration.hpp +++ b/components/lua/configuration.hpp @@ -25,7 +25,7 @@ namespace LuaUtil ScriptIdsWithInitializationData getGlobalConf() const { return getConfByFlag(ESM::LuaScriptCfg::sGlobal); } ScriptIdsWithInitializationData getPlayerConf() const { return getConfByFlag(ESM::LuaScriptCfg::sPlayer); } ScriptIdsWithInitializationData getLocalConf( - uint32_t type, std::string_view recordId, ESM::RefNum refnum) const; + uint32_t type, const ESM::RefId& recordId, ESM::RefNum refnum) const; private: ScriptIdsWithInitializationData getConfByFlag(ESM::LuaScriptCfg::Flags flag) const; @@ -40,7 +40,7 @@ namespace LuaUtil std::string_view mInitializationData; }; std::map> mScriptsPerType; - std::map, std::less<>> mScriptsPerRecordId; + std::map, std::less<>> mScriptsPerRecordId; std::map> mScriptsPerRefNum; }; diff --git a/components/resource/foreachbulletobject.cpp b/components/resource/foreachbulletobject.cpp index d96f3ee078..dbad2aea62 100644 --- a/components/resource/foreachbulletobject.cpp +++ b/components/resource/foreachbulletobject.cpp @@ -31,12 +31,12 @@ namespace Resource { ESM::RecNameInts mType; ESM::RefNum mRefNum; - std::string mRefId; + ESM::RefId mRefId; float mScale; ESM::Position mPos; CellRef( - ESM::RecNameInts type, ESM::RefNum refNum, std::string&& refId, float scale, const ESM::Position& pos) + ESM::RecNameInts type, ESM::RefNum refNum, ESM::RefId&& refId, float scale, const ESM::Position& pos) : mType(type) , mRefNum(refNum) , mRefId(std::move(refId)) @@ -46,7 +46,7 @@ namespace Resource } }; - ESM::RecNameInts getType(const EsmLoader::EsmData& esmData, std::string_view refId) + ESM::RecNameInts getType(const EsmLoader::EsmData& esmData, const ESM::RefId& refId) { const auto it = std::lower_bound( esmData.mRefIdTypes.begin(), esmData.mRefIdTypes.end(), refId, EsmLoader::LessById{}); @@ -69,7 +69,6 @@ namespace Resource bool deleted = false; while (ESM::Cell::getNextRef(*reader, cellRef, deleted)) { - Misc::StringUtils::lowerCaseInPlace(cellRef.mRefID); const ESM::RecNameInts type = getType(esmData, cellRef.mRefID); if (type == ESM::RecNameInts{}) continue;