Merged unit info into Node.

This commit is contained in:
2024-06-06 02:31:02 +02:00
parent a59492b229
commit 4918c0319a
2 changed files with 10 additions and 10 deletions

View File

@@ -7,7 +7,6 @@
#include <set>
#define TERRAIN(x, y) (_terrain[(x) + (y) * _width])
#define UNITS(x, y) (_units[(x) + (y) * _width])
#define NODES(x, y) (_nodes[(x) + (y) * _width])
using namespace godot;
@@ -15,14 +14,15 @@ using namespace godot;
static const int STRAIGHT_DISTANCE = 10;
static const int DIAGONAL_DISTANCE = 14;
Node::Node()
Node::Node() { }
Node::Node(int x, int y)
{
this->hasUnit = false;
this->openPass = 0;
this->closedPass = 0;
}
Node::Node(int x, int y) : Node()
{
this->x = x;
this->y = y;
}
@@ -153,7 +153,6 @@ void MultilevelAStarEx::init(const Rect2i &region)
_trans = region.get_position();
_terrain.resize(_width * _height, BLOCKED);
_units.resize(_width * _height, false);
_nodes.resize(_width * _height);
std::vector<Node>::iterator iter = _nodes.begin();
@@ -199,7 +198,7 @@ void MultilevelAStarEx::set_unit(const Vector2i &cell, bool blocked)
DEV_ASSERT(_region.has_point(cell));
Vector2i cell2 = cell - _trans;
UNITS(cell2.x, cell2.y) = blocked;
NODES(cell2.x, cell2.y).hasUnit = blocked;
}
bool MultilevelAStarEx::get_unit(const Vector2i &cell) const
@@ -208,12 +207,12 @@ bool MultilevelAStarEx::get_unit(const Vector2i &cell) const
DEV_ASSERT(_region.has_point(cell));
Vector2i cell2 = cell - _trans;
return UNITS(cell2.x, cell2.y);
return NODES(cell2.x, cell2.y).hasUnit;
}
bool MultilevelAStarEx::can_move(const Node *current, int x, int y) const
{
if (UNITS(x, y)) return false;
if (NODES(x, y).hasUnit) return false;
TerrainType tc = TERRAIN(current->x, current->y);
TerrainType td = TERRAIN(x, y);

View File

@@ -20,6 +20,8 @@ public:
};
private:
bool hasUnit;
int openPass, closedPass;
int x, y;
@@ -57,7 +59,6 @@ private:
bool _init;
int _pass;
std::vector<TerrainType> _terrain;
std::vector<bool> _units;
std::vector<Node> _nodes;
Rect2i _region;