MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / FindPath

Method FindPath

engine/Poseidon/Game/OperMap.cpp:1444–2117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1442#endif
1443
1444bool OperMap::FindPath(AIUnit* unit, int dir, int xs, int zs, int xe, int ze, bool locks)
1445{
1446#if LOG_MAPS >= 2 || LOG_PROBL
1447 int xMin = LandRangeMask;
1448 int xMax = 0;
1449 int zMin = LandRangeMask;
1450 int zMax = 0;
1451 for (int i = 0; i < _fields.Size(); i++)
1452 {
1453 OperField* fld = _fields[i];
1454 if (fld->_x < xMin)
1455 xMin = fld->_x;
1456 if (fld->_x > xMax)
1457 xMax = fld->_x;
1458 if (fld->_z < zMin)
1459 zMin = fld->_z;
1460 if (fld->_z > zMax)
1461 zMax = fld->_z;
1462 }
1463#endif
1464
1465 _alternateGoal = false;
1466
1467 // scan for min,max,avg cost and do some arithmetics with results
1468 float maxCost = 0, minCost = GET_UNACCESSIBLE, avgCost = 0;
1469 int cntCost = 0;
1470
1471 int n = _fields.Size();
1472 for (int i = 0; i < n; i++)
1473 {
1474 OperField* fld = _fields[i];
1475 float cost = fld->HeurCost();
1476 if (cost < GET_UNACCESSIBLE)
1477 {
1478 saturateMax(maxCost, cost);
1479 saturateMin(minCost, cost);
1480 avgCost += cost;
1481 cntCost++;
1482 }
1483 }
1484 avgCost /= cntCost;
1485
1486 float heurCost;
1487 switch (unit->GetIter())
1488 {
1489 case 0:
1490 heurCost = avgCost * 0.8 + minCost * 0.2;
1491 break;
1492 case 1:
1493 heurCost = maxCost * 0.4 + avgCost * 0.6;
1494 break;
1495 case 2:
1496 default:
1497 heurCost = maxCost;
1498 break;
1499 }
1500
1501 EntityAI* veh = unit->GetVehicle();

Callers

nothing calls this directly

Calls 15

saturateMaxFunction · 0.85
saturateMinFunction · 0.85
WaitForCloseFunction · 0.85
OperHeuristicFunction · 0.85
absFunction · 0.85
sqrtFunction · 0.85
HeurCostMethod · 0.80
GetIterMethod · 0.80
IsSoldierMethod · 0.80
IsAttachedMethod · 0.80
GetBestNodeMethod · 0.80
SearchIDMethod · 0.80

Tested by

no test coverage detected