summaryrefslogtreecommitdiffstats
path: root/src/control/Script.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/control/Script.h')
-rw-r--r--src/control/Script.h361
1 files changed, 180 insertions, 181 deletions
diff --git a/src/control/Script.h b/src/control/Script.h
index 8cf6bb42..5682024b 100644
--- a/src/control/Script.h
+++ b/src/control/Script.h
@@ -1,7 +1,5 @@
#pragma once
-#include "common.h"
#include "Font.h"
-#include "Ped.h"
#include "PedType.h"
#include "Text.h"
#include "Sprite2d.h"
@@ -20,27 +18,34 @@ extern int32 ScriptParams[32];
void FlushLog();
#define script_assert(_Expression) FlushLog(); assert(_Expression);
-#define PICKUP_PLACEMENT_OFFSET 0.5f
-#define PED_FIND_Z_OFFSET 5.0f
+#define PICKUP_PLACEMENT_OFFSET (0.5f)
+#define PED_FIND_Z_OFFSET (5.0f)
-#define SPHERE_MARKER_R 0
-#define SPHERE_MARKER_G 128
-#define SPHERE_MARKER_B 255
-#define SPHERE_MARKER_A 128
-#define SPHERE_MARKER_PULSE_PERIOD 2048
-#define SPHERE_MARKER_PULSE_FRACTION 0.1f
+#define UPSIDEDOWN_UP_THRESHOLD (-0.97f)
+#define UPSIDEDOWN_MOVE_SPEED_THRESHOLD (0.01f)
+#define UPSIDEDOWN_TURN_SPEED_THRESHOLD (0.02f)
+#define UPSIDEDOWN_TIMER_THRESHOLD (1000)
+
+#define SPHERE_MARKER_R (0)
+#define SPHERE_MARKER_G (128)
+#define SPHERE_MARKER_B (255)
+#define SPHERE_MARKER_A (128)
+#define SPHERE_MARKER_PULSE_PERIOD (2048)
+#define SPHERE_MARKER_PULSE_FRACTION (0.1f)
#ifdef USE_PRECISE_MEASUREMENT_CONVERTION
-#define METERS_IN_FOOT 0.3048f
-#define FEET_IN_METER 3.28084f
+#define MILES_IN_METER (0.000621371192f)
+#define METERS_IN_FOOT (0.3048f)
+#define FEET_IN_METER (3.28084f)
#else
-#define METERS_IN_FOOT 0.3f
-#define FEET_IN_METER 3.33f
+#define MILES_IN_METER (1 / 1670.f)
+#define METERS_IN_FOOT (0.3f)
+#define FEET_IN_METER (3.33f)
#endif
-#define KEY_LENGTH_IN_SCRIPT 8
+#define KEY_LENGTH_IN_SCRIPT (8)
-#if GTA_VERSION <= GTA_PS2_160
+#if GTA_VERSION <= GTA3_PS2_160
#define GTA_SCRIPT_COLLECTIVE
#endif
@@ -95,8 +100,8 @@ struct intro_text_line
m_bCentered = false;
m_bBackground = false;
m_bBackgroundOnly = false;
- m_fWrapX = 182.0f; /* TODO: scaling as bugfix */
- m_fCenterSize = 640.0f; /* --||-- */
+ m_fWrapX = 182.0f;
+ m_fCenterSize = DEFAULT_SCREEN_WIDTH;
m_sBackgroundColor = CRGBA(128, 128, 128, 128);
m_bTextProportional = true;
m_bTextBeforeFade = false;
@@ -149,10 +154,10 @@ enum {
class CMissionCleanup
{
+public:
cleanup_entity_struct m_sEntities[MAX_CLEANUP];
uint8 m_nCount;
-public:
CMissionCleanup();
void Init();
@@ -162,7 +167,7 @@ public:
void Process();
};
-struct CUpsideDownCarCheckEntry
+struct upsidedown_car_data
{
int32 m_nVehicleIndex;
uint32 m_nUpsideDownTimer;
@@ -170,11 +175,12 @@ struct CUpsideDownCarCheckEntry
class CUpsideDownCarCheck
{
- CUpsideDownCarCheckEntry m_sCars[MAX_UPSIDEDOWN_CAR_CHECKS];
+ upsidedown_car_data m_sCars[MAX_UPSIDEDOWN_CAR_CHECKS];
public:
void Init();
bool IsCarUpsideDown(int32);
+ bool IsCarUpsideDown(CVehicle*);
void UpdateTimers();
bool AreAnyCarsUpsideDown();
void AddCarToCheck(int32);
@@ -192,7 +198,7 @@ struct stuck_car_data
bool m_bStuck;
stuck_car_data() { }
- inline void Reset();
+ void Reset();
};
class CStuckCarCheck
@@ -242,6 +248,156 @@ struct tBuildingSwap
enum {
+#if GTA_VERSION > GTA3_PS2_160
+ MAX_STACK_DEPTH = 6,
+#else
+ MAX_STACK_DEPTH = 4,
+#endif
+ NUM_LOCAL_VARS = 16,
+ NUM_TIMERS = 2
+};
+
+class CRunningScript
+{
+ enum {
+ ANDOR_NONE = 0,
+ ANDS_1 = 1,
+ ANDS_2,
+ ANDS_3,
+ ANDS_4,
+ ANDS_5,
+ ANDS_6,
+ ANDS_7,
+ ANDS_8,
+ ORS_1 = 21,
+ ORS_2,
+ ORS_3,
+ ORS_4,
+ ORS_5,
+ ORS_6,
+ ORS_7,
+ ORS_8
+ };
+
+public:
+ CRunningScript* next;
+ CRunningScript* prev;
+ char m_abScriptName[8];
+ uint32 m_nIp;
+ uint32 m_anStack[MAX_STACK_DEPTH];
+ uint16 m_nStackPointer;
+ int32 m_anLocalVariables[NUM_LOCAL_VARS + NUM_TIMERS];
+ bool m_bCondResult;
+ bool m_bIsMissionScript;
+ bool m_bSkipWakeTime;
+ uint32 m_nWakeTime;
+ uint16 m_nAndOrState;
+ bool m_bNotFlag;
+ bool m_bDeatharrestEnabled;
+ bool m_bDeatharrestExecuted;
+ bool m_bMissionFlag;
+
+public:
+ void SetIP(uint32 ip) { m_nIp = ip; }
+ CRunningScript* GetNext() const { return next; }
+
+ void Save(uint8*& buf);
+ void Load(uint8*& buf);
+
+ void UpdateTimers(float timeStep) {
+ m_anLocalVariables[NUM_LOCAL_VARS] += timeStep;
+ m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep;
+ }
+
+ void Init();
+ void Process();
+
+ void RemoveScriptFromList(CRunningScript**);
+ void AddScriptToList(CRunningScript**);
+
+ static const uint32 nSaveStructSize;
+
+ void CollectParameters(uint32*, int16);
+ int32 CollectNextParameterWithoutIncreasingPC(uint32);
+ int32* GetPointerToScriptVariable(uint32*, int16);
+ void StoreParameters(uint32*, int16);
+
+ int8 ProcessOneCommand();
+ void DoDeatharrestCheck();
+ void UpdateCompareFlag(bool);
+ int16 GetPadState(uint16, uint16);
+
+ int8 ProcessCommands0To99(int32);
+ int8 ProcessCommands100To199(int32);
+ int8 ProcessCommands200To299(int32);
+ int8 ProcessCommands300To399(int32);
+ int8 ProcessCommands400To499(int32);
+ int8 ProcessCommands500To599(int32);
+ int8 ProcessCommands600To699(int32);
+ int8 ProcessCommands700To799(int32);
+ int8 ProcessCommands800To899(int32);
+ int8 ProcessCommands900To999(int32);
+ int8 ProcessCommands1000To1099(int32);
+#if GTA_VERSION > GTA3_PS2_160
+ int8 ProcessCommands1100To1199(int32);
+#endif
+ void LocatePlayerCommand(int32, uint32*);
+ void LocatePlayerCharCommand(int32, uint32*);
+ void LocatePlayerCarCommand(int32, uint32*);
+ void LocateCharCommand(int32, uint32*);
+ void LocateCharCharCommand(int32, uint32*);
+ void LocateCharCarCommand(int32, uint32*);
+ void LocateCharObjectCommand(int32, uint32*);
+ void LocateCarCommand(int32, uint32*);
+ void LocateSniperBulletCommand(int32, uint32*);
+ void PlayerInAreaCheckCommand(int32, uint32*);
+ void PlayerInAngledAreaCheckCommand(int32, uint32*);
+ void CharInAreaCheckCommand(int32, uint32*);
+ void CarInAreaCheckCommand(int32, uint32*);
+
+#ifdef GTA_SCRIPT_COLLECTIVE
+ void LocateCollectiveCommand(int32, uint32*);
+ void LocateCollectiveCharCommand(int32, uint32*);
+ void LocateCollectiveCarCommand(int32, uint32*);
+ void LocateCollectivePlayerCommand(int32, uint32*);
+ void CollectiveInAreaCheckCommand(int32, uint32*);
+#endif
+
+#ifdef MISSION_REPLAY
+ bool CanAllowMissionReplay();
+#endif
+
+#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
+ int CollectParameterForDebug(char* buf, bool& var);
+ void GetStoredParameterForDebug(char* buf);
+#endif
+
+ float LimitAngleOnCircle(float angle) { return angle < 0.0f ? angle + 360.0f : angle; }
+
+ bool ThisIsAValidRandomPed(uint32 pedtype) {
+ switch (pedtype) {
+ case PEDTYPE_CIVMALE:
+ case PEDTYPE_CIVFEMALE:
+ case PEDTYPE_GANG1:
+ case PEDTYPE_GANG2:
+ case PEDTYPE_GANG3:
+ case PEDTYPE_GANG4:
+ case PEDTYPE_GANG5:
+ case PEDTYPE_GANG6:
+ case PEDTYPE_GANG7:
+ case PEDTYPE_GANG8:
+ case PEDTYPE_GANG9:
+ case PEDTYPE_CRIMINAL:
+ case PEDTYPE_PROSTITUTE:
+ return true;
+ default:
+ return false;
+ }
+ }
+};
+
+
+enum {
VAR_LOCAL = 1,
VAR_GLOBAL = 2,
};
@@ -269,6 +425,7 @@ enum {
class CTheScripts
{
+public:
static uint8 ScriptSpace[SIZE_SCRIPT_SPACE];
static CRunningScript ScriptsArray[MAX_NUM_SCRIPTS];
static int32 BaseBriefIdForContact[MAX_NUM_CONTACTS];
@@ -285,7 +442,7 @@ class CTheScripts
static CStoredLine aStoredLines[MAX_NUM_STORED_LINES];
static bool DbgFlag;
static uint32 OnAMissionFlag;
- static CMissionCleanup MissionCleanup;
+ static CMissionCleanup MissionCleanUp;
static CStuckCarCheck StuckCars;
static CUpsideDownCarCheck UpsideDownCars;
static int32 StoreVehicleIndex;
@@ -310,7 +467,6 @@ class CTheScripts
static uint16 CommandsExecuted;
static uint16 ScriptsUpdated;
-public:
static void Init();
static void Process();
@@ -367,8 +523,6 @@ public:
return Read4BytesFromScript(&tmp);
}
-private:
-
static CRunningScript* StartNewScript(uint32);
static void CleanUpThisVehicle(CVehicle*);
@@ -418,167 +572,12 @@ private:
static void SetObjectiveForAllPedsInCollective(int, eObjective);
#endif
- friend class CRunningScript;
- friend class CHud;
- friend void CMissionCleanup::Process();
-#ifdef MISSION_REPLAY
- friend void RetryMission(int, int);
-#endif
-
#ifdef MISSION_SWITCHER
public:
static void SwitchToMission(int32 mission);
#endif
};
-
-enum {
- MAX_STACK_DEPTH = 6, // 4 PS2
- NUM_LOCAL_VARS = 16,
- NUM_TIMERS = 2
-};
-
-class CRunningScript
-{
- enum {
- ANDOR_NONE = 0,
- ANDS_1 = 1,
- ANDS_2,
- ANDS_3,
- ANDS_4,
- ANDS_5,
- ANDS_6,
- ANDS_7,
- ANDS_8,
- ORS_1 = 21,
- ORS_2,
- ORS_3,
- ORS_4,
- ORS_5,
- ORS_6,
- ORS_7,
- ORS_8
- };
-
- CRunningScript* next;
- CRunningScript* prev;
- char m_abScriptName[8];
- uint32 m_nIp;
- uint32 m_anStack[MAX_STACK_DEPTH];
- uint16 m_nStackPointer;
- int32 m_anLocalVariables[NUM_LOCAL_VARS + NUM_TIMERS];
- bool m_bCondResult;
- bool m_bIsMissionScript;
- bool m_bSkipWakeTime;
- uint32 m_nWakeTime;
- uint16 m_nAndOrState;
- bool m_bNotFlag;
- bool m_bDeatharrestEnabled;
- bool m_bDeatharrestExecuted;
- bool m_bMissionFlag;
-
-public:
- void SetIP(uint32 ip) { m_nIp = ip; }
- CRunningScript* GetNext() const { return next; }
-
- void Save(uint8*& buf);
- void Load(uint8*& buf);
-
- void UpdateTimers(float timeStep) {
- m_anLocalVariables[NUM_LOCAL_VARS] += timeStep;
- m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep;
- }
-
- void Init();
- void Process();
-
- void RemoveScriptFromList(CRunningScript**);
- void AddScriptToList(CRunningScript**);
-
- static const uint32 nSaveStructSize;
-
-private:
- void CollectParameters(uint32*, int16);
- int32 CollectNextParameterWithoutIncreasingPC(uint32);
- int32* GetPointerToScriptVariable(uint32*, int16);
- void StoreParameters(uint32*, int16);
-
- int8 ProcessOneCommand();
- void DoDeatharrestCheck();
- void UpdateCompareFlag(bool);
- int16 GetPadState(uint16, uint16);
-
- int8 ProcessCommands0To99(int32);
- int8 ProcessCommands100To199(int32);
- int8 ProcessCommands200To299(int32);
- int8 ProcessCommands300To399(int32);
- int8 ProcessCommands400To499(int32);
- int8 ProcessCommands500To599(int32);
- int8 ProcessCommands600To699(int32);
- int8 ProcessCommands700To799(int32);
- int8 ProcessCommands800To899(int32);
- int8 ProcessCommands900To999(int32);
- int8 ProcessCommands1000To1099(int32);
-#ifndef GTA_PS2
- int8 ProcessCommands1100To1199(int32);
-#endif
- void LocatePlayerCommand(int32, uint32*);
- void LocatePlayerCharCommand(int32, uint32*);
- void LocatePlayerCarCommand(int32, uint32*);
- void LocateCharCommand(int32, uint32*);
- void LocateCharCharCommand(int32, uint32*);
- void LocateCharCarCommand(int32, uint32*);
- void LocateCharObjectCommand(int32, uint32*);
- void LocateCarCommand(int32, uint32*);
- void LocateSniperBulletCommand(int32, uint32*);
- void PlayerInAreaCheckCommand(int32, uint32*);
- void PlayerInAngledAreaCheckCommand(int32, uint32*);
- void CharInAreaCheckCommand(int32, uint32*);
- void CarInAreaCheckCommand(int32, uint32*);
-
-#ifdef GTA_SCRIPT_COLLECTIVE
- void LocateCollectiveCommand(int32, uint32*);
- void LocateCollectiveCharCommand(int32, uint32*);
- void LocateCollectiveCarCommand(int32, uint32*);
- void LocateCollectivePlayerCommand(int32, uint32*);
- void CollectiveInAreaCheckCommand(int32, uint32*);
-#endif
-
-#ifdef MISSION_REPLAY
- bool CanAllowMissionReplay();
-#endif
-
-#ifdef USE_ADVANCED_SCRIPT_DEBUG_OUTPUT
- int CollectParameterForDebug(char* buf, bool& var);
- void GetStoredParameterForDebug(char* buf);
-#endif
-
- float LimitAngleOnCircle(float angle) { return angle < 0.0f ? angle + 360.0f : angle; }
-
- bool ThisIsAValidRandomPed(uint32 pedtype) {
- switch (pedtype) {
- case PEDTYPE_CIVMALE:
- case PEDTYPE_CIVFEMALE:
- case PEDTYPE_GANG1:
- case PEDTYPE_GANG2:
- case PEDTYPE_GANG3:
- case PEDTYPE_GANG4:
- case PEDTYPE_GANG5:
- case PEDTYPE_GANG6:
- case PEDTYPE_GANG7:
- case PEDTYPE_GANG8:
- case PEDTYPE_GANG9:
- case PEDTYPE_CRIMINAL:
- case PEDTYPE_PROSTITUTE:
- return true;
- default:
- return false;
- }
- }
-
- friend class CTheScripts;
-};
-
#ifdef MISSION_REPLAY
extern int AllowMissionReplay;
extern uint32 WaitForMissionActivate;