Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements developer mode command to reload Rules and Art files. #998

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ This page lists all the individual contributions to the project by their author.
- Adds keyboard commands to reproduce the last items that were built.
- Change starting unit placement to be the same as Red Alert 2.
- Add the framework for new ArmorTypes.
- Implement developer mode command to reload Rules and Art files.
- **Kerbiter (Metadorius)**:
- Initial documentation setup.
- **MarkJFox**:
Expand Down
10 changes: 9 additions & 1 deletion docs/Miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ It is not recommended that you modify or remove any of the original mix files, t
- The name shown in the dialog is the value of the `Name=` _(with a limit of 128 characters)_ entry under `[General]` in the Rule INI. If the user presses Cancel on the dialog, the game will load the standard `RULES.INI` file.

```{note}
Due to the nature of its use, this feature is only available when Vinifera is running in Developer Mode
Due to the nature of its use, this feature is only available when Vinifera is running in Developer Mode.
```

![image](https://user-images.githubusercontent.com/73803386/137135038-0a1e983f-d295-4723-86fb-1ab94ba8948b.png)
Expand Down Expand Up @@ -186,6 +186,14 @@ This option tells the game to exit when you press Cancel or Back from the dialog

- Dumps all existing triggers, tags, and local and global variables to the log output.

#### `[ ]` Reload Rules

- Reloads the Rules and Art INI files.

```{warning}
This could very well crash the game, please use it with caution and make small incremental changes only!
```

#### `[ ]` Instant Build (Player)

- Toggles the instant build cheat for the player.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ New:
- Add `TransformsInto` and `TransformRequiresFullCharge` to UnitTypes (by Rampastring)
- Add developer command to dump all existing triggers, tags, and local and global variables to the log output (by Rampastring)
- Add `PipWrap` (by ZivDero)
- Implement developer mode command to reload Rules and Art files (by CCHyper)


Vanilla fixes:
Expand Down
37 changes: 37 additions & 0 deletions src/extensions/command/commandext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4107,3 +4107,40 @@ bool DumpHeapsCommandClass::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 @@ -1414,3 +1414,22 @@ class DumpHeapsCommandClass : public ViniferaCommandClass

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


/**
* 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); }
};
3 changes: 3 additions & 0 deletions src/extensions/command/commandext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ void Init_Vinifera_Commands()

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

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

/**
Expand Down
105 changes: 105 additions & 0 deletions src/extensions/mainloop/mainloopext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
#include "tibsun_globals.h"
#include "tibsun_functions.h"
#include "command.h"
#include "uicontrol.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"6
Expand Down Expand Up @@ -77,6 +82,106 @@ 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();
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 (Is_Addon_Available(ADDON_FIRESTORM) && Is_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 (Is_Addon_Available(ADDON_FIRESTORM) && Is_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 INIs.
*/
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");
}

/**
* Finally, reload miscellaneous classes.
*/
{
CCFileClass workingfile;
CCINIClass workingini;

DEBUG_INFO("Calling UIControls->Read_INI().\n");
workingfile.Set_Name("UI.INI");
workingini.Clear();
workingini.Load(workingfile, false);
UIControls->Read_INI(workingini);
DEBUG_INFO("Finished UIControls->Read_INI().\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 @@ -74,6 +74,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
Loading