Skip to content

Commit

Permalink
Implements LowPowerPenaltyModifier for RulesClass.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Mar 28, 2023
1 parent e7e5f99 commit b04a53a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/extensions/rules/rulesext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ RulesClassExtension::RulesClassExtension(const RulesClass *this_ptr) :
IsMPAutoDeployMCV(false),
IsMPPrePlacedConYards(false),
IsBuildOffAlly(true),
IsShowSuperWeaponTimers(true)
IsShowSuperWeaponTimers(true),
LowPowerPenaltyModifier(1.0f)
{
//if (this_ptr) EXT_DEBUG_TRACE("RulesClassExtension::RulesClassExtension - 0x%08X\n", (uintptr_t)(ThisPtr));

Expand Down Expand Up @@ -430,6 +431,8 @@ bool RulesClassExtension::General(CCINIClass &ini)
*/
This()->EngineerDamage = ini.Get_Float(GENERAL, "EngineerDamage", This()->EngineerDamage);

LowPowerPenaltyModifier = ini.Get_Float(GENERAL, "LowPowerPenaltyModifier", LowPowerPenaltyModifier);

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions src/extensions/rules/rulesext.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ class RulesClassExtension final : public GlobalExtensionClass<RulesClass>
* on the tactical view?
*/
bool IsShowSuperWeaponTimers;

/**
* The "double penalty" or "half penalty". Multiply this by the power
* units you are short of to get the actual penalty to the build speed.
*/
float LowPowerPenaltyModifier;
};
12 changes: 12 additions & 0 deletions src/extensions/techno/technoext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
#include "building.h"
#include "buildingtype.h"
#include "rules.h"
#include "rulesext.h"
#include "voc.h"
#include "ebolt.h"
#include "tactical.h"
#include "tibsun_inline.h"
#include "tibsun_globals.h"
#include "extension_globals.h"
#include "wwcrc.h"
#include "extension.h"
#include "asserthandler.h"
Expand Down Expand Up @@ -417,6 +419,16 @@ int TechnoClassExtension::Time_To_Build() const
*/
double power = This()->House->Power_Fraction();
double scale = 1.0f;

/**
* #issue-656
*
* Implements LowPowerPenaltyModifier for RulesClass.
*
* @author: CCHyper
*/
scale = 1.0f - (1.0f - power) * RuleExtension->LowPowerPenaltyModifier;

if (power > 1.0) {
scale = 1.0;

Expand Down

0 comments on commit b04a53a

Please sign in to comment.