@@ -2313,17 +2313,17 @@ int Scene::SetOwnerOfAllDoors(int team, int player) {
2313
2313
}
2314
2314
2315
2315
void Scene::ResetPathFinding () {
2316
- GetPathFinder (Activity::Teams::NoTeam)-> RecalculateAllCosts ();
2316
+ GetPathFinder (Activity::Teams::NoTeam). RecalculateAllCosts ();
2317
2317
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
2318
2318
g_MovableMan.OverrideMaterialDoors (true , team);
2319
- GetPathFinder (static_cast <Activity::Teams>(team))-> RecalculateAllCosts ();
2319
+ GetPathFinder (static_cast <Activity::Teams>(team)). RecalculateAllCosts ();
2320
2320
g_MovableMan.OverrideMaterialDoors (false , team);
2321
2321
}
2322
2322
}
2323
2323
2324
2324
void Scene::BlockUntilAllPathingRequestsComplete () {
2325
2325
for (int team = Activity::Teams::NoTeam; team < Activity::Teams::MaxTeamCount; ++team) {
2326
- while (GetPathFinder (static_cast <Activity::Teams>(team))-> GetCurrentPathingRequests () != 0 ) {};
2326
+ while (GetPathFinder (static_cast <Activity::Teams>(team)). GetCurrentPathingRequests () != 0 ) {};
2327
2327
}
2328
2328
}
2329
2329
@@ -2337,7 +2337,7 @@ void Scene::UpdatePathFinding() {
2337
2337
// TODO: this can indefinitely block updates if pathing requests are made every frame. Figure out a solution for this
2338
2338
// Either force-complete pathing requests occasionally, or delay starting new pathing requests if we've not updated in a while
2339
2339
for (int team = Activity::Teams::NoTeam; team < Activity::Teams::MaxTeamCount; ++team) {
2340
- if (GetPathFinder (static_cast <Activity::Teams>(team))-> GetCurrentPathingRequests () != 0 ) {
2340
+ if (GetPathFinder (static_cast <Activity::Teams>(team)). GetCurrentPathingRequests () != 0 ) {
2341
2341
return ;
2342
2342
};
2343
2343
}
@@ -2349,7 +2349,7 @@ void Scene::UpdatePathFinding() {
2349
2349
}
2350
2350
2351
2351
// Update our shared pathFinder
2352
- std::vector<int > updatedNodes = GetPathFinder (Activity::Teams::NoTeam)-> RecalculateAreaCosts (m_pTerrain->GetUpdatedMaterialAreas (), nodesToUpdate);
2352
+ std::vector<int > updatedNodes = GetPathFinder (Activity::Teams::NoTeam). RecalculateAreaCosts (m_pTerrain->GetUpdatedMaterialAreas (), nodesToUpdate);
2353
2353
if (!updatedNodes.empty ()) {
2354
2354
// Update each team's pathFinder
2355
2355
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
@@ -2360,7 +2360,7 @@ void Scene::UpdatePathFinding() {
2360
2360
// Remove the material representation of all doors of this team so we can navigate through them (they'll open for us).
2361
2361
g_MovableMan.OverrideMaterialDoors (true , team);
2362
2362
2363
- GetPathFinder (static_cast <Activity::Teams>(team))-> UpdateNodeList (updatedNodes);
2363
+ GetPathFinder (static_cast <Activity::Teams>(team)). UpdateNodeList (updatedNodes);
2364
2364
2365
2365
// Place back the material representation of all doors of this team so they are as we found them.
2366
2366
g_MovableMan.OverrideMaterialDoors (false , team);
@@ -2373,23 +2373,14 @@ void Scene::UpdatePathFinding() {
2373
2373
2374
2374
float Scene::CalculatePath (const Vector& start, const Vector& end, std::list<Vector>& pathResult, float digStrength, Activity::Teams team) {
2375
2375
float totalCostResult = -1 ;
2376
+ int result = GetPathFinder (team).CalculatePath (start, end, pathResult, totalCostResult, digStrength);
2376
2377
2377
- if (const std::unique_ptr<PathFinder>& pathFinder = GetPathFinder (team)) {
2378
- int result = pathFinder->CalculatePath (start, end, pathResult, totalCostResult, digStrength);
2379
-
2380
- // It's ok if start and end nodes happen to be the same, the exact pixel locations are added at the front and end of the result regardless
2381
- return (result == micropather::MicroPather::SOLVED || result == micropather::MicroPather::START_END_SAME) ? totalCostResult : -1 ;
2382
- }
2383
-
2384
- return false ;
2378
+ // It's ok if start and end nodes happen to be the same, the exact pixel locations are added at the front and end of the result regardless
2379
+ return (result == micropather::MicroPather::SOLVED || result == micropather::MicroPather::START_END_SAME) ? totalCostResult : -1 ;
2385
2380
}
2386
2381
2387
2382
std::shared_ptr<volatile PathRequest> Scene::CalculatePathAsync (const Vector& start, const Vector& end, float digStrength, Activity::Teams team, PathCompleteCallback callback) {
2388
- if (const std::unique_ptr<PathFinder>& pathFinder = GetPathFinder (team)) {
2389
- return pathFinder->CalculatePathAsync (start, end, digStrength, callback);
2390
- }
2391
-
2392
- return nullptr ;
2383
+ return GetPathFinder (team).CalculatePathAsync (start, end, digStrength, callback);
2393
2384
}
2394
2385
2395
2386
int Scene::GetScenePathSize () const {
@@ -2401,11 +2392,7 @@ std::list<Vector>& Scene::GetScenePath() {
2401
2392
}
2402
2393
2403
2394
bool Scene::PositionsAreTheSamePathNode (const Vector& pos1, const Vector& pos2) const {
2404
- if (const std::unique_ptr<PathFinder>& pathFinder = const_cast <Scene*>(this )->GetPathFinder (Activity::Teams::NoTeam)) {
2405
- return pathFinder->PositionsAreTheSamePathNode (pos1, pos2);
2406
- }
2407
-
2408
- return false ;
2395
+ return const_cast <Scene*>(this )->GetPathFinder (Activity::Teams::NoTeam).PositionsAreTheSamePathNode (pos1, pos2);
2409
2396
}
2410
2397
2411
2398
void Scene::Lock () {
@@ -2447,7 +2434,7 @@ void Scene::Update() {
2447
2434
2448
2435
m_NavigatableAreasUpToDate = true ;
2449
2436
for (int team = Activity::Teams::NoTeam; team < Activity::Teams::MaxTeamCount; ++team) {
2450
- PathFinder& pathFinder = * GetPathFinder (static_cast <Activity::Teams>(team));
2437
+ PathFinder& pathFinder = GetPathFinder (static_cast <Activity::Teams>(team));
2451
2438
2452
2439
pathFinder.MarkAllNodesNavigatable (m_NavigatableAreas.empty ());
2453
2440
@@ -2467,7 +2454,11 @@ void Scene::Update() {
2467
2454
}
2468
2455
}
2469
2456
2470
- std::unique_ptr<PathFinder>& Scene::GetPathFinder (Activity::Teams team) {
2457
+ PathFinder& Scene::GetPathFinder (Activity::Teams team) {
2458
+ if (team < Activity::NoTeam || team >= Activity::MaxTeamCount) {
2459
+ return *m_pPathFinders[0 ]; // Use NoTeam if a mod does something insane like applying an actor to team 6 (yes this actually happens)
2460
+ }
2461
+
2471
2462
// Note - we use + 1 when getting pathfinders by index, because our shared NoTeam pathfinder occupies index 0, and the rest come after that.
2472
- return m_pPathFinders[static_cast <int >(team) + 1 ];
2463
+ return * m_pPathFinders[static_cast <int >(team) + 1 ];
2473
2464
}
0 commit comments