diff options
author | eray orçunus <erayorcunus@gmail.com> | 2020-09-23 22:29:56 +0200 |
---|---|---|
committer | eray orçunus <erayorcunus@gmail.com> | 2020-09-24 00:54:37 +0200 |
commit | dbc458a4d762e48023c4ad69f6bae4b0258c94ce (patch) | |
tree | ff9c407775ddb0d12cd120143c73f8ad0d46b5e7 /src/peds/CivilianPed.cpp | |
parent | Add .gitattributes for better language stats (diff) | |
download | re3-dbc458a4d762e48023c4ad69f6bae4b0258c94ce.tar re3-dbc458a4d762e48023c4ad69f6bae4b0258c94ce.tar.gz re3-dbc458a4d762e48023c4ad69f6bae4b0258c94ce.tar.bz2 re3-dbc458a4d762e48023c4ad69f6bae4b0258c94ce.tar.lz re3-dbc458a4d762e48023c4ad69f6bae4b0258c94ce.tar.xz re3-dbc458a4d762e48023c4ad69f6bae4b0258c94ce.tar.zst re3-dbc458a4d762e48023c4ad69f6bae4b0258c94ce.zip |
Diffstat (limited to 'src/peds/CivilianPed.cpp')
-rw-r--r-- | src/peds/CivilianPed.cpp | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/src/peds/CivilianPed.cpp b/src/peds/CivilianPed.cpp index 9f938a56..ae30fdfe 100644 --- a/src/peds/CivilianPed.cpp +++ b/src/peds/CivilianPed.cpp @@ -12,13 +12,33 @@ #include "Weather.h" #include "PedAttractor.h" #include "Object.h" +#include "CarCtrl.h" +#ifndef _WIN32 +#include <float.h> +#endif + +// --MIAMI: Done CCivilianPed::CCivilianPed(ePedType pedtype, uint32 mi) : CPed(pedtype) { SetModelIndex(mi); for (int i = 0; i < ARRAY_SIZE(m_nearPeds); i++) { m_nearPeds[i] = nil; } + m_bLookForVacantCars = false; + if (pedtype == PEDTYPE_CRIMINAL) + m_bLookForVacantCars = true; + + m_nLookForVacantCarsCounter = 0; + m_bJustStoleACar = false; + m_bStealCarEvenIfThereIsSomeoneInIt = false; + for (int i = 0; i < ARRAY_SIZE(m_nStealWishList); i++) { + uint32 randomCarModel = CGeneral::GetRandomNumberInRange(MI_LANDSTAL, MI_LAST_VEHICLE + 1); + if (CModelInfo::IsCarModel(randomCarModel) || CModelInfo::IsBikeModel(randomCarModel)) + m_nStealWishList[i] = randomCarModel; + else + m_nStealWishList[i] = MI_CHEETAH; + } m_nAttractorCycleState = 0; m_bAttractorUnk = (CGeneral::GetRandomNumberInRange(0.0f, 1.0f) < 1.25f); } @@ -384,7 +404,7 @@ CCivilianPed::ProcessControl(void) CivilianAI(); if (CharCreatedBy == RANDOM_CHAR) { - // TODO(Miami): EnterVacantNearbyCars(); + EnterVacantNearbyCars(); UseNearbyAttractors(); } @@ -483,3 +503,83 @@ bool CCivilianPed::IsAttractedTo(int8 type) } return false; } + +// --MIAMI: Done +void +CCivilianPed::EnterVacantNearbyCars(void) +{ + if (!m_bLookForVacantCars) + return; + + if (m_bJustStoleACar && bInVehicle && m_carInObjective == m_pMyVehicle) { + m_bJustStoleACar = false; + m_pMyVehicle->SetStatus(STATUS_PHYSICS); + m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_CRUISE; + m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 10; + m_pMyVehicle->bEngineOn = true; + + } else if (!bHasAlreadyStoleACar) { + if (m_nLookForVacantCarsCounter == 8) { + m_nLookForVacantCarsCounter = 0; + if (IsPedInControl() && m_objective == OBJECTIVE_NONE) { + + CVehicle *foundCar = nil; + float closestDist = FLT_MAX; + int minX = CWorld::GetSectorIndexX(GetPosition().x - 10.0f); + if (minX < 0) minX = 0; + int minY = CWorld::GetSectorIndexY(GetPosition().y - 10.0f); + if (minY < 0) minY = 0; + int maxX = CWorld::GetSectorIndexX(GetPosition().x + 10.0f); + if (maxX > NUMSECTORS_X - 1) maxX = NUMSECTORS_X - 1; + int maxY = CWorld::GetSectorIndexY(GetPosition().y + 10.0f); + if (maxY > NUMSECTORS_Y - 1) maxY = NUMSECTORS_Y - 1; + + for (int curY = minY; curY <= maxY; curY++) { + for (int curX = minX; curX <= maxX; curX++) { + CSector* sector = CWorld::GetSector(curX, curY); + for (CPtrNode* node = sector->m_lists[ENTITYLIST_VEHICLES].first; node; node = node->next) { + CVehicle* veh = (CVehicle*)node->item; + if (veh && veh->IsCar()) { + + // Looks like PARKED_VEHICLE condition isn't there in Mobile. + if (veh->VehicleCreatedBy == RANDOM_VEHICLE || veh->VehicleCreatedBy == PARKED_VEHICLE) { + if (IsOnStealWishList(veh->GetModelIndex()) && !veh->IsLawEnforcementVehicle() + && (m_bStealCarEvenIfThereIsSomeoneInIt || !veh->pDriver && !veh->m_nNumPassengers) + && !veh->m_nNumGettingIn && !veh->m_nGettingInFlags && !veh->m_nGettingOutFlags + && !veh->m_pCarFire && veh->m_fHealth > 800.0f + && !veh->IsUpsideDown() && !veh->IsOnItsSide() && veh->CanPedEnterCar()) { + float dist = (GetPosition() - veh->GetPosition()).MagnitudeSqr(); + if (dist < sq(10.0f) && dist < closestDist && veh->IsClearToDriveAway()) { + foundCar = veh; + closestDist = dist; + } + } + } + } + } + } + } + if (foundCar) { + m_bJustStoleACar = true; + bHasAlreadyStoleACar = true; + CCarCtrl::JoinCarWithRoadSystem(foundCar); + SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, foundCar); + SetObjectiveTimer(10000); + } + } + } else { + ++m_nLookForVacantCarsCounter; + } + } +} + +bool +CCivilianPed::IsOnStealWishList(int32 model) +{ + for (int i = 0; i < ARRAY_SIZE(m_nStealWishList); i++) { + if (model == m_nStealWishList[i]) { + return true; + } + } + return false; +}
\ No newline at end of file |