Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline power plant indicator #1104

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a847b76
Initial commit
Fryone Jul 16, 2023
f576228
Update Whats-New.md
Fryone Jul 16, 2023
12edf3c
Updated conditions
Fryone Jul 18, 2023
03bd804
Added disabler
Fryone Jul 21, 2023
9ee1837
Merge branch 'develop' into fryone/lowpower_sign
Fryone Aug 7, 2023
183e5da
Update src/Ext/Building/Hooks.cpp
Fryone Aug 8, 2023
12f6034
Update src/Ext/Building/Hooks.cpp
Fryone Aug 8, 2023
cd450a8
Update src/Ext/Building/Hooks.cpp
Fryone Aug 8, 2023
f50a97a
Fixes
Fryone Aug 8, 2023
25562b3
Update Whats-New.md
Fryone Aug 8, 2023
bd7cc59
Merge branch 'develop' into fryone/lowpower_sign
Fryone Aug 19, 2023
441b00e
Merge branch 'develop' into fryone/lowpower_sign
Fryone Aug 24, 2023
3b4a132
Update src/Ext/Building/Hooks.cpp
Fryone Aug 26, 2023
1d61437
Update src/Ext/Techno/Hooks.cpp
Fryone Aug 26, 2023
11fa48c
Update src/Ext/Building/Hooks.cpp
Fryone Aug 26, 2023
36f6538
Update src/Ext/Building/Hooks.cpp
Fryone Aug 26, 2023
a0430ba
Update src/Ext/Building/Hooks.cpp
Fryone Aug 26, 2023
0b3a160
Update src/Ext/Building/Hooks.cpp
Fryone Aug 26, 2023
9633056
Update docs/Fixed-or-Improved-Logics.md
Fryone Aug 26, 2023
c30ebc9
Merge branch 'fryone/lowpower_sign' of https://github.com/Fryone/Phob…
Fryone Aug 26, 2023
9d2f4cd
Custom shape param
Fryone Aug 27, 2023
afa3759
Small fixes
Fryone Aug 28, 2023
7c34a27
Merge branch 'develop' into fryone/lowpower_sign
Fryone Aug 31, 2023
b20c487
Merge branch 'develop' into fryone/lowpower_sign
Fryone Sep 6, 2023
95e429b
Merge branch 'develop' into fryone/lowpower_sign
Fryone Sep 13, 2023
8a24c05
Merge branch 'develop' into fryone/lowpower_sign
Fryone Sep 14, 2023
08a6267
Merge branch 'develop' into fryone/lowpower_sign
Fryone Sep 26, 2023
9c6abbd
Merge branch 'develop' into fryone/lowpower_sign
Fryone Sep 27, 2023
8ee35b5
Merge branch 'develop' into fryone/lowpower_sign
Fryone Sep 29, 2023
12f70f4
Merge remote-tracking branch 'upstream/develop' into fryone/lowpower_…
Fryone Oct 2, 2023
ae4fce0
Merge remote-tracking branch 'upstream/develop' into fryone/lowpower_…
Fryone Oct 7, 2023
047f17a
Update Hooks.cpp
Fryone Oct 7, 2023
e260985
Merge remote-tracking branch 'upstream/develop' into fryone/lowpower_…
Fryone May 17, 2024
64bbaa8
rework update
Fryone May 18, 2024
99c82c2
Update Hooks.cpp
Fryone May 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ This page lists all the individual contributions to the project by their author.
- Sound entry on unit's creation
- Auto-deploy/Deploy block on ammo change
- Flashing Technos on selecting
- Offline power plant indicator
- **ZivDero**
- Allow giving ownership of buildings to players in Skirmish and MP using <Player @ A-H>
- Re-enable the Veinhole Monster and Weeds from TS
Expand Down
20 changes: 20 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,26 @@ In `rulesmd.ini`:
SellBuildupLength=23 ; integer, number of buildup frames to play
```

### Offline power plant indicator

- If `DrawPowerOffline` is set, indicator will appear on power plants when being offline, for example, drained by floating disk, infiltrated or disabled when using ForceShield.
- `DrawPowerOffline.Offset` is used to adjust position of indicator.
- `DrawPowerOffline.Shape` is a name of shape used to draw indicator. `POWEROFF.SHP` is used by default if not set.
- `DrawPowerOffline.Palette` is a name of palette used to draw indicator. `MOUSEPAL.PAL` is used by default if not set.
- `DisablePowerOfflineIcon` is used to disable indicator per building type.

In `rulesmd.ini`:
```ini
[AudioVisual]
DrawPowerOffline=false ; boolean
DrawPowerOffline.Shape= ; shape name without .shp extension
DrawPowerOffline.Palette= ; palette name with .pal extension
DrawPowerOffline.Offset=0,0 ; integer, offset

