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

Method orderDrop

game/ui/tileview/battleview.cpp:2692–2730  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2690}
2691
2692void 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
2732void BattleView::orderSelect(StateRef<BattleUnit> u, bool inverse, bool additive)
2733{

Callers

nothing calls this directly

Calls 9

emptyMethod · 0.80
getFirstItemInSlotMethod · 0.80
getItemsMethod · 0.80
getOwningTileMethod · 0.80
spendTUMethod · 0.80
getPickupCostMethod · 0.80
addMissionMethod · 0.45
addEquipmentMethod · 0.45
dieMethod · 0.45

Tested by

no test coverage detected