From c0d53a255797374b75df98050af11feb0d87e7e6 Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Wed, 31 Aug 2016 11:02:04 -0400 Subject: [PATCH] Fix CellRefs being teleported from interior to exterior cells. --- apps/opencs/model/world/cellcoordinates.cpp | 7 ++++++- apps/opencs/model/world/cellcoordinates.hpp | 4 +++- apps/opencs/view/render/object.cpp | 13 ++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/opencs/model/world/cellcoordinates.cpp b/apps/opencs/model/world/cellcoordinates.cpp index 80ec9dc04..abb3bc82e 100644 --- a/apps/opencs/model/world/cellcoordinates.cpp +++ b/apps/opencs/model/world/cellcoordinates.cpp @@ -37,11 +37,16 @@ std::string CSMWorld::CellCoordinates::getId (const std::string& worldspace) con return stream.str(); } +bool CSMWorld::CellCoordinates::isExteriorCell (const std::string& id) +{ + return (!id.empty() && id[0]=='#'); +} + std::pair CSMWorld::CellCoordinates::fromId ( const std::string& id) { // no worldspace for now, needs to be changed for 1.1 - if (!id.empty() && id[0]=='#') + if (isExteriorCell(id)) { int x, y; char ignore; diff --git a/apps/opencs/model/world/cellcoordinates.hpp b/apps/opencs/model/world/cellcoordinates.hpp index 696868d00..9207aede5 100644 --- a/apps/opencs/model/world/cellcoordinates.hpp +++ b/apps/opencs/model/world/cellcoordinates.hpp @@ -32,12 +32,14 @@ namespace CSMWorld std::string getId (const std::string& worldspace) const; ///< Return the ID for the cell at these coordinates. + static bool isExteriorCell (const std::string& id); + /// \return first: CellCoordinates (or 0, 0 if cell does not have coordinates), /// second: is cell paged? /// /// \note The worldspace part of \a id is ignored static std::pair fromId (const std::string& id); - + /// \return cell coordinates such that given world coordinates are in it. static std::pair coordinatesToCellIndex (float x, float y); }; diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index 3a6640c54..eb90e9db3 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -644,13 +644,16 @@ void CSVRender::Object::apply (CSMWorld::CommandMacro& commands) int column = collection.findColumnIndex (static_cast ( CSMWorld::Columns::ColumnId_Cell)); - std::pair cellIndex = collection.getRecord (recordIndex).get().getCellIndex(); + if (CSMWorld::CellCoordinates::isExteriorCell(collection.getRecord (recordIndex).get().mCell)) + { + std::pair cellIndex = collection.getRecord (recordIndex).get().getCellIndex(); - /// \todo figure out worldspace (not important until multiple worldspaces are supported) - std::string cellId = CSMWorld::CellCoordinates (cellIndex).getId (""); + /// \todo figure out worldspace (not important until multiple worldspaces are supported) + std::string cellId = CSMWorld::CellCoordinates (cellIndex).getId (""); - commands.push (new CSMWorld::ModifyCommand (*model, - model->index (recordIndex, column), QString::fromUtf8 (cellId.c_str()))); + commands.push (new CSMWorld::ModifyCommand (*model, + model->index (recordIndex, column), QString::fromUtf8 (cellId.c_str()))); + } } if (mOverrideFlags & Override_Rotation)