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

Method cancelMissions

game/state/battle/battleunit.cpp:5637–5746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5635}
5636
5637bool BattleUnit::cancelMissions(GameState &state, bool forced)
5638{
5639 if (forced)
5640 {
5641 // Drop gear used by missions, remove headcrab
5642 std::list<sp<AEquipment>> equipToDrop;
5643 for (auto &m : missions)
5644 {
5645 if (m->item && m->item->ownerAgent)
5646 {
5647 equipToDrop.push_back(m->item);
5648 }
5649 if (m->targetUnit && m->type == BattleUnitMission::Type::Brainsuck)
5650 {
5651 m->targetUnit->brainSucker.clear();
5652 }
5653 }
5654 missions.clear();
5655 for (auto &e : equipToDrop)
5656 {
5657 addMission(state, BattleUnitMission::dropItem(*this, e));
5658 }
5659 }
5660 else
5661 {
5662 popFinishedMissions(state);
5663 if (retreated)
5664 {
5665 return false;
5666 }
5667 if (missions.empty())
5668 {
5669 return true;
5670 }
5671
5672 // Figure out if we can cancel the mission in front
5673 bool letFinish = false;
5674 int facingDelta = 0;
5675 switch (missions.front()->type)
5676 {
5677 // Missions that cannot be cancelled
5678 case BattleUnitMission::Type::ThrowItem:
5679 case BattleUnitMission::Type::Brainsuck:
5680 return false;
5681 // Jump can only be cancelled if we have not jumped yet
5682 case BattleUnitMission::Type::Jump:
5683 return !missions.front()->jumped;
5684 // Drop Item can only be cancelled if item is in agent's inventory
5685 case BattleUnitMission::Type::DropItem:
5686 if (missions.front()->item && !missions.front()->item->ownerAgent)
5687 {
5688 return false;
5689 }
5690 break;
5691 // Missions that must be let finish
5692 case BattleUnitMission::Type::ChangeBodyState:
5693 case BattleUnitMission::Type::Turn:
5694 case BattleUnitMission::Type::GotoLocation:

Callers 2

beginTurnRoutineMethod · 0.80
handleKeyDownMethod · 0.80

Calls 3

emptyMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected