|
1 | 1 | // methods used in TechnoClass_AI hooks or anything similar
|
2 | 2 | #include "Body.h"
|
3 | 3 |
|
| 4 | +#include <SessionClass.h> |
4 | 5 | #include <SpawnManagerClass.h>
|
5 | 6 | #include <ParticleSystemClass.h>
|
6 | 7 |
|
@@ -678,33 +679,67 @@ void TechnoExt::ApplyGainedSelfHeal(TechnoClass* pThis)
|
678 | 679 | if (selfHealType == SelfHealGainType::NoHeal)
|
679 | 680 | return;
|
680 | 681 |
|
681 |
| - bool applyHeal = false; |
682 | 682 | int amount = 0;
|
| 683 | + auto const pOwner = pThis->Owner; |
683 | 684 |
|
684 | 685 | if (selfHealType == SelfHealGainType::Infantry)
|
685 | 686 | {
|
686 |
| - int count = RulesExt::Global()->InfantryGainSelfHealCap.isset() ? |
687 |
| - std::min(std::max(RulesExt::Global()->InfantryGainSelfHealCap.Get(), 1), pThis->Owner->InfantrySelfHeal) : |
688 |
| - pThis->Owner->InfantrySelfHeal; |
| 687 | + if (Unsorted::CurrentFrame % RulesClass::Instance->SelfHealInfantryFrames) |
| 688 | + return; |
689 | 689 |
|
690 |
| - amount = RulesClass::Instance->SelfHealInfantryAmount * count; |
| 690 | + const bool hasCap = RulesExt::Global()->InfantryGainSelfHealCap.isset(); |
| 691 | + const int cap = RulesExt::Global()->InfantryGainSelfHealCap.Get(); |
| 692 | + int count = hasCap ? std::clamp(pOwner->InfantrySelfHeal, 1, cap) : pOwner->InfantrySelfHeal; |
691 | 693 |
|
692 |
| - if (!(Unsorted::CurrentFrame % RulesClass::Instance->SelfHealInfantryFrames) && amount) |
693 |
| - applyHeal = true; |
| 694 | + if (RulesExt::Global()->GainSelfHealAllowPlayerControl && SessionClass::IsCampaign() && (!hasCap || count < cap)) |
| 695 | + { |
| 696 | + for (auto pHouse : HouseClass::Array) |
| 697 | + { |
| 698 | + if (pHouse != pOwner && pHouse->IsControlledByCurrentPlayer()) |
| 699 | + { |
| 700 | + count += pHouse->InfantrySelfHeal; |
| 701 | + |
| 702 | + if (hasCap && count >= cap) |
| 703 | + { |
| 704 | + count = cap; |
| 705 | + break; |
| 706 | + } |
| 707 | + } |
| 708 | + } |
| 709 | + } |
| 710 | + |
| 711 | + amount = RulesClass::Instance->SelfHealInfantryAmount * count; |
694 | 712 | }
|
695 | 713 | else
|
696 | 714 | {
|
697 |
| - int count = RulesExt::Global()->UnitsGainSelfHealCap.isset() ? |
698 |
| - std::min(std::max(RulesExt::Global()->UnitsGainSelfHealCap.Get(), 1), pThis->Owner->UnitsSelfHeal) : |
699 |
| - pThis->Owner->UnitsSelfHeal; |
| 715 | + if (Unsorted::CurrentFrame % RulesClass::Instance->SelfHealUnitFrames) |
| 716 | + return; |
700 | 717 |
|
701 |
| - amount = RulesClass::Instance->SelfHealUnitAmount * count; |
| 718 | + const bool hasCap = RulesExt::Global()->UnitsGainSelfHealCap.isset(); |
| 719 | + const int cap = RulesExt::Global()->UnitsGainSelfHealCap.Get(); |
| 720 | + int count = hasCap ? std::clamp(pOwner->UnitsSelfHeal, 1, cap) : pOwner->UnitsSelfHeal; |
702 | 721 |
|
703 |
| - if (!(Unsorted::CurrentFrame % RulesClass::Instance->SelfHealUnitFrames) && amount) |
704 |
| - applyHeal = true; |
| 722 | + if (RulesExt::Global()->GainSelfHealAllowPlayerControl && SessionClass::IsCampaign() && (!hasCap || count < cap)) |
| 723 | + { |
| 724 | + for (auto pHouse : HouseClass::Array) |
| 725 | + { |
| 726 | + if (pHouse != pOwner && pHouse->IsControlledByCurrentPlayer()) |
| 727 | + { |
| 728 | + count += pHouse->UnitsSelfHeal; |
| 729 | + |
| 730 | + if (hasCap && count >= cap) |
| 731 | + { |
| 732 | + count = cap; |
| 733 | + break; |
| 734 | + } |
| 735 | + } |
| 736 | + } |
| 737 | + } |
| 738 | + |
| 739 | + amount = RulesClass::Instance->SelfHealUnitAmount * count; |
705 | 740 | }
|
706 | 741 |
|
707 |
| - if (applyHeal && amount) |
| 742 | + if (amount) |
708 | 743 | {
|
709 | 744 | if (amount >= healthDeficit)
|
710 | 745 | amount = healthDeficit;
|
|
0 commit comments