lcs script mode

This commit is contained in:
Nikolay Korolev 2021-01-09 00:20:09 +03:00
parent 613d08d3e2
commit a9559f03b0
8 changed files with 268 additions and 110 deletions

View file

@ -49,18 +49,20 @@
#include "Timecycle.h" #include "Timecycle.h"
#include "TxdStore.h" #include "TxdStore.h"
#include "Bike.h" #include "Bike.h"
#include "memoryManager.h"
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
#include <stdarg.h> #include <stdarg.h>
#endif #endif
//--MIAMI: file done //--MIAMI: file done
uint8 CTheScripts::ScriptSpace[SIZE_SCRIPT_SPACE]; uint8* CTheScripts::ScriptSpace;
CRunningScript CTheScripts::ScriptsArray[MAX_NUM_SCRIPTS]; CRunningScript CTheScripts::ScriptsArray[MAX_NUM_SCRIPTS];
intro_text_line CTheScripts::IntroTextLines[MAX_NUM_INTRO_TEXT_LINES]; intro_text_line CTheScripts::IntroTextLines[MAX_NUM_INTRO_TEXT_LINES];
intro_script_rectangle CTheScripts::IntroRectangles[MAX_NUM_INTRO_RECTANGLES]; intro_script_rectangle CTheScripts::IntroRectangles[MAX_NUM_INTRO_RECTANGLES];
CSprite2d CTheScripts::ScriptSprites[MAX_NUM_SCRIPT_SRPITES]; CSprite2d CTheScripts::ScriptSprites[MAX_NUM_SCRIPT_SRPITES];
script_sphere_struct CTheScripts::ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES]; script_sphere_struct CTheScripts::ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES];
tCollectiveData CTheScripts::CollectiveArray[MAX_NUM_COLLECTIVES];
tUsedObject CTheScripts::UsedObjectArray[MAX_NUM_USED_OBJECTS]; tUsedObject CTheScripts::UsedObjectArray[MAX_NUM_USED_OBJECTS];
int32 CTheScripts::MultiScriptArray[MAX_NUM_MISSION_SCRIPTS]; int32 CTheScripts::MultiScriptArray[MAX_NUM_MISSION_SCRIPTS];
tBuildingSwap CTheScripts::BuildingSwapArray[MAX_NUM_BUILDING_SWAPS]; tBuildingSwap CTheScripts::BuildingSwapArray[MAX_NUM_BUILDING_SWAPS];
@ -101,6 +103,13 @@ int16 CTheScripts::CardStack[CARDS_IN_DECK * MAX_DECKS];
int16 CTheScripts::CardStackPosition; int16 CTheScripts::CardStackPosition;
#endif #endif
int CTheScripts::AllowedCollision[MAX_ALLOWED_COLLISIONS]; int CTheScripts::AllowedCollision[MAX_ALLOWED_COLLISIONS];
bool CTheScripts::FSDestroyedFlag;
short* CTheScripts::SavedVarIndices;
int CTheScripts::NumSaveVars;
int gScriptsFile = -1;
int CTheScripts::NextProcessId = 1;
bool CTheScripts::InTheScripts;
CRunningScript* pCurrent;
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
@ -226,7 +235,7 @@ const tScriptCommandData commands[] = {
REGISTER_COMMAND(COMMAND_GOSUB, INPUT_ARGUMENTS(ARGTYPE_LABEL,), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_GOSUB, INPUT_ARGUMENTS(ARGTYPE_LABEL,), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_RETURN, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_RETURN, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_LINE, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_LINE, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT, ARGTYPE_INT,), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_CREATE_PLAYER, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_CREATE_PLAYER, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(ARGTYPE_INT,), false, -1, ""),
REGISTER_COMMAND(COMMAND_GET_PLAYER_COORDINATES, INPUT_ARGUMENTS(ARGTYPE_INT,), OUTPUT_ARGUMENTS(ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT,), false, -1, ""), REGISTER_COMMAND(COMMAND_GET_PLAYER_COORDINATES, INPUT_ARGUMENTS(ARGTYPE_INT,), OUTPUT_ARGUMENTS(ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT,), false, -1, ""),
REGISTER_COMMAND(COMMAND_SET_PLAYER_COORDINATES, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_SET_PLAYER_COORDINATES, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT,), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_IS_PLAYER_IN_AREA_2D, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_BOOL,), OUTPUT_ARGUMENTS(), true, -1, ""), REGISTER_COMMAND(COMMAND_IS_PLAYER_IN_AREA_2D, INPUT_ARGUMENTS(ARGTYPE_INT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_FLOAT, ARGTYPE_BOOL,), OUTPUT_ARGUMENTS(), true, -1, ""),
@ -357,6 +366,11 @@ const tScriptCommandData commands[] = {
REGISTER_COMMAND(COMMAND_WHILE, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_WHILE, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_WHILENOT, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_WHILENOT, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_ENDWHILE, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_ENDWHILE, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_214, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_215, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_216, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_217, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_218, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_ANDOR, INPUT_ARGUMENTS(ARGTYPE_ANDOR,), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_ANDOR, INPUT_ARGUMENTS(ARGTYPE_ANDOR,), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_LAUNCH_MISSION, INPUT_ARGUMENTS(ARGTYPE_LABEL,), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_LAUNCH_MISSION, INPUT_ARGUMENTS(ARGTYPE_LABEL,), OUTPUT_ARGUMENTS(), false, -1, ""),
REGISTER_COMMAND(COMMAND_MISSION_HAS_FINISHED, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""), REGISTER_COMMAND(COMMAND_MISSION_HAS_FINISHED, INPUT_ARGUMENTS(), OUTPUT_ARGUMENTS(), false, -1, ""),
@ -2134,10 +2148,10 @@ bool CStuckCarCheck::HasCarBeenStuckForAWhile(int32 id)
return false; return false;
} }
// done(LCS)
void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameters) void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameters)
{ {
while (total--){ while (total--){
uint16 varIndex;
switch (CTheScripts::Read1ByteFromScript(pIp)) switch (CTheScripts::Read1ByteFromScript(pIp))
{ {
case ARGUMENT_END: case ARGUMENT_END:
@ -2152,7 +2166,7 @@ void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameter
*pParameters = (uint32)(uint8)CTheScripts::Read1ByteFromScript(pIp) << 24; *pParameters = (uint32)(uint8)CTheScripts::Read1ByteFromScript(pIp) << 24;
break; break;
case ARGUMENT_FLOAT_2BYTES: case ARGUMENT_FLOAT_2BYTES:
*pParameters = (uint32)(uint8)CTheScripts::Read2BytesFromScript(pIp) << 16; *pParameters = (uint32)(uint16)CTheScripts::Read2BytesFromScript(pIp) << 16;
break; break;
case ARGUMENT_FLOAT_3BYTES: case ARGUMENT_FLOAT_3BYTES:
*pParameters = (uint32)(uint8)CTheScripts::Read1ByteFromScript(pIp) << 8; *pParameters = (uint32)(uint8)CTheScripts::Read1ByteFromScript(pIp) << 8;
@ -2169,6 +2183,7 @@ void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameter
*pParameters = CTheScripts::Read2BytesFromScript(pIp); *pParameters = CTheScripts::Read2BytesFromScript(pIp);
break; break;
default: default:
*pIp -= 1;
*pParameters = *GetPointerToScriptVariable(pIp, 0); *pParameters = *GetPointerToScriptVariable(pIp, 0);
break; break;
} }
@ -2177,10 +2192,54 @@ void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameter
} }
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
// done(LCS)
int32* GetPointerToScriptVariableForDebug(CRunningScript* pScript, uint32* pIp, char* buf)
{
char tmpstr[24];
uint8 type = CTheScripts::Read1ByteFromScript(pIp);
if (type >= ARGUMENT_GLOBAL_ARRAY) {
uint8 index_in_block = CTheScripts::Read1ByteFromScript(pIp);
uint8 index_id = CTheScripts::Read1ByteFromScript(pIp);
uint8 size = CTheScripts::Read1ByteFromScript(pIp);
script_assert(size > 0);
script_assert(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id] < size);
uint8 index = Min(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id], size - 1);
sprintf(tmpstr, " $%d[%d@]", ((int)(type - ARGUMENT_GLOBAL_ARRAY) << 8) + index_in_block, index_id);
strcat(buf, tmpstr);
return (int32*)&CTheScripts::ScriptSpace[4 * (((int)(type - ARGUMENT_GLOBAL_ARRAY) << 8) + index + index_in_block)];
}
else if (type >= ARGUMENT_GLOBAL) {
uint8 index_in_block = CTheScripts::Read1ByteFromScript(pIp);
sprintf(tmpstr, " $%d", ((int)(type - ARGUMENT_GLOBAL) << 8) + index_in_block);
strcat(buf, tmpstr);
return (int32*)&CTheScripts::ScriptSpace[4 * (((int)(type - ARGUMENT_GLOBAL) << 8) + index_in_block)];
}
else if (type >= ARGUMENT_LOCAL_ARRAY) {
uint8 index_id = CTheScripts::Read1ByteFromScript(pIp);
uint8 size = CTheScripts::Read1ByteFromScript(pIp);
script_assert(size > 0);
script_assert(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id] < size);
uint8 index = Min(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id], size - 1);
sprintf(tmpstr, " %d@[%d@]", (type - ARGUMENT_LOCAL_ARRAY), index_id);
strcat(buf, tmpstr);
return &pScript->m_anLocalVariables[pScript->m_nLocalsPointer + (type - ARGUMENT_LOCAL_ARRAY) + index];
}
else if (type >= ARGUMENT_LOCAL) {
sprintf(tmpstr, " %d@", (type - ARGUMENT_LOCAL));
strcat(buf, tmpstr);
return &pScript->m_anLocalVariables[pScript->m_nLocalsPointer + (type - ARGUMENT_LOCAL)];
}
else {
assert(type >= ARGUMENT_TIMER);
sprintf(tmpstr, " TIMER%d@", (type - ARGUMENT_LOCAL_ARRAY));
strcat(buf, tmpstr);
return &pScript->m_anLocalVariables[NUM_LOCAL_VARS + 8 + (type - ARGUMENT_TIMER)]; // why 8?
}
}
// done(LCS)
int CRunningScript::CollectParameterForDebug(char* buf, bool& var) int CRunningScript::CollectParameterForDebug(char* buf, bool& var)
{ {
uint16 varIndex;
char tmpstr[24];
var = false; var = false;
int tmp; int tmp;
switch (CTheScripts::Read1ByteFromScript(&m_nIp)) switch (CTheScripts::Read1ByteFromScript(&m_nIp))
@ -2194,27 +2253,11 @@ int CRunningScript::CollectParameterForDebug(char* buf, bool& var)
case ARGUMENT_FLOAT_1BYTE: case ARGUMENT_FLOAT_1BYTE:
return (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 24; return (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 24;
case ARGUMENT_FLOAT_2BYTES: case ARGUMENT_FLOAT_2BYTES:
return (uint32)(uint8)CTheScripts::Read2BytesFromScript(&m_nIp) << 16; return (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
case ARGUMENT_FLOAT_3BYTES: case ARGUMENT_FLOAT_3BYTES:
tmp = (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 8; tmp = (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 8;
tmp |= (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16; tmp |= (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
return tmp; return tmp;
/*
case ARGUMENT_GLOBALVAR:
varIndex = CTheScripts::Read2BytesFromScript(&m_nIp);
script_assert(varIndex >= 8 && varIndex < CTheScripts::GetSizeOfVariableSpace());
var = true;
sprintf(tmpstr, " $%d", varIndex / 4);
strcat(buf, tmpstr);
return *((int32*)&CTheScripts::ScriptSpace[varIndex]);
case ARGUMENT_LOCALVAR:
varIndex = CTheScripts::Read2BytesFromScript(&m_nIp);
script_assert(varIndex >= 0 && varIndex < ARRAY_SIZE(m_anLocalVariables));
var = true;
sprintf(tmpstr, " %d@", varIndex);
strcat(buf, tmpstr);
return m_anLocalVariables[varIndex];
*/
case ARGUMENT_INT32: case ARGUMENT_INT32:
case ARGUMENT_FLOAT: case ARGUMENT_FLOAT:
return CTheScripts::Read4BytesFromScript(&m_nIp); return CTheScripts::Read4BytesFromScript(&m_nIp);
@ -2226,36 +2269,22 @@ int CRunningScript::CollectParameterForDebug(char* buf, bool& var)
return CTheScripts::Read2BytesFromScript(&m_nIp); return CTheScripts::Read2BytesFromScript(&m_nIp);
break; break;
default: default:
// TODO(LCS): GetPointerToScriptVariableForDebug(); var = true;
--m_nIp;
GetPointerToScriptVariableForDebug(this, &m_nIp, buf);
break; break;
} }
return 0; return 0;
} }
// done(LCS)
void CRunningScript::GetStoredParameterForDebug(char* buf) void CRunningScript::GetStoredParameterForDebug(char* buf)
{ {
uint16 varIndex; GetPointerToScriptVariableForDebug(this, &m_nIp, buf);
char tmpstr[24];
switch (CTheScripts::Read1ByteFromScript(&m_nIp)) {
/*
case ARGUMENT_GLOBALVAR:
varIndex = CTheScripts::Read2BytesFromScript(&m_nIp);
sprintf(tmpstr, " $%d", varIndex / 4);
strcat(buf, tmpstr);
break;
case ARGUMENT_LOCALVAR:
varIndex = CTheScripts::Read2BytesFromScript(&m_nIp);
sprintf(tmpstr, " %d@", varIndex);
strcat(buf, tmpstr);
break;
*/
default:
PrintToLog("%s - script_assertion failed in GetStoredParameterForDebug", buf);
script_assert(0);
}
} }
#endif #endif
// done(LCS)
int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip) int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip)
{ {
uint32* pIp = &ip; uint32* pIp = &ip;
@ -2271,7 +2300,7 @@ int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip)
case ARGUMENT_FLOAT_1BYTE: case ARGUMENT_FLOAT_1BYTE:
return (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 24; return (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 24;
case ARGUMENT_FLOAT_2BYTES: case ARGUMENT_FLOAT_2BYTES:
return (uint32)(uint8)CTheScripts::Read2BytesFromScript(&m_nIp) << 16; return (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
case ARGUMENT_FLOAT_3BYTES: case ARGUMENT_FLOAT_3BYTES:
tmp = (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 8; tmp = (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 8;
tmp |= (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16; tmp |= (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
@ -2285,11 +2314,13 @@ int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip)
case ARGUMENT_FLOAT: case ARGUMENT_FLOAT:
return CTheScripts::Read4BytesFromScript(pIp); return CTheScripts::Read4BytesFromScript(pIp);
default: default:
pIp--;
return *GetPointerToScriptVariable(pIp, 0); return *GetPointerToScriptVariable(pIp, 0);
} }
return -1; return -1;
} }
// done(LCS)
void CRunningScript::StoreParameters(uint32* pIp, int16 number) void CRunningScript::StoreParameters(uint32* pIp, int16 number)
{ {
for (int16 i = 0; i < number; i++){ for (int16 i = 0; i < number; i++){
@ -2297,18 +2328,60 @@ void CRunningScript::StoreParameters(uint32* pIp, int16 number)
} }
} }
// done(LCS)
int32* GetPointerToScriptVariable(CRunningScript* pScript, uint32* pIp) int32* GetPointerToScriptVariable(CRunningScript* pScript, uint32* pIp)
{ {
uint8 type = CTheScripts::Read1ByteFromScript(pIp);
if (type >= ARGUMENT_GLOBAL_ARRAY) {
uint8 index_in_block = CTheScripts::Read1ByteFromScript(pIp);
uint8 index_id = CTheScripts::Read1ByteFromScript(pIp);
uint8 size = CTheScripts::Read1ByteFromScript(pIp);
script_assert(size > 0);
script_assert(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id] < size);
uint8 index = Min(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id], size - 1);
return (int32*)&CTheScripts::ScriptSpace[((int)(type - ARGUMENT_GLOBAL_ARRAY) << 8) + index + index_in_block];
}
else if (type >= ARGUMENT_GLOBAL) {
uint8 index_in_block = CTheScripts::Read1ByteFromScript(pIp);
return (int32*)&CTheScripts::ScriptSpace[((int)(type - ARGUMENT_GLOBAL) << 8) + index_in_block];
}
else if (type >= ARGUMENT_LOCAL_ARRAY) {
uint8 index_id = CTheScripts::Read1ByteFromScript(pIp);
uint8 size = CTheScripts::Read1ByteFromScript(pIp);
script_assert(size > 0);
script_assert(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id] < size);
uint8 index = Min(pScript->m_anLocalVariables[pScript->m_nLocalsPointer + index_id], size - 1);
return &pScript->m_anLocalVariables[pScript->m_nLocalsPointer + (type - ARGUMENT_LOCAL_ARRAY) + index];
}
else if (type >= ARGUMENT_LOCAL) {
return &pScript->m_anLocalVariables[pScript->m_nLocalsPointer + (type - ARGUMENT_LOCAL)];
}
else {
assert(type >= ARGUMENT_TIMER);
return &pScript->m_anLocalVariables[NUM_LOCAL_VARS + 8 + (type - ARGUMENT_TIMER)];
}
} }
// done(LCS)
int32 *CRunningScript::GetPointerToScriptVariable(uint32* pIp, int16 type) int32 *CRunningScript::GetPointerToScriptVariable(uint32* pIp, int16 type)
{ {
return ::GetPointerToScriptVariable(this, pIp); return ::GetPointerToScriptVariable(this, pIp);
} }
// done(LCS)
int CTheScripts::GetSaveVarIndex(int var)
{
for (int i = 0; i < NumSaveVars; i++) {
if (SavedVarIndices[i] == var)
return i;
}
return -1;
}
// done(LCS)
void CRunningScript::Init() void CRunningScript::Init()
{ {
strcpy(m_abScriptName, "noname"); sprintf(m_abScriptName, "id%02i", m_nId);
next = prev = nil; next = prev = nil;
SetIP(0); SetIP(0);
for (int i = 0; i < MAX_STACK_DEPTH; i++) for (int i = 0; i < MAX_STACK_DEPTH; i++)
@ -2319,13 +2392,29 @@ void CRunningScript::Init()
m_bCondResult = false; m_bCondResult = false;
m_bIsMissionScript = false; m_bIsMissionScript = false;
m_bSkipWakeTime = false; m_bSkipWakeTime = false;
for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++) for (int i = 0; i < NUM_LOCAL_VARS + 8 + NUM_TIMERS; i++)
m_anLocalVariables[i] = 0; m_anLocalVariables[i] = 0;
m_nAndOrState = 0; m_nAndOrState = 0;
m_bNotFlag = false; m_bNotFlag = false;
m_bDeatharrestEnabled = true; m_bDeatharrestEnabled = true;
m_bDeatharrestExecuted = false; m_bDeatharrestExecuted = false;
m_bMissionFlag = false; m_bMissionFlag = false;
m_nLocalsPointer = 0;
}
// done(LCS)
void CTheScripts::Shutdown()
{
if (gScriptsFile != -1) {
CFileMgr::CloseFile(gScriptsFile);
gScriptsFile = -1;
}
if (ScriptSpace) {
base::cMainMemoryManager::Instance()->Free(ScriptSpace);
ScriptSpace = nil;
FSDestroyedFlag = false;
OnAMissionFlag = 0;
}
} }
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
@ -2355,10 +2444,11 @@ int open_script()
} }
#endif #endif
void CTheScripts::Init() // done(LCS)
bool CTheScripts::Init(bool loaddata)
{ {
for (int i = 0; i < SIZE_SCRIPT_SPACE; i++) bool retval = false;
ScriptSpace[i] = 0; printf("CTheScripts::Init\n");
pActiveScripts = pIdleScripts = nil; pActiveScripts = pIdleScripts = nil;
for (int i = 0; i < MAX_NUM_SCRIPTS; i++){ for (int i = 0; i < MAX_NUM_SCRIPTS; i++){
ScriptsArray[i].Init(); ScriptsArray[i].Init();
@ -2367,25 +2457,39 @@ void CTheScripts::Init()
MissionCleanUp.Init(); MissionCleanUp.Init();
UpsideDownCars.Init(); UpsideDownCars.Init();
StuckCars.Init(); StuckCars.Init();
CFileMgr::SetDir("data");
#ifdef USE_DEBUG_SCRIPT_LOADER
int mainf = open_script();
#else
int mainf = CFileMgr::OpenFile("main.scm", "rb");
#endif
CFileMgr::Read(mainf, (char*)ScriptSpace, SIZE_MAIN_SCRIPT);
CFileMgr::CloseFile(mainf);
CFileMgr::SetDir("");
StoreVehicleIndex = -1; StoreVehicleIndex = -1;
StoreVehicleWasRandom = true; StoreVehicleWasRandom = true;
OnAMissionFlag = 0; OnAMissionFlag = 0;
LastMissionPassedTime = (uint32)-1; LastMissionPassedTime = (uint32)-1;
for (int i = 0; i < MAX_NUM_COLLECTIVES; i++) {
CollectiveArray[i].colIndex = -1;
CollectiveArray[i].pedIndex = 0;
}
NextFreeCollectiveIndex = 0;
LastRandomPedId = -1; LastRandomPedId = -1;
for (int i = 0; i < MAX_NUM_USED_OBJECTS; i++){ for (int i = 0; i < MAX_NUM_USED_OBJECTS; i++){
memset(&UsedObjectArray[i].name, 0, sizeof(UsedObjectArray[i].name)); memset(&UsedObjectArray[i].name, 0, sizeof(UsedObjectArray[i].name));
UsedObjectArray[i].index = 0; UsedObjectArray[i].index = 0;
} }
NumberOfUsedObjects = 0; NumberOfUsedObjects = 0;
if (ScriptSpace)
Shutdown();
CFileMgr::SetDir("DATA");
#ifdef USE_DEBUG_SCRIPT_LOADER
int mainf = open_script();
#else
int mainf = CFileMgr::OpenFile("main.scm", "rb");
#endif
CFileMgr::Read(mainf, (char*)&MainScriptSize, sizeof(MainScriptSize));
int nLargestMissionSize = 0;
CFileMgr::Read(mainf, (char*)&nLargestMissionSize, sizeof(nLargestMissionSize));
// some cSmallHeap shit - TODO
ScriptSpace = (uint8*)base::cMainMemoryManager::Instance()->Allocate(MainScriptSize + nLargestMissionSize);
memset(ScriptSpace, 0, MainScriptSize + nLargestMissionSize);
CFileMgr::Read(mainf, (char*)ScriptSpace, MainScriptSize);
gScriptsFile = mainf;
CFileMgr::CloseFile(mainf);
CFileMgr::SetDir("");
ReadObjectNamesFromScript(); ReadObjectNamesFromScript();
UpdateObjectIndices(); UpdateObjectIndices();
bAlreadyRunningAMissionScript = false; bAlreadyRunningAMissionScript = false;
@ -2395,11 +2499,10 @@ void CTheScripts::Init()
NumberOfExclusiveMissionScripts = 0; NumberOfExclusiveMissionScripts = 0;
NumberOfMissionScripts = 0; NumberOfMissionScripts = 0;
LargestMissionScriptSize = 0; LargestMissionScriptSize = 0;
MainScriptSize = 0;
ReadMultiScriptFileOffsetsFromScript(); ReadMultiScriptFileOffsetsFromScript();
FailCurrentMission = 0; FailCurrentMission = 0;
DbgFlag = false; DbgFlag = false;
NumScriptDebugLines = 0; //NumScriptDebugLines = 0;
RiotIntensity = 0; RiotIntensity = 0;
bPlayerHasMetDebbieHarry = false; bPlayerHasMetDebbieHarry = false;
bPlayerIsInTheStatium = false; bPlayerIsInTheStatium = false;
@ -2423,7 +2526,7 @@ void CTheScripts::Init()
IntroRectangles[i].m_sColor = CRGBA(255, 255, 255, 255); IntroRectangles[i].m_sColor = CRGBA(255, 255, 255, 255);
} }
NumberOfIntroRectanglesThisFrame = 0; NumberOfIntroRectanglesThisFrame = 0;
RemoveScriptTextureDictionary(); RemoveScriptTextureDictionary(); // TODO(LCS) - probably not needed
for (int i = 0; i < MAX_NUM_BUILDING_SWAPS; i++){ for (int i = 0; i < MAX_NUM_BUILDING_SWAPS; i++){
BuildingSwapArray[i].m_pBuilding = nil; BuildingSwapArray[i].m_pBuilding = nil;
BuildingSwapArray[i].m_nNewModel = -1; BuildingSwapArray[i].m_nNewModel = -1;
@ -2431,6 +2534,12 @@ void CTheScripts::Init()
} }
for (int i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) for (int i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++)
InvisibilitySettingArray[i] = nil; InvisibilitySettingArray[i] = nil;
if (loaddata) {
printf("loaddata = true\n");
retval = GenericLoad();
}
for (int i = 0; i < MAX_ALLOWED_COLLISIONS; i++)
AllowedCollision[i] = 0;
#if defined USE_ADVANCED_SCRIPT_DEBUG_OUTPUT && SCRIPT_LOG_FILE_LEVEL == 2 #if defined USE_ADVANCED_SCRIPT_DEBUG_OUTPUT && SCRIPT_LOG_FILE_LEVEL == 2
CFileMgr::SetDirMyDocuments(); CFileMgr::SetDirMyDocuments();
@ -2441,8 +2550,10 @@ void CTheScripts::Init()
PrintToLog(init_msg); PrintToLog(init_msg);
CFileMgr::SetDir(""); CFileMgr::SetDir("");
#endif #endif
return retval;
} }
// LCS - to remove?
void CTheScripts::RemoveScriptTextureDictionary() void CTheScripts::RemoveScriptTextureDictionary()
{ {
for (int i = 0; i < ARRAY_SIZE(CTheScripts::ScriptSprites); i++) for (int i = 0; i < ARRAY_SIZE(CTheScripts::ScriptSprites); i++)
@ -2452,6 +2563,7 @@ void CTheScripts::RemoveScriptTextureDictionary()
CTxdStore::RemoveTxd(slot); CTxdStore::RemoveTxd(slot);
} }
// done(LCS)
void CRunningScript::RemoveScriptFromList(CRunningScript** ppScript) void CRunningScript::RemoveScriptFromList(CRunningScript** ppScript)
{ {
if (prev) if (prev)
@ -2462,6 +2574,7 @@ void CRunningScript::RemoveScriptFromList(CRunningScript** ppScript)
next->prev = prev; next->prev = prev;
} }
// done(LCS)
void CRunningScript::AddScriptToList(CRunningScript** ppScript) void CRunningScript::AddScriptToList(CRunningScript** ppScript)
{ {
next = *ppScript; next = *ppScript;
@ -2471,11 +2584,13 @@ void CRunningScript::AddScriptToList(CRunningScript** ppScript)
*ppScript = this; *ppScript = this;
} }
// done(LCS)
CRunningScript* CTheScripts::StartNewScript(uint32 ip) CRunningScript* CTheScripts::StartNewScript(uint32 ip)
{ {
CRunningScript* pNew = pIdleScripts; CRunningScript* pNew = pIdleScripts;
script_assert(pNew); script_assert(pNew);
pNew->RemoveScriptFromList(&pIdleScripts); pNew->RemoveScriptFromList(&pIdleScripts);
pNew->m_nId = NextProcessId++;
pNew->Init(); pNew->Init();
pNew->SetIP(ip); pNew->SetIP(ip);
pNew->AddScriptToList(&pActiveScripts); pNew->AddScriptToList(&pActiveScripts);
@ -2487,6 +2602,8 @@ void CTheScripts::Process()
{ {
if (CReplay::IsPlayingBack()) if (CReplay::IsPlayingBack())
return; return;
if (!ScriptSpace)
return;
CommandsExecuted = 0; CommandsExecuted = 0;
ScriptsUpdated = 0; ScriptsUpdated = 0;
float timeStep = CTimer::GetTimeStepInMilliseconds(); float timeStep = CTimer::GetTimeStepInMilliseconds();
@ -2509,6 +2626,8 @@ void CTheScripts::Process()
UseTextCommands = 0; UseTextCommands = 0;
} }
// TODO: mCoronas
#ifdef MISSION_REPLAY #ifdef MISSION_REPLAY
static uint32 TimeToWaitTill; static uint32 TimeToWaitTill;
switch (AllowMissionReplay) { switch (AllowMissionReplay) {
@ -2558,6 +2677,7 @@ void CTheScripts::Process()
#endif #endif
CRunningScript* script = pActiveScripts; CRunningScript* script = pActiveScripts;
InTheScripts = true;
while (script != nil){ while (script != nil){
CRunningScript* next = script->GetNext(); CRunningScript* next = script->GetNext();
++ScriptsUpdated; ++ScriptsUpdated;
@ -2577,21 +2697,25 @@ void CTheScripts::Process()
#endif #endif
} }
// done(LCS)
CRunningScript* CTheScripts::StartTestScript() CRunningScript* CTheScripts::StartTestScript()
{ {
return StartNewScript(0); return StartNewScript(0);
} }
// done(LCS)
bool CTheScripts::IsPlayerOnAMission() bool CTheScripts::IsPlayerOnAMission()
{ {
return OnAMissionFlag && *(int32*)&ScriptSpace[OnAMissionFlag] == 1; return OnAMissionFlag && *(int32*)&ScriptSpace[OnAMissionFlag] == 1;
} }
// done(LCS)
void CRunningScript::Process() void CRunningScript::Process()
{ {
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
PrintToLog("\n\nProcessing script %s (id %d)\n\n", m_abScriptName, this - CTheScripts::ScriptsArray); PrintToLog("\n\nProcessing script %s (id %d)\n\n", m_abScriptName, this - CTheScripts::ScriptsArray);
#endif #endif
pCurrent = this;
if (m_bIsMissionScript) if (m_bIsMissionScript)
DoDeatharrestCheck(); DoDeatharrestCheck();
if (m_bMissionFlag && CTheScripts::FailCurrentMission == 1 && m_nStackPointer == 1) if (m_bMissionFlag && CTheScripts::FailCurrentMission == 1 && m_nStackPointer == 1)
@ -2660,32 +2784,36 @@ int8 CRunningScript::ProcessOneCommand()
retval = ProcessCommands0To99(command); retval = ProcessCommands0To99(command);
else if (command < 200) else if (command < 200)
retval = ProcessCommands100To199(command); retval = ProcessCommands100To199(command);
else if (command < 300) else if (command < 305)
retval = ProcessCommands200To299(command); retval = ProcessCommands200To299(command);
else if (command < 400) else if (command < 405)
retval = ProcessCommands300To399(command); retval = ProcessCommands300To399(command);
else if (command < 500) else if (command < 505)
retval = ProcessCommands400To499(command); retval = ProcessCommands400To499(command);
else if (command < 600) else if (command < 605)
retval = ProcessCommands500To599(command); retval = ProcessCommands500To599(command);
else if (command < 700) else if (command < 705)
retval = ProcessCommands600To699(command); retval = ProcessCommands600To699(command);
else if (command < 800) else if (command < 805)
retval = ProcessCommands700To799(command); retval = ProcessCommands700To799(command);
else if (command < 900) else if (command < 905)
retval = ProcessCommands800To899(command); retval = ProcessCommands800To899(command);
else if (command < 1000) else if (command < 1005)
retval = ProcessCommands900To999(command); retval = ProcessCommands900To999(command);
else if (command < 1100) else if (command < 1105)
retval = ProcessCommands1000To1099(command); retval = ProcessCommands1000To1099(command);
else if (command < 1200) else if (command < 1205)
retval = ProcessCommands1100To1199(command); retval = ProcessCommands1100To1199(command);
else if (command < 1300) else if (command < 1305)
retval = ProcessCommands1200To1299(command); retval = ProcessCommands1200To1299(command);
else if (command < 1400) else if (command < 1405)
retval = ProcessCommands1300To1399(command); retval = ProcessCommands1300To1399(command);
else if (command < 1500) else if (command < 1497)
retval = ProcessCommands1400To1499(command); retval = ProcessCommands1400To1499(command);
//else if (command < 1600) // TODO
// retval = ProcessCommands1500To1599(command);
//else if (command < 1700)
// retval = ProcessCommands1600To1699(command);
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
if (command < ARRAY_SIZE(commands)) { if (command < ARRAY_SIZE(commands)) {
if (commands[command].cond || commands[command].output[0] != ARGTYPE_NONE) { if (commands[command].cond || commands[command].output[0] != ARGTYPE_NONE) {
@ -3242,12 +3370,12 @@ int8 CRunningScript::ProcessCommands0To99(int32 command)
case ARGUMENT_INT32: case ARGUMENT_INT32:
pNew->m_anLocalVariables[i] = CTheScripts::Read4BytesFromScript(&m_nIp); pNew->m_anLocalVariables[i] = CTheScripts::Read4BytesFromScript(&m_nIp);
break; break;
case ARGUMENT_GLOBALVAR: //case ARGUMENT_GLOBALVAR:
pNew->m_anLocalVariables[i] = *(int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(&m_nIp)]; // pNew->m_anLocalVariables[i] = *(int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(&m_nIp)];
break; // break;
case ARGUMENT_LOCALVAR: //case ARGUMENT_LOCALVAR:
pNew->m_anLocalVariables[i] = m_anLocalVariables[CTheScripts::Read2BytesFromScript(&m_nIp)]; // pNew->m_anLocalVariables[i] = m_anLocalVariables[CTheScripts::Read2BytesFromScript(&m_nIp)];
break; // break;
case ARGUMENT_INT8: case ARGUMENT_INT8:
pNew->m_anLocalVariables[i] = CTheScripts::Read1ByteFromScript(&m_nIp); pNew->m_anLocalVariables[i] = CTheScripts::Read1ByteFromScript(&m_nIp);
break; break;

View file

@ -47,7 +47,7 @@ void FlushLog();
#define KEY_LENGTH_IN_SCRIPT (8) #define KEY_LENGTH_IN_SCRIPT (8)
//#define GTA_SCRIPT_COLLECTIVE #define GTA_SCRIPT_COLLECTIVE
struct intro_script_rectangle struct intro_script_rectangle
{ {
@ -214,6 +214,13 @@ public:
bool HasCarBeenStuckForAWhile(int32); bool HasCarBeenStuckForAWhile(int32);
}; };
enum {
MAX_STACK_DEPTH = 16,
NUM_LOCAL_VARS = 96,
NUM_TIMERS = 2,
NUM_GLOBAL_SLOTS = 26
};
enum { enum {
ARGUMENT_END = 0, ARGUMENT_END = 0,
ARGUMENT_INT_ZERO, ARGUMENT_INT_ZERO,
@ -224,9 +231,17 @@ enum {
ARGUMENT_INT32, ARGUMENT_INT32,
ARGUMENT_INT8, ARGUMENT_INT8,
ARGUMENT_INT16, ARGUMENT_INT16,
ARGUMENT_FLOAT ARGUMENT_FLOAT,
ARGUMENT_TIMER,
ARGUMENT_LOCAL = ARGUMENT_TIMER + NUM_TIMERS,
ARGUMENT_LOCAL_ARRAY = ARGUMENT_LOCAL + NUM_LOCAL_VARS,
ARGUMENT_GLOBAL = ARGUMENT_LOCAL_ARRAY + NUM_LOCAL_VARS,
ARGUMENT_GLOBAL_ARRAY = ARGUMENT_GLOBAL + NUM_GLOBAL_SLOTS,
MAX_ARGUMENT = ARGUMENT_GLOBAL_ARRAY + NUM_GLOBAL_SLOTS
}; };
static_assert(MAX_ARGUMENT <= 256, "MAX_ARGUMENT must be less or equal to 256");
struct tCollectiveData struct tCollectiveData
{ {
int32 colIndex; int32 colIndex;
@ -272,10 +287,11 @@ enum {
MAX_NUM_INTRO_RECTANGLES = 16, MAX_NUM_INTRO_RECTANGLES = 16,
MAX_NUM_SCRIPT_SRPITES = 16, MAX_NUM_SCRIPT_SRPITES = 16,
MAX_NUM_SCRIPT_SPHERES = 16, MAX_NUM_SCRIPT_SPHERES = 16,
MAX_NUM_USED_OBJECTS = 220, MAX_NUM_COLLECTIVES = 32,
MAX_NUM_MISSION_SCRIPTS = 120, MAX_NUM_USED_OBJECTS = 305,
MAX_NUM_BUILDING_SWAPS = 25, MAX_NUM_MISSION_SCRIPTS = 150,
MAX_NUM_INVISIBILITY_SETTINGS = 20, MAX_NUM_BUILDING_SWAPS = 80,
MAX_NUM_INVISIBILITY_SETTINGS = 52,
MAX_NUM_STORED_LINES = 1024, MAX_NUM_STORED_LINES = 1024,
MAX_ALLOWED_COLLISIONS = 2 MAX_ALLOWED_COLLISIONS = 2
}; };
@ -283,12 +299,13 @@ enum {
class CTheScripts class CTheScripts
{ {
public: public:
static uint8 ScriptSpace[SIZE_SCRIPT_SPACE]; static uint8* ScriptSpace;
static CRunningScript ScriptsArray[MAX_NUM_SCRIPTS]; static CRunningScript ScriptsArray[MAX_NUM_SCRIPTS];
static intro_text_line IntroTextLines[MAX_NUM_INTRO_TEXT_LINES]; static intro_text_line IntroTextLines[MAX_NUM_INTRO_TEXT_LINES];
static intro_script_rectangle IntroRectangles[MAX_NUM_INTRO_RECTANGLES]; static intro_script_rectangle IntroRectangles[MAX_NUM_INTRO_RECTANGLES];
static CSprite2d ScriptSprites[MAX_NUM_SCRIPT_SRPITES]; static CSprite2d ScriptSprites[MAX_NUM_SCRIPT_SRPITES];
static script_sphere_struct ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES]; static script_sphere_struct ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES];
static tCollectiveData CollectiveArray[MAX_NUM_COLLECTIVES];
static tUsedObject UsedObjectArray[MAX_NUM_USED_OBJECTS]; static tUsedObject UsedObjectArray[MAX_NUM_USED_OBJECTS];
static int32 MultiScriptArray[MAX_NUM_MISSION_SCRIPTS]; static int32 MultiScriptArray[MAX_NUM_MISSION_SCRIPTS];
static tBuildingSwap BuildingSwapArray[MAX_NUM_BUILDING_SWAPS]; static tBuildingSwap BuildingSwapArray[MAX_NUM_BUILDING_SWAPS];
@ -328,14 +345,21 @@ public:
#define CARDS_IN_STACK (CARDS_IN_DECK * MAX_DECKS) #define CARDS_IN_STACK (CARDS_IN_DECK * MAX_DECKS)
static int16 CardStack[CARDS_IN_STACK]; static int16 CardStack[CARDS_IN_STACK];
static int16 CardStackPosition; static int16 CardStackPosition;
static int AllowedCollision[MAX_ALLOWED_COLLISIONS];
#endif #endif
static bool bPlayerIsInTheStatium; static bool bPlayerIsInTheStatium;
static uint8 RiotIntensity; static uint8 RiotIntensity;
static bool bPlayerHasMetDebbieHarry; static bool bPlayerHasMetDebbieHarry;
static void Init(); static int AllowedCollision[MAX_ALLOWED_COLLISIONS];
static short* SavedVarIndices;
static int NumSaveVars;
static bool FSDestroyedFlag;
static int NextProcessId;
static bool InTheScripts;
static CRunningScript* pCurrent;
static bool Init(bool loaddata = false);
static void Process(); static void Process();
static CRunningScript* StartTestScript(); static CRunningScript* StartTestScript();
@ -426,6 +450,9 @@ public:
static void SwitchToMission(int32 mission); static void SwitchToMission(int32 mission);
#endif #endif
static int GetSaveVarIndex(int);
static void Shutdown(void);
#ifdef GTA_SCRIPT_COLLECTIVE #ifdef GTA_SCRIPT_COLLECTIVE
static void AdvanceCollectiveIndex() static void AdvanceCollectiveIndex()
{ {
@ -447,13 +474,6 @@ public:
}; };
enum {
MAX_STACK_DEPTH = 6,
NUM_LOCAL_VARS = 16,
NUM_TIMERS = 2
};
extern int ScriptParams[32]; extern int ScriptParams[32];
class CRunningScript class CRunningScript
@ -481,11 +501,13 @@ class CRunningScript
public: public:
CRunningScript* next; CRunningScript* next;
CRunningScript* prev; CRunningScript* prev;
int m_nId;
char m_abScriptName[8]; char m_abScriptName[8];
uint32 m_nIp; uint32 m_nIp;
uint32 m_anStack[MAX_STACK_DEPTH]; uint32 m_anStack[MAX_STACK_DEPTH];
uint16 m_nStackPointer; uint16 m_nStackPointer;
int32 m_anLocalVariables[NUM_LOCAL_VARS + NUM_TIMERS]; int32 m_anLocalVariables[NUM_LOCAL_VARS + 8 + NUM_TIMERS]; // TODO(LCS): figure out why 106
int32 m_nLocalsPointer;
bool m_bIsActive; bool m_bIsActive;
bool m_bCondResult; bool m_bCondResult;
bool m_bIsMissionScript; bool m_bIsMissionScript;
@ -505,8 +527,8 @@ public:
void Load(uint8*& buf); void Load(uint8*& buf);
void UpdateTimers(float timeStep) { void UpdateTimers(float timeStep) {
m_anLocalVariables[NUM_LOCAL_VARS] += timeStep; for (int i = 0; i < NUM_TIMERS; i++)
m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep; m_anLocalVariables[NUM_LOCAL_VARS + 8 + i] += timeStep;
} }
void Init(); void Init();
@ -608,3 +630,6 @@ void RetryMission(int, int);
#ifdef USE_DEBUG_SCRIPT_LOADER #ifdef USE_DEBUG_SCRIPT_LOADER
extern int scriptToLoad; extern int scriptToLoad;
#endif #endif
extern int gScriptsFile;

View file

@ -168,7 +168,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
*/ */
case COMMAND_DISPLAY_ONSCREEN_TIMER: case COMMAND_DISPLAY_ONSCREEN_TIMER:
{ {
script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR); //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++; m_nIp++;
uint16 offset = CTheScripts::Read2BytesFromScript(&m_nIp); uint16 offset = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 1); CollectParameters(&m_nIp, 1);
@ -177,14 +177,14 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
} }
case COMMAND_CLEAR_ONSCREEN_TIMER: case COMMAND_CLEAR_ONSCREEN_TIMER:
{ {
script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR); //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++; m_nIp++;
CUserDisplay::OnscnTimer.ClearClock((uint16)CTheScripts::Read2BytesFromScript(&m_nIp)); CUserDisplay::OnscnTimer.ClearClock((uint16)CTheScripts::Read2BytesFromScript(&m_nIp));
return 0; return 0;
} }
case COMMAND_DISPLAY_ONSCREEN_COUNTER: case COMMAND_DISPLAY_ONSCREEN_COUNTER:
{ {
script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR); //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++; m_nIp++;
int16 counter = CTheScripts::Read2BytesFromScript(&m_nIp); int16 counter = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 1); CollectParameters(&m_nIp, 1);
@ -193,7 +193,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
} }
case COMMAND_CLEAR_ONSCREEN_COUNTER: case COMMAND_CLEAR_ONSCREEN_COUNTER:
{ {
script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR); //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++; m_nIp++;
CUserDisplay::OnscnTimer.ClearCounter((uint16)CTheScripts::Read2BytesFromScript(&m_nIp)); CUserDisplay::OnscnTimer.ClearCounter((uint16)CTheScripts::Read2BytesFromScript(&m_nIp));
return 0; return 0;
@ -590,7 +590,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
//case COMMAND_MOVE_CAMERA_ALONG_SPLINE: //case COMMAND_MOVE_CAMERA_ALONG_SPLINE:
//case COMMAND_GET_CAMERA_POSITION_ALONG_SPLINE: //case COMMAND_GET_CAMERA_POSITION_ALONG_SPLINE:
case COMMAND_DECLARE_MISSION_FLAG: case COMMAND_DECLARE_MISSION_FLAG:
CTheScripts::OnAMissionFlag = (uint16)CTheScripts::Read2BytesFromScript(&++m_nIp); CTheScripts::OnAMissionFlag = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) - (int32*)CTheScripts::ScriptSpace;
return 0; return 0;
case COMMAND_DECLARE_MISSION_FLAG_FOR_CONTACT: case COMMAND_DECLARE_MISSION_FLAG_FOR_CONTACT:
return 0; return 0;

View file

@ -1781,7 +1781,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command)
*/ */
case COMMAND_DISPLAY_ONSCREEN_TIMER_WITH_STRING: case COMMAND_DISPLAY_ONSCREEN_TIMER_WITH_STRING:
{ {
script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR); //script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR);
uint16 var = CTheScripts::Read2BytesFromScript(&m_nIp); uint16 var = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 1); CollectParameters(&m_nIp, 1);
wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ??? wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ???
@ -1792,7 +1792,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command)
} }
case COMMAND_DISPLAY_ONSCREEN_COUNTER_WITH_STRING: case COMMAND_DISPLAY_ONSCREEN_COUNTER_WITH_STRING:
{ {
script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR); //script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR);
uint16 var = CTheScripts::Read2BytesFromScript(&m_nIp); uint16 var = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 1); CollectParameters(&m_nIp, 1);
wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ??? wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ???

View file

@ -2556,7 +2556,7 @@ void CTheScripts::SetObjectiveForAllPedsInCollective(int colIndex, eObjective ob
} }
else { else {
pPed->bScriptObjectiveCompleted = false; pPed->bScriptObjectiveCompleted = false;
pPed->SetObjective(objective, p1, p2); //pPed->SetObjective(objective, p1, p2); TODO!
} }
} }
} }

