1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-10 20:29:15 +00:00
re3/src/control/GameLogic.cpp

624 lines
21 KiB
C++
Raw Normal View History

2019-10-07 21:29:30 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2020-04-09 18:50:24 +00:00
#include "GameLogic.h"
#include "Clock.h"
#include "Stats.h"
#include "Pickups.h"
#include "Timer.h"
#include "Streaming.h"
#include "CutsceneMgr.h"
#include "World.h"
#include "PlayerPed.h"
#include "Wanted.h"
#include "Camera.h"
#include "Messages.h"
#include "CarCtrl.h"
#include "Restart.h"
#include "Pad.h"
#include "References.h"
#include "Fire.h"
#include "Script.h"
#include "Garages.h"
2020-05-31 17:59:01 +00:00
#include "Population.h"
#include "General.h"
#include "DMAudio.h"
#include "Radar.h"
#include "Pools.h"
#include "Hud.h"
#include "Particle.h"
#include "ColStore.h"
#include "Automobile.h"
#include "MBlur.h"
2020-11-19 18:07:32 +00:00
#include "screendroplets.h"
2020-04-09 18:50:24 +00:00
2020-04-17 05:54:14 +00:00
uint8 CGameLogic::ActivePlayers;
2020-05-31 17:59:01 +00:00
uint8 CGameLogic::ShortCutState;
CAutomobile* CGameLogic::pShortCutTaxi;
uint32 CGameLogic::NumAfterDeathStartPoints;
CVector CGameLogic::ShortCutStart;
float CGameLogic::ShortCutStartOrientation;
CVector CGameLogic::ShortCutDestination;
float CGameLogic::ShortCutDestinationOrientation;
uint32 CGameLogic::ShortCutTimer;
CVector CGameLogic::AfterDeathStartPoints[NUM_SHORTCUT_START_POINTS];
float CGameLogic::AfterDeathStartPointOrientation[NUM_SHORTCUT_START_POINTS];
CVector CGameLogic::ShortCutDropOffForMission;
float CGameLogic::ShortCutDropOffOrientationForMission;
bool CGameLogic::MissionDropOffReadyToBeUsed;
2021-01-18 19:20:44 +00:00
char CGameLogic::mStoredPlayerOutfit[8] = "plr3";
2020-05-31 17:59:01 +00:00
#define SHORTCUT_TAXI_COST (9)
2020-10-11 09:56:33 +00:00
#define TOTAL_BUSTED_AUDIO (28)
2020-04-09 18:50:24 +00:00
void
CGameLogic::InitAtStartOfGame()
{
ActivePlayers = 1;
2020-05-31 17:59:01 +00:00
ShortCutState = SHORTCUT_NONE;
pShortCutTaxi = nil;
NumAfterDeathStartPoints = 0;
2020-04-09 18:50:24 +00:00
}
void
CGameLogic::PassTime(uint32 time)
{
int32 minutes, hours, days;
minutes = time + CClock::GetMinutes();
hours = CClock::GetHours();
for (; minutes >= 60; minutes -= 60)
hours++;
if (hours > 23) {
days = CStats::DaysPassed;
for (; hours >= 24; hours -= 24)
days++;
CStats::DaysPassed = days;
}
CClock::SetGameClock(hours, minutes);
CPickups::PassTime(time * 1000);
}
void
CGameLogic::SortOutStreamingAndMemory(const CVector &pos)
{
CTimer::Stop();
CStreaming::FlushRequestList();
CStreaming::DeleteRwObjectsAfterDeath(pos);
CStreaming::RemoveUnusedModelsInLoadedList();
CGame::DrasticTidyUpMemory(true);
2021-01-18 19:20:44 +00:00
CWorld::Players[CWorld::PlayerInFocus].m_pPed->Undress(mStoredPlayerOutfit);
2020-05-31 17:59:01 +00:00
CStreaming::LoadSceneCollision(pos);
2020-04-09 18:50:24 +00:00
CStreaming::LoadScene(pos);
2020-05-31 17:59:01 +00:00
CWorld::Players[CWorld::PlayerInFocus].m_pPed->Dress();
2020-04-09 18:50:24 +00:00
CTimer::Update();
}
void
CGameLogic::Update()
{
CVector vecRestartPos;
float fRestartFloat;
if (CCutsceneMgr::IsCutsceneProcessing()) return;
2020-05-31 17:59:01 +00:00
UpdateShortCut();
2020-04-09 18:50:24 +00:00
CPlayerInfo &pPlayerInfo = CWorld::Players[CWorld::PlayerInFocus];
2020-05-31 17:59:01 +00:00
2020-04-09 18:50:24 +00:00
switch (pPlayerInfo.m_WBState) {
case WBSTATE_PLAYING:
if (pPlayerInfo.m_pPed->m_nPedState == PED_DEAD) {
pPlayerInfo.m_pPed->ClearAdrenaline();
pPlayerInfo.KillPlayer();
}
if (pPlayerInfo.m_pPed->m_nPedState == PED_ARRESTED) {
pPlayerInfo.m_pPed->ClearAdrenaline();
pPlayerInfo.ArrestPlayer();
}
break;
case WBSTATE_WASTED:
2020-05-26 21:25:12 +00:00
#ifdef MISSION_REPLAY
if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > AddExtraDeathDelay() + 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= AddExtraDeathDelay() + 0x800)) {
#else
2020-04-09 18:50:24 +00:00
if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= 0x800)) {
2020-05-26 21:25:12 +00:00
#endif
2020-04-09 18:50:24 +00:00
TheCamera.SetFadeColour(200, 200, 200);
TheCamera.Fade(2.0f, FADE_OUT);
}
2020-05-26 21:25:12 +00:00
#ifdef MISSION_REPLAY
if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= AddExtraDeathDelay() + 0x1000) {
#else
2020-04-09 18:50:24 +00:00
if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= 0x1000) {
2020-05-26 21:25:12 +00:00
#endif
2020-04-09 18:50:24 +00:00
pPlayerInfo.m_WBState = WBSTATE_PLAYING;
if (pPlayerInfo.m_bGetOutOfHospitalFree) {
pPlayerInfo.m_bGetOutOfHospitalFree = false;
} else {
2020-05-31 17:59:01 +00:00
pPlayerInfo.m_nMoney = Max(0, pPlayerInfo.m_nMoney - 100);
2020-04-09 18:50:24 +00:00
pPlayerInfo.m_pPed->ClearWeapons();
}
if (pPlayerInfo.m_pPed->bInVehicle) {
CVehicle *pVehicle = pPlayerInfo.m_pPed->m_pMyVehicle;
if (pVehicle != nil) {
if (pVehicle->pDriver == pPlayerInfo.m_pPed) {
pVehicle->pDriver = nil;
if (pVehicle->GetStatus() != STATUS_WRECKED)
pVehicle->SetStatus(STATUS_ABANDONED);
2020-04-09 18:50:24 +00:00
} else
pVehicle->RemovePassenger(pPlayerInfo.m_pPed);
}
}
CEventList::Initialise();
2020-11-19 18:07:32 +00:00
#ifdef SCREEN_DROPLETS
ScreenDroplets::Initialise();
#endif
2020-04-09 18:50:24 +00:00
CMessages::ClearMessages();
CCarCtrl::ClearInterestingVehicleList();
CWorld::ClearExcitingStuffFromArea(pPlayerInfo.GetPos(), 4000.0f, 1);
CRestart::FindClosestHospitalRestartPoint(pPlayerInfo.GetPos(), &vecRestartPos, &fRestartFloat);
2020-07-13 14:43:09 +00:00
CRestart::OverrideHospitalLevel = LEVEL_GENERIC;
CRestart::OverridePoliceStationLevel = LEVEL_GENERIC;
2020-04-09 18:50:24 +00:00
PassTime(720);
RestorePlayerStuffDuringResurrection(pPlayerInfo.m_pPed, vecRestartPos, fRestartFloat);
2020-05-31 17:59:01 +00:00
AfterDeathArrestSetUpShortCutTaxi();
2020-04-09 18:50:24 +00:00
SortOutStreamingAndMemory(pPlayerInfo.GetPos());
TheCamera.m_fCamShakeForce = 0.0f;
2020-06-27 21:01:51 +00:00
TheCamera.SetMotionBlur(0, 0, 0, 0, MOTION_BLUR_NONE);
2020-04-09 18:50:24 +00:00
CPad::GetPad(0)->StopShaking(0);
CReferences::RemoveReferencesToPlayer();
2020-05-31 17:59:01 +00:00
CPopulation::m_CountDownToPedsAtStart = 10;
CCarCtrl::CountDownToCarsAtStart = 10;
2020-04-09 18:50:24 +00:00
CPad::GetPad(CWorld::PlayerInFocus)->DisablePlayerControls = PLAYERCONTROL_ENABLED;
if (CRestart::bFadeInAfterNextDeath) {
TheCamera.SetFadeColour(200, 200, 200);
TheCamera.Fade(4.0f, FADE_IN);
2020-05-31 17:59:01 +00:00
} else
CRestart::bFadeInAfterNextDeath = true;
2020-04-09 18:50:24 +00:00
}
break;
case WBSTATE_BUSTED:
2020-05-26 21:25:12 +00:00
#ifdef MISSION_REPLAY
if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > AddExtraDeathDelay() + 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= AddExtraDeathDelay() + 0x800)) {
#else
2020-04-09 18:50:24 +00:00
if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= 0x800)) {
2020-05-26 21:25:12 +00:00
#endif
2020-04-09 18:50:24 +00:00
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(2.0f, FADE_OUT);
}
2020-05-31 17:59:01 +00:00
2020-05-31 17:59:01 +00:00
if (!CTheScripts::IsPlayerOnAMission() && pPlayerInfo.m_nBustedAudioStatus == 0) {
if (CGeneral::GetRandomNumberInRange(0, 4) == 0)
pPlayerInfo.m_nBustedAudioStatus = BUSTEDAUDIO_DONE;
else {
pPlayerInfo.m_nBustedAudioStatus = BUSTEDAUDIO_LOADING;
char name[12];
sprintf(name, pPlayerInfo.m_nCurrentBustedAudio >= 10 ? "bust_%d" : "bust_0%d", pPlayerInfo.m_nCurrentBustedAudio);
2020-06-08 13:22:49 +00:00
DMAudio.ClearMissionAudio(0);
DMAudio.PreloadMissionAudio(0, name);
2020-10-11 09:56:33 +00:00
pPlayerInfo.m_nCurrentBustedAudio = pPlayerInfo.m_nCurrentBustedAudio % TOTAL_BUSTED_AUDIO + 1;
2020-05-31 17:59:01 +00:00
}
}
if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > 4000 &&
pPlayerInfo.m_nBustedAudioStatus == BUSTEDAUDIO_LOADING &&
2020-06-08 13:22:49 +00:00
DMAudio.GetMissionAudioLoadingStatus(0) == 1) {
DMAudio.PlayLoadedMissionAudio(0);
2020-05-31 17:59:01 +00:00
pPlayerInfo.m_nBustedAudioStatus = BUSTEDAUDIO_DONE;
}
2020-05-26 21:25:12 +00:00
#ifdef MISSION_REPLAY
if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= AddExtraDeathDelay() + 0x1000) {
#else
2020-04-09 18:50:24 +00:00
if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= 0x1000) {
#endif
2020-05-31 17:59:01 +00:00
#ifdef FIX_BUGS
pPlayerInfo.m_nBustedAudioStatus = BUSTEDAUDIO_NONE;
#endif
2020-04-09 18:50:24 +00:00
pPlayerInfo.m_WBState = WBSTATE_PLAYING;
int takeMoney;
2021-01-21 23:20:51 +00:00
switch (pPlayerInfo.m_pPed->m_pWanted->GetWantedLevel()) {
2020-04-09 18:50:24 +00:00
case 0:
case 1:
takeMoney = 100;
break;
case 2:
takeMoney = 200;
break;
case 3:
takeMoney = 400;
break;
case 4:
takeMoney = 600;
break;
case 5:
takeMoney = 900;
break;
case 6:
takeMoney = 1500;
break;
}
if (pPlayerInfo.m_bGetOutOfJailFree) {
pPlayerInfo.m_bGetOutOfJailFree = false;
} else {
2020-04-19 16:34:08 +00:00
pPlayerInfo.m_nMoney = Max(0, pPlayerInfo.m_nMoney - takeMoney);
2020-04-09 18:50:24 +00:00
pPlayerInfo.m_pPed->ClearWeapons();
}
if (pPlayerInfo.m_pPed->bInVehicle) {
CVehicle *pVehicle = pPlayerInfo.m_pPed->m_pMyVehicle;
if (pVehicle != nil) {
if (pVehicle->pDriver == pPlayerInfo.m_pPed) {
pVehicle->pDriver = nil;
if (pVehicle->GetStatus() != STATUS_WRECKED)
pVehicle->SetStatus(STATUS_ABANDONED);
2020-04-09 18:50:24 +00:00
}
else
pVehicle->RemovePassenger(pPlayerInfo.m_pPed);
}
}
CEventList::Initialise();
2020-11-19 18:07:32 +00:00
#ifdef SCREEN_DROPLETS
ScreenDroplets::Initialise();
#endif
2020-04-09 18:50:24 +00:00
CMessages::ClearMessages();
CCarCtrl::ClearInterestingVehicleList();
CWorld::ClearExcitingStuffFromArea(pPlayerInfo.GetPos(), 4000.0f, 1);
CRestart::FindClosestPoliceRestartPoint(pPlayerInfo.GetPos(), &vecRestartPos, &fRestartFloat);
2020-07-13 14:43:09 +00:00
CRestart::OverrideHospitalLevel = LEVEL_GENERIC;
CRestart::OverridePoliceStationLevel = LEVEL_GENERIC;
2020-04-09 18:50:24 +00:00
PassTime(720);
RestorePlayerStuffDuringResurrection(pPlayerInfo.m_pPed, vecRestartPos, fRestartFloat);
2020-05-31 17:59:01 +00:00
AfterDeathArrestSetUpShortCutTaxi();
2020-04-09 18:50:24 +00:00
pPlayerInfo.m_pPed->ClearWeapons();
SortOutStreamingAndMemory(pPlayerInfo.GetPos());
TheCamera.m_fCamShakeForce = 0.0f;
2020-06-27 21:01:51 +00:00
TheCamera.SetMotionBlur(0, 0, 0, 0, MOTION_BLUR_NONE);
2020-04-09 18:50:24 +00:00
CPad::GetPad(0)->StopShaking(0);
CReferences::RemoveReferencesToPlayer();
2020-05-31 17:59:01 +00:00
CPopulation::m_CountDownToPedsAtStart = 10;
CCarCtrl::CountDownToCarsAtStart = 10;
2020-04-09 18:50:24 +00:00
CPad::GetPad(CWorld::PlayerInFocus)->DisablePlayerControls = PLAYERCONTROL_ENABLED;
if (CRestart::bFadeInAfterNextArrest) {
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(4.0f, FADE_IN);
2020-05-31 17:59:01 +00:00
} else
CRestart::bFadeInAfterNextArrest = true;
2020-04-09 18:50:24 +00:00
}
break;
case WBSTATE_FAILED_CRITICAL_MISSION:
2020-05-26 21:25:12 +00:00
#ifdef MISSION_REPLAY
if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > AddExtraDeathDelay() + 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= AddExtraDeathDelay() + 0x800)) {
#else
if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= 0x800)) {
#endif
2020-04-09 18:50:24 +00:00
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(2.0f, FADE_OUT);
}
2020-05-26 21:25:12 +00:00
#ifdef MISSION_REPLAY
if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= AddExtraDeathDelay() + 0x1000) {
#else
2020-04-09 18:50:24 +00:00
if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= 0x1000) {
2020-05-26 21:25:12 +00:00
#endif
2020-04-09 18:50:24 +00:00
pPlayerInfo.m_WBState = WBSTATE_PLAYING;
if (pPlayerInfo.m_pPed->bInVehicle) {
CVehicle *pVehicle = pPlayerInfo.m_pPed->m_pMyVehicle;
if (pVehicle != nil) {
if (pVehicle->pDriver == pPlayerInfo.m_pPed) {
pVehicle->pDriver = nil;
if (pVehicle->GetStatus() != STATUS_WRECKED)
pVehicle->SetStatus(STATUS_ABANDONED);
2020-04-09 18:50:24 +00:00
} else
pVehicle->RemovePassenger(pPlayerInfo.m_pPed);
}
}
CEventList::Initialise();
2020-11-19 18:07:32 +00:00
#ifdef SCREEN_DROPLETS
ScreenDroplets::Initialise();
#endif
2020-04-09 18:50:24 +00:00
CMessages::ClearMessages();
CCarCtrl::ClearInterestingVehicleList();
CWorld::ClearExcitingStuffFromArea(pPlayerInfo.GetPos(), 4000.0f, 1);
CRestart::FindClosestPoliceRestartPoint(pPlayerInfo.GetPos(), &vecRestartPos, &fRestartFloat);
2020-07-13 14:43:09 +00:00
CRestart::OverridePoliceStationLevel = LEVEL_GENERIC;
CRestart::OverrideHospitalLevel = LEVEL_GENERIC;
2020-04-09 18:50:24 +00:00
RestorePlayerStuffDuringResurrection(pPlayerInfo.m_pPed, vecRestartPos, fRestartFloat);
SortOutStreamingAndMemory(pPlayerInfo.GetPos());
TheCamera.m_fCamShakeForce = 0.0f;
2020-06-27 21:01:51 +00:00
TheCamera.SetMotionBlur(0, 0, 0, 0, MOTION_BLUR_NONE);
2020-04-09 18:50:24 +00:00
CPad::GetPad(0)->StopShaking(0);
CReferences::RemoveReferencesToPlayer();
2020-05-31 17:59:01 +00:00
CPopulation::m_CountDownToPedsAtStart = 10;
CCarCtrl::CountDownToCarsAtStart = 10;
2020-04-09 18:50:24 +00:00
CPad::GetPad(CWorld::PlayerInFocus)->DisablePlayerControls = PLAYERCONTROL_ENABLED;
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(4.0f, FADE_IN);
}
break;
case 4:
return;
}
}
void
CGameLogic::RestorePlayerStuffDuringResurrection(CPlayerPed *pPlayerPed, CVector pos, float angle)
{
2020-05-31 17:59:01 +00:00
ClearShortCut();
CPlayerInfo* pPlayerInfo = pPlayerPed->GetPlayerInfoForThisPlayerPed();
pPlayerPed->m_fHealth = pPlayerInfo->m_nMaxHealth;
2020-04-09 18:50:24 +00:00
pPlayerPed->m_fArmour = 0.0f;
pPlayerPed->bIsVisible = true;
pPlayerPed->m_bloodyFootprintCountOrDeathTime = 0;
pPlayerPed->bDoBloodyFootprints = false;
pPlayerPed->m_nDrunkenness = 0;
pPlayerPed->m_nFadeDrunkenness = 0;
CMBlur::ClearDrunkBlur();
pPlayerPed->m_nDrunkCountdown = 0;
2020-04-09 18:50:24 +00:00
pPlayerPed->ClearAdrenaline();
pPlayerPed->m_fCurrentStamina = pPlayerPed->m_fMaxStamina;
if (pPlayerPed->m_pFire)
pPlayerPed->m_pFire->Extinguish();
pPlayerPed->bInVehicle = false;
pPlayerPed->m_pMyVehicle = nil;
pPlayerPed->m_pVehicleAnim = nil;
pPlayerPed->m_pWanted->Reset();
2020-05-31 17:59:01 +00:00
pPlayerPed->bCancelEnteringCar = false;
2020-04-09 18:50:24 +00:00
pPlayerPed->RestartNonPartialAnims();
2020-05-31 17:59:01 +00:00
pPlayerInfo->MakePlayerSafe(false);
2020-04-09 18:50:24 +00:00
pPlayerPed->bRemoveFromWorld = false;
pPlayerPed->ClearWeaponTarget();
pPlayerPed->SetInitialState();
CCarCtrl::ClearInterestingVehicleList();
2020-05-31 17:59:01 +00:00
pPlayerPed->Teleport(pos + CVector(0.0f, 0.0f, 1.0f));
pPlayerPed->SetMoveSpeed(0.0f, 0.0f, 0.0f);
2020-04-09 18:50:24 +00:00
pPlayerPed->m_fRotationCur = DEGTORAD(angle);
pPlayerPed->m_fRotationDest = pPlayerPed->m_fRotationCur;
pPlayerPed->SetHeading(pPlayerPed->m_fRotationCur);
CTheScripts::ClearSpaceForMissionEntity(pos, pPlayerPed);
CWorld::ClearExcitingStuffFromArea(pos, 4000.0, 1);
pPlayerPed->RestoreHeadingRate();
2020-05-31 17:59:01 +00:00
CGame::currArea = AREA_MAIN_MAP;
2020-08-20 22:05:05 +00:00
CStreaming::RemoveBuildingsNotInArea(0);
2020-04-09 18:50:24 +00:00
TheCamera.SetCameraDirectlyInFrontForFollowPed_CamOnAString();
2020-05-31 17:59:01 +00:00
TheCamera.Restore();
2020-04-09 18:50:24 +00:00
CReferences::RemoveReferencesToPlayer();
CGarages::PlayerArrestedOrDied();
CStats::CheckPointReachedUnsuccessfully();
CWorld::Remove(pPlayerPed);
CWorld::Add(pPlayerPed);
CHud::ResetWastedText();
2020-05-31 17:59:01 +00:00
CStreaming::StreamZoneModels(pos);
2021-01-12 21:07:24 +00:00
//clearWaterDrop = true;
2020-05-31 17:59:01 +00:00
}
void
CGameLogic::ClearShortCut()
{
if (pShortCutTaxi) {
if (pShortCutTaxi->VehicleCreatedBy == MISSION_VEHICLE) {
pShortCutTaxi->VehicleCreatedBy = RANDOM_VEHICLE;
--CCarCtrl::NumMissionCars;
++CCarCtrl::NumRandomCars;
}
CRadar::ClearBlipForEntity(BLIP_CAR, CPools::GetVehiclePool()->GetIndex(pShortCutTaxi));
pShortCutTaxi = nil;
}
CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_SHORTCUT_TAXI);
}
void
CGameLogic::SetUpShortCut(CVector vStartPos, float fStartAngle, CVector vEndPos, float fEndAngle)
{
ClearShortCut();
ShortCutState = SHORTCUT_INIT;
ShortCutStart = vStartPos;
ShortCutStartOrientation = fStartAngle;
ShortCutDestination = vEndPos;
ShortCutDestinationOrientation = fEndAngle;
2021-01-08 00:41:40 +00:00
CStreaming::RequestModel(MI_CABBIE, 0);
2020-05-31 17:59:01 +00:00
}
void
CGameLogic::AbandonShortCutIfTaxiHasBeenMessedWith()
{
if (!pShortCutTaxi)
return;
if (pShortCutTaxi->pDriver == nil ||
pShortCutTaxi->pDriver->DyingOrDead() ||
pShortCutTaxi->pDriver->GetPedState() == PED_DRAG_FROM_CAR ||
pShortCutTaxi->pDriver->GetPedState() == PED_ON_FIRE ||
pShortCutTaxi->pDriver->m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE ||
pShortCutTaxi->m_fHealth < 250.0f ||
pShortCutTaxi->bRenderScorched)
ClearShortCut();
}
void
CGameLogic::AbandonShortCutIfPlayerMilesAway()
{
if (!pShortCutTaxi)
return;
if ((FindPlayerCoors() - pShortCutTaxi->GetPosition()).Magnitude() > 120.0f)
ClearShortCut();
}
void
CGameLogic::UpdateShortCut()
{
switch (ShortCutState) {
case SHORTCUT_INIT:
2021-01-08 00:41:40 +00:00
if (!CStreaming::HasModelLoaded(MI_CABBIE)) {
CStreaming::RequestModel(MI_CABBIE, 0);
2020-05-31 17:59:01 +00:00
return;
}
2021-01-08 00:41:40 +00:00
pShortCutTaxi = new CAutomobile(MI_CABBIE, RANDOM_VEHICLE);
2020-05-31 17:59:01 +00:00
if (!pShortCutTaxi)
return;
pShortCutTaxi->SetPosition(ShortCutStart);
pShortCutTaxi->SetHeading(DEGTORAD(ShortCutStartOrientation));
pShortCutTaxi->PlaceOnRoadProperly();
pShortCutTaxi->SetStatus(STATUS_PHYSICS);
pShortCutTaxi->AutoPilot.m_nCarMission = MISSION_STOP_FOREVER;
pShortCutTaxi->AutoPilot.m_nCruiseSpeed = 0;
pShortCutTaxi->SetUpDriver();
pShortCutTaxi->VehicleCreatedBy = MISSION_VEHICLE;
++CCarCtrl::NumMissionCars;
--CCarCtrl::NumRandomCars;
CTheScripts::ClearSpaceForMissionEntity(ShortCutStart, pShortCutTaxi);
CWorld::Add(pShortCutTaxi);
CRadar::SetEntityBlip(BLIP_CAR, CPools::GetVehiclePool()->GetIndex(pShortCutTaxi), 0, BLIP_DISPLAY_MARKER_ONLY);
ShortCutState = SHORTCUT_IDLE;
break;
case SHORTCUT_IDLE:
if (FindPlayerPed()->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER && FindPlayerPed()->m_carInObjective == pShortCutTaxi) {
CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_SHORTCUT_TAXI);
FindPlayerPed()->SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, pShortCutTaxi);
ShortCutState = SHORTCUT_GETTING_IN;
}
AbandonShortCutIfTaxiHasBeenMessedWith();
AbandonShortCutIfPlayerMilesAway();
break;
case SHORTCUT_GETTING_IN:
if (pShortCutTaxi->pPassengers[0] == FindPlayerPed() ||
pShortCutTaxi->pPassengers[1] == FindPlayerPed() ||
pShortCutTaxi->pPassengers[2] == FindPlayerPed()) {
pShortCutTaxi->AutoPilot.m_nTempAction = TEMPACT_GOFORWARD;
pShortCutTaxi->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2500;
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(2.5f, 0);
ShortCutState = SHORTCUT_TRANSITION;
ShortCutTimer = CTimer::GetTimeInMilliseconds() + 3000;
CMessages::AddBigMessage(TheText.Get("TAXI"), 4500, 1);
}
AbandonShortCutIfTaxiHasBeenMessedWith();
break;
case SHORTCUT_TRANSITION:
if (CTimer::GetTimeInMilliseconds() > ShortCutTimer) {
CTimer::Suspend();
CColStore::RequestCollision(ShortCutDestination);
CStreaming::LoadSceneCollision(ShortCutDestination);
CStreaming::LoadScene(ShortCutDestination);
CTheScripts::ClearSpaceForMissionEntity(ShortCutDestination, pShortCutTaxi);
pShortCutTaxi->Teleport(ShortCutDestination);
pShortCutTaxi->SetHeading(DEGTORAD(ShortCutDestinationOrientation));
pShortCutTaxi->PlaceOnRoadProperly();
pShortCutTaxi->SetMoveSpeed(pShortCutTaxi->GetForward() * 0.4f);
ShortCutTimer = CTimer::GetTimeInMilliseconds() + 1500;
TheCamera.SetFadeColour(0, 0, 0);
TheCamera.Fade(1.0f, 1);
ShortCutState = SHORTCUT_ARRIVING;
CTimer::Resume();
}
break;
case SHORTCUT_ARRIVING:
if (CTimer::GetTimeInMilliseconds() > ShortCutTimer) {
CWorld::Players[CWorld::PlayerInFocus].m_nMoney = Max(0, CWorld::Players[CWorld::PlayerInFocus].m_nMoney - SHORTCUT_TAXI_COST);
FindPlayerPed()->SetObjective(OBJECTIVE_LEAVE_CAR, pShortCutTaxi);
2020-05-31 17:59:01 +00:00
FindPlayerPed()->m_carInObjective = pShortCutTaxi;
ShortCutState = SHORTCUT_GETTING_OUT;
}
AbandonShortCutIfTaxiHasBeenMessedWith();
break;
case SHORTCUT_GETTING_OUT:
if (pShortCutTaxi->pPassengers[0] != FindPlayerPed() &&
pShortCutTaxi->pPassengers[1] != FindPlayerPed() &&
pShortCutTaxi->pPassengers[2] != FindPlayerPed()) {
CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_SHORTCUT_TAXI);
pShortCutTaxi->AutoPilot.m_nCarMission = MISSION_CRUISE;
pShortCutTaxi->AutoPilot.m_nCruiseSpeed = 18;
CCarCtrl::JoinCarWithRoadSystem(pShortCutTaxi);
pShortCutTaxi->VehicleCreatedBy = RANDOM_VEHICLE;
++CCarCtrl::NumRandomCars;
--CCarCtrl::NumMissionCars;
CRadar::ClearBlipForEntity(BLIP_CAR, CPools::GetVehiclePool()->GetIndex(pShortCutTaxi));
ShortCutState = SHORTCUT_NONE;
pShortCutTaxi = nil;
}
AbandonShortCutIfTaxiHasBeenMessedWith();
break;
}
}
void
CGameLogic::AddShortCutPointAfterDeath(CVector point, float angle)
{
if (NumAfterDeathStartPoints >= NUM_SHORTCUT_START_POINTS)
return;
AfterDeathStartPoints[NumAfterDeathStartPoints] = point;
AfterDeathStartPointOrientation[NumAfterDeathStartPoints] = angle;
NumAfterDeathStartPoints++;
}
void
CGameLogic::AddShortCutDropOffPointForMission(CVector point, float angle)
{
ShortCutDropOffForMission = point;
ShortCutDropOffOrientationForMission = angle;
MissionDropOffReadyToBeUsed = true;
}
void
CGameLogic::RemoveShortCutDropOffPointForMission()
{
MissionDropOffReadyToBeUsed = false;
}
void
CGameLogic::AfterDeathArrestSetUpShortCutTaxi()
{
if (!MissionDropOffReadyToBeUsed)
return;
int nClosestPoint = -1;
float fDistanceToPoint = 999999.9f;
for (int i = 0; i < NUM_SHORTCUT_START_POINTS; i++) {
float dist = (AfterDeathStartPoints[i] - FindPlayerCoors()).Magnitude();
if (dist < fDistanceToPoint) {
fDistanceToPoint = dist;
nClosestPoint = i;
}
}
if (fDistanceToPoint < 100.0f)
SetUpShortCut(AfterDeathStartPoints[nClosestPoint],
AfterDeathStartPointOrientation[nClosestPoint],
ShortCutDropOffForMission,
ShortCutDropOffOrientationForMission);
MissionDropOffReadyToBeUsed = false;
}
void
CGameLogic::Save(uint8* buf, uint32* size)
{
INITSAVEBUF
WriteSaveBuf(buf, NumAfterDeathStartPoints);
*size += sizeof(NumAfterDeathStartPoints);
for (int i = 0; i < NUM_SHORTCUT_START_POINTS; i++) {
WriteSaveBuf(buf, AfterDeathStartPoints[i].x);
*size += sizeof(AfterDeathStartPoints[i].x);
WriteSaveBuf(buf, AfterDeathStartPoints[i].y);
*size += sizeof(AfterDeathStartPoints[i].y);
WriteSaveBuf(buf, AfterDeathStartPoints[i].z);
*size += sizeof(AfterDeathStartPoints[i].z);
WriteSaveBuf(buf, AfterDeathStartPointOrientation[i]);
*size += sizeof(AfterDeathStartPointOrientation[i]);
}
VALIDATESAVEBUF(*size)
}
void
CGameLogic::Load(uint8* buf, uint32 size)
{
INITSAVEBUF
NumAfterDeathStartPoints = ReadSaveBuf<uint32>(buf);
for (int i = 0; i < NUM_SHORTCUT_START_POINTS; i++) {
AfterDeathStartPoints[i].x = ReadSaveBuf<float>(buf);
AfterDeathStartPoints[i].y = ReadSaveBuf<float>(buf);
AfterDeathStartPoints[i].z = ReadSaveBuf<float>(buf);
AfterDeathStartPointOrientation[i] = ReadSaveBuf<float>(buf);
}
VALIDATESAVEBUF(size)
2020-04-09 18:50:24 +00:00
}