Skip to content

Commit e936c88

Browse files
committed
PowerMode2003: Some minor refactoring & added documentation
1 parent c609260 commit e936c88

File tree

4 files changed

+69
-29
lines changed

4 files changed

+69
-29
lines changed

src/game_map.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ void Game_Map::SetupFromSave(
284284
// FIXME: RPG_RT compatibility bug: On async platforms, panorama async loading can
285285
// cause panorama chunks to be out of sync.
286286
Game_Map::Parallax::ChangeBG(GetParallaxParams());
287-
288-
RuntimePatches::PowerMode2003::Init();
289287
}
290288

291289
std::unique_ptr<lcf::rpg::Map> Game_Map::LoadMapFile(int map_id) {

src/game_runtime_patches.cpp

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,27 @@ void RuntimePatches::DetermineActivePatches(std::vector<std::string>& patches) {
185185
#endif
186186
}
187187

188+
void RuntimePatches::OnResetGameObjects() {
189+
#ifdef NO_RUNTIME_PATCHES
190+
// no-op
191+
return;
192+
#endif
193+
if (Player::game_config.patch_powermode.Get()) {
194+
Player::game_config.new_game.Set(true);
195+
Main_Data::game_variables->Set(PowerMode2003::PM_VAR_CR0, FileFinder::HasSavegame() ? 1 : 0);
196+
}
197+
}
198+
199+
void RuntimePatches::OnLoadSavegame() {
200+
#ifdef NO_RUNTIME_PATCHES
201+
// no-op
202+
return;
203+
#endif
204+
if (Player::game_config.patch_powermode.Get()) {
205+
Main_Data::game_variables->Set(PowerMode2003::PM_VAR_CR0, FileFinder::HasSavegame() ? 1 : 0);
206+
}
207+
}
208+
188209
void RuntimePatches::OnVariableChanged(int variable_id) {
189210
#ifdef NO_RUNTIME_PATCHES
190211
// no-op
@@ -195,6 +216,7 @@ void RuntimePatches::OnVariableChanged(int variable_id) {
195216
PowerMode2003::HandleVariableHooks(variable_id);
196217
}
197218
}
219+
198220
void RuntimePatches::OnVariableChanged(std::initializer_list<int> variable_ids) {
199221
#ifdef NO_RUNTIME_PATCHES
200222
// no-op
@@ -436,6 +458,27 @@ bool RuntimePatches::GuardRevamp::OverrideDamageAdjustment(int& dmg, const Game_
436458
}
437459

438460
namespace RuntimePatches::PowerMode2003 {
461+
void HandleCommands() {
462+
int op = Main_Data::game_variables->Get(PM_VAR_CR0);
463+
if (op == 255 && FileFinder::HasSavegame()) {
464+
Scene::instance->SetRequestedScene(std::make_shared<Scene_Load>());
465+
} else if (op == 254) {
466+
Player::exit_flag = true;
467+
}
468+
Main_Data::game_variables->Set(PM_VAR_CR0, FileFinder::HasSavegame() ? 1 : 0);
469+
}
470+
471+
void HandleMouse() {
472+
#if !defined(USE_MOUSE_OR_TOUCH) || !defined(SUPPORT_MOUSE_OR_TOUCH)
473+
Output::Warning("PowerMode2003: Mouse input is not supported on this platform");
474+
return;
475+
#endif
476+
Point mouse_pos = Input::GetMousePosition();
477+
Main_Data::game_variables->Set(PM_VAR_MCOORDX, mouse_pos.x);
478+
Main_Data::game_variables->Set(PM_VAR_MCOORDY, mouse_pos.y);
479+
480+
}
481+
439482
void HandleKeyboard() {
440483
#if !defined(SUPPORT_KEYBOARD)
441484
Output::Warning("PowerMode2003: Keyboard input is not supported on this platform");
@@ -511,17 +554,6 @@ namespace RuntimePatches::PowerMode2003 {
511554
}
512555
}
513556

514-
void RuntimePatches::PowerMode2003::Init() {
515-
#ifdef NO_RUNTIME_PATCHES
516-
// no-op
517-
return;
518-
#endif
519-
if (Player::game_config.patch_powermode.Get()) {
520-
Player::game_config.new_game.Set(true);
521-
Main_Data::game_variables->Set(PM_VAR_CR0, FileFinder::HasSavegame() ? 1 : 0);
522-
}
523-
}
524-
525557
void RuntimePatches::PowerMode2003::HandleVariableHooks(int var_id) {
526558
#ifdef NO_RUNTIME_PATCHES
527559
// no-op
@@ -530,24 +562,12 @@ void RuntimePatches::PowerMode2003::HandleVariableHooks(int var_id) {
530562
#endif
531563
switch (var_id) {
532564
case PM_VAR_CR0:
533-
{
534-
int op = Main_Data::game_variables->Get(PM_VAR_CR0);
535-
if (op == 255 && FileFinder::HasSavegame()) {
536-
Scene::instance->SetRequestedScene(std::make_shared<Scene_Load>());
537-
} else if (op == 254) {
538-
Player::exit_flag = true;
539-
}
540-
Main_Data::game_variables->Set(PM_VAR_CR0, FileFinder::HasSavegame() ? 1 : 0);
565+
HandleCommands();
541566
break;
542-
}
543567
case PM_VAR_MCOORDY:
544-
{
545-
Point mouse_pos = Input::GetMousePosition();
546-
Main_Data::game_variables->Set(PM_VAR_MCOORDX, mouse_pos.x);
547-
Main_Data::game_variables->Set(PM_VAR_MCOORDY, mouse_pos.y);
568+
HandleMouse();
548569
Game_Map::SetNeedRefreshForVarChange(PM_VAR_MCOORDX);
549570
break;
550-
}
551571
case PM_VAR_KEY:
552572
HandleKeyboard();
553573
break;

src/game_runtime_patches.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ namespace RuntimePatches {
5151

5252
void DetermineActivePatches(std::vector<std::string>& patches);
5353

54+
void OnResetGameObjects();
55+
56+
void OnLoadSavegame();
57+
5458
// Handles patch side effects caused by Variable changes. This function is meant
5559
// to be called only for operations that are possible in an unpatched RPG_RT!
5660
void OnVariableChanged(int variable_id);
@@ -214,6 +218,23 @@ namespace RuntimePatches {
214218

215219
}
216220

221+
222+
/**
223+
* Support for RPG_RT patch 'Power Mode 2003'.
224+
* (aka. "Mega Patch 2003" in Italian scene)
225+
*
226+
* This patch adds some specialiced commands by hooking into
227+
* the first 8 in-game variables, functionally using them
228+
* as 'Control Registers'.
229+
*
230+
* These new commands include:
231+
* - V[1]: Calling up the Load menu, Exiting the game
232+
* & Checking for the existence of Savefiles
233+
* - V[2-3]: Retrieving the current coordinates of the mouse cursor.
234+
* - V[4]: Retrieving key inputs for entire keyboard.
235+
* - V[5-7]: Floating-point operations
236+
* - V[8]: Specifying custom rotation for Picture IDs 1 - 50
237+
* */
217238
namespace PowerMode2003 {
218239
constexpr int PM_VAR_CR0 = 1;
219240
constexpr int PM_VAR_MCOORDX = 2;
@@ -224,8 +245,8 @@ namespace RuntimePatches {
224245
constexpr int PM_VAR_FCODE = 7;
225246
constexpr int PM_VAR_SPECIAL = 8;
226247

227-
void Init();
228248
void HandleVariableHooks(int var_id);
249+
229250
bool ApplyPictureRotation(lcf::rpg::SavePicture& pict);
230251
}
231252
}

src/player.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ void Player::ResetGameObjects() {
961961

962962
Main_Data::game_system->ReloadSystemGraphic();
963963

964-
RuntimePatches::PowerMode2003::Init();
964+
RuntimePatches::OnResetGameObjects();
965965

966966
Input::ResetMask();
967967
}
@@ -1220,6 +1220,7 @@ void Player::LoadSavegame(const std::string& save_name, int save_id) {
12201220
Game_Map::Dispose();
12211221

12221222
OnMapSaveFileReady(request, std::move(save));
1223+
RuntimePatches::OnLoadSavegame();
12231224

12241225
if (load_on_map) {
12251226
// Increment frame counter for consistency with a normal savegame load

0 commit comments

Comments
 (0)