Skip to content

Commit dc90beb

Browse files
committed
Add game mode tracking
1 parent 90da216 commit dc90beb

File tree

12 files changed

+128
-0
lines changed

12 files changed

+128
-0
lines changed

src/automap.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ int _automapDisplayMap(int map)
297297
// 0x41B8BC
298298
void automapShow(bool isInGame, bool isUsingScanner)
299299
{
300+
ScopedGameMode gm(GameMode::kAutomap);
301+
300302
int frmIds[AUTOMAP_FRM_COUNT];
301303
memcpy(frmIds, gAutomapFrmIds, sizeof(gAutomapFrmIds));
302304

src/character_editor.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ static std::vector<TownReputationEntry> gCustomTownReputationEntries;
790790
// 0x431DF8
791791
int characterEditorShow(bool isCreationMode)
792792
{
793+
ScopedGameMode gm(!isCreationMode ? GameMode::kEditor : 0);
794+
793795
char* messageListItemText;
794796
char line1[128];
795797
char line2[128];

src/combat.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,6 +3131,8 @@ void _combat_turn_run()
31313131
// 0x4227F4
31323132
static int _combat_input()
31333133
{
3134+
ScopedGameMode gm(GameMode::kPlayerTurn);
3135+
31343136
while ((gCombatState & COMBAT_STATE_0x02) != 0) {
31353137
sharedFpsLimiter.mark();
31363138

@@ -3369,6 +3371,8 @@ static bool _combat_should_end()
33693371
// 0x422D2C
33703372
void _combat(STRUCT_664980* attack)
33713373
{
3374+
ScopedGameMode gm(GameMode::kCombat);
3375+
33723376
if (attack == NULL
33733377
|| (attack->attacker == NULL || attack->attacker->elevation == gElevation)
33743378
|| (attack->defender == NULL || attack->defender->elevation == gElevation)) {

src/game.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,8 @@ static void gameFreeGlobalVars()
11511151
// 0x443F74
11521152
static void showHelp()
11531153
{
1154+
ScopedGameMode gm(GameMode::kHelp);
1155+
11541156
bool isoWasEnabled = isoDisable();
11551157
gameMouseObjectsHide();
11561158

@@ -1437,4 +1439,34 @@ int gameShowDeathDialog(const char* message)
14371439
return rc;
14381440
}
14391441

1442+
int GameMode::currentGameMode = 0;
1443+
1444+
void GameMode::enterGameMode(int gameMode)
1445+
{
1446+
currentGameMode |= gameMode;
1447+
debugPrint("Entering game mode: %d", gameMode);
1448+
}
1449+
1450+
void GameMode::exitGameMode(int gameMode)
1451+
{
1452+
currentGameMode &= ~gameMode;
1453+
debugPrint("Exiting game mode: %d", gameMode);
1454+
}
1455+
1456+
bool GameMode::isInGameMode(int gameMode)
1457+
{
1458+
return (currentGameMode & gameMode) != 0;
1459+
}
1460+
1461+
ScopedGameMode::ScopedGameMode(int gameMode)
1462+
{
1463+
this->gameMode = gameMode;
1464+
GameMode::enterGameMode(gameMode);
1465+
}
1466+
1467+
ScopedGameMode::~ScopedGameMode()
1468+
{
1469+
GameMode::exitGameMode(gameMode);
1470+
}
1471+
14401472
} // namespace fallout

src/game.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,52 @@ int showQuitConfirmationDialog();
4141

4242
int gameShowDeathDialog(const char* message);
4343

44+
class GameMode
45+
{
46+
public:
47+
enum Flags
48+
{
49+
kWorldmap = 0x1,
50+
kDialog = 0x4,
51+
kOptions = 0x8,
52+
kSaveGame = 0x10,
53+
kLoadGame = 0x20,
54+
kCombat = 0x40,
55+
kPreferences = 0x80,
56+
kHelp = 0x100,
57+
kEditor = 0x200,
58+
kPipboy = 0x400,
59+
kPlayerTurn = 0x800,
60+
kInventory = 0x1000,
61+
kAutomap = 0x2000,
62+
kSkilldex = 0x4000,
63+
kUseOn = 0x8000,
64+
kLoot = 0x10000,
65+
kBarter = 0x20000,
66+
kHero = 0x40000,
67+
kDialogReview = 0x80000,
68+
kCounter = 0x100000,
69+
kSpecial = 0x80000000,
70+
};
71+
72+
static void enterGameMode(int gameMode);
73+
static void exitGameMode(int gameMode);
74+
static bool isInGameMode(int gameMode);
75+
static int getCurrentGameMode() { return currentGameMode; }
76+
77+
private:
78+
static int currentGameMode;
79+
};
80+
81+
class ScopedGameMode {
82+
public:
83+
ScopedGameMode(int gameMode);
84+
~ScopedGameMode();
85+
86+
private:
87+
int gameMode;
88+
};
89+
4490
} // namespace fallout
4591

4692
#endif /* GAME_H */

src/game_dialog.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,8 @@ int _gdialogInitFromScript(int headFid, int reaction)
922922

923923
_gdDialogWentOff = true;
924924

925+
GameMode::enterGameMode(GameMode::kDialog);
926+
925927
return 0;
926928
}
927929

@@ -947,7 +949,11 @@ int _gdialogExitFromScript()
947949
_tile_scroll_to(gGameDialogOldCenterTile, 2);
948950
}
949951

952+
GameMode::exitGameMode(GameMode::kDialog);
953+
954+
GameMode::enterGameMode(GameMode::kSpecial);
950955
_gdDestroyHeadWindow();
956+
GameMode::exitGameMode(GameMode::kSpecial);
951957

952958
// CE: Fix Barter button.
953959
gameDialogRedButtonsExit();
@@ -1189,10 +1195,14 @@ void _gdialogUpdatePartyStatus()
11891195
// NOTE: Uninline.
11901196
gdHide();
11911197

1198+
GameMode::enterGameMode(GameMode::kSpecial);
1199+
11921200
_gdialog_window_destroy();
11931201

11941202
gGameDialogSpeakerIsPartyMember = isPartyMember;
11951203

1204+
GameMode::exitGameMode(GameMode::kSpecial);
1205+
11961206
_gdialog_window_create();
11971207

11981208
// NOTE: Uninline.
@@ -1430,6 +1440,8 @@ int gameDialogReviewWindowFree(int* win)
14301440
// 0x445CA0
14311441
int gameDialogShowReview()
14321442
{
1443+
ScopedGameMode gm(GameMode::kDialogReview);
1444+
14331445
int win;
14341446

14351447
if (gameDialogReviewWindowInit(&win) == -1) {
@@ -1871,6 +1883,9 @@ int _gdProcess()
18711883
} else {
18721884
if (_dialogue_switch_mode == 3) {
18731885
_dialogue_state = 4;
1886+
1887+
GameMode::exitGameMode(GameMode::kSpecial);
1888+
18741889
inventoryOpenTrade(gGameDialogWindow, gGameDialogSpeaker, _peon_table_obj, _barterer_table_obj, gGameDialogBarterModifier);
18751890
_gdialog_barter_cleanup_tables();
18761891

@@ -2745,6 +2760,9 @@ void gameDialogTicker()
27452760
case 2:
27462761
_loop_cnt = -1;
27472762
_dialogue_switch_mode = 3;
2763+
2764+
GameMode::enterGameMode(GameMode::kSpecial);
2765+
27482766
_gdialog_window_destroy();
27492767
_gdialog_barter_create_win();
27502768
break;

src/inventory.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ void inventoryOpen()
548548
}
549549
}
550550

551+
ScopedGameMode gm(GameMode::kInventory);
552+
551553
if (inventoryCommonInit() == -1) {
552554
return;
553555
}
@@ -2618,6 +2620,8 @@ static void _adjust_fid()
26182620
// 0x4717E4
26192621
void inventoryOpenUseItemOn(Object* a1)
26202622
{
2623+
ScopedGameMode gm(GameMode::kUseOn);
2624+
26212625
if (inventoryCommonInit() == -1) {
26222626
return;
26232627
}
@@ -4044,6 +4048,8 @@ int inventoryOpenLooting(Object* a1, Object* a2)
40444048
return 0;
40454049
}
40464050

4051+
ScopedGameMode gm(GameMode::kLoot);
4052+
40474053
if (FID_TYPE(a2->fid) == OBJ_TYPE_CRITTER) {
40484054
if (_critter_flag_check(a2->pid, CRITTER_NO_STEAL)) {
40494055
// You can't find anything to take from that.
@@ -5018,6 +5024,8 @@ static void inventoryWindowRenderInnerInventories(int win, Object* a2, Object* a
50185024
// 0x4757F0
50195025
void inventoryOpenTrade(int win, Object* a2, Object* a3, Object* a4, int a5)
50205026
{
5027+
ScopedGameMode gm(GameMode::kBarter);
5028+
50215029
_barter_mod = a5;
50225030

50235031
if (inventoryCommonInit() == -1) {
@@ -5568,6 +5576,8 @@ static void _draw_amount(int value, int inventoryWindowType)
55685576
// 0x47688C
55695577
static int inventoryQuantitySelect(int inventoryWindowType, Object* item, int max)
55705578
{
5579+
ScopedGameMode gm(GameMode::kCounter);
5580+
55715581
inventoryQuantityWindowInit(inventoryWindowType, item);
55725582

55735583
int value;

src/loadsave.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ void _ResetLoadSave()
350350
// 0x47B88C
351351
int lsgSaveGame(int mode)
352352
{
353+
ScopedGameMode gm(GameMode::kSaveGame);
354+
353355
MessageListItem messageListItem;
354356

355357
_ls_error_code = 0;
@@ -854,6 +856,8 @@ static int _QuickSnapShot()
854856
// 0x47C640
855857
int lsgLoadGame(int mode)
856858
{
859+
ScopedGameMode gm(GameMode::kLoadGame);
860+
857861
MessageListItem messageListItem;
858862

859863
const char* body[] = {

src/options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ int showOptions()
462462
// 0x48FC50
463463
int showOptionsWithInitialKeyCode(int initialKeyCode)
464464
{
465+
ScopedGameMode gm(GameMode::kOptions);
466+
465467
if (optionsWindowInit() == -1) {
466468
debugPrint("\nOPTION MENU: Error loading option dialog data!\n");
467469
return -1;
@@ -1699,6 +1701,8 @@ static int preferencesWindowFree()
16991701
// 0x490798
17001702
static int _do_prefscreen()
17011703
{
1704+
ScopedGameMode gm(GameMode::kPreferences);
1705+
17021706
if (preferencesWindowInit() == -1) {
17031707
debugPrint("\nPREFERENCE MENU: Error loading preference dialog data!\n");
17041708
return -1;

src/pipboy.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ int pipboyOpen(int intent)
406406
return 0;
407407
}
408408

409+
ScopedGameMode gm(GameMode::kPipboy);
410+
409411
intent = pipboyWindowInit(intent);
410412
if (intent == -1) {
411413
return -1;

0 commit comments

Comments
 (0)