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

Method useItem

game/state/battle/battleunit.cpp:5054–5123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5052}
5053
5054bool BattleUnit::useItem(GameState &state, sp<AEquipment> item)
5055{
5056 if (item->ownerAgent != agent || (item->equippedSlotType != EquipmentSlotType::RightHand &&
5057 item->equippedSlotType != EquipmentSlotType::LeftHand))
5058 {
5059 LogError("Unit %s attempting to use item that is not in hand or does not belong to us?",
5060 id);
5061 return false;
5062 }
5063 switch (item->type->type)
5064 {
5065 // Items that cannot be used this way
5066 case AEquipmentType::Type::Weapon:
5067 case AEquipmentType::Type::Grenade:
5068 case AEquipmentType::Type::MindBender:
5069 case AEquipmentType::Type::Teleporter:
5070 return false;
5071 // Items that do nothing
5072 case AEquipmentType::Type::AlienDetector:
5073 case AEquipmentType::Type::Ammo:
5074 case AEquipmentType::Type::Armor:
5075 case AEquipmentType::Type::CloakingField:
5076 case AEquipmentType::Type::DimensionForceField:
5077 case AEquipmentType::Type::DisruptorShield:
5078 case AEquipmentType::Type::Loot:
5079 case AEquipmentType::Type::MindShield:
5080 case AEquipmentType::Type::MultiTracker:
5081 case AEquipmentType::Type::StructureProbe:
5082 case AEquipmentType::Type::VortexAnalyzer:
5083 return false;
5084 case AEquipmentType::Type::MotionScanner:
5085 if (item->inUse)
5086 {
5087 state.current_battle->removeScanner(state, *item);
5088 }
5089 else
5090 {
5091 if (state.current_battle->mode == Battle::Mode::TurnBased)
5092 {
5093 // 10% of max TUs
5094 if (!spendTU(state, getMotionScannerCost()))
5095 {
5096 LogWarning("Notify unsufficient TU for motion scanner");
5097 return false;
5098 }
5099 }
5100 else
5101 {
5102 state.current_battle->addScanner(state, *item);
5103 }
5104 }
5105 item->inUse = !item->inUse;
5106 return true;
5107 case AEquipmentType::Type::MediKit:
5108 // Initial use of medikit just brings up interface, action and TU spent happens
5109 // when individual body part is clicked
5110 item->inUse = !item->inUse;
5111 return true;

Callers 1

orderUseMethod · 0.80

Calls 2

removeScannerMethod · 0.80
addScannerMethod · 0.80

Tested by

no test coverage detected