Skip to content

Commit

Permalink
Add game mode tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov committed Dec 6, 2022
1 parent 90da216 commit dc90beb
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/automap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 2 additions & 0 deletions src/character_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ static std::vector<TownReputationEntry> gCustomTownReputationEntries;
// 0x431DF8
int characterEditorShow(bool isCreationMode)
{
ScopedGameMode gm(!isCreationMode ? GameMode::kEditor : 0);

char* messageListItemText;
char line1[128];
char line2[128];
Expand Down
4 changes: 4 additions & 0 deletions src/combat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)) {
Expand Down
32 changes: 32 additions & 0 deletions src/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,8 @@ static void gameFreeGlobalVars()
// 0x443F74
static void showHelp()
{
ScopedGameMode gm(GameMode::kHelp);

bool isoWasEnabled = isoDisable();
gameMouseObjectsHide();

Expand Down Expand Up @@ -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
46 changes: 46 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
18 changes: 18 additions & 0 deletions src/game_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ int _gdialogInitFromScript(int headFid, int reaction)

_gdDialogWentOff = true;

GameMode::enterGameMode(GameMode::kDialog);

return 0;
}

Expand All @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1430,6 +1440,8 @@ int gameDialogReviewWindowFree(int* win)
// 0x445CA0
int gameDialogShowReview()
{
ScopedGameMode gm(GameMode::kDialogReview);

int win;

if (gameDialogReviewWindowInit(&win) == -1) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/inventory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ void inventoryOpen()
}
}

ScopedGameMode gm(GameMode::kInventory);

if (inventoryCommonInit() == -1) {
return;
}
Expand Down Expand Up @@ -2618,6 +2620,8 @@ static void _adjust_fid()
// 0x4717E4
void inventoryOpenUseItemOn(Object* a1)
{
ScopedGameMode gm(GameMode::kUseOn);

if (inventoryCommonInit() == -1) {
return;
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/loadsave.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ void _ResetLoadSave()
// 0x47B88C
int lsgSaveGame(int mode)
{
ScopedGameMode gm(GameMode::kSaveGame);

MessageListItem messageListItem;

_ls_error_code = 0;
Expand Down Expand Up @@ -854,6 +856,8 @@ static int _QuickSnapShot()
// 0x47C640
int lsgLoadGame(int mode)
{
ScopedGameMode gm(GameMode::kLoadGame);

MessageListItem messageListItem;

const char* body[] = {
Expand Down
4 changes: 4 additions & 0 deletions src/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/pipboy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ int pipboyOpen(int intent)
return 0;
}

ScopedGameMode gm(GameMode::kPipboy);

intent = pipboyWindowInit(intent);
if (intent == -1) {
return -1;
Expand Down
2 changes: 2 additions & 0 deletions src/skilldex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/worldmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2958,6 +2958,8 @@ void wmWorldMap()
// 0x4BFE10
static int wmWorldMapFunc(int a1)
{
ScopedGameMode gm(GameMode::kWorldmap);

if (wmInterfaceInit() == -1) {
wmInterfaceExit();
return -1;
Expand Down

0 comments on commit dc90beb

Please sign in to comment.