Allow string_view lookups in MWWorld::Store and get some use out of that

post_malone
Evil Eye 3 years ago
parent bb9884c024
commit de51525c76

@ -137,7 +137,7 @@ namespace MWBase
virtual MWWorld::CellStore *getExterior (int x, int y) = 0; virtual MWWorld::CellStore *getExterior (int x, int y) = 0;
virtual MWWorld::CellStore *getInterior (const std::string& name) = 0; virtual MWWorld::CellStore* getInterior(std::string_view name) = 0;
virtual MWWorld::CellStore *getCell (const ESM::CellId& id) = 0; virtual MWWorld::CellStore *getCell (const ESM::CellId& id) = 0;
@ -236,7 +236,7 @@ namespace MWBase
virtual bool toggleSky() = 0; virtual bool toggleSky() = 0;
///< \return Resulting mode ///< \return Resulting mode
virtual void changeWeather(const std::string& region, const unsigned int id) = 0; virtual void changeWeather(std::string_view region, const unsigned int id) = 0;
virtual int getCurrentWeather() const = 0; virtual int getCurrentWeather() const = 0;
@ -252,7 +252,7 @@ namespace MWBase
virtual void setMoonColour (bool red) = 0; virtual void setMoonColour (bool red) = 0;
virtual void modRegion(const std::string &regionid, const std::vector<char> &chances) = 0; virtual void modRegion(std::string_view regionid, const std::vector<char> &chances) = 0;
virtual float getTimeScaleFactor() const = 0; virtual float getTimeScaleFactor() const = 0;
@ -271,7 +271,7 @@ namespace MWBase
virtual void changeToCell (const ESM::CellId& cellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true) = 0; virtual void changeToCell (const ESM::CellId& cellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true) = 0;
///< @param changeEvent If false, do not trigger cell change flag or detect worldspace changes ///< @param changeEvent If false, do not trigger cell change flag or detect worldspace changes
virtual const ESM::Cell *getExterior (const std::string& cellName) const = 0; virtual const ESM::Cell* getExterior(std::string_view cellName) const = 0;
///< Return a cell matching the given name or a 0-pointer, if there is no such cell. ///< Return a cell matching the given name or a 0-pointer, if there is no such cell.
virtual void markCellAsUnchanged() = 0; virtual void markCellAsUnchanged() = 0;
@ -518,7 +518,7 @@ namespace MWBase
/// Find default position inside interior cell specified by name /// Find default position inside interior cell specified by name
/// \return false if interior with given name not exists, true otherwise /// \return false if interior with given name not exists, true otherwise
virtual bool findInteriorPosition(const std::string &name, ESM::Position &pos) = 0; virtual bool findInteriorPosition(std::string_view name, ESM::Position &pos) = 0;
/// Enables or disables use of teleport spell effects (recall, intervention, etc). /// Enables or disables use of teleport spell effects (recall, intervention, etc).
virtual void enableTeleporting(bool enable) = 0; virtual void enableTeleporting(bool enable) = 0;
@ -591,7 +591,7 @@ namespace MWBase
virtual void goToJail () = 0; virtual void goToJail () = 0;
/// Spawn a random creature from a levelled list next to the player /// Spawn a random creature from a levelled list next to the player
virtual void spawnRandomCreature(const std::string& creatureList) = 0; virtual void spawnRandomCreature(std::string_view creatureList) = 0;
/// Spawn a blood effect for \a ptr at \a worldPosition /// Spawn a blood effect for \a ptr at \a worldPosition
virtual void spawnBloodEffect (const MWWorld::Ptr& ptr, const osg::Vec3f& worldPosition) = 0; virtual void spawnBloodEffect (const MWWorld::Ptr& ptr, const osg::Vec3f& worldPosition) = 0;

