summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio/AudioManager.cpp12
-rw-r--r--src/audio/DMAudio.h2
-rw-r--r--src/control/Garages.cpp700
-rw-r--r--src/control/Garages.h84
-rw-r--r--src/control/Script.cpp8
-rw-r--r--src/core/Pad.h7
-rw-r--r--src/core/Stats.cpp1
-rw-r--r--src/core/Stats.h1
-rw-r--r--src/core/World.cpp1
-rw-r--r--src/core/World.h1
-rw-r--r--src/core/config.h2
-rw-r--r--src/vehicles/Vehicle.cpp24
-rw-r--r--src/vehicles/Vehicle.h2
13 files changed, 795 insertions, 50 deletions
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp
index 539c9e91..39c03ef6 100644
--- a/src/audio/AudioManager.cpp
+++ b/src/audio/AudioManager.cpp
@@ -3889,7 +3889,7 @@ cAudioManager::ProcessGarages()
CalculateDistance(distCalculated, distSquared); \
m_sQueueSample.m_bVolume = ComputeVolume(60, 80.f, m_sQueueSample.m_fDistance); \
if(m_sQueueSample.m_bVolume) { \
- if(CGarages::Garages[i].m_eGarageType == GARAGE_CRUSHER) { \
+ if(CGarages::aGarages[i].m_eGarageType == GARAGE_CRUSHER) { \
m_sQueueSample.m_nSampleIndex = SFX_COL_CAR_PANEL_2; \
m_sQueueSample.m_nFrequency = 6735; \
} else if(m_asAudioEntities[m_sQueueSample.m_nEntityIndex] \
@@ -3925,20 +3925,20 @@ cAudioManager::ProcessGarages()
}
for(uint32 i = 0; i < CGarages::NumGarages; ++i) {
- if(CGarages::Garages[i].m_eGarageType == GARAGE_NONE) continue;
- entity = CGarages::Garages[i].m_pDoor1;
+ if(CGarages::aGarages[i].m_eGarageType == GARAGE_NONE) continue;
+ entity = CGarages::aGarages[i].m_pDoor1;
if(!entity) continue;
m_sQueueSample.m_vecPos = entity->GetPosition();
distCalculated = false;
distSquared = GetDistanceSquared(&m_sQueueSample.m_vecPos);
if(distSquared < 6400.f) {
- state = CGarages::Garages[i].m_eGarageState;
+ state = CGarages::aGarages[i].m_eGarageState;
if(state == GS_OPENING || state == GS_CLOSING || state == GS_AFTERDROPOFF) {
CalculateDistance(distCalculated, distSquared);
m_sQueueSample.m_bVolume = ComputeVolume(90u, 80.f, m_sQueueSample.m_fDistance);
if(m_sQueueSample.m_bVolume) {
- if(CGarages::Garages[i].m_eGarageType == GARAGE_CRUSHER) {
- if(CGarages::Garages[i].m_eGarageState == GS_AFTERDROPOFF) {
+ if(CGarages::aGarages[i].m_eGarageType == GARAGE_CRUSHER) {
+ if(CGarages::aGarages[i].m_eGarageState == GS_AFTERDROPOFF) {
if(!(m_FrameCounter & 1)) {
LOOP_HELPER
continue;
diff --git a/src/audio/DMAudio.h b/src/audio/DMAudio.h
index 125263f0..41901c0d 100644
--- a/src/audio/DMAudio.h
+++ b/src/audio/DMAudio.h
@@ -65,7 +65,7 @@ enum eSound : int16
SOUND_GARAGE_NO_MONEY = 57,
SOUND_GARAGE_BAD_VEHICLE = 58,
SOUND_GARAGE_OPENING = 59,
- SOUND_3C = 60,
+ SOUND_GARAGE_DENIED = 60,
SOUND_GARAGE_BOMB1_SET = 61,
SOUND_GARAGE_BOMB2_SET = 62,
SOUND_GARAGE_BOMB3_SET = 63,
diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp
index 5ac15377..af443f8e 100644
--- a/src/control/Garages.cpp
+++ b/src/control/Garages.cpp
@@ -1,15 +1,55 @@
#include "common.h"
#include "patcher.h"
-#include "main.h"
-#include "ModelIndices.h"
#include "Garages.h"
-#include "Timer.h"
+#include "main.h"
+
+#include "General.h"
#include "Font.h"
+#include "Hud.h"
#include "Messages.h"
+#include "ModelIndices.h"
+#include "Particle.h"
#include "PlayerPed.h"
+#include "Replay.h"
+#include "Stats.h"
#include "Text.h"
+#include "Timer.h"
+#include "Vehicle.h"
#include "World.h"
+#define CRUSHER_GARAGE_X1 (1135.5f)
+#define CRUSHER_GARAGE_Y1 (7.0f)
+#define CRUSHER_GARAGE_Z1 (-1.0f)
+#define CRUSHER_GARAGE_X2 (1149.5f)
+#define CRUSHER_GARAGE_Y2 (63.7f)
+#define CRUSHER_GARAGE_Z2 (3.5f)
+
+#define ROTATED_DOOR_OPEN_SPEED (0.015f)
+#define ROTATED_DOOR_CLOSE_SPEED (0.02f)
+#define DEFAULT_DOOR_OPEN_SPEED (0.035f)
+#define DEFAULT_DOOR_CLOSE_SPEED (0.04f)
+
+#define BOMB_PRICE 1000
+#define RESPRAY_PRICE 1000
+
+#define DISTANCE_TO_CALL_OFF_CHASE 10.0f
+#define DISTANCE_FOR_MRWHOOP_HACK 4.0f
+#define DISTANCE_TO_ACTIVATE_GARAGE 8.0f
+#define DISTANCE_TO_CLOSE_MISSION_GARAGE 30.0f
+#define DISTANCE_TO_CLOSE_COLLECTCARS_GARAGE 25.0
+
+#define TIME_TO_RESPRAY 2000
+
+#define FREE_RESPRAY_HEALTH_THRESHOLD 970.0f
+#define NUM_PARTICLES_IN_RESPRAY 200
+
+#define KGS_OF_EXPLOSIVES_IN_BOMB 10
+
+#define REWARD_FOR_FIRST_POLICE_CAR 5000
+#define REWARD_FOR_FIRST_BANK_VAN 5000
+#define MAX_POLICE_CARS_TO_COLLECT 10
+#define MAX_BANK_VANS_TO_COLLECT 10
+
int32 &CGarages::BankVansCollected = *(int32 *)0x8F1B34;
bool &CGarages::BombsAreFree = *(bool *)0x95CD7A;
bool &CGarages::RespraysAreFree = *(bool *)0x95CD1D;
@@ -26,13 +66,632 @@ uint32 &CGarages::NumGarages = *(uint32 *)0x8F29F4;
bool &CGarages::PlayerInGarage = *(bool *)0x95CD83;
int32 &CGarages::PoliceCarsCollected = *(int32 *)0x941444;
uint32 &CGarages::GarageToBeTidied = *(uint32 *)0x623570;
+CStoredCar(&CGarages::aCarsInSafeHouse1)[NUM_GARAGE_STORED_CARS] = *(CStoredCar(*)[NUM_GARAGE_STORED_CARS])*(uintptr*)0x6FA210;
+CStoredCar(&CGarages::aCarsInSafeHouse2)[NUM_GARAGE_STORED_CARS] = *(CStoredCar(*)[NUM_GARAGE_STORED_CARS])*(uintptr*)0x6FA300;
+CStoredCar(&CGarages::aCarsInSafeHouse3)[NUM_GARAGE_STORED_CARS] = *(CStoredCar(*)[NUM_GARAGE_STORED_CARS])*(uintptr*)0x6FA3F0;
+int32& CGarages::AudioEntity = *(int32*)0x5ECEA8;
+CGarage(&CGarages::aGarages)[NUM_GARAGES] = *(CGarage(*)[NUM_GARAGES])*(uintptr*)0x72BCD0;
+bool& CGarages::bCamShouldBeOutisde = *(bool*)0x95CDB2;
+
+void CGarages::Init(void)
+{
+ CrushedCarId = -1;
+ NumGarages = 0;
+ MessageEndTime = 0;
+ MessageStartTime = 0;
+ PlayerInGarage = false;
+ BombsAreFree = false;
+ CarsCollected = 0;
+ BankVansCollected = 0;
+ PoliceCarsCollected = 0;
+ for (int i = 0; i < TOTAL_COLLECTCARS_GARAGES; i++)
+ CarTypesCollected[i] = 0;
+ LastTimeHelpMessage = 0;
+ for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++)
+ aCarsInSafeHouse1[i].Init();
+ for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++)
+ aCarsInSafeHouse2[i].Init();
+ for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++)
+ aCarsInSafeHouse3[i].Init();
+ AudioEntity = DMAudio.CreateEntity(AUDIOTYPE_GARAGE, (void*)1);
+ if (AudioEntity >= 0)
+ DMAudio.SetEntityStatus(AudioEntity, 1);
+ AddOne(
+ CRUSHER_GARAGE_X1, CRUSHER_GARAGE_Y1, CRUSHER_GARAGE_Z1,
+ CRUSHER_GARAGE_X2, CRUSHER_GARAGE_Y2, CRUSHER_GARAGE_Z2,
+ GARAGE_CRUSHER, 0);
+}
+
+#ifndef PS2
+void CGarages::Shutdown(void)
+{
+ NumGarages = 0;
+ if (AudioEntity < 0)
+ return;
+ DMAudio.DestroyEntity(AudioEntity);
+ AudioEntity = AEHANDLE_NONE;
+}
+#endif
+
+void CGarages::Update(void)
+{
+ static int GarageToBeTidied = 0;
+#ifndef PS2
+ if (CReplay::IsPlayingBack())
+ return;
+#endif
+ bCamShouldBeOutisde = false;
+ TheCamera.pToGarageWeAreIn = nil;
+ TheCamera.pToGarageWeAreInForHackAvoidFirstPerson = nil;
+ for (int i = 0; i < NUM_GARAGES; i++) {
+ if (aGarages[i].IsUsed())
+ aGarages[i].Update();
+ }
+ if ((CTimer::GetFrameCounter() & 0xF) != 0xC)
+ return;
+ if (++GarageToBeTidied >= 32)
+ GarageToBeTidied = 0;
+ if (!aGarages[GarageToBeTidied].IsUsed())
+ return;
+ if (aGarages[GarageToBeTidied].IsClose())
+ aGarages[GarageToBeTidied].TidyUpGarageClose();
+ else
+ aGarages[GarageToBeTidied].TidyUpGarage();
+}
+
+int16 CGarages::AddOne(float X1, float Y1, float Z1, float X2, float Y2, float Z2, eGarageType type, int32 targetId)
+{
+ if (NumGarages >= NUM_GARAGES) {
+ assert(0);
+ return NumGarages++;
+ }
+ CGarage* pGarage = &aGarages[NumGarages];
+ pGarage->m_fX1 = min(X1, X2);
+ pGarage->m_fX2 = max(X1, X2);
+ pGarage->m_fY1 = min(Y1, Y2);
+ pGarage->m_fY2 = max(Y1, Y2);
+ pGarage->m_fZ1 = min(Z1, Z2);
+ pGarage->m_fZ2 = max(Z1, Z2);
+ pGarage->m_pDoor1 = nil;
+ pGarage->m_pDoor2 = nil;
+ pGarage->m_fDoor1Z = Z1;
+ pGarage->m_fDoor2Z = Z1;
+ pGarage->m_eGarageType = type;
+ pGarage->field_24 = 0;
+ pGarage->m_bRotatedDoor = false;
+ pGarage->m_bCameraFollowsPlayer = false;
+ pGarage->RefreshDoorPointers(true);
+ if (pGarage->m_pDoor1) {
+ pGarage->m_fDoor1Z = pGarage->m_pDoor1->GetPosition().z;
+ pGarage->m_fDoor1X = pGarage->m_pDoor1->GetPosition().x;
+ pGarage->m_fDoor1Y = pGarage->m_pDoor1->GetPosition().y;
+ }
+ if (pGarage->m_pDoor2) {
+ pGarage->m_fDoor2Z = pGarage->m_pDoor2->GetPosition().z;
+ pGarage->m_fDoor2X = pGarage->m_pDoor2->GetPosition().x;
+ pGarage->m_fDoor2Y = pGarage->m_pDoor2->GetPosition().y;
+ }
+ pGarage->m_fDoorHeight = pGarage->m_pDoor1 ? FindDoorHeightForMI(pGarage->m_pDoor1->GetModelIndex()) : 4.0f;
+ pGarage->m_fDoorPos = 0.0f;
+ pGarage->m_eGarageState = GS_FULLYCLOSED;
+ pGarage->m_nTimeToStartAction = 0;
+ pGarage->field_2 = 0;
+ pGarage->m_nTargetModelIndex = targetId;
+ pGarage->field_96 = 0;
+ pGarage->m_bCollectedCarsState = 0;
+ pGarage->m_bDeactivated = false;
+ pGarage->m_bResprayHappened = false;
+ switch (type) {
+ case GARAGE_MISSION:
+ case GARAGE_COLLECTORSITEMS:
+ case GARAGE_COLLECTSPECIFICCARS:
+ case GARAGE_COLLECTCARS_1:
+ case GARAGE_COLLECTCARS_2:
+ case GARAGE_COLLECTCARS_3:
+ case GARAGE_FORCARTOCOMEOUTOF:
+ case GARAGE_60SECONDS:
+ case GARAGE_MISSION_KEEPCAR:
+ case GARAGE_FOR_SCRIPT_TO_OPEN:
+ case GARAGE_HIDEOUT_ONE:
+ case GARAGE_HIDEOUT_TWO:
+ case GARAGE_HIDEOUT_THREE:
+ case GARAGE_FOR_SCRIPT_TO_OPEN_AND_CLOSE:
+ case GARAGE_KEEPS_OPENING_FOR_SPECIFIC_CAR:
+ case GARAGE_MISSION_KEEPCAR_REMAINCLOSED:
+ pGarage->m_eGarageState = GS_FULLYCLOSED;
+ pGarage->m_fDoorPos = 0.0f;
+ break;
+ case GARAGE_BOMBSHOP1:
+ case GARAGE_BOMBSHOP2:
+ case GARAGE_BOMBSHOP3:
+ case GARAGE_RESPRAY:
+ pGarage->m_eGarageState = GS_OPENED;
+ pGarage->m_fDoorPos = pGarage->m_fDoorHeight;
+ break;
+ case GARAGE_CRUSHER:
+ pGarage->m_eGarageState = GS_OPENED;
+ pGarage->m_fDoorPos = HALFPI;
+ break;
+ default:
+ assert(false);
+ }
+ if (type == GARAGE_CRUSHER)
+ pGarage->UpdateCrusherAngle();
+ else
+ pGarage->UpdateDoorsHeight();
+ return NumGarages++;
+}
+
+void CGarages::ChangeGarageType(int16 garage, eGarageType type, int32 mi)
+{
+ CGarage* pGarage = &aGarages[garage];
+ pGarage->m_eGarageType = type;
+ pGarage->m_nTargetModelIndex = mi;
+ pGarage->m_eGarageState = GS_FULLYCLOSED;
+}
-CGarage(&CGarages::Garages)[NUM_GARAGES] = *(CGarage(*)[NUM_GARAGES])*(uintptr*)0x72BCD0;
+void CGarage::Update()
+{
+ if (m_eGarageType != GARAGE_CRUSHER) {
+ switch (m_eGarageState) {
+ case GS_FULLYCLOSED:
+ case GS_OPENED:
+ case GS_CLOSING:
+ case GS_OPENING:
+ case GS_OPENEDCONTAINSCAR:
+ case GS_CLOSEDCONTAINSCAR:
+ if (FindPlayerPed() && !m_bCameraFollowsPlayer) {
+ CVehicle* pVehicle = FindPlayerVehicle();
+ if (IsEntityEntirelyInside3D(FindPlayerPed(), 0.25f)) {
+ TheCamera.pToGarageWeAreIn = this;
+ CGarages::bCamShouldBeOutisde = true;
+ }
+ if (pVehicle && IsEntityEntirelyOutside(pVehicle, 0.0f))
+ TheCamera.pToGarageWeAreInForHackAvoidFirstPerson = this;
+ if (pVehicle->GetModelIndex() == MI_MRWHOOP) {
+ if (pVehicle->IsWithinArea(
+ m_fX1 - DISTANCE_FOR_MRWHOOP_HACK,
+ m_fX2 + DISTANCE_FOR_MRWHOOP_HACK,
+ m_fY1 - DISTANCE_FOR_MRWHOOP_HACK,
+ m_fY2 + DISTANCE_FOR_MRWHOOP_HACK)) {
+ TheCamera.pToGarageWeAreIn = this;
+ CGarages::bCamShouldBeOutisde = true;
+ }
+ }
+ }
+ }
+ }
+ if (m_bDeactivated && m_eGarageState == GS_FULLYCLOSED)
+ return;
+ switch (m_eGarageType) {
+ case GARAGE_RESPRAY:
+ switch (m_eGarageState) {
+ case GS_OPENED:
+ if (IsStaticPlayerCarEntirelyInside() && !IsAnyOtherCarTouchingGarage(FindPlayerVehicle())) {
+ if (IsCarSprayable()) {
+ if (CWorld::Players[CWorld::PlayerInFocus].m_nMoney >= RESPRAY_PRICE || CGarages::RespraysAreFree) {
+ m_eGarageState = GS_CLOSING;
+ CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = true;
+ } else {
+ CGarages::TriggerMessage("GA_3", -1, 4000, -1); // No more freebies. $1000 to respray!
+ m_eGarageState = GS_OPENEDCONTAINSCAR;
+ DMAudio.PlayFrontEndSound(SOUND_GARAGE_NO_MONEY, 1);
+ }
+ } else {
+ CGarages::TriggerMessage("GA_1", -1, 4000, -1); // Whoa! I don't touch nothing THAT hot!
+ m_eGarageState = GS_OPENEDCONTAINSCAR;
+ DMAudio.PlayFrontEndSound(SOUND_GARAGE_BAD_VEHICLE, 1);
+ }
+ }
+ if (FindPlayerVehicle()) {
+ if (CalcDistToGarageRectangleSquared(FindPlayerVehicle()->GetPosition().x, FindPlayerVehicle()->GetPosition().y) < SQR(DISTANCE_TO_ACTIVATE_GARAGE))
+ CWorld::CallOffChaseForArea(
+ m_fX1 - DISTANCE_TO_CALL_OFF_CHASE,
+ m_fY1 - DISTANCE_TO_CALL_OFF_CHASE,
+ m_fX2 + DISTANCE_TO_CALL_OFF_CHASE,
+ m_fY2 + DISTANCE_TO_CALL_OFF_CHASE);
+ }
+ break;
+ case GS_CLOSING:
+ m_fDoorPos = max(0.0f, m_fDoorPos - m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : ROTATED_DOOR_CLOSE_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == 0.0f) {
+ m_eGarageState = GS_FULLYCLOSED;
+ m_nTimeToStartAction = CTimer::GetTimeInMilliseconds() + TIME_TO_RESPRAY;
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f);
+ CStats::CheckPointReachedSuccessfully();
+ }
+ UpdateDoorsHeight();
+#ifdef FIX_BUGS
+ if (FindPlayerVehicle() && FindPlayerVehicle()->IsCar())
+#else
+ if (FindPlayerVehicle())
+#endif
+ ((CAutomobile*)(FindPlayerVehicle()))->m_fFireBlowUpTimer = 0.0f;
+ CWorld::CallOffChaseForArea(
+ m_fX1 - DISTANCE_TO_CALL_OFF_CHASE,
+ m_fY1 - DISTANCE_TO_CALL_OFF_CHASE,
+ m_fX2 + DISTANCE_TO_CALL_OFF_CHASE,
+ m_fY2 + DISTANCE_TO_CALL_OFF_CHASE);
+ break;
+ case GS_FULLYCLOSED:
+ if (CTimer::GetTimeInMilliseconds() > m_nTimeToStartAction) {
+ m_eGarageState = GS_OPENING;
+ DMAudio.PlayFrontEndSound(SOUND_GARAGE_OPENING, 1);
+ bool bTakeMoney = false;
+ if (FindPlayerPed()->m_pWanted->m_nWantedLevel != 0)
+ bTakeMoney = true;
+ FindPlayerPed()->m_pWanted->Reset();
+ CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = true;
+#ifdef FIX_BUGS
+ bool bChangedColour = false;
+#else
+ bool bChangedColour;
+#endif
+ if (FindPlayerVehicle() && FindPlayerVehicle()->IsCar()) {
+ if (FindPlayerVehicle()->m_fHealth < FREE_RESPRAY_HEALTH_THRESHOLD)
+ bTakeMoney = true;
+ FindPlayerVehicle()->m_fHealth = 1000.0f;
+ ((CAutomobile*)(FindPlayerVehicle()))->m_fFireBlowUpTimer = 0.0f;
+ ((CAutomobile*)(FindPlayerVehicle()))->Fix();
+ if (FindPlayerVehicle()->GetUp().z < 0.0f) {
+ FindPlayerVehicle()->GetUp() = -FindPlayerVehicle()->GetUp();
+ FindPlayerVehicle()->GetRight() = -FindPlayerVehicle()->GetRight();
+ }
+ bChangedColour = false;
+ if (!((CAutomobile*)(FindPlayerVehicle()))->bFixedColour) {
+ uint8 colour1, colour2;
+ uint16 attempt;
+ ((CVehicleModelInfo*)CModelInfo::GetModelInfo(FindPlayerVehicle()->GetModelIndex()))->ChooseVehicleColour(colour1, colour2);
+ for (attempt = 0; attempt < 10; attempt++) {
+ if (colour1 != FindPlayerVehicle()->m_currentColour1 || colour2 != FindPlayerVehicle()->m_currentColour2)
+ break;
+ ((CVehicleModelInfo*)CModelInfo::GetModelInfo(FindPlayerVehicle()->GetModelIndex()))->ChooseVehicleColour(colour1, colour2);
+ }
+ bChangedColour = (attempt < 10);
+ FindPlayerVehicle()->m_currentColour1 = colour1;
+ FindPlayerVehicle()->m_currentColour2 = colour2;
+ if (bChangedColour) {
+ for (int i = 0; i < NUM_PARTICLES_IN_RESPRAY; i++) {
+ CVector pos;
+#ifdef FIX_BUGS
+ pos.x = CGeneral::GetRandomNumberInRange(m_fX1 + 0.5f, m_fX2 - 0.5f);
+ pos.y = CGeneral::GetRandomNumberInRange(m_fY1 + 0.5f, m_fY2 - 0.5f);
+ pos.z = CGeneral::GetRandomNumberInRange(m_fDoor1Z - 3.0f, m_fDoor1Z + 1.0f);
+#else
+ // wtf is this
+ pos.x = m_fX1 + 0.5f + (uint8)(CGeneral::GetRandomNumber()) / 256.0f * (m_fX2 - m_fX1 - 1.0f);
+ pos.y = m_fY1 + 0.5f + (uint8)(CGeneral::GetRandomNumber()) / 256.0f * (m_fY2 - m_fY1 - 1.0f);
+ pos.z = m_fDoor1Z - 3.0f + (uint8)(CGeneral::GetRandomNumber()) / 256.0f * 4.0f;
+#endif
+ CParticle::AddParticle(PARTICLE_GARAGEPAINT_SPRAY, pos, CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, CVehicleModelInfo::ms_vehicleColourTable[colour1]);
+ }
+ }
+ }
+ CenterCarInGarage(FindPlayerVehicle());
+ }
+ if (bTakeMoney) {
+ if (!CGarages::RespraysAreFree)
+ CWorld::Players[CWorld::PlayerInFocus].m_nMoney = max(0, CWorld::Players[CWorld::PlayerInFocus].m_nMoney - RESPRAY_PRICE);
+ CGarages::TriggerMessage("GA_2", -1, 4000, -1); // New engine and paint job. The cops won't recognize you!
+ }
+ else if (bChangedColour) {
+ if (CGeneral::GetRandomTrueFalse())
+ CGarages::TriggerMessage("GA_15", -1, 4000, -1); // Hope you like the new color.
+ else
+ CGarages::TriggerMessage("GA_16", -1, 4000, -1); // Respray is complementary.
+ }
+ m_bResprayHappened = true;
+ }
+ CWorld::CallOffChaseForArea(
+ m_fX1 - DISTANCE_TO_CALL_OFF_CHASE,
+ m_fY1 - DISTANCE_TO_CALL_OFF_CHASE,
+ m_fX2 + DISTANCE_TO_CALL_OFF_CHASE,
+ m_fY2 + DISTANCE_TO_CALL_OFF_CHASE);
+ break;
+ case GS_OPENING:
+ m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : ROTATED_DOOR_OPEN_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == m_fDoorHeight) {
+ m_eGarageState = GS_OPENED;
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f);
+ }
+ UpdateDoorsHeight();
+ break;
+ case GS_OPENEDCONTAINSCAR:
+ if (IsPlayerOutsideGarage())
+ m_eGarageState = GS_OPENED;
+ break;
+ //case GS_CLOSEDCONTAINSCAR:
+ //case GS_AFTERDROPOFF:
+ default:
+ }
+ break;
+ case GARAGE_BOMBSHOP1:
+ case GARAGE_BOMBSHOP2:
+ case GARAGE_BOMBSHOP3:
+ switch (m_eGarageState) {
+ case GS_OPENED:
+ if (IsStaticPlayerCarEntirelyInside() && !IsAnyOtherCarTouchingGarage(FindPlayerVehicle())) {
+#ifdef FIX_BUGS // FindPlayerVehicle() can never be NULL here because IsStaticPlayerCarEntirelyInside() is true, and there is no IsCar() check
+ if (FindPlayerVehicle()->IsCar() && ((CAutomobile*)FindPlayerVehicle())->m_bombType) {
+#else
+ if (!FindPlayerVehicle() || ((CAutomobile*)FindPlayerVehicle())->m_bombType) {
+#endif
+ CGarages::TriggerMessage("GA_5", -1, 4000, -1); //"Your car is already fitted with a bomb"
+ m_eGarageState = GS_OPENEDCONTAINSCAR;
+ DMAudio.PlayFrontEndSound(SOUND_GARAGE_DENIED, 1);
+ break;
+ }
+ if (!CGarages::BombsAreFree && CWorld::Players[CWorld::PlayerInFocus].m_nMoney >= BOMB_PRICE) {
+ CGarages::TriggerMessage("GA_4", -1, 4000, -1); // "Car bombs are $1000 each"
+ m_eGarageState = GS_OPENEDCONTAINSCAR;
+ DMAudio.PlayFrontEndSound(SOUND_GARAGE_NO_MONEY, 1);
+ break;
+ }
+ m_eGarageState = GS_CLOSING;
+ CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = true;
+ }
+ break;
+ case GS_CLOSING:
+ m_fDoorPos = max(0.0f, m_fDoorPos - m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : ROTATED_DOOR_CLOSE_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == 0.0f) {
+ m_eGarageState = GS_FULLYCLOSED;
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f);
+ }
+ UpdateDoorsHeight();
+ break;
+ case GS_FULLYCLOSED:
+ if (CTimer::GetTimeInMilliseconds() > m_nTimeToStartAction) {
+ switch (m_eGarageType) {
+ case GARAGE_BOMBSHOP1: DMAudio.PlayFrontEndSound(SOUND_GARAGE_BOMB1_SET, 1); break;
+ case GARAGE_BOMBSHOP2: DMAudio.PlayFrontEndSound(SOUND_GARAGE_BOMB2_SET, 1); break;
+ case GARAGE_BOMBSHOP3: DMAudio.PlayFrontEndSound(SOUND_GARAGE_BOMB3_SET, 1); break;
+ }
+ m_eGarageState = GS_OPENING;
+ if (!CGarages::BombsAreFree)
+ CWorld::Players[CWorld::PlayerInFocus].m_nMoney = max(0, CWorld::Players[CWorld::PlayerInFocus].m_nMoney - BOMB_PRICE);
+ if (FindPlayerVehicle() && FindPlayerVehicle()->IsCar()) {
+ ((CAutomobile*)(FindPlayerVehicle()))->m_bombType = CGarages::GetBombTypeForGarageType(m_eGarageType);
+ ((CAutomobile*)(FindPlayerVehicle()))->m_pBombRigger = FindPlayerPed();
+ if (m_eGarageType == GARAGE_BOMBSHOP3)
+ CGarages::GivePlayerDetonator();
+ CStats::KgOfExplosivesUsed += KGS_OF_EXPLOSIVES_IN_BOMB;
+ }
+ switch (m_eGarageType) {
+ case GARAGE_BOMBSHOP1:
+ switch (CPad::GetPad(0)->Mode) {
+ case 0:
+ case 1:
+ case 2:
+ CHud::SetHelpMessage(TheText.Get("GA_6"), false); // Arm with ~h~~k~~PED_FIREWEAPON~ button~w~. Bomb will go off when engine is started.
+ break;
+ case 3:
+ CHud::SetHelpMessage(TheText.Get("GA_6B"), false); // Arm with ~h~~k~~PED_FIREWEAPON~ button~w~. Bomb will go off when engine is started.
+ break;
+ }
+ break;
+ case GARAGE_BOMBSHOP2:
+ switch (CPad::GetPad(0)->Mode) {
+ case 0:
+ case 1:
+ case 2:
+ CHud::SetHelpMessage(TheText.Get("GA_7"), false); // Park it, prime it by pressing the ~h~~k~~PED_FIREWEAPON~ button~w~ and LEG IT!
+ break;
+ case 3:
+ CHud::SetHelpMessage(TheText.Get("GA_7B"), false); // Park it, prime it by pressing the ~h~~k~~PED_FIREWEAPON~ button~w~ and LEG IT!
+ break;
+ }
+ break;
+ case GARAGE_BOMBSHOP3:
+ CHud::SetHelpMessage(TheText.Get("GA_8"), false); // Use the detonator to activate the bomb.
+ break;
+ }
+ CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = false;
+ break;
+ }
+ case GS_OPENING:
+ m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : ROTATED_DOOR_OPEN_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == m_fDoorHeight) {
+ m_eGarageState = GS_OPENED;
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f);
+ }
+ UpdateDoorsHeight();
+ break;
+ case GS_OPENEDCONTAINSCAR:
+ if (IsPlayerOutsideGarage())
+ m_eGarageState = GS_OPENED;
+ break;
+ //case GS_CLOSEDCONTAINSCAR:
+ //case GS_AFTERDROPOFF:
+ default:
+ break;
+ }
+ break;
+ case GARAGE_MISSION:
+ switch (m_eGarageState) {
+ case GS_OPENED:
+ if (((CVector2D)FindPlayerCoors() - CVector2D(GetGarageCenterX(), GetGarageCenterY())).MagnitudeSqr() > SQR(DISTANCE_TO_CLOSE_MISSION_GARAGE)) {
+ if (!FindPlayerVehicle() && m_pTarget && IsEntityEntirelyInside3D(m_pTarget, 0.0f) && !IsAnyOtherCarTouchingGarage(m_pTarget)) {
+ CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = true;
+ m_eGarageState = GS_CLOSING;
+ m_bClosingWithoutTargetCar = false;
+ }
+ }
+ else if ((CTimer::GetFrameCounter() & 0x1F) == 0 && IsAnyOtherCarTouchingGarage(nil)) {
+ m_eGarageState = GS_CLOSING;
+ m_bClosingWithoutTargetCar = true;
+ }
+ break;
+ case GS_CLOSING:
+ m_fDoorPos = max(0.0f, m_fDoorPos - m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : ROTATED_DOOR_CLOSE_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == 0.0f) {
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f);
+ if (m_bClosingWithoutTargetCar)
+ m_eGarageState = GS_FULLYCLOSED;
+ else {
+ if (m_pTarget) {
+ m_eGarageState = GS_CLOSEDCONTAINSCAR;
+ DestroyVehicleAndDriverAndPassengers(m_pTarget);
+ m_pTarget = nil;
+ }
+ else {
+ m_eGarageState = GS_FULLYCLOSED;
+ }
+ CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = false;
+ }
+ }
+ UpdateDoorsHeight();
+ break;
+ case GS_FULLYCLOSED:
+ if (FindPlayerVehicle() == m_pTarget && m_pTarget) {
+ if (CalcDistToGarageRectangleSquared(
+ FindPlayerVehicle()->GetPosition().x,
+ FindPlayerVehicle()->GetPosition().y) < SQR(DISTANCE_TO_ACTIVATE_GARAGE))
+ m_eGarageState = GS_OPENING;
+ }
+ break;
+ case GS_OPENING:
+ m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : ROTATED_DOOR_OPEN_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == m_fDoorHeight) {
+ m_eGarageState = GS_OPENED;
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f);
+ }
+ UpdateDoorsHeight();
+ break;
+ //case GS_OPENEDCONTAINSCAR:
+ //case GS_CLOSEDCONTAINSCAR:
+ //case GS_AFTERDROPOFF:
+ default:
+ break;
+ }
+ break;
+ case GARAGE_COLLECTSPECIFICCARS:
+ switch (m_eGarageState) {
+ case GS_OPENED:
+ if (FindPlayerVehicle() && m_nTargetModelIndex == FindPlayerVehicle()->GetModelIndex()) {
+ m_pTarget = FindPlayerVehicle();
+ m_pTarget->RegisterReference((CEntity**)&m_pTarget);
+ }
+ if (!FindPlayerVehicle()) {
+ if (m_pTarget && IsEntityEntirelyInside3D(m_pTarget, 0.0f) && !IsAnyOtherCarTouchingGarage(m_pTarget)) {
+ if (IsEntityEntirelyOutside(FindPlayerPed(), 2.0f)) {
+ CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = true;
+ m_eGarageState = GS_CLOSING;
+ }
+ }
+ else if (Abs(FindPlayerCoors().x - GetGarageCenterX()) > DISTANCE_TO_CLOSE_COLLECTCARS_GARAGE ||
+ Abs(FindPlayerCoors().y - GetGarageCenterY()) > DISTANCE_TO_CLOSE_COLLECTCARS_GARAGE) {
+ m_eGarageState = GS_CLOSING;
+ m_pTarget = nil;
+ }
+ }
+ break;
+ case GS_CLOSING:
+ m_fDoorPos = max(0.0f, m_fDoorPos - m_bRotatedDoor ? ROTATED_DOOR_CLOSE_SPEED : ROTATED_DOOR_CLOSE_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == 0.0f) {
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_CLOSED, 1.0f);
+ if (m_pTarget) {
+ DestroyVehicleAndDriverAndPassengers(m_pTarget);
+ m_pTarget = nil;
+ CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_GARAGE);
+ FindPlayerPed()->m_pWanted->m_bIgnoredByCops = false;
+ int16 reward;
+ switch (m_nTargetModelIndex) {
+ case MI_POLICE:
+ reward = REWARD_FOR_FIRST_POLICE_CAR * (MAX_POLICE_CARS_TO_COLLECT - CGarages::PoliceCarsCollected++) / MAX_POLICE_CARS_TO_COLLECT;
+ break;
+ case MI_SECURICA:
+ reward = REWARD_FOR_FIRST_BANK_VAN * (MAX_BANK_VANS_TO_COLLECT - CGarages::BankVansCollected++) / MAX_BANK_VANS_TO_COLLECT;
+ break;
+#ifdef FIX_BUGS // not possible though
+ default:
+ reward = 0;
+ break;
+#endif
+ }
+ if (reward > 0) {
+ CWorld::Players[CWorld::PlayerInFocus].m_nMoney += reward;
+ CGarages::TriggerMessage("GA_10", reward, 4000, -1); // Nice one. Here's your $~1~
+ DMAudio.PlayFrontEndSound(SOUND_GARAGE_VEHICLE_ACCEPTED, 1);
+ }
+ else {
+ CGarages::TriggerMessage("GA_11", -1, 4000, -1); // We got these wheels already. It's worthless to us!
+ DMAudio.PlayFrontEndSound(SOUND_GARAGE_VEHICLE_DECLINED, 1);
+ }
+ }
+ }
+ UpdateDoorsHeight();
+ break;
+ case GS_FULLYCLOSED:
+ if (FindPlayerVehicle() && m_nTargetModelIndex == FindPlayerVehicle()->GetModelIndex()) {
+ if (CalcDistToGarageRectangleSquared(FindPlayerVehicle()->GetPosition().x, FindPlayerVehicle()->GetPosition().y) < SQR(DISTANCE_TO_ACTIVATE_GARAGE))
+ m_eGarageState = GS_OPENING;
+ }
+ break;
+ case GS_OPENING:
+ if (FindPlayerVehicle() && m_nTargetModelIndex == FindPlayerVehicle()->GetModelIndex()) {
+ m_pTarget = FindPlayerVehicle();
+ m_pTarget->RegisterReference((CEntity**)&m_pTarget);
+ }
+ m_fDoorPos = min(m_fDoorHeight, m_fDoorPos + m_bRotatedDoor ? ROTATED_DOOR_OPEN_SPEED : ROTATED_DOOR_OPEN_SPEED * CTimer::GetTimeStep());
+ if (m_fDoorPos == m_fDoorHeight) {
+ m_eGarageState = GS_OPENED;
+ DMAudio.PlayOneShot(CGarages::AudioEntity, SOUND_GARAGE_DOOR_OPENED, 1.0f);
+ }
+ break;
+ //case GS_OPENEDCONTAINSCAR:
+ //case GS_CLOSEDCONTAINSCAR:
+ //case GS_AFTERDROPOFF:
+ default:
+ }
+ break;
+ case GARAGE_COLLECTORSITEMS:
+ case GARAGE_COLLECTCARS_1:
+ case GARAGE_COLLECTCARS_2:
+ case GARAGE_COLLECTCARS_3:
+ case GARAGE_FORCARTOCOMEOUTOF:
+ case GARAGE_60SECONDS:
+ case GARAGE_CRUSHER:
+ case GARAGE_MISSION_KEEPCAR:
+ case GARAGE_FOR_SCRIPT_TO_OPEN:
+ case GARAGE_HIDEOUT_ONE:
+ case GARAGE_HIDEOUT_TWO:
+ case GARAGE_HIDEOUT_THREE:
+ case GARAGE_FOR_SCRIPT_TO_OPEN_AND_CLOSE:
+ case GARAGE_KEEPS_OPENING_FOR_SPECIFIC_CAR:
+ case GARAGE_MISSION_KEEPCAR_REMAINCLOSED:
+ switch (m_eGarageState) {
+ case GS_FULLYCLOSED:
+ case GS_OPENING:
+ case GS_OPENED:
+ case GS_CLOSING:
+ case GS_OPENEDCONTAINSCAR:
+ case GS_CLOSEDCONTAINSCAR:
+ case GS_AFTERDROPOFF:
+ default:
+ }
+ break;
+ default:
+ break;
+ }
+
+}
-WRAPPER void CGarages::Init(void) { EAXJMP(0x421C60); }
-WRAPPER void CGarages::Update(void) { EAXJMP(0x421E40); }
WRAPPER void CGarages::Load(uint8* buf, uint32 size) { EAXJMP(0x428940); }
-WRAPPER void CGarages::Save(uint8* buf, uint32 *size) { EAXJMP(0x4284e0); }
+WRAPPER void CGarages::Save(uint8* buf, uint32 *size) { EAXJMP(0x4284E0); }
+
+WRAPPER void CGarage::TidyUpGarageClose() { EAXJMP(0x427D90); }
+WRAPPER void CGarage::TidyUpGarage() { EAXJMP(0x427C30); }
+WRAPPER void CGarage::RefreshDoorPointers(bool) { EAXJMP(0x426980); }
+WRAPPER void CGarage::UpdateCrusherAngle() { EAXJMP(0x4268A0); }
+WRAPPER void CGarage::UpdateDoorsHeight() { EAXJMP(0x426730); }
+WRAPPER float CGarages::FindDoorHeightForMI(int32) { EAXJMP(0x427C10); }
bool
CGarages::IsModelIndexADoor(uint32 id)
@@ -81,7 +740,6 @@ WRAPPER void CGarages::TriggerMessage(const char *text, int16, uint16 time, int1
WRAPPER bool CGarages::IsPointWithinHideOutGarage(CVector&) { EAXJMP(0x428260); }
WRAPPER bool CGarages::IsPointWithinAnyGarage(CVector&) { EAXJMP(0x428320); }
WRAPPER void CGarages::PlayerArrestedOrDied() { EAXJMP(0x427F60); }
-WRAPPER int16 CGarages::AddOne(float, float, float, float, float, float, uint8, uint32) { EAXJMP(0x421FA0); }
WRAPPER void CGarages::SetTargetCarForMissonGarage(int16, CVehicle*) { EAXJMP(0x426BD0); }
WRAPPER bool CGarages::HasCarBeenDroppedOffYet(int16) { EAXJMP(0x426C20); }
WRAPPER void CGarages::DeActivateGarage(int16) { EAXJMP(0x426C40); }
@@ -99,7 +757,6 @@ void CGarages::GivePlayerDetonator()
}
WRAPPER bool CGarages::HasThisCarBeenCollected(int16 garage, uint8 id) { EAXJMP(0x426D50); }
-WRAPPER void CGarages::ChangeGarageType(int16 garage, eGarageType type, int32 mi) { EAXJMP(0x4222A0); }
WRAPPER bool CGarages::HasResprayHappened(int16 garage) { EAXJMP(0x4274F0); }
WRAPPER bool CGarages::IsThisCarWithinGarageArea(int16 garage, CEntity* pCar) { EAXJMP(0x427570); }
@@ -111,12 +768,12 @@ void CGarage::OpenThisGarage()
bool CGarages::IsGarageOpen(int16 garage)
{
- return Garages[garage].IsOpen();
+ return aGarages[garage].IsOpen();
}
bool CGarages::IsGarageClosed(int16 garage)
{
- return Garages[garage].IsClosed();
+ return aGarages[garage].IsClosed();
}
void CGarage::CloseThisGarage()
@@ -127,21 +784,21 @@ void CGarage::CloseThisGarage()
void CGarages::SetGarageDoorToRotate(int16 garage)
{
- if (Garages[garage].m_bRotatedDoor)
+ if (aGarages[garage].m_bRotatedDoor)
return;
- Garages[garage].m_bRotatedDoor = true;
- Garages[garage].m_fDoorHeight /= 2.0f;
- Garages[garage].m_fDoorHeight -= 0.1f;
+ aGarages[garage].m_bRotatedDoor = true;
+ aGarages[garage].m_fDoorHeight /= 2.0f;
+ aGarages[garage].m_fDoorHeight -= 0.1f;
}
bool CGarages::HasImportExportGarageCollectedThisCar(int16 garage, int8 car)
{
- return CarTypesCollected[GetCarsCollectedIndexForGarageType(Garages[garage].m_eGarageType)] & (1 << car);
+ return CarTypesCollected[GetCarsCollectedIndexForGarageType(aGarages[garage].m_eGarageType)] & (1 << car);
}
void CGarages::SetLeaveCameraForThisGarage(int16 garage)
{
- Garages[garage].m_bCameraFollowsPlayer = true;
+ aGarages[garage].m_bCameraFollowsPlayer = true;
}
#if 0
@@ -187,4 +844,11 @@ void CGarages::PrintMessages()
}
}
}
-#endif \ No newline at end of file
+#endif
+
+STARTPATCHES
+ InjectHook(0x421C60, CGarages::Init, PATCH_JUMP);
+#ifndef PS2
+ InjectHook(0x421E10, CGarages::Shutdown, PATCH_JUMP);
+#endif
+ENDPATCHES \ No newline at end of file
diff --git a/src/control/Garages.h b/src/control/Garages.h
index 5e106ade..89d51a05 100644
--- a/src/control/Garages.h
+++ b/src/control/Garages.h
@@ -1,6 +1,7 @@
#pragma once
#include "Automobile.h"
#include "audio_enums.h"
+#include "Camera.h"
#include "config.h"
class CVehicle;
@@ -63,34 +64,39 @@ class CStoredCar
int8 m_nVariationA;
int8 m_nVariationB;
int8 m_nCarBombType;
+public:
+ void Init() { m_nModelIndex = 0; }
};
static_assert(sizeof(CStoredCar) == 0x28, "CStoredCar");
+#define SWITCH_GARAGE_DISTANCE_CLOSE 40.0f
+
class CGarage
{
public:
eGarageType m_eGarageType;
eGarageState m_eGarageState;
char field_2;
- char m_bClosingWithoutTargetCar;
- char m_bDeactivated;
- char m_bResprayHappened;
- char field_6;
- char field_7;
+ bool m_bClosingWithoutTargetCar;
+ bool m_bDeactivated;
+ bool m_bResprayHappened;
int m_nTargetModelIndex;
CEntity *m_pDoor1;
CEntity *m_pDoor2;
- char m_bDoor1PoolIndex;
- char m_bDoor2PoolIndex;
- char m_bIsDoor1Object;
- char m_bIsDoor2Object;
+ uint8 m_bDoor1PoolIndex;
+ uint8 m_bDoor2PoolIndex;
+ bool m_bIsDoor1Object;
+ bool m_bIsDoor2Object;
char field_24;
- char m_bRotatedDoor;
- char m_bCameraFollowsPlayer;
- char field_27;
- CVector m_vecInf;
- CVector m_vecSup;
+ bool m_bRotatedDoor;
+ bool m_bCameraFollowsPlayer;
+ float m_fX1;
+ float m_fX2;
+ float m_fY1;
+ float m_fY2;
+ float m_fZ1;
+ float m_fZ2;
float m_fDoorPos;
float m_fDoorHeight;
float m_fDoor1X;
@@ -99,7 +105,7 @@ public:
float m_fDoor2Y;
float m_fDoor1Z;
float m_fDoor2Z;
- int m_nDoorOpenTime;
+ uint32 m_nTimeToStartAction;
char m_bCollectedCarsState;
char field_89;
char field_90;
@@ -112,6 +118,33 @@ public:
void CloseThisGarage();
bool IsOpen() { return m_eGarageState == GS_OPENED || m_eGarageState == GS_OPENEDCONTAINSCAR; }
bool IsClosed() { return m_eGarageState == GS_FULLYCLOSED; }
+ 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);
+ float CalcDistToGarageRectangleSquared(float, float);
+ bool IsAnyOtherCarTouchingGarage(CVehicle* pException);
+ bool IsStaticPlayerCarEntirelyInside();
+ bool IsPlayerOutsideGarage();
+ bool IsCarSprayable();
+ void CenterCarInGarage(CVehicle*);
};
static_assert(sizeof(CGarage) == 140, "CGarage");
@@ -135,9 +168,19 @@ public:
static bool &PlayerInGarage;
static int32 &PoliceCarsCollected;
static uint32 &GarageToBeTidied;
- static CGarage(&Garages)[NUM_GARAGES];
-
+ 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;
public:
+ 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);
+
static bool IsModelIndexADoor(uint32 id);
static void TriggerMessage(const char *text, int16, uint16 time, int16);
static void PrintMessages(void);
@@ -145,11 +188,10 @@ public:
static bool IsPointWithinHideOutGarage(CVector&);
static bool IsPointWithinAnyGarage(CVector&);
static void PlayerArrestedOrDied();
- static void Init(void);
+
static void Update(void);
static void Load(uint8 *buf, uint32 size);
static void Save(uint8 *buf, uint32 *size);
- static int16 AddOne(float, float, float, float, float, float, uint8, uint32);
static void SetTargetCarForMissonGarage(int16, CVehicle*);
static bool HasCarBeenDroppedOffYet(int16);
static void ActivateGarage(int16);
@@ -166,5 +208,9 @@ public:
static void SetLeaveCameraForThisGarage(int16);
static bool IsThisCarWithinGarageArea(int16, CEntity*);
+ static int GetBombTypeForGarageType(eGarageType type) { return type - GARAGE_BOMBSHOP1 + 1; }
static int GetCarsCollectedIndexForGarageType(eGarageType type) { return type - GARAGE_COLLECTCARS_1; }
+
+private:
+ static float FindDoorHeightForMI(int32);
};
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index 4aeacf3f..42b75554 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -4629,7 +4629,7 @@ int8 CRunningScript::ProcessCommands500To599(int32 command)
infZ = *(float*)&ScriptParams[5];
supZ = *(float*)&ScriptParams[2];
}
- ScriptParams[0] = CGarages::AddOne(infX, infY, infZ, supX, supY, supZ, ScriptParams[6], 0);
+ ScriptParams[0] = CGarages::AddOne(infX, infY, infZ, supX, supY, supZ, (eGarageType)ScriptParams[6], 0);
StoreParameters(&m_nIp, 1);
return 0;
}
@@ -4654,7 +4654,7 @@ int8 CRunningScript::ProcessCommands500To599(int32 command)
infZ = *(float*)&ScriptParams[5];
supZ = *(float*)&ScriptParams[2];
}
- ScriptParams[0] = CGarages::AddOne(infX, infY, infZ, supX, supY, supZ, ScriptParams[6], ScriptParams[7]);
+ ScriptParams[0] = CGarages::AddOne(infX, infY, infZ, supX, supY, supZ, (eGarageType)ScriptParams[6], ScriptParams[7]);
StoreParameters(&m_nIp, 1);
return 0;
}
@@ -7130,13 +7130,13 @@ int8 CRunningScript::ProcessCommands800To899(int32 command)
case COMMAND_OPEN_GARAGE:
{
CollectParameters(&m_nIp, 1);
- CGarages::Garages[ScriptParams[0]].OpenThisGarage();
+ CGarages::aGarages[ScriptParams[0]].OpenThisGarage();
return 0;
}
case COMMAND_CLOSE_GARAGE:
{
CollectParameters(&m_nIp, 1);
- CGarages::Garages[ScriptParams[0]].CloseThisGarage();
+ CGarages::aGarages[ScriptParams[0]].CloseThisGarage();
return 0;
}
case COMMAND_WARP_CHAR_FROM_CAR_TO_COORD:
diff --git a/src/core/Pad.h b/src/core/Pad.h
index 09691128..a231900e 100644
--- a/src/core/Pad.h
+++ b/src/core/Pad.h
@@ -4,7 +4,7 @@ enum {
PLAYERCONTROL_ENABLED = 0,
PLAYERCONTROL_DISABLED_1 = 1,
PLAYERCONTROL_DISABLED_2 = 2,
- PLAYERCONTROL_DISABLED_4 = 4,
+ PLAYERCONTROL_GARAGE = 4,
PLAYERCONTROL_DISABLED_8 = 8,
PLAYERCONTROL_DISABLED_10 = 16,
PLAYERCONTROL_DISABLED_20 = 32, // used on CPlayerInfo::MakePlayerSafe
@@ -423,7 +423,10 @@ public:
bool GetRightShoulder1(void) { return !!NewState.RightShoulder1; }
bool GetRightShoulder2(void) { return !!NewState.RightShoulder2; }
- bool ArePlayerControlsDisabled(void) { return DisablePlayerControls != PLAYERCONTROL_ENABLED; }
+ bool ArePlayerControlsDisabled(void) { return DisablePlayerControls != PLAYERCONTROL_ENABLED; }
+ void SetDisablePlayerControls(uint8 who) { DisablePlayerControls |= who; }
+ void SetEnablePlayerControls(uint8 who) { DisablePlayerControls &= ~who; }
+ bool IsPlayerControlsDisabledBy(uint8 who) { return DisablePlayerControls & who; }
};
VALIDATE_SIZE(CPad, 0xFC);
diff --git a/src/core/Stats.cpp b/src/core/Stats.cpp
index 93eeb759..2a3f06b3 100644
--- a/src/core/Stats.cpp
+++ b/src/core/Stats.cpp
@@ -48,6 +48,7 @@ int32& CStats::LongestFlightInDodo = *(int32*)0x8F5FE4;
int32& CStats::TimeTakenDefuseMission = *(int32*)0x880E24;
int32& CStats::TotalNumberKillFrenzies = *(int32*)0x8E2884;
int32& CStats::TotalNumberMissions = *(int32*)0x8E2820;
+int32& CStats::KgOfExplosivesUsed = *(int32*)0x8F2510;
int32(&CStats::FastestTimes)[CStats::TOTAL_FASTEST_TIMES] = *(int32(*)[CStats::TOTAL_FASTEST_TIMES])*(uintptr*)0x6E9128;
int32(&CStats::HighestScores)[CStats::TOTAL_HIGHEST_SCORES] = *(int32(*)[CStats::TOTAL_HIGHEST_SCORES]) * (uintptr*)0x8622B0;
diff --git a/src/core/Stats.h b/src/core/Stats.h
index 0a750d5e..f6ff8187 100644
--- a/src/core/Stats.h
+++ b/src/core/Stats.h
@@ -53,6 +53,7 @@ public:
static int32 &TotalNumberMissions;
static int32(&FastestTimes)[TOTAL_FASTEST_TIMES];
static int32(&HighestScores)[TOTAL_HIGHEST_SCORES];
+ static int32 &KgOfExplosivesUsed;
public:
static void RegisterFastestTime(int32, int32);
diff --git a/src/core/World.cpp b/src/core/World.cpp
index cbceb292..1832ce72 100644
--- a/src/core/World.cpp
+++ b/src/core/World.cpp
@@ -52,6 +52,7 @@ WRAPPER void CWorld::FindObjectsOfTypeInRangeSectorList(uint32, CPtrList&, CVect
WRAPPER void CWorld::FindMissionEntitiesIntersectingCube(const CVector&, const CVector&, int16*, int16, CEntity**, bool, bool, bool) { EAXJMP(0x4B3680); }
WRAPPER void CWorld::ClearCarsFromArea(float, float, float, float, float, float) { EAXJMP(0x4B50E0); }
WRAPPER void CWorld::ClearPedsFromArea(float, float, float, float, float, float) { EAXJMP(0x4B52B0); }
+WRAPPER void CWorld::CallOffChaseForArea(float, float, float, float) { EAXJMP(0x4B5530); }
void
CWorld::Initialise()
diff --git a/src/core/World.h b/src/core/World.h
index 1ad65ac4..75d17a71 100644
--- a/src/core/World.h
+++ b/src/core/World.h
@@ -117,6 +117,7 @@ public:
static void FindMissionEntitiesIntersectingCube(const CVector&, const CVector&, int16*, int16, CEntity**, bool, bool, bool);
static void ClearCarsFromArea(float, float, float, float, float, float);
static void ClearPedsFromArea(float, float, float, float, float, float);
+ static void CallOffChaseForArea(float, float, float, float);
static float GetSectorX(float f) { return ((f - WORLD_MIN_X)/SECTOR_SIZE_X); }
static float GetSectorY(float f) { return ((f - WORLD_MIN_Y)/SECTOR_SIZE_Y); }
diff --git a/src/core/config.h b/src/core/config.h
index 9235e744..54a4c25f 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -114,6 +114,8 @@ enum Config {
NUM_AUDIO_REFLECTIONS = 5,
NUM_SCRIPT_MAX_ENTITIES = 40,
+
+ NUM_GARAGE_STORED_CARS = 6
};
// We'll use this once we're ready to become independent of the game
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp
index 90848d6c..63c9519f 100644
--- a/src/vehicles/Vehicle.cpp
+++ b/src/vehicles/Vehicle.cpp
@@ -16,6 +16,7 @@
#include "Renderer.h"
#include "DMAudio.h"
#include "Radar.h"
+#include "Darkel.h"
bool &CVehicle::bWheelsOnlyCheat = *(bool *)0x95CD78;
bool &CVehicle::bAllDodosCheat = *(bool *)0x95CD75;
@@ -763,6 +764,29 @@ CVehicle::IsSphereTouchingVehicle(float sx, float sy, float sz, float radius)
return true;
}
+void
+DestroyVehicleAndDriverAndPassengers(CVehicle* pVehicle)
+{
+ if (pVehicle->pDriver) {
+#ifndef FIX_BUGS
+ // this just isn't fair
+ CDarkel::RegisterKillByPlayer(pVehicle->pDriver, WEAPONTYPE_UNIDENTIFIED);
+#endif
+ pVehicle->pDriver->FlagToDestroyWhenNextProcessed();
+ }
+ for (int i = 0; i < pVehicle->m_nNumMaxPassengers; i++) {
+ if (pVehicle->pPassengers[i]) {
+#ifndef FIX_BUGS
+ // this just isn't fair
+ CDarkel::RegisterKillByPlayer(pVehicle->pPassengers[i], WEAPONTYPE_UNIDENTIFIED);
+#endif
+ pVehicle->pPassengers[i]->FlagToDestroyWhenNextProcessed();
+ }
+ }
+ CWorld::Remove(pVehicle);
+ delete pVehicle;
+}
+
class CVehicle_ : public CVehicle
{
diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h
index bd8df694..8c0825cf 100644
--- a/src/vehicles/Vehicle.h
+++ b/src/vehicles/Vehicle.h
@@ -300,3 +300,5 @@ public:
};
static_assert(sizeof(cVehicleParams) == 0x18, "cVehicleParams: error");
+
+void DestroyVehicleAndDriverAndPassengers(CVehicle* pVehicle);