MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / findPath

Method findPath

game/state/tilemap/pathfinding.cpp:1473–1501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1471}
1472
1473std::list<Vec3<int>> RoadSegment::findPath(Vec3<int> origin, Vec3<int> destination) const
1474{
1475 // Expecting to contain both points
1476 int originIndex = -1;
1477 int destinationIndex = -1;
1478 for (int i = 0; i < tilePosition.size(); i++)
1479 {
1480 if (tilePosition.at(i) == origin)
1481 {
1482 originIndex = i;
1483 }
1484 if (tilePosition.at(i) == destination)
1485 {
1486 destinationIndex = i;
1487 }
1488 }
1489 std::list<Vec3<int>> path;
1490 int diff = destinationIndex > originIndex ? 1 : -1;
1491 for (int i = originIndex; i != destinationIndex + diff; i += diff)
1492 {
1493 if (!tileIntact.at(i))
1494 {
1495 return path;
1496 }
1497 path.push_back(tilePosition.at(i));
1498 }
1499
1500 return path;
1501}
1502
1503std::list<Vec3<int>> RoadSegment::findClosestPath(Vec3<int> origin, Vec3<int> destination) const
1504{

Callers 1

findShortestPathMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected