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

Method orderUse

game/ui/tileview/battleview.cpp:2563–2679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2561}
2562
2563void BattleView::orderUse(bool right, bool automatic)
2564{
2565 if (battle.battleViewSelectedUnits.empty())
2566 {
2567 return;
2568 }
2569 auto unit = battle.battleViewSelectedUnits.front();
2570 auto item = unit->agent->getFirstItemInSlot(right ? EquipmentSlotType::RightHand
2571 : EquipmentSlotType::LeftHand);
2572
2573 if (!item)
2574 {
2575 return;
2576 }
2577 if (!item->canBeUsed(*state))
2578 {
2579 auto message_box = mksp<MessageBox>(
2580 tr("Alien Artifact"), tr("You must research Alien technology before you can use it."),
2581 MessageBox::ButtonOptions::Ok);
2582 fw().stageQueueCommand({StageCmd::Command::PUSH, message_box});
2583 return;
2584 }
2585
2586 switch (item->type->type)
2587 {
2588 case AEquipmentType::Type::Weapon:
2589 // Weapon has no automatic mode
2590 if (!item->canFire(*state) || automatic)
2591 {
2592 break;
2593 }
2594 selectionState =
2595 right ? BattleSelectionState::FireRight : BattleSelectionState::FireLeft;
2596 break;
2597 case AEquipmentType::Type::Grenade:
2598 if (automatic)
2599 {
2600 if (!item->primed)
2601 {
2602 item->prime();
2603 }
2604 selectionState =
2605 right ? BattleSelectionState::ThrowRight : BattleSelectionState::ThrowLeft;
2606 }
2607 else
2608 {
2609 if (item->primed)
2610 {
2611 break;
2612 }
2613 setSelectedTab(primingTab);
2614 refreshDelayText();
2615 refreshRangeText();
2616 activeTab->findControlTyped<CheckBox>("HIDDEN_CHECK_RIGHT_HAND")->setChecked(right);
2617
2618 bool range;
2619 switch (item->type->trigger_type)
2620 {

Callers

nothing calls this directly

Calls 11

trFunction · 0.85
emptyMethod · 0.80
getFirstItemInSlotMethod · 0.80
stageQueueCommandMethod · 0.80
primeMethod · 0.80
findControlMethod · 0.80
useItemMethod · 0.80
canBeUsedMethod · 0.45
canFireMethod · 0.45
setCheckedMethod · 0.45
setVisibleMethod · 0.45

Tested by

no test coverage detected