re3-wiiu/src/control/Garages.h

306 lines
9.0 KiB
C
Raw Normal View History

2019-05-28 08:39:36 +02:00
#pragma once
2020-01-03 17:48:13 +01:00
#include "Automobile.h"
#include "audio_enums.h"
2020-03-28 13:24:13 +01:00
#include "Camera.h"
2020-01-03 17:48:13 +01:00
#include "config.h"
2019-05-28 08:39:36 +02:00
2019-10-21 23:39:59 +02:00
class CVehicle;
2020-04-02 12:48:01 +02:00
class CCamera;
2019-10-21 23:39:59 +02:00
2020-01-03 17:48:13 +01: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-05-10 16:54:13 +02:00
GARAGE_COLLECTCARS_4,
GARAGE_FOR_SCRIPT_TO_OPEN_FOR_CAR,
GARAGE_HIDEOUT_FOUR,
GARAGE_HIDEOUT_FIVE,
GARAGE_HIDEOUT_SIX,
GARAGE_HIDEOUT_SEVEN,
GARAGE_HIDEOUT_EIGHT,
GARAGE_HIDEOUT_NINE,
GARAGE_HIDEOUT_TEN,
GARAGE_HIDEOUT_ELEVEN,
GARAGE_HIDEOUT_TWELVE
2020-01-03 17:48:13 +01:00
};
2020-02-15 12:53:42 +01:00
enum
{
2020-05-11 20:04:35 +02:00
TOTAL_COLLECTCARS_GARAGES = 4,
TOTAL_HIDEOUT_GARAGES = 12,
TOTAL_COLLECTCARS_CARS = 6
2020-02-15 12:53:42 +01:00
};
2020-01-03 17:48:13 +01: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 13:24:13 +01:00
public:
void Init() { m_nModelIndex = 0; }
2020-03-30 23:01:03 +02:00
void Clear() { m_nModelIndex = 0; }
bool HasCar() { return m_nModelIndex != 0; }
const CStoredCar &operator=(const CStoredCar& other);
2020-03-28 18:52:25 +01:00
void StoreCar(CVehicle*);
CVehicle* RestoreCar();
2020-01-03 17:48:13 +01:00
};
VALIDATE_SIZE(CStoredCar, 0x28);
2020-01-03 17:48:13 +01:00
2020-03-28 13:24:13 +01:00
#define SWITCH_GARAGE_DISTANCE_CLOSE 40.0f
2020-01-03 17:48:13 +01:00
class CGarage
{
eGarageType m_eGarageType;
eGarageState m_eGarageState;
2020-05-11 00:00:41 +02:00
uint8 m_nMaxStoredCars;
2020-03-30 23:46:44 +02:00
bool field_2; // unused
2020-03-28 13:24:13 +01:00
bool m_bClosingWithoutTargetCar;
bool m_bDeactivated;
bool m_bResprayHappened;
2020-01-03 17:48:13 +01:00
int m_nTargetModelIndex;
CEntity *m_pDoor1;
CEntity *m_pDoor2;
2020-03-28 13:24:13 +01:00
uint8 m_bDoor1PoolIndex;
uint8 m_bDoor2PoolIndex;
2020-03-28 21:41:37 +01:00
bool m_bDoor1IsDummy;
bool m_bDoor2IsDummy;
bool m_bRecreateDoorOnNextRefresh;
2020-03-28 13:24:13 +01:00
bool m_bRotatedDoor;
bool m_bCameraFollowsPlayer;
2020-05-11 20:04:35 +02:00
CVector2D m_vecCorner1;
float m_fInfZ;
2020-05-11 00:00:41 +02:00
CVector2D m_vDir1;
CVector2D m_vDir2;
float m_fSupZ;
float m_fDir1Len;
float m_fDir2Len;
float m_fInfX;
float m_fSupX;
float m_fInfY;
float m_fSupY;
2020-01-03 17:48:13 +01: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 13:24:13 +01:00
uint32 m_nTimeToStartAction;
2020-03-30 23:01:03 +02:00
uint8 m_bCollectedCarsState;
2020-01-03 17:48:13 +01:00
CVehicle *m_pTarget;
2020-03-30 23:46:44 +02:00
void* field_96; // unused
2020-03-30 23:01:03 +02:00
CStoredCar m_sStoredCar; // not needed
2020-02-15 12:53:42 +01:00
2020-01-03 17:48:13 +01:00
void OpenThisGarage();
void CloseThisGarage();
2020-02-15 12:53:42 +01:00
bool IsOpen() { return m_eGarageState == GS_OPENED || m_eGarageState == GS_OPENEDCONTAINSCAR; }
bool IsClosed() { return m_eGarageState == GS_FULLYCLOSED; }
2020-03-28 13:24:13 +01:00
bool IsUsed() { return m_eGarageType != GARAGE_NONE; }
void Update();
2020-05-11 20:04:35 +02:00
float GetGarageCenterX() { return (m_fInfX + m_fSupX) / 2; }
float GetGarageCenterY() { return (m_fInfY + m_fSupY) / 2; }
2020-03-30 23:01:03 +02:00
bool IsFar()
2020-03-28 13:24:13 +01:00
{
#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);
float CalcDistToGarageRectangleSquared(float, float);
2020-03-28 18:52:25 +01:00
float CalcSmallestDistToGarageDoorSquared(float, float);
2020-03-28 13:24:13 +01:00
bool IsAnyOtherCarTouchingGarage(CVehicle* pException);
bool IsStaticPlayerCarEntirelyInside();
bool IsPlayerOutsideGarage();
2020-03-28 18:52:25 +01:00
bool IsAnyCarBlockingDoor();
2020-03-28 13:24:13 +01:00
void CenterCarInGarage(CVehicle*);
2020-03-28 18:52:25 +01:00
bool DoesCraigNeedThisCar(int32);
2020-03-29 17:48:57 +02:00
bool MarkThisCarAsCollectedForCraig(int32);
2020-03-28 18:52:25 +01:00
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-03-30 23:46:44 +02:00
2020-05-11 20:04:35 +02:00
bool IsPointInsideGarage(CVector);
bool IsPointInsideGarage(CVector, float);
void ThrowCarsNearDoorOutOfGarage(CVehicle*);
int32 FindMaxNumStoredCarsForGarage() { return Max(NUM_GARAGE_STORED_CARS, m_nMaxStoredCars); }
2020-03-30 23:46:44 +02:00
friend class CGarages;
friend class cAudioManager;
2020-04-02 12:48:01 +02:00
friend class CCamera;
2020-01-03 17:48:13 +01:00
};
2019-05-28 08:39:36 +02:00
class CGarages
{
2020-03-31 23:07:09 +02:00
enum {
2020-05-11 20:04:35 +02:00
MESSAGE_LENGTH = 8,
MAX_NUM_CARS_IN_HIDEOUT_GARAGE = 4
2020-03-31 23:07:09 +02:00
};
static int32 BankVansCollected;
static bool BombsAreFree;
static bool RespraysAreFree;
static int32 CarsCollected;
static int32 CarTypesCollected[TOTAL_COLLECTCARS_GARAGES];
static int32 CrushedCarId;
static uint32 LastTimeHelpMessage;
static int32 MessageNumberInString;
static char MessageIDString[MESSAGE_LENGTH];
static int32 MessageNumberInString2;
static uint32 MessageStartTime;
static uint32 MessageEndTime;
static uint32 NumGarages;
static bool PlayerInGarage;
static int32 PoliceCarsCollected;
static CGarage aGarages[NUM_GARAGES];
2020-05-11 20:04:35 +02:00
static CStoredCar aCarsInSafeHouses[TOTAL_HIDEOUT_GARAGES][MAX_NUM_CARS_IN_HIDEOUT_GARAGE];
static int32 AudioEntity;
static bool bCamShouldBeOutisde;
2020-03-30 23:46:44 +02:00
2019-05-28 08:39:36 +02:00
public:
2020-03-28 13:24:13 +01:00
static void Init(void);
#ifndef PS2
static void Shutdown(void);
#endif
2020-03-30 23:46:44 +02:00
static void Update(void);
2020-03-28 13:24:13 +01:00
2020-05-10 16:54:13 +02:00
static int16 AddOne(float X1, float Y1, float Z1, float X2, float Y2, float X3, float Y3, float Z2, eGarageType type, int32 targetId);
2020-03-30 23:46:44 +02:00
static void ChangeGarageType(int16, eGarageType, int32);
static void PrintMessages(void);
2020-03-30 23:46:44 +02:00
static void TriggerMessage(const char* text, int16, uint16 time, int16);
2019-10-21 23:39:59 +02:00
static void SetTargetCarForMissonGarage(int16, CVehicle*);
static bool HasCarBeenDroppedOffYet(int16);
2019-10-27 10:51:09 +01:00
static void DeActivateGarage(int16);
2020-03-30 23:46:44 +02:00
static void ActivateGarage(int16);
2019-10-27 10:51:09 +01:00
static int32 QueryCarsCollected(int16);
2020-03-30 23:46:44 +02:00
static bool HasImportExportGarageCollectedThisCar(int16, int8);
2020-02-15 12:53:42 +01:00
static bool IsGarageOpen(int16);
static bool IsGarageClosed(int16);
2020-03-30 23:46:44 +02:00
static bool HasThisCarBeenCollected(int16, uint8);
static void OpenGarage(int16 garage) { aGarages[garage].OpenThisGarage(); }
static void CloseGarage(int16 garage) { aGarages[garage].CloseThisGarage(); }
static bool HasResprayHappened(int16);
2020-02-15 12:53:42 +01:00
static void SetGarageDoorToRotate(int16);
static void SetLeaveCameraForThisGarage(int16);
2020-02-16 21:08:54 +01:00
static bool IsThisCarWithinGarageArea(int16, CEntity*);
2020-03-30 23:46:44 +02:00
static bool HasCarBeenCrushed(int32);
2020-03-28 18:52:25 +01:00
static bool IsPointInAGarageCameraZone(CVector);
2020-03-30 23:46:44 +02:00
static bool CameraShouldBeOutside(void);
static void GivePlayerDetonator(void);
static void PlayerArrestedOrDied(void);
2020-04-30 12:48:01 +02:00
static bool IsPointWithinHideOutGarage(Const CVector&);
static bool IsPointWithinAnyGarage(Const CVector&);
2020-03-30 23:46:44 +02:00
static void SetAllDoorsBackToOriginalHeight(void);
static void Save(uint8* buf, uint32* size);
static void Load(uint8* buf, uint32 size);
static bool IsModelIndexADoor(uint32 id);
static void SetFreeBombs(bool bValue) { BombsAreFree = bValue; }
static void SetFreeResprays(bool bValue) { RespraysAreFree = bValue; }
2020-05-11 20:04:35 +02:00
static void SetMaxNumStoredCarsForGarage(int16 garage, uint8 num) { aGarages[garage].m_nMaxStoredCars = num; }
2020-03-28 13:24:13 +01:00
private:
2020-03-30 23:46:44 +02:00
static bool IsCarSprayable(CVehicle*);
2020-03-28 13:24:13 +01:00
static float FindDoorHeightForMI(int32);
2020-03-30 23:46:44 +02:00
static void CloseHideOutGaragesBeforeSave(void);
static int32 CountCarsInHideoutGarage(eGarageType);
static int32 GetBombTypeForGarageType(eGarageType type) { return type - GARAGE_BOMBSHOP1 + 1; }
2020-05-11 20:04:35 +02:00
static int32 GetCarsCollectedIndexForGarageType(eGarageType type)
{
switch (type) {
case GARAGE_COLLECTCARS_1: return 0;
case GARAGE_COLLECTCARS_2: return 1;
case GARAGE_COLLECTCARS_3: return 2;
case GARAGE_COLLECTCARS_4: return 3;
default: assert(0);
}
return 0;
}
static int32 FindSafeHouseIndexForGarageType(eGarageType type)
{
switch (type) {
case GARAGE_HIDEOUT_ONE: return 0;
case GARAGE_HIDEOUT_TWO: return 1;
case GARAGE_HIDEOUT_THREE: return 2;
case GARAGE_HIDEOUT_FOUR: return 3;
case GARAGE_HIDEOUT_FIVE: return 4;
case GARAGE_HIDEOUT_SIX: return 5;
case GARAGE_HIDEOUT_SEVEN: return 6;
case GARAGE_HIDEOUT_EIGHT: return 7;
case GARAGE_HIDEOUT_NINE: return 8;
case GARAGE_HIDEOUT_TEN: return 9;
case GARAGE_HIDEOUT_ELEVEN: return 10;
case GARAGE_HIDEOUT_TWELVE: return 11;
}
return -1;
}
static bool IsThisGarageTypeSafehouse(eGarageType type) { return FindSafeHouseIndexForGarageType(type) >= 0; }
2020-03-30 23:46:44 +02:00
friend class cAudioManager;
2020-09-26 20:10:23 +02:00
friend class CReplay;
2020-03-30 23:46:44 +02:00
friend class CGarage;
2019-05-28 08:39:36 +02:00
};