[SOMEBUILDING]
DisablePowerOfflineIcon=false ; boolean
```

## Particle systems

### Fire particle target coordinate adjustment when firer rotates
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ New:
- Reloading ammo in transports (by Starkku)
- Dump variables to file on scenario end / hotkey (by Morton)
- "House owns TechnoType" and "House doesn't own TechnoType" trigger events
- Offline power plant indicator (by Fryone)
- Allow toggling `Infantry/UnitsGainSelfHeal` for `MultiplayPassive=true` houses (by Starkku)
- Customizable straight trajectory detonation & snap distance and pass-through option (by Starkku)
- Airstrike & spy plane fixed spawn distance & height (by Starkku)
Expand Down
10 changes: 10 additions & 0 deletions src/Ext/Building/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@ bool BuildingExt::HandleInfiltrate(BuildingClass* pBuilding, HouseClass* pInfilt
return true;
}

void BuildingExt::DrawOfflinePlantIndicator(Point2D* pPosition, RectangleStruct* pBounds, int drawSpeed)
{
SHPStruct* pSHP = RulesExt::Global()->DrawPowerOffline_Shape ? RulesExt::Global()->DrawPowerOffline_Shape : FileSystem::POWEROFF_SHP;
ConvertClass* pPalette = RulesExt::Global()->DrawPowerOffline_Palette.GetOrDefaultConvert(FileSystem::MOUSE_PAL);
Point2D nPoint = *pPosition + RulesExt::Global()->DrawPowerOffline_Offset;

const int frame = (pSHP->Frames * (Unsorted::CurrentFrame % drawSpeed)) / drawSpeed;
DSurface::Temp->DrawSHP(pPalette, pSHP, frame, &nPoint, pBounds, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);
}

// =============================
// load / save

Expand Down
2 changes: 2 additions & 0 deletions src/Ext/Building/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ class BuildingExt
static bool DoGrindingExtras(BuildingClass* pBuilding, TechnoClass* pTechno, int refund);
static bool HandleInfiltrate(BuildingClass* pBuilding, HouseClass* pInfiltratorHouse);
static bool CanUndeployOnSell(BuildingClass* pThis);

static void DrawOfflinePlantIndicator(Point2D* pPosition, RectangleStruct* pBounds, int drawSpeed);
};
39 changes: 39 additions & 0 deletions src/Ext/Building/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,42 @@ DEFINE_HOOK(0x4511D6, BuildingClass_AnimationAI_SellBuildup, 0x7)

return pTypeExt->SellBuildupLength == pThis->Animation.Value ? Continue : Skip;
}

// Addition to Ares' Extras
DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7)
{
GET(TechnoClass*, pThis, EBP);
GET_STACK(RectangleStruct*, pRect, 0xA0);

const auto pBld = abstract_cast<BuildingClass*>(pThis);
auto exit = [R, pRect]()
{
R->ESI(pRect);
return 0x6F534E;
};

if (!pBld)
return exit();

if (!RulesExt::Global()->DrawPowerOffline)
return exit();

const auto pTypeExt = BuildingTypeExt::ExtMap.Find(pBld->Type);
bool showLowPower = (pTypeExt->DisablePowerOfflineIcon == false)
&& (pBld->Type->PowerBonus > 0)
&& (pBld->Factory == nullptr)
&& (pBld->IsPowerOnline() == false || pBld->IsBeingDrained())
&& (pBld->IsBeingWarpedOut() == false)
&& (pBld->WarpingOut == false)
&& ((pBld->GetCurrentMission() != Mission::Selling) && (pBld->GetCurrentMission() != Mission::Construction))
&& (pBld->CloakState == CloakState::Uncloaked);

if (!showLowPower || MapClass::Instance->GetCellAt(pBld->GetMapCoords())->IsShrouded())
return exit();

Point2D nPoint = TacticalClass::Instance->CoordsToClient(pBld->GetCenterCoords()).first;
const int speed = Math::max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2);
BuildingExt::DrawOfflinePlantIndicator(&nPoint, pRect, speed);

return exit();
}
2 changes: 2 additions & 0 deletions src/Ext/BuildingType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)

this->ConsideredVehicle.Read(exINI, pSection, "ConsideredVehicle");
this->SellBuildupLength.Read(exINI, pSection, "SellBuildupLength");
this->DisablePowerOfflineIcon.Read(exINI, pSection, "DisablePowerOfflineIcon");

if (pThis->NumberOfDocks > 0)
{
Expand Down Expand Up @@ -259,6 +260,7 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm)
.Process(this->ZShapePointMove_OnBuildup)
.Process(this->SellBuildupLength)
.Process(this->AircraftDockingDirs)
.Process(this->DisablePowerOfflineIcon)
;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Ext/BuildingType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class BuildingTypeExt
Nullable<bool> ConsideredVehicle;
Valueable<bool> ZShapePointMove_OnBuildup;
Valueable<int> SellBuildupLength;
Valueable<bool> DisablePowerOfflineIcon;

std::vector<OptionalStruct<DirType, true>> AircraftDockingDirs;

Expand Down Expand Up @@ -101,6 +102,7 @@ class BuildingTypeExt
, ZShapePointMove_OnBuildup { false }
, SellBuildupLength { 23 }
, AircraftDockingDirs {}
, DisablePowerOfflineIcon { false }
{ }

// Ares 0.A functions
Expand Down
9 changes: 9 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->HeightShadowScaling.Read(exINI, GameStrings::AudioVisual, "HeightShadowScaling");
this->HeightShadowScaling_MinScale.Read(exINI, GameStrings::AudioVisual, "HeightShadowScaling.MinScale");

this->DrawPowerOffline.Read(exINI, GameStrings::AudioVisual, "DrawPowerOffline");
this->DrawPowerOffline_Offset.Read(exINI, GameStrings::AudioVisual, "DrawPowerOffline.Offset");
this->DrawPowerOffline_Shape.Read(exINI, GameStrings::AudioVisual, "DrawPowerOffline.Shape");
this->DrawPowerOffline_Palette.LoadFromINI(pINI, GameStrings::AudioVisual, "DrawPowerOffline.Palette");

this->AllowParallelAIQueues.Read(exINI, "GlobalControls", "AllowParallelAIQueues");
this->ForbidParallelAIQueues_Aircraft.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Infantry");
this->ForbidParallelAIQueues_Building.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Building");
Expand Down Expand Up @@ -295,6 +300,10 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->DrawTurretShadow)
.Process(this->IsVoiceCreatedGlobal)
.Process(this->SelectionFlashDuration)
.Process(this->DrawPowerOffline)
.Process(this->DrawPowerOffline_Offset)
.Process(this->DrawPowerOffline_Shape)
.Process(this->DrawPowerOffline_Palette)
.Process(this->AnimRemapDefaultColorScheme)
.Process(this->TimerBlinkColorScheme)
.Process(this->Buildings_DefaultDigitalDisplayTypes)
Expand Down
9 changes: 9 additions & 0 deletions src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class RulesExt
ValueableIdx<ColorScheme> AnimRemapDefaultColorScheme;
ValueableIdx<ColorScheme> TimerBlinkColorScheme;

Valueable<bool> DrawPowerOffline;
Valueable<Point2D> DrawPowerOffline_Offset;
Nullable<SHPStruct*> DrawPowerOffline_Shape;
CustomPalette DrawPowerOffline_Palette;

ValueableVector<DigitalDisplayTypeClass*> Buildings_DefaultDigitalDisplayTypes;
ValueableVector<DigitalDisplayTypeClass*> Infantry_DefaultDigitalDisplayTypes;
ValueableVector<DigitalDisplayTypeClass*> Vehicles_DefaultDigitalDisplayTypes;
Expand Down Expand Up @@ -193,6 +198,10 @@ class RulesExt
, DrawTurretShadow { false }
, IsVoiceCreatedGlobal { false }
, SelectionFlashDuration { 0 }
, DrawPowerOffline { false }
, DrawPowerOffline_Offset { { 0, 0 } }
, DrawPowerOffline_Shape { }
, DrawPowerOffline_Palette { }
, AnimRemapDefaultColorScheme { 0 }
, TimerBlinkColorScheme { 5 }
, Buildings_DefaultDigitalDisplayTypes {}
Expand Down
Loading