Merge branch 'fix_esm4_ai' into 'master'

Fix AI in ESM4 cells

See merge request OpenMW/openmw!3338
This commit is contained in:
jvoisin 2023-08-14 22:00:24 +00:00
commit 4cf80cdac2
12 changed files with 50 additions and 35 deletions

View file

@ -133,7 +133,7 @@ namespace DetourNavigator
void NavigatorImpl::addPathgrid(const ESM::Cell& cell, const ESM::Pathgrid& pathgrid)
{
Misc::CoordinateConverter converter(&cell);
const Misc::CoordinateConverter converter = Misc::makeCoordinateConverter(cell);
for (const auto& edge : pathgrid.mEdges)
{
const auto src = Misc::Convert::makeOsgVec3f(converter.toWorldPoint(pathgrid.mPoints[edge.mV0]));

View file

@ -5,11 +5,14 @@
#include <string>
#include <vector>
#include "cellref.hpp"
#include "components/esm/defs.hpp"
#include "components/esm/esmcommon.hpp"
#include "components/esm/refid.hpp"
#include <components/misc/constants.hpp>
#include "cellref.hpp"
namespace MWWorld
{
class ESMStore;
@ -70,6 +73,8 @@ namespace ESM
constexpr static RecNameInts sRecordId = REC_CELL;
static constexpr int sSize = Constants::CellSizeInUnits;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Cell"; }

View file

@ -35,6 +35,7 @@
#include <components/esm/refid.hpp>
#include <components/esm/util.hpp>
#include <components/esm4/reader.hpp>
#include <components/misc/constants.hpp>
#include "lighting.hpp"
@ -62,6 +63,8 @@ namespace ESM4
// The cells need to be organised under world spaces.
struct Cell
{
static constexpr int sSize = Constants::ESM4CellSizeInUnits;
ESM::RefId mId; // from the header
std::uint32_t mFlags = 0; // from the header, see enum type RecordFlag for details

View file

@ -3,9 +3,9 @@
#include <components/esm/esmbridge.hpp>
#include <components/esm3/loadcell.hpp>
#include <components/esm3/loadland.hpp>
#include <components/esm3/loadpgrd.hpp>
#include <components/esm4/loadcell.hpp>
#include <components/misc/constants.hpp>
namespace Misc
{
@ -13,21 +13,9 @@ namespace Misc
class CoordinateConverter
{
public:
CoordinateConverter(bool exterior, int cellX, int cellY)
: mCellX(exterior ? cellX * ESM::Land::REAL_SIZE : 0)
, mCellY(exterior ? cellY * ESM::Land::REAL_SIZE : 0)
{
}
explicit CoordinateConverter(const ESM::CellVariant& cell)
: CoordinateConverter(cell.isEsm4() ? cell.getEsm4().isExterior() : cell.getEsm3().isExterior(),
cell.isEsm4() ? cell.getEsm4().getGridX() : cell.getEsm3().getGridX(),
cell.isEsm4() ? cell.getEsm4().getGridY() : cell.getEsm3().getGridY())
{
}
explicit CoordinateConverter(const ESM::Cell* cell)
: CoordinateConverter(cell->isExterior(), cell->getGridX(), cell->getGridY())
explicit CoordinateConverter(int cellX, int cellY)
: mCellX(cellX)
, mCellY(cellY)
{
}
@ -81,6 +69,29 @@ namespace Misc
int mCellX;
int mCellY;
};
template <class T>
CoordinateConverter makeCoordinateConverterImpl(const T& cell)
{
if (cell.isExterior())
return CoordinateConverter(cell.sSize * cell.getGridX(), cell.sSize * cell.getGridY());
return CoordinateConverter(0, 0);
}
inline CoordinateConverter makeCoordinateConverter(const ESM::Cell& cell)
{
return makeCoordinateConverterImpl(cell);
}
inline CoordinateConverter makeCoordinateConverter(const ESM4::Cell& cell)
{
return makeCoordinateConverterImpl(cell);
}
inline CoordinateConverter makeCoordinateConverter(const ESM::CellVariant& cell)
{
return visit([](const auto& v) { return makeCoordinateConverterImpl(v); }, cell);
}
}
#endif