Skip to content

Commit

Permalink
[TD] Adds support for [Recharge] section of rules.ini.
Browse files Browse the repository at this point in the history
Also adds support for loading rules from scenario ini files.
  • Loading branch information
OmniBlade committed Jun 26, 2024
1 parent 9fa3ee3 commit f9f4aba
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tiberiandawn/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ void HouseClass::operator delete(void* ptr)
*=============================================================================================*/
HouseClass::HouseClass(HousesType house)
: Class(&HouseTypeClass::As_Reference(house))
, IonCannon(ION_CANNON_GONE_TIME, VOX_ION_READY, VOX_ION_CHARGING, VOX_ION_CHARGING, VOX_NO_POWER)
, AirStrike(AIR_CANNON_GONE_TIME, VOX_AIRSTRIKE_READY, VOX_NONE, VOX_NOT_READY, VOX_NOT_READY)
, NukeStrike(NUKE_GONE_TIME, VOX_NUKE_AVAILABLE, VOX_NONE, VOX_NOT_READY, VOX_NO_POWER)
, IonCannon(TICKS_PER_MINUTE * Rule.IonTime, VOX_ION_READY, VOX_ION_CHARGING, VOX_ION_CHARGING, VOX_NO_POWER)
, AirStrike(TICKS_PER_MINUTE * Rule.AirStrikeTime, VOX_AIRSTRIKE_READY, VOX_NONE, VOX_NOT_READY, VOX_NOT_READY)
, NukeStrike(TICKS_PER_MINUTE * Rule.NukeTime, VOX_NUKE_AVAILABLE, VOX_NONE, VOX_NOT_READY, VOX_NO_POWER)
, AircraftTotals()
, InfantryTotals()
, UnitTotals()
Expand Down
42 changes: 42 additions & 0 deletions tiberiandawn/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ RulesClass::RulesClass(void)
, AllowSuperWeapons(true)
, IsThreePoint(false)
, IsBoxing(false)
, NukeTime(14)
, IonTime(10)
, AirStrikeTime(8)
{
#ifndef REMASTER_BUILD

Expand Down Expand Up @@ -267,6 +270,7 @@ static void Difficulty_Put(CCINIClass& ini, DifficultyClass& diff, char const* s
bool RulesClass::Process(CCINIClass& ini)
{
General(ini);
Recharge(ini);
AI(ini);
IQ(ini);
Difficulty(ini);
Expand All @@ -291,6 +295,7 @@ bool RulesClass::Process(CCINIClass& ini)
bool RulesClass::Export(CCINIClass& ini)
{
Export_General(ini);
Export_Recharge(ini);
Export_AI(ini);
Export_IQ(ini);
Export_Difficulty(ini);
Expand Down Expand Up @@ -337,6 +342,43 @@ bool RulesClass::General(CCINIClass& ini)
return (false);
}

/***********************************************************************************************
* RulesClass::Recharge -- Process the super weapon recharge statistics. *
* *
* Use this to set the recharge times for the various super weapons available. *
* *
* INPUT: ini -- Reference to the database. *
* *
* OUTPUT: bool; Was the recharge section found and processed? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 08/08/1996 JLB : Created. *
*=============================================================================================*/
bool RulesClass::Recharge(CCINIClass& ini)
{
static char const* const RECHARGE = "Recharge";
if (ini.Is_Present(RECHARGE)) {
AirStrikeTime = ini.Get_Fixed(RECHARGE, "AirStrike", AirStrikeTime);
IonTime = ini.Get_Fixed(RECHARGE, "IonCannon", IonTime);
NukeTime = ini.Get_Fixed(RECHARGE, "Nuke", NukeTime);
return (true);
}
return (false);
}

bool RulesClass::Export_Recharge(CCINIClass& ini)
{
static char const RECHARGE[] = "Recharge";

ini.Put_Fixed(RECHARGE, "AirStrike", AirStrikeTime);
ini.Put_Fixed(RECHARGE, "IonCannon", IonTime);
ini.Put_Fixed(RECHARGE, "Nuke", NukeTime);

return (true);
}

/***********************************************************************************************
* RulesClass::General -- Process the general main game rules. *
* *
Expand Down
6 changes: 6 additions & 0 deletions tiberiandawn/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ class RulesClass

bool Process(CCINIClass& file);
bool General(CCINIClass& ini);
bool Recharge(CCINIClass& ini);
bool AI(CCINIClass& ini);
bool IQ(CCINIClass& ini);
bool Difficulty(CCINIClass& ini);
bool Export(CCINIClass& file);
bool Export_General(CCINIClass& ini);
bool Export_Recharge(CCINIClass& ini);
bool Export_AI(CCINIClass& ini);
bool Export_IQ(CCINIClass& ini);
bool Export_Difficulty(CCINIClass& ini);
Expand Down Expand Up @@ -340,6 +342,10 @@ class RulesClass
** this flag is true.
*/
bool IsBoxing;

fixed NukeTime;
fixed IonTime;
fixed AirStrikeTime;
};

bool Is_MCV_Deploy();
Expand Down
35 changes: 35 additions & 0 deletions tiberiandawn/saveload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,41 @@ bool Load_Game(const char* file_name)
#endif

Call_Back();

/*
** Rescan the scenario file for any rules updates.
*/
CCINIClass ini;
CCFileClass scenarioFile(Scen.ScenarioName);
int result = ini.Load(scenarioFile, true);

/*
** Reset the rules values to their initial settings.
*/
Rule.General(RuleINI);
Rule.Recharge(RuleINI);
Rule.AI(RuleINI);
// Rule.Powerups(RuleINI);
// Rule.Land_Types(RuleINI);
// Rule.Themes(RuleINI);
Rule.IQ(RuleINI);
// Rule.Objects(RuleINI);
Rule.Difficulty(RuleINI);

/*
** Override any rules values specified in this
** particular scenario file.
*/
Rule.General(ini);
Rule.Recharge(ini);
Rule.AI(ini);
// Rule.Powerups(RuleINI);
// Rule.Land_Types(RuleINI);
// Rule.Themes(RuleINI);
Rule.IQ(ini);
// Rule.Objects(RuleINI);
Rule.Difficulty(ini);

return (true);
}

Expand Down
48 changes: 48 additions & 0 deletions tiberiandawn/scenarioini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,30 @@ bool Read_Scenario_Ini(char* root, bool fresh)
GlyphX_Debug_Print(fname);
}

