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

Method updatePathPreview

game/ui/tileview/battleview.cpp:2279–2372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2277}
2278
2279void BattleView::updatePathPreview()
2280{
2281 auto target = selectedTilePosition;
2282 if (!lastSelectedUnit)
2283 {
2284 LogError("Trying to update path preview with no unit selected!?");
2285 return;
2286 }
2287
2288 if (!lastSelectedUnit->canMove())
2289 return;
2290 auto &map = lastSelectedUnit->tileObject->map;
2291 auto to = map.getTile(target);
2292
2293 // Standard check for passability
2294 while (true)
2295 {
2296 auto u = to->getUnitIfPresent(true, true, false, nullptr, false, true);
2297 auto unit = u ? u->getUnit() : nullptr;
2298 if (unit && unit->owner != battle.currentPlayer &&
2299 battle.visibleUnits[battle.currentPlayer].find({&*state, unit->id}) ==
2300 battle.visibleUnits[battle.currentPlayer].end())
2301 {
2302 unit = nullptr;
2303 }
2304 if (!to->getPassable(lastSelectedUnit->isLarge(),
2305 lastSelectedUnit->agent->type->bodyType->maxHeight) ||
2306 unit)
2307 {
2308 previewedPathCost = static_cast<int>(PreviewedPathCostSpecial::UNREACHABLE);
2309 return;
2310 }
2311 if (lastSelectedUnit->canFly() || to->getCanStand(lastSelectedUnit->isLarge()))
2312 {
2313 break;
2314 }
2315 target.z--;
2316 if (target.z == -1)
2317 {
2318 LogError("Solid ground missing on level 0? Reached %d %d %d", target.x, target.y,
2319 target.z);
2320 return;
2321 }
2322 to = map.getTile(target);
2323 }
2324
2325 // Cost to move is 1.5x if prone and 0.5x if running, to keep things in integer
2326 // we use a value that is then divided by 2
2327 float cost = 0.0f;
2328 int cost_multiplier_x_2 = 2;
2329 if (lastSelectedUnit->agent->canRun() &&
2330 lastSelectedUnit->movement_mode == MovementMode::Running)
2331 {
2332 cost_multiplier_x_2 = 1;
2333 }
2334 if (lastSelectedUnit->movement_mode == MovementMode::Prone)
2335 {
2336 cost_multiplier_x_2 = 3;

Callers

nothing calls this directly

Calls 12

canMoveMethod · 0.80
getTileMethod · 0.80
getUnitIfPresentMethod · 0.80
getUnitMethod · 0.80
endMethod · 0.80
getPassableMethod · 0.80
isLargeMethod · 0.80
canFlyMethod · 0.80
getCanStandMethod · 0.80
emptyMethod · 0.80
canRunMethod · 0.45
findShortestPathMethod · 0.45

Tested by

no test coverage detected