View file

@ -540,7 +540,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command)
case COMMAND_DISPLAY_NTH_ONSCREEN_COUNTER_WITH_STRING: case COMMAND_DISPLAY_NTH_ONSCREEN_COUNTER_WITH_STRING:
{ {
char onscreen_str[12]; char onscreen_str[12];
script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR); //script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR);
uint16 var = CTheScripts::Read2BytesFromScript(&m_nIp); uint16 var = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 2); CollectParameters(&m_nIp, 2);
wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ??? wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ???

View file

@ -215,6 +215,11 @@ enum {
COMMAND_WHILE, COMMAND_WHILE,
COMMAND_WHILENOT, COMMAND_WHILENOT,
COMMAND_ENDWHILE, COMMAND_ENDWHILE,
COMMAND_214,
COMMAND_215,
COMMAND_216,
COMMAND_217,
COMMAND_218,
COMMAND_ANDOR, COMMAND_ANDOR,
COMMAND_LAUNCH_MISSION, COMMAND_LAUNCH_MISSION,
COMMAND_MISSION_HAS_FINISHED, COMMAND_MISSION_HAS_FINISHED,

View file

@ -332,7 +332,7 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually
#endif #endif
//#define SIMPLIER_MISSIONS // apply simplifications from mobile //#define SIMPLIER_MISSIONS // apply simplifications from mobile
#define USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #define USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
#define SCRIPT_LOG_FILE_LEVEL 0 // 0 == no log, 1 == overwrite every frame, 2 == full log #define SCRIPT_LOG_FILE_LEVEL 2 // 0 == no log, 1 == overwrite every frame, 2 == full log
#ifndef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT #ifndef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
#define USE_BASIC_SCRIPT_DEBUG_OUTPUT #define USE_BASIC_SCRIPT_DEBUG_OUTPUT