Re3/src/control/Garages.h

245 lines
7.1 KiB
C
Raw Normal View History

2019-05-28 02:39:36 -04:00
#pragma once
2020-01-03 11:48:13 -05:00
#include "Automobile.h"
#include "audio_enums.h"
2020-03-28 08:24:13 -04:00
#include "Camera.h"
2020-01-03 11:48:13 -05:00
#include "config.h"
2019-05-28 02:39:36 -04:00
2019-10-21 17:39:59 -04:00
class CVehicle;
2020-01-03 11:48:13 -05:00
enum eGarageState : int8
{
GS_FULLYCLOSED,
GS_OPENED,
GS_CLOSING,
GS_OPENING,
GS_OPENEDCONTAINSCAR,
GS_CLOSEDCONTAINSCAR,
GS_AFTERDROPOFF,
};
enum eGarageType : int8
{
GARAGE_NONE,
GARAGE_MISSION,
GARAGE_BOMBSHOP1,
GARAGE_BOMBSHOP2,
GARAGE_BOMBSHOP3,
GARAGE_RESPRAY,
GARAGE_COLLECTORSITEMS,
GARAGE_COLLECTSPECIFICCARS,
GARAGE_COLLECTCARS_1,
GARAGE_COLLECTCARS_2,
GARAGE_COLLECTCARS_3,
GARAGE_FORCARTOCOMEOUTOF,
GARAGE_60SECONDS,
GARAGE_CRUSHER,
GARAGE_MISSION_KEEPCAR,
GARAGE_FOR_SCRIPT_TO_OPEN,
GARAGE_HIDEOUT_ONE,
GARAGE_HIDEOUT_TWO,
GARAGE_HIDEOUT_THREE,
GARAGE_FOR_SCRIPT_TO_OPEN_AND_CLOSE,
GARAGE_KEEPS_OPENING_FOR_SPECIFIC_CAR,
GARAGE_MISSION_KEEPCAR_REMAINCLOSED,
};
2020-02-15 06:53:42 -05:00
enum
{
TOTAL_COLLECTCARS_GARAGES = GARAGE_COLLECTCARS_3 - GARAGE_COLLECTCARS_1 + 1
};
2020-01-03 11:48:13 -05:00
class CStoredCar
{
int32 m_nModelIndex;
CVector m_vecPos;
CVector m_vecAngle;
int32 m_bBulletproof : 1;
int32 m_bFireproof : 1;
int32 m_bExplosionproof : 1;
int32 m_bCollisionproof : 1;
int32 m_bMeleeproof : 1;
int8 m_nPrimaryColor;
int8 m_nSecondaryColor;
int8 m_nRadioStation;
int8 m_nVariationA;
int8 m_nVariationB;
int8 m_nCarBombType;
2020-03-28 08:24:13 -04:00
public:
void Init() { m_nModelIndex = 0; }
2020-03-28 13:52:25 -04:00
CStoredCar(const CStoredCar& other);
void StoreCar(CVehicle*);
CVehicle* RestoreCar();
2020-01-03 11:48:13 -05:00
};
static_assert(sizeof(CStoredCar) == 0x28, "CStoredCar");
2020-03-28 08:24:13 -04:00
#define SWITCH_GARAGE_DISTANCE_CLOSE 40.0f
2020-01-03 11:48:13 -05:00
class CGarage
{
2020-02-15 06:53:42 -05:00
public:
2020-01-03 11:48:13 -05:00
eGarageType m_eGarageType;
eGarageState m_eGarageState;
char field_2;
2020-03-28 08:24:13 -04:00
bool m_bClosingWithoutTargetCar;
bool m_bDeactivated;
bool m_bResprayHappened;
2020-01-03 11:48:13 -05:00
int m_nTargetModelIndex;
CEntity *m_pDoor1;
CEntity *m_pDoor2;
2020-03-28 08:24:13 -04:00
uint8 m_bDoor1PoolIndex;
uint8 m_bDoor2PoolIndex;
2020-03-28 16:41:37 -04:00
bool m_bDoor1IsDummy;
bool m_bDoor2IsDummy;
bool m_bRecreateDoorOnNextRefresh;
2020-03-28 08:24:13 -04:00
bool m_bRotatedDoor;
bool m_bCameraFollowsPlayer;
float m_fX1;
float m_fX2;
float m_fY1;
float m_fY2;
float m_fZ1;
float m_fZ2;
2020-01-03 11:48:13 -05:00
float m_fDoorPos;
float m_fDoorHeight;
float m_fDoor1X;
float m_fDoor1Y;
float m_fDoor2X;
float m_fDoor2Y;
float m_fDoor1Z;
float m_fDoor2Z;
2020-03-28 08:24:13 -04:00
uint32 m_nTimeToStartAction;
2020-01-03 11:48:13 -05:00
char m_bCollectedCarsState;
char field_89;
char field_90;
char field_91;
CVehicle *m_pTarget;
int field_96;
CStoredCar m_sStoredCar;
2020-02-15 06:53:42 -05:00
2020-01-03 11:48:13 -05:00
void OpenThisGarage();
void CloseThisGarage();
2020-02-15 06:53:42 -05:00
bool IsOpen() { return m_eGarageState == GS_OPENED || m_eGarageState == GS_OPENEDCONTAINSCAR; }
bool IsClosed() { return m_eGarageState == GS_FULLYCLOSED; }
2020-03-28 08:24:13 -04:00
bool IsUsed() { return m_eGarageType != GARAGE_NONE; }
void Update();
float GetGarageCenterX() { return (m_fX1 + m_fX2) / 2; }
float GetGarageCenterY() { return (m_fY1 + m_fY2) / 2; }
bool IsClose()
{
#ifdef FIX_BUGS
return Abs(TheCamera.GetPosition().x - GetGarageCenterX()) > SWITCH_GARAGE_DISTANCE_CLOSE ||
Abs(TheCamera.GetPosition().y - GetGarageCenterY()) > SWITCH_GARAGE_DISTANCE_CLOSE;
#else
return Abs(TheCamera.GetPosition().x - m_fX1) > SWITCH_GARAGE_DISTANCE_CLOSE ||
Abs(TheCamera.GetPosition().y - m_fY1) > SWITCH_GARAGE_DISTANCE_CLOSE;
#endif
}
void TidyUpGarageClose();
void TidyUpGarage();
void RefreshDoorPointers(bool);
void UpdateCrusherAngle();
void UpdateDoorsHeight();
bool IsEntityEntirelyInside3D(CEntity*, float);
bool IsEntityEntirelyOutside(CEntity*, float);
2020-03-28 13:52:25 -04:00
bool IsEntityEntirelyInside(CEntity*);
2020-03-28 08:24:13 -04:00
float CalcDistToGarageRectangleSquared(float, float);
2020-03-28 13:52:25 -04:00
float CalcSmallestDistToGarageDoorSquared(float, float);
2020-03-28 08:24:13 -04:00
bool IsAnyOtherCarTouchingGarage(CVehicle* pException);
bool IsStaticPlayerCarEntirelyInside();
bool IsPlayerOutsideGarage();
2020-03-28 13:52:25 -04:00
bool IsAnyCarBlockingDoor();
2020-03-28 08:24:13 -04:00
void CenterCarInGarage(CVehicle*);
2020-03-28 13:52:25 -04:00
bool DoesCraigNeedThisCar(int32);
void MarkThisCarAsCollectedForCraig(int32);
bool HasCraigCollectedThisCar(int32);
bool IsGarageEmpty();
void UpdateCrusherShake(float, float);
int32 CountCarsWithCenterPointWithinGarage(CEntity* pException);
void RemoveCarsBlockingDoorNotInside();
void StoreAndRemoveCarsForThisHideout(CStoredCar*, int32);
bool RestoreCarsForThisHideout(CStoredCar*);
bool IsEntityTouching3D(CEntity*);
bool EntityHasASphereWayOutsideGarage(CEntity*, float);
bool IsAnyOtherPedTouchingGarage(CPed* pException);
void BuildRotatedDoorMatrix(CEntity*, float);
void FindDoorsEntities();
void FindDoorsEntitiesSectorList(CPtrList&, bool);
void PlayerArrestedOrDied();
2020-01-03 11:48:13 -05:00
};
static_assert(sizeof(CGarage) == 140, "CGarage");
2019-05-28 02:39:36 -04:00
class CGarages
{
public:
static int32 &BankVansCollected;
static bool &BombsAreFree;
static bool &RespraysAreFree;
static int32 &CarsCollected;
2020-02-15 06:53:42 -05:00
static int32 (&CarTypesCollected)[TOTAL_COLLECTCARS_GARAGES];
static int32 &CrushedCarId;
static uint32 &LastTimeHelpMessage;
static int32 &MessageNumberInString;
static const char *MessageIDString;
static int32 &MessageNumberInString2;
static uint32 &MessageStartTime;
static uint32 &MessageEndTime;
static uint32 &NumGarages;
static bool &PlayerInGarage;
static int32 &PoliceCarsCollected;
static uint32 &GarageToBeTidied;
2020-03-28 08:24:13 -04:00
static CGarage(&aGarages)[NUM_GARAGES];
static CStoredCar(&aCarsInSafeHouse1)[NUM_GARAGE_STORED_CARS];
static CStoredCar(&aCarsInSafeHouse2)[NUM_GARAGE_STORED_CARS];
static CStoredCar(&aCarsInSafeHouse3)[NUM_GARAGE_STORED_CARS];
static int32 &AudioEntity;
static bool &bCamShouldBeOutisde;
2019-05-28 02:39:36 -04:00
public:
2020-03-28 08:24:13 -04:00
static void Init(void);
#ifndef PS2
static void Shutdown(void);
#endif
static int16 AddOne(float X1, float Y1, float Z1, float X2, float Y2, float Z2, eGarageType type, int32 targetId);
2019-05-28 02:39:36 -04:00
static bool IsModelIndexADoor(uint32 id);
2019-08-16 14:17:15 -04:00
static void TriggerMessage(const char *text, int16, uint16 time, int16);
static void PrintMessages(void);
2019-07-27 14:28:18 -04:00
static bool HasCarBeenCrushed(int32);
2019-09-16 13:32:58 -04:00
static bool IsPointWithinHideOutGarage(CVector&);
static bool IsPointWithinAnyGarage(CVector&);
2019-10-07 17:29:30 -04:00
static void PlayerArrestedOrDied();
2020-03-28 08:24:13 -04:00
2019-10-18 18:23:40 -04:00
static void Update(void);
2020-03-10 23:25:50 -04:00
static void Load(uint8 *buf, uint32 size);
static void Save(uint8 *buf, uint32 *size);
2019-10-21 17:39:59 -04:00
static void SetTargetCarForMissonGarage(int16, CVehicle*);
static bool HasCarBeenDroppedOffYet(int16);
2019-10-27 05:51:09 -04:00
static void ActivateGarage(int16);
static void DeActivateGarage(int16);
static int32 QueryCarsCollected(int16);
static bool HasThisCarBeenCollected(int16, uint8);
2020-02-15 06:53:42 -05:00
static void ChangeGarageType(int16, eGarageType, int32);
2020-01-03 11:48:13 -05:00
static bool HasResprayHappened(int16);
static void GivePlayerDetonator();
2020-02-15 06:53:42 -05:00
static bool IsGarageOpen(int16);
static bool IsGarageClosed(int16);
static void SetGarageDoorToRotate(int16);
static bool HasImportExportGarageCollectedThisCar(int16, int8);
static void SetLeaveCameraForThisGarage(int16);
2020-02-16 15:08:54 -05:00
static bool IsThisCarWithinGarageArea(int16, CEntity*);
2020-03-28 13:52:25 -04:00
static bool IsCarSprayable(CVehicle*);
static int32 FindMaxNumStoredCarsForGarage(eGarageType);
static int32 CountCarsInHideoutGarage(eGarageType);
static bool IsPointInAGarageCameraZone(CVector);
static bool CameraShouldBeOutside();
static void CloseHideOutGaragesBeforeSave();
static void SetAllDoorsBackToOriginalHeight();
2020-02-15 06:53:42 -05:00
2020-03-28 08:24:13 -04:00
static int GetBombTypeForGarageType(eGarageType type) { return type - GARAGE_BOMBSHOP1 + 1; }
2020-02-15 06:53:42 -05:00
static int GetCarsCollectedIndexForGarageType(eGarageType type) { return type - GARAGE_COLLECTCARS_1; }
2020-03-28 08:24:13 -04:00
private:
static float FindDoorHeightForMI(int32);
2019-05-28 02:39:36 -04:00
};