mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
limiting pathfinding for units to their types of cells
This commit is contained in:
@@ -2,7 +2,7 @@ numUnits = 4
|
||||
|
||||
UnitClass = {VESSEL = 0, ENGINEER = 1, SAMPLE_STRUCTURE = 2};
|
||||
|
||||
UnitType = {UNDERWATER = 0, SEA_LEVEL = 1, LAND = 2, AIR = 3};
|
||||
UnitType = {UNDERWATER = 0, SEA_LEVEL = 1, HOVER = 2, LAND = 3, AIR = 4};
|
||||
|
||||
unitClass = {
|
||||
UnitClass.VESSEL, UnitClass.VESSEL,
|
||||
@@ -10,8 +10,8 @@ unitClass = {
|
||||
};
|
||||
|
||||
unitType = {
|
||||
UnitType.SEA_LEVEL, UnitType.UNDERWATER,
|
||||
UnitType.LAND, UnitType.LAND
|
||||
UnitType.HOVER, UnitType.SEA_LEVEL,
|
||||
UnitType.LAND, UnitType.HOVER
|
||||
}
|
||||
|
||||
isVehicle = {
|
||||
|
||||
+8
-3
@@ -1,7 +1,7 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "pathfinder.h"
|
||||
#include "unit.h"
|
||||
|
||||
namespace battleship{
|
||||
using namespace std;
|
||||
@@ -19,7 +19,7 @@ namespace battleship{
|
||||
Pathfinder::Pathfinder(){
|
||||
}
|
||||
|
||||
vector<int> Pathfinder::findPath(vector<Map::Cell> &cells, int source, int dest){
|
||||
vector<int> Pathfinder::findPath(vector<Map::Cell> &cells, int source, int dest, int unitType){
|
||||
int size = cells.size();
|
||||
u32 distances[size];
|
||||
vector<int> paths[size];
|
||||
@@ -52,8 +52,13 @@ namespace battleship{
|
||||
|
||||
for(int i = 0; i < size; i++){
|
||||
bool isChecked = find(checkedNodes.begin(), checkedNodes.end(), i) != checkedNodes.end();
|
||||
bool canMoveToStrichCell = true;
|
||||
bool ship = ((UnitType)unitType == UnitType::UNDERWATER || (UnitType)unitType == UnitType::SEA_LEVEL);
|
||||
|
||||
if(!isChecked && (distances[vertStrich] + cells[vertStrich].getEdgeWeight(i) < distances[i])){
|
||||
if((ship && cells[vertStrich].type != Map::Cell::WATER) || ((UnitType)unitType == UnitType::LAND && cells[vertStrich].type != Map::Cell::LAND))
|
||||
canMoveToStrichCell = false;
|
||||
|
||||
if(!isChecked && (canMoveToStrichCell && distances[vertStrich] + cells[vertStrich].getEdgeWeight(i) < distances[i])){
|
||||
distances[i] = distances[vertStrich] + cells[vertStrich].getEdgeWeight(i);
|
||||
paths[i] = paths[vertStrich];
|
||||
paths[i].push_back(i);
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace battleship{
|
||||
class Pathfinder{
|
||||
public:
|
||||
static Pathfinder* getSingleton();
|
||||
std::vector<int> findPath(std::vector<Map::Cell>&, int, int);
|
||||
std::vector<int> findPath(std::vector<Map::Cell>&, int, int, int = -1);
|
||||
inline vb01::u32 getImpassibleNodeVal(){return impassibleNodeVal;}
|
||||
inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;}
|
||||
private:
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace battleship{
|
||||
enum class MoveDir {LEFT, UP, FORW};
|
||||
enum class Corner {FRONT_LEFT, FRONT_RIGHT, REAR_LEFT, REAR_RIGHT};
|
||||
enum class UnitClass {VESSEL, ENGINEER, SAMPLE_BUILDING};
|
||||
enum class UnitType {UNDERWATER, SEA_LEVEL, LAND, AIR};
|
||||
enum class UnitType {UNDERWATER, SEA_LEVEL, HOVER, LAND, AIR, NONE = -1};
|
||||
|
||||
class Unit {
|
||||
public:
|
||||
|
||||
+8
-1
@@ -153,8 +153,15 @@ namespace battleship{
|
||||
int source = map->getCellId(pos);
|
||||
int dest = map->getCellId(order.targets[0].pos);
|
||||
|
||||
if(type == UnitType::UNDERWATER || type == UnitType::SEA_LEVEL || type == UnitType::LAND){
|
||||
Map::Cell::Type cellType = (type == UnitType::LAND ? Map::Cell::LAND : Map::Cell::WATER);
|
||||
bool canReach = (cells[source].type == cellType && cells[dest].type == cellType);
|
||||
|
||||
if(!canReach) return;
|
||||
}
|
||||
|
||||
Pathfinder *pathfinder = Pathfinder::getSingleton();
|
||||
vector<int> path = pathfinder->findPath(cells, source, dest);
|
||||
vector<int> path = pathfinder->findPath(cells, source, dest, (int)type);
|
||||
Node *rootNode = Root::getSingleton()->getRootNode();
|
||||
|
||||
for(int p : path){
|
||||
|
||||
Reference in New Issue
Block a user