diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index 9f1ad3e4a2..3ea6766b90 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -1,15 +1,47 @@ #include "cell.hpp" +#include "esmstore.hpp" + +#include "../mwbase/environment.hpp" + #include #include #include #include -#include "../mwbase/environment.hpp" -#include "esmstore.hpp" +#include +#include namespace MWWorld { + namespace + { + std::string getDescription(const ESM4::World& value) + { + if (!value.mEditorId.empty()) + return value.mEditorId; + + return value.mId.serializeText(); + } + + std::string getCellDescription(const ESM4::Cell& cell, const ESM4::World* world) + { + std::string result; + + if (!cell.mEditorId.empty()) + result = cell.mEditorId; + else if (world != nullptr && cell.isExterior()) + result = getDescription(*world); + else + result = cell.mId.serializeText(); + + if (cell.isExterior()) + result += " (" + std::to_string(cell.mX) + ", " + std::to_string(cell.mY) + ")"; + + return result; + } + } + Cell::Cell(const ESM4::Cell& cell) : ESM::CellVariant(cell) , mIsExterior(!(cell.mCellFlags & ESM4::CELL_Interior)) @@ -23,7 +55,6 @@ namespace MWWorld , mId(cell.mId) , mParent(cell.mParent) , mWaterHeight(cell.mWaterHeight) - , mDescription(cell.mEditorId) , mMood{ .mAmbiantColor = cell.mLighting.ambient, .mDirectionalColor = cell.mLighting.directional, @@ -32,12 +63,15 @@ namespace MWWorld .mFogDensity = 1.f, } { + const ESM4::World* world = MWBase::Environment::get().getESMStore()->get().search(mParent); if (isExterior()) { - auto& worldStore = MWBase::Environment::get().getESMStore()->get(); - const ESM4::World* cellWorld = worldStore.find(mParent); - mWaterHeight = cellWorld->mWaterLevel; + if (world == nullptr) + throw std::runtime_error( + "Cell " + cell.mId.toDebugString() + " parent world " + mParent.toDebugString() + " is not found"); + mWaterHeight = world->mWaterLevel; } + mDescription = getCellDescription(cell, world); } Cell::Cell(const ESM::Cell& cell)