@ -1433,7 +1433,7 @@ namespace MWClass
return true; return true;
} }
std::string Npc::getPrimaryFaction (const MWWorld::ConstPtr& ptr) const std::string_view Npc::getPrimaryFaction(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>(); const MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
return ref->mBase->mFaction; return ref->mBase->mFaction;
@ -1441,7 +1441,7 @@ namespace MWClass
int Npc::getPrimaryFactionRank (const MWWorld::ConstPtr& ptr) const int Npc::getPrimaryFactionRank (const MWWorld::ConstPtr& ptr) const
{ {
std::string factionID = ptr.getClass().getPrimaryFaction(ptr); std::string_view factionID = ptr.getClass().getPrimaryFaction(ptr);
if(factionID.empty()) if(factionID.empty())
return -1; return -1;

@ -159,7 +159,7 @@ namespace MWClass
int getBaseFightRating (const MWWorld::ConstPtr& ptr) const override; int getBaseFightRating (const MWWorld::ConstPtr& ptr) const override;
std::string getPrimaryFaction(const MWWorld::ConstPtr &ptr) const override; std::string_view getPrimaryFaction(const MWWorld::ConstPtr &ptr) const override;
int getPrimaryFactionRank(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 std::string& id, MWMechanics::AiSetting setting, int value) const override;

@ -359,7 +359,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con
case SelectWrapper::Function_RankRequirement: case SelectWrapper::Function_RankRequirement:
{ {
std::string faction = mActor.getClass().getPrimaryFaction(mActor); std::string_view faction = mActor.getClass().getPrimaryFaction(mActor);
if (faction.empty()) if (faction.empty())
return 0; return 0;
@ -397,7 +397,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con
case SelectWrapper::Function_FactionRankDiff: case SelectWrapper::Function_FactionRankDiff:
{ {
std::string faction = mActor.getClass().getPrimaryFaction(mActor); std::string_view faction = mActor.getClass().getPrimaryFaction(mActor);
if (faction.empty()) if (faction.empty())
return 0; return 0;
@ -416,7 +416,7 @@ int MWDialogue::Filter::getSelectStructInteger (const SelectWrapper& select) con
{ {
bool low = select.getFunction()==SelectWrapper::Function_RankLow; bool low = select.getFunction()==SelectWrapper::Function_RankLow;
std::string factionId = mActor.getClass().getPrimaryFaction(mActor); std::string_view factionId = mActor.getClass().getPrimaryFaction(mActor);
if (factionId.empty()) if (factionId.empty())
return 0; return 0;
@ -517,7 +517,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co
case SelectWrapper::Function_PcExpelled: case SelectWrapper::Function_PcExpelled:
{ {
std::string faction = mActor.getClass().getPrimaryFaction(mActor); std::string_view faction = mActor.getClass().getPrimaryFaction(mActor);
if (faction.empty()) if (faction.empty())
return false; return false;
@ -561,20 +561,13 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co
} }
} }
int MWDialogue::Filter::getFactionRank (const MWWorld::Ptr& actor, const std::string& factionId) const int MWDialogue::Filter::getFactionRank (const MWWorld::Ptr& actor, std::string_view factionId) const
{ {
MWMechanics::NpcStats& stats = actor.getClass().getNpcStats (actor); MWMechanics::NpcStats& stats = actor.getClass().getNpcStats (actor);
return stats.getFactionRank(factionId);
std::map<std::string, int>::const_iterator iter = stats.getFactionRanks().find (Misc::StringUtils::lowerCase(factionId));
if (iter==stats.getFactionRanks().end())
return -1;
return iter->second;
} }
bool MWDialogue::Filter::hasFactionRankSkillRequirements (const MWWorld::Ptr& actor, bool MWDialogue::Filter::hasFactionRankSkillRequirements(const MWWorld::Ptr& actor, std::string_view factionId, int rank) const
const std::string& factionId, int rank) const
{ {
if (rank<0 || rank>=10) if (rank<0 || rank>=10)
throw std::runtime_error ("rank index out of range"); throw std::runtime_error ("rank index out of range");
@ -591,8 +584,7 @@ bool MWDialogue::Filter::hasFactionRankSkillRequirements (const MWWorld::Ptr& ac
stats.getAttribute (faction.mData.mAttribute[1]).getBase()>=faction.mData.mRankData[rank].mAttribute2; stats.getAttribute (faction.mData.mAttribute[1]).getBase()>=faction.mData.mRankData[rank].mAttribute2;
} }
bool MWDialogue::Filter::hasFactionRankReputationRequirements (const MWWorld::Ptr& actor, bool MWDialogue::Filter::hasFactionRankReputationRequirements(const MWWorld::Ptr& actor, std::string_view factionId, int rank) const
const std::string& factionId, int rank) const
{ {
if (rank<0 || rank>=10) if (rank<0 || rank>=10)
throw std::runtime_error ("rank index out of range"); throw std::runtime_error ("rank index out of range");

@ -43,13 +43,11 @@ namespace MWDialogue
bool getSelectStructBoolean (const SelectWrapper& select) const; bool getSelectStructBoolean (const SelectWrapper& select) const;
int getFactionRank (const MWWorld::Ptr& actor, const std::string& factionId) const; int getFactionRank(const MWWorld::Ptr& actor, std::string_view factionId) const;
bool hasFactionRankSkillRequirements (const MWWorld::Ptr& actor, const std::string& factionId, bool hasFactionRankSkillRequirements(const MWWorld::Ptr& actor, std::string_view factionId, int rank) const;
int rank) const;
bool hasFactionRankReputationRequirements (const MWWorld::Ptr& actor, const std::string& factionId, bool hasFactionRankReputationRequirements(const MWWorld::Ptr& actor, std::string_view factionId, int rank) const;
int rank) const;
public: public:

@ -16,7 +16,7 @@
namespace MWDialogue namespace MWDialogue
{ {
Entry::Entry (const std::string& topic, const std::string& infoId, const MWWorld::Ptr& actor) Entry::Entry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor)
: mInfoId (infoId) : mInfoId (infoId)
{ {
const ESM::Dialogue *dialogue = const ESM::Dialogue *dialogue =
@ -40,7 +40,7 @@ namespace MWDialogue
return; return;
} }
throw std::runtime_error ("unknown info ID " + mInfoId + " for topic " + topic); throw std::runtime_error ("unknown info ID " + mInfoId + " for topic " + std::string(topic));
} }
Entry::Entry (const ESM::JournalEntry& record) : mInfoId (record.mInfo), mText (record.mText), mActorName(record.mActorName) {} Entry::Entry (const ESM::JournalEntry& record) : mInfoId (record.mInfo), mText (record.mText), mActorName(record.mActorName) {}
@ -58,7 +58,7 @@ namespace MWDialogue
} }
JournalEntry::JournalEntry (const std::string& topic, const std::string& infoId, const MWWorld::Ptr& actor) JournalEntry::JournalEntry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor)
: Entry (topic, infoId, actor), mTopic (topic) : Entry (topic, infoId, actor), mTopic (topic)
{} {}
@ -72,12 +72,12 @@ namespace MWDialogue
entry.mTopic = mTopic; entry.mTopic = mTopic;
} }
JournalEntry JournalEntry::makeFromQuest (const std::string& topic, int index) JournalEntry JournalEntry::makeFromQuest(std::string_view topic, int index)
{ {
return JournalEntry (topic, idFromIndex (topic, index), MWWorld::Ptr()); return JournalEntry (topic, idFromIndex (topic, index), MWWorld::Ptr());
} }
std::string JournalEntry::idFromIndex (const std::string& topic, int index) std::string_view JournalEntry::idFromIndex (std::string_view topic, int index)
{ {
const ESM::Dialogue *dialogue = const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (topic); MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (topic);
@ -89,7 +89,7 @@ namespace MWDialogue
return iter->mId; return iter->mId;
} }
throw std::runtime_error ("unknown journal index for topic " + topic); throw std::runtime_error ("unknown journal index for topic " + std::string(topic));
} }
@ -97,7 +97,7 @@ namespace MWDialogue
: mDay (0), mMonth (0), mDayOfMonth (0) : mDay (0), mMonth (0), mDayOfMonth (0)
{} {}
StampedJournalEntry::StampedJournalEntry (const std::string& topic, const std::string& infoId, StampedJournalEntry::StampedJournalEntry(std::string_view topic, std::string_view infoId,
int day, int month, int dayOfMonth, const MWWorld::Ptr& actor) int day, int month, int dayOfMonth, const MWWorld::Ptr& actor)
: JournalEntry (topic, infoId, actor), mDay (day), mMonth (month), mDayOfMonth (dayOfMonth) : JournalEntry (topic, infoId, actor), mDay (day), mMonth (month), mDayOfMonth (dayOfMonth)
{} {}
@ -115,7 +115,7 @@ namespace MWDialogue
entry.mDayOfMonth = mDayOfMonth; entry.mDayOfMonth = mDayOfMonth;
} }
StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index, const MWWorld::Ptr& actor) StampedJournalEntry StampedJournalEntry::makeFromQuest(std::string_view topic, int index, const MWWorld::Ptr& actor)
{ {
int day = MWBase::Environment::get().getWorld()->getGlobalInt ("dayspassed"); int day = MWBase::Environment::get().getWorld()->getGlobalInt ("dayspassed");
int month = MWBase::Environment::get().getWorld()->getGlobalInt ("month"); int month = MWBase::Environment::get().getWorld()->getGlobalInt ("month");

@ -2,6 +2,7 @@
#define GAME_MWDIALOGUE_JOURNALENTRY_H #define GAME_MWDIALOGUE_JOURNALENTRY_H
#include <string> #include <string>
#include <string_view>
namespace ESM namespace ESM
{ {
@ -25,7 +26,7 @@ namespace MWDialogue
Entry() = default; Entry() = default;
/// actor is optional /// actor is optional
Entry (const std::string& topic, const std::string& infoId, const MWWorld::Ptr& actor); Entry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor);
Entry (const ESM::JournalEntry& record); Entry (const ESM::JournalEntry& record);
@ -43,15 +44,15 @@ namespace MWDialogue
JournalEntry() = default; JournalEntry() = default;
JournalEntry (const std::string& topic, const std::string& infoId, const MWWorld::Ptr& actor); JournalEntry(std::string_view topic, std::string_view infoId, const MWWorld::Ptr& actor);
JournalEntry (const ESM::JournalEntry& record); JournalEntry (const ESM::JournalEntry& record);
void write (ESM::JournalEntry& entry) const; void write (ESM::JournalEntry& entry) const;
static JournalEntry makeFromQuest (const std::string& topic, int index); static JournalEntry makeFromQuest(std::string_view topic, int index);
static std::string idFromIndex (const std::string& topic, int index); static std::string_view idFromIndex(std::string_view topic, int index);
}; };
/// \brief A quest entry with a timestamp. /// \brief A quest entry with a timestamp.
@ -63,14 +64,14 @@ namespace MWDialogue
StampedJournalEntry(); StampedJournalEntry();
StampedJournalEntry (const std::string& topic, const std::string& infoId, StampedJournalEntry(std::string_view topic, std::string_view infoId,
int day, int month, int dayOfMonth, const MWWorld::Ptr& actor); int day, int month, int dayOfMonth, const MWWorld::Ptr& actor);
StampedJournalEntry (const ESM::JournalEntry& record); StampedJournalEntry (const ESM::JournalEntry& record);
void write (ESM::JournalEntry& entry) const; void write (ESM::JournalEntry& entry) const;
static StampedJournalEntry makeFromQuest (const std::string& topic, int index, const MWWorld::Ptr& actor); static StampedJournalEntry makeFromQuest(std::string_view topic, int index, const MWWorld::Ptr& actor);
}; };
} }

