From a847b7651d1f6b60c2f6ee786b215034f79cd49a Mon Sep 17 00:00:00 2001 From: Fryone Date: Sun, 16 Jul 2023 13:41:06 +0300 Subject: [PATCH 01/21] Initial commit --- CREDITS.md | 1 + docs/Fixed-or-Improved-Logics.md | 12 +++++++ src/Ext/Rules/Body.cpp | 5 +++ src/Ext/Rules/Body.h | 5 +++ src/Ext/Techno/Hooks.cpp | 55 ++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+) diff --git a/CREDITS.md b/CREDITS.md index 24ea6547d7..103936123a 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -284,6 +284,7 @@ This page lists all the individual contributions to the project by their author. - Vehicle voxel turret shadows & body multi-section shadows - **Fryone** - Customizable ElectricBolt Arcs + - Offline power plant indicator - **Ares developers** - YRpp and Syringe which are used, save/load, project foundation and generally useful code from Ares - unfinished RadTypes code diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index fe358b8091..994812ac2b 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -272,6 +272,18 @@ In `rulesmd.ini`: SellBuildupLength=23 ; integer, number of buildup frames to play ``` +### Offline power plant indicator + +- If `DrawPowerOffline` is set, `POWEROFF.SHP` indicator will appear on power plants when being infiltrated or drained. +- `DrawPowerOffline.Offset` is used to vertically adjust position of indicator. + +In `rulesmd.ini`: +```ini +[AudioVisual] +DrawPowerOffline=false ; boolean +DrawPowerOffline.Offset=0 ; integer, vertical offset, +``` + ## Projectiles ### Cluster scatter distance customization diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index 454c401871..fde8f5bba0 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -104,6 +104,9 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) this->RadialIndicatorVisibility.Read(exINI, GameStrings::AudioVisual, "RadialIndicatorVisibility"); this->DrawTurretShadow.Read(exINI, GameStrings::AudioVisual, "DrawTurretShadow"); + this->DrawPowerOffline.Read(exINI, GameStrings::AudioVisual, "DrawPowerOffline"); + this->DrawPowerOffline_Offset.Read(exINI, GameStrings::AudioVisual, "DrawPowerOffline.Offset"); + this->AllowParallelAIQueues.Read(exINI, "GlobalControls", "AllowParallelAIQueues"); this->ForbidParallelAIQueues_Aircraft.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Infantry"); this->ForbidParallelAIQueues_Building.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Building"); @@ -247,6 +250,8 @@ void RulesExt::ExtData::Serialize(T& Stm) .Process(this->CrateOnlyOnLand) .Process(this->RadialIndicatorVisibility) .Process(this->DrawTurretShadow) + .Process(this->DrawPowerOffline) + .Process(this->DrawPowerOffline_Offset) .Process(this->Buildings_DefaultDigitalDisplayTypes) .Process(this->Infantry_DefaultDigitalDisplayTypes) .Process(this->Vehicles_DefaultDigitalDisplayTypes) diff --git a/src/Ext/Rules/Body.h b/src/Ext/Rules/Body.h index d5768bfa5f..2a5bdb0220 100644 --- a/src/Ext/Rules/Body.h +++ b/src/Ext/Rules/Body.h @@ -89,6 +89,9 @@ class RulesExt Valueable RadialIndicatorVisibility; Valueable DrawTurretShadow; + Valueable DrawPowerOffline; + Valueable DrawPowerOffline_Offset; + ValueableVector Buildings_DefaultDigitalDisplayTypes; ValueableVector Infantry_DefaultDigitalDisplayTypes; ValueableVector Vehicles_DefaultDigitalDisplayTypes; @@ -145,6 +148,8 @@ class RulesExt , CrateOnlyOnLand { false } , RadialIndicatorVisibility { AffectedHouse::Allies } , DrawTurretShadow { false } + , DrawPowerOffline { false } + , DrawPowerOffline_Offset { 0 } , Buildings_DefaultDigitalDisplayTypes {} , Infantry_DefaultDigitalDisplayTypes {} , Vehicles_DefaultDigitalDisplayTypes {} diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index cf2d142f09..1df9c484fc 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -1,4 +1,7 @@ + +#include #include +#include #include "Body.h" #include @@ -604,3 +607,55 @@ DEFINE_HOOK(0x51BAFB, InfantryClass_ChronoSparkleDelay, 0x5) R->ECX(RulesExt::Global()->ChronoSparkleDisplayDelay); return 0x51BB00; } + +//Addition to Ares' Extras +DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) +{ + GET(TechnoClass*, pThis, EBP); + GET_STACK(RectangleStruct*, pRect, 0xA0); + + if(auto pBld = abstract_cast(pThis)) + { + bool drawPowOffline = RulesExt::Global()->DrawPowerOffline; + if(!drawPowOffline) + { + R->ESI(pRect); + return 0x6F534E; + } + + bool showLowPower = FileSystem::POWEROFF_SHP + && (pBld->Type->PowerBonus > 0) + && (pBld->Factory == nullptr) + && (pBld->IsPowerOnline() == false || pBld->IsBeingDrained()) + && (pBld->IsBeingWarpedOut() == false) + && (pBld->WarpingOut == false) + && (pBld->CloakState == CloakState::Uncloaked); + + if(showLowPower) { + auto cell = pBld->GetMapCoords(); + + if(!MapClass::Instance->GetCellAt(cell)->IsShrouded()) { + auto crd = pBld->GetRenderCoords(); + + Point2D nPoint; + TacticalClass::Instance->CoordsToClient(crd, &nPoint); + + Point2D ptPower = nPoint; + + ptPower.Y += 22; //wrench offset + ptPower.Y -= RulesExt::Global()->DrawPowerOffline_Offset; + + int speed = GameOptionsClass::Instance->GetAnimSpeed(14) / 4; + if(speed < 2) { + speed = 2; + } + + int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; + DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &ptPower, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + + } + } + } + R->ESI(pRect); + return 0x6F534E; +} From f5762288f126a9dc95eff92b54d89b5ea51f5e57 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sun, 16 Jul 2023 14:10:17 +0300 Subject: [PATCH 02/21] Update Whats-New.md --- docs/Whats-New.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Whats-New.md b/docs/Whats-New.md index b16736fb50..b25bb151b5 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -326,6 +326,7 @@ New: - Digital display of HP and SP (by ststl, FlyStar, Saigyouji, JunJacobYoung) - PipScale pip size & ammo pip frame customization (by Starkku) - Additional sync logging in case of desync errors occuring (by Starkku) +- Offline power plant indicator (by Fryone) Vanilla fixes: - Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy) From 12edf3cf03459668932124db7632c2c7ca55d6c6 Mon Sep 17 00:00:00 2001 From: Fryone Date: Tue, 18 Jul 2023 21:14:32 +0300 Subject: [PATCH 03/21] Updated conditions - Buildup/Sellup fix - Tech Power Plants excluded --- src/Ext/Techno/Hooks.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index 1df9c484fc..86ad40b9c2 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -629,6 +629,8 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) && (pBld->IsPowerOnline() == false || pBld->IsBeingDrained()) && (pBld->IsBeingWarpedOut() == false) && (pBld->WarpingOut == false) + && (pBld->Type->NeedsEngineer == false) + && ((pBld->GetCurrentMission() != Mission::Selling) && (pBld->GetCurrentMission() != Mission::Construction)) && (pBld->CloakState == CloakState::Uncloaked); if(showLowPower) { From 03bd8040dba8cd033e27e2d6f91d5def96ff2067 Mon Sep 17 00:00:00 2001 From: Fryone Date: Fri, 21 Jul 2023 18:50:22 +0300 Subject: [PATCH 04/21] Added disabler added disabler per building type --- docs/Fixed-or-Improved-Logics.md | 8 +++-- src/Ext/Building/Hooks.cpp | 55 ++++++++++++++++++++++++++++++++ src/Ext/BuildingType/Body.cpp | 2 ++ src/Ext/BuildingType/Body.h | 2 ++ src/Ext/Techno/Hooks.cpp | 54 ------------------------------- 5 files changed, 65 insertions(+), 56 deletions(-) diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 994812ac2b..f2e3905f99 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -276,12 +276,16 @@ SellBuildupLength=23 ; integer, number of buildup frames to play - If `DrawPowerOffline` is set, `POWEROFF.SHP` indicator will appear on power plants when being infiltrated or drained. - `DrawPowerOffline.Offset` is used to vertically adjust position of indicator. +- `DisablePowerOfflineIcon` is used to disable indicator per building type. In `rulesmd.ini`: ```ini [AudioVisual] -DrawPowerOffline=false ; boolean -DrawPowerOffline.Offset=0 ; integer, vertical offset, +DrawPowerOffline=false ; boolean +DrawPowerOffline.Offset=0 ; integer, vertical offset, + +[SOMEBUILDING] +DisablePowerOfflineIcon=false ; boolean ``` ## Projectiles diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index a08f9061a4..e7493c47ea 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -430,3 +430,58 @@ 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); + + if(auto pBld = abstract_cast(pThis)) + { + bool drawPowOffline = RulesExt::Global()->DrawPowerOffline; + if(!drawPowOffline) + { + R->ESI(pRect); + return 0x6F534E; + } + + const auto pBldExt = BuildingTypeExt::ExtMap.Find(pBld->Type); + bool showLowPower = FileSystem::POWEROFF_SHP + && (pBld->Type->PowerBonus > 0) + && (pBld->Factory == nullptr) + && (pBld->IsPowerOnline() == false || pBld->IsBeingDrained()) + && (pBld->IsBeingWarpedOut() == false) + && (pBld->WarpingOut == false) + && (pBldExt->DisablePowerOfflineIcon == false) + && ((pBld->GetCurrentMission() != Mission::Selling) && (pBld->GetCurrentMission() != Mission::Construction)) + && (pBld->CloakState == CloakState::Uncloaked); + + if(showLowPower) { + auto cell = pBld->GetMapCoords(); + + if(!MapClass::Instance->GetCellAt(cell)->IsShrouded()) { + auto crd = pBld->GetRenderCoords(); + + Point2D nPoint; + TacticalClass::Instance->CoordsToClient(crd, &nPoint); + + Point2D ptPower = nPoint; + + ptPower.Y += 22; //wrench offset + ptPower.Y -= RulesExt::Global()->DrawPowerOffline_Offset; + + int speed = GameOptionsClass::Instance->GetAnimSpeed(14) / 4; + if(speed < 2) { + speed = 2; + } + + int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; + DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &ptPower, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + + } + } + } + R->ESI(pRect); + return 0x6F534E; +} diff --git a/src/Ext/BuildingType/Body.cpp b/src/Ext/BuildingType/Body.cpp index faebf7bb09..887c8c5d97 100644 --- a/src/Ext/BuildingType/Body.cpp +++ b/src/Ext/BuildingType/Body.cpp @@ -146,6 +146,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"); // Ares tag this->SpyEffect_Custom.Read(exINI, pSection, "SpyEffect.Custom"); @@ -233,6 +234,7 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm) .Process(this->ConsideredVehicle) .Process(this->ZShapePointMove_OnBuildup) .Process(this->SellBuildupLength) + .Process(this->DisablePowerOfflineIcon) ; } diff --git a/src/Ext/BuildingType/Body.h b/src/Ext/BuildingType/Body.h index beba93e1c3..ba7874f6a8 100644 --- a/src/Ext/BuildingType/Body.h +++ b/src/Ext/BuildingType/Body.h @@ -60,6 +60,7 @@ class BuildingTypeExt Nullable ConsideredVehicle; Valueable ZShapePointMove_OnBuildup; Valueable SellBuildupLength; + Valueable DisablePowerOfflineIcon; ExtData(BuildingTypeClass* OwnerObject) : Extension(OwnerObject) , PowersUp_Owner { AffectedHouse::Owner } @@ -96,6 +97,7 @@ class BuildingTypeExt , ConsideredVehicle {} , ZShapePointMove_OnBuildup { false } , SellBuildupLength { 23 } + , DisablePowerOfflineIcon { false } { } // Ares 0.A functions diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index 86ad40b9c2..8aab95b401 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -607,57 +607,3 @@ DEFINE_HOOK(0x51BAFB, InfantryClass_ChronoSparkleDelay, 0x5) R->ECX(RulesExt::Global()->ChronoSparkleDisplayDelay); return 0x51BB00; } - -//Addition to Ares' Extras -DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) -{ - GET(TechnoClass*, pThis, EBP); - GET_STACK(RectangleStruct*, pRect, 0xA0); - - if(auto pBld = abstract_cast(pThis)) - { - bool drawPowOffline = RulesExt::Global()->DrawPowerOffline; - if(!drawPowOffline) - { - R->ESI(pRect); - return 0x6F534E; - } - - bool showLowPower = FileSystem::POWEROFF_SHP - && (pBld->Type->PowerBonus > 0) - && (pBld->Factory == nullptr) - && (pBld->IsPowerOnline() == false || pBld->IsBeingDrained()) - && (pBld->IsBeingWarpedOut() == false) - && (pBld->WarpingOut == false) - && (pBld->Type->NeedsEngineer == false) - && ((pBld->GetCurrentMission() != Mission::Selling) && (pBld->GetCurrentMission() != Mission::Construction)) - && (pBld->CloakState == CloakState::Uncloaked); - - if(showLowPower) { - auto cell = pBld->GetMapCoords(); - - if(!MapClass::Instance->GetCellAt(cell)->IsShrouded()) { - auto crd = pBld->GetRenderCoords(); - - Point2D nPoint; - TacticalClass::Instance->CoordsToClient(crd, &nPoint); - - Point2D ptPower = nPoint; - - ptPower.Y += 22; //wrench offset - ptPower.Y -= RulesExt::Global()->DrawPowerOffline_Offset; - - int speed = GameOptionsClass::Instance->GetAnimSpeed(14) / 4; - if(speed < 2) { - speed = 2; - } - - int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; - DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &ptPower, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); - - } - } - } - R->ESI(pRect); - return 0x6F534E; -} From 183e5daa005a0554f7f312fdc8dac33cde718350 Mon Sep 17 00:00:00 2001 From: Fryone Date: Tue, 8 Aug 2023 16:56:29 +0300 Subject: [PATCH 05/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index e7493c47ea..ab54088acc 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -439,8 +439,7 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) if(auto pBld = abstract_cast(pThis)) { - bool drawPowOffline = RulesExt::Global()->DrawPowerOffline; - if(!drawPowOffline) + if (!RulesExt::Global()->DrawPowerOffline) { R->ESI(pRect); return 0x6F534E; From 12f6034d7de1fe0b1cd80e42361dcc3375f78d4d Mon Sep 17 00:00:00 2001 From: Fryone Date: Tue, 8 Aug 2023 17:06:08 +0300 Subject: [PATCH 06/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index ab54088acc..ced665c0ff 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -456,30 +456,21 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) && ((pBld->GetCurrentMission() != Mission::Selling) && (pBld->GetCurrentMission() != Mission::Construction)) && (pBld->CloakState == CloakState::Uncloaked); - if(showLowPower) { - auto cell = pBld->GetMapCoords(); - - if(!MapClass::Instance->GetCellAt(cell)->IsShrouded()) { - auto crd = pBld->GetRenderCoords(); - - Point2D nPoint; - TacticalClass::Instance->CoordsToClient(crd, &nPoint); - - Point2D ptPower = nPoint; - - ptPower.Y += 22; //wrench offset - ptPower.Y -= RulesExt::Global()->DrawPowerOffline_Offset; + if (!showLowPower || MapClass::Instance->GetCellAt(pBld->GetMapCoords())->IsShrouded()) + { + R->ESI(pRect); + return 0x6F534E; + } - int speed = GameOptionsClass::Instance->GetAnimSpeed(14) / 4; - if(speed < 2) { - speed = 2; - } + Point2D nPoint; + TacticalClass::Instance->CoordsToClient(pBld->GetRenderCoords(), &nPoint); - int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; - DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &ptPower, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + nPoint.Y += 22; // wrench offset + nPoint.Y -= RulesExt::Global()->DrawPowerOffline_Offset; - } - } + const int speed = max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); + const int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; + DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } R->ESI(pRect); return 0x6F534E; From cd450a8bd1672236005215ac7c51bff0e1504f31 Mon Sep 17 00:00:00 2001 From: Fryone Date: Tue, 8 Aug 2023 17:07:54 +0300 Subject: [PATCH 07/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index ced665c0ff..a64d8516ea 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -446,13 +446,13 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) } const auto pBldExt = BuildingTypeExt::ExtMap.Find(pBld->Type); - bool showLowPower = FileSystem::POWEROFF_SHP + bool showLowPower = (pBldExt->DisablePowerOfflineIcon == false) + && FileSystem::POWEROFF_SHP && (pBld->Type->PowerBonus > 0) && (pBld->Factory == nullptr) && (pBld->IsPowerOnline() == false || pBld->IsBeingDrained()) && (pBld->IsBeingWarpedOut() == false) && (pBld->WarpingOut == false) - && (pBldExt->DisablePowerOfflineIcon == false) && ((pBld->GetCurrentMission() != Mission::Selling) && (pBld->GetCurrentMission() != Mission::Construction)) && (pBld->CloakState == CloakState::Uncloaked); From f50a97ab8258b0bdbfa2b1a0558c7f48971fd75f Mon Sep 17 00:00:00 2001 From: Fryone Date: Tue, 8 Aug 2023 17:23:22 +0300 Subject: [PATCH 08/21] Fixes --- docs/Fixed-or-Improved-Logics.md | 2 +- src/Ext/Building/Hooks.cpp | 2 +- src/Ext/Techno/Hooks.cpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index d17d97ea83..0b1a7adaf9 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -281,7 +281,7 @@ SellBuildupLength=23 ; integer, number of buildup frames to play ### Offline power plant indicator -- If `DrawPowerOffline` is set, `POWEROFF.SHP` indicator will appear on power plants when being infiltrated or drained. +- If `DrawPowerOffline` is set, `POWEROFF.SHP` 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 vertically adjust position of indicator. - `DisablePowerOfflineIcon` is used to disable indicator per building type. diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index a64d8516ea..77c70d221e 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -468,7 +468,7 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) nPoint.Y += 22; // wrench offset nPoint.Y -= RulesExt::Global()->DrawPowerOffline_Offset; - const int speed = max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); + const int speed = Math::max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); const int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index 8aab95b401..2017bfffe7 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -1,6 +1,5 @@ #include -#include #include #include "Body.h" From 25562b320b7f25016cf24a3d09606062b67f263c Mon Sep 17 00:00:00 2001 From: Fryone Date: Tue, 8 Aug 2023 17:25:25 +0300 Subject: [PATCH 09/21] Update Whats-New.md --- docs/Whats-New.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/Whats-New.md b/docs/Whats-New.md index d62361de25..33ac339e21 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -325,7 +325,6 @@ New: - Script action to Chronoshift teams to enemy base (by Starkku) - Digital display of HP and SP (by ststl, FlyStar, Saigyouji, JunJacobYoung) - PipScale pip size & ammo pip frame customization (by Starkku) -- Additional sync logging in case of desync errors occuring (by Starkku) - `AltPalette` lighting toggle (by Starkku) - Unhardcoded timer blinking color scheme (by Starkku) - Customizing shield self-healing timer restart when shield is damaged (by Starkku) From 3b4a132fff74a9aa2f5c278e28337e6187fa2f82 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 26 Aug 2023 21:36:05 +0300 Subject: [PATCH 10/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index 77c70d221e..d0939773e5 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -431,7 +431,7 @@ DEFINE_HOOK(0x4511D6, BuildingClass_AnimationAI_SellBuildup, 0x7) return pTypeExt->SellBuildupLength == pThis->Animation.Value ? Continue : Skip; } -//Addition to Ares' Extras +// Addition to Ares' Extras DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) { GET(TechnoClass*, pThis, EBP); From 1d61437cc6cc9770d5fed3c6b1146933b44199ae Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 26 Aug 2023 21:36:43 +0300 Subject: [PATCH 11/21] Update src/Ext/Techno/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Techno/Hooks.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index b0caaa11af..3bf21202ab 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -1,4 +1,3 @@ - #include #include #include "Body.h" From 11fa48c17ceae6d0544cabf75c31aca616ab2b5a Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 26 Aug 2023 21:37:42 +0300 Subject: [PATCH 12/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index d0939773e5..5aa2727293 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -437,8 +437,15 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) GET(TechnoClass*, pThis, EBP); GET_STACK(RectangleStruct*, pRect, 0xA0); - if(auto pBld = abstract_cast(pThis)) + auto exit = [pRect]() { + R->ESI(pRect); + return 0x6F534E + }; + + const auto pBld = abstract_cast(pThis) + if (!pBld) + return exit(); if (!RulesExt::Global()->DrawPowerOffline) { R->ESI(pRect); From 36f65381922f403c6a380a7a1bc804ddbb8dd02d Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 26 Aug 2023 21:37:53 +0300 Subject: [PATCH 13/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index 5aa2727293..f191ee1484 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -447,10 +447,7 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) if (!pBld) return exit(); if (!RulesExt::Global()->DrawPowerOffline) - { - R->ESI(pRect); - return 0x6F534E; - } + return exit(); const auto pBldExt = BuildingTypeExt::ExtMap.Find(pBld->Type); bool showLowPower = (pBldExt->DisablePowerOfflineIcon == false) From a0430ba4cac818b24a1f981b7e743a3ec4488dc9 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 26 Aug 2023 21:38:00 +0300 Subject: [PATCH 14/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index f191ee1484..ba6a267d17 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -461,10 +461,7 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) && (pBld->CloakState == CloakState::Uncloaked); if (!showLowPower || MapClass::Instance->GetCellAt(pBld->GetMapCoords())->IsShrouded()) - { - R->ESI(pRect); - return 0x6F534E; - } + return exit(); Point2D nPoint; TacticalClass::Instance->CoordsToClient(pBld->GetRenderCoords(), &nPoint); From 0b3a1604bd0ddc987be0c4ecd3880220a497e943 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 26 Aug 2023 21:38:11 +0300 Subject: [PATCH 15/21] Update src/Ext/Building/Hooks.cpp Co-authored-by: MortonPL --- src/Ext/Building/Hooks.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index ba6a267d17..e616da8f2f 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -472,7 +472,6 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) const int speed = Math::max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); const int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); - } - R->ESI(pRect); - return 0x6F534E; + + return exit(); } From 96330563ed3fe5187cd8a9f1aa27f8543c6a7e31 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 26 Aug 2023 21:38:18 +0300 Subject: [PATCH 16/21] Update docs/Fixed-or-Improved-Logics.md Co-authored-by: MortonPL --- docs/Fixed-or-Improved-Logics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 0b1a7adaf9..515f233125 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -289,7 +289,7 @@ In `rulesmd.ini`: ```ini [AudioVisual] DrawPowerOffline=false ; boolean -DrawPowerOffline.Offset=0 ; integer, vertical offset, +DrawPowerOffline.Offset=0 ; integer, vertical offset [SOMEBUILDING] DisablePowerOfflineIcon=false ; boolean From 9d2f4cd06493d0d65ae5345c3cb8213792899968 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sun, 27 Aug 2023 19:13:05 +0300 Subject: [PATCH 17/21] Custom shape param --- docs/Fixed-or-Improved-Logics.md | 8 ++++--- src/Ext/Building/Hooks.cpp | 40 +++++++++++++++++++------------- src/Ext/Rules/Body.cpp | 2 ++ src/Ext/Rules/Body.h | 6 +++-- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 2e83167818..145fc869c8 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -281,15 +281,17 @@ SellBuildupLength=23 ; integer, number of buildup frames to play ### Offline power plant indicator -- If `DrawPowerOffline` is set, `POWEROFF.SHP` 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 vertically adjust position of 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 name of shape used to draw indicator in `MOUSE.PAL` palette. `POWEROFF.SHP` 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.Offset=0 ; integer, vertical offset +DrawPowerOffline.Shape= ; shape name without .shp extension +DrawPowerOffline.Offset=0,0 ; integer, offset [SOMEBUILDING] DisablePowerOfflineIcon=false ; boolean diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index e616da8f2f..829ed4b15e 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -436,22 +436,26 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) { GET(TechnoClass*, pThis, EBP); GET_STACK(RectangleStruct*, pRect, 0xA0); + Point2D pict_offset = RulesExt::Global()->DrawPowerOffline_Offset; - auto exit = [pRect]() + ConvertClass* pPalette = FileSystem::MOUSE_PAL; + SHPStruct* pSHP = RulesExt::Global()->DrawPowerOffline_Shape ? RulesExt::Global()->DrawPowerOffline_Shape : FileSystem::POWEROFF_SHP; + + const auto pBld = abstract_cast(pThis); + if (!pBld) { R->ESI(pRect); - return 0x6F534E - }; - - const auto pBld = abstract_cast(pThis) - if (!pBld) - return exit(); - if (!RulesExt::Global()->DrawPowerOffline) - return exit(); + return 0x6F534E; + } + if (!RulesExt::Global()->DrawPowerOffline) + { + R->ESI(pRect); + return 0x6F534E; + } const auto pBldExt = BuildingTypeExt::ExtMap.Find(pBld->Type); bool showLowPower = (pBldExt->DisablePowerOfflineIcon == false) - && FileSystem::POWEROFF_SHP + && pSHP && (pBld->Type->PowerBonus > 0) && (pBld->Factory == nullptr) && (pBld->IsPowerOnline() == false || pBld->IsBeingDrained()) @@ -461,17 +465,21 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) && (pBld->CloakState == CloakState::Uncloaked); if (!showLowPower || MapClass::Instance->GetCellAt(pBld->GetMapCoords())->IsShrouded()) - return exit(); + { + R->ESI(pRect); + return 0x6F534E; + } Point2D nPoint; TacticalClass::Instance->CoordsToClient(pBld->GetRenderCoords(), &nPoint); - nPoint.Y += 22; // wrench offset - nPoint.Y -= RulesExt::Global()->DrawPowerOffline_Offset; + nPoint.Y += 22 + pict_offset.X; // wrench offset + nPoint.Y -= pict_offset.Y; const int speed = Math::max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); - const int frame = (FileSystem::POWEROFF_SHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; - DSurface::Temp->DrawSHP(FileSystem::MOUSE_PAL, FileSystem::POWEROFF_SHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + const int frame = (pSHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; + DSurface::Temp->DrawSHP(pPalette, pSHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); - return exit(); + R->ESI(pRect); + return 0x6F534E; } diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index 7b98824507..5e56da4814 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -110,6 +110,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) 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->AllowParallelAIQueues.Read(exINI, "GlobalControls", "AllowParallelAIQueues"); this->ForbidParallelAIQueues_Aircraft.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Infantry"); @@ -258,6 +259,7 @@ void RulesExt::ExtData::Serialize(T& Stm) .Process(this->DrawTurretShadow) .Process(this->DrawPowerOffline) .Process(this->DrawPowerOffline_Offset) + .Process(this->DrawPowerOffline_Shape) .Process(this->AnimRemapDefaultColorScheme) .Process(this->TimerBlinkColorScheme) .Process(this->Buildings_DefaultDigitalDisplayTypes) diff --git a/src/Ext/Rules/Body.h b/src/Ext/Rules/Body.h index c999fe5aec..4014c1c493 100644 --- a/src/Ext/Rules/Body.h +++ b/src/Ext/Rules/Body.h @@ -94,7 +94,8 @@ class RulesExt ValueableIdx TimerBlinkColorScheme; Valueable DrawPowerOffline; - Valueable DrawPowerOffline_Offset; + Valueable DrawPowerOffline_Offset; + Nullable DrawPowerOffline_Shape; ValueableVector Buildings_DefaultDigitalDisplayTypes; ValueableVector Infantry_DefaultDigitalDisplayTypes; @@ -155,7 +156,8 @@ class RulesExt , RadialIndicatorVisibility { AffectedHouse::Allies } , DrawTurretShadow { false } , DrawPowerOffline { false } - , DrawPowerOffline_Offset { 0 } + , DrawPowerOffline_Offset { { 0, 0 } } + , DrawPowerOffline_Shape { } , AnimRemapDefaultColorScheme { 0 } , TimerBlinkColorScheme { 5 } , Buildings_DefaultDigitalDisplayTypes {} From afa3759b9e911da06af5f34eb9d7a34a81db0d93 Mon Sep 17 00:00:00 2001 From: Fryone Date: Mon, 28 Aug 2023 19:43:54 +0300 Subject: [PATCH 18/21] Small fixes --- src/Ext/Building/Hooks.cpp | 58 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index 829ed4b15e..f90a8f8dfa 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -436,7 +436,7 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) { GET(TechnoClass*, pThis, EBP); GET_STACK(RectangleStruct*, pRect, 0xA0); - Point2D pict_offset = RulesExt::Global()->DrawPowerOffline_Offset; + Point2D pictOffset = RulesExt::Global()->DrawPowerOffline_Offset; ConvertClass* pPalette = FileSystem::MOUSE_PAL; SHPStruct* pSHP = RulesExt::Global()->DrawPowerOffline_Shape ? RulesExt::Global()->DrawPowerOffline_Shape : FileSystem::POWEROFF_SHP; @@ -448,37 +448,37 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) return 0x6F534E; } - if (!RulesExt::Global()->DrawPowerOffline) - { - R->ESI(pRect); - return 0x6F534E; - } - const auto pBldExt = BuildingTypeExt::ExtMap.Find(pBld->Type); - bool showLowPower = (pBldExt->DisablePowerOfflineIcon == false) - && pSHP - && (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()) - { - R->ESI(pRect); - return 0x6F534E; - } + if (!RulesExt::Global()->DrawPowerOffline) + { + R->ESI(pRect); + return 0x6F534E; + } + const auto pTypeExt = BuildingTypeExt::ExtMap.Find(pBld->Type); + bool showLowPower = (pTypeExt->DisablePowerOfflineIcon == false) + && pSHP + && (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()) + { + R->ESI(pRect); + return 0x6F534E; + } - Point2D nPoint; - TacticalClass::Instance->CoordsToClient(pBld->GetRenderCoords(), &nPoint); + Point2D nPoint; + TacticalClass::Instance->CoordsToClient(pBld->GetRenderCoords(), &nPoint); - nPoint.Y += 22 + pict_offset.X; // wrench offset - nPoint.Y -= pict_offset.Y; + nPoint.Y += 22 + pictOffset.X; // wrench offset + nPoint.Y -= pictOffset.Y; - const int speed = Math::max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); - const int frame = (pSHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; - DSurface::Temp->DrawSHP(pPalette, pSHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + const int speed = Math::max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); + const int frame = (pSHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; + DSurface::Temp->DrawSHP(pPalette, pSHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); R->ESI(pRect); return 0x6F534E; From 047f17a22721aea5b35bef32c1eba4d0ddb03d2a Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 7 Oct 2023 15:23:25 +0300 Subject: [PATCH 19/21] Update Hooks.cpp --- src/Ext/Building/Hooks.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index f90a8f8dfa..293191666b 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -438,6 +438,8 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) GET_STACK(RectangleStruct*, pRect, 0xA0); Point2D pictOffset = RulesExt::Global()->DrawPowerOffline_Offset; + //CustomPalette custPal = RulesExt::Global()->DrawPowerOffline_Palette; + ConvertClass* pPalette = FileSystem::MOUSE_PAL; SHPStruct* pSHP = RulesExt::Global()->DrawPowerOffline_Shape ? RulesExt::Global()->DrawPowerOffline_Shape : FileSystem::POWEROFF_SHP; From 64bbaa856f4d75a9859b78e953471a88f637b076 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 18 May 2024 14:06:52 +0300 Subject: [PATCH 20/21] rework update - palette support - moved code from techno to buildings ext --- docs/Fixed-or-Improved-Logics.md | 4 +++- src/Ext/Building/Body.cpp | 10 ++++++++++ src/Ext/Building/Body.h | 2 ++ src/Ext/Building/Hooks.cpp | 18 +++--------------- src/Ext/Rules/Body.cpp | 2 +- src/Ext/Rules/Body.h | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 5683cc661d..3cb201ad9b 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -352,7 +352,8 @@ SellBuildupLength=23 ; integer, number of buildup frames to play - 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 name of shape used to draw indicator in `MOUSE.PAL` palette. `POWEROFF.SHP` is used by default if not set. +- `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`: @@ -360,6 +361,7 @@ In `rulesmd.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] diff --git a/src/Ext/Building/Body.cpp b/src/Ext/Building/Body.cpp index 07a52c24fe..5a4d10f6b2 100644 --- a/src/Ext/Building/Body.cpp +++ b/src/Ext/Building/Body.cpp @@ -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 diff --git a/src/Ext/Building/Body.h b/src/Ext/Building/Body.h index 5f20ae79f2..f5179fe431 100644 --- a/src/Ext/Building/Body.h +++ b/src/Ext/Building/Body.h @@ -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); }; diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index 1477d954fa..be0a7ed5a0 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -424,12 +424,6 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) { GET(TechnoClass*, pThis, EBP); GET_STACK(RectangleStruct*, pRect, 0xA0); - Point2D pictOffset = RulesExt::Global()->DrawPowerOffline_Offset; - - //CustomPalette custPal = RulesExt::Global()->DrawPowerOffline_Palette; - - ConvertClass* pPalette = FileSystem::MOUSE_PAL; - SHPStruct* pSHP = RulesExt::Global()->DrawPowerOffline_Shape ? RulesExt::Global()->DrawPowerOffline_Shape : FileSystem::POWEROFF_SHP; const auto pBld = abstract_cast(pThis); if (!pBld) @@ -443,9 +437,9 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) R->ESI(pRect); return 0x6F534E; } + const auto pTypeExt = BuildingTypeExt::ExtMap.Find(pBld->Type); bool showLowPower = (pTypeExt->DisablePowerOfflineIcon == false) - && pSHP && (pBld->Type->PowerBonus > 0) && (pBld->Factory == nullptr) && (pBld->IsPowerOnline() == false || pBld->IsBeingDrained()) @@ -460,15 +454,9 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) return 0x6F534E; } - Point2D nPoint; - TacticalClass::Instance->CoordsToClient(pBld->GetRenderCoords(), &nPoint); - - nPoint.Y += 22 + pictOffset.X; // wrench offset - nPoint.Y -= pictOffset.Y; - + Point2D nPoint = TacticalClass::Instance->CoordsToClient(pBld->GetCenterCoords()).first; const int speed = Math::max(GameOptionsClass::Instance->GetAnimSpeed(14) / 4, 2); - const int frame = (pSHP->Frames * (Unsorted::CurrentFrame % speed)) / speed; - DSurface::Temp->DrawSHP(pPalette, pSHP, frame, &nPoint, pRect, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + BuildingExt::DrawOfflinePlantIndicator(&nPoint, pRect, speed); R->ESI(pRect); return 0x6F534E; diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index 65f645e29e..960ddd5000 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -128,7 +128,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) 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.Read(exINI, GameStrings::AudioVisual, "DrawPowerOffline.Palette"); + this->DrawPowerOffline_Palette.LoadFromINI(pINI, GameStrings::AudioVisual, "DrawPowerOffline.Palette"); this->AllowParallelAIQueues.Read(exINI, "GlobalControls", "AllowParallelAIQueues"); this->ForbidParallelAIQueues_Aircraft.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Infantry"); diff --git a/src/Ext/Rules/Body.h b/src/Ext/Rules/Body.h index 0818e8b660..ecd5fd86d4 100644 --- a/src/Ext/Rules/Body.h +++ b/src/Ext/Rules/Body.h @@ -113,7 +113,7 @@ class RulesExt Valueable DrawPowerOffline; Valueable DrawPowerOffline_Offset; Nullable DrawPowerOffline_Shape; - Nullable<*> DrawPowerOffline_Palette; + CustomPalette DrawPowerOffline_Palette; ValueableVector Buildings_DefaultDigitalDisplayTypes; ValueableVector Infantry_DefaultDigitalDisplayTypes; From 99c82c24519a473a096803b736225c4596e300d4 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 18 May 2024 15:21:10 +0300 Subject: [PATCH 21/21] Update Hooks.cpp --- src/Ext/Building/Hooks.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Ext/Building/Hooks.cpp b/src/Ext/Building/Hooks.cpp index be0a7ed5a0..a7917befb5 100644 --- a/src/Ext/Building/Hooks.cpp +++ b/src/Ext/Building/Hooks.cpp @@ -426,17 +426,17 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) GET_STACK(RectangleStruct*, pRect, 0xA0); const auto pBld = abstract_cast(pThis); - if (!pBld) + auto exit = [R, pRect]() { R->ESI(pRect); return 0x6F534E; - } + }; + + if (!pBld) + return exit(); if (!RulesExt::Global()->DrawPowerOffline) - { - R->ESI(pRect); - return 0x6F534E; - } + return exit(); const auto pTypeExt = BuildingTypeExt::ExtMap.Find(pBld->Type); bool showLowPower = (pTypeExt->DisablePowerOfflineIcon == false) @@ -449,15 +449,11 @@ DEFINE_HOOK(0x6F5347, TechnoClass_DrawExtras_OfflinePlants, 0x7) && (pBld->CloakState == CloakState::Uncloaked); if (!showLowPower || MapClass::Instance->GetCellAt(pBld->GetMapCoords())->IsShrouded()) - { - R->ESI(pRect); - return 0x6F534E; - } + 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); - R->ESI(pRect); - return 0x6F534E; + return exit(); }