From dc90beb69628ce227a2e061ac74ede985d122070 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Tue, 6 Dec 2022 17:22:30 +0300 Subject: [PATCH] Add game mode tracking --- src/automap.cc | 2 ++ src/character_editor.cc | 2 ++ src/combat.cc | 4 ++++ src/game.cc | 32 ++++++++++++++++++++++++++++ src/game.h | 46 +++++++++++++++++++++++++++++++++++++++++ src/game_dialog.cc | 18 ++++++++++++++++ src/inventory.cc | 10 +++++++++ src/loadsave.cc | 4 ++++ src/options.cc | 4 ++++ src/pipboy.cc | 2 ++ src/skilldex.cc | 2 ++ src/worldmap.cc | 2 ++ 12 files changed, 128 insertions(+) diff --git a/src/automap.cc b/src/automap.cc index 5d5e44c..8665775 100644 --- a/src/automap.cc +++ b/src/automap.cc @@ -297,6 +297,8 @@ int _automapDisplayMap(int map) // 0x41B8BC void automapShow(bool isInGame, bool isUsingScanner) { + ScopedGameMode gm(GameMode::kAutomap); + int frmIds[AUTOMAP_FRM_COUNT]; memcpy(frmIds, gAutomapFrmIds, sizeof(gAutomapFrmIds)); diff --git a/src/character_editor.cc b/src/character_editor.cc index f557852..020e689 100644 --- a/src/character_editor.cc +++ b/src/character_editor.cc @@ -790,6 +790,8 @@ static std::vector gCustomTownReputationEntries; // 0x431DF8 int characterEditorShow(bool isCreationMode) { + ScopedGameMode gm(!isCreationMode ? GameMode::kEditor : 0); + char* messageListItemText; char line1[128]; char line2[128]; diff --git a/src/combat.cc b/src/combat.cc index 349ca84..bb96cd1 100644 --- a/src/combat.cc +++ b/src/combat.cc @@ -3131,6 +3131,8 @@ void _combat_turn_run() // 0x4227F4 static int _combat_input() { + ScopedGameMode gm(GameMode::kPlayerTurn); + while ((gCombatState & COMBAT_STATE_0x02) != 0) { sharedFpsLimiter.mark(); @@ -3369,6 +3371,8 @@ static bool _combat_should_end() // 0x422D2C void _combat(STRUCT_664980* attack) { + ScopedGameMode gm(GameMode::kCombat); + if (attack == NULL || (attack->attacker == NULL || attack->attacker->elevation == gElevation) || (attack->defender == NULL || attack->defender->elevation == gElevation)) { diff --git a/src/game.cc b/src/game.cc index 6df6d17..9383793 100644 --- a/src/game.cc +++ b/src/game.cc @@ -1151,6 +1151,8 @@ static void gameFreeGlobalVars() // 0x443F74 static void showHelp() { + ScopedGameMode gm(GameMode::kHelp); + bool isoWasEnabled = isoDisable(); gameMouseObjectsHide(); @@ -1437,4 +1439,34 @@ int gameShowDeathDialog(const char* message) return rc; } +int GameMode::currentGameMode = 0; + +void GameMode::enterGameMode(int gameMode) +{ + currentGameMode |= gameMode; + debugPrint("Entering game mode: %d", gameMode); +} + +void GameMode::exitGameMode(int gameMode) +{ + currentGameMode &= ~gameMode; + debugPrint("Exiting game mode: %d", gameMode); +} + +bool GameMode::isInGameMode(int gameMode) +{ + return (currentGameMode & gameMode) != 0; +} + +ScopedGameMode::ScopedGameMode(int gameMode) +{ + this->gameMode = gameMode; + GameMode::enterGameMode(gameMode); +} + +ScopedGameMode::~ScopedGameMode() +{ + GameMode::exitGameMode(gameMode); +} + } // namespace fallout diff --git a/src/game.h b/src/game.h index c8db879..01a8950 100644 --- a/src/game.h +++ b/src/game.h @@ -41,6 +41,52 @@ int showQuitConfirmationDialog(); int gameShowDeathDialog(const char* message); +class GameMode +{ +public: + enum Flags + { + kWorldmap = 0x1, + kDialog = 0x4, + kOptions = 0x8, + kSaveGame = 0x10, + kLoadGame = 0x20, + kCombat = 0x40, + kPreferences = 0x80, + kHelp = 0x100, + kEditor = 0x200, + kPipboy = 0x400, + kPlayerTurn = 0x800, + kInventory = 0x1000, + kAutomap = 0x2000, + kSkilldex = 0x4000, + kUseOn = 0x8000, + kLoot = 0x10000, + kBarter = 0x20000, + kHero = 0x40000, + kDialogReview = 0x80000, + kCounter = 0x100000, + kSpecial = 0x80000000, + }; + + static void enterGameMode(int gameMode); + static void exitGameMode(int gameMode); + static bool isInGameMode(int gameMode); + static int getCurrentGameMode() { return currentGameMode; } + +private: + static int currentGameMode; +}; + +class ScopedGameMode { +public: + ScopedGameMode(int gameMode); + ~ScopedGameMode(); + +private: + int gameMode; +}; + } // namespace fallout #endif /* GAME_H */ diff --git a/src/game_dialog.cc b/src/game_dialog.cc index 99d226b..afbdf7f 100644 --- a/src/game_dialog.cc +++ b/src/game_dialog.cc @@ -922,6 +922,8 @@ int _gdialogInitFromScript(int headFid, int reaction) _gdDialogWentOff = true; + GameMode::enterGameMode(GameMode::kDialog); + return 0; } @@ -947,7 +949,11 @@ int _gdialogExitFromScript() _tile_scroll_to(gGameDialogOldCenterTile, 2); } + GameMode::exitGameMode(GameMode::kDialog); + + GameMode::enterGameMode(GameMode::kSpecial); _gdDestroyHeadWindow(); + GameMode::exitGameMode(GameMode::kSpecial); // CE: Fix Barter button. gameDialogRedButtonsExit(); @@ -1189,10 +1195,14 @@ void _gdialogUpdatePartyStatus() // NOTE: Uninline. gdHide(); + GameMode::enterGameMode(GameMode::kSpecial); + _gdialog_window_destroy(); gGameDialogSpeakerIsPartyMember = isPartyMember; + GameMode::exitGameMode(GameMode::kSpecial); + _gdialog_window_create(); // NOTE: Uninline. @@ -1430,6 +1440,8 @@ int gameDialogReviewWindowFree(int* win) // 0x445CA0 int gameDialogShowReview() { + ScopedGameMode gm(GameMode::kDialogReview); + int win; if (gameDialogReviewWindowInit(&win) == -1) { @@ -1871,6 +1883,9 @@ int _gdProcess() } else { if (_dialogue_switch_mode == 3) { _dialogue_state = 4; + + GameMode::exitGameMode(GameMode::kSpecial); + inventoryOpenTrade(gGameDialogWindow, gGameDialogSpeaker, _peon_table_obj, _barterer_table_obj, gGameDialogBarterModifier); _gdialog_barter_cleanup_tables(); @@ -2745,6 +2760,9 @@ void gameDialogTicker() case 2: _loop_cnt = -1; _dialogue_switch_mode = 3; + + GameMode::enterGameMode(GameMode::kSpecial); + _gdialog_window_destroy(); _gdialog_barter_create_win(); break; diff --git a/src/inventory.cc b/src/inventory.cc index e2f4d9e..1d36c83 100644 --- a/src/inventory.cc +++ b/src/inventory.cc @@ -548,6 +548,8 @@ void inventoryOpen() } } + ScopedGameMode gm(GameMode::kInventory); + if (inventoryCommonInit() == -1) { return; } @@ -2618,6 +2620,8 @@ static void _adjust_fid() // 0x4717E4 void inventoryOpenUseItemOn(Object* a1) { + ScopedGameMode gm(GameMode::kUseOn); + if (inventoryCommonInit() == -1) { return; } @@ -4044,6 +4048,8 @@ int inventoryOpenLooting(Object* a1, Object* a2) return 0; } + ScopedGameMode gm(GameMode::kLoot); + if (FID_TYPE(a2->fid) == OBJ_TYPE_CRITTER) { if (_critter_flag_check(a2->pid, CRITTER_NO_STEAL)) { // You can't find anything to take from that. @@ -5018,6 +5024,8 @@ static void inventoryWindowRenderInnerInventories(int win, Object* a2, Object* a // 0x4757F0 void inventoryOpenTrade(int win, Object* a2, Object* a3, Object* a4, int a5) { + ScopedGameMode gm(GameMode::kBarter); + _barter_mod = a5; if (inventoryCommonInit() == -1) { @@ -5568,6 +5576,8 @@ static void _draw_amount(int value, int inventoryWindowType) // 0x47688C static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max) { + ScopedGameMode gm(GameMode::kCounter); + inventoryQuantityWindowInit(inventoryWindowType, item); int value; diff --git a/src/loadsave.cc b/src/loadsave.cc index 7329cf8..60f8c5c 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -350,6 +350,8 @@ void _ResetLoadSave() // 0x47B88C int lsgSaveGame(int mode) { + ScopedGameMode gm(GameMode::kSaveGame); + MessageListItem messageListItem; _ls_error_code = 0; @@ -854,6 +856,8 @@ static int _QuickSnapShot() // 0x47C640 int lsgLoadGame(int mode) { + ScopedGameMode gm(GameMode::kLoadGame); + MessageListItem messageListItem; const char* body[] = { diff --git a/src/options.cc b/src/options.cc index d66a458..893089f 100644 --- a/src/options.cc +++ b/src/options.cc @@ -462,6 +462,8 @@ int showOptions() // 0x48FC50 int showOptionsWithInitialKeyCode(int initialKeyCode) { + ScopedGameMode gm(GameMode::kOptions); + if (optionsWindowInit() == -1) { debugPrint("\nOPTION MENU: Error loading option dialog data!\n"); return -1; @@ -1699,6 +1701,8 @@ static int preferencesWindowFree() // 0x490798 static int _do_prefscreen() { + ScopedGameMode gm(GameMode::kPreferences); + if (preferencesWindowInit() == -1) { debugPrint("\nPREFERENCE MENU: Error loading preference dialog data!\n"); return -1; diff --git a/src/pipboy.cc b/src/pipboy.cc index b553fdc..028c4c3 100644 --- a/src/pipboy.cc +++ b/src/pipboy.cc @@ -406,6 +406,8 @@ int pipboyOpen(int intent) return 0; } + ScopedGameMode gm(GameMode::kPipboy); + intent = pipboyWindowInit(intent); if (intent == -1) { return -1; diff --git a/src/skilldex.cc b/src/skilldex.cc index 6955e20..6f7347e 100644 --- a/src/skilldex.cc +++ b/src/skilldex.cc @@ -109,6 +109,8 @@ static FrmImage _skilldexFrmImages[SKILLDEX_FRM_COUNT]; // 0x4ABFD0 int skilldexOpen() { + ScopedGameMode gm(GameMode::kSkilldex); + if (skilldexWindowInit() == -1) { debugPrint("\n ** Error loading skilldex dialog data! **\n"); return -1; diff --git a/src/worldmap.cc b/src/worldmap.cc index 74943ac..1fc325e 100644 --- a/src/worldmap.cc +++ b/src/worldmap.cc @@ -2958,6 +2958,8 @@ void wmWorldMap() // 0x4BFE10 static int wmWorldMapFunc(int a1) { + ScopedGameMode gm(GameMode::kWorldmap); + if (wmInterfaceInit() == -1) { wmInterfaceExit(); return -1;