summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/control/Script.cpp288
-rw-r--r--src/control/Script.h65
-rw-r--r--src/control/Script2.cpp10
-rw-r--r--src/control/Script4.cpp4
-rw-r--r--src/control/Script5.cpp2
-rw-r--r--src/control/Script7.cpp2
-rw-r--r--src/control/ScriptCommands.h5
-rw-r--r--src/core/config.h2
8 files changed, 268 insertions, 110 deletions
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index ce6d6ee2..414e3f67 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -49,18 +49,20 @@
#include "Timecycle.h"
#include "TxdStore.h"
#include "Bike.h"
+#include "memoryManager.h"
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
#include <stdarg.h>
#endif
//--MIAMI: file done
-uint8 CTheScripts::ScriptSpace[SIZE_SCRIPT_SPACE];
+uint8* CTheScripts::ScriptSpace;
CRunningScript CTheScripts::ScriptsArray[MAX_NUM_SCRIPTS];
intro_text_line CTheScripts::IntroTextLines[MAX_NUM_INTRO_TEXT_LINES];
intro_script_rectangle CTheScripts::IntroRectangles[MAX_NUM_INTRO_RECTANGLES];
CSprite2d CTheScripts::ScriptSprites[MAX_NUM_SCRIPT_SRPITES];
script_sphere_struct CTheScripts::ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES];
+tCollectiveData CTheScripts::CollectiveArray[MAX_NUM_COLLECTIVES];
tUsedObject CTheScripts::UsedObjectArray[MAX_NUM_USED_OBJECTS];
int32 CTheScripts::MultiScriptArray[MAX_NUM_MISSION_SCRIPTS];
tBuildingSwap CTheScripts::BuildingSwapArray[MAX_NUM_BUILDING_SWAPS];
@@ -101,6 +103,13 @@ int16 CTheScripts::CardStack[CARDS_IN_DECK * MAX_DECKS];
int16 CTheScripts::CardStackPosition;
#endif
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
@@ -226,7 +235,7 @@ const tScriptCommandData commands[] = {
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_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_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, ""),
@@ -357,6 +366,11 @@ const tScriptCommandData commands[] = {
REGISTER_COMMAND(COMMAND_WHILE, 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_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_LAUNCH_MISSION, INPUT_ARGUMENTS(ARGTYPE_LABEL,), 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;
}
+// done(LCS)
void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameters)
{
while (total--){
- uint16 varIndex;
switch (CTheScripts::Read1ByteFromScript(pIp))
{
case ARGUMENT_END:
@@ -2152,7 +2166,7 @@ void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameter
*pParameters = (uint32)(uint8)CTheScripts::Read1ByteFromScript(pIp) << 24;
break;
case ARGUMENT_FLOAT_2BYTES:
- *pParameters = (uint32)(uint8)CTheScripts::Read2BytesFromScript(pIp) << 16;
+ *pParameters = (uint32)(uint16)CTheScripts::Read2BytesFromScript(pIp) << 16;
break;
case ARGUMENT_FLOAT_3BYTES:
*pParameters = (uint32)(uint8)CTheScripts::Read1ByteFromScript(pIp) << 8;
@@ -2169,6 +2183,7 @@ void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameter
*pParameters = CTheScripts::Read2BytesFromScript(pIp);
break;
default:
+ *pIp -= 1;
*pParameters = *GetPointerToScriptVariable(pIp, 0);
break;
}
@@ -2177,10 +2192,54 @@ void CRunningScript::CollectParameters(uint32* pIp, int16 total, int* pParameter
}
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
-int CRunningScript::CollectParameterForDebug(char* buf, bool& var)
+// done(LCS)
+int32* GetPointerToScriptVariableForDebug(CRunningScript* pScript, uint32* pIp, char* buf)
{
- uint16 varIndex;
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)
+{
var = false;
int tmp;
switch (CTheScripts::Read1ByteFromScript(&m_nIp))
@@ -2194,27 +2253,11 @@ int CRunningScript::CollectParameterForDebug(char* buf, bool& var)
case ARGUMENT_FLOAT_1BYTE:
return (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 24;
case ARGUMENT_FLOAT_2BYTES:
- return (uint32)(uint8)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
+ return (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
case ARGUMENT_FLOAT_3BYTES:
tmp = (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 8;
tmp |= (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
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_FLOAT:
return CTheScripts::Read4BytesFromScript(&m_nIp);
@@ -2226,36 +2269,22 @@ int CRunningScript::CollectParameterForDebug(char* buf, bool& var)
return CTheScripts::Read2BytesFromScript(&m_nIp);
break;
default:
- // TODO(LCS): GetPointerToScriptVariableForDebug();
+ var = true;
+ --m_nIp;
+ GetPointerToScriptVariableForDebug(this, &m_nIp, buf);
break;
}
return 0;
}
+// done(LCS)
void CRunningScript::GetStoredParameterForDebug(char* buf)
{
- uint16 varIndex;
- 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);
- }
+ GetPointerToScriptVariableForDebug(this, &m_nIp, buf);
}
#endif
+// done(LCS)
int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip)
{
uint32* pIp = &ip;
@@ -2271,7 +2300,7 @@ int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip)
case ARGUMENT_FLOAT_1BYTE:
return (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 24;
case ARGUMENT_FLOAT_2BYTES:
- return (uint32)(uint8)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
+ return (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
case ARGUMENT_FLOAT_3BYTES:
tmp = (uint32)(uint8)CTheScripts::Read1ByteFromScript(&m_nIp) << 8;
tmp |= (uint32)(uint16)CTheScripts::Read2BytesFromScript(&m_nIp) << 16;
@@ -2285,11 +2314,13 @@ int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip)
case ARGUMENT_FLOAT:
return CTheScripts::Read4BytesFromScript(pIp);
default:
+ pIp--;
return *GetPointerToScriptVariable(pIp, 0);
}
return -1;
}
+// done(LCS)
void CRunningScript::StoreParameters(uint32* pIp, int16 number)
{
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)
{
+ 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)
{
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()
{
- strcpy(m_abScriptName, "noname");
+ sprintf(m_abScriptName, "id%02i", m_nId);
next = prev = nil;
SetIP(0);
for (int i = 0; i < MAX_STACK_DEPTH; i++)
@@ -2319,13 +2392,29 @@ void CRunningScript::Init()
m_bCondResult = false;
m_bIsMissionScript = 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_nAndOrState = 0;
m_bNotFlag = false;
m_bDeatharrestEnabled = true;
m_bDeatharrestExecuted = 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
@@ -2355,10 +2444,11 @@ int open_script()
}
#endif
-void CTheScripts::Init()
+// done(LCS)
+bool CTheScripts::Init(bool loaddata)
{
- for (int i = 0; i < SIZE_SCRIPT_SPACE; i++)
- ScriptSpace[i] = 0;
+ bool retval = false;
+ printf("CTheScripts::Init\n");
pActiveScripts = pIdleScripts = nil;
for (int i = 0; i < MAX_NUM_SCRIPTS; i++){
ScriptsArray[i].Init();
@@ -2367,25 +2457,39 @@ void CTheScripts::Init()
MissionCleanUp.Init();
UpsideDownCars.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;
StoreVehicleWasRandom = true;
OnAMissionFlag = 0;
LastMissionPassedTime = (uint32)-1;
+ for (int i = 0; i < MAX_NUM_COLLECTIVES; i++) {
+ CollectiveArray[i].colIndex = -1;
+ CollectiveArray[i].pedIndex = 0;
+ }
+ NextFreeCollectiveIndex = 0;
LastRandomPedId = -1;
for (int i = 0; i < MAX_NUM_USED_OBJECTS; i++){
memset(&UsedObjectArray[i].name, 0, sizeof(UsedObjectArray[i].name));
UsedObjectArray[i].index = 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();
UpdateObjectIndices();
bAlreadyRunningAMissionScript = false;
@@ -2395,11 +2499,10 @@ void CTheScripts::Init()
NumberOfExclusiveMissionScripts = 0;
NumberOfMissionScripts = 0;
LargestMissionScriptSize = 0;
- MainScriptSize = 0;
ReadMultiScriptFileOffsetsFromScript();
FailCurrentMission = 0;
DbgFlag = false;
- NumScriptDebugLines = 0;
+ //NumScriptDebugLines = 0;
RiotIntensity = 0;
bPlayerHasMetDebbieHarry = false;
bPlayerIsInTheStatium = false;
@@ -2423,7 +2526,7 @@ void CTheScripts::Init()
IntroRectangles[i].m_sColor = CRGBA(255, 255, 255, 255);
}
NumberOfIntroRectanglesThisFrame = 0;
- RemoveScriptTextureDictionary();
+ RemoveScriptTextureDictionary(); // TODO(LCS) - probably not needed
for (int i = 0; i < MAX_NUM_BUILDING_SWAPS; i++){
BuildingSwapArray[i].m_pBuilding = nil;
BuildingSwapArray[i].m_nNewModel = -1;
@@ -2431,6 +2534,12 @@ void CTheScripts::Init()
}
for (int i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++)
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
CFileMgr::SetDirMyDocuments();
@@ -2441,8 +2550,10 @@ void CTheScripts::Init()
PrintToLog(init_msg);
CFileMgr::SetDir("");
#endif
+ return retval;
}
+// LCS - to remove?
void CTheScripts::RemoveScriptTextureDictionary()
{
for (int i = 0; i < ARRAY_SIZE(CTheScripts::ScriptSprites); i++)
@@ -2452,6 +2563,7 @@ void CTheScripts::RemoveScriptTextureDictionary()
CTxdStore::RemoveTxd(slot);
}
+// done(LCS)
void CRunningScript::RemoveScriptFromList(CRunningScript** ppScript)
{
if (prev)
@@ -2462,6 +2574,7 @@ void CRunningScript::RemoveScriptFromList(CRunningScript** ppScript)
next->prev = prev;
}
+// done(LCS)
void CRunningScript::AddScriptToList(CRunningScript** ppScript)
{
next = *ppScript;
@@ -2471,11 +2584,13 @@ void CRunningScript::AddScriptToList(CRunningScript** ppScript)
*ppScript = this;
}
+// done(LCS)
CRunningScript* CTheScripts::StartNewScript(uint32 ip)
{
CRunningScript* pNew = pIdleScripts;
script_assert(pNew);
pNew->RemoveScriptFromList(&pIdleScripts);
+ pNew->m_nId = NextProcessId++;
pNew->Init();
pNew->SetIP(ip);
pNew->AddScriptToList(&pActiveScripts);
@@ -2487,6 +2602,8 @@ void CTheScripts::Process()
{
if (CReplay::IsPlayingBack())
return;
+ if (!ScriptSpace)
+ return;
CommandsExecuted = 0;
ScriptsUpdated = 0;
float timeStep = CTimer::GetTimeStepInMilliseconds();
@@ -2509,6 +2626,8 @@ void CTheScripts::Process()
UseTextCommands = 0;
}
+ // TODO: mCoronas
+
#ifdef MISSION_REPLAY
static uint32 TimeToWaitTill;
switch (AllowMissionReplay) {
@@ -2558,6 +2677,7 @@ void CTheScripts::Process()
#endif
CRunningScript* script = pActiveScripts;
+ InTheScripts = true;
while (script != nil){
CRunningScript* next = script->GetNext();
++ScriptsUpdated;
@@ -2577,21 +2697,25 @@ void CTheScripts::Process()
#endif
}
+// done(LCS)
CRunningScript* CTheScripts::StartTestScript()
{
return StartNewScript(0);
}
+// done(LCS)
bool CTheScripts::IsPlayerOnAMission()
{
return OnAMissionFlag && *(int32*)&ScriptSpace[OnAMissionFlag] == 1;
}
+// done(LCS)
void CRunningScript::Process()
{
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
PrintToLog("\n\nProcessing script %s (id %d)\n\n", m_abScriptName, this - CTheScripts::ScriptsArray);
#endif
+ pCurrent = this;
if (m_bIsMissionScript)
DoDeatharrestCheck();
if (m_bMissionFlag && CTheScripts::FailCurrentMission == 1 && m_nStackPointer == 1)
@@ -2660,32 +2784,36 @@ int8 CRunningScript::ProcessOneCommand()
retval = ProcessCommands0To99(command);
else if (command < 200)
retval = ProcessCommands100To199(command);
- else if (command < 300)
+ else if (command < 305)
retval = ProcessCommands200To299(command);
- else if (command < 400)
+ else if (command < 405)
retval = ProcessCommands300To399(command);
- else if (command < 500)
+ else if (command < 505)
retval = ProcessCommands400To499(command);
- else if (command < 600)
+ else if (command < 605)
retval = ProcessCommands500To599(command);
- else if (command < 700)
+ else if (command < 705)
retval = ProcessCommands600To699(command);
- else if (command < 800)
+ else if (command < 805)
retval = ProcessCommands700To799(command);
- else if (command < 900)
+ else if (command < 905)
retval = ProcessCommands800To899(command);
- else if (command < 1000)
+ else if (command < 1005)
retval = ProcessCommands900To999(command);
- else if (command < 1100)
+ else if (command < 1105)
retval = ProcessCommands1000To1099(command);
- else if (command < 1200)
+ else if (command < 1205)
retval = ProcessCommands1100To1199(command);
- else if (command < 1300)
+ else if (command < 1305)
retval = ProcessCommands1200To1299(command);
- else if (command < 1400)
+ else if (command < 1405)
retval = ProcessCommands1300To1399(command);
- else if (command < 1500)
+ else if (command < 1497)
retval = ProcessCommands1400To1499(command);
+ //else if (command < 1600) // TODO
+ // retval = ProcessCommands1500To1599(command);
+ //else if (command < 1700)
+ // retval = ProcessCommands1600To1699(command);
#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
if (command < ARRAY_SIZE(commands)) {
if (commands[command].cond || commands[command].output[0] != ARGTYPE_NONE) {
@@ -3242,12 +3370,12 @@ int8 CRunningScript::ProcessCommands0To99(int32 command)
case ARGUMENT_INT32:
pNew->m_anLocalVariables[i] = CTheScripts::Read4BytesFromScript(&m_nIp);
break;
- case ARGUMENT_GLOBALVAR:
- pNew->m_anLocalVariables[i] = *(int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(&m_nIp)];
- break;
- case ARGUMENT_LOCALVAR:
- pNew->m_anLocalVariables[i] = m_anLocalVariables[CTheScripts::Read2BytesFromScript(&m_nIp)];
- break;
+ //case ARGUMENT_GLOBALVAR:
+ // pNew->m_anLocalVariables[i] = *(int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(&m_nIp)];
+ // break;
+ //case ARGUMENT_LOCALVAR:
+ // pNew->m_anLocalVariables[i] = m_anLocalVariables[CTheScripts::Read2BytesFromScript(&m_nIp)];
+ // break;
case ARGUMENT_INT8:
pNew->m_anLocalVariables[i] = CTheScripts::Read1ByteFromScript(&m_nIp);
break;
diff --git a/src/control/Script.h b/src/control/Script.h
index e4196220..0a7f64bf 100644
--- a/src/control/Script.h
+++ b/src/control/Script.h
@@ -47,7 +47,7 @@ void FlushLog();
#define KEY_LENGTH_IN_SCRIPT (8)
-//#define GTA_SCRIPT_COLLECTIVE
+#define GTA_SCRIPT_COLLECTIVE
struct intro_script_rectangle
{
@@ -215,6 +215,13 @@ public:
};
enum {
+ MAX_STACK_DEPTH = 16,
+ NUM_LOCAL_VARS = 96,
+ NUM_TIMERS = 2,
+ NUM_GLOBAL_SLOTS = 26
+};
+
+enum {
ARGUMENT_END = 0,
ARGUMENT_INT_ZERO,
ARGUMENT_FLOAT_ZERO,
@@ -224,9 +231,17 @@ enum {
ARGUMENT_INT32,
ARGUMENT_INT8,
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
{
int32 colIndex;
@@ -272,10 +287,11 @@ enum {
MAX_NUM_INTRO_RECTANGLES = 16,
MAX_NUM_SCRIPT_SRPITES = 16,
MAX_NUM_SCRIPT_SPHERES = 16,
- MAX_NUM_USED_OBJECTS = 220,
- MAX_NUM_MISSION_SCRIPTS = 120,
- MAX_NUM_BUILDING_SWAPS = 25,
- MAX_NUM_INVISIBILITY_SETTINGS = 20,
+ MAX_NUM_COLLECTIVES = 32,
+ MAX_NUM_USED_OBJECTS = 305,
+ MAX_NUM_MISSION_SCRIPTS = 150,
+ MAX_NUM_BUILDING_SWAPS = 80,
+ MAX_NUM_INVISIBILITY_SETTINGS = 52,
MAX_NUM_STORED_LINES = 1024,
MAX_ALLOWED_COLLISIONS = 2
};
@@ -283,12 +299,13 @@ enum {
class CTheScripts
{
public:
- static uint8 ScriptSpace[SIZE_SCRIPT_SPACE];
+ static uint8* ScriptSpace;
static CRunningScript ScriptsArray[MAX_NUM_SCRIPTS];
static intro_text_line IntroTextLines[MAX_NUM_INTRO_TEXT_LINES];
static intro_script_rectangle IntroRectangles[MAX_NUM_INTRO_RECTANGLES];
static CSprite2d ScriptSprites[MAX_NUM_SCRIPT_SRPITES];
static script_sphere_struct ScriptSphereArray[MAX_NUM_SCRIPT_SPHERES];
+ static tCollectiveData CollectiveArray[MAX_NUM_COLLECTIVES];
static tUsedObject UsedObjectArray[MAX_NUM_USED_OBJECTS];
static int32 MultiScriptArray[MAX_NUM_MISSION_SCRIPTS];
static tBuildingSwap BuildingSwapArray[MAX_NUM_BUILDING_SWAPS];
@@ -328,14 +345,21 @@ public:
#define CARDS_IN_STACK (CARDS_IN_DECK * MAX_DECKS)
static int16 CardStack[CARDS_IN_STACK];
static int16 CardStackPosition;
-
- static int AllowedCollision[MAX_ALLOWED_COLLISIONS];
#endif
+
static bool bPlayerIsInTheStatium;
static uint8 RiotIntensity;
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 CRunningScript* StartTestScript();
@@ -426,6 +450,9 @@ public:
static void SwitchToMission(int32 mission);
#endif
+ static int GetSaveVarIndex(int);
+ static void Shutdown(void);
+
#ifdef GTA_SCRIPT_COLLECTIVE
static void AdvanceCollectiveIndex()
{
@@ -447,13 +474,6 @@ public:
};
-
-enum {
- MAX_STACK_DEPTH = 6,
- NUM_LOCAL_VARS = 16,
- NUM_TIMERS = 2
-};
-
extern int ScriptParams[32];
class CRunningScript
@@ -481,11 +501,13 @@ class CRunningScript
public:
CRunningScript* next;
CRunningScript* prev;
+ int m_nId;
char m_abScriptName[8];
uint32 m_nIp;
uint32 m_anStack[MAX_STACK_DEPTH];
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_bCondResult;
bool m_bIsMissionScript;
@@ -505,8 +527,8 @@ public:
void Load(uint8*& buf);
void UpdateTimers(float timeStep) {
- m_anLocalVariables[NUM_LOCAL_VARS] += timeStep;
- m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep;
+ for (int i = 0; i < NUM_TIMERS; i++)
+ m_anLocalVariables[NUM_LOCAL_VARS + 8 + i] += timeStep;
}
void Init();
@@ -608,3 +630,6 @@ void RetryMission(int, int);
#ifdef USE_DEBUG_SCRIPT_LOADER
extern int scriptToLoad;
#endif
+
+extern int gScriptsFile;
+
diff --git a/src/control/Script2.cpp b/src/control/Script2.cpp
index a94bf907..10f122ca 100644
--- a/src/control/Script2.cpp
+++ b/src/control/Script2.cpp
@@ -168,7 +168,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
*/
case COMMAND_DISPLAY_ONSCREEN_TIMER:
{
- script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
+ //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++;
uint16 offset = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 1);
@@ -177,14 +177,14 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
}
case COMMAND_CLEAR_ONSCREEN_TIMER:
{
- script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
+ //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++;
CUserDisplay::OnscnTimer.ClearClock((uint16)CTheScripts::Read2BytesFromScript(&m_nIp));
return 0;
}
case COMMAND_DISPLAY_ONSCREEN_COUNTER:
{
- script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
+ //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++;
int16 counter = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 1);
@@ -193,7 +193,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
}
case COMMAND_CLEAR_ONSCREEN_COUNTER:
{
- script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
+ //script_assert(CTheScripts::ScriptSpace[m_nIp] == ARGUMENT_GLOBALVAR);
m_nIp++;
CUserDisplay::OnscnTimer.ClearCounter((uint16)CTheScripts::Read2BytesFromScript(&m_nIp));
return 0;
@@ -590,7 +590,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command)
//case COMMAND_MOVE_CAMERA_ALONG_SPLINE:
//case COMMAND_GET_CAMERA_POSITION_ALONG_SPLINE:
case COMMAND_DECLARE_MISSION_FLAG:
- CTheScripts::OnAMissionFlag = (uint16)CTheScripts::Read2BytesFromScript(&++m_nIp);
+ CTheScripts::OnAMissionFlag = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) - (int32*)CTheScripts::ScriptSpace;
return 0;
case COMMAND_DECLARE_MISSION_FLAG_FOR_CONTACT:
return 0;
diff --git a/src/control/Script4.cpp b/src/control/Script4.cpp
index a8658532..64928e7a 100644
--- a/src/control/Script4.cpp
+++ b/src/control/Script4.cpp
@@ -1781,7 +1781,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command)
*/
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);
CollectParameters(&m_nIp, 1);
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:
{
- script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR);
+ //script_assert(CTheScripts::ScriptSpace[m_nIp++] == ARGUMENT_GLOBALVAR);
uint16 var = CTheScripts::Read2BytesFromScript(&m_nIp);
CollectParameters(&m_nIp, 1);
wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ???
diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp
index 822a70a8..ef680672 100644
--- a/src/control/Script5.cpp
+++ b/src/control/Script5.cpp
@@ -2556,7 +2556,7 @@ void CTheScripts::SetObjectiveForAllPedsInCollective(int colIndex, eObjective ob
}
else {
pPed->bScriptObjectiveCompleted = false;
- pPed->SetObjective(objective, p1, p2);
+ //pPed->SetObjective(objective, p1, p2); TODO!
}
}
}
diff --git a/src/control/Script7.cpp b/src/control/Script7.cpp
index 1eaa6cd0..12bb18d7 100644
--- a/src/control/Script7.cpp
+++ b/src/control/Script7.cpp
@@ -540,7 +540,7 @@ int8 CRunningScript::ProcessCommands1200To1299(int32 command)
case COMMAND_DISPLAY_NTH_ONSCREEN_COUNTER_WITH_STRING:
{
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);
CollectParameters(&m_nIp, 2);
wchar* text = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]); // ???
diff --git a/src/control/ScriptCommands.h b/src/control/ScriptCommands.h
index 9863e852..8cf73abd 100644
--- a/src/control/ScriptCommands.h
+++ b/src/control/ScriptCommands.h
@@ -215,6 +215,11 @@ enum {
COMMAND_WHILE,
COMMAND_WHILENOT,
COMMAND_ENDWHILE,
+ COMMAND_214,
+ COMMAND_215,
+ COMMAND_216,
+ COMMAND_217,
+ COMMAND_218,
COMMAND_ANDOR,
COMMAND_LAUNCH_MISSION,
COMMAND_MISSION_HAS_FINISHED,
diff --git a/src/core/config.h b/src/core/config.h
index 7dfb5bba..a06977f8 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -332,7 +332,7 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually
#endif
//#define SIMPLIER_MISSIONS // apply simplifications from mobile
#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
#define USE_BASIC_SCRIPT_DEBUG_OUTPUT