Skip to content

Commit 7b7d4c3

Browse files
committed
GainSelfHealAllowAllies and self healing pip
1 parent db34a8a commit 7b7d4c3

File tree

7 files changed

+76
-48
lines changed

7 files changed

+76
-48
lines changed

CREDITS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ This page lists all the individual contributions to the project by their author.
419419
- Enhanced Bombard trajectory
420420
- Shield armor inheritance customization
421421
- Fix `DefaultDisguise` showing wrong house colors for different players
422-
- Allowed player's self-healing effects to be benefited by houses with `PlayerControl=true` in campaign
422+
- Allowed player's self-healing effects to be benefited by allied or `PlayerControl=true` houses
423423
- **NaotoYuuki** - Vertical & meteor trajectory projectile prototypes
424424
- **handama** - AI script action to `16005 Jump Back To Previous Script`
425425
- **TaranDahl (航味麻酱)**:

docs/Fixed-or-Improved-Logics.md

+2
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ BallisticScatter.Max= ; floating point value, distance in cells
620620
- It is now possible to set a global cap for the effects of `InfantryGainSelfHeal` and `UnitsGainSelfHeal` by setting `InfantryGainSelfHealCap` & `UnitsGainSelfHealCap` under `[General]`, respectively.
621621
- Whether or not `MultiplayPassive=true` houses benefit from these effects can be controlled via `GainSelfHealAllowMultiplayPassive`.
622622
- In campaign, whether or not these effects for player can be benefited by houses with `PlayerControl=true` can be controlled via `GainSelfHealAllowPlayerControl`.
623+
- Whether or not these effects can be benefited by allied houses can be controlled via `GainSelfHealAllowAllies`.
623624
- It is also possible to change the pip frames displayed from `pips.shp` individually for infantry, units and buildings by setting the frames for infantry & unit self-healing on `Pips.SelfHeal.Infantry/Units/Buildings` under `[AudioVisual]`, respectively.
624625
- `Pips.SelfHeal.Infantry/Units/Buildings.Offset` can be used to customize the pixel offsets for the displayed pips, individually for infantry, units and buildings.
625626
- Whether or not a TechnoType benefits from effects of `InfantryGainSelfHeal` or `UnitsGainSelfHeal` buildings or neither can now be controlled by setting `SelfHealGainType`.
@@ -632,6 +633,7 @@ InfantryGainSelfHealCap= ; integer, maximum amount of InfantryGai
632633
UnitsGainSelfHealCap= ; integer, maximum amount of UnitsGainSelfHeal that can be in effect at once, must be 1 or higher
633634
GainSelfHealAllowMultiplayPassive=true ; boolean
634635
GainSelfHealAllowPlayerControl=false ; boolean
636+
GainSelfHealAllowAllies=false ; boolean
635637

636638
[AudioVisual]
637639
Pips.SelfHeal.Infantry=13,20 ; integer, frames of pips.shp for infantry & unit-self healing pips, respectively

docs/Whats-New.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ New:
341341
- Play an anim when recycling a spawner (by TaranDahl)
342342
- Recycle the spawner on other FLH (by TaranDahl)
343343
- Technos can maintain a suitable distance after firing (by CrimRecya)
344-
- Allowed player's self-healing effects to be benefited by houses with `PlayerControl=true` in campaign (by Ollerus)
344+
- Allowed player's self-healing effects to be benefited by allied or `PlayerControl=true` houses (by Ollerus)
345345

346346
Vanilla fixes:
347347
- Prevent the units with locomotors that cause problems from entering the tank bunker (by TaranDahl)

src/Ext/Rules/Body.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
7272
this->UnitsGainSelfHealCap.Read(exINI, GameStrings::General, "UnitsGainSelfHealCap");
7373
this->GainSelfHealAllowMultiplayPassive.Read(exINI, GameStrings::General, "GainSelfHealAllowMultiplayPassive");
7474
this->GainSelfHealAllowPlayerControl.Read(exINI, GameStrings::General, "GainSelfHealAllowPlayerControl");
75+
this->GainSelfHealAllowAllies.Read(exINI, GameStrings::General, "GainSelfHealAllowAllies");
7576
this->EnemyInsignia.Read(exINI, GameStrings::General, "EnemyInsignia");
7677
this->DisguiseBlinkingVisibility.Read(exINI, GameStrings::General, "DisguiseBlinkingVisibility");
7778
this->ChronoSparkleDisplayDelay.Read(exINI, GameStrings::General, "ChronoSparkleDisplayDelay");
@@ -312,6 +313,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
312313
.Process(this->UnitsGainSelfHealCap)
313314
.Process(this->GainSelfHealAllowMultiplayPassive)
314315
.Process(this->GainSelfHealAllowPlayerControl)
316+
.Process(this->GainSelfHealAllowAllies)
315317
.Process(this->EnemyInsignia)
316318
.Process(this->DisguiseBlinkingVisibility)
317319
.Process(this->ChronoSparkleDisplayDelay)

