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

Method thinkInternal

game/state/battle/ai/unitaivanilla.cpp:698–818  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

696}
697
698AIDecision UnitAIVanilla::thinkInternal(GameState &state, BattleUnit &u)
699{
700#ifdef VANILLA_AI_DEBUG_OUTPUT
701 LogWarning("VANILLA AI %s: thinkInternal()", u.id);
702#endif
703 switch (u.getAIType())
704 {
705 case AIType::None:
706 case AIType::Civilian:
707 return {};
708 case AIType::PanicFreeze:
709 case AIType::PanicRun:
710 case AIType::Berserk:
711 LogError("Calling UnitAIVanilla on panic/berserk unit!?");
712 return {};
713 case AIType::Loner:
714 case AIType::Group:
715 // Go on below
716 break;
717 }
718
719 // Clear actions that are done
720 if (lastDecision.action && lastDecision.action->isFinished(u))
721 {
722 lastDecision.action = nullptr;
723 // Clear subordinate movement
724 if (lastDecision.movement && lastDecision.movement->subordinate)
725 {
726 lastDecision.movement = nullptr;
727 }
728 }
729 // Clear movements that are done
730 if (lastDecision.movement && lastDecision.movement->isFinished(u))
731 {
732 // Clear action if action is not in progress but subordinate movement finished
733 if (lastDecision.movement->subordinate)
734 {
735 if (lastDecision.action && !lastDecision.action->inProgress(u))
736 {
737 lastDecision.action = nullptr;
738 }
739 }
740 lastDecision.movement = nullptr;
741 }
742 // Clear actions that are outdated
743 if (lastDecision.action && lastDecision.action->targetUnit &&
744 !lastDecision.action->targetUnit->isConscious())
745 {
746 lastDecision.action = nullptr;
747 }
748
749 //
750 // See whether re-think is required
751 //
752
753 // Conditions that prevent re-thinking:
754
755 // 1: Decision is never re-thought if currently throwing

Callers

nothing calls this directly

Calls 8

getAITypeMethod · 0.80
inProgressMethod · 0.80
isConsciousMethod · 0.80
emptyMethod · 0.80
getTicksMethod · 0.80
isAttackingMethod · 0.80
isFinishedMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected