Skip to content

Commit

Permalink
Adds case to fixup the loaded Rules data due to the change to the def…
Browse files Browse the repository at this point in the history
…ault engineer capture values.
  • Loading branch information
CCHyper committed Dec 29, 2022
1 parent 536649a commit 8ed53c6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 3 deletions.
97 changes: 95 additions & 2 deletions src/extensions/rules/rulesext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "wwcrc.h"
#include "noinit.h"
#include "swizzle.h"
#include "addon.h"
#include "vinifera_saveload.h"
#include "asserthandler.h"
#include "debughandler.h"
Expand Down Expand Up @@ -78,6 +79,18 @@ RulesClassExtension::RulesClassExtension(const RulesClass *this_ptr) :
IsShowSuperWeaponTimers(true)
{
//if (this_ptr) EXT_DEBUG_TRACE("RulesClassExtension::RulesClassExtension - 0x%08X\n", (uintptr_t)(ThisPtr));

/**
* Due to the changes made when addressing issues #632, 633, and 635, we
* need change the default engineer capture values. These values are from
* Red Alert 1, and they match the expected hardcoded behavior of the
* Multi Engineer logic in the release version of Tiberian Sun.
*
* Fixing the default values here ensures Multi-Engineer works in Tiberian Sun
* without manually fixing up the ini data (which is required for Firestorm).
*/
This()->EngineerDamage = 1.0f / 3; // Amount of damage an engineer does.
This()->EngineerCaptureLevel = This()->ConditionRed; // Building damage level before engineer can capture.
}


Expand Down Expand Up @@ -276,7 +289,7 @@ void RulesClassExtension::Process(CCINIClass &ini)
/**
* Fixup various inconsistencies in the original INI files.
*/
Fixups();
Fixups(ini);
}


Expand Down Expand Up @@ -520,8 +533,87 @@ void RulesClassExtension::Check()
*
* @author: CCHyper
*/
void RulesClassExtension::Fixups()
void RulesClassExtension::Fixups(CCINIClass &ini)
{
DEBUG_INFO("Rules::Fixups(enter)\n");

/**
* These are the CRC values for the unmodified ini files, TS2.03EN.
*/
static const int Unmodified_RuleINI_CRC = 0x9F3ECD2A;
static const int Unmodified_FSRuleINI_CRC = 0xA0738E22;

/**
* Constant values to change to.
*/
static const float CorrectEngineerDamage = 0.33f;
static const float CorrectEngineerCaptureLevel = 0.66f;

/**
* Fetch the unique crc values for both rule databases.
*/
int rule_crc = RuleINI->Get_Unique_ID();
DEV_DEBUG_INFO("Rules: RuleINI CRC = %lX\n", rule_crc);

int fsrule_crc = FSRuleINI.Get_Unique_ID();
if (Addon_Installed(ADDON_FIRESTORM)) {
DEV_DEBUG_INFO("Rules: FSRuleINI CRC = %lX\n", fsrule_crc);
}

/**
* Check to see if the ini files have been modified.
*/
bool rule_unmodified = false;
if (rule_crc == Unmodified_RuleINI_CRC) {
DEBUG_INFO("Rules: RuleINI is unmodified (version 2.03).\n");
rule_unmodified = true;
}
bool fsrule_unmodified = false;
if (Addon_Installed(ADDON_FIRESTORM)) {
if (fsrule_crc == Unmodified_FSRuleINI_CRC) {
DEBUG_INFO("Rules: FSRuleINI is unmodified (version 2.03).\n");
fsrule_unmodified = true;
}
}

/**
* Detect which unmodified ini file we are currently processing.
*/
bool is_ruleini = false;
if (ini.Get_Unique_ID() == Unmodified_RuleINI_CRC) {
DEV_DEBUG_INFO("Rules: Current INI is RuleINI.\n");
is_ruleini = true;
}
bool is_fsruleini = false;
if (Addon_Installed(ADDON_FIRESTORM) && ini.Get_Unique_ID() == Unmodified_FSRuleINI_CRC) {
DEV_DEBUG_INFO("Rules: Current INI is FSRuleINI.\n");
is_fsruleini = true;
}

/**
* Fix up the multi engineer values if we have possibly detected the original, unmodified ini databases.
*
* Match criteria;
* - Are we currently processing FSRuleINI?
* - EngineerCaptureLevel is "1.0"
* - EngineerDamage is "0.0"
*/
if (is_fsruleini) {

if (This()->EngineerCaptureLevel == 1.0f && This()->EngineerDamage == 0.0f) {

DEBUG_WARNING("Rules: EngineerCaptureLevel is '%.2f', changing to '%.2f'!\n", This()->EngineerDamage, CorrectEngineerCaptureLevel);
DEBUG_WARNING("Rules: Please consider changing EngineerCaptureLevel to %.2f!\n", CorrectEngineerCaptureLevel);
This()->EngineerCaptureLevel = CorrectEngineerCaptureLevel;

DEBUG_WARNING("Rules: EngineerDamage is '%.2f', changing to '%.2f'!\n", This()->EngineerDamage, CorrectEngineerDamage);
DEBUG_WARNING("Rules: Please consider changing EngineerDamage to %.2f!\n", CorrectEngineerDamage);
This()->EngineerDamage = CorrectEngineerDamage;

}

}

HouseTypeClass *housetype = HouseTypes[HOUSE_NOD];
if (housetype) {

Expand Down Expand Up @@ -583,4 +675,5 @@ void RulesClassExtension::Fixups()

}

DEBUG_INFO("Rules::Fixups(exit)\n");
}
2 changes: 1 addition & 1 deletion src/extensions/rules/rulesext.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class RulesClassExtension final : public GlobalExtensionClass<RulesClass>

private:
void Check();
void Fixups();
void Fixups(CCINIClass &ini);

public:
/**
Expand Down

0 comments on commit 8ed53c6

Please sign in to comment.