summaryrefslogtreecommitdiffstats
path: root/src/control/Script.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/control/Script.cpp')
-rw-r--r--src/control/Script.cpp146
1 files changed, 8 insertions, 138 deletions
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index 02701cc0..d12196e0 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -2789,14 +2789,8 @@ bool CTheScripts::Init(bool loaddata)
for (int i = 0; i < MAX_ALLOWED_COLLISIONS; i++)
AllowedCollision[i] = 0;
-#if defined USE_ADVANCED_SCRIPT_DEBUG_OUTPUT && SCRIPT_LOG_FILE_LEVEL == 2
- CFileMgr::SetDirMyDocuments();
- if (dbg_log)
- fclose(dbg_log);
- dbg_log = fopen("SCRDBG.LOG", "w");
- static const char* init_msg = "Starting debug script log\n\n";
- PrintToLog(init_msg);
- CFileMgr::SetDir("");
+#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
+ LogAfterScriptInitializing();
#endif
#ifdef USE_MISSION_REPLAY_OVERRIDE_FOR_NON_MOBILE_SCRIPT
UsingMobileScript = false;
@@ -2924,15 +2918,7 @@ void CTheScripts::Process()
#endif
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
-#if SCRIPT_LOG_FILE_LEVEL == 1
- CFileMgr::SetDirMyDocuments();
- dbg_log = fopen("SCRDBG.LOG", "w");
- static const char* init_msg = "Starting debug script log\n\n";
- PrintToLog(init_msg);
- CFileMgr::SetDir("");
-#endif
- PrintToLog("------------------------\n");
- PrintToLog("CTheScripts::Process started, CTimer::GetTimeInMilliseconds == %u\n", CTimer::GetTimeInMilliseconds());
+ LogBeforeScriptProcessing();
#endif
CRunningScript* script = pActiveScripts;
@@ -2952,12 +2938,9 @@ void CTheScripts::Process()
-i->item.size, 450.0f, i->item.type, i->item.flareType, 1, 0, 0, 0.0f);
}
DbgFlag = false;
+
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
- PrintToLog("Script processing done, ScriptsUpdated: %d, CommandsExecuted: %d\n", ScriptsUpdated, CommandsExecuted);
-#if SCRIPT_LOG_FILE_LEVEL == 1
- fclose(dbg_log);
- dbg_log = nil;
-#endif
+ LogAfterScriptProcessing();
#endif
}
@@ -2974,7 +2957,7 @@ bool CTheScripts::IsPlayerOnAMission()
void CRunningScript::Process()
{
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
- PrintToLog("\n\nProcessing script %s (id %d)\n\n", m_abScriptName, this - CTheScripts::ScriptsArray);
+ LogOnStartProcessing();
#endif
pCurrent = this;
if (m_bIsMissionScript)
@@ -3007,66 +2990,7 @@ int8 CRunningScript::ProcessOneCommand()
m_bNotFlag = (command & 0x8000);
command &= 0x7FFF;
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
- char commandInfo[1024];
- uint32 ip = m_nIp;
- uint8 nInputParams;
- uint8 nOutputParameters;
- uint8 nLocalsOffset;
- if (command < ARRAY_SIZE(commands)) {
- script_assert(commands[command].id == command);
- m_nIp -= 2;
- sprintf(commandInfo, m_nIp >= CTheScripts::MainScriptSize ? "M<%5d> " : "<%6d> ", m_nIp >= CTheScripts::MainScriptSize ? m_nIp - CTheScripts::MainScriptSize : m_nIp);
- m_nIp += 2;
- if (m_bNotFlag)
- strcat(commandInfo, "NOT ");
- if (commands[command].position == -1)
- strcat(commandInfo, commands[command].name + sizeof("COMMAND_") - 1);
- if (commands[command].input[0] == ARGTYPE_FUNCTION) {
- char tmp[32];
- bool var = false;
- nInputParams = CTheScripts::Read1ByteFromScript(&m_nIp);
- nOutputParameters = CTheScripts::Read1ByteFromScript(&m_nIp);
- nLocalsOffset = CTheScripts::Read1ByteFromScript(&m_nIp);
- int value = CollectParameterForDebug(commandInfo, var);
- sprintf(tmp, var ? " (%s(%d))" : " %s(%d)", value >= 0 ? "G" : "L", abs(value));
- strcat(commandInfo, tmp);
- strcat(commandInfo, "{");
- for (int i = 0; i < nInputParams; i++) {
- if (i != 0)
- strcat(commandInfo, ", ");
- value = CollectParameterForDebug(commandInfo, var);
- sprintf(tmp, var ? "(%d)" : "%d", value);
- strcat(commandInfo, tmp);
-
- }
- strcat(commandInfo, "}");
- }
- else {
- for (int i = 0; commands[command].input[i] != ARGTYPE_NONE; i++) {
- char tmp[32];
- bool var = false;
- int value;
- switch (commands[command].input[i]) {
- case ARGTYPE_INT:
- case ARGTYPE_PED_HANDLE:
- case ARGTYPE_VEHICLE_HANDLE:
- case ARGTYPE_OBJECT_HANDLE: value = CollectParameterForDebug(commandInfo, var); sprintf(tmp, var ? " (%d)" : " %d", value); break;
- case ARGTYPE_FLOAT: value = CollectParameterForDebug(commandInfo, var); sprintf(tmp, var ? " (%.3f)" : " %.3f", *(float*)&value); break;
- case ARGTYPE_STRING: sprintf(tmp, " '%s'", (const char*)&CTheScripts::ScriptSpace[m_nIp]); m_nIp += KEY_LENGTH_IN_SCRIPT; break;
- case ARGTYPE_LABEL: value = CollectParameterForDebug(commandInfo, var); sprintf(tmp, var ? " (%s(%d))" : " %s(%d)", value >= 0 ? "G" : "L", abs(value)); break;
- case ARGTYPE_BOOL: value = CollectParameterForDebug(commandInfo, var); sprintf(tmp, var ? " (%s)" : " %s", value ? "TRUE" : "FALSE"); break;
- case ARGTYPE_ANDOR: value = CollectParameterForDebug(commandInfo, var); sprintf(tmp, " %d %ss", (value) % 10, value / 10 == 0 ? "AND" : "OR"); break;
- default: script_assert(0);
- }
- strcat(commandInfo, tmp);
- if (commands[command].position == i)
- strcat(commandInfo, commands[command].name_override);
- }
- }
- uint32 t = m_nIp;
- m_nIp = ip;
- ip = t;
- }
+ LogBeforeProcessingCommand(command);
#endif
if (command < 100)
retval = ProcessCommands0To99(command);
@@ -3105,38 +3029,7 @@ int8 CRunningScript::ProcessOneCommand()
else
script_assert(false);
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
- if (command < ARRAY_SIZE(commands)) {
- if (commands[command].cond || commands[command].output[0] != ARGTYPE_NONE) {
- strcat(commandInfo, " ->");
- if (commands[command].cond)
- strcat(commandInfo, m_bCondResult ? " TRUE" : " FALSE");
- uint32 t = m_nIp;
- m_nIp = ip;
- ip = t;
- if (commands[command].input[0] != ARGTYPE_FUNCTION) {
- for (int i = 0; commands[command].output[i] != ARGTYPE_NONE; i++) {
- char tmp[32];
- switch (commands[command].output[i]) {
- case ARGTYPE_INT:
- case ARGTYPE_PED_HANDLE:
- case ARGTYPE_VEHICLE_HANDLE:
- case ARGTYPE_OBJECT_HANDLE: GetStoredParameterForDebug(commandInfo); sprintf(tmp, " (%d)", ScriptParams[i]); strcat(commandInfo, tmp); break;
- case ARGTYPE_FLOAT: GetStoredParameterForDebug(commandInfo); sprintf(tmp, " (%8.3f)", *(float*)&ScriptParams[i]); strcat(commandInfo, tmp); break;
- default: script_assert(0 && "Script only returns INTs and FLOATs");
- }
- }
- }
- m_nIp = ip;
- }
- PrintToLog("%s\n", commandInfo);
- if (m_bMissionFlag) {
- for (int i = 0; commandInfo[i]; i++) {
- if (commandInfo[i] == '_')
- commandInfo[i] = ' ';
- }
- CDebug::DebugAddText(commandInfo);
- }
- }
+ LogAfterProcessingCommand(command);
#elif defined USE_BASIC_SCRIPT_DEBUG_OUTPUT
if (m_bMissionFlag) {
char tmp[128];
@@ -5332,29 +5225,6 @@ 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;