small refactoring

This commit is contained in:
Nikolay Korolev 2021-08-08 16:57:37 +03:00
parent 15f770531c
commit 63046894b0
8 changed files with 73 additions and 42 deletions

View File

@ -17,6 +17,9 @@
#include "FileMgr.h" #include "FileMgr.h"
#include "Frontend.h" #include "Frontend.h"
#include "General.h" #include "General.h"
#ifdef MISSION_REPLAY
#include "GenericGameStorage.h"
#endif
#include "HandlingMgr.h" #include "HandlingMgr.h"
#include "Heli.h" #include "Heli.h"
#include "Hud.h" #include "Hud.h"
@ -495,11 +498,12 @@ void CRunningScript::Init()
} }
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
int scriptToLoad = 0; int CTheScripts::ScriptToLoad = 0;
int open_script() int CTheScripts::OpenScript()
{ {
switch (scriptToLoad) { CFileMgr::ChangeDir("\\");
switch (ScriptToLoad) {
case 0: return CFileMgr::OpenFile("data\\main.scm", "rb"); case 0: return CFileMgr::OpenFile("data\\main.scm", "rb");
case 1: return CFileMgr::OpenFile("data\\main_freeroam.scm", "rb"); case 1: return CFileMgr::OpenFile("data\\main_freeroam.scm", "rb");
case 2: return CFileMgr::OpenFile("data\\main_d.scm", "rb"); case 2: return CFileMgr::OpenFile("data\\main_d.scm", "rb");
@ -523,11 +527,11 @@ void CTheScripts::Init()
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
// glfwGetKey doesn't work because of CGame::Initialise is blocking // glfwGetKey doesn't work because of CGame::Initialise is blocking
CPad::UpdatePads(); CPad::UpdatePads();
if(CPad::GetPad(0)->GetChar('G')) scriptToLoad = 0; if(CPad::GetPad(0)->GetChar('G')) ScriptToLoad = 0;
if(CPad::GetPad(0)->GetChar('R')) scriptToLoad = 1; if(CPad::GetPad(0)->GetChar('R')) ScriptToLoad = 1;
if(CPad::GetPad(0)->GetChar('D')) scriptToLoad = 2; if(CPad::GetPad(0)->GetChar('D')) ScriptToLoad = 2;
int mainf = open_script(); int mainf = OpenScript();
#else #else
CFileMgr::SetDir("data"); CFileMgr::SetDir("data");
int mainf = CFileMgr::OpenFile("main.scm", "rb"); int mainf = CFileMgr::OpenFile("main.scm", "rb");
@ -663,25 +667,25 @@ void CTheScripts::Process()
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
static uint32 TimeToWaitTill; static uint32 TimeToWaitTill;
switch (AllowMissionReplay) { switch (AllowMissionReplay) {
case 2: case MISSION_RETRY_STAGE_START_PROCESSING:
AllowMissionReplay = 3; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_DELAY;
TimeToWaitTill = CTimer::GetTimeInMilliseconds() + (AddExtraDeathDelay() > 1000 ? 4000 : 2500); TimeToWaitTill = CTimer::GetTimeInMilliseconds() + (AddExtraDeathDelay() > 1000 ? 4000 : 2500);
break; break;
case 3: case MISSION_RETRY_STAGE_WAIT_FOR_DELAY:
if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) if (TimeToWaitTill < CTimer::GetTimeInMilliseconds())
AllowMissionReplay = 4; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_MENU;
break; break;
case 4: case MISSION_RETRY_STAGE_WAIT_FOR_MENU:
AllowMissionReplay = 5; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_USER;
RetryMission(0, 0); RetryMission(0, 0);
break; break;
case 6: case MISSION_RETRY_STAGE_START_RESTARTING:
AllowMissionReplay = 7; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART;
TimeToWaitTill = CTimer::GetTimeInMilliseconds() + 500; TimeToWaitTill = CTimer::GetTimeInMilliseconds() + 500;
break; break;
case 7: case MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART:
if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) { if (TimeToWaitTill < CTimer::GetTimeInMilliseconds()) {
AllowMissionReplay = 0; AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL;
return; return;
} }
break; break;
@ -1298,11 +1302,11 @@ int8 CRunningScript::ProcessCommands0To99(int32 command)
CPlayerInfo* pPlayerInfo = &CWorld::Players[CWorld::PlayerInFocus]; CPlayerInfo* pPlayerInfo = &CWorld::Players[CWorld::PlayerInFocus];
#if 0 // makeing autosave is pointless and is a bit buggy #if 0 // makeing autosave is pointless and is a bit buggy
if (pPlayerInfo->m_pPed->GetPedState() != PED_DEAD && pPlayerInfo->m_WBState == WBSTATE_PLAYING && !m_bDeatharrestExecuted) if (pPlayerInfo->m_pPed->GetPedState() != PED_DEAD && pPlayerInfo->m_WBState == WBSTATE_PLAYING && !m_bDeatharrestExecuted)
SaveGameForPause(1); SaveGameForPause(SAVE_TYPE_QUICKSAVE);
#endif #endif
oldTargetX = oldTargetY = 0.0f; oldTargetX = oldTargetY = 0.0f;
if (AllowMissionReplay == 1) if (AllowMissionReplay == MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE)
AllowMissionReplay = 2; AllowMissionReplay = MISSION_RETRY_STAGE_START_PROCESSING;
// I am fairly sure they forgot to set return value here // I am fairly sure they forgot to set return value here
} }
#endif #endif
@ -2310,7 +2314,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command)
wchar* key = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); wchar* key = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]);
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
if (strcmp((char*)&CTheScripts::ScriptSpace[m_nIp], "M_FAIL") == 0 && CanAllowMissionReplay()) if (strcmp((char*)&CTheScripts::ScriptSpace[m_nIp], "M_FAIL") == 0 && CanAllowMissionReplay())
AllowMissionReplay = 1; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE;
#endif #endif
m_nIp += KEY_LENGTH_IN_SCRIPT; m_nIp += KEY_LENGTH_IN_SCRIPT;
CollectParameters(&m_nIp, 2); CollectParameters(&m_nIp, 2);
@ -2973,7 +2977,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command)
bool CRunningScript::CanAllowMissionReplay() bool CRunningScript::CanAllowMissionReplay()
{ {
if (AllowMissionReplay) if (AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL)
return false; return false;
if (CStats::LastMissionPassedName[0] == '\0') if (CStats::LastMissionPassedName[0] == '\0')
return false; return false;
@ -2995,14 +2999,14 @@ uint32 AddExtraDeathDelay()
void RetryMission(int type, int unk) void RetryMission(int type, int unk)
{ {
if (type == 0) { if (type == MISSION_RETRY_TYPE_SUGGEST_TO_PLAYER) {
doingMissionRetry = true; doingMissionRetry = true;
FrontEndMenuManager.m_nCurrScreen = MENUPAGE_MISSION_RETRY; FrontEndMenuManager.m_nCurrScreen = MENUPAGE_MISSION_RETRY;
FrontEndMenuManager.RequestFrontEndStartUp(); FrontEndMenuManager.RequestFrontEndStartUp();
} }
else if (type == 2) { else if (type == MISSION_RETRY_TYPE_BEGIN_RESTARTING) {
doingMissionRetry = false; doingMissionRetry = false;
AllowMissionReplay = 6; AllowMissionReplay = MISSION_RETRY_STAGE_START_RESTARTING;
CTheScripts::MissionCleanUp.Process(); CTheScripts::MissionCleanUp.Process();
} }
} }

View File

@ -584,6 +584,11 @@ public:
static void SwitchToMission(int32 mission); static void SwitchToMission(int32 mission);
#endif #endif
#ifdef USE_DEBUG_SCRIPT_LOADER
static int ScriptToLoad;
static int OpenScript();
#endif
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
static void LogAfterScriptInitializing(); static void LogAfterScriptInitializing();
static void LogBeforeScriptProcessing(); static void LogBeforeScriptProcessing();
@ -601,9 +606,21 @@ extern bool doingMissionRetry;
uint32 AddExtraDeathDelay(); uint32 AddExtraDeathDelay();
void RetryMission(int, int); void RetryMission(int, int);
#endif
#ifdef USE_DEBUG_SCRIPT_LOADER enum {
int open_script(); MISSION_RETRY_TYPE_SUGGEST_TO_PLAYER = 0,
extern int scriptToLoad; MISSION_RETRY_TYPE_1,
#endif MISSION_RETRY_TYPE_BEGIN_RESTARTING
};
enum {
MISSION_RETRY_STAGE_NORMAL = 0,
MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE,
MISSION_RETRY_STAGE_START_PROCESSING,
MISSION_RETRY_STAGE_WAIT_FOR_DELAY,
MISSION_RETRY_STAGE_WAIT_FOR_MENU,
MISSION_RETRY_STAGE_WAIT_FOR_USER,
MISSION_RETRY_STAGE_START_RESTARTING,
MISSION_RETRY_STAGE_WAIT_FOR_TIMER_AFTER_RESTART,
};
#endif

View File

@ -1239,10 +1239,10 @@ void CRunningScript::DoDeatharrestCheck()
if (!pPlayer->IsRestartingAfterDeath() && !pPlayer->IsRestartingAfterArrest() && !CTheScripts::UpsideDownCars.AreAnyCarsUpsideDown()) if (!pPlayer->IsRestartingAfterDeath() && !pPlayer->IsRestartingAfterArrest() && !CTheScripts::UpsideDownCars.AreAnyCarsUpsideDown())
return; return;
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
if (AllowMissionReplay != 0) if (AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL)
return; return;
if (CanAllowMissionReplay()) if (CanAllowMissionReplay())
AllowMissionReplay = 1; AllowMissionReplay = MISSION_RETRY_STAGE_WAIT_FOR_SCRIPT_TO_TERMINATE;
#endif #endif
script_assert(m_nStackPointer > 0); script_assert(m_nStackPointer > 0);
while (m_nStackPointer > 1) while (m_nStackPointer > 1)

View File

@ -82,8 +82,8 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command)
{ {
CollectParameters(&m_nIp, 1); CollectParameters(&m_nIp, 1);
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
AllowMissionReplay = 0; AllowMissionReplay = MISSION_RETRY_STAGE_NORMAL;
SaveGameForPause(3); SaveGameForPause(SAVE_TYPE_QUICKSAVE_FOR_MISSION_REPLAY);
#endif #endif
CPlayerInfo* pPlayerInfo = &CWorld::Players[ScriptParams[0]]; CPlayerInfo* pPlayerInfo = &CWorld::Players[ScriptParams[0]];
CPad::GetPad(ScriptParams[0])->SetDisablePlayerControls(PLAYERCONTROL_CUTSCENE); CPad::GetPad(ScriptParams[0])->SetDisablePlayerControls(PLAYERCONTROL_CUTSCENE);
@ -304,10 +304,10 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command)
#endif #endif
CTimer::Suspend(); CTimer::Suspend();
int offset = CTheScripts::MultiScriptArray[ScriptParams[0]]; int offset = CTheScripts::MultiScriptArray[ScriptParams[0]];
CFileMgr::ChangeDir("\\");
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
int handle = open_script(); int handle = CTheScripts::OpenScript();
#else #else
CFileMgr::ChangeDir("\\");
int handle = CFileMgr::OpenFile("data\\main.scm", "rb"); int handle = CFileMgr::OpenFile("data\\main.scm", "rb");
#endif #endif
CFileMgr::Seek(handle, offset, 0); CFileMgr::Seek(handle, offset, 0);

View File

@ -1423,10 +1423,10 @@ CTheScripts::SwitchToMission(int32 mission)
#endif #endif
CTimer::Suspend(); CTimer::Suspend();
int offset = CTheScripts::MultiScriptArray[mission]; int offset = CTheScripts::MultiScriptArray[mission];
CFileMgr::ChangeDir("\\");
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
int handle = open_script(); int handle = OpenScript();
#else #else
CFileMgr::ChangeDir("\\");
int handle = CFileMgr::OpenFile("data\\main.scm", "rb"); int handle = CFileMgr::OpenFile("data\\main.scm", "rb");
#endif #endif
CFileMgr::Seek(handle, offset, 0); CFileMgr::Seek(handle, offset, 0);

View File

@ -4182,7 +4182,7 @@ CMenuManager::Process(void)
#endif #endif
if (CheckSlotDataValid(m_nCurrSaveSlot)) { if (CheckSlotDataValid(m_nCurrSaveSlot)) {
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
scriptToLoad = 0; CTheScripts::ScriptToLoad = 0;
#endif #endif
#ifdef PC_PLAYER_CONTROLS #ifdef PC_PLAYER_CONTROLS
TheCamera.m_bUseMouse3rdPerson = m_ControlMethod == CONTROL_STANDARD; TheCamera.m_bUseMouse3rdPerson = m_ControlMethod == CONTROL_STANDARD;
@ -4312,12 +4312,12 @@ CMenuManager::ProcessButtonPresses(void)
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
if (m_nCurrScreen == MENUPAGE_START_MENU || m_nCurrScreen == MENUPAGE_NEW_GAME || m_nCurrScreen == MENUPAGE_NEW_GAME_RELOAD) { if (m_nCurrScreen == MENUPAGE_START_MENU || m_nCurrScreen == MENUPAGE_NEW_GAME || m_nCurrScreen == MENUPAGE_NEW_GAME_RELOAD) {
if (CPad::GetPad(0)->GetChar('R')) { if (CPad::GetPad(0)->GetChar('R')) {
scriptToLoad = 1; CTheScripts::ScriptToLoad = 1;
DoSettingsBeforeStartingAGame(); DoSettingsBeforeStartingAGame();
return; return;
} }
if (CPad::GetPad(0)->GetChar('D')) { if (CPad::GetPad(0)->GetChar('D')) {
scriptToLoad = 2; CTheScripts::ScriptToLoad = 2;
DoSettingsBeforeStartingAGame(); DoSettingsBeforeStartingAGame();
return; return;
} }

View File

@ -1153,7 +1153,9 @@ void DisplaySaveResult(int unk, char* name)
bool SaveGameForPause(int type) bool SaveGameForPause(int type)
{ {
if (AllowMissionReplay != 0 || type != 3 && WaitForSave > CTimer::GetTimeInMilliseconds()) if (AllowMissionReplay != MISSION_RETRY_STAGE_NORMAL)
return false;
if (type != SAVE_TYPE_QUICKSAVE_FOR_MISSION_REPLAY && WaitForSave > CTimer::GetTimeInMilliseconds())
return false; return false;
WaitForSave = 0; WaitForSave = 0;
if (gGameState != GS_PLAYING_GAME || CTheScripts::IsPlayerOnAMission() || CStats::LastMissionPassedName[0] == '\0') { if (gGameState != GS_PLAYING_GAME || CTheScripts::IsPlayerOnAMission() || CStats::LastMissionPassedName[0] == '\0') {

View File

@ -52,4 +52,12 @@ const char TopLineEmptyFile[] = "THIS FILE IS NOT VALID YET";
extern int8 IsQuickSave; // originally int extern int8 IsQuickSave; // originally int
bool SaveGameForPause(int); bool SaveGameForPause(int);
enum {
SAVE_TYPE_NORMAL,
SAVE_TYPE_QUICKSAVE,
SAVE_TYPE_2,
SAVE_TYPE_QUICKSAVE_FOR_MISSION_REPLAY
};
#endif #endif