Skip to content

Commit

Permalink
rework update
Browse files Browse the repository at this point in the history
- palette support
- moved code from techno to buildings ext
  • Loading branch information
Fryone committed May 18, 2024
1 parent e260985 commit 64bbaa8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,16 @@ 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`:
```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]
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);
};
18 changes: 3 additions & 15 deletions src/Ext/Building/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuildingClass*>(pThis);
if (!pBld)
Expand All @@ -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())
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class RulesExt
Valueable<bool> DrawPowerOffline;
Valueable<Point2D> DrawPowerOffline_Offset;
Nullable<SHPStruct*> DrawPowerOffline_Shape;
Nullable<*> DrawPowerOffline_Palette;
CustomPalette DrawPowerOffline_Palette;

ValueableVector<DigitalDisplayTypeClass*> Buildings_DefaultDigitalDisplayTypes;
ValueableVector<DigitalDisplayTypeClass*> Infantry_DefaultDigitalDisplayTypes;
Expand Down

0 comments on commit 64bbaa8

Please sign in to comment.