summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/control/Script.cpp77
-rw-r--r--src/control/Script.h11
-rw-r--r--src/core/re3.cpp2
3 files changed, 63 insertions, 27 deletions
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index 77528b6e..957815fe 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -166,10 +166,6 @@ bool doingMissionRetry;
#endif
-#ifdef MISSION_SWITCHER
-int switchMissionTo = -1;
-#endif
-
const uint32 CRunningScript::nSaveStructSize =
#ifdef COMPATIBLE_SAVES
136;
@@ -889,18 +885,10 @@ void CRunningScript::Process()
int8 CRunningScript::ProcessOneCommand()
{
- int32 command;
-#ifdef MISSION_SWITCHER
- if (switchMissionTo != -1)
- command = COMMAND_LOAD_AND_LAUNCH_MISSION_INTERNAL;
- else
-#endif
- {
- ++CTheScripts::CommandsExecuted;
- command = CTheScripts::Read2BytesFromScript(&m_nIp);
- m_bNotFlag = (command & 0x8000);
- command &= 0x7FFF;
- }
+ ++CTheScripts::CommandsExecuted;
+ int32 command = CTheScripts::Read2BytesFromScript(&m_nIp);
+ m_bNotFlag = (command & 0x8000);
+ command &= 0x7FFF;
if (command < 100)
return ProcessCommands0To99(command);
if (command < 200)
@@ -9143,12 +9131,6 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command)
return 0;
case COMMAND_LOAD_AND_LAUNCH_MISSION_INTERNAL:
{
-#ifdef MISSION_SWITCHER
- if (switchMissionTo != -1) {
- ScriptParams[0] = switchMissionTo;
- switchMissionTo = -1;
- } else
-#endif
CollectParameters(&m_nIp, 1);
if (CTheScripts::NumberOfExclusiveMissionScripts > 0 && ScriptParams[0] <= UINT16_MAX - 2)
@@ -14480,3 +14462,54 @@ void RetryMission(int type, int unk)
}
#endif
+
+#ifdef MISSION_SWITCHER
+void
+CTheScripts::SwitchToMission(int32 mission)
+{
+ for (CRunningScript* pScript = CTheScripts::pActiveScripts; pScript != nil; pScript = pScript->GetNext()) {
+ if (!pScript->m_bIsMissionScript || !pScript->m_bDeatharrestEnabled) {
+ continue;
+ }
+ while (pScript->m_nStackPointer > 0)
+ --pScript->m_nStackPointer;
+
+ pScript->m_nIp = pScript->m_anStack[pScript->m_nStackPointer];
+ *(int32*)&CTheScripts::ScriptSpace[CTheScripts::OnAMissionFlag] = 0;
+ pScript->m_nWakeTime = 0;
+ pScript->m_bDeatharrestExecuted = true;
+
+ while (!pScript->ProcessOneCommand());
+
+ CMessages::ClearMessages();
+ }
+
+ if (CTheScripts::NumberOfExclusiveMissionScripts > 0 && mission <= UINT16_MAX - 2)
+ return;
+
+#ifdef MISSION_REPLAY
+ missionRetryScriptIndex = mission;
+ if (missionRetryScriptIndex == 19)
+ CStats::LastMissionPassedName[0] = '\0';
+#endif
+ CTimer::Suspend();
+ int offset = CTheScripts::MultiScriptArray[mission];
+#ifdef USE_DEBUG_SCRIPT_LOADER
+ CFileMgr::ChangeDir("\\data\\");
+ int handle = CFileMgr::OpenFile(scriptfile, "rb");
+ CFileMgr::ChangeDir("\\");
+#else
+ CFileMgr::ChangeDir("\\");
+ int handle = CFileMgr::OpenFile("data\\main.scm", "rb");
+#endif
+ CFileMgr::Seek(handle, offset, 0);
+ CFileMgr::Read(handle, (const char*)&CTheScripts::ScriptSpace[SIZE_MAIN_SCRIPT], SIZE_MISSION_SCRIPT);
+ CFileMgr::CloseFile(handle);
+ CRunningScript* pMissionScript = CTheScripts::StartNewScript(SIZE_MAIN_SCRIPT);
+ CTimer::Resume();
+ pMissionScript->m_bIsMissionScript = true;
+ pMissionScript->m_bMissionFlag = true;
+ CTheScripts::bAlreadyRunningAMissionScript = true;
+ CGameLogic::ClearShortCut();
+}
+#endif \ No newline at end of file
diff --git a/src/control/Script.h b/src/control/Script.h
index 45475e6e..9b2de580 100644
--- a/src/control/Script.h
+++ b/src/control/Script.h
@@ -375,6 +375,11 @@ private:
static void RemoveScriptTextureDictionary();
static void RemoveThisPed(CPed* pPed);
+#ifdef MISSION_SWITCHER
+public:
+ static void SwitchToMission(int32 mission);
+#endif
+
friend class CRunningScript;
friend class CHud;
friend void CMissionCleanup::Process();
@@ -526,6 +531,8 @@ private:
bool CheckDamagedWeaponType(int32 actual, int32 type);
static bool ThisIsAValidRandomCop(int32 mi, bool cop, bool swat, bool fbi, bool army, bool miami);
+
+ friend class CTheScripts;
};
#ifdef USE_DEBUG_SCRIPT_LOADER
@@ -545,8 +552,4 @@ void RetryMission(int, int);
#ifdef USE_DEBUG_SCRIPT_LOADER
extern int scriptToLoad;
-#endif
-
-#ifdef MISSION_SWITCHER
-extern int switchMissionTo;
#endif \ No newline at end of file
diff --git a/src/core/re3.cpp b/src/core/re3.cpp
index 76865339..5ee67195 100644
--- a/src/core/re3.cpp
+++ b/src/core/re3.cpp
@@ -315,7 +315,7 @@ int8 nextMissionToSwitch = 0;
static void
SwitchToMission(void)
{
- switchMissionTo = nextMissionToSwitch;
+ CTheScripts::SwitchToMission(nextMissionToSwitch);
}
#endif