diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index e06c4fd07c..cf94f24f88 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -2,8 +2,12 @@ #include #include +#include #include +#include "../mwbase/environment.hpp" +#include "esmstore.hpp" + namespace MWWorld { Cell::Cell(const ESM4::Cell& cell) @@ -26,6 +30,12 @@ namespace MWWorld .mFogDensity = 1.f,} ,mWaterHeight(cell.mWaterHeight) { + if (isExterior() && mWaterHeight == ESM4::Cell::sInvalidWaterLevel) + { + auto& worldStore = MWBase::Environment::get().getESMStore()->get(); + const ESM4::World* cellWorld = worldStore.find(mParent); + mWaterHeight = cellWorld->mWaterLevel; + } } Cell::Cell(const ESM::Cell& cell) @@ -48,6 +58,8 @@ namespace MWWorld } ,mWaterHeight(cell.mWater) { + if (isExterior()) + mWaterHeight = -1.f; } std::string Cell::getDescription() const diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 2c5ab8d3ea..f000af01e5 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -664,7 +664,7 @@ namespace MWWorld float CellStore::getWaterLevel() const { if (isExterior()) - return -1; + return getCell()->getWaterHeight(); return mWaterLevel; } diff --git a/components/esm4/loadcell.cpp b/components/esm4/loadcell.cpp index 22d9a1035d..a9d8db0003 100644 --- a/components/esm4/loadcell.cpp +++ b/components/esm4/loadcell.cpp @@ -33,6 +33,7 @@ #include #include // FLT_MAX for gcc #include // FIXME: debug only +#include #include #include "grouptype.hpp" @@ -41,6 +42,8 @@ #include +float ESM4::Cell::sInvalidWaterLevel = std::numeric_limits::min(); + // TODO: Try loading only EDID and XCLC (along with mFormId, mFlags and mParent) // // But, for external cells we may be scanning the whole record since we don't know if there is @@ -55,7 +58,7 @@ void ESM4::Cell::load(ESM4::Reader& reader) mId = ESM::RefId::formIdRefId(mFormId); mFlags = reader.hdr().record.flags; mParent = ESM::RefId::formIdRefId(reader.currWorld()); - + mWaterHeight = sInvalidWaterLevel; reader.clearCellGrid(); // clear until XCLC FIXME: somehow do this automatically? // Sometimes cell 0,0 does not have an XCLC sub record (e.g. ToddLand 000009BF) @@ -237,7 +240,8 @@ void ESM4::Cell::load(ESM4::Reader& reader) throw std::runtime_error("ESM4::CELL::load - Unknown subrecord " + ESM::printName(subHdr.typeId)); } } - + if (mWaterHeight > 1e8) // A Bit of a hack for skyrim, there is a value for the cell but it is all wrong. + mWaterHeight = sInvalidWaterLevel; mReaderContext = reader.getContext(); } diff --git a/components/esm4/loadcell.hpp b/components/esm4/loadcell.hpp index 97abb88751..5fd32a598d 100644 --- a/components/esm4/loadcell.hpp +++ b/components/esm4/loadcell.hpp @@ -107,6 +107,8 @@ namespace ESM4 int getGridX() const { return mX; } int getGridY() const { return mY; } bool isExterior() const { return !(mCellFlags & CELL_Interior); } + + static float sInvalidWaterLevel; }; }