diff --git a/src/landscape.cpp b/src/landscape.cpp index 9065844904..d9bc4bc659 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1223,13 +1223,13 @@ static void River_GetNeighbours(AyStar *aystar, PathNode *current) { TileIndex tile = current->GetTile(); - aystar->num_neighbours = 0; + aystar->neighbours.clear(); for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) { TileIndex t2 = tile + TileOffsByDiagDir(d); if (IsValidTile(t2) && FlowsDown(tile, t2)) { - aystar->neighbours[aystar->num_neighbours].m_tile = t2; - aystar->neighbours[aystar->num_neighbours].m_td = INVALID_TRACKDIR; - aystar->num_neighbours++; + auto &neighbour = aystar->neighbours.emplace_back(); + neighbour.m_tile = t2; + neighbour.m_td = INVALID_TRACKDIR; } } } diff --git a/src/pathfinder/aystar.cpp b/src/pathfinder/aystar.cpp index 711f7c0467..41ffc84668 100644 --- a/src/pathfinder/aystar.cpp +++ b/src/pathfinder/aystar.cpp @@ -111,9 +111,9 @@ int AyStar::Loop() this->GetNeighbours(this, current); /* Go through all neighbours */ - for (int i = 0; i < this->num_neighbours; i++) { + for (auto &neighbour : this->neighbours) { /* Check and add them to the OpenList if needed */ - this->CheckTile(&this->neighbours[i], current); + this->CheckTile(&neighbour, current); } if (this->max_search_nodes != 0 && this->nodes.ClosedCount() >= this->max_search_nodes) { diff --git a/src/pathfinder/aystar.h b/src/pathfinder/aystar.h index d375a052a5..8fa8490644 100644 --- a/src/pathfinder/aystar.h +++ b/src/pathfinder/aystar.h @@ -125,10 +125,8 @@ struct AyStar { int max_path_cost; ///< If the g-value goes over this number, it stops searching, 0 = infinite. int max_search_nodes = AYSTAR_DEF_MAX_SEARCH_NODES; ///< The maximum number of nodes that will be expanded, 0 = infinite. - /* These should be filled with the neighbours of a tile by - * GetNeighbours */ - AyStarNode neighbours[12]; - uint8_t num_neighbours; + /* These should be filled with the neighbours of a tile by GetNeighbours */ + std::vector neighbours; /* These will contain the methods for manipulating the AyStar. Only * Main() should be called externally */