Review game state functions

This commit is contained in:
Alexander Batalov 2022-10-03 15:54:18 +03:00
parent fe4c125474
commit e1f22b8218
6 changed files with 34 additions and 34 deletions

View File

@ -92,7 +92,7 @@ static char _aDec11199816543[] = VERSION_BUILD_TIME;
static bool gGameUiDisabled = false; static bool gGameUiDisabled = false;
// 0x5186B8 // 0x5186B8
static int _game_state_cur = GAME_STATE_0; static int gGameState = GAME_STATE_0;
// 0x5186BC // 0x5186BC
static bool gIsMapper = false; static bool gIsMapper = false;
@ -439,7 +439,7 @@ void gameExit()
int gameHandleKey(int eventCode, bool isInCombatMode) int gameHandleKey(int eventCode, bool isInCombatMode)
{ {
// NOTE: Uninline. // NOTE: Uninline.
if (_game_state() == GAME_STATE_5) { if (gameGetState() == GAME_STATE_5) {
_gdialogSystemEnter(); _gdialogSystemEnter();
} }
@ -1041,48 +1041,48 @@ int globalVarsRead(const char* path, const char* section, int* variablesListLeng
} }
// 0x443E2C // 0x443E2C
int _game_state() int gameGetState()
{ {
return _game_state_cur; return gGameState;
} }
// 0x443E34 // 0x443E34
int _game_state_request(int a1) int gameRequestState(int newGameState)
{ {
if (a1 == GAME_STATE_0) { switch (newGameState) {
a1 = GAME_STATE_1; case GAME_STATE_0:
} else if (a1 == GAME_STATE_2) { newGameState = GAME_STATE_1;
a1 = GAME_STATE_3; break;
} else if (a1 == GAME_STATE_4) { case GAME_STATE_2:
a1 = GAME_STATE_5; newGameState = GAME_STATE_3;
break;
case GAME_STATE_4:
newGameState = GAME_STATE_5;
break;
} }
if (_game_state_cur != GAME_STATE_4 || a1 != GAME_STATE_5) { if (gGameState == GAME_STATE_4 && newGameState == GAME_STATE_5) {
_game_state_cur = a1; return -1;
return 0;
} }
return -1; gGameState = newGameState;
return 0;
} }
// 0x443E90 // 0x443E90
void _game_state_update() void gameUpdateState()
{ {
int v0; switch (gGameState) {
v0 = _game_state_cur;
switch (_game_state_cur) {
case GAME_STATE_1: case GAME_STATE_1:
v0 = GAME_STATE_0; gGameState = GAME_STATE_0;
break; break;
case GAME_STATE_3: case GAME_STATE_3:
v0 = GAME_STATE_2; gGameState = GAME_STATE_2;
break; break;
case GAME_STATE_5: case GAME_STATE_5:
v0 = GAME_STATE_4; gGameState = GAME_STATE_4;
break;
} }
_game_state_cur = v0;
} }
// 0x443EF0 // 0x443EF0

View File

@ -34,9 +34,9 @@ bool gameUiIsDisabled();
int gameGetGlobalVar(int var); int gameGetGlobalVar(int var);
int gameSetGlobalVar(int var, int value); int gameSetGlobalVar(int var, int value);
int globalVarsRead(const char* path, const char* section, int* variablesListLengthPtr, int** variablesListPtr); int globalVarsRead(const char* path, const char* section, int* variablesListLengthPtr, int** variablesListPtr);
int _game_state(); int gameGetState();
int _game_state_request(int a1); int gameRequestState(int newGameState);
void _game_state_update(); void gameUpdateState();
int showQuitConfirmationDialog(); int showQuitConfirmationDialog();
int gameShowDeathDialog(const char* message); int gameShowDeathDialog(const char* message);

View File

@ -792,7 +792,7 @@ void gameDialogEnter(Object* speaker, int a2)
// 0x444FE4 // 0x444FE4
void _gdialogSystemEnter() void _gdialogSystemEnter()
{ {
_game_state_update(); gameUpdateState();
_gdDialogTurnMouseOff = true; _gdDialogTurnMouseOff = true;
@ -808,9 +808,9 @@ void _gdialogSystemEnter()
_tile_scroll_to(gGameDialogOldCenterTile, 2); _tile_scroll_to(gGameDialogOldCenterTile, 2);
} }
_game_state_request(GAME_STATE_2); gameRequestState(GAME_STATE_2);
_game_state_update(); gameUpdateState();
} }
// 0x445050 // 0x445050

View File

@ -2699,7 +2699,7 @@ static void opGameDialogSystemEnter(Program* program)
return; return;
} }
if (_game_state_request(GAME_STATE_4) == -1) { if (gameRequestState(GAME_STATE_4) == -1) {
return; return;
} }

View File

@ -599,7 +599,7 @@ void inventoryOpen()
_display_body(-1, INVENTORY_WINDOW_TYPE_NORMAL); _display_body(-1, INVENTORY_WINDOW_TYPE_NORMAL);
if (_game_state() == GAME_STATE_5) { if (gameGetState() == GAME_STATE_5) {
break; break;
} }

View File

@ -746,7 +746,7 @@ static void _script_chk_timed_events()
v1 = true; v1 = true;
} }
if (_game_state() != GAME_STATE_4) { if (gameGetState() != GAME_STATE_4) {
if (getTicksBetween(v0, _last_light_time) >= 30000) { if (getTicksBetween(v0, _last_light_time) >= 30000) {
_last_light_time = v0; _last_light_time = v0;
scriptsExecMapUpdateScripts(SCRIPT_PROC_MAP_UPDATE); scriptsExecMapUpdateScripts(SCRIPT_PROC_MAP_UPDATE);