Initial commit.
This commit is contained in:
85
src/MultilevelAStarEx.h
Normal file
85
src/MultilevelAStarEx.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#ifndef MultilevelAStarEx_H
|
||||
#define MultilevelAStarEx_H
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
#include <godot_cpp/classes/ref.hpp>
|
||||
#include <godot_cpp/variant/array.hpp>
|
||||
#include <godot_cpp/variant/vector2i.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Node {
|
||||
friend class MultilevelAStarEx;
|
||||
|
||||
public:
|
||||
enum NodeState
|
||||
{
|
||||
UNUSED, OPEN, CLOSED
|
||||
};
|
||||
|
||||
private:
|
||||
NodeState state;
|
||||
int x, y;
|
||||
|
||||
Node* parent;
|
||||
int distanceFromStart;
|
||||
int distanceToEnd;
|
||||
|
||||
int distanceToEndForClosest;
|
||||
|
||||
Node(int x, int y);
|
||||
void init(Node* parent, int distanceFromStart, const Vector2i &end);
|
||||
int total_cost() const;
|
||||
|
||||
public:
|
||||
Node();
|
||||
};
|
||||
|
||||
class MultilevelAStarEx : public RefCounted
|
||||
{
|
||||
GDCLASS(MultilevelAStarEx, RefCounted)
|
||||
|
||||
public:
|
||||
enum TerrainType
|
||||
{
|
||||
STAIRS = -1,
|
||||
BLOCKED = 0,
|
||||
GROUND = 1,
|
||||
};
|
||||
|
||||
private:
|
||||
bool _init;
|
||||
std::vector<TerrainType> _terrain;
|
||||
std::vector<bool> _units;
|
||||
std::vector<Node> _nodes;
|
||||
|
||||
Rect2i _region;
|
||||
Vector2i _trans;
|
||||
int _width, _height;
|
||||
|
||||
bool can_move(const Node* current, int x, int y) const;
|
||||
TypedArray<Vector2i> generate_path(const Node* current) const;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
MultilevelAStarEx();
|
||||
~MultilevelAStarEx();
|
||||
|
||||
void init(const Rect2i ®ion);
|
||||
Rect2i get_region() const;
|
||||
void set_terrain(const Vector2i &cell, TerrainType type);
|
||||
TerrainType get_terrain(const Vector2i &cell) const;
|
||||
void set_unit(const Vector2i &cell, bool blocked);
|
||||
bool get_unit(const Vector2i &cell) const;
|
||||
Variant find_path(const Vector2i &from, const Vector2i &to, const bool return_closest);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
VARIANT_ENUM_CAST(MultilevelAStarEx::TerrainType);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user