| 696 | } |
| 697 | |
| 698 | AIDecision 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 |
nothing calls this directly
no test coverage detected