summaryrefslogtreecommitdiffstats
path: root/src/control/Script.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/control/Script.cpp831
1 files changed, 825 insertions, 6 deletions
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index b50c101e..bd43d301 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -4,10 +4,17 @@
#include "Script.h"
#include "ScriptCommands.h"
+#include "Boat.h"
#include "Camera.h"
#include "CarCtrl.h"
+#include "CivilianPed.h"
+#include "Clock.h"
+#include "CopPed.h"
#include "DMAudio.h"
+#include "EmergencyPed.h"
#include "FileMgr.h"
+#include "General.h"
+#include "HandlingMgr.h"
#include "Hud.h"
#include "Messages.h"
#include "ModelIndices.h"
@@ -18,9 +25,11 @@
#include "Population.h"
#include "Replay.h"
#include "Streaming.h"
+#include "Text.h"
#include "User.h"
#include "Weather.h"
#include "World.h"
+#include "Zones.h"
uint8 (&CTheScripts::ScriptSpace)[SIZE_SCRIPT_SPACE] = *(uint8(*)[SIZE_SCRIPT_SPACE])*(uintptr*)0x74B248;
CRunningScript(&CTheScripts::ScriptsArray)[MAX_NUM_SCRIPTS] = *(CRunningScript(*)[MAX_NUM_SCRIPTS])*(uintptr*)0x6F5C08;
@@ -70,6 +79,7 @@ CMissionCleanup::CMissionCleanup()
void CMissionCleanup::Init()
{
+ m_nCount = 0;
for (int i = 0; i < MAX_CLEANUP; i++){
m_sEntities[i].type = CLEANUP_UNUSED;
m_sEntities[i].id = 0;
@@ -93,7 +103,7 @@ void CMissionCleanup::AddEntityToList(int32 id, uint8 type)
return;
pNew->id = id;
pNew->type = type;
- m_bCount++;
+ m_nCount++;
}
void CMissionCleanup::RemoveEntityFromList(int32 id, uint8 type)
@@ -102,6 +112,7 @@ void CMissionCleanup::RemoveEntityFromList(int32 id, uint8 type)
if (m_sEntities[i].type == type && m_sEntities[i].id == id){
m_sEntities[i].id = 0;
m_sEntities[i].type = CLEANUP_UNUSED;
+ m_nCount--;
}
}
}
@@ -124,8 +135,8 @@ void CMissionCleanup::Process()
CHud::m_ItemToFlash = -1;
CHud::SetHelpMessage(nil, false);
CUserDisplay::OnscnTimer.m_bDisabled = false;
- CWorld::Players[0].m_pPed->m_pWanted->m_IsIgnoredByCops = false;
- CWorld::Players[0].m_pPed->m_pWanted->m_IsIgnoredByEveryOne = false;
+ CWorld::Players[0].m_pPed->m_pWanted->m_bIgnoredByCops = false;
+ CWorld::Players[0].m_pPed->m_pWanted->m_bIgnoredByEveryone = false;
CWorld::Players[0].MakePlayerSafe(false);
CTheScripts::StoreVehicleIndex = -1;
CTheScripts::StoreVehicleWasRandom = true;
@@ -594,7 +605,7 @@ void CTheScripts::Process()
if (UseTextCommands){
for (int i = 0; i < MAX_NUM_INTRO_TEXT_LINES; i++)
IntroTextLines[i].Reset();
- NumberOfIntroRectanglesThisFrame = 0;
+ NumberOfIntroTextLinesThisFrame = 0;
for (int i = 0; i < MAX_NUM_INTRO_RECTANGLES; i++){
IntroRectangles[i].m_bIsUsed = false;
IntroRectangles[i].m_bBeforeFade = false;
@@ -701,7 +712,7 @@ int8 CRunningScript::ProcessCommandsFrom0To99(int32 command)
return 0;
case COMMAND_SHAKE_CAM:
CollectParameters(&m_nIp, 1);
- TheCamera.CamShake(ScriptParams[0] / 1000.0f);
+ CamShakeNoPos(&TheCamera, ScriptParams[0] / 1000.0f);
return 0;
case COMMAND_SET_VAR_INT:
{
@@ -1342,6 +1353,7 @@ int8 CRunningScript::ProcessCommandsFrom0To99(int32 command)
*(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
return 0;
default:
+ assert(0);
break;
}
return -1;
@@ -1374,7 +1386,814 @@ void CRunningScript::UpdateCompareFlag(bool flag)
}
-WRAPPER int8 CRunningScript::ProcessCommandsFrom100To199(int32 command) { EAXJMP(0x43AEA0); }
+int8 CRunningScript::ProcessCommandsFrom100To199(int32 command)
+{
+ switch (command) {
+ case COMMAND_SUB_INT_LVAR_FROM_INT_VAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_SUB_INT_VAR_FROM_INT_LVAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_SUB_FLOAT_LVAR_FROM_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_SUB_FLOAT_VAR_FROM_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_MULT_INT_VAR_BY_INT_VAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_MULT_INT_LVAR_BY_INT_VAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_MULT_INT_VAR_BY_INT_LVAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_MULT_INT_LVAR_BY_INT_LVAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_MULT_FLOAT_VAR_BY_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_MULT_FLOAT_LVAR_BY_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_MULT_FLOAT_VAR_BY_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_MULT_FLOAT_LVAR_BY_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) *= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_DIV_INT_VAR_BY_INT_VAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_DIV_INT_LVAR_BY_INT_VAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_DIV_INT_VAR_BY_INT_LVAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_DIV_INT_LVAR_BY_INT_LVAR:
+ *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_DIV_FLOAT_VAR_BY_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_DIV_FLOAT_LVAR_BY_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_DIV_FLOAT_VAR_BY_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_DIV_FLOAT_LVAR_BY_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) /= *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_ADD_TIMED_VAL_TO_FLOAT_VAR:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ CollectParameters(&m_nIp, 1);
+ *(float*)ptr += CTimer::GetTimeStep() * *(float*)&ScriptParams[0];
+ return 0;
+ }
+ case COMMAND_ADD_TIMED_VAL_TO_FLOAT_LVAR:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ CollectParameters(&m_nIp, 1);
+ *(float*)ptr += CTimer::GetTimeStep() * *(float*)&ScriptParams[0];
+ return 0;
+ }
+ case COMMAND_ADD_TIMED_FLOAT_VAR_TO_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_ADD_TIMED_FLOAT_LVAR_TO_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_ADD_TIMED_FLOAT_VAR_TO_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_ADD_TIMED_FLOAT_LVAR_TO_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) += CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_SUB_TIMED_VAL_FROM_FLOAT_VAR:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ CollectParameters(&m_nIp, 1);
+ *(float*)ptr -= CTimer::GetTimeStep() * *(float*)&ScriptParams[0];
+ return 0;
+ }
+ case COMMAND_SUB_TIMED_VAL_FROM_FLOAT_LVAR:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ CollectParameters(&m_nIp, 1);
+ *(float*)ptr -= CTimer::GetTimeStep() * *(float*)&ScriptParams[0];
+ return 0;
+ }
+ case COMMAND_SUB_TIMED_FLOAT_VAR_FROM_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_SUB_TIMED_FLOAT_LVAR_FROM_FLOAT_VAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_SUB_TIMED_FLOAT_VAR_FROM_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ case COMMAND_SUB_TIMED_FLOAT_LVAR_FROM_FLOAT_LVAR:
+ *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL) -= CTimer::GetTimeStep() * *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ case COMMAND_SET_VAR_INT_TO_VAR_INT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_SET_LVAR_INT_TO_VAR_INT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_SET_VAR_INT_TO_LVAR_INT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_SET_LVAR_INT_TO_LVAR_INT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_SET_VAR_FLOAT_TO_VAR_FLOAT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_SET_LVAR_FLOAT_TO_VAR_FLOAT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_SET_VAR_FLOAT_TO_LVAR_FLOAT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_SET_LVAR_FLOAT_TO_LVAR_FLOAT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_CSET_VAR_INT_TO_VAR_FLOAT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_CSET_LVAR_INT_TO_VAR_FLOAT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_CSET_VAR_INT_TO_LVAR_FLOAT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_CSET_LVAR_INT_TO_LVAR_FLOAT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *(float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_CSET_VAR_FLOAT_TO_VAR_INT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_CSET_LVAR_FLOAT_TO_VAR_INT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_CSET_VAR_FLOAT_TO_LVAR_INT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ return 0;
+ }
+ case COMMAND_CSET_LVAR_FLOAT_TO_LVAR_INT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = *GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ return 0;
+ }
+ case COMMAND_ABS_VAR_INT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = ABS(*ptr);
+ return 0;
+ }
+ case COMMAND_ABS_LVAR_INT:
+ {
+ int32* ptr = GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = ABS(*ptr);
+ return 0;
+ }
+ case COMMAND_ABS_VAR_FLOAT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ *ptr = ABS(*ptr);
+ return 0;
+ }
+ case COMMAND_ABS_LVAR_FLOAT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_LOCAL);
+ *ptr = ABS(*ptr);
+ return 0;
+ }
+ case COMMAND_GENERATE_RANDOM_FLOAT:
+ {
+ float* ptr = (float*)GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL);
+ CGeneral::GetRandomNumber();
+ CGeneral::GetRandomNumber();
+ CGeneral::GetRandomNumber(); /* To make it EXTRA random! */
+ *ptr = CGeneral::GetRandomNumber() / 65536.0f;
+ /* Between 0 and 0.5 on PC (oh well...), never used in original script. */
+ return 0;
+ }
+ case COMMAND_GENERATE_RANDOM_INT:
+ /* On PC between 0 and 32767, even though script expects values between 0 and 65536 */
+ *GetPointerToScriptVariable(&m_nIp, VAR_GLOBAL) = CGeneral::GetRandomNumber();
+ return 0;
+ case COMMAND_CREATE_CHAR:
+ {
+ CollectParameters(&m_nIp, 5);
+ switch (ScriptParams[1]) {
+ case MI_COP:
+ if (ScriptParams[0] == PEDTYPE_COP)
+ ScriptParams[1] = COP_STREET;
+ break;
+ case MI_SWAT:
+ if (ScriptParams[0] == PEDTYPE_COP)
+ ScriptParams[1] = COP_SWAT;
+ break;
+ case MI_FBI:
+ if (ScriptParams[0] == PEDTYPE_COP)
+ ScriptParams[1] = COP_FBI;
+ break;
+ case MI_ARMY:
+ if (ScriptParams[0] == PEDTYPE_COP)
+ ScriptParams[1] = COP_ARMY;
+ break;
+ case MI_MEDIC:
+ if (ScriptParams[0] == PEDTYPE_EMERGENCY)
+ ScriptParams[1] = PEDTYPE_EMERGENCY;
+ break;
+ case MI_FIREMAN:
+ if (ScriptParams[0] == PEDTYPE_FIREMAN)
+ ScriptParams[1] = PEDTYPE_FIREMAN;
+ break;
+ default:
+ break;
+ }
+ CPed* ped;
+ if (ScriptParams[0] == PEDTYPE_COP)
+ ped = new CCopPed((eCopType)ScriptParams[1]);
+ else if (ScriptParams[0] == PEDTYPE_EMERGENCY || ScriptParams[0] == PEDTYPE_FIREMAN)
+ ped = new CEmergencyPed(ScriptParams[1]);
+ else
+ ped = new CCivilianPed(ScriptParams[0], ScriptParams[1]);
+ ped->CharCreatedBy = MISSION_CHAR;
+ ped->bRespondsToThreats = false;
+ ped->m_ped_flagG2 = false;
+ CVector pos = *(CVector*)&ScriptParams[2];
+ if (pos.z <= -100.0f)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ pos.z += 1.0f;
+ ped->GetPosition() = pos;
+ ped->SetOrientation(0.0f, 0.0f, 0.0f);
+ CTheScripts::ClearSpaceForMissionEntity(pos, ped);
+ CWorld::Add(ped);
+ ped->m_level = CTheZones::GetLevelFromPosition(pos);
+ CPopulation::ms_nTotalMissionPeds++;
+ ScriptParams[0] = CPools::GetPedPool()->GetIndex(ped);
+ StoreParameters(&m_nIp, 1);
+ if (m_bIsMissionScript)
+ CTheScripts::MissionCleanup.AddEntityToList(ScriptParams[0], CLEANUP_CHAR);
+ return 0;
+ }
+ case COMMAND_DELETE_CHAR:
+ {
+ CollectParameters(&m_nIp, 1);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ if (ped) {
+ if (ped->bInVehicle && ped->m_pMyVehicle) {
+ if (ped->m_pMyVehicle->pDriver == ped) {
+ ped->m_pMyVehicle->RemoveDriver();
+ ped->m_pMyVehicle->m_status = STATUS_ABANDONED;
+ if (ped->m_pMyVehicle->m_nDoorLock == CARLOCK_LOCKED_INITIALLY)
+ ped->m_pMyVehicle->m_nDoorLock = CARLOCK_UNLOCKED;
+ if (ped->m_nPedType == PEDTYPE_COP && ped->m_pMyVehicle->IsLawEnforcementVehicle())
+ ped->m_pMyVehicle->ChangeLawEnforcerState(0);
+ }
+ else {
+ ped->m_pMyVehicle->RemovePassenger(ped);
+ }
+ }
+ CWorld::RemoveReferencesToDeletedObject(ped);
+ delete ped;
+ --CPopulation::ms_nTotalMissionPeds;
+ }
+ if (m_bIsMissionScript)
+ CTheScripts::MissionCleanup.RemoveEntityFromList(ScriptParams[0], CLEANUP_CHAR);
+ return 0;
+ }
+ case COMMAND_CHAR_WANDER_DIR:
+ {
+ CollectParameters(&m_nIp, 2);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(ped);
+ ped->ClearAll();
+ int8 path = ScriptParams[1];
+ if (ScriptParams[1] < 0 || ScriptParams[1] > 7)
+ path = CGeneral::GetRandomNumberInRange(0, 7);
+ ped->SetWanderPath(path);
+ return 0;
+ }
+ case COMMAND_CHAR_FOLLOW_PATH:
+ {
+ CollectParameters(&m_nIp, 4);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(ped);
+ CVector pos = *(CVector*)&ScriptParams[1];
+ if (pos.z <= -100.0f)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ ped->ClearAll();
+ ped->SetFollowPath(pos);
+ return 0;
+ }
+ case COMMAND_CHAR_SET_IDLE:
+ {
+ CollectParameters(&m_nIp, 1);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(ped);
+ ped->m_bScriptObjectiveCompleted = false;
+ ped->SetObjective(OBJECTIVE_IDLE);
+ return 0;
+ }
+ case COMMAND_GET_CHAR_COORDINATES:
+ {
+ CollectParameters(&m_nIp, 1);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(ped);
+ CVehicle* vehicle;
+ CVector pos;
+ /* Seems a bit clumsy but I'll leave original flow */
+ if (ped->bInVehicle)
+ vehicle = ped->m_pMyVehicle;
+ else
+ vehicle = nil;
+ if (vehicle)
+ pos = vehicle->GetPosition();
+ else
+ pos = ped->GetPosition();
+ *(CVector*)&ScriptParams[0] = pos;
+ StoreParameters(&m_nIp, 3);
+ return 0;
+ }
+ case COMMAND_SET_CHAR_COORDINATES:
+ {
+ CollectParameters(&m_nIp, 4);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(ped);
+ CVehicle* vehicle;
+ if (ped->bInVehicle)
+ vehicle = ped->m_pMyVehicle;
+ else
+ vehicle = nil;
+ CVector pos = *(CVector*)&ScriptParams[1];
+ if (pos.z <= -100.0f)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ /* The following block was once again written
+ * by someone not familiar with virtual functions.
+ * It doesn't require any ifs at all.
+ * To keep as close to original as possible, I'll keep it.
+ * Maybe there was more commented out/debug
+ * stuff, but I doubt it.
+ */
+ if (!vehicle) {
+ pos.z += ped->GetDistanceFromCentreOfMassToBaseOfModel();
+ ped->Teleport(pos);
+ CTheScripts::ClearSpaceForMissionEntity(pos, ped);
+ }
+ else if (vehicle->IsBoat()) {
+ pos.z += vehicle->GetDistanceFromCentreOfMassToBaseOfModel();
+ vehicle->Teleport(pos);
+ CTheScripts::ClearSpaceForMissionEntity(pos, vehicle);
+ }
+ else {
+ pos.z += vehicle->GetDistanceFromCentreOfMassToBaseOfModel();
+ vehicle->Teleport(pos);
+ CTheScripts::ClearSpaceForMissionEntity(pos, vehicle);
+ }
+ /* Short version of this command.
+ *
+ * CollectParameters(&m_nIp, 4);
+ * CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ * assert(ped);
+ * CEntity* entityToMove = ped->bInVehicle ? ped->m_pMyVehicle : ped;
+ * CVector pos = *(CVector*)&ScriptParams[1];
+ * if (pos.z <= -100.0f)
+ * pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ * pos.z += entityToMove->GetDistanceFromCentreOfMassToBaseOfModel();
+ * entityToMove->Teleport(pos);
+ * CTheScripts::ClearSpaceForMissionEntity(pos, entityToMove);
+ *
+ */
+ return 0;
+ }
+ case COMMAND_IS_CHAR_STILL_ALIVE:
+ {
+ CollectParameters(&m_nIp, 1);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ UpdateCompareFlag(ped && ped->m_status != PED_DEAD && ped->m_status != PED_DIE);
+ return 0;
+ }
+ case COMMAND_IS_CHAR_IN_AREA_2D:
+ {
+ CollectParameters(&m_nIp, 6);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(ped);
+ CVehicle* vehicle;
+ if (ped->bInVehicle)
+ vehicle = ped->m_pMyVehicle;
+ else
+ vehicle = nil;
+ float x1, y1, x2, y2;
+ x1 = *(float*)&ScriptParams[1];
+ y1 = *(float*)&ScriptParams[2];
+ x2 = *(float*)&ScriptParams[3];
+ y2 = *(float*)&ScriptParams[4];
+ if (vehicle)
+ UpdateCompareFlag(ped->m_pMyVehicle->IsWithinArea(x1, y1, x2, y2));
+ else
+ UpdateCompareFlag(ped->IsWithinArea(x1, y1, x2, y2));
+ CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, -100.0f);
+ if (CTheScripts::DbgFlag)
+ CTheScripts::DrawDebugSquare(x1, y1, x2, y2);
+ return 0;
+ }
+ case COMMAND_IS_CHAR_IN_AREA_3D:
+ {
+ CollectParameters(&m_nIp, 8);
+ CPed* ped = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(ped);
+ CVehicle* vehicle;
+ if (ped->bInVehicle)
+ vehicle = ped->m_pMyVehicle;
+ else
+ vehicle = nil;
+ float x1, y1, z1, x2, y2, z2;
+ x1 = *(float*)&ScriptParams[1];
+ y1 = *(float*)&ScriptParams[2];
+ z1 = *(float*)&ScriptParams[3];
+ x2 = *(float*)&ScriptParams[4];
+ y2 = *(float*)&ScriptParams[5];
+ z2 = *(float*)&ScriptParams[6];
+ if (vehicle)
+ UpdateCompareFlag(ped->m_pMyVehicle->IsWithinArea(x1, y1, z1, x2, y2, z2));
+ else
+ UpdateCompareFlag(ped->IsWithinArea(x1, y1, z1, x2, y2, z2));
+ CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, -100.0f);
+ if (CTheScripts::DbgFlag)
+ CTheScripts::DrawDebugCube(x1, y1, z1, x2, y2, z2);
+ return 0;
+ }
+ case COMMAND_CREATE_CAR:
+ {
+ CollectParameters(&m_nIp, 4);
+ int32 handle;
+ if (CModelInfo::IsBoatModel(ScriptParams[0])) {
+ CBoat* boat = new CBoat(ScriptParams[0], MISSION_VEHICLE);
+ CVector pos = *(CVector*)&ScriptParams[1];
+ if (pos.z <= -100.0f)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ pos.z += boat->GetDistanceFromCentreOfMassToBaseOfModel();
+ boat->GetPosition() = pos;
+ CTheScripts::ClearSpaceForMissionEntity(pos, boat);
+ boat->m_status = STATUS_ABANDONED;
+ boat->bIsLocked = true;
+ boat->AutoPilot.m_nCarMission = MISSION_NONE;
+ boat->AutoPilot.m_nAnimationId = TEMPACT_NONE; /* Animation ID? */
+ boat->AutoPilot.m_nCruiseSpeed = boat->AutoPilot.m_fMaxTrafficSpeed = 20.0f;
+ CWorld::Add(boat);
+ handle = CPools::GetVehiclePool()->GetIndex(boat);
+ }
+ else {
+ CVehicle* car;
+ if (!CModelInfo::IsBikeModel(ScriptParams[0]))
+ car = new CAutomobile(ScriptParams[0], MISSION_VEHICLE);
+ CVector pos = *(CVector*)&ScriptParams[1];
+ if (pos.z <= -100.0f)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ pos.z += car->GetDistanceFromCentreOfMassToBaseOfModel();
+ car->GetPosition() = pos;
+ CTheScripts::ClearSpaceForMissionEntity(pos, car);
+ car->m_status = STATUS_ABANDONED;
+ car->bIsLocked = true;
+ CCarCtrl::JoinCarWithRoadSystem(car);
+ car->AutoPilot.m_nCarMission = MISSION_NONE;
+ car->AutoPilot.m_nAnimationId = TEMPACT_NONE; /* Animation ID? */
+ car->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_STOP_FOR_CARS;
+ car->AutoPilot.m_nCruiseSpeed = car->AutoPilot.m_fMaxTrafficSpeed = 9.0f;
+ car->AutoPilot.m_nPreviousLane = car->AutoPilot.m_nCurrentLane = 0;
+ car->bEngineOn = false;
+ car->m_level = CTheZones::GetLevelFromPosition(pos);
+ car->bHasBeenOwnedByPlayer = true;
+ CWorld::Add(car);
+ handle = CPools::GetVehiclePool()->GetIndex(car);
+ }
+ ScriptParams[0] = handle;
+ StoreParameters(&m_nIp, 1);
+ if (m_bIsMissionScript)
+ CTheScripts::MissionCleanup.AddEntityToList(handle, CLEANUP_CAR);
+ return 0;
+ }
+ case COMMAND_DELETE_CAR:
+ {
+ CollectParameters(&m_nIp, 1);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ if (car) {
+ CWorld::Remove(car);
+ CWorld::RemoveReferencesToDeletedObject(car);
+ delete car;
+ }
+ if (m_bIsMissionScript)
+ CTheScripts::MissionCleanup.RemoveEntityFromList(ScriptParams[0], CLEANUP_CAR);
+ return 0;
+ }
+ case COMMAND_CAR_GOTO_COORDINATES:
+ {
+ CollectParameters(&m_nIp, 4);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ CVector pos = *(CVector*)&ScriptParams[1];
+ if (pos.z <= -100.0f)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ pos.z += car->GetDistanceFromCentreOfMassToBaseOfModel();
+ if (CCarCtrl::JoinCarWithRoadSystemGotoCoors(car, pos, false))
+ car->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS_STRAIGHT;
+ else
+ car->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS;
+ car->m_status = STATUS_PHYSICS;
+ car->bEngineOn = true;
+ car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6);
+ car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds();
+ return 0;
+ }
+ case COMMAND_CAR_WANDER_RANDOMLY:
+ {
+ CollectParameters(&m_nIp, 1);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ CCarCtrl::JoinCarWithRoadSystem(car);
+ car->AutoPilot.m_nCarMission = MISSION_CRUISE;
+ car->bEngineOn = true;
+ car->AutoPilot.m_nCruiseSpeed = max(car->AutoPilot.m_nCruiseSpeed, 6);
+ car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds();
+ return 0;
+ }
+ case COMMAND_CAR_SET_IDLE:
+ {
+ CollectParameters(&m_nIp, 1);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ car->AutoPilot.m_nCarMission = MISSION_NONE;
+ return 0;
+ }
+ case COMMAND_GET_CAR_COORDINATES:
+ {
+ CollectParameters(&m_nIp, 1);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ *(CVector*)&ScriptParams[0] = car->GetPosition();
+ StoreParameters(&m_nIp, 3);
+ return 0;
+ }
+ case COMMAND_SET_CAR_COORDINATES:
+ {
+ CollectParameters(&m_nIp, 4);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ CVector pos = *(CVector*)&ScriptParams[1];
+ if (pos.z <= -100.0f)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ pos.z += car->GetDistanceFromCentreOfMassToBaseOfModel();
+ car->bIsStatic = false;
+ /* Again weird usage of virtual functions. */
+ if (car->IsBoat()) {
+ car->Teleport(pos);
+ CTheScripts::ClearSpaceForMissionEntity(pos, car);
+ }
+ else {
+ car->Teleport(pos);
+ CTheScripts::ClearSpaceForMissionEntity(pos, car);
+ /* May the following be inlined CCarCtrl function? */
+ switch (car->AutoPilot.m_nCarMission) {
+ case MISSION_CRUISE:
+ CCarCtrl::JoinCarWithRoadSystem(car);
+ break;
+ case MISSION_RAMPLAYER_FARAWAY:
+ case MISSION_RAMPLAYER_CLOSE:
+ case MISSION_BLOCKPLAYER_FARAWAY:
+ case MISSION_BLOCKPLAYER_CLOSE:
+ case MISSION_BLOCKPLAYER_HANDBRAKESTOP:
+ CCarCtrl::JoinCarWithRoadSystemGotoCoors(car, FindPlayerCoors(), false);
+ break;
+ case MISSION_GOTOCOORDS:
+ case MISSION_GOTOCOORDS_STRAIGHT:
+ CCarCtrl::JoinCarWithRoadSystemGotoCoors(car, car->AutoPilot.m_vecDestinationCoors, false);
+ break;
+ case MISSION_GOTOCOORDS_ACCURATE:
+ case MISSION_GOTO_COORDS_STRAIGHT_ACCURATE:
+ CCarCtrl::JoinCarWithRoadSystemGotoCoors(car, car->AutoPilot.m_vecDestinationCoors, false);
+ break;
+ case MISSION_RAMCAR_FARAWAY:
+ case MISSION_RAMCAR_CLOSE:
+ case MISSION_BLOCKCAR_FARAWAY:
+ case MISSION_BLOCKCAR_CLOSE:
+ case MISSION_BLOCKCAR_HANDBRAKESTOP:
+ CCarCtrl::JoinCarWithRoadSystemGotoCoors(car, car->AutoPilot.m_pTargetCar->GetPosition(), false);
+ break;
+ default:
+ break;
+ }
+ }
+ return 0;
+ }
+ case COMMAND_IS_CAR_STILL_ALIVE:
+ {
+ CollectParameters(&m_nIp, 4);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ UpdateCompareFlag(car && car->m_status != STATUS_WRECKED && (car->IsBoat() || !car->bIsInWater));
+ return 0;
+ }
+ case COMMAND_SET_CAR_CRUISE_SPEED:
+ {
+ CollectParameters(&m_nIp, 2);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ car->AutoPilot.m_nCruiseSpeed = min(*(float*)&ScriptParams[1], 60.0f * car->pHandling->Transmission.fUnkMaxVelocity);
+ return 0;
+ }
+ case COMMAND_SET_CAR_DRIVING_STYLE:
+ {
+ CollectParameters(&m_nIp, 2);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ car->AutoPilot.m_nDrivingStyle = (eCarDrivingStyle)ScriptParams[1];
+ return 0;
+ }
+ case COMMAND_SET_CAR_MISSION:
+ {
+ CollectParameters(&m_nIp, 2);
+ CVehicle* car = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(car);
+ car->AutoPilot.m_nCarMission = (eCarMission)ScriptParams[1];
+ car->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds();
+ car->bEngineOn = true;
+ return 0;
+ }
+ case COMMAND_IS_CAR_IN_AREA_2D:
+ {
+ CollectParameters(&m_nIp, 6);
+ CVehicle* vehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(vehicle);
+ float x1, y1, x2, y2;
+ x1 = *(float*)&ScriptParams[1];
+ y1 = *(float*)&ScriptParams[2];
+ x2 = *(float*)&ScriptParams[3];
+ y2 = *(float*)&ScriptParams[4];
+ UpdateCompareFlag(vehicle->IsWithinArea(x1, y1, x2, y2));
+ CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, -100.0f);
+ if (CTheScripts::DbgFlag)
+ CTheScripts::DrawDebugSquare(x1, y1, x2, y2);
+ return 0;
+ }
+ case COMMAND_IS_CAR_IN_AREA_3D:
+ {
+ CollectParameters(&m_nIp, 8);
+ CVehicle* vehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(vehicle);
+ float x1, y1, z1, x2, y2, z2;
+ x1 = *(float*)&ScriptParams[1];
+ y1 = *(float*)&ScriptParams[2];
+ z1 = *(float*)&ScriptParams[3];
+ x2 = *(float*)&ScriptParams[4];
+ y2 = *(float*)&ScriptParams[5];
+ z2 = *(float*)&ScriptParams[6];
+ UpdateCompareFlag(vehicle->IsWithinArea(x1, y1, z1, x2, y2, z2));
+ CTheScripts::HighlightImportantArea((uint32)this + m_nIp, x1, y1, x2, y2, -100.0f);
+ if (CTheScripts::DbgFlag)
+ CTheScripts::DrawDebugCube(x1, y1, z1, x2, y2, z2);
+ return 0;
+ }
+ case COMMAND_SPECIAL_0:
+ case COMMAND_SPECIAL_1:
+ case COMMAND_SPECIAL_2:
+ case COMMAND_SPECIAL_3:
+ case COMMAND_SPECIAL_4:
+ case COMMAND_SPECIAL_5:
+ case COMMAND_SPECIAL_6:
+ case COMMAND_SPECIAL_7:
+ assert(0);
+ return 0;
+ case COMMAND_PRINT_BIG:
+ {
+ wchar* key = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]);
+ m_nIp += 8;
+ CollectParameters(&m_nIp, 2);
+ CMessages::AddBigMessage(key, ScriptParams[0], ScriptParams[1] - 1);
+ return 0;
+ }
+ case COMMAND_PRINT:
+ {
+ wchar* key = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]);
+ m_nIp += 8;
+ CollectParameters(&m_nIp, 2);
+ CMessages::AddMessage(key, ScriptParams[0], ScriptParams[1]);
+ return 0;
+ }
+ case COMMAND_PRINT_NOW:
+ {
+ wchar* key = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]);
+ m_nIp += 8;
+ CollectParameters(&m_nIp, 2);
+ CMessages::AddMessageJumpQ(key, ScriptParams[0], ScriptParams[1]);
+ return 0;
+ }
+ case COMMAND_PRINT_SOON:
+ {
+ wchar* key = TheText.Get((char*)&CTheScripts::ScriptSpace[m_nIp]);
+ m_nIp += 8;
+ CollectParameters(&m_nIp, 2);
+ CMessages::AddMessage(key, ScriptParams[0], ScriptParams[1]);
+ return 0;
+ }
+ case COMMAND_CLEAR_PRINTS:
+ CMessages::ClearMessages();
+ return 0;
+ case COMMAND_GET_TIME_OF_DAY:
+ ScriptParams[0] = CClock::GetHours();
+ ScriptParams[1] = CClock::GetMinutes();
+ StoreParameters(&m_nIp, 2);
+ return 0;
+ case COMMAND_SET_TIME_OF_DAY:
+ CollectParameters(&m_nIp, 2);
+ CClock::SetGameClock(ScriptParams[0], ScriptParams[1]);
+ return 0;
+ case COMMAND_GET_MINUTES_TO_TIME_OF_DAY:
+ CollectParameters(&m_nIp, 2);
+ ScriptParams[0] = CClock::GetGameClockMinutesUntil(ScriptParams[0], ScriptParams[1]);
+ StoreParameters(&m_nIp, 1);
+ return 0;
+ case COMMAND_IS_POINT_ON_SCREEN:
+ {
+ CollectParameters(&m_nIp, 4);
+ CVector pos = *(CVector*)&ScriptParams[0];
+ if (pos.z <= -100)
+ pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y);
+ UpdateCompareFlag(TheCamera.IsSphereVisible(pos, *(float*)&ScriptParams[3]));
+ }
+ case COMMAND_DEBUG_ON:
+ CTheScripts::DbgFlag = true;
+ return 0;
+ case COMMAND_DEBUG_OFF:
+ CTheScripts::DbgFlag = false;
+ return 0;
+ case COMMAND_RETURN_TRUE:
+ UpdateCompareFlag(true);
+ return 0;
+ case COMMAND_RETURN_FALSE:
+ UpdateCompareFlag(false);
+ return 0;
+ default:
+ assert(0);
+ break;
+ }
+ return -1;
+}
+
WRAPPER int8 CRunningScript::ProcessCommandsFrom200To299(int32 command) { EAXJMP(0x43D530); }
WRAPPER int8 CRunningScript::ProcessCommandsFrom300To399(int32 command) { EAXJMP(0x43ED30); }
WRAPPER int8 CRunningScript::ProcessCommandsFrom400To499(int32 command) { EAXJMP(0x440CB0); }