mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 01:45:38 +00:00
Fixed issue with getSummonedCreature( that returned a reference to a non const static value
Fix compile, and apply review comment Fixed greater vs more typo. getCellname is back to a string view. Because in most cases was used as a strong not a refId. and there was a fundamental issue with region names used as a cellname
This commit is contained in:
parent
1ef1de974d
commit
dc21df97c8
17 changed files with 57 additions and 43 deletions
|
@ -177,12 +177,12 @@ namespace MWBase
|
|||
virtual char getGlobalVariableType(std::string_view name) const = 0;
|
||||
///< Return ' ', if there is no global variable with this name.
|
||||
|
||||
virtual const ESM::RefId& getCellName(const MWWorld::CellStore* cell = nullptr) const = 0;
|
||||
virtual std::string_view 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 const ESM::RefId getCellName(const ESM::Cell* cell) const = 0;
|
||||
virtual std::string_view getCellName(const ESM::Cell* cell) const = 0;
|
||||
|
||||
virtual void removeRefScript(MWWorld::RefData* ref) = 0;
|
||||
//< Remove the script attached to ref from mLocalScripts
|
||||
|
|
|
@ -299,7 +299,7 @@ namespace MWClass
|
|||
|
||||
std::string Door::getDestination(const MWWorld::LiveCellRef<ESM::Door>& door)
|
||||
{
|
||||
auto dest = door.mRef.getDestCell();
|
||||
std::string_view dest = door.mRef.getDestCell().getRefIdString();
|
||||
if (dest.empty())
|
||||
{
|
||||
// door leads to exterior, use cell name (if any), otherwise translated region name
|
||||
|
@ -310,7 +310,7 @@ namespace MWClass
|
|||
dest = world->getCellName(cell);
|
||||
}
|
||||
|
||||
return "#{sCell=" + dest.getRefIdString() + "}";
|
||||
return "#{sCell=" + std::string{ dest } + "}";
|
||||
}
|
||||
|
||||
MWWorld::Ptr Door::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const
|
||||
|
|
|
@ -196,8 +196,7 @@ bool MWDialogue::Filter::testPlayer(const ESM::DialInfo& info) const
|
|||
if (!info.mCell.empty())
|
||||
{
|
||||
// supports partial matches, just like getPcCell
|
||||
std::string_view playerCell
|
||||
= MWBase::Environment::get().getWorld()->getCellName(player.getCell()).getRefIdString();
|
||||
std::string_view playerCell = MWBase::Environment::get().getWorld()->getCellName(player.getCell());
|
||||
if (!Misc::StringUtils::ciStartsWith(playerCell, info.mCell.getRefIdString()))
|
||||
return false;
|
||||
}
|
||||
|
@ -554,8 +553,7 @@ bool MWDialogue::Filter::getSelectStructBoolean(const SelectWrapper& select) con
|
|||
|
||||
case SelectWrapper::Function_NotCell:
|
||||
{
|
||||
std::string_view actorCell
|
||||
= MWBase::Environment::get().getWorld()->getCellName(mActor.getCell()).getRefIdString();
|
||||
std::string_view actorCell = MWBase::Environment::get().getWorld()->getCellName(mActor.getCell());
|
||||
return !Misc::StringUtils::ciStartsWith(actorCell, select.getName());
|
||||
}
|
||||
case SelectWrapper::Function_SameGender:
|
||||
|
|
|
@ -330,7 +330,7 @@ namespace MWGui
|
|||
continue;
|
||||
if (mGenderIndex != (bodypart.mData.mFlags & ESM::BodyPart::BPF_Female))
|
||||
continue;
|
||||
bool firstPerson = idString.ends_with("1st");
|
||||
bool firstPerson = Misc::StringUtils::ciEndsWith(idString, "1st");
|
||||
if (firstPerson)
|
||||
continue;
|
||||
if (bodypart.mRace == mCurrentRaceId)
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace MWGui
|
|||
|
||||
for (unsigned int i = 0; i < transport.size(); i++)
|
||||
{
|
||||
ESM::RefId cellname = transport[i].mCellName;
|
||||
std::string_view cellname = transport[i].mCellName.getRefIdString();
|
||||
bool interior = true;
|
||||
const osg::Vec2i cellIndex
|
||||
= MWWorld::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]);
|
||||
|
@ -134,7 +134,7 @@ namespace MWGui
|
|||
cellname = MWBase::Environment::get().getWorld()->getCellName(cell);
|
||||
interior = false;
|
||||
}
|
||||
addDestination(cellname, transport[i].mPos, interior);
|
||||
addDestination(ESM::RefId::stringRefId(cellname), transport[i].mPos, interior);
|
||||
}
|
||||
|
||||
updateLabels();
|
||||
|
|
|
@ -933,7 +933,7 @@ namespace MWGui
|
|||
{
|
||||
mMap->requestMapRender(cell);
|
||||
|
||||
std::string name = MWBase::Environment::get().getWorld()->getCellName(cell).getRefIdString();
|
||||
std::string name{ MWBase::Environment::get().getWorld()->getCellName(cell) };
|
||||
|
||||
mMap->setCellName(name);
|
||||
mHud->setCellName(name);
|
||||
|
|
|
@ -29,9 +29,14 @@ namespace MWMechanics
|
|||
|| (effectId >= ESM::MagicEffect::SummonFabricant && effectId <= ESM::MagicEffect::SummonCreature05));
|
||||
}
|
||||
|
||||
const ESM::RefId& getSummonedCreature(int effectId)
|
||||
static const std::map<int, ESM::RefId>& getSummonMap()
|
||||
{
|
||||
static const std::map<int, std::string_view> summonMap{
|
||||
static std::map<int, ESM::RefId> summonMap;
|
||||
|
||||
if (summonMap.size() > 0)
|
||||
return summonMap;
|
||||
|
||||
const std::map<int, std::string_view> summonMapToGameSetting{
|
||||
{ ESM::MagicEffect::SummonAncestralGhost, "sMagicAncestralGhostID" },
|
||||
{ ESM::MagicEffect::SummonBonelord, "sMagicBonelordID" },
|
||||
{ ESM::MagicEffect::SummonBonewalker, "sMagicLeastBonewalkerID" },
|
||||
|
@ -56,16 +61,25 @@ namespace MWMechanics
|
|||
{ ESM::MagicEffect::SummonCreature05, "sMagicCreature05ID" },
|
||||
};
|
||||
|
||||
for (const auto& it : summonMapToGameSetting)
|
||||
{
|
||||
summonMap[it.first] = ESM::RefId::stringRefId(MWBase::Environment::get()
|
||||
.getWorld()
|
||||
->getStore()
|
||||
.get<ESM::GameSetting>()
|
||||
.find(it.second)
|
||||
->mValue.getString());
|
||||
}
|
||||
return summonMap;
|
||||
}
|
||||
|
||||
const ESM::RefId& getSummonedCreature(int effectId)
|
||||
{
|
||||
const auto& summonMap = getSummonMap();
|
||||
auto it = summonMap.find(effectId);
|
||||
if (it != summonMap.end())
|
||||
{
|
||||
static ESM::RefId val = ESM::RefId::stringRefId(MWBase::Environment::get()
|
||||
.getWorld()
|
||||
->getStore()
|
||||
.get<ESM::GameSetting>()
|
||||
.find(it->second)
|
||||
->mValue.getString());
|
||||
return val;
|
||||
return it->second;
|
||||
}
|
||||
return ESM::RefId::sEmpty;
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ namespace MWScript
|
|||
}
|
||||
const MWWorld::CellStore* cell = MWMechanics::getPlayer().getCell();
|
||||
|
||||
std::string_view current = MWBase::Environment::get().getWorld()->getCellName(cell).getRefIdString();
|
||||
std::string_view current = MWBase::Environment::get().getWorld()->getCellName(cell);
|
||||
bool match = Misc::StringUtils::ciCompareLen(name, current, name.length()) == 0;
|
||||
|
||||
runtime.push(match ? 1 : 0);
|
||||
|
|
|
@ -414,7 +414,7 @@ namespace MWScript
|
|||
|
||||
std::string_view InterpreterContext::getCurrentCellName() const
|
||||
{
|
||||
return MWBase::Environment::get().getWorld()->getCellName().getRefIdString();
|
||||
return MWBase::Environment::get().getWorld()->getCellName();
|
||||
}
|
||||
|
||||
void InterpreterContext::executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor)
|
||||
|
|
|
@ -210,7 +210,7 @@ namespace MWScript
|
|||
return iter->second;
|
||||
}
|
||||
|
||||
throw std::logic_error("script " + std::string{ name.getRefIdString() } + " does not exist");
|
||||
throw std::logic_error("script " + name.getRefIdString() + " does not exist");
|
||||
}
|
||||
|
||||
GlobalScripts& ScriptManager::getGlobalScripts()
|
||||
|
|
|
@ -222,7 +222,7 @@ void MWState::StateManager::saveGame(const std::string& description, const Slot*
|
|||
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;
|
||||
|
|
|
@ -957,7 +957,7 @@ namespace MWWorld
|
|||
|
||||
Store<ESM::Skill>::Store() {}
|
||||
|
||||
// Magic effect
|
||||
// Game Settings
|
||||
//=========================================================================
|
||||
|
||||
const ESM::GameSetting* Store<ESM::GameSetting>::search(const ESM::RefId& id) const
|
||||
|
@ -973,9 +973,10 @@ namespace MWWorld
|
|||
const ESM::GameSetting* Store<ESM::GameSetting>::search(std::string_view id) const
|
||||
{
|
||||
return TypedDynamicStore::search(ESM::RefId::stringRefId(id));
|
||||
;
|
||||
}
|
||||
|
||||
// Magic effect
|
||||
//=========================================================================
|
||||
Store<ESM::MagicEffect>::Store() {}
|
||||
|
||||
// Attribute
|
||||
|
|
|
@ -572,7 +572,7 @@ namespace MWWorld
|
|||
if (cell)
|
||||
return cell;
|
||||
// treat "Wilderness" like an empty string
|
||||
const ESM::RefId defaultName
|
||||
static const ESM::RefId defaultName
|
||||
= ESM::RefId::stringRefId(mStore.get<ESM::GameSetting>().find("sDefaultCellname")->mValue.getString());
|
||||
if (cellName == defaultName)
|
||||
{
|
||||
|
@ -584,7 +584,7 @@ namespace MWWorld
|
|||
// didn't work -> now check for regions
|
||||
for (const ESM::Region& region : mStore.get<ESM::Region>())
|
||||
{
|
||||
if (Misc::StringUtils::ciEqual(cellName.getRefIdString(), region.mName))
|
||||
if (cellName == ESM::RefId::stringRefId(region.mName))
|
||||
{
|
||||
return mStore.get<ESM::Cell>().searchExtByRegion(region.mId);
|
||||
}
|
||||
|
@ -656,24 +656,25 @@ namespace MWWorld
|
|||
return mCurrentDate->getMonthName(month);
|
||||
}
|
||||
|
||||
const ESM::RefId& World::getCellName(const MWWorld::CellStore* cell) const
|
||||
std::string_view World::getCellName(const MWWorld::CellStore* cell) const
|
||||
{
|
||||
if (!cell)
|
||||
cell = mWorldScene->getCurrentCell();
|
||||
return getCellName(cell->getCell());
|
||||
}
|
||||
|
||||
const ESM::RefId World::getCellName(const ESM::Cell* cell) const
|
||||
std::string_view World::getCellName(const ESM::Cell* cell) const
|
||||
{
|
||||
if (cell)
|
||||
{
|
||||
if (!cell->isExterior() || !cell->mName.empty())
|
||||
return cell->mName;
|
||||
return cell->mName.getRefIdString();
|
||||
|
||||
if (const ESM::Region* region = mStore.get<ESM::Region>().search(cell->mRegion))
|
||||
return ESM::RefId::stringRefId(region->mName);
|
||||
return region->mName;
|
||||
}
|
||||
return ESM::RefId::stringRefId(mStore.get<ESM::GameSetting>().find("sDefaultCellname")->mValue.getString());
|
||||
|
||||
return mStore.get<ESM::GameSetting>().find("sDefaultCellname")->mValue.getString();
|
||||
}
|
||||
|
||||
void World::removeRefScript(MWWorld::RefData* ref)
|
||||
|
@ -1422,7 +1423,7 @@ namespace MWWorld
|
|||
esmPos.pos[0] = traced.x();
|
||||
esmPos.pos[1] = traced.y();
|
||||
esmPos.pos[2] = traced.z();
|
||||
const ESM::RefId* cell;
|
||||
const ESM::RefId* cell = &ESM::RefId::sEmpty;
|
||||
if (!actor.getCell()->isExterior())
|
||||
cell = &actor.getCell()->getCell()->mName;
|
||||
MWWorld::ActionTeleport(*cell, esmPos, false).execute(actor);
|
||||
|
@ -3430,7 +3431,7 @@ namespace MWWorld
|
|||
return;
|
||||
}
|
||||
|
||||
const ESM::RefId* cellName;
|
||||
const ESM::RefId* cellName = &ESM::RefId::sEmpty;
|
||||
if (!closestMarker.mCell->isExterior())
|
||||
cellName = &closestMarker.mCell->getCell()->mName;
|
||||
|
||||
|
|
|
@ -267,12 +267,12 @@ namespace MWWorld
|
|||
char getGlobalVariableType(std::string_view name) const override;
|
||||
///< Return ' ', if there is no global variable with this name.
|
||||
|
||||
const ESM::RefId& getCellName(const MWWorld::CellStore* cell = nullptr) const override;
|
||||
std::string_view 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.
|
||||
const ESM::RefId getCellName(const ESM::Cell* cell) const override;
|
||||
std::string_view getCellName(const ESM::Cell* cell) const override;
|
||||
|
||||
void removeRefScript(MWWorld::RefData* ref) override;
|
||||
//< Remove the script attached to ref from mLocalScripts
|
||||
|
|
|
@ -65,7 +65,7 @@ MWWorld::CellStore* MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
|
|||
auto result = mInteriors.find(cell->mName);
|
||||
|
||||
if (result == mInteriors.end())
|
||||
result = mInteriors.emplace(std::move(cell->mName), CellStore(cell, mStore, mReaders)).first;
|
||||
result = mInteriors.emplace(cell->mName, CellStore(cell, mStore, mReaders)).first;
|
||||
|
||||
return &result->second;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace ESM
|
|||
|
||||
bool RefId::operator>(const RefId& rhs) const
|
||||
{
|
||||
return Misc::StringUtils::ciMore(mId, rhs.mId);
|
||||
return Misc::StringUtils::ciGreater(mId, rhs.mId);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const RefId& refId)
|
||||
|
|
|
@ -20,14 +20,14 @@ namespace Misc::StringUtils
|
|||
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharLess());
|
||||
}
|
||||
|
||||
struct CiCharMore
|
||||
struct CiCharGreater
|
||||
{
|
||||
bool operator()(char x, char y) const { return toLower(x) > toLower(y); }
|
||||
};
|
||||
|
||||
inline bool ciMore(std::string_view x, std::string_view y)
|
||||
inline bool ciGreater(std::string_view x, std::string_view y)
|
||||
{
|
||||
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharMore());
|
||||
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), CiCharGreater());
|
||||
}
|
||||
|
||||
inline bool ciEqual(std::string_view x, std::string_view y)
|
||||
|
|
Loading…
Reference in a new issue