1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-18 03:21:27 +02:00

Refactoring

This commit is contained in:
nordsoft 2022-08-27 21:25:24 +04:00
parent 035857c190
commit b0526ca51b
4 changed files with 8 additions and 10 deletions

View File

@ -88,11 +88,9 @@ bool Area::connected() const
std::list<Area> connectedAreas(const Area & area, bool disableDiagonalConnections)
{
auto allDirs = int3::getDirs();
std::vector<int3> dirs;
std::vector<int3> dirs(allDirs.begin(), allDirs.end());
if(disableDiagonalConnections)
dirs.insert(dirs.begin(), allDirs.begin(), allDirs.begin() + 4);
else
dirs.insert(dirs.begin(), allDirs.begin(), allDirs.end());
dirs.assign(rmg::dirs4.begin(), rmg::dirs4.end());
std::list<Area> result;
Tileset connected = area.getTiles();

View File

@ -15,6 +15,9 @@
namespace rmg
{
static const std::array<int3, 4> dirs4 = { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0) };
static const std::array<int3, 4> dirsDiagonal= { int3(1,1,0),int3(1,-1,0),int3(-1,1,0),int3(-1,-1,0) };
using Tileset = std::set<int3>;
using DistanceMap = std::map<int3, int>;
void toAbsolute(Tileset & tiles, const int3 & position);

View File

@ -30,9 +30,6 @@
#include "Functions.h"
#include "CMapGenerator.h"
static const int3 dirs4[] = {int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0)};
static const int3 dirsDiagonal[] = { int3(1,1,0),int3(1,-1,0),int3(-1,1,0),int3(-1,-1,0) };
RmgMap::RmgMap(const CMapGenOptions& mapGenOptions) :
mapGenOptions(mapGenOptions), zonesTotal(0)
{
@ -54,7 +51,7 @@ void RmgMap::foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> f
void RmgMap::foreachDirectNeighbour(const int3& pos, std::function<void(int3& pos)> foo)
{
for(const int3 &dir : dirs4)
for(const int3 &dir : rmg::dirs4)
{
int3 n = pos + dir;
if(mapInstance->isInTheMap(n))
@ -64,7 +61,7 @@ void RmgMap::foreachDirectNeighbour(const int3& pos, std::function<void(int3& po
void RmgMap::foreachDiagonalNeighbour(const int3& pos, std::function<void(int3& pos)> foo)
{
for (const int3 &dir : dirsDiagonal)
for (const int3 &dir : rmg::dirsDiagonal)
{
int3 n = pos + dir;
if (mapInstance->isInTheMap(n))

View File

@ -137,7 +137,7 @@ Path Path::search(const Tileset & dst, bool straight, std::function<float(const
auto dirs = int3::getDirs();
std::vector<int3> neighbors(dirs.begin(), dirs.end());
if(straight)
neighbors = { { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0) } };
neighbors.assign(rmg::dirs4.begin(), rmg::dirs4.end());
for(auto & i : neighbors)
{
computeTileScore(currentNode + i);