src/Ext/Rules/Body.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class RulesExt
3636
Nullable<int> UnitsGainSelfHealCap;
3737
Valueable<bool> GainSelfHealAllowMultiplayPassive;
3838
Valueable<bool> GainSelfHealAllowPlayerControl;
39+
Valueable<bool> GainSelfHealAllowAllies;
3940
Valueable<bool> EnemyInsignia;
4041
Valueable<AffectedHouse> DisguiseBlinkingVisibility;
4142
Valueable<int> ChronoSparkleDisplayDelay;
@@ -202,6 +203,7 @@ class RulesExt
202203
, UnitsGainSelfHealCap {}
203204
, GainSelfHealAllowMultiplayPassive { true }
204205
, GainSelfHealAllowPlayerControl { false }
206+
, GainSelfHealAllowAllies { false }
205207
, EnemyInsignia { true }
206208
, DisguiseBlinkingVisibility { AffectedHouse::Owner }
207209
, ChronoSparkleDisplayDelay { 24 }

src/Ext/Techno/Body.Update.cpp

+35-44
Original file line numberDiff line numberDiff line change
@@ -678,66 +678,57 @@ void TechnoExt::ApplyGainedSelfHeal(TechnoClass* pThis)
678678

679679
if (selfHealType == SelfHealGainType::NoHeal)
680680
return;
681+
else if (selfHealType == SelfHealGainType::Infantry && Unsorted::CurrentFrame % RulesClass::Instance->SelfHealInfantryFrames)
682+
return;
683+
else if (Unsorted::CurrentFrame % RulesClass::Instance->SelfHealUnitFrames)
684+
return;
681685

682686
int amount = 0;
683-
auto const pOwner = pThis->Owner;
684-
685-
if (selfHealType == SelfHealGainType::Infantry)
686-
{
687-
if (Unsorted::CurrentFrame % RulesClass::Instance->SelfHealInfantryFrames)
688-
return;
689-
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;
693687

694-
if (RulesExt::Global()->GainSelfHealAllowPlayerControl && SessionClass::IsCampaign() && (!hasCap || count < cap))
688+
auto countSelfHealing = [](const bool infantryHeal)
695689
{
696-
for (auto pHouse : HouseClass::Array)
697-
{
698-
if (pHouse != pOwner && pHouse->IsControlledByCurrentPlayer())
699-
{
700-
count += pHouse->InfantrySelfHeal;
690+
auto const pOwner = pThis->Owner;
691+
const bool hasCap = RulesExt::Global()->InfantryGainSelfHealCap.isset();
692+
const int cap = RulesExt::Global()->InfantryGainSelfHealCap.Get();
693+
int count = std::max(infantryHeal ? pOwner->InfantrySelfHeal : pOwner->UnitsSelfHeal, 1);
701694

702-
if (hasCap && count >= cap)
703-
{
704-
count = cap;
705-
break;
706-
}
707-
}
695+
if (hasCap && count >= cap)
696+
{
697+
count = cap;
698+
return count;
708699
}
709-
}
710700

711-
amount = RulesClass::Instance->SelfHealInfantryAmount * count;
712-
}
713-
else
714-
{
715-
if (Unsorted::CurrentFrame % RulesClass::Instance->SelfHealUnitFrames)
716-
return;
701+
const bool allowPlayerControl = RulesExt::Global()->GainSelfHealAllowPlayerControl && SessionClass::IsCampaign();
702+
const bool allowAllies = RulesExt::Global()->GainSelfHealAllowAllies;
717703

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;
721-
722-
if (RulesExt::Global()->GainSelfHealAllowPlayerControl && SessionClass::IsCampaign() && (!hasCap || count < cap))
723-
{
724-
for (auto pHouse : HouseClass::Array)
704+
if (allowPlayerControl || allowAllies)
725705
{
726-
if (pHouse != pOwner && pHouse->IsControlledByCurrentPlayer())
706+
for (auto pHouse : HouseClass::Array)
727707
{
728-
count += pHouse->UnitsSelfHeal;
708+
if (pHouse == pOwner)
709+
continue;
729710

730-
if (hasCap && count >= cap)
711+
if ((allowPlayerControl && pHouse->IsControlledByCurrentPlayer())
712+
|| (allowAllies && !pHouse->IsControlledByCurrentPlayer() && pHouse->IsAlliedWith(pOwner)))
731713
{
732-
count = cap;
733-
break;
714+
count += infantryHeal ? pHouse->InfantrySelfHeal : pHouse->UnitsSelfHeal;
715+
716+
if (hasCap && count >= cap)
717+
{
718+
count = cap;
719+
return count;
720+
}
734721
}
735722
}
736723
}
737-
}
738724

739-
amount = RulesClass::Instance->SelfHealUnitAmount * count;
740-
}
725+
return count;
726+
};
727+
728+
if (selfHealType == SelfHealGainType::Infantry)
729+
amount = RulesClass::Instance->SelfHealInfantryAmount * countSelfHealing(true);
730+
else
731+
amount = RulesClass::Instance->SelfHealUnitAmount * countSelfHealing(false);
741732

