| 2277 | } |
| 2278 | |
| 2279 | void 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; |
nothing calls this directly
no test coverage detected