@ -80,7 +80,7 @@ namespace MWDialogue
void Journal::addEntry (const std::string& id, int index, const MWWorld::Ptr& actor) void Journal::addEntry (const std::string& id, int index, const MWWorld::Ptr& actor)
{ {
// bail out if we already have heard this... // bail out if we already have heard this...
std::string infoId = JournalEntry::idFromIndex (id, index); std::string_view infoId = JournalEntry::idFromIndex(id, index);
for (TEntryIter i = mJournal.begin (); i != mJournal.end (); ++i) for (TEntryIter i = mJournal.begin (); i != mJournal.end (); ++i)
if (i->mTopic == id && i->mInfoId == infoId) if (i->mTopic == id && i->mInfoId == infoId)
{ {

@ -518,9 +518,7 @@ namespace MWMechanics
float reaction = 0; float reaction = 0;
int rank = 0; int rank = 0;
std::string npcFaction = ptr.getClass().getPrimaryFaction(ptr); std::string npcFaction = Misc::StringUtils::lowerCase(ptr.getClass().getPrimaryFaction(ptr));
Misc::StringUtils::lowerCaseInPlace(npcFaction);
if (playerStats.getFactionRanks().find(npcFaction) != playerStats.getFactionRanks().end()) if (playerStats.getFactionRanks().find(npcFaction) != playerStats.getFactionRanks().end())
{ {
@ -985,7 +983,7 @@ namespace MWMechanics
if (ownerFound != owners.end()) if (ownerFound != owners.end())
return true; return true;
const std::string factionid = ptr.getClass().getPrimaryFaction(ptr); const std::string_view factionid = ptr.getClass().getPrimaryFaction(ptr);
if (!factionid.empty()) if (!factionid.empty())
{ {
OwnerMap::const_iterator factionOwnerFound = owners.find(std::make_pair(Misc::StringUtils::lowerCase(factionid), true)); OwnerMap::const_iterator factionOwnerFound = owners.find(std::make_pair(Misc::StringUtils::lowerCase(factionid), true));
@ -1010,7 +1008,7 @@ namespace MWMechanics
owner.first = victim.getCellRef().getRefId(); owner.first = victim.getCellRef().getRefId();
owner.second = false; owner.second = false;
const std::string victimFaction = victim.getClass().getPrimaryFaction(victim); const std::string_view victimFaction = victim.getClass().getPrimaryFaction(victim);
if (!victimFaction.empty() && Misc::StringUtils::ciEqual(item.getCellRef().getFaction(), victimFaction)) // Is the item faction-owned? if (!victimFaction.empty() && Misc::StringUtils::ciEqual(item.getCellRef().getFaction(), victimFaction)) // Is the item faction-owned?
{ {
owner.first = victimFaction; owner.first = victimFaction;
@ -1375,7 +1373,7 @@ namespace MWMechanics
// If committing a crime against a faction member, expell from the faction // If committing a crime against a faction member, expell from the faction
if (!victim.isEmpty() && victim.getClass().isNpc()) if (!victim.isEmpty() && victim.getClass().isNpc())
{ {
std::string factionID = victim.getClass().getPrimaryFaction(victim); std::string_view factionID = victim.getClass().getPrimaryFaction(victim);
const std::map<std::string, int>& playerRanks = player.getClass().getNpcStats(player).getFactionRanks(); const std::map<std::string, int>& playerRanks = player.getClass().getNpcStats(player).getFactionRanks();
if (playerRanks.find(Misc::StringUtils::lowerCase(factionID)) != playerRanks.end()) if (playerRanks.find(Misc::StringUtils::lowerCase(factionID)) != playerRanks.end())

@ -69,7 +69,7 @@ const std::map<std::string, int>& MWMechanics::NpcStats::getFactionRanks() const
return mFactionRank; return mFactionRank;
} }
int MWMechanics::NpcStats::getFactionRank(const std::string &faction) const int MWMechanics::NpcStats::getFactionRank(std::string_view faction) const
{ {
const std::string lower = Misc::StringUtils::lowerCase(faction); const std::string lower = Misc::StringUtils::lowerCase(faction);
std::map<std::string, int>::const_iterator it = mFactionRank.find(lower); std::map<std::string, int>::const_iterator it = mFactionRank.find(lower);
@ -79,7 +79,7 @@ int MWMechanics::NpcStats::getFactionRank(const std::string &faction) const
return -1; return -1;
} }
void MWMechanics::NpcStats::raiseRank(const std::string &faction) void MWMechanics::NpcStats::raiseRank(std::string_view faction)
{ {
const std::string lower = Misc::StringUtils::lowerCase(faction); const std::string lower = Misc::StringUtils::lowerCase(faction);
std::map<std::string, int>::iterator it = mFactionRank.find(lower); std::map<std::string, int>::iterator it = mFactionRank.find(lower);
@ -92,7 +92,7 @@ void MWMechanics::NpcStats::raiseRank(const std::string &faction)
} }
} }
void MWMechanics::NpcStats::lowerRank(const std::string &faction) void MWMechanics::NpcStats::lowerRank(std::string_view faction)
{ {
const std::string lower = Misc::StringUtils::lowerCase(faction); const std::string lower = Misc::StringUtils::lowerCase(faction);
std::map<std::string, int>::iterator it = mFactionRank.find(lower); std::map<std::string, int>::iterator it = mFactionRank.find(lower);
@ -107,7 +107,7 @@ void MWMechanics::NpcStats::lowerRank(const std::string &faction)
} }
} }
void MWMechanics::NpcStats::joinFaction(const std::string& faction) void MWMechanics::NpcStats::joinFaction(std::string_view faction)
{ {
const std::string lower = Misc::StringUtils::lowerCase(faction); const std::string lower = Misc::StringUtils::lowerCase(faction);
std::map<std::string, int>::iterator it = mFactionRank.find(lower); std::map<std::string, int>::iterator it = mFactionRank.find(lower);
@ -115,12 +115,12 @@ void MWMechanics::NpcStats::joinFaction(const std::string& faction)
mFactionRank[lower] = 0; mFactionRank[lower] = 0;
} }
bool MWMechanics::NpcStats::getExpelled(const std::string& factionID) const bool MWMechanics::NpcStats::getExpelled(std::string_view factionID) const
{ {
return mExpelled.find(Misc::StringUtils::lowerCase(factionID)) != mExpelled.end(); return mExpelled.find(Misc::StringUtils::lowerCase(factionID)) != mExpelled.end();
} }
void MWMechanics::NpcStats::expell(const std::string& factionID) void MWMechanics::NpcStats::expell(std::string_view factionID)
{ {
std::string lower = Misc::StringUtils::lowerCase(factionID); std::string lower = Misc::StringUtils::lowerCase(factionID);
if (mExpelled.find(lower) == mExpelled.end()) if (mExpelled.find(lower) == mExpelled.end())
@ -132,17 +132,17 @@ void MWMechanics::NpcStats::expell(const std::string& factionID)
} }
} }
void MWMechanics::NpcStats::clearExpelled(const std::string& factionID) void MWMechanics::NpcStats::clearExpelled(std::string_view factionID)
{ {
mExpelled.erase(Misc::StringUtils::lowerCase(factionID)); mExpelled.erase(Misc::StringUtils::lowerCase(factionID));
} }
bool MWMechanics::NpcStats::isInFaction (const std::string& faction) const bool MWMechanics::NpcStats::isInFaction(std::string_view faction) const
{ {
return (mFactionRank.find(Misc::StringUtils::lowerCase(faction)) != mFactionRank.end()); return (mFactionRank.find(Misc::StringUtils::lowerCase(faction)) != mFactionRank.end());
} }
int MWMechanics::NpcStats::getFactionReputation (const std::string& faction) const int MWMechanics::NpcStats::getFactionReputation(std::string_view faction) const
{ {
std::map<std::string, int>::const_iterator iter = mFactionReputation.find (Misc::StringUtils::lowerCase(faction)); std::map<std::string, int>::const_iterator iter = mFactionReputation.find (Misc::StringUtils::lowerCase(faction));
@ -152,7 +152,7 @@ int MWMechanics::NpcStats::getFactionReputation (const std::string& faction) con
return iter->second; return iter->second;
} }
void MWMechanics::NpcStats::setFactionReputation (const std::string& faction, int value) void MWMechanics::NpcStats::setFactionReputation(std::string_view faction, int value)
{ {
mFactionReputation[Misc::StringUtils::lowerCase(faction)] = value; mFactionReputation[Misc::StringUtils::lowerCase(faction)] = value;
} }
@ -387,7 +387,7 @@ void MWMechanics::NpcStats::setCrimeId(int id)
mCrimeId = id; mCrimeId = id;
} }
bool MWMechanics::NpcStats::hasSkillsForRank (const std::string& factionId, int rank) const bool MWMechanics::NpcStats::hasSkillsForRank(std::string_view factionId, int rank) const
{ {
if (rank<0 || rank>=10) if (rank<0 || rank>=10)
throw std::runtime_error ("rank index out of range"); throw std::runtime_error ("rank index out of range");

@ -61,22 +61,22 @@ namespace MWMechanics
SkillValue& getSkill (int index); SkillValue& getSkill (int index);
void setSkill(int index, const SkillValue& value); void setSkill(int index, const SkillValue& value);
int getFactionRank(const std::string &faction) const; int getFactionRank(std::string_view faction) const;
const std::map<std::string, int>& getFactionRanks() const; const std::map<std::string, int>& getFactionRanks() const;
/// Increase the rank in this faction by 1, if such a rank exists. /// Increase the rank in this faction by 1, if such a rank exists.
void raiseRank(const std::string& faction); void raiseRank(std::string_view faction);
/// Lower the rank in this faction by 1, if such a rank exists. /// Lower the rank in this faction by 1, if such a rank exists.
void lowerRank(const std::string& faction); void lowerRank(std::string_view faction);
/// Join this faction, setting the initial rank to 0. /// Join this faction, setting the initial rank to 0.
void joinFaction(const std::string& faction); void joinFaction(std::string_view faction);
const std::set<std::string>& getExpelled() const { return mExpelled; } const std::set<std::string>& getExpelled() const { return mExpelled; }
bool getExpelled(const std::string& factionID) const; bool getExpelled(std::string_view factionID) const;
void expell(const std::string& factionID); void expell(std::string_view factionID);
void clearExpelled(const std::string& factionID); void clearExpelled(std::string_view factionID);
bool isInFaction (const std::string& faction) const; bool isInFaction(std::string_view faction) const;
float getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const; float getSkillProgressRequirement (int skillIndex, const ESM::Class& class_) const;
@ -107,11 +107,11 @@ namespace MWMechanics
void setBounty (int bounty); void setBounty (int bounty);
int getFactionReputation (const std::string& faction) const; int getFactionReputation(std::string_view faction) const;
void setFactionReputation (const std::string& faction, int value); void setFactionReputation(std::string_view faction, int value);
bool hasSkillsForRank (const std::string& factionId, int rank) const; bool hasSkillsForRank(std::string_view factionId, int rank) const;
bool isWerewolf() const; bool isWerewolf() const;

@ -14,13 +14,13 @@
namespace namespace
{ {
template<class T> template<class T>
const std::vector<std::string> getSpellList(const std::string& id) const std::vector<std::string> getSpellList(std::string_view id)
{ {
return MWBase::Environment::get().getWorld()->getStore().get<T>().find(id)->mSpells.mList; return MWBase::Environment::get().getWorld()->getStore().get<T>().find(id)->mSpells.mList;
} }
template<class T> template<class T>
bool withBaseRecord(const std::string& id, const std::function<bool(std::vector<std::string>&)>& function) bool withBaseRecord(std::string_view id, const std::function<bool(std::vector<std::string>&)>& function)
{ {
T copy = *MWBase::Environment::get().getWorld()->getStore().get<T>().find(id); T copy = *MWBase::Environment::get().getWorld()->getStore().get<T>().find(id);
bool changed = function(copy.mSpells.mList); bool changed = function(copy.mSpells.mList);
@ -60,7 +60,7 @@ namespace MWMechanics
} }
} }
const ESM::Spell* SpellList::getSpell(const std::string& id) const ESM::Spell* SpellList::getSpell(std::string_view id)
{ {
return MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(id); return MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(id);
} }

@ -37,7 +37,7 @@ namespace MWMechanics
SpellList(const std::string& id, int type); SpellList(const std::string& id, int type);
/// Get spell from ID, throws exception if not found /// Get spell from ID, throws exception if not found
static const ESM::Spell* getSpell(const std::string& id); static const ESM::Spell* getSpell(std::string_view id);
void add (const ESM::Spell* spell); void add (const ESM::Spell* spell);
///< Adding a spell that is already listed in *this is a no-op. ///< Adding a spell that is already listed in *this is a no-op.

@ -46,7 +46,7 @@ namespace MWMechanics
return mSpells.end(); return mSpells.end();
} }
bool Spells::hasSpell(const std::string &spell) const bool Spells::hasSpell(std::string_view spell) const
{ {
return hasSpell(SpellList::getSpell(spell)); return hasSpell(SpellList::getSpell(spell));
} }
@ -61,7 +61,7 @@ namespace MWMechanics
mSpellList->add(spell); mSpellList->add(spell);
} }
void Spells::add (const std::string& spellId) void Spells::add(std::string_view spellId)
{ {
add(SpellList::getSpell(spellId)); add(SpellList::getSpell(spellId));
} }
@ -72,7 +72,7 @@ namespace MWMechanics
mSpells.emplace_back(spell); mSpells.emplace_back(spell);
} }
void Spells::remove (const std::string& spellId) void Spells::remove(std::string_view spellId)
{ {
const auto spell = SpellList::getSpell(spellId); const auto spell = SpellList::getSpell(spellId);
removeSpell(spell); removeSpell(spell);

@ -69,16 +69,16 @@ namespace MWMechanics
std::vector<const ESM::Spell*>::const_iterator end() const; std::vector<const ESM::Spell*>::const_iterator end() const;
bool hasSpell(const std::string& spell) const; bool hasSpell(std::string_view spell) const;
bool hasSpell(const ESM::Spell* spell) const; bool hasSpell(const ESM::Spell* spell) const;
void add (const std::string& spell); void add(std::string_view spell);
///< Adding a spell that is already listed in *this is a no-op. ///< Adding a spell that is already listed in *this is a no-op.
void add (const ESM::Spell* spell); void add (const ESM::Spell* spell);
///< Adding a spell that is already listed in *this is a no-op. ///< Adding a spell that is already listed in *this is a no-op.
void remove (const std::string& spell); void remove(std::string_view spell);
///< If the spell to be removed is the selected spell, the selected spell will be changed to ///< If the spell to be removed is the selected spell, the selected spell will be changed to
/// no spell (empty string). /// no spell (empty string).

@ -168,7 +168,7 @@ namespace MWScript
if (cellID.empty()) if (cellID.empty())
return; return;
if (!MWBase::Environment::get().getWorld()->getStore().get<ESM::Cell>().search(std::string{cellID})) if (!MWBase::Environment::get().getWorld()->getStore().get<ESM::Cell>().search(cellID))
return; return;
MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast<int>(duration), x, y, z, repeat); MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast<int>(duration), x, y, z, repeat);

