Skip to content

Commit

Permalink
Load rules ini on scenario start instead of only game start, this fix…
Browse files Browse the repository at this point in the history
…es isse with not all RulesClass data resetting after loading a mod map
  • Loading branch information
Maikel authored and OmniBlade committed Jun 19, 2024
1 parent 3fe4c5d commit 2185010
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 182 deletions.
2 changes: 1 addition & 1 deletion redalert/aadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ AircraftType AircraftTypeClass::From_Name(char const* name)
* HISTORY: *
* 07/26/1994 JLB : Created. *
*=============================================================================================*/
void AircraftTypeClass::One_Time(void)
void AircraftTypeClass::Init_Clear(void)
{
for (int index = AIRCRAFT_FIRST; index < AIRCRAFT_COUNT; index++) {
char fullname[_MAX_FNAME + _MAX_EXT];
Expand Down
24 changes: 11 additions & 13 deletions redalert/adata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ void AnimTypeClass::Init_Heap(void)
* HISTORY: *
* 06/02/1994 JLB : Created. *
*=============================================================================================*/
void AnimTypeClass::One_Time(void)
void AnimTypeClass::Init_Clear(void)
{
for (int index = ANIM_FIRST; index < ANIM_COUNT; index++) {
char fullname[_MAX_FNAME + _MAX_EXT];
Expand Down Expand Up @@ -2436,22 +2436,20 @@ void AnimTypeClass::One_Time(void)
*=============================================================================================*/
void AnimTypeClass::Init(TheaterType theater)
{
if (theater != LastTheater) {
for (int index = ANIM_FIRST; index < ANIM_COUNT; index++) {
AnimTypeClass const& anim = As_Reference((AnimType)index);

if (anim.IsTheater) {
char fullname[_MAX_FNAME + _MAX_EXT]; // Fully constructed iconset name.
_makepath(fullname, NULL, NULL, anim.IniName, Theaters[theater].Suffix);
((void const*&)anim.ImageData) = MFCD::Retrieve(fullname);
}
for (int index = ANIM_FIRST; index < ANIM_COUNT; index++) {
AnimTypeClass const& anim = As_Reference((AnimType)index);

if (anim.IsTheater) {
char fullname[_MAX_FNAME + _MAX_EXT]; // Fully constructed iconset name.
_makepath(fullname, NULL, NULL, anim.IniName, Theaters[theater].Suffix);
((void const*&)anim.ImageData) = MFCD::Retrieve(fullname);
}
}

#ifdef REMASTER_BUILD
// Set up beacon image data manually since they're new animations only available in the virtual renderer
((void const*&)As_Reference(ANIM_BEACON_VIRTUAL).ImageData) = As_Reference(ANIM_BEACON).ImageData;
// Set up beacon image data manually since they're new animations only available in the virtual renderer
((void const*&)As_Reference(ANIM_BEACON_VIRTUAL).ImageData) = As_Reference(ANIM_BEACON).ImageData;
#endif
}
}

/***********************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion redalert/bbdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void BulletTypeClass::Init_Heap(void)
* HISTORY: *
* 05/28/1994 JLB : Created. *
*=============================================================================================*/
void BulletTypeClass::One_Time(void)
void BulletTypeClass::Init_Clear(void)
{
/*
** Load the bullet shapes.
Expand Down
49 changes: 22 additions & 27 deletions redalert/bdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2956,7 +2956,7 @@ void BuildingTypeClass::Init_Heap(void)
* 05/28/1994 JLB : Created. *
* 06/11/1994 JLB : Updated construction time and frame count logic. *
*=============================================================================================*/
void BuildingTypeClass::One_Time(void)
void BuildingTypeClass::Init_Clear(void)
{
static const struct
{
Expand Down Expand Up @@ -3013,18 +3013,15 @@ void BuildingTypeClass::One_Time(void)
/*
** Fetch the sidebar cameo image for this building.
*/
if (building.Level != -1) {
// if (building.IsBuildable) {
sprintf(buffer, "%sICON", building.Graphic_Name());
sprintf(buffer, "%sICON", building.Graphic_Name());

if (building.IsFake) {
buffer[3] = 'F';
}

_makepath(fullname, NULL, NULL, buffer, ".SHP");
((void const*&)building.CameoData) = MFCD::Retrieve(fullname);
if (building.IsFake) {
buffer[3] = 'F';
}

_makepath(fullname, NULL, NULL, buffer, ".SHP");
((void const*&)building.CameoData) = MFCD::Retrieve(fullname);

/*
** Fetch the construction animation for this building.
*/
Expand Down Expand Up @@ -3253,30 +3250,28 @@ void BuildingTypeClass::Init_Anim(BStateType state, int start, int count, int ra
*=============================================================================================*/
void BuildingTypeClass::Init(TheaterType theater)
{
if (theater != LastTheater) {
char fullname[_MAX_FNAME + _MAX_EXT];
char fullname[_MAX_FNAME + _MAX_EXT];

for (int sindex = STRUCT_FIRST; sindex < STRUCT_COUNT; sindex++) {
BuildingTypeClass const* classptr = &As_Reference((StructType)sindex);
for (int sindex = STRUCT_FIRST; sindex < STRUCT_COUNT; sindex++) {
BuildingTypeClass const* classptr = &As_Reference((StructType)sindex);

if (classptr->IsTheater) {
_makepath(fullname, NULL, NULL, classptr->Graphic_Name(), Theaters[theater].Suffix);
((void const*&)classptr->ImageData) = MFCD::Retrieve(fullname);
if (classptr->IsTheater) {
_makepath(fullname, NULL, NULL, classptr->Graphic_Name(), Theaters[theater].Suffix);
((void const*&)classptr->ImageData) = MFCD::Retrieve(fullname);

/*
/*
** Buildup data is probably theater specific as well. Fetch a pointer to the
** data at this time as well.
*/
sprintf(fullname, "%sMAKE.%s", classptr->Graphic_Name(), Theaters[theater].Suffix);
((void const*&)classptr->BuildupData) = MFCD::Retrieve(fullname);
if (classptr->BuildupData) {
int timedelay = 1;
int count = Get_Build_Frame_Count(classptr->BuildupData);
if (count != 0) {
timedelay = (5 * TICKS_PER_SECOND) / count;
}
classptr->Init_Anim(BSTATE_CONSTRUCTION, 0, count, timedelay);
sprintf(fullname, "%sMAKE.%s", classptr->Graphic_Name(), Theaters[theater].Suffix);
((void const*&)classptr->BuildupData) = MFCD::Retrieve(fullname);
if (classptr->BuildupData) {
int timedelay = 1;
int count = Get_Build_Frame_Count(classptr->BuildupData);
if (count != 0) {
timedelay = (5 * TICKS_PER_SECOND) / count;
}
classptr->Init_Anim(BSTATE_CONSTRUCTION, 0, count, timedelay);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion redalert/cdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ ObjectClass* TemplateTypeClass::Create_One_Of(HouseClass*) const
* HISTORY: *
* 08/12/1994 JLB : Created. *
*=============================================================================================*/
void TemplateTypeClass::One_Time(void)
void TemplateTypeClass::Init_Clear(void)
{
}

Expand Down
2 changes: 1 addition & 1 deletion redalert/hdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ HousesType HouseTypeClass::From_Name(char const* name)
* 05/21/1994 JLB : Converted to member function. *
* 06/19/1996 JLB : Converted to regular heap class management. *
*=============================================================================================*/
void HouseTypeClass::One_Time(void)
void HouseTypeClass::Init_Clear(void)
{
}

Expand Down
2 changes: 1 addition & 1 deletion redalert/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ HouseClass* HouseClass::As_Pointer(HousesType house)
* HISTORY: *
* 12/09/1994 JLB : Created. *
*=============================================================================================*/
void HouseClass::One_Time(void)
void HouseClass::Init_Clear(void)
{
BuildChoice.Set_Heap(STRUCT_COUNT);
}
Expand Down
2 changes: 1 addition & 1 deletion redalert/house.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class HouseClass
};

static void Init(void);
static void One_Time(void);
static void Init_Clear(void);
static HouseClass* As_Pointer(HousesType house);
static void Recalc_Attributes(void);

Expand Down
2 changes: 1 addition & 1 deletion redalert/idata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ InfantryType InfantryTypeClass::From_Name(char const* name)
* HISTORY: *
* 09/24/1994 JLB : Created. *
*=============================================================================================*/
void InfantryTypeClass::One_Time(void)
void InfantryTypeClass::Init_Clear(void)
{
for (InfantryType index = INFANTRY_FIRST; index < INFANTRY_COUNT; index++) {
char fullname[_MAX_FNAME + _MAX_EXT];
Expand Down
19 changes: 2 additions & 17 deletions redalert/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ bool Init_Game(int, char*[])
*/
CCFileClass rulesIniFile("RULES.INI");
if (RuleINI.Load(rulesIniFile, false)) {
Rule.Process(RuleINI);
Rule.Process(RuleINI, true);
}
#ifdef FIXIT_CSII // checked - ajw 9/28/98
// Aftermath runtime change 9/29/98
// This is safe to do, as only rules for aftermath units are included in this ini.
if (Is_Aftermath_Installed() == true) {
CCFileClass aftermathIniFile("AFTRMATH.INI");
if (AftermathINI.Load(aftermathIniFile, false)) {
Rule.Process(AftermathINI);
Rule.Process(AftermathINI, true);
}
}
#endif
Expand Down Expand Up @@ -2171,21 +2171,6 @@ static void Init_One_Time_Systems(void)
Logic.One_Time();
Options.One_Time();
Session.One_Time();

ObjectTypeClass::One_Time();
BuildingTypeClass::One_Time();
BulletTypeClass::One_Time();
HouseTypeClass::One_Time();
TemplateTypeClass::One_Time();
OverlayTypeClass::One_Time();
SmudgeTypeClass::One_Time();
TerrainTypeClass::One_Time();
UnitTypeClass::One_Time();
VesselTypeClass::One_Time();
InfantryTypeClass::One_Time();
AnimTypeClass::One_Time();
AircraftTypeClass::One_Time();
HouseClass::One_Time();
}

/***********************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion redalert/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ short const* ObjectTypeClass::Overlap_List(void) const
* HISTORY: *
* 11/01/1994 JLB : Created. *
*=============================================================================================*/
void ObjectTypeClass::One_Time(void)
void ObjectTypeClass::Init_Clear(void)
{
SelectShapes = MFCD::Retrieve("SELECT.SHP");

Expand Down
33 changes: 15 additions & 18 deletions redalert/odata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void OverlayTypeClass::Init_Heap(void)
* HISTORY: *
* 08/12/1994 JLB : Created. *
*=============================================================================================*/
void OverlayTypeClass::One_Time(void)
void OverlayTypeClass::Init_Clear(void)
{
}

Expand Down Expand Up @@ -852,25 +852,22 @@ void OverlayTypeClass::Draw_It(int x, int y, int data) const
*=============================================================================================*/
void OverlayTypeClass::Init(TheaterType theater)
{
if (theater != LastTheater) {

for (OverlayType index = OVERLAY_FIRST; index < OVERLAY_COUNT; index++) {
OverlayTypeClass& overlay = As_Reference(index);
char fullname[_MAX_FNAME + _MAX_EXT]; // Fully constructed iconset name.

if (overlay.IsTheater) {
_makepath(fullname, NULL, NULL, overlay.IniName, Theaters[theater].Suffix);
} else {
_makepath(fullname, NULL, NULL, overlay.IniName, ".SHP");
}
overlay.ImageData = MFCD::Retrieve(fullname);
for (OverlayType index = OVERLAY_FIRST; index < OVERLAY_COUNT; index++) {
OverlayTypeClass& overlay = As_Reference(index);
char fullname[_MAX_FNAME + _MAX_EXT]; // Fully constructed iconset name.

IsTheaterShape = overlay.IsTheater; // Tell Build_Frame if this is a theater specific shape
if (overlay.RadarIcon != NULL)
delete[](char*) overlay.RadarIcon;
overlay.RadarIcon = Get_Radar_Icon(overlay.Get_Image_Data(), 0, -1, 3);
IsTheaterShape = false;
if (overlay.IsTheater) {
_makepath(fullname, NULL, NULL, overlay.IniName, Theaters[theater].Suffix);
} else {
_makepath(fullname, NULL, NULL, overlay.IniName, ".SHP");
}
overlay.ImageData = MFCD::Retrieve(fullname);

IsTheaterShape = overlay.IsTheater; // Tell Build_Frame if this is a theater specific shape
if (overlay.RadarIcon != NULL)
delete[](char*) overlay.RadarIcon;
overlay.RadarIcon = Get_Radar_Icon(overlay.Get_Image_Data(), 0, -1, 3);
IsTheaterShape = false;
}
}

Expand Down
6 changes: 4 additions & 2 deletions redalert/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,16 @@ static void Difficulty_Get(CCINIClass& ini, DifficultyClass& diff, char const* s
* HISTORY: *
* 06/17/1996 JLB : Created. *
*=============================================================================================*/
bool RulesClass::Process(CCINIClass& ini)
bool RulesClass::Process(CCINIClass& ini, bool setheapmaximums)
{
BStart(BENCH_RULES);

General(ini);
MPlayer(ini);
Recharge(ini);
Heap_Maximums(ini);
if (setheapmaximums) {
Heap_Maximums(ini);
}
AI(ini);
Powerups(ini);
Land_Types(ini);
Expand Down
2 changes: 1 addition & 1 deletion redalert/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RulesClass
public:
RulesClass(void);

bool Process(CCINIClass& file);
bool Process(CCINIClass& file, bool setheapmaximums);
bool General(CCINIClass& ini);
bool MPlayer(CCINIClass& ini);
bool Recharge(CCINIClass& ini);
Expand Down
Loading

0 comments on commit 2185010

Please sign in to comment.