summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2020-02-24 19:17:15 +0100
committerNikolay Korolev <nickvnuk@gmail.com>2020-02-24 19:17:15 +0100
commit56c83dfaaebffc1eabec01671c2da892661059af (patch)
treee23ff527d9280b206aa3774576c47341539e1c26
parentMerge branch 'master' into script_dev (diff)
downloadre3-56c83dfaaebffc1eabec01671c2da892661059af.tar
re3-56c83dfaaebffc1eabec01671c2da892661059af.tar.gz
re3-56c83dfaaebffc1eabec01671c2da892661059af.tar.bz2
re3-56c83dfaaebffc1eabec01671c2da892661059af.tar.lz
re3-56c83dfaaebffc1eabec01671c2da892661059af.tar.xz
re3-56c83dfaaebffc1eabec01671c2da892661059af.tar.zst
re3-56c83dfaaebffc1eabec01671c2da892661059af.zip
-rw-r--r--src/control/Script.cpp640
-rw-r--r--src/control/Script.h16
-rw-r--r--src/core/main.cpp3
3 files changed, 635 insertions, 24 deletions
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index 3e4c7e8f..b167ac54 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -29,6 +29,7 @@
#include "HandlingMgr.h"
#include "Heli.h"
#include "Hud.h"
+#include "Lines.h"
#include "main.h"
#include "Messages.h"
#include "ModelIndices.h"
@@ -95,6 +96,7 @@ tUsedObject(&CTheScripts::UsedObjectArray)[MAX_NUM_USED_OBJECTS] = *(tUsedObject
int32(&CTheScripts::MultiScriptArray)[MAX_NUM_MISSION_SCRIPTS] = *(int32(*)[MAX_NUM_MISSION_SCRIPTS])*(uintptr*)0x6F0558;
tBuildingSwap(&CTheScripts::BuildingSwapArray)[MAX_NUM_BUILDING_SWAPS] = *(tBuildingSwap(*)[MAX_NUM_BUILDING_SWAPS])*(uintptr*)0x880E30;
CEntity*(&CTheScripts::InvisibilitySettingArray)[MAX_NUM_INVISIBILITY_SETTINGS] = *(CEntity*(*)[MAX_NUM_INVISIBILITY_SETTINGS])*(uintptr*)0x8620F0;
+CStoredLine (&CTheScripts::aStoredLines)[MAX_NUM_STORED_LINES] = *(CStoredLine(*)[MAX_NUM_STORED_LINES])*(uintptr*)0x743018;
bool &CTheScripts::DbgFlag = *(bool*)0x95CD87;
uint32 &CTheScripts::OnAMissionFlag = *(uint32*)0x8F1B64;
int32 &CTheScripts::StoreVehicleIndex = *(int32*)0x8F5F3C;
@@ -115,7 +117,7 @@ uint8 &CTheScripts::DelayMakingPlayerUnsafeThisTime = *(uint8*)0x95CD88;
uint16 &CTheScripts::NumScriptDebugLines = *(uint16*)0x95CC42;
uint16 &CTheScripts::NumberOfIntroRectanglesThisFrame = *(uint16*)0x95CC88;
uint16 &CTheScripts::NumberOfIntroTextLinesThisFrame = *(uint16*)0x95CC32;
-bool &CTheScripts::UseTextCommands = *(bool*)0x95CD57;
+uint8 &CTheScripts::UseTextCommands = *(uint8*)0x95CD57;
CMissionCleanup (&CTheScripts::MissionCleanup) = *(CMissionCleanup*)0x8F2A24;
CUpsideDownCarCheck (&CTheScripts::UpsideDownCars) = *(CUpsideDownCarCheck*)0x6EE450;
CStuckCarCheck (&CTheScripts::StuckCars) = *(CStuckCarCheck*)0x87C588;
@@ -561,7 +563,7 @@ void CTheScripts::Init()
ReadMultiScriptFileOffsetsFromScript();
FailCurrentMission = 0;
CountdownToMakePlayerUnsafe = 0;
- DbgFlag = 0;
+ DbgFlag = false;
DelayMakingPlayerUnsafeThisTime = 1;
NumScriptDebugLines = 0;
for (int i = 0; i < MAX_NUM_SCRIPT_SPHERES; i++){
@@ -575,7 +577,7 @@ void CTheScripts::Init()
IntroTextLines[i].Reset();
}
NumberOfIntroTextLinesThisFrame = 0;
- UseTextCommands = false;
+ UseTextCommands = 0;
for (int i = 0; i < MAX_NUM_INTRO_RECTANGLES; i++){
IntroRectangles[i].m_bIsUsed = false;
IntroRectangles[i].m_bBeforeFade = false;
@@ -702,6 +704,9 @@ int8 CRunningScript::ProcessOneCommand()
int32 command = Read2BytesFromScript(&m_nIp);
m_bNotFlag = (command & 0x8000);
command &= 0x7FFF;
+ if (command >= 1000)
+ debug("Time: %d, Script: %s, Command: %d\n", CTheScripts::CommandsExecuted, m_abScriptName, command);
+ debug("IntroSomething: %d\n", CTheScripts::NumberOfIntroTextLinesThisFrame);
if (command < 100)
return ProcessCommands0To99(command);
if (command < 200)
@@ -2454,9 +2459,9 @@ int8 CRunningScript::ProcessCommands200To299(int32 command)
{
CollectParameters(&m_nIp, 2);
bool value = GetPadState(ScriptParams[0], ScriptParams[1]) != 0;
- if (CGame::playingIntro && ScriptParams[0] == 0 && ScriptParams[1] == 12){ /* pad1, start */
+ if (CGame::playingIntro && ScriptParams[0] == 0 && ScriptParams[1] == 12) {
if (CPad::GetPad(0)->GetLeftMouseJustDown() ||
- CPad::GetPad(0)->GetPadEnterJustDown() ||
+ CPad::GetPad(0)->GetEnterJustDown() ||
CPad::GetPad(0)->GetCharJustDown(' '))
value = true;
}
@@ -8454,7 +8459,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command)
}
case COMMAND_USE_TEXT_COMMANDS:
CollectParameters(&m_nIp, 1);
- CTheScripts::UseTextCommands = ScriptParams[0] != 0 ? 2 : 1;
+ CTheScripts::UseTextCommands = (ScriptParams[0] != 0) ? 2 : 1;
return 0;
case COMMAND_SET_THREAT_FOR_PED_TYPE:
CollectParameters(&m_nIp, 2);
@@ -9972,7 +9977,7 @@ void CRunningScript::LocatePlayerCharCommand(int32 command, uint32* pIp)
debug = ScriptParams[5];
}
else {
- debug = ScriptParams[5];
+ debug = ScriptParams[4];
}
result = false;
bool in_area;
@@ -10561,11 +10566,503 @@ void CRunningScript::LocateSniperBulletCommand(int32 command, uint32* pIp)
}
}
-WRAPPER void CRunningScript::PlayerInAreaCheckCommand(int32, uint32*) { EAXJMP(0x451A60); }
-WRAPPER void CRunningScript::PlayerInAngledAreaCheckCommand(int32, uint32*) { EAXJMP(0x451E50); }
-WRAPPER void CRunningScript::CharInAreaCheckCommand(int32, uint32*) { EAXJMP(0x4523B0); }
-WRAPPER void CRunningScript::CarInAreaCheckCommand(int32, uint32*) { EAXJMP(0x452750); }
-WRAPPER void CRunningScript::DoDeatharrestCheck() { EAXJMP(0x452A30); }
+void CRunningScript::PlayerInAreaCheckCommand(int32 command, uint32* pIp)
+{
+ bool b3D, result, debug, decided = false;
+ float infX, infY, infZ, supX, supY, supZ;
+ switch (command) {
+ case COMMAND_IS_PLAYER_IN_AREA_3D:
+ case COMMAND_IS_PLAYER_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_IN_AREA_IN_CAR_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_IN_CAR_3D:
+ b3D = true;
+ break;
+ default:
+ b3D = false;
+ break;
+ }
+ CollectParameters(pIp, b3D ? 8 : 6);
+ CPlayerInfo* pPlayerInfo = &CWorld::Players[ScriptParams[0]];
+ switch (command) {
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_IN_CAR_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_ON_FOOT_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_IN_CAR_2D:
+ if (!CTheScripts::IsPlayerStopped(pPlayerInfo)) {
+ result = false;
+ decided = true;
+ }
+ break;
+ default:
+ break;
+ }
+ infX = *(float*)&ScriptParams[1];
+ infY = *(float*)&ScriptParams[2];
+ if (b3D) {
+ infZ = *(float*)&ScriptParams[3];
+ supX = *(float*)&ScriptParams[4];
+ supY = *(float*)&ScriptParams[5];
+ supZ = *(float*)&ScriptParams[6];
+ if (infZ > supZ) {
+ infZ = *(float*)&ScriptParams[6];
+ supZ = *(float*)&ScriptParams[3];
+ }
+ debug = ScriptParams[7];
+ }
+ else {
+ supX = *(float*)&ScriptParams[3];
+ supY = *(float*)&ScriptParams[4];
+ debug = ScriptParams[5];
+ }
+ if (infX > supX) {
+ float tmp = infX;
+ infX = supX;
+ supX = tmp;
+ }
+ if (infY > supY) {
+ float tmp = infY;
+ infY = supY;
+ supY = tmp;
+ }
+ if (!decided) {
+ CVector pos = pPlayerInfo->GetPos();
+ result = false;
+ bool in_area;
+ if (b3D) {
+ in_area = infX <= pos.x &&
+ supX >= pos.x &&
+ infY <= pos.y &&
+ supY >= pos.y &&
+ infZ <= pos.z &&
+ supZ >= pos.z;
+ }
+ else {
+ in_area = infX <= pos.x &&
+ supX >= pos.x &&
+ infY <= pos.y &&
+ supY >= pos.y;
+ }
+ if (in_area) {
+ switch (command) {
+ case COMMAND_IS_PLAYER_IN_AREA_2D:
+ case COMMAND_IS_PLAYER_IN_AREA_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_3D:
+ result = true;
+ break;
+ case COMMAND_IS_PLAYER_IN_AREA_ON_FOOT_2D:
+ case COMMAND_IS_PLAYER_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_ON_FOOT_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_ON_FOOT_3D:
+ result = !pPlayerInfo->m_pPed->bInVehicle;
+ break;
+ case COMMAND_IS_PLAYER_IN_AREA_IN_CAR_2D:
+ case COMMAND_IS_PLAYER_IN_AREA_IN_CAR_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_IN_CAR_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_AREA_IN_CAR_3D:
+ result = pPlayerInfo->m_pPed->bInVehicle;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ }
+ UpdateCompareFlag(result);
+ if (debug)
+ CTheScripts::HighlightImportantArea((uint32)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : -100.0f);
+ if (CTheScripts::DbgFlag) {
+ if (b3D)
+ CTheScripts::DrawDebugCube(infX, infY, infZ, supX, supY, supZ);
+ else
+ CTheScripts::DrawDebugSquare(infX, infY, supX, supY);
+ }
+}
+
+void CRunningScript::PlayerInAngledAreaCheckCommand(int32 command, uint32* pIp)
+{
+ bool b3D, result, debug, decided = false;
+ float infX, infY, infZ, supX, supY, supZ, side2length;
+ switch (command) {
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_3D:
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_IN_CAR_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_IN_CAR_3D:
+ b3D = true;
+ break;
+ default:
+ b3D = false;
+ break;
+ }
+ CollectParameters(pIp, b3D ? 9 : 7);
+ CPlayerInfo* pPlayerInfo = &CWorld::Players[ScriptParams[0]];
+ switch (command) {
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_IN_CAR_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_ON_FOOT_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_IN_CAR_2D:
+ if (!CTheScripts::IsPlayerStopped(pPlayerInfo)) {
+ result = false;
+ decided = true;
+ }
+ break;
+ default:
+ break;
+ }
+ infX = *(float*)&ScriptParams[1];
+ infY = *(float*)&ScriptParams[2];
+ if (b3D) {
+ infZ = *(float*)&ScriptParams[3];
+ supX = *(float*)&ScriptParams[4];
+ supY = *(float*)&ScriptParams[5];
+ supZ = *(float*)&ScriptParams[6];
+ if (infZ > supZ) {
+ infZ = *(float*)&ScriptParams[6];
+ supZ = *(float*)&ScriptParams[3];
+ }
+ side2length = *(float*)&ScriptParams[7];
+ debug = ScriptParams[8];
+ }
+ else {
+ supX = *(float*)&ScriptParams[3];
+ supY = *(float*)&ScriptParams[4];
+ side2length = *(float*)&ScriptParams[5];
+ debug = ScriptParams[6];
+ }
+ float initAngle = CGeneral::GetRadianAngleBetweenPoints(infX, infY, supX, supY) + HALFPI;
+ while (initAngle < 0.0f)
+ initAngle += TWOPI;
+ while (initAngle > TWOPI)
+ initAngle -= TWOPI;
+ // it looks like the idea is to use a rectangle using the diagonal of the rectangle as
+ // the side of new rectangle, with "length" being the length of second side
+ float rotatedSupX = supX + side2length * sin(initAngle);
+ float rotatedSupY = supY - side2length * cos(initAngle);
+ float rotatedInfX = infX + side2length * sin(initAngle);
+ float rotatedInfY = infY - side2length * cos(initAngle);
+ float side1X = supX - infX;
+ float side1Y = supY - infY;
+ float side1Length = CVector2D(side1X, side1Y).Magnitude();
+ float side2X = rotatedInfX - infX;
+ float side2Y = rotatedInfY - infY;
+ float side2Length = CVector2D(side2X, side2Y).Magnitude(); // == side2length?
+ if (!decided) {
+ CVector pos = pPlayerInfo->GetPos();
+ result = false;
+ float X = pos.x - infX;
+ float Y = pos.y - infY;
+ float positionAlongSide1 = X * side1X / side1Length + Y * side1Y / side1Length;
+ bool in_area = false;
+ if (positionAlongSide1 >= 0.0f && positionAlongSide1 <= side1Length) {
+ float positionAlongSide2 = X * side2X / side2Length + Y * side2Y / side2Length;
+ if (positionAlongSide2 >= 0.0f && positionAlongSide2 <= side2Length) {
+ in_area = !b3D || pos.z >= infZ && pos.z <= supZ;
+ }
+ }
+
+ if (in_area) {
+ switch (command) {
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_2D:
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_3D:
+ result = true;
+ break;
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_ON_FOOT_2D:
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_ON_FOOT_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_ON_FOOT_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_ON_FOOT_3D:
+ result = !pPlayerInfo->m_pPed->bInVehicle;
+ break;
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_IN_CAR_2D:
+ case COMMAND_IS_PLAYER_IN_ANGLED_AREA_IN_CAR_3D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_IN_CAR_2D:
+ case COMMAND_IS_PLAYER_STOPPED_IN_ANGLED_AREA_IN_CAR_3D:
+ result = pPlayerInfo->m_pPed->bInVehicle;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ }
+ UpdateCompareFlag(result);
+ if (debug)
+ CTheScripts::HighlightImportantAngledArea((uint32)this + m_nIp, infX, infY, supX, supY,
+ rotatedSupX, rotatedSupY, rotatedInfX, rotatedInfY, b3D ? (infZ + supZ) / 2 : -100.0f);
+ if (CTheScripts::DbgFlag) {
+ if (b3D)
+ CTheScripts::DrawDebugAngledCube(infX, infY, infZ, supX, supY, supZ,
+ rotatedSupX, rotatedSupY, rotatedInfX, rotatedInfY);
+ else
+ CTheScripts::DrawDebugAngledSquare(infX, infY, supX, supY,
+ rotatedSupX, rotatedSupY, rotatedInfX, rotatedInfY);
+ }
+}
+
+void CRunningScript::CharInAreaCheckCommand(int32 command, uint32* pIp)
+{
+ bool b3D, result, debug, decided = false;
+ float infX, infY, infZ, supX, supY, supZ;
+ switch (command) {
+ case COMMAND_IS_CHAR_IN_AREA_3D:
+ case COMMAND_IS_CHAR_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_CHAR_IN_AREA_IN_CAR_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_IN_CAR_3D:
+ b3D = true;
+ break;
+ default:
+ b3D = false;
+ break;
+ }
+ CollectParameters(pIp, b3D ? 8 : 6);
+ CPed* pPed = CPools::GetPedPool()->GetAt(ScriptParams[0]);
+ assert(pPed);
+ CVector pos = pPed->bInVehicle ? pPed->m_pMyVehicle->GetPosition() : pPed->GetPosition();
+ switch (command) {
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_IN_CAR_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_2D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_ON_FOOT_2D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_IN_CAR_2D:
+ if (!CTheScripts::IsPedStopped(pPed)) {
+ result = false;
+ decided = true;
+ }
+ break;
+ default:
+ break;
+ }
+ infX = *(float*)&ScriptParams[1];
+ infY = *(float*)&ScriptParams[2];
+ if (b3D) {
+ infZ = *(float*)&ScriptParams[3];
+ supX = *(float*)&ScriptParams[4];
+ supY = *(float*)&ScriptParams[5];
+ supZ = *(float*)&ScriptParams[6];
+ if (infZ > supZ) {
+ infZ = *(float*)&ScriptParams[6];
+ supZ = *(float*)&ScriptParams[3];
+ }
+ debug = ScriptParams[7];
+ }
+ else {
+ supX = *(float*)&ScriptParams[3];
+ supY = *(float*)&ScriptParams[4];
+ debug = ScriptParams[5];
+ }
+ if (infX > supX) {
+ float tmp = infX;
+ infX = supX;
+ supX = tmp;
+ }
+ if (infY > supY) {
+ float tmp = infY;
+ infY = supY;
+ supY = tmp;
+ }
+ if (!decided) {
+ result = false;
+ bool in_area;
+ if (b3D) {
+ in_area = infX <= pos.x &&
+ supX >= pos.x &&
+ infY <= pos.y &&
+ supY >= pos.y &&
+ infZ <= pos.z &&
+ supZ >= pos.z;
+ }
+ else {
+ in_area = infX <= pos.x &&
+ supX >= pos.x &&
+ infY <= pos.y &&
+ supY >= pos.y;
+ }
+ if (in_area) {
+ switch (command) {
+ case COMMAND_IS_CHAR_IN_AREA_2D:
+ case COMMAND_IS_CHAR_IN_AREA_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_2D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_3D:
+ result = true;
+ break;
+ case COMMAND_IS_CHAR_IN_AREA_ON_FOOT_2D:
+ case COMMAND_IS_CHAR_IN_AREA_ON_FOOT_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_ON_FOOT_2D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_ON_FOOT_3D:
+ result = !pPed->bInVehicle;
+ break;
+ case COMMAND_IS_CHAR_IN_AREA_IN_CAR_2D:
+ case COMMAND_IS_CHAR_IN_AREA_IN_CAR_3D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_IN_CAR_2D:
+ case COMMAND_IS_CHAR_STOPPED_IN_AREA_IN_CAR_3D:
+ result = pPed->bInVehicle;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ }
+ UpdateCompareFlag(result);
+ if (debug)
+ CTheScripts::HighlightImportantArea((uint32)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : -100.0f);
+ if (CTheScripts::DbgFlag) {
+ if (b3D)
+ CTheScripts::DrawDebugCube(infX, infY, infZ, supX, supY, supZ);
+ else
+ CTheScripts::DrawDebugSquare(infX, infY, supX, supY);
+ }
+}
+
+void CRunningScript::CarInAreaCheckCommand(int32 command, uint32* pIp)
+{
+ bool b3D, result, debug, decided = false;
+ float infX, infY, infZ, supX, supY, supZ;
+ switch (command) {
+ case COMMAND_IS_CAR_IN_AREA_3D:
+ case COMMAND_IS_CAR_STOPPED_IN_AREA_3D:
+ b3D = true;
+ break;
+ default:
+ b3D = false;
+ break;
+ }
+ CollectParameters(pIp, b3D ? 8 : 6);
+ CVehicle* pVehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
+ assert(pVehicle);
+ CVector pos = pVehicle->GetPosition();
+ switch (command) {
+ case COMMAND_IS_CAR_STOPPED_IN_AREA_3D:
+ case COMMAND_IS_CAR_STOPPED_IN_AREA_2D:
+ if (!CTheScripts::IsVehicleStopped(pVehicle)) {
+ result = false;
+ decided = true;
+ }
+ break;
+ default:
+ break;
+ }
+ infX = *(float*)&ScriptParams[1];
+ infY = *(float*)&ScriptParams[2];
+ if (b3D) {
+ infZ = *(float*)&ScriptParams[3];
+ supX = *(float*)&ScriptParams[4];
+ supY = *(float*)&ScriptParams[5];
+ supZ = *(float*)&ScriptParams[6];
+ if (infZ > supZ) {
+ infZ = *(float*)&ScriptParams[6];
+ supZ = *(float*)&ScriptParams[3];
+ }
+ debug = ScriptParams[7];
+ }
+ else {
+ supX = *(float*)&ScriptParams[3];
+ supY = *(float*)&ScriptParams[4];
+ debug = ScriptParams[5];
+ }
+ if (infX > supX) {
+ float tmp = infX;
+ infX = supX;
+ supX = tmp;
+ }
+ if (infY > supY) {
+ float tmp = infY;
+ infY = supY;
+ supY = tmp;
+ }
+ if (!decided) {
+ result = false;
+ bool in_area;
+ if (b3D) {
+ in_area = infX <= pos.x &&
+ supX >= pos.x &&
+ infY <= pos.y &&
+ supY >= pos.y &&
+ infZ <= pos.z &&
+ supZ >= pos.z;
+ }
+ else {
+ in_area = infX <= pos.x &&
+ supX >= pos.x &&
+ infY <= pos.y &&
+ supY >= pos.y;
+ }
+ if (in_area) {
+ switch (command) {
+ case COMMAND_IS_CAR_IN_AREA_2D:
+ case COMMAND_IS_CAR_IN_AREA_3D:
+ case COMMAND_IS_CAR_STOPPED_IN_AREA_2D:
+ case COMMAND_IS_CAR_STOPPED_IN_AREA_3D:
+ result = true;
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ }
+ UpdateCompareFlag(result);
+ if (debug)
+ CTheScripts::HighlightImportantArea((uint32)this + m_nIp, infX, infY, supX, supY, b3D ? (infZ + supZ) / 2 : -100.0f);
+ if (CTheScripts::DbgFlag) {
+ if (b3D)
+ CTheScripts::DrawDebugCube(infX, infY, infZ, supX, supY, supZ);
+ else
+ CTheScripts::DrawDebugSquare(infX, infY, supX, supY);
+ }
+}
+
+void CRunningScript::DoDeatharrestCheck()
+{
+ if (!m_bDeatharrestEnabled)
+ return;
+ if (!CTheScripts::IsPlayerOnAMission())
+ return;
+ CPlayerInfo* pPlayer = &CWorld::Players[CWorld::PlayerInFocus];
+ if (!pPlayer->IsRestartingAfterDeath() && !pPlayer->IsRestartingAfterArrest() && !CTheScripts::UpsideDownCars.AreAnyCarsUpsideDown())
+ return;
+ assert(m_nStackPointer > 0);
+ while (m_nStackPointer > 1)
+ --m_nStackPointer;
+ m_nIp = m_anStack[--m_nStackPointer];
+ int16 messageId;
+ if (pPlayer->IsRestartingAfterDeath())
+ messageId = 0;
+ else if (pPlayer->IsRestartingAfterArrest())
+ messageId = 5;
+ else
+ messageId = 10;
+ messageId += CGeneral::GetRandomNumberInRange(0, 5);
+ bool found = false;
+ for (int16 contact = 0; !found && contact < MAX_NUM_CONTACTS; contact++) {
+ int contactFlagOffset = CTheScripts::OnAMissionForContactFlag[contact];
+ if (contactFlagOffset && CTheScripts::ScriptSpace[contactFlagOffset] == 1) {
+ messageId += CTheScripts::BaseBriefIdForContact[contact];
+ }
+ }
+ if (!found)
+ messageId = 8001;
+ char tmp[16];
+ sprintf(tmp, "%d", messageId);
+ CMessages::ClearSmallMessagesOnly();
+ wchar* text = TheText.Get(tmp);
+ // ...and do nothing about it
+ *(int32*)&CTheScripts::ScriptSpace[CTheScripts::OnAMissionFlag] = 0;
+ m_bDeatharrestExecuted = true;
+ m_nWakeTime = 0;
+}
int16 CRunningScript::GetPadState(uint16 pad, uint16 button)
{
@@ -10596,12 +11093,115 @@ int16 CRunningScript::GetPadState(uint16 pad, uint16 button)
return 0;
}
-WRAPPER void CTheScripts::DrawDebugSquare(float, float, float, float) { EAXJMP(0x452D00); }
-WRAPPER void CTheScripts::DrawDebugAngledSquare(float, float, float, float, float, float, float, float) { EAXJMP(0x452F00); }
-WRAPPER void CTheScripts::DrawDebugCube(float, float, float, float, float, float) { EAXJMP(0x453100); }
-WRAPPER void CTheScripts::DrawDebugAngledCube(float, float, float, float, float, float, float, float, float, float) { EAXJMP(0x4532F0); }
-WRAPPER void CTheScripts::ScriptDebugLine3D(float x1, float y1, float z1, float x2, float y2, float z2, int col, int col2) { EAXJMP(0x4534E0); }
-WRAPPER void CTheScripts::RenderTheScriptDebugLines() { EAXJMP(0x453550); }
+uint32 DbgLineColour = 0x0000FFFF; // r = 0, g = 0, b = 255, a = 255
+
+void CTheScripts::DrawDebugSquare(float infX, float infY, float supX, float supY)
+{
+ CColPoint tmpCP;
+ CEntity* tmpEP;
+ CVector p1, p2, p3, p4;
+ p1 = CVector(infX, infY, -1000.0f);
+ CWorld::ProcessVerticalLine(p1, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p1.z = 2.0f + tmpCP.point.z;
+ p2 = CVector(supX, supY, -1000.0f);
+ CWorld::ProcessVerticalLine(p2, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p2.z = 2.0f + tmpCP.point.z;
+ p3 = CVector(infX, supY, -1000.0f);
+ CWorld::ProcessVerticalLine(p3, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p3.z = 2.0f + tmpCP.point.z;
+ p4 = CVector(supX, infY, -1000.0f);
+ CWorld::ProcessVerticalLine(p4, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p4.z = 2.0f + tmpCP.point.z;
+ CTheScripts::ScriptDebugLine3D(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(p3.x, p3.y, p3.z, p4.x, p4.y, p4.z, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(p4.x, p4.y, p4.z, p1.x, p1.y, p1.z, DbgLineColour, DbgLineColour);
+}
+
+void CTheScripts::DrawDebugAngledSquare(float infX, float infY, float supX, float supY, float rotSupX, float rotSupY, float rotInfX, float rotInfY)
+{
+ CColPoint tmpCP;
+ CEntity* tmpEP;
+ CVector p1, p2, p3, p4;
+ p1 = CVector(infX, infY, -1000.0f);
+ CWorld::ProcessVerticalLine(p1, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p1.z = 2.0f + tmpCP.point.z;
+ p2 = CVector(supX, supY, -1000.0f);
+ CWorld::ProcessVerticalLine(p2, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p2.z = 2.0f + tmpCP.point.z;
+ p3 = CVector(rotSupX, rotSupY, -1000.0f);
+ CWorld::ProcessVerticalLine(p3, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p3.z = 2.0f + tmpCP.point.z;
+ p4 = CVector(rotInfX, rotInfY, -1000.0f);
+ CWorld::ProcessVerticalLine(p4, 1000.0f, tmpCP, tmpEP, true, false, false, false, true, false, nil);
+ p4.z = 2.0f + tmpCP.point.z;
+ CTheScripts::ScriptDebugLine3D(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(p3.x, p3.y, p3.z, p4.x, p4.y, p4.z, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(p4.x, p4.y, p4.z, p1.x, p1.y, p1.z, DbgLineColour, DbgLineColour);
+}
+
+void CTheScripts::DrawDebugCube(float infX, float infY, float infZ, float supX, float supY, float supZ)
+{
+ CTheScripts::ScriptDebugLine3D(infX, infY, infZ, supX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, infY, infZ, supX, supY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, supY, infZ, infX, supY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(infX, supY, infZ, infX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(infX, infY, supZ, supX, infY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, infY, supZ, supX, supY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, supY, supZ, infX, supY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(infX, supY, supZ, infX, infY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(infX, infY, supZ, infX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, infY, supZ, supX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, supY, supZ, supX, supY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(infX, supY, supZ, infX, supY, infZ, DbgLineColour, DbgLineColour);
+}
+
+void CTheScripts::DrawDebugAngledCube(float infX, float infY, float infZ, float supX, float supY, float supZ, float rotSupX, float rotSupY, float rotInfX, float rotInfY)
+{
+ CTheScripts::ScriptDebugLine3D(infX, infY, infZ, supX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, infY, infZ, rotSupX, rotSupY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(rotSupX, rotSupY, infZ, rotInfX, rotInfY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(rotInfX, rotInfY, infZ, infX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(infX, infY, supZ, supX, infY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, infY, supZ, rotSupX, rotSupY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(rotSupX, rotSupY, rotInfX, rotInfY, supY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(rotInfX, rotInfY, supZ, infX, infY, supZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(infX, infY, supZ, infX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(supX, infY, supZ, supX, infY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(rotSupX, rotSupY, supZ, rotSupX, rotSupY, infZ, DbgLineColour, DbgLineColour);
+ CTheScripts::ScriptDebugLine3D(rotInfX, rotInfY, supZ, rotInfX, rotInfY, infZ, DbgLineColour, DbgLineColour);
+}
+
+void CTheScripts::ScriptDebugLine3D(float x1, float y1, float z1, float x2, float y2, float z2, uint32 col, uint32 col2)
+{
+ if (NumScriptDebugLines >= MAX_NUM_STORED_LINES)
+ return;
+ aStoredLines[NumScriptDebugLines].vecInf = CVector(x1, y1, z1);
+ aStoredLines[NumScriptDebugLines].vecSup = CVector(x2, y2, z2);
+ aStoredLines[NumScriptDebugLines].color1 = col;
+ aStoredLines[NumScriptDebugLines++].color2 = col2;
+}
+
+void CTheScripts::RenderTheScriptDebugLines()
+{
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)1);
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)1);
+ for (int i = 0; i < NumScriptDebugLines; i++) {
+ CLines::RenderLineWithClipping(
+ aStoredLines[i].vecInf.x,
+ aStoredLines[i].vecInf.y,
+ aStoredLines[i].vecInf.z,
+ aStoredLines[i].vecSup.x,
+ aStoredLines[i].vecSup.y,
+ aStoredLines[i].vecSup.z,
+ aStoredLines[i].color1,
+ aStoredLines[i].color2);
+ }
+ NumScriptDebugLines = 0;
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)0);
+}
+
WRAPPER void CTheScripts::SaveAllScripts(uint8*, uint32*) { EAXJMP(0x4535E0); }
WRAPPER void CTheScripts::LoadAllScripts(uint8*, uint32) { EAXJMP(0x453B30); }
WRAPPER void CTheScripts::ClearSpaceForMissionEntity(const CVector&, CEntity*) { EAXJMP(0x454060); }
@@ -10629,8 +11229,8 @@ InjectHook(0x439400, &CTheScripts::StartTestScript, PATCH_JUMP);
InjectHook(0x439410, &CTheScripts::IsPlayerOnAMission, PATCH_JUMP);
InjectHook(0x44FD10, &CTheScripts::UndoBuildingSwaps, PATCH_JUMP);
InjectHook(0x44FD60, &CTheScripts::UndoEntityVisibilitySettings, PATCH_JUMP);
-//InjectHook(0x4534E0, &CTheScripts::ScriptDebugLine3D, PATCH_JUMP);
-//InjectHook(0x453550, &CTheScripts::RenderTheScriptDebugLines, PATCH_JUMP);
+InjectHook(0x4534E0, &CTheScripts::ScriptDebugLine3D, PATCH_JUMP);
+InjectHook(0x453550, &CTheScripts::RenderTheScriptDebugLines, PATCH_JUMP);
//InjectHook(0x4535E0, &CTheScripts::SaveAllScripts, PATCH_JUMP);
//InjectHook(0x453B30, &CTheScripts::LoadAllScripts, PATCH_JUMP);
//InjectHook(0x454060, &CTheScripts::ClearSpaceForMissionEntity, PATCH_JUMP);
diff --git a/src/control/Script.h b/src/control/Script.h
index 5533c417..18d148bf 100644
--- a/src/control/Script.h
+++ b/src/control/Script.h
@@ -83,6 +83,14 @@ struct CScriptSphere
float m_fRadius;
};
+struct CStoredLine
+{
+ CVector vecInf;
+ CVector vecSup;
+ uint32 color1;
+ uint32 color2;
+};
+
enum {
CLEANUP_UNUSED = 0,
CLEANUP_CAR,
@@ -217,7 +225,8 @@ enum {
MAX_NUM_USED_OBJECTS = 200,
MAX_NUM_MISSION_SCRIPTS = 120,
MAX_NUM_BUILDING_SWAPS = 25,
- MAX_NUM_INVISIBILITY_SETTINGS = 20
+ MAX_NUM_INVISIBILITY_SETTINGS = 20,
+ MAX_NUM_STORED_LINES = 1024
};
class CTheScripts
@@ -235,6 +244,7 @@ class CTheScripts
static int32(&MultiScriptArray)[MAX_NUM_MISSION_SCRIPTS];
static tBuildingSwap(&BuildingSwapArray)[MAX_NUM_BUILDING_SWAPS];
static CEntity*(&InvisibilitySettingArray)[MAX_NUM_INVISIBILITY_SETTINGS];
+ static CStoredLine(&aStoredLines)[MAX_NUM_STORED_LINES];
static bool &DbgFlag;
static uint32 &OnAMissionFlag;
static CMissionCleanup &MissionCleanup;
@@ -258,7 +268,7 @@ class CTheScripts
static uint16 &NumScriptDebugLines;
static uint16 &NumberOfIntroRectanglesThisFrame;
static uint16 &NumberOfIntroTextLinesThisFrame;
- static bool &UseTextCommands;
+ static uint8 &UseTextCommands;
static uint16 &CommandsExecuted;
static uint16 &ScriptsUpdated;
@@ -273,7 +283,7 @@ public:
static void UndoBuildingSwaps();
static void UndoEntityVisibilitySettings();
- static void ScriptDebugLine3D(float x1, float y1, float z1, float x2, float y2, float z2, int col, int col2);
+ static void ScriptDebugLine3D(float x1, float y1, float z1, float x2, float y2, float z2, uint32 col, uint32 col2);
static void RenderTheScriptDebugLines();
static void SaveAllScripts(uint8*, uint32*);
diff --git a/src/core/main.cpp b/src/core/main.cpp
index 2f266a9e..90afff72 100644
--- a/src/core/main.cpp
+++ b/src/core/main.cpp
@@ -48,6 +48,7 @@
#include "RpAnimBlend.h"
#include "Frontend.h"
#include "AnimViewer.h"
+#include "Script.h"
#define DEFAULT_VIEWWINDOW (Tan(DEGTORAD(CDraw::GetFOV() * 0.5f)))
@@ -356,7 +357,7 @@ RenderScene(void)
void
RenderDebugShit(void)
{
- // CTheScripts::RenderTheScriptDebugLines()
+ CTheScripts::RenderTheScriptDebugLines();
if(gbShowCollisionLines)
CRenderer::RenderCollisionLines();
}