@ -310,7 +310,7 @@ namespace MWScript
std::string InterpreterContext::getNPCRank() const std::string InterpreterContext::getNPCRank() const
{ {
const MWWorld::Ptr& ptr = getReferenceImp(); const MWWorld::Ptr& ptr = getReferenceImp();
std::string faction = ptr.getClass().getPrimaryFaction(ptr); std::string_view faction = ptr.getClass().getPrimaryFaction(ptr);
if (faction.empty()) if (faction.empty())
throw std::runtime_error("getNPCRank(): NPC is not in a faction"); throw std::runtime_error("getNPCRank(): NPC is not in a faction");
@ -350,7 +350,7 @@ namespace MWScript
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
std::string factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); std::string_view factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp());
if (factionId.empty()) if (factionId.empty())
throw std::runtime_error("getPCRank(): NPC is not in a faction"); throw std::runtime_error("getPCRank(): NPC is not in a faction");
@ -379,7 +379,7 @@ namespace MWScript
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
std::string factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp()); std::string_view factionId = getReferenceImp().getClass().getPrimaryFaction(getReferenceImp());
if (factionId.empty()) if (factionId.empty())
throw std::runtime_error("getPCNextRank(): NPC is not in a faction"); throw std::runtime_error("getPCNextRank(): NPC is not in a faction");

@ -1215,7 +1215,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string spellId{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string targetId = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral(runtime[0].mInteger)); std::string targetId = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral(runtime[0].mInteger));
@ -1224,7 +1224,7 @@ namespace MWScript
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellId); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellId);
if (!spell) if (!spell)
{ {
runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\""); runtime.getContext().report("spellcasting failed: cannot find spell \""+std::string(spellId)+"\"");
return; return;
} }
@ -1264,13 +1264,13 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string spellId{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellId); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellId);
if (!spell) if (!spell)
{ {
runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\""); runtime.getContext().report("spellcasting failed: cannot find spell \""+std::string(spellId)+"\"");
return; return;
} }
@ -1427,7 +1427,7 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -1445,7 +1445,7 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -1463,7 +1463,7 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -1481,7 +1481,7 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();