742733
if (amount)
743734
{

src/Ext/Techno/Body.Visuals.cpp

+33-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,44 @@ void TechnoExt::DrawSelfHealPips(TechnoClass* pThis, Point2D* pLocation, Rectang
2626
if (pThis->WhatAmI() == AbstractType::Infantry || (pThis->GetTechnoType()->Organic && pThis->WhatAmI() == AbstractType::Unit))
2727
isOrganic = true;
2828

29-
if (pThis->Owner->InfantrySelfHeal > 0 && (hasInfantrySelfHeal || (isOrganic && !hasUnitSelfHeal)))
29+
auto hasSelfHeal = [](const bool infantryHeal)
30+
{
31+
if (infantryHeal ? pThis->Owner->InfantrySelfHeal > 0 : pThis->Owner->UnitsSelfHeal > 0)
32+
return true;
33+
34+
const bool allowPlayerControl = RulesExt::Global()->GainSelfHealAllowPlayerControl && SessionClass::IsCampaign();
35+
const bool allowAllies = RulesExt::Global()->GainSelfHealAllowAllies;
36+
37+
if (allowPlayerControl || allowAllies)
38+
{
39+
for (auto pHouse : HouseClass::Array)
40+
{
41+
if (pHouse == pOwner)
42+
continue;
43+
44+
if (allowPlayerControl && pHouse->IsControlledByCurrentPlayer())
45+
{
46+
if (infantryHeal ? pHouse->InfantrySelfHeal > 0 : pHouse->UnitsSelfHeal > 0)
47+
return true;
48+
}
49+
else if (allowAllies && !pHouse->IsControlledByCurrentPlayer() && pHouse->IsAlliedWith(pOwner))
50+
{
51+
if (infantryHeal ? pHouse->InfantrySelfHeal > 0 : pHouse->UnitsSelfHeal > 0)
52+
return true;
53+
}
54+
}
55+
}
56+
57+
return false;
58+
};
59+
60+
if ((hasInfantrySelfHeal || (isOrganic && !hasUnitSelfHeal)) && hasSelfHeal(true))
3061
{
3162
drawPip = true;
3263
selfHealFrames = RulesClass::Instance->SelfHealInfantryFrames;
3364
isInfantryHeal = true;
3465
}
35-
else if (pThis->Owner->UnitsSelfHeal > 0 && (hasUnitSelfHeal || (pThis->WhatAmI() == AbstractType::Unit && !isOrganic)))
66+
else if ((hasUnitSelfHeal || (pThis->WhatAmI() == AbstractType::Unit && !isOrganic)) && hasSelfHeal(false))
3667
{
3768
drawPip = true;
3869
selfHealFrames = RulesClass::Instance->SelfHealUnitFrames;

0 commit comments

Comments
 (0)