| 2690 | } |
| 2691 | |
| 2692 | void BattleView::orderDrop(bool right) |
| 2693 | { |
| 2694 | if (battle.battleViewSelectedUnits.empty()) |
| 2695 | { |
| 2696 | return; |
| 2697 | } |
| 2698 | auto unit = battle.battleViewSelectedUnits.front(); |
| 2699 | |
| 2700 | if (!unit->agent->type->inventory) |
| 2701 | { |
| 2702 | return; |
| 2703 | } |
| 2704 | |
| 2705 | auto item = unit->agent->getFirstItemInSlot(right ? EquipmentSlotType::RightHand |
| 2706 | : EquipmentSlotType::LeftHand); |
| 2707 | if (item) // Drop item |
| 2708 | { |
| 2709 | // Special case, just add mission in front of anything and start it, no need to clear orders |
| 2710 | unit->addMission(*state, BattleUnitMission::dropItem(*unit, item)); |
| 2711 | LogWarning("BattleUnit \"%s\" dropping item in %s hand", unit->agent->name, |
| 2712 | right ? "right" : "left"); |
| 2713 | } |
| 2714 | else // Try to pick something up |
| 2715 | { |
| 2716 | auto items = unit->tileObject->getOwningTile()->getItems(); |
| 2717 | if (items.empty()) |
| 2718 | { |
| 2719 | return; |
| 2720 | } |
| 2721 | if (!unit->spendTU(*state, unit->getPickupCost())) |
| 2722 | { |
| 2723 | return; |
| 2724 | } |
| 2725 | auto item = items.front(); |
| 2726 | unit->agent->addEquipment( |
| 2727 | *state, item->item, right ? EquipmentSlotType::RightHand : EquipmentSlotType::LeftHand); |
| 2728 | item->die(*state, false); |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | void BattleView::orderSelect(StateRef<BattleUnit> u, bool inverse, bool additive) |
| 2733 | { |
nothing calls this directly
no test coverage detected