Rule.General(RuleINI);
Rule.Recharge(RuleINI);
Rule.AI(RuleINI);
// Rule.Powerups(RuleINI);
// Rule.Land_Types(RuleINI);
// Rule.Themes(RuleINI);
Rule.IQ(RuleINI);
// Rule.Objects(RuleINI);
Rule.Difficulty(RuleINI);

/*
** Override any rules values specified in this
** particular scenario file.
*/
Rule.General(ini);
Rule.Recharge(ini);
Rule.AI(ini);
// Rule.Powerups(RuleINI);
// Rule.Land_Types(RuleINI);
// Rule.Themes(RuleINI);
Rule.IQ(ini);
// Rule.Objects(RuleINI);
Rule.Difficulty(ini);

/*
** Init the Scenario CRC value
*/
Expand Down Expand Up @@ -693,6 +717,30 @@ bool Read_Scenario_Ini_File(char* scenario_file_name, char* bin_file_name, const
GlyphX_Debug_Print(scenario_file_name);
}

Rule.General(RuleINI);
Rule.Recharge(RuleINI);
Rule.AI(RuleINI);
// Rule.Powerups(RuleINI);
// Rule.Land_Types(RuleINI);
// Rule.Themes(RuleINI);
Rule.IQ(RuleINI);
// Rule.Objects(RuleINI);
Rule.Difficulty(RuleINI);

/*
** Override any rules values specified in this
** particular scenario file.
*/
Rule.General(ini);
Rule.Recharge(ini);
Rule.AI(ini);
// Rule.Powerups(RuleINI);
// Rule.Land_Types(RuleINI);
// Rule.Themes(RuleINI);
Rule.IQ(ini);
// Rule.Objects(RuleINI);
Rule.Difficulty(ini);

/*
** Init the Scenario CRC value
*/
Expand Down

0 comments on commit f9f4aba

Please sign in to comment.