| 761 | } |
| 762 | |
| 763 | int BattleUnit::getAttackCost(GameState &state, AEquipment &item, Vec3<int> tile) |
| 764 | { |
| 765 | std::ignore = state; |
| 766 | int totalCost = 0; |
| 767 | |
| 768 | // Step 1: Turning cost |
| 769 | auto targetFacing = BattleUnitMission::getFacing(*this, tile); |
| 770 | bool turning = goalFacing != targetFacing; |
| 771 | if (turning) |
| 772 | { |
| 773 | int curFacing = facing_dir_map.at(goalFacing); |
| 774 | int tarFacing = facing_dir_map.at(targetFacing); |
| 775 | if (tarFacing > 7) |
| 776 | tarFacing -= 8; |
| 777 | |
| 778 | int clockwiseDistance = tarFacing - curFacing; |
| 779 | if (clockwiseDistance < 0) |
| 780 | { |
| 781 | clockwiseDistance += 8; |
| 782 | } |
| 783 | int counterClockwiseDistance = curFacing - tarFacing; |
| 784 | if (counterClockwiseDistance < 0) |
| 785 | { |
| 786 | counterClockwiseDistance += 8; |
| 787 | } |
| 788 | totalCost = std::min(clockwiseDistance, counterClockwiseDistance) * getTurnCost(); |
| 789 | } |
| 790 | |
| 791 | // Step 2: Body state change cost |
| 792 | if (turning) |
| 793 | { |
| 794 | if (target_body_state == BodyState::Prone) |
| 795 | { |
| 796 | totalCost += getBodyStateChangeCost(BodyState::Prone, BodyState::Kneeling); |
| 797 | } |
| 798 | if (movement_mode == MovementMode::Prone && kneeling_mode == KneelingMode::None) |
| 799 | { |
| 800 | totalCost += getBodyStateChangeCost(BodyState::Kneeling, BodyState::Prone); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | // Step 3: Actual cost to fire the weapon |
| 805 | totalCost += item.getFireCost(fire_aiming_mode, initialTU); |
| 806 | |
| 807 | return totalCost; |
| 808 | } |
| 809 | |
| 810 | void BattleUnit::setFocus(GameState &state, StateRef<BattleUnit> unit) |
| 811 | { |
no test coverage detected