corrected unit removal

dropping the SUPPLY order if there are no extractors
addded optional exact destination pos to shortest paths
This commit is contained in:
devZoGok
2024-01-24 14:54:34 +02:00
parent 1c680aebf2
commit a7718cb9e1
10 changed files with 47 additions and 29 deletions
+6 -1
View File
@@ -227,7 +227,7 @@ namespace battleship{
debugPathPoints.push_back(n);
}
void Vehicle::preparePathpoints(Order &order, Vector3 destPos){
void Vehicle::preparePathpoints(Order &order, Vector3 destPos, bool appendDestPos){
removeAllPathpoints();
Map *map = Map::getSingleton();
@@ -243,12 +243,14 @@ namespace battleship{
Pathfinder *pathfinder = Pathfinder::getSingleton();
int dest = map->getCellId(destPos);
vector<int> path = pathfinder->findPath(cells, source, dest, (int)type);
bool pathTruncated = false;
for(int i = 0; i < path.size(); i++){
if((ship && cells[path[i]].type != Map::Cell::WATER) || (order.type != Order::TYPE::GARRISON && type == UnitType::LAND && cells[path[i]].type != Map::Cell::LAND)){
path = vector<int>(path.begin(), path.begin() + i);
order.targets[0].unit = nullptr;
order.targets[0].pos = cells[path[i - 1]].pos;
pathTruncated = true;
break;
}
else if(order.type == Order::TYPE::GARRISON && type == UnitType::LAND && cells[path[i]].type != Map::Cell::LAND && path.size() - 1 != i)
@@ -257,6 +259,9 @@ namespace battleship{
for(int p : path)
addPathpoint(cells[p].pos);
if(appendDestPos && !pathTruncated)
addPathpoint(destPos);
}
void Vehicle::removePathpoint(int i){