Skip to content

Commit dd05d2c

Browse files
committed
power plant damage factor
1 parent 13d71be commit dd05d2c

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
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+
- Customizing power output decrement when a power plant is damaged
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/New-or-Enhanced-Logics.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This page describes all the engine features that are either new and introduced b
3535
- `Tint.VisibleToHouses` can be used to control which houses can see the tint effect.
3636
- `FirepowerMultiplier`, `ArmorMultiplier`, `SpeedMultiplier` and `ROFMultiplier` can be used to modify the object's firepower, armor strength, movement speed and weapon reload rate, respectively.
3737
- `ArmorMultiplier.AllowWarheads` and `ArmorMultiplier.DisallowWarheads` can be used to restrict which Warheads the armor multiplier is applied to when dealing damage.
38-
- If `ROFMultiplier.ApplyOnCurrentTimer` is set to true, `ROFMultiplier` is applied on currently running reload timer (if any) when the effect is first applied.
38+
- If `ROFMultiplier.ApplyOnCurrentTimer` is set to true, `ROFMultiplier` is applied on currently running reload timer (if any) when the effect is first applied.
3939
- If `Cloakable` is set to true, the object the effect is attached to is granted ability to cloak itself for duration of the effect.
4040
- `ForceDecloak`, if set to true, will uncloak and make the object the effect is attached to unable to cloak itself for duration of the effect.
4141
- `WeaponRange.Multiplier` and `WeaponRange.ExtraRange` can be used to multiply the weapon firing range of the object the effect is attached to, or give it an increase / decrease (measured in cells), respectively. `ExtraRange` is cumulatively applied from all attached effects after all `Multiplier` values have been applied.
@@ -554,6 +554,17 @@ In `rulesmd.ini`:
554554
IsDestroyableObstacle=false ; boolean
555555
```
556556

557+
### Power plant damage factor
558+
559+
- It is possible to customize the power decrement of a power plant when it's damaged. The actual power output for this plant will be: `Power` minuses the product of original power decrement and `Powerplant.DamageFactor`. Can't reduce power output lower than 0.
560+
- Specifically, if the factor is set to 0.0, power output won't be decreased by losing health for this power plant.
561+
562+
In `rulesmd.ini`:
563+
```ini
564+
[SOMEBUILDING] ; BuildingType
565+
PowerPlant.DamageFactor=1.0 ; floating point value
566+
```
567+
557568
### Power plant enhancer
558569

559570
- When it exists, it can increase the power amount generated by the power plants.

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+
- Customizing power output decrement when a power plant is damaged (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/BuildingType/Body.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int BuildingTypeExt::ExtData::GetSuperWeaponIndex(const int index) const
4141
return -1;
4242
}
4343

44-
int BuildingTypeExt::GetEnhancedPower(BuildingClass* pBuilding, HouseClass* pHouse)
44+
int BuildingTypeExt::GetEnhancedPower(BuildingClass* pBuilding, HouseClass* pHouse, int power)
4545
{
4646
int nAmount = 0;
4747
float fFactor = 1.0f;
@@ -57,7 +57,7 @@ int BuildingTypeExt::GetEnhancedPower(BuildingClass* pBuilding, HouseClass* pHou
5757
}
5858
}
5959

60-
return static_cast<int>(std::round(pBuilding->GetPowerOutput() * fFactor)) + nAmount;
60+
return static_cast<int>(std::round(power * fFactor)) + nAmount;
6161
}
6262

6363
int BuildingTypeExt::GetUpgradesAmount(BuildingTypeClass* pBuilding, HouseClass* pHouse) // not including producing upgrades
@@ -161,6 +161,8 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
161161
this->Adjacent_Allowed.Read(exINI, pSection, "Adjacent.Allowed");
162162
this->Adjacent_Disallowed.Read(exINI, pSection, "Adjacent.Disallowed");
163163

164+
this->PowerPlant_DamageFactor.Read(exINI, pSection, "PowerPlant.DamageFactor");
165+
164166
if (pThis->NumberOfDocks > 0)
165167
{
166168
this->AircraftDockingDirs.clear();
@@ -283,6 +285,7 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm)
283285
.Process(this->NoBuildAreaOnBuildup)
284286
.Process(this->Adjacent_Allowed)
285287
.Process(this->Adjacent_Disallowed)
288+
.Process(this->PowerPlant_DamageFactor)
286289
;
287290
}
288291

src/Ext/BuildingType/Body.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class BuildingTypeExt
7878
ValueableVector<BuildingTypeClass*> Adjacent_Allowed;
7979
ValueableVector<BuildingTypeClass*> Adjacent_Disallowed;
8080

81+
Valueable<double> PowerPlant_DamageFactor;
82+
8183
ExtData(BuildingTypeClass* OwnerObject) : Extension<BuildingTypeClass>(OwnerObject)
8284
, PowersUp_Owner { AffectedHouse::Owner }
8385
, PowersUp_Buildings {}
@@ -126,6 +128,7 @@ class BuildingTypeExt
126128
, NoBuildAreaOnBuildup { false }
127129
, Adjacent_Allowed {}
128130
, Adjacent_Disallowed {}
131+
, PowerPlant_DamageFactor { 1.0 }
129132
{ }
130133

131134
// Ares 0.A functions
@@ -162,7 +165,7 @@ class BuildingTypeExt
162165
static bool LoadGlobals(PhobosStreamReader& Stm);
163166
static bool SaveGlobals(PhobosStreamWriter& Stm);
164167

165-
static int GetEnhancedPower(BuildingClass* pBuilding, HouseClass* pHouse);
168+
static int GetEnhancedPower(BuildingClass* pBuilding, HouseClass* pHouse, int power);
166169
static bool CanUpgrade(BuildingClass* pBuilding, BuildingTypeClass* pUpgradeType, HouseClass* pUpgradeOwner);
167170
static int GetUpgradesAmount(BuildingTypeClass* pBuilding, HouseClass* pHouse);
168171
};

src/Ext/House/Hooks.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,33 @@ DEFINE_HOOK(0x508C30, HouseClass_UpdatePower_UpdateCounter, 0x5)
3232
return 0;
3333
}
3434

35-
// Power Plant Enhancer #131
3635
DEFINE_HOOK(0x508CF2, HouseClass_UpdatePower_PowerOutput, 0x7)
3736
{
3837
GET(HouseClass*, pThis, ESI);
3938
GET(BuildingClass*, pBld, EDI);
4039

41-
pThis->PowerOutput += BuildingTypeExt::GetEnhancedPower(pBld, pThis);
40+
int power = pBld->GetPowerOutput();
41+
42+
if (!pBld->Deactivated && !pBld->IsUnderEMP() && !pBld->IsBeingDrained())
43+
{
44+
const auto pType = pBld->Type;
45+
const double factor = BuildingTypeExt::ExtMap.Find(pType)->PowerPlant_DamageFactor;
46+
47+
if (factor != 1.0)
48+
{
49+
double powerOutput = static_cast<double>(pType->PowerBonus - pType->PowerDrain);
50+
51+
for (const auto& pUpgrade : pBld->Upgrades)
52+
{
53+
if (pUpgrade && pUpgrade->PowerBonus > 0)
54+
powerOutput += (pUpgrade->PowerBonus - pUpgrade->PowerDrain);
55+
}
56+
57+
power = Math::max(static_cast<int>(std::round(powerOutput - (powerOutput - power) * factor)), 0);
58+
}
59+
}
60+
61+
pThis->PowerOutput += BuildingTypeExt::GetEnhancedPower(pBld, pThis, power);
4262

4363
return 0x508D07;
4464
}

0 commit comments

Comments
 (0)