Skip to content

Commit 3def3f7

Browse files
committed
fake health display
1 parent a5fbfe7 commit 3def3f7

File tree

7 files changed

+71
-28
lines changed

7 files changed

+71
-28
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ This page lists all the individual contributions to the project by their author.
372372
- **Ollerus**
373373
- Build limit group enhancement
374374
- Customizable rocker amplitude
375+
- Allow faking digital display for `InfoType=Health`
375376
- **handama** - AI script action to jump back to previous script
376377
- **TaranDahl (航味麻酱)**
377378
- Skirmish AI "sell all buildings and set all technos to hunt" behavior dehardcode

docs/User-Interface.md

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ IngameScore.LoseTheme= ; Soundtrack theme ID
3434
*Default configuration of digital display using example shapes from [Phobos supplementaries](https://github.com/Phobos-developers/PhobosSupplementaries).*
3535

3636
- You can now configure various types of numerical counters to be displayed over Techno to represent its attributes, such as health points or shield points.
37-
- `Anchor.Horizontal` and `Anchor.Vertical` set the anchor point from which the display is drawn (depending on `Align`) relative to unit's center/selection box. For buildings, `Anchor.Building` is used instead.
37+
- `Anchor.Horizontal` and `Anchor.Vertical` set the anchor point from which the display is drawn (depending on `Align`) relative to unit's center/selection box. For buildings, `Anchor.Building` is used instead.
3838
- `Offset` and `Offset.ShieldDelta` (the latter applied when a shield is active) can be used to further modify the position.
3939
- By default, values are displayed in `current/maximum` format (i.e. 20/40). `HideMaxValue=yes` will make the counter show only the current value (i.e. 20). `Percentage=yes` changes the format to `percent%` (i.e. 50%).
4040
- `CanSee` and `CanSee.Observer` can limit visibility to specific players.
@@ -46,50 +46,56 @@ IngameScore.LoseTheme= ; Soundtrack theme ID
4646
- Default `Shape.Spacing` for buildings is `4,-2`, `4,0` for others.
4747
- `ValueScaleDivisor` can be used to adjust scale of displayed values. Both the current & maximum value will be divided by the integer number given, if higher than 1.
4848

49+
- If a TechnoType has a DigitalDisplayType with `InfoType=Health`, it's allowed to display fake values to enemy players.
50+
- `DigitalDisplay.Health.FakeStrength`, if set, will be used as the maximum value of health display. The current value will be displayed as the percentage of its current health multiplies the new maximum value.
51+
- `DigitalDisplay.Health.FakeAtDisguise`, if set to true on an InfantryType with Disguise, will use the disguised TechnoType's `Strength` value as the maximum value of health display. The current value will be displayed as the percentage of its current health multiplies the new maximum value. This will be applied before `DigitalDisplay.Health.FakeStrength`.
52+
4953
In `rulesmd.ini`:
5054
```ini
5155
[DigitalDisplayTypes]
5256
0=SOMEDIGITALDISPLAYTYPE
5357

5458
[AudioVisual]
55-
Buildings.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
56-
Infantry.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
57-
Vehicles.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
58-
Aircraft.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
59+
Buildings.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
60+
Infantry.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
61+
Vehicles.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
62+
Aircraft.DefaultDigitalDisplayTypes= ; list of DigitalDisplayTypes
5963

60-
[SOMEDIGITALDISPLAYTYPE] ; DigitalDisplayType
64+
[SOMEDIGITALDISPLAYTYPE] ; DigitalDisplayType
6165
; Generic
62-
InfoType=Health ; Displayed value enumeration (health|shield|ammo|mindcontrol|spawns|passengers|tiberium|experience|occupants|gattlingstage)
63-
Offset=0,0 ; integers - horizontal, vertical
64-
Offset.ShieldDelta= ; integers - horizontal, vertical
65-
Align=right ; Text alignment enumeration (left|right|center/centre)
66-
Anchor.Horizontal=right ; Horizontal position enumeration (left|center/centre|right)
67-
Anchor.Vertical=top ; Vertical position enumeration (top|center/centre|bottom)
68-
Anchor.Building=top ; Hexagon vertex enumeration (top|lefttop|leftbottom|bottom|rightbottom|righttop)
69-
Percentage=false ; boolean
70-
HideMaxValue=false ; boolean
71-
VisibleToHouses=owner ; Affected house enumeration (none|owner/self|allies/ally|team|enemies/enemy|all)
72-
VisibleToHouses.Observer=true ; boolean
73-
ValueScaleDivisor=1 ; integer
66+
InfoType=Health ; Displayed value enumeration (health|shield|ammo|mindcontrol|spawns|passengers|tiberium|experience|occupants|gattlingstage)
67+
Offset=0,0 ; integers - horizontal, vertical
68+
Offset.ShieldDelta= ; integers - horizontal, vertical
69+
Align=right ; Text alignment enumeration (left|right|center/centre)
70+
Anchor.Horizontal=right ; Horizontal position enumeration (left|center/centre|right)
71+
Anchor.Vertical=top ; Vertical position enumeration (top|center/centre|bottom)
72+
Anchor.Building=top ; Hexagon vertex enumeration (top|lefttop|leftbottom|bottom|rightbottom|righttop)
73+
Percentage=false ; boolean
74+
HideMaxValue=false ; boolean
75+
VisibleToHouses=owner ; Affected house enumeration (none|owner/self|allies/ally|team|enemies/enemy|all)
76+
VisibleToHouses.Observer=true ; boolean
77+
ValueScaleDivisor=1 ; integer
7478
; Text
75-
Text.Color=0,255,0 ; integers - Red, Green, Blue
76-
Text.Color.ConditionYellow=255,255,0 ; integers - Red, Green, Blue
77-
Text.Color.ConditionRed=255,0,0 ; integers - Red, Green, Blue
78-
Text.Background=false ; boolean
79+
Text.Color=0,255,0 ; integers - Red, Green, Blue
80+
Text.Color.ConditionYellow=255,255,0 ; integers - Red, Green, Blue
81+
Text.Color.ConditionRed=255,0,0 ; integers - Red, Green, Blue
82+
Text.Background=false ; boolean
7983
; Shape
80-
Shape= ; filename with .shp extension, if not present, game-drawn text will be used instead
81-
Palette=palette.pal ; filename with .pal extension
82-
Shape.Spacing= ; integers - horizontal, vertical spacing between digits
84+
Shape= ; filename with .shp extension, if not present, game-drawn text will be used instead
85+
Palette=palette.pal ; filename with .pal extension
86+
Shape.Spacing= ; integers - horizontal, vertical spacing between digits
8387

8488
[SOMETECHNOTYPE]
85-
DigitalDisplay.Disable=false ; boolean
86-
DigitalDisplayTypes= ; list of DigitalDisplayTypes
89+
DigitalDisplay.Disable=false ; boolean
90+
DigitalDisplayTypes= ; list of DigitalDisplayTypes
91+
DigitalDisplay.Health.FakeStrength=-1 ; integer
92+
DigitalDisplay.Health.FakeAtDisguise=true ; boolean
8793
```
8894

8995
In `RA2MD.ini`:
9096
```ini
9197
[Phobos]
92-
DigitalDisplay.Enable=false ; boolean
98+
DigitalDisplay.Enable=false ; boolean
9399
```
94100

95101
```{note}

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ New:
468468
- Allow infantry to use land sequences in water (by Starkku)
469469
- `<Player @ X>` can now be used as owner for pre-placed objects on skirmish and multiplayer maps (by Starkku)
470470
- Allow customizing charge turret delays per burst on a weapon (by Starkku)
471+
- Allow faking digital display for `InfoType=Health` (by Ollerus)
471472
472473
Vanilla fixes:
473474
- Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy)

src/Ext/Techno/Body.Visuals.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ void TechnoExt::GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType
371371
{
372372
value = pThis->Health;
373373
maxValue = pType->Strength;
374+
375+
if (!pThis->Owner->IsAlliedWith(HouseClass::CurrentPlayer))
376+
GetDigitalDisplayFakeHealth(pThis, value, maxValue);
377+
374378
break;
375379
}
376380
case DisplayInfoType::Shield:
@@ -465,3 +469,22 @@ void TechnoExt::GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType
465469
}
466470
}
467471
}
472+
473+
void TechnoExt::GetDigitalDisplayFakeHealth(TechnoClass* pThis, int& value, int& maxValue)
474+
{
475+
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
476+
int newMaxValue = pTypeExt->DigitalDisplay_Health_FakeStrength;
477+
478+
if (pThis->Disguised && pTypeExt->DigitalDisplay_Health_FakeAtDisguise && pThis->WhatAmI() == AbstractType::Infantry)
479+
{
480+
if (const auto pType = TechnoTypeExt::GetTechnoType(pThis->Disguise))
481+
newMaxValue = pType->Strength;
482+
}
483+
484+
if (newMaxValue >= 0)
485+
{
486+
double ratio = static_cast<double>(value) / maxValue;
487+
value = static_cast<int>(ratio * newMaxValue);
488+
maxValue = newMaxValue;
489+
}
490+
}

src/Ext/Techno/Body.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class TechnoExt
173173
static Point2D GetBuildingSelectBracketPosition(TechnoClass* pThis, BuildingSelectBracketPosition bracketPosition);
174174
static void ProcessDigitalDisplays(TechnoClass* pThis);
175175
static void GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType, int& value, int& maxValue);
176+
static void GetDigitalDisplayFakeHealth(TechnoClass* pThis, int& value, int& maxValue);
176177

177178
// WeaponHelpers.cpp
178179
static int PickWeaponIndex(TechnoClass* pThis, TechnoClass* pTargetTechno, AbstractClass* pTarget, int weaponIndexOne, int weaponIndexTwo, bool allowFallback = true, bool allowAAFallback = true);

src/Ext/TechnoType/Body.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
462462
this->Wake_Grapple.Read(exINI, pSection, "Wake.Grapple");
463463
this->Wake_Sinking.Read(exINI, pSection, "Wake.Sinking");
464464

465+
this->DigitalDisplay_Health_FakeStrength.Read(exINI, pSection, "DigitalDisplay.Health.FakeStrength");
466+
this->DigitalDisplay_Health_FakeAtDisguise.Read(exINI, pSection, "DigitalDisplay.Health.FakeAtDisguise");
467+
465468
// Ares 0.2
466469
this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius");
467470

@@ -831,6 +834,9 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
831834
.Process(this->Wake)
832835
.Process(this->Wake_Grapple)
833836
.Process(this->Wake_Sinking)
837+
838+
.Process(this->DigitalDisplay_Health_FakeStrength)
839+
.Process(this->DigitalDisplay_Health_FakeAtDisguise)
834840
;
835841
}
836842
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)

src/Ext/TechnoType/Body.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ class TechnoTypeExt
248248
std::vector<std::vector<CoordStruct>> DeployedWeaponBurstFLHs;
249249
std::vector<std::vector<CoordStruct>> EliteDeployedWeaponBurstFLHs;
250250

251+
Valueable<int> DigitalDisplay_Health_FakeStrength;
252+
Valueable<bool> DigitalDisplay_Health_FakeAtDisguise;
251253

252254
ExtData(TechnoTypeClass* OwnerObject) : Extension<TechnoTypeClass>(OwnerObject)
253255
, HealthBar_Hide { false }
@@ -450,6 +452,9 @@ class TechnoTypeExt
450452
, Wake { }
451453
, Wake_Grapple { }
452454
, Wake_Sinking { }
455+
456+
, DigitalDisplay_Health_FakeStrength { -1 }
457+
, DigitalDisplay_Health_FakeAtDisguise { true }
453458
{ }
454459

455460
virtual ~ExtData() = default;

0 commit comments

Comments
 (0)