| 2372 | } |
| 2373 | |
| 2374 | void BattleView::updateAttackCost() |
| 2375 | { |
| 2376 | auto target = selectedTilePosition; |
| 2377 | if (!lastSelectedUnit) |
| 2378 | { |
| 2379 | LogError("Trying to update path attack cost with no unit selected!?"); |
| 2380 | return; |
| 2381 | } |
| 2382 | WeaponStatus status; |
| 2383 | switch (selectionState) |
| 2384 | { |
| 2385 | case BattleSelectionState::FireLeft: |
| 2386 | status = WeaponStatus::FiringLeftHand; |
| 2387 | break; |
| 2388 | case BattleSelectionState::FireRight: |
| 2389 | status = WeaponStatus::FiringRightHand; |
| 2390 | break; |
| 2391 | case BattleSelectionState::Normal: |
| 2392 | case BattleSelectionState::NormalAlt: |
| 2393 | case BattleSelectionState::FireAny: |
| 2394 | status = WeaponStatus::FiringBothHands; |
| 2395 | break; |
| 2396 | default: |
| 2397 | status = WeaponStatus::NotFiring; |
| 2398 | break; |
| 2399 | } |
| 2400 | if (status == WeaponStatus::FiringBothHands) |
| 2401 | { |
| 2402 | // Right hand has priority |
| 2403 | auto rhItem = lastSelectedUnit->agent->getFirstItemInSlot(EquipmentSlotType::RightHand); |
| 2404 | if (rhItem && rhItem->canFire(*state)) |
| 2405 | { |
| 2406 | status = WeaponStatus::FiringRightHand; |
| 2407 | } |
| 2408 | else |
| 2409 | { |
| 2410 | // We don't care what's in the left hand, |
| 2411 | // we will just cancel firing in update() if there's nothing to fire |
| 2412 | status = WeaponStatus::FiringLeftHand; |
| 2413 | } |
| 2414 | } |
| 2415 | auto weapon = (status == WeaponStatus::FiringRightHand) |
| 2416 | ? lastSelectedUnit->agent->getFirstItemInSlot(EquipmentSlotType::RightHand) |
| 2417 | : lastSelectedUnit->agent->getFirstItemInSlot(EquipmentSlotType::LeftHand); |
| 2418 | if (!weapon) |
| 2419 | { |
| 2420 | calculatedAttackCost = static_cast<int>(CalculatedAttackCostSpecial::NO_WEAPON); |
| 2421 | } |
| 2422 | else if (!weapon->canFire(*state, target)) |
| 2423 | { |
| 2424 | calculatedAttackCost = |
| 2425 | static_cast<int>(weapon->type->launcher ? CalculatedAttackCostSpecial::NO_ARC |
| 2426 | : CalculatedAttackCostSpecial::OUT_OF_RANGE); |
| 2427 | } |
| 2428 | else |
| 2429 | { |
| 2430 | calculatedAttackCost = |
| 2431 | lastSelectedUnit->getAttackCost(*state, *weapon, selectedTilePosition); |
nothing calls this directly
no test coverage detected