Skip to content

Commit

Permalink
Implements developer command to reload Rules and Art files.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Mar 28, 2023
1 parent 9310876 commit cdccc00
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/extensions/command/commandext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3439,3 +3439,40 @@ bool DumpNetworkCRCCommandClass::Process()

return true;
}


/**
* Reloads the Rules and Art INI files.
*
* @author: CCHyper
*/
const char *ReloadRulesCommandClass::Get_Name() const
{
return "ReloadRules";
}

const char * ReloadRulesCommandClass::Get_UI_Name() const
{
return "Reload Rules";
}

const char *ReloadRulesCommandClass::Get_Category() const
{
return CATEGORY_DEVELOPER;
}

const char *ReloadRulesCommandClass::Get_Description() const
{
return "Reloads the Rules and Art INI files.";
}

bool ReloadRulesCommandClass::Process()
{
if (!Session.Singleplayer_Game()) {
return false;
}

Vinifera_Developer_IsToReloadRules = true;

return true;
}
19 changes: 19 additions & 0 deletions src/extensions/command/commandext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,25 @@ class DumpNetworkCRCCommandClass : public ViniferaCommandClass
};


/**
* Reload Rules and Art.
*/
class ReloadRulesCommandClass : public ViniferaCommandClass
{
public:
ReloadRulesCommandClass() : ViniferaCommandClass() { IsDeveloper = true; }
virtual ~ReloadRulesCommandClass() {}

virtual const char *Get_Name() const override;
virtual const char *Get_UI_Name() const override;
virtual const char *Get_Category() const override;
virtual const char *Get_Description() const override;
virtual bool Process() override;

virtual KeyNumType Default_Key() const override { return KeyNumType(KN_NONE); }
};


#ifndef DEBUG
/**
* Based class for all new developer/debug command classes.
Expand Down
3 changes: 3 additions & 0 deletions src/extensions/command/commandext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ void Init_Vinifera_Commands()

cmdptr = new DumpNetworkCRCCommandClass;
Commands.Add(cmdptr);

cmdptr = new ReloadRulesCommandClass;
Commands.Add(cmdptr);
}

#ifndef NDEBUG
Expand Down
89 changes: 89 additions & 0 deletions src/extensions/mainloop/mainloopext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
#include "vinifera_globals.h"
#include "tibsun_globals.h"
#include "tibsun_functions.h"
#include "rules.h"
#include "iomap.h"
#include "tactical.h"
#include "house.h"
#include "ccfile.h"
#include "addon.h"
#include "ccini.h"
#include "fatal.h"
#include "debughandler.h"
#include "asserthandler.h"
Expand Down Expand Up @@ -76,6 +80,91 @@ static void Before_Main_Loop()

static void After_Main_Loop()
{
/**
* Has we been flagged to reload the rules data?
*/
if (Vinifera_Developer_IsToReloadRules) {

/**
* Reinitalise the Rule instance to the defaults.
*/
Rule->RulesClass::~RulesClass();
new (Rule) RulesClass();

/**
* Clear the current ini databases.
*/
ArtINI.Clear();
RuleINI->Clear();
FSRuleINI.Clear();

/**
* Reload RULES.INI and FIRESTRM.INI.
*/
{
CCFileClass rulefile("RULES.INI");
RuleINI->Load(rulefile, false);
ASSERT_FATAL(rulefile.Is_Available());

if (Addon_Installed(ADDON_FIRESTORM) && Addon_Enabled(ADDON_FIRESTORM)) {
rulefile.Set_Name("FIRESTRM.INI");
ASSERT_FATAL(rulefile.Is_Available());
FSRuleINI.Load(rulefile, false);
}
}

/**
* Reload ART.INI and ARTFS.INI.
*/
{
CCFileClass artfile("ART.INI");

DEBUG_INFO("Loading ART.INI.\n");
ArtINI.Load(artfile, false);
ASSERT_FATAL(artfile.Is_Available());
DEBUG_INFO("Finished loading ART.INI.\n");

if (Addon_Installed(ADDON_FIRESTORM) && Addon_Enabled(ADDON_FIRESTORM)) {
DEBUG_INFO("Loading ARTFS.INI.\n");
artfile.Set_Name("ARTFS.INI");
ASSERT_FATAL(artfile.Is_Available());
ArtINI.Load(artfile, false);
DEBUG_INFO("Finished loading ARTFS.INI.\n");
}
}

/**
* Process rule ini's.
*/
DEBUG_INFO("Calling Rule->Process(*RuleINI).\n");
Rule->Process(*RuleINI);
DEBUG_INFO("Finished Rule->Process(*RuleINI).\n");

DEBUG_INFO("Calling Rule->Addition(FSRuleINI).\n");
Rule->Addition(FSRuleINI);
DEBUG_INFO("Finished Rule->Addition(FSRuleINI).\n");

/**
* Process scenario rule overrides.
*/
{
CCFileClass scenfile(Scen->ScenarioName);
ASSERT_FATAL(scenfile.Is_Available());

CCINIClass scenini;

scenini.Load(scenfile, false);

DEBUG_INFO("Calling Rule->Addition() with scenario overrides.\n");
Rule->Addition(scenini);
DEBUG_INFO("Finished Rule->Addition() with scenario overrides.\n");
}

/**
* All done!
*/
Vinifera_Developer_IsToReloadRules = false;
}
}


Expand Down
1 change: 1 addition & 0 deletions src/vinifera/vinifera_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bool Vinifera_Developer_ShowCursorPosition = false;
bool Vinifera_Developer_FrameStep = false;
int Vinifera_Developer_FrameStepCount = 0;
bool Vinifera_Developer_AIControl = false;
bool Vinifera_Developer_IsToReloadRules = false;

bool Vinifera_SkipLogoMovies = false;
bool Vinifera_SkipStartupMovies = false;
Expand Down
1 change: 1 addition & 0 deletions src/vinifera/vinifera_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extern bool Vinifera_Developer_ShowCursorPosition;
extern bool Vinifera_Developer_FrameStep;
extern int Vinifera_Developer_FrameStepCount;
extern bool Vinifera_Developer_AIControl;
extern bool Vinifera_Developer_IsToReloadRules;


/**
Expand Down

0 comments on commit cdccc00

Please sign in to comment.