@ -87,7 +87,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
std::string region{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view region{runtime.getStringLiteral(runtime[0].mInteger)};
runtime.pop(); runtime.pop();
Interpreter::Type_Integer id = runtime[0].mInteger; Interpreter::Type_Integer id = runtime[0].mInteger;
@ -97,7 +97,7 @@ namespace MWScript
if (reg) if (reg)
MWBase::Environment::get().getWorld()->changeWeather(region, id); MWBase::Environment::get().getWorld()->changeWeather(region, id);
else else
runtime.getContext().report("Warning: Region \"" + region + "\" was not found"); runtime.getContext().report("Warning: Region \"" + std::string(region) + "\" was not found");
} }
}; };
@ -107,7 +107,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime, unsigned int arg0) override void execute (Interpreter::Runtime& runtime, unsigned int arg0) override
{ {
std::string region{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view region{runtime.getStringLiteral(runtime[0].mInteger)};
runtime.pop(); runtime.pop();
std::vector<char> chances; std::vector<char> chances;

@ -31,9 +31,9 @@
namespace namespace
{ {
std::string getDialogueActorFaction(const MWWorld::ConstPtr& actor) std::string_view getDialogueActorFaction(const MWWorld::ConstPtr& actor)
{ {
std::string factionId = actor.getClass().getPrimaryFaction(actor); std::string_view factionId = actor.getClass().getPrimaryFaction(actor);
if (factionId.empty()) if (factionId.empty())
throw std::runtime_error ( throw std::runtime_error (
"failed to determine dialogue actors faction (because actor is factionless)"); "failed to determine dialogue actors faction (because actor is factionless)");
@ -453,7 +453,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (id); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (id);
@ -480,7 +480,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr);
@ -538,7 +538,7 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer value = 0; Interpreter::Type_Integer value = 0;
@ -559,7 +559,7 @@ namespace MWScript
{ {
MWWorld::ConstPtr actor = R()(runtime, false); MWWorld::ConstPtr actor = R()(runtime, false);
std::string factionID; std::string_view factionID;
if(arg0==0) if(arg0==0)
{ {
@ -570,11 +570,10 @@ namespace MWScript
factionID = runtime.getStringLiteral (runtime[0].mInteger); factionID = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
} }
::Misc::StringUtils::lowerCaseInPlace(factionID);
// Make sure this faction exists // Make sure this faction exists
MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID); MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID);
if(factionID != "") if(!factionID.empty())
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).joinFaction(factionID); player.getClass().getNpcStats(player).joinFaction(factionID);
@ -591,7 +590,7 @@ namespace MWScript
{ {
MWWorld::ConstPtr actor = R()(runtime, false); MWWorld::ConstPtr actor = R()(runtime, false);
std::string factionID; std::string_view factionID;
if(arg0==0) if(arg0==0)
{ {
@ -602,14 +601,13 @@ namespace MWScript
factionID = runtime.getStringLiteral (runtime[0].mInteger); factionID = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
} }
::Misc::StringUtils::lowerCaseInPlace(factionID);
// Make sure this faction exists // Make sure this faction exists
MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID); MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID);
if(factionID != "") if(!factionID.empty())
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) == player.getClass().getNpcStats(player).getFactionRanks().end()) if(!player.getClass().getNpcStats(player).isInFaction(factionID))
{ {
player.getClass().getNpcStats(player).joinFaction(factionID); player.getClass().getNpcStats(player).joinFaction(factionID);
} }
@ -630,7 +628,7 @@ namespace MWScript
{ {
MWWorld::ConstPtr actor = R()(runtime, false); MWWorld::ConstPtr actor = R()(runtime, false);
std::string factionID; std::string_view factionID;
if(arg0==0) if(arg0==0)
{ {
@ -641,11 +639,10 @@ namespace MWScript
factionID = runtime.getStringLiteral (runtime[0].mInteger); factionID = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
} }
::Misc::StringUtils::lowerCaseInPlace(factionID);
// Make sure this faction exists // Make sure this faction exists
MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID); MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID);
if(factionID != "") if(!factionID.empty())
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).lowerRank(factionID); player.getClass().getNpcStats(player).lowerRank(factionID);
@ -662,7 +659,7 @@ namespace MWScript
{ {
MWWorld::ConstPtr ptr = R()(runtime, false); MWWorld::ConstPtr ptr = R()(runtime, false);
std::string factionID; std::string_view factionID;
if(arg0 >0) if(arg0 >0)
{ {
factionID = runtime.getStringLiteral (runtime[0].mInteger); factionID = runtime.getStringLiteral (runtime[0].mInteger);
@ -672,21 +669,13 @@ namespace MWScript
{ {
factionID = ptr.getClass().getPrimaryFaction(ptr); factionID = ptr.getClass().getPrimaryFaction(ptr);
} }
::Misc::StringUtils::lowerCaseInPlace(factionID);
// Make sure this faction exists // Make sure this faction exists
MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID); MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>().find(factionID);
MWWorld::Ptr player = MWMechanics::getPlayer(); if(!factionID.empty())
if(factionID!="")
{ {
if(player.getClass().getNpcStats(player).getFactionRanks().find(factionID) != player.getClass().getNpcStats(player).getFactionRanks().end()) MWWorld::Ptr player = MWMechanics::getPlayer();
{ runtime.push(player.getClass().getNpcStats(player).getFactionRank(factionID));
runtime.push(player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
}
else
{
runtime.push(-1);
}
} }
else else
{ {
@ -783,8 +772,6 @@ namespace MWScript
if (factionId.empty()) if (factionId.empty())
throw std::runtime_error ("failed to determine faction"); throw std::runtime_error ("failed to determine faction");
::Misc::StringUtils::lowerCaseInPlace (factionId);
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
runtime.push ( runtime.push (
player.getClass().getNpcStats (player).getFactionReputation (factionId)); player.getClass().getNpcStats (player).getFactionReputation (factionId));
@ -818,8 +805,6 @@ namespace MWScript
if (factionId.empty()) if (factionId.empty())
throw std::runtime_error ("failed to determine faction"); throw std::runtime_error ("failed to determine faction");
::Misc::StringUtils::lowerCaseInPlace (factionId);
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats (player).setFactionReputation (factionId, value); player.getClass().getNpcStats (player).setFactionReputation (factionId, value);
} }
@ -852,8 +837,6 @@ namespace MWScript
if (factionId.empty()) if (factionId.empty())
throw std::runtime_error ("failed to determine faction"); throw std::runtime_error ("failed to determine faction");
::Misc::StringUtils::lowerCaseInPlace (factionId);
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats (player).setFactionReputation (factionId, player.getClass().getNpcStats (player).setFactionReputation (factionId,
player.getClass().getNpcStats (player).getFactionReputation (factionId)+ player.getClass().getNpcStats (player).getFactionReputation (factionId)+
@ -926,7 +909,7 @@ namespace MWScript
{ {
MWWorld::ConstPtr ptr = R()(runtime, false); MWWorld::ConstPtr ptr = R()(runtime, false);
std::string factionID; std::string_view factionID;
if(arg0 >0 ) if(arg0 >0 )
{ {
factionID = runtime.getStringLiteral (runtime[0].mInteger); factionID = runtime.getStringLiteral (runtime[0].mInteger);
@ -936,9 +919,8 @@ namespace MWScript
{ {
factionID = ptr.getClass().getPrimaryFaction(ptr); factionID = ptr.getClass().getPrimaryFaction(ptr);
} }
::Misc::StringUtils::lowerCaseInPlace(factionID);
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(!factionID.empty())
{ {
runtime.push(player.getClass().getNpcStats(player).getExpelled(factionID)); runtime.push(player.getClass().getNpcStats(player).getExpelled(factionID));
} }
@ -958,7 +940,7 @@ namespace MWScript
{ {
MWWorld::ConstPtr ptr = R()(runtime, false); MWWorld::ConstPtr ptr = R()(runtime, false);
std::string factionID; std::string_view factionID;
if(arg0 >0 ) if(arg0 >0 )
{ {
factionID = runtime.getStringLiteral (runtime[0].mInteger); factionID = runtime.getStringLiteral (runtime[0].mInteger);
@ -969,7 +951,7 @@ namespace MWScript
factionID = ptr.getClass().getPrimaryFaction(ptr); factionID = ptr.getClass().getPrimaryFaction(ptr);
} }
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(!factionID.empty())
{ {
player.getClass().getNpcStats(player).expell(factionID); player.getClass().getNpcStats(player).expell(factionID);
} }
@ -985,7 +967,7 @@ namespace MWScript
{ {
MWWorld::ConstPtr ptr = R()(runtime, false); MWWorld::ConstPtr ptr = R()(runtime, false);
std::string factionID; std::string_view factionID;
if(arg0 >0 ) if(arg0 >0 )
{ {
factionID = runtime.getStringLiteral (runtime[0].mInteger); factionID = runtime.getStringLiteral (runtime[0].mInteger);
@ -996,7 +978,7 @@ namespace MWScript
factionID = ptr.getClass().getPrimaryFaction(ptr); factionID = ptr.getClass().getPrimaryFaction(ptr);
} }
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(!factionID.empty())
player.getClass().getNpcStats(player).clearExpelled(factionID); player.getClass().getNpcStats(player).clearExpelled(factionID);
} }
}; };
@ -1010,7 +992,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string factionID = ptr.getClass().getPrimaryFaction(ptr); std::string_view factionID = ptr.getClass().getPrimaryFaction(ptr);
if(factionID.empty()) if(factionID.empty())
return; return;
@ -1045,7 +1027,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string factionID = ptr.getClass().getPrimaryFaction(ptr); std::string_view factionID = ptr.getClass().getPrimaryFaction(ptr);
if(factionID.empty()) if(factionID.empty())
return; return;

@ -381,7 +381,7 @@ namespace MWScript
runtime.pop(); runtime.pop();
Interpreter::Type_Float zRot = runtime[0].mFloat; Interpreter::Type_Float zRot = runtime[0].mFloat;
runtime.pop(); runtime.pop();
std::string cellID{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (ptr.getContainerStore()) if (ptr.getContainerStore())
@ -404,7 +404,7 @@ namespace MWScript
const ESM::Cell* cell = MWBase::Environment::get().getWorld()->getExterior(cellID); const ESM::Cell* cell = MWBase::Environment::get().getWorld()->getExterior(cellID);
if(!cell) if(!cell)
{ {
std::string error = "Warning: PositionCell: unknown interior cell (" + cellID + ")"; std::string error = "Warning: PositionCell: unknown interior cell (" + std::string(cellID) + ")";
if(isPlayer) if(isPlayer)
error += ", moving to exterior instead"; error += ", moving to exterior instead";
runtime.getContext().report (error); runtime.getContext().report (error);
@ -496,7 +496,7 @@ namespace MWScript
{ {
std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string cellID{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float x = runtime[0].mFloat; Interpreter::Type_Float x = runtime[0].mFloat;
@ -520,7 +520,7 @@ namespace MWScript
store = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y()); store = MWBase::Environment::get().getWorld()->getExterior(cellIndex.x(), cellIndex.y());
if(!cell) if(!cell)
{ {
runtime.getContext().report ("unknown cell (" + cellID + ")"); runtime.getContext().report("unknown cell (" + std::string(cellID) + ")");
Log(Debug::Error) << "Error: unknown cell (" << cellID << ")"; Log(Debug::Error) << "Error: unknown cell (" << cellID << ")";
} }
} }

@ -197,7 +197,7 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
if (!character) if (!character)
{ {
MWWorld::ConstPtr player = MWMechanics::getPlayer(); MWWorld::ConstPtr player = MWMechanics::getPlayer();
std::string name = player.get<ESM::NPC>()->mBase->mName; const std::string& name = player.get<ESM::NPC>()->mBase->mName;
character = mCharacterManager.createCharacter(name); character = mCharacterManager.createCharacter(name);
mCharacterManager.setCurrentCharacter(character); mCharacterManager.setCurrentCharacter(character);
@ -214,7 +214,7 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
profile.mPlayerName = player.get<ESM::NPC>()->mBase->mName; profile.mPlayerName = player.get<ESM::NPC>()->mBase->mName;
profile.mPlayerLevel = player.getClass().getNpcStats (player).getLevel(); profile.mPlayerLevel = player.getClass().getNpcStats (player).getLevel();
std::string classId = player.get<ESM::NPC>()->mBase->mClass; const std::string& classId = player.get<ESM::NPC>()->mBase->mClass;
if (world.getStore().get<ESM::Class>().isDynamic(classId)) if (world.getStore().get<ESM::Class>().isDynamic(classId))
profile.mPlayerClassName = world.getStore().get<ESM::Class>().find(classId)->mName; profile.mPlayerClassName = world.getStore().get<ESM::Class>().find(classId)->mName;
else else

@ -172,7 +172,7 @@ MWWorld::CellStore *MWWorld::Cells::getExterior (int x, int y)
return &result->second; return &result->second;
} }
MWWorld::CellStore *MWWorld::Cells::getInterior (const std::string& name) MWWorld::CellStore* MWWorld::Cells::getInterior(std::string_view name)
{ {
std::string lowerName = Misc::StringUtils::lowerCase(name); std::string lowerName = Misc::StringUtils::lowerCase(name);
std::map<std::string, CellStore>::iterator result = mInteriors.find (lowerName); std::map<std::string, CellStore>::iterator result = mInteriors.find (lowerName);

@ -56,7 +56,7 @@ namespace MWWorld
CellStore *getExterior (int x, int y); CellStore *getExterior (int x, int y);
CellStore *getInterior (const std::string& name); CellStore* getInterior(std::string_view name);
CellStore *getCell (const ESM::CellId& id); CellStore *getCell (const ESM::CellId& id);

@ -483,9 +483,9 @@ namespace MWWorld
throw std::runtime_error("class does not support fight rating"); throw std::runtime_error("class does not support fight rating");
} }
std::string Class::getPrimaryFaction (const MWWorld::ConstPtr& ptr) const std::string_view Class::getPrimaryFaction(const MWWorld::ConstPtr& ptr) const
{ {
return std::string(); return {};
} }
int Class::getPrimaryFactionRank (const MWWorld::ConstPtr& ptr) const int Class::getPrimaryFactionRank (const MWWorld::ConstPtr& ptr) const
{ {

@ -355,7 +355,7 @@ namespace MWWorld
virtual int getBaseFightRating (const MWWorld::ConstPtr& ptr) const; virtual int getBaseFightRating (const MWWorld::ConstPtr& ptr) const;
virtual std::string getPrimaryFaction (const MWWorld::ConstPtr& ptr) const; virtual std::string_view getPrimaryFaction(const MWWorld::ConstPtr& ptr) const;
virtual int getPrimaryFactionRank (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. /// Get the effective armor rating, factoring in the actor's skills, for the given armor.

@ -306,7 +306,7 @@ void ESMStore::countAllCellRefs(ESM::ReadersCache& readers)
Misc::forEachUnique(refs.rbegin(), refs.rend(), equalByRefNum, incrementRefCount); Misc::forEachUnique(refs.rbegin(), refs.rend(), equalByRefNum, incrementRefCount);
} }
int ESMStore::getRefCount(const std::string& id) const int ESMStore::getRefCount(std::string_view id) const
{ {
const std::string lowerId = Misc::StringUtils::lowerCase(id); const std::string lowerId = Misc::StringUtils::lowerCase(id);
auto it = mRefCount.find(lowerId); auto it = mRefCount.find(lowerId);

@ -120,7 +120,7 @@ namespace MWWorld
} }
/// Look up the given ID in 'all'. Returns 0 if not found. /// Look up the given ID in 'all'. Returns 0 if not found.
int find(const std::string &id) const int find(std::string_view id) const
{ {
IDMap::const_iterator it = mIds.find(id); IDMap::const_iterator it = mIds.find(id);
if (it == mIds.end()) { if (it == mIds.end()) {
@ -284,7 +284,7 @@ namespace MWWorld
void checkPlayer(); void checkPlayer();
/// @return The number of instances defined in the base files. Excludes changes from the save file. /// @return The number of instances defined in the base files. Excludes changes from the save file.
int getRefCount(const std::string& id) const; int getRefCount(std::string_view id) const;
/// Actors with the same ID share spells, abilities, etc. /// 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. /// @return The shared spell list to use for this actor and whether or not it has already been initialized.

@ -12,6 +12,22 @@
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
namespace
{
// TODO: Switch to C++23 to get a working version of std::unordered_map::erase
template<class T>
bool eraseFromMap(T& map, std::string_view value)
{
auto it = map.find(value);
if(it != map.end())
{
map.erase(it);
return true;
}
return false;
}
}
namespace MWWorld namespace MWWorld
{ {
RecordId::RecordId(const std::string &id, bool isDeleted) RecordId::RecordId(const std::string &id, bool isDeleted)
@ -97,7 +113,7 @@ namespace MWWorld
} }
template<typename T> template<typename T>
const T *Store<T>::search(const std::string &id) const const T* Store<T>::search(std::string_view id) const
{ {
typename Dynamic::const_iterator dit = mDynamic.find(id); typename Dynamic::const_iterator dit = mDynamic.find(id);
if (dit != mDynamic.end()) if (dit != mDynamic.end())
@ -110,7 +126,7 @@ namespace MWWorld
return nullptr; return nullptr;
} }
template<typename T> template<typename T>
const T *Store<T>::searchStatic(const std::string &id) const const T* Store<T>::searchStatic(std::string_view id) const
{ {
typename Static::const_iterator it = mStatic.find(id); typename Static::const_iterator it = mStatic.find(id);
if (it != mStatic.end()) if (it != mStatic.end())
@ -120,13 +136,13 @@ namespace MWWorld
} }
template<typename T> template<typename T>
bool Store<T>::isDynamic(const std::string &id) const bool Store<T>::isDynamic(std::string_view id) const
{ {
typename Dynamic::const_iterator dit = mDynamic.find(id); typename Dynamic::const_iterator dit = mDynamic.find(id);
return (dit != mDynamic.end()); return (dit != mDynamic.end());
} }
template<typename T> template<typename T>
const T *Store<T>::searchRandom(const std::string &id, Misc::Rng::Generator& prng) const const T* Store<T>::searchRandom(std::string_view id, Misc::Rng::Generator& prng) const
{ {
std::vector<const T*> results; std::vector<const T*> results;
std::copy_if(mShared.begin(), mShared.end(), std::back_inserter(results), std::copy_if(mShared.begin(), mShared.end(), std::back_inserter(results),
@ -139,7 +155,7 @@ namespace MWWorld
return nullptr; return nullptr;
} }
template<typename T> template<typename T>
const T *Store<T>::find(const std::string &id) const const T* Store<T>::find(std::string_view id) const
{ {
const T *ptr = search(id); const T *ptr = search(id);
if (ptr == nullptr) if (ptr == nullptr)
@ -226,7 +242,7 @@ namespace MWWorld
return ptr; return ptr;
} }
template<typename T> template<typename T>
bool Store<T>::eraseStatic(const std::string &id) bool Store<T>::eraseStatic(std::string_view id)
{ {
typename Static::iterator it = mStatic.find(id); typename Static::iterator it = mStatic.find(id);
@ -249,9 +265,9 @@ namespace MWWorld
} }
template<typename T> template<typename T>
bool Store<T>::erase(const std::string &id) bool Store<T>::erase(std::string_view id)
{ {
if (!mDynamic.erase(id)) if (!eraseFromMap(mDynamic, id))
return false; return false;
// have to reinit the whole shared part // have to reinit the whole shared part
@ -475,7 +491,7 @@ namespace MWWorld
esm.restoreContext(ctx); esm.restoreContext(ctx);
} }
const ESM::Cell *Store<ESM::Cell>::search(const std::string &id) const const ESM::Cell* Store<ESM::Cell>::search(std::string_view id) const
{ {
DynamicInt::const_iterator it = mInt.find(id); DynamicInt::const_iterator it = mInt.find(id);
if (it != mInt.end()) { if (it != mInt.end()) {
@ -534,12 +550,12 @@ namespace MWWorld
return &mExt.insert(std::make_pair(key, newCell)).first->second; return &mExt.insert(std::make_pair(key, newCell)).first->second;
} }
const ESM::Cell *Store<ESM::Cell>::find(const std::string &id) const const ESM::Cell* Store<ESM::Cell>::find(std::string_view id) const
{ {
const ESM::Cell *ptr = search(id); const ESM::Cell *ptr = search(id);
if (ptr == nullptr) if (ptr == nullptr)
{ {
const std::string msg = "Cell '" + id + "' not found"; const std::string msg = "Cell '" + std::string(id) + "' not found";
throw std::runtime_error(msg); throw std::runtime_error(msg);
} }
return ptr; return ptr;
@ -677,7 +693,7 @@ namespace MWWorld
{ {
return iterator(mSharedExt.end()); return iterator(mSharedExt.end());
} }
const ESM::Cell *Store<ESM::Cell>::searchExtByName(const std::string &id) const const ESM::Cell* Store<ESM::Cell>::searchExtByName(std::string_view id) const
{ {
const ESM::Cell *cell = nullptr; const ESM::Cell *cell = nullptr;
for (const ESM::Cell *sharedCell : mSharedExt) for (const ESM::Cell *sharedCell : mSharedExt)
@ -694,7 +710,7 @@ namespace MWWorld
} }
return cell; return cell;
} }
const ESM::Cell *Store<ESM::Cell>::searchExtByRegion(const std::string &id) const const ESM::Cell* Store<ESM::Cell>::searchExtByRegion(std::string_view id) const
{ {
const ESM::Cell *cell = nullptr; const ESM::Cell *cell = nullptr;
for (const ESM::Cell *sharedCell : mSharedExt) for (const ESM::Cell *sharedCell : mSharedExt)
@ -760,7 +776,7 @@ namespace MWWorld
} }
return erase(cell.mName); return erase(cell.mName);
} }
bool Store<ESM::Cell>::erase(const std::string &id) bool Store<ESM::Cell>::erase(std::string_view id)
{ {
DynamicInt::iterator it = mDynamicInt.find(id); DynamicInt::iterator it = mDynamicInt.find(id);
@ -877,7 +893,7 @@ namespace MWWorld
return &(it->second); return &(it->second);
return nullptr; return nullptr;
} }
const ESM::Pathgrid *Store<ESM::Pathgrid>::search(const std::string& name) const const ESM::Pathgrid* Store<ESM::Pathgrid>::search(std::string_view name) const
{ {
Interior::const_iterator it = mInt.find(name); Interior::const_iterator it = mInt.find(name);
if (it != mInt.end()) if (it != mInt.end())
@ -894,12 +910,12 @@ namespace MWWorld
} }
return pathgrid; return pathgrid;
} }
const ESM::Pathgrid* Store<ESM::Pathgrid>::find(const std::string& name) const const ESM::Pathgrid* Store<ESM::Pathgrid>::find(std::string_view name) const
{ {
const ESM::Pathgrid* pathgrid = search(name); const ESM::Pathgrid* pathgrid = search(name);
if (!pathgrid) if (!pathgrid)
{ {
const std::string msg = "Pathgrid in cell '" + name + "' not found"; const std::string msg = "Pathgrid in cell '" + std::string(name) + "' not found";
throw std::runtime_error(msg); throw std::runtime_error(msg);
} }
return pathgrid; return pathgrid;
@ -1012,7 +1028,7 @@ namespace MWWorld
mKeywordSearchModFlag = true; mKeywordSearchModFlag = true;
} }
const ESM::Dialogue *Store<ESM::Dialogue>::search(const std::string &id) const const ESM::Dialogue* Store<ESM::Dialogue>::search(std::string_view id) const
{ {
typename Static::const_iterator it = mStatic.find(id); typename Static::const_iterator it = mStatic.find(id);
if (it != mStatic.end()) if (it != mStatic.end())
@ -1021,7 +1037,7 @@ namespace MWWorld
return nullptr; return nullptr;
} }
const ESM::Dialogue *Store<ESM::Dialogue>::find(const std::string &id) const const ESM::Dialogue* Store<ESM::Dialogue>::find(std::string_view id) const
{ {
const ESM::Dialogue *ptr = search(id); const ESM::Dialogue *ptr = search(id);
if (ptr == nullptr) if (ptr == nullptr)
@ -1072,9 +1088,9 @@ namespace MWWorld
return RecordId(dialogue.mId, isDeleted); return RecordId(dialogue.mId, isDeleted);
} }
bool Store<ESM::Dialogue>::eraseStatic(const std::string &id) bool Store<ESM::Dialogue>::eraseStatic(std::string_view id)
{ {
if (mStatic.erase(id)) if (eraseFromMap(mStatic, id))
mKeywordSearchModFlag = true; mKeywordSearchModFlag = true;
return true; return true;

@ -31,7 +31,7 @@ namespace MWWorld
std::string mId; std::string mId;
bool mIsDeleted; bool mIsDeleted;
RecordId(const std::string &id = "", bool isDeleted = false); RecordId(const std::string &id = {}, bool isDeleted = false);
}; };
class StoreBase class StoreBase
@ -48,7 +48,7 @@ namespace MWWorld
virtual int getDynamicSize() const { return 0; } virtual int getDynamicSize() const { return 0; }
virtual RecordId load(ESM::ESMReader &esm) = 0; virtual RecordId load(ESM::ESMReader &esm) = 0;
virtual bool eraseStatic(const std::string &id) {return false;} virtual bool eraseStatic(std::string_view id) { return false; }
virtual void clearDynamic() {} virtual void clearDynamic() {}
virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const {} virtual void write (ESM::ESMWriter& writer, Loading::Listener& progress) const {}
@ -175,19 +175,19 @@ namespace MWWorld
void clearDynamic() override; void clearDynamic() override;
void setUp() override; void setUp() override;
const T *search(const std::string &id) const; const T* search(std::string_view id) const;
const T *searchStatic(const std::string &id) const; const T* searchStatic(std::string_view id) const;
/** /**
* Does the record with this ID come from the dynamic store? * Does the record with this ID come from the dynamic store?
*/ */
bool isDynamic(const std::string &id) const; bool isDynamic(std::string_view id) const;
/** Returns a random record that starts with the named ID, or nullptr if not found. */ /** Returns a random record that starts with the named ID, or nullptr if not found. */
const T *searchRandom(const std::string &id, Misc::Rng::Generator& prng) const; const T* searchRandom(std::string_view id, Misc::Rng::Generator& prng) const;
// calls `search` and throws an exception if not found // calls `search` and throws an exception if not found
const T *find(const std::string &id) const; const T* find(std::string_view id) const;
iterator begin() const; iterator begin() const;
iterator end() const; iterator end() const;
@ -201,8 +201,8 @@ namespace MWWorld
T *insert(const T &item, bool overrideOnly = false); T *insert(const T &item, bool overrideOnly = false);
T *insertStatic(const T &item); T *insertStatic(const T &item);
bool eraseStatic(const std::string &id) override; bool eraseStatic(std::string_view id) override;
bool erase(const std::string &id); bool erase(std::string_view id);
bool erase(const T &item); bool erase(const T &item);
RecordId load(ESM::ESMReader &esm) override; RecordId load(ESM::ESMReader &esm) override;
@ -318,12 +318,12 @@ namespace MWWorld
public: public:
typedef SharedIterator<ESM::Cell> iterator; typedef SharedIterator<ESM::Cell> iterator;
const ESM::Cell *search(const std::string &id) const; const ESM::Cell* search(std::string_view id) const;
const ESM::Cell *search(int x, int y) const; const ESM::Cell *search(int x, int y) const;
const ESM::Cell *searchStatic(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 *searchOrCreate(int x, int y);
const ESM::Cell *find(const std::string &id) const; const ESM::Cell* find(std::string_view id) const;
const ESM::Cell *find(int x, int y) const; const ESM::Cell *find(int x, int y) const;
void clearDynamic() override; void clearDynamic() override;
@ -337,10 +337,10 @@ namespace MWWorld
iterator extEnd() const; iterator extEnd() const;
// Return the northernmost cell in the easternmost column. // Return the northernmost cell in the easternmost column.
const ESM::Cell *searchExtByName(const std::string &id) const; const ESM::Cell* searchExtByName(std::string_view id) const;
// Return the northernmost cell in the easternmost column. // Return the northernmost cell in the easternmost column.
const ESM::Cell *searchExtByRegion(const std::string &id) const; const ESM::Cell* searchExtByRegion(std::string_view id) const;
size_t getSize() const override; size_t getSize() const override;
size_t getExtSize() const; size_t getExtSize() const;
@ -351,7 +351,7 @@ namespace MWWorld
ESM::Cell *insert(const ESM::Cell &cell); ESM::Cell *insert(const ESM::Cell &cell);
bool erase(const ESM::Cell &cell); bool erase(const ESM::Cell &cell);
bool erase(const std::string &id); bool erase(std::string_view id);
bool erase(int x, int y); bool erase(int x, int y);
}; };
@ -379,9 +379,9 @@ namespace MWWorld
void setUp() override; void setUp() override;
const ESM::Pathgrid *search(int x, int y) const; const ESM::Pathgrid *search(int x, int y) const;
const ESM::Pathgrid *search(const std::string& name) const; const ESM::Pathgrid* search(std::string_view name) const;
const ESM::Pathgrid *find(int x, int y) const; const ESM::Pathgrid *find(int x, int y) const;
const ESM::Pathgrid* find(const std::string& name) const; const ESM::Pathgrid* find(std::string_view name) const;
const ESM::Pathgrid *search(const ESM::Cell &cell) const; const ESM::Pathgrid *search(const ESM::Cell &cell) const;
const ESM::Pathgrid *find(const ESM::Cell &cell) const; const ESM::Pathgrid *find(const ESM::Cell &cell) const;
}; };
@ -470,15 +470,15 @@ namespace MWWorld
void setUp() override; void setUp() override;
const ESM::Dialogue *search(const std::string &id) const; const ESM::Dialogue* search(std::string_view id) const;
const ESM::Dialogue *find(const std::string &id) const; const ESM::Dialogue* find(std::string_view id) const;
iterator begin() const; iterator begin() const;
iterator end() const; iterator end() const;
size_t getSize() const override; size_t getSize() const override;
bool eraseStatic(const std::string &id) override; bool eraseStatic(std::string_view id) override;
RecordId load(ESM::ESMReader &esm) override; RecordId load(ESM::ESMReader &esm) override;

@ -626,7 +626,7 @@ namespace
stopSounds(); stopSounds();
} }
void WeatherManager::changeWeather(const std::string& regionID, const unsigned int weatherID) void WeatherManager::changeWeather(std::string_view regionID, const unsigned int weatherID)
{ {
// In Morrowind, this seems to have the following behavior, when applied to the current region: // 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. // - When there is no transition in progress, start transitioning to the new weather.
@ -648,7 +648,7 @@ namespace
} }
} }
void WeatherManager::modRegion(const std::string& regionID, const std::vector<char>& chances) void WeatherManager::modRegion(std::string_view regionID, const std::vector<char>& chances)
{ {
// Sets the region's probability for various weather patterns. Note that this appears to be saved permanently. // 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: // In Morrowind, this seems to have the following behavior when applied to the current region:

@ -284,8 +284,8 @@ namespace MWWorld
* @param region that should be changed * @param region that should be changed
* @param ID of the weather setting to shift to * @param ID of the weather setting to shift to
*/ */
void changeWeather(const std::string& regionID, const unsigned int weatherID); void changeWeather(std::string_view regionID, const unsigned int weatherID);
void modRegion(const std::string& regionID, const std::vector<char>& chances); void modRegion(std::string_view regionID, const std::vector<char>& chances);
void playerTeleported(const std::string& playerRegion, bool isExterior); void playerTeleported(const std::string& playerRegion, bool isExterior);
/** /**

@ -547,7 +547,7 @@ namespace MWWorld
mRandomSeed = seed; mRandomSeed = seed;
} }
const ESM::Cell* World::getExterior(const std::string& cellName) const const ESM::Cell* World::getExterior(std::string_view cellName) const
{ {
// first try named cells // first try named cells
const ESM::Cell *cell = mStore.get<ESM::Cell>().searchExtByName (cellName); const ESM::Cell *cell = mStore.get<ESM::Cell>().searchExtByName (cellName);
@ -579,7 +579,7 @@ namespace MWWorld
return mCells.getExterior (x, y); return mCells.getExterior (x, y);
} }
CellStore *World::getInterior (const std::string& name) CellStore *World::getInterior(std::string_view name)
{ {
return mCells.getInterior (name); return mCells.getInterior (name);
} }
@ -2040,12 +2040,12 @@ namespace MWWorld
return mWeatherManager->getNightDayMode(); return mWeatherManager->getNightDayMode();
} }
void World::changeWeather(const std::string& region, const unsigned int id) void World::changeWeather(std::string_view region, const unsigned int id)
{ {
mWeatherManager->changeWeather(region, id); mWeatherManager->changeWeather(region, id);
} }
void World::modRegion(const std::string &regionid, const std::vector<char> &chances) void World::modRegion(std::string_view regionid, const std::vector<char>& chances)
{ {
mWeatherManager->modRegion(regionid, chances); mWeatherManager->modRegion(regionid, chances);
} }
@ -2767,7 +2767,7 @@ namespace MWWorld
physicActor->enableCollisionBody(enable); physicActor->enableCollisionBody(enable);
} }
bool World::findInteriorPosition(const std::string &name, ESM::Position &pos) bool World::findInteriorPosition(std::string_view name, ESM::Position& pos)
{ {
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0; pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
@ -3686,7 +3686,7 @@ namespace MWWorld
return file; return file;
} }
void World::spawnRandomCreature(const std::string &creatureList) void World::spawnRandomCreature(std::string_view creatureList)
{ {
const ESM::CreatureLevList* list = mStore.get<ESM::CreatureLevList>().find(creatureList); const ESM::CreatureLevList* list = mStore.get<ESM::CreatureLevList>().find(creatureList);
@ -3883,7 +3883,7 @@ namespace MWWorld
return mPhysics->getHitDistance(weaponPos, target) - halfExtents.y(); return mPhysics->getHitDistance(weaponPos, target) - halfExtents.y();
} }
void preload(MWWorld::Scene* scene, const ESMStore& store, const std::string& obj) void preload(MWWorld::Scene* scene, const ESMStore& store, std::string_view obj)
{ {
if (obj.empty()) if (obj.empty())
return; return;

@ -222,7 +222,7 @@ namespace MWWorld
CellStore *getExterior (int x, int y) override; CellStore *getExterior (int x, int y) override;
CellStore *getInterior (const std::string& name) override; CellStore* getInterior(std::string_view name) override;
CellStore *getCell (const ESM::CellId& id) override; CellStore *getCell (const ESM::CellId& id) override;
@ -333,7 +333,7 @@ namespace MWWorld
bool toggleSky() override; bool toggleSky() override;
///< \return Resulting mode ///< \return Resulting mode
void changeWeather (const std::string& region, const unsigned int id) override; void changeWeather(std::string_view region, const unsigned int id) override;
int getCurrentWeather() const override; int getCurrentWeather() const override;
@ -349,7 +349,7 @@ namespace MWWorld
void setMoonColour (bool red) override; void setMoonColour (bool red) override;
void modRegion(const std::string &regionid, const std::vector<char> &chances) override; void modRegion(std::string_view regionid, const std::vector<char> &chances) override;
float getTimeScaleFactor() const override; float getTimeScaleFactor() const override;
@ -368,7 +368,7 @@ namespace MWWorld
void changeToCell (const ESM::CellId& cellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true) override; void changeToCell (const ESM::CellId& cellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true) override;
///< @param changeEvent If false, do not trigger cell change flag or detect worldspace changes ///< @param changeEvent If false, do not trigger cell change flag or detect worldspace changes
const ESM::Cell *getExterior (const std::string& cellName) const override; const ESM::Cell* getExterior(std::string_view cellName) const override;
///< Return a cell matching the given name or a 0-pointer, if there is no such cell. ///< Return a cell matching the given name or a 0-pointer, if there is no such cell.
void markCellAsUnchanged() override; void markCellAsUnchanged() override;
@ -617,7 +617,7 @@ namespace MWWorld
/// Find position in interior cell near door entrance /// Find position in interior cell near door entrance
/// \return false if interior with given name not exists, true otherwise /// \return false if interior with given name not exists, true otherwise
bool findInteriorPosition(const std::string &name, ESM::Position &pos) override; bool findInteriorPosition(std::string_view name, ESM::Position &pos) override;
/// Enables or disables use of teleport spell effects (recall, intervention, etc). /// Enables or disables use of teleport spell effects (recall, intervention, etc).
void enableTeleporting(bool enable) override; void enableTeleporting(bool enable) override;
@ -687,7 +687,7 @@ namespace MWWorld
void goToJail () override; void goToJail () override;
/// Spawn a random creature from a levelled list next to the player /// Spawn a random creature from a levelled list next to the player
void spawnRandomCreature(const std::string& creatureList) override; void spawnRandomCreature(std::string_view creatureList) override;
/// Spawn a blood effect for \a ptr at \a worldPosition /// Spawn a blood effect for \a ptr at \a worldPosition
void spawnBloodEffect (const MWWorld::Ptr& ptr, const osg::Vec3f& worldPosition) override; void spawnBloodEffect (const MWWorld::Ptr& ptr, const osg::Vec3f& worldPosition) override;

@ -57,6 +57,8 @@ namespace Misc::StringUtils
struct CiEqual struct CiEqual
{ {
using is_transparent = void;
bool operator()(std::string_view left, std::string_view right) const bool operator()(std::string_view left, std::string_view right) const
{ {
return ciEqual(left, right); return ciEqual(left, right);
@ -65,10 +67,12 @@ namespace Misc::StringUtils
struct CiHash struct CiHash
{ {
std::size_t operator()(std::string str) const using is_transparent = void;
std::size_t operator()(std::string_view str) const
{ {
lowerCaseInPlace(str); // TODO avoid string copy
return std::hash<std::string>{}(str); return std::hash<std::string>{}(lowerCase(str));
} }
}; };

Loading…
Cancel
Save