re3/src/control/CarAI.cpp

798 lines
32 KiB
C++
Raw Normal View History

#include "common.h"
2020-04-17 13:31:11 +00:00
#include "CarAI.h"
2020-01-11 12:50:11 +00:00
#include "Accident.h"
2019-08-11 17:11:54 +00:00
#include "AutoPilot.h"
2020-11-16 19:20:56 +00:00
#include "Bridge.h"
2019-10-06 11:25:13 +00:00
#include "CarCtrl.h"
#include "General.h"
2019-10-10 21:02:55 +00:00
#include "HandlingMgr.h"
2019-10-06 11:25:13 +00:00
#include "ModelIndices.h"
#include "PlayerPed.h"
2020-03-28 14:47:52 +00:00
#include "Wanted.h"
#include "DMAudio.h"
#include "Fire.h"
2019-10-10 21:02:55 +00:00
#include "Pools.h"
2020-05-08 20:29:43 +00:00
#include "Population.h"
2019-08-11 17:11:54 +00:00
#include "Timer.h"
2019-10-06 11:25:13 +00:00
#include "TrafficLights.h"
2019-08-11 17:11:54 +00:00
#include "Vehicle.h"
2019-10-06 11:25:13 +00:00
#include "World.h"
#include "ZoneCull.h"
2019-08-11 17:11:54 +00:00
2019-10-06 11:25:13 +00:00
#define DISTANCE_TO_SWITCH_DISTANCE_GOTO 20.0f
2020-05-24 10:48:17 +00:00
//--MIAMI: file done
2020-05-05 11:40:35 +00:00
float CCarAI::FindSwitchDistanceClose(CVehicle* pVehicle)
2019-10-06 11:25:13 +00:00
{
return pVehicle->AutoPilot.m_nSwitchDistance;
2019-10-06 11:25:13 +00:00
}
2020-05-05 11:40:35 +00:00
float CCarAI::FindSwitchDistanceFarNormalVehicle(CVehicle* pVehicle)
{
return FindSwitchDistanceClose(pVehicle) + 5.0f;
}
2019-10-06 11:25:13 +00:00
float CCarAI::FindSwitchDistanceFar(CVehicle* pVehicle)
{
2020-05-05 11:40:35 +00:00
if (pVehicle->bIsLawEnforcer)
return 50.0f;
return FindSwitchDistanceFarNormalVehicle(pVehicle);
}
void CCarAI::BackToCruisingIfNoWantedLevel(CVehicle* pVehicle)
{
if (FindPlayerPed()->m_pWanted->m_bIgnoredByEveryone || pVehicle->bIsLawEnforcer &&
(FindPlayerPed()->m_pWanted->m_nWantedLevel == 0 || FindPlayerPed()->m_pWanted->m_bIgnoredByCops || CCullZones::NoPolice())) {
CCarCtrl::JoinCarWithRoadSystem(pVehicle);
pVehicle->AutoPilot.m_nCarMission = MISSION_CRUISE;
pVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_STOP_FOR_CARS;
pVehicle->m_bSirenOrAlarm = false;
if (CCullZones::NoPolice())
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
}
}
2019-10-06 11:25:13 +00:00
void CCarAI::UpdateCarAI(CVehicle* pVehicle)
{
if (pVehicle->bIsLawEnforcer){
if (pVehicle->AutoPilot.m_nCarMission == MISSION_BLOCKCAR_FARAWAY ||
pVehicle->AutoPilot.m_nCarMission == MISSION_RAMPLAYER_FARAWAY ||
pVehicle->AutoPilot.m_nCarMission == MISSION_BLOCKPLAYER_CLOSE ||
pVehicle->AutoPilot.m_nCarMission == MISSION_RAMPLAYER_CLOSE)
pVehicle->AutoPilot.m_nCruiseSpeed = FindPoliceCarSpeedForWantedLevel(pVehicle);
}
switch (pVehicle->GetStatus()){
2019-10-06 11:25:13 +00:00
case STATUS_PLAYER:
case STATUS_PLAYER_PLAYBACKFROMBUFFER:
case STATUS_TRAIN_MOVING:
case STATUS_TRAIN_NOT_MOVING:
case STATUS_HELI:
case STATUS_PLANE:
case STATUS_PLAYER_REMOTE:
case STATUS_PLAYER_DISABLED:
break;
case STATUS_SIMPLE:
2020-11-16 19:20:56 +00:00
{
if (pVehicle->m_pCurGroundEntity && CBridge::ThisIsABridgeObjectMovingUp(pVehicle->m_pCurGroundEntity->GetModelIndex()))
pVehicle->SetStatus(STATUS_PHYSICS);
CColPoint colPoint;
CEntity* pEntity;
2021-01-08 09:41:39 +00:00
if ((pVehicle->m_randomSeed & 0x3F) == (CTimer::GetFrameCounter() & 0x3F) &&
2020-11-16 19:20:56 +00:00
!CWorld::ProcessVerticalLine(pVehicle->GetPosition(), -2.0f, colPoint, pEntity, true, false, false, false, true, false, nil)) {
debug("FLOATING CAR TURNED INTO PHYSICS CAR!\n");
pVehicle->SetStatus(STATUS_PHYSICS);
}
}
// fallthough
2019-10-06 11:25:13 +00:00
case STATUS_PHYSICS:
switch (pVehicle->AutoPilot.m_nCarMission) {
case MISSION_RAMPLAYER_FARAWAY:
if (FindSwitchDistanceClose(pVehicle) > (FindPlayerCoors() - pVehicle->GetPosition()).Magnitude2D() ||
pVehicle->AutoPilot.m_bIgnorePathfinding) {
pVehicle->AutoPilot.m_nCarMission = MISSION_RAMPLAYER_CLOSE;
if (pVehicle->UsesSiren())
2019-10-06 11:25:13 +00:00
pVehicle->m_bSirenOrAlarm = true;
}
BackToCruisingIfNoWantedLevel(pVehicle);
2019-10-06 11:25:13 +00:00
break;
case MISSION_RAMPLAYER_CLOSE:
2019-10-10 21:02:55 +00:00
if (FindSwitchDistanceFar(pVehicle) >= (FindPlayerCoors() - pVehicle->GetPosition()).Magnitude2D() ||
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_bIgnorePathfinding) {
2019-10-08 20:57:21 +00:00
if (FindPlayerVehicle()) {
2019-10-06 11:25:13 +00:00
if (pVehicle->GetHasCollidedWith(FindPlayerVehicle())) {
if (pVehicle->AutoPilot.m_nTempAction != TEMPACT_TURNLEFT && pVehicle->AutoPilot.m_nTempAction != TEMPACT_TURNRIGHT) {
if (FindPlayerVehicle()->GetMoveSpeed().Magnitude() < 0.05f) {
pVehicle->AutoPilot.m_nTempAction = TEMPACT_REVERSE;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 800;
}
else {
pVehicle->AutoPilot.m_nTempAction = TEMPACT_REVERSE;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 50;
}
}
}
}
if (FindPlayerVehicle() && FindPlayerVehicle()->GetMoveSpeed().Magnitude() < 0.05f)
#ifdef FIX_BUGS
pVehicle->m_nTimeBlocked += CTimer::GetTimeStepInMilliseconds();
#else
pVehicle->m_nTimeBlocked += 1000.0f / 60.0f * CTimer::GetTimeStep();
#endif
else
pVehicle->m_nTimeBlocked = 0;
if (!FindPlayerVehicle() || FindPlayerVehicle()->IsUpsideDown() ||
2019-10-10 21:02:55 +00:00
FindPlayerVehicle()->GetMoveSpeed().Magnitude() < 0.05f && pVehicle->m_nTimeBlocked > TIME_COPS_WAIT_TO_EXIT_AFTER_STOPPING) {
2019-10-06 11:25:13 +00:00
if (pVehicle->bIsLawEnforcer &&
(pVehicle->GetModelIndex() != MI_RHINO || pVehicle->m_randomSeed > 10000) &&
2019-10-08 20:57:21 +00:00
(FindPlayerCoors() - pVehicle->GetPosition()).Magnitude2D() < 10.0f) {
2019-10-06 11:25:13 +00:00
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCruiseSpeed = 0;
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
if (FindPlayerPed()->m_pWanted->m_nWantedLevel <= 1)
pVehicle->m_bSirenOrAlarm = false;
}
}
}
2019-10-08 20:57:21 +00:00
else if (!CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, FindPlayerCoors(), true)){
pVehicle->AutoPilot.m_nCarMission = MISSION_RAMPLAYER_FARAWAY;
pVehicle->m_bSirenOrAlarm = false;
pVehicle->m_nCarHornTimer = 0;
}
if (pVehicle->bIsLawEnforcer)
MellowOutChaseSpeed(pVehicle);
BackToCruisingIfNoWantedLevel(pVehicle);
2019-10-06 11:25:13 +00:00
break;
case MISSION_BLOCKPLAYER_FARAWAY:
if (FindSwitchDistanceClose(pVehicle) > (FindPlayerCoors() - pVehicle->GetPosition()).Magnitude2D() ||
pVehicle->AutoPilot.m_bIgnorePathfinding) {
pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKPLAYER_CLOSE;
if (pVehicle->UsesSiren())
2019-10-06 11:25:13 +00:00
pVehicle->m_bSirenOrAlarm = true;
}
BackToCruisingIfNoWantedLevel(pVehicle);
2019-10-06 11:25:13 +00:00
break;
case MISSION_BLOCKPLAYER_CLOSE:
2019-10-10 21:02:55 +00:00
if (FindSwitchDistanceFar(pVehicle) >= (FindPlayerCoors() - pVehicle->GetPosition()).Magnitude2D() ||
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_bIgnorePathfinding) {
2020-05-05 17:22:13 +00:00
if (FindPlayerVehicle() && FindPlayerVehicle()->GetMoveSpeed().Magnitude() < 0.04f)
2019-10-06 11:25:13 +00:00
#ifdef FIX_BUGS
2019-10-08 20:57:21 +00:00
pVehicle->m_nTimeBlocked += CTimer::GetTimeStepInMilliseconds();
2019-10-06 11:25:13 +00:00
#else
2019-10-08 20:57:21 +00:00
pVehicle->m_nTimeBlocked += 1000.0f / 60.0f * CTimer::GetTimeStep();
2019-10-06 11:25:13 +00:00
#endif
2019-10-08 20:57:21 +00:00
else
pVehicle->m_nTimeBlocked = 0;
if (!FindPlayerVehicle() || FindPlayerVehicle()->IsUpsideDown() ||
2020-05-05 17:22:13 +00:00
FindPlayerVehicle()->GetMoveSpeed().Magnitude() < 0.04f && pVehicle->m_nTimeBlocked > TIME_COPS_WAIT_TO_EXIT_AFTER_STOPPING) {
2019-10-08 20:57:21 +00:00
if (pVehicle->bIsLawEnforcer &&
(pVehicle->GetModelIndex() != MI_RHINO || pVehicle->m_randomSeed > 10000) &&
(FindPlayerCoors() - pVehicle->GetPosition()).Magnitude2D() < 10.0f) {
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCruiseSpeed = 0;
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
if (FindPlayerPed()->m_pWanted->m_nWantedLevel <= 1)
2019-10-06 11:25:13 +00:00
pVehicle->m_bSirenOrAlarm = false;
}
}
2019-10-08 20:57:21 +00:00
}else if (!CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, FindPlayerCoors(), true)) {
pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKPLAYER_FARAWAY;
pVehicle->m_bSirenOrAlarm = false;
pVehicle->m_nCarHornTimer = 0;
}
if (pVehicle->bIsLawEnforcer)
MellowOutChaseSpeed(pVehicle);
BackToCruisingIfNoWantedLevel(pVehicle);
2019-10-06 11:25:13 +00:00
break;
case MISSION_GOTOCOORDS:
if ((pVehicle->AutoPilot.m_vecDestinationCoors - pVehicle->GetPosition()).Magnitude2D() < FindSwitchDistanceClose(pVehicle) ||
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_bIgnorePathfinding)
pVehicle->AutoPilot.m_nCarMission = MISSION_GOTOCOORDS_STRAIGHT;
break;
case MISSION_GOTOCOORDS_STRAIGHT:
{
float distance = (pVehicle->AutoPilot.m_vecDestinationCoors - pVehicle->GetPosition()).Magnitude2D();
if ((pVehicle->bIsAmbulanceOnDuty || pVehicle->bIsFireTruckOnDuty) && distance < 20.0f)
pVehicle->AutoPilot.m_nCarMission = MISSION_EMERGENCYVEHICLE_STOP;
if (distance < 3.0f){
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
if (pVehicle->bParking) {
TellOccupantsToLeaveCar(pVehicle);
pVehicle->bParking = false;
}
2019-10-06 11:25:13 +00:00
}
2020-05-05 11:40:35 +00:00
else if (distance > FindSwitchDistanceFarNormalVehicle(pVehicle) && !pVehicle->AutoPilot.m_bIgnorePathfinding && (CTimer::GetFrameCounter() & 7) == 0){
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
pVehicle->AutoPilot.m_nCarMission = (CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, pVehicle->AutoPilot.m_vecDestinationCoors, true)) ?
MISSION_GOTOCOORDS_STRAIGHT : MISSION_GOTOCOORDS;
}
break;
}
case MISSION_EMERGENCYVEHICLE_STOP:
if (pVehicle->GetMoveSpeed().Magnitude2D() < 0.01f){
if (pVehicle->bIsAmbulanceOnDuty){
float distance = 30.0f;
if (gAccidentManager.FindNearestAccident(pVehicle->AutoPilot.m_vecDestinationCoors, &distance)){
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCarMission = MISSION_STOP_FOREVER;
}else{
CCarCtrl::JoinCarWithRoadSystem(pVehicle);
pVehicle->AutoPilot.m_nCarMission = MISSION_CRUISE;
pVehicle->m_bSirenOrAlarm = false;
pVehicle->AutoPilot.m_nCruiseSpeed = 17;
if (pVehicle->bIsAmbulanceOnDuty){
pVehicle->bIsAmbulanceOnDuty = false;
--CCarCtrl::NumAmbulancesOnDuty;
}
}
}
if (pVehicle->bIsFireTruckOnDuty) {
float distance = 30.0f;
if (gFireManager.FindNearestFire(pVehicle->AutoPilot.m_vecDestinationCoors, &distance)) {
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCarMission = MISSION_STOP_FOREVER;
}
else {
CCarCtrl::JoinCarWithRoadSystem(pVehicle);
pVehicle->AutoPilot.m_nCarMission = MISSION_CRUISE;
pVehicle->m_bSirenOrAlarm = false;
pVehicle->AutoPilot.m_nCruiseSpeed = 17;
if (pVehicle->bIsFireTruckOnDuty) {
pVehicle->bIsFireTruckOnDuty = false;
--CCarCtrl::NumFiretrucksOnDuty;
}
}
}
}
break;
case MISSION_GOTOCOORDS_ACCURATE:
if ((pVehicle->AutoPilot.m_vecDestinationCoors - pVehicle->GetPosition()).Magnitude2D() < FindSwitchDistanceClose(pVehicle) ||
pVehicle->AutoPilot.m_bIgnorePathfinding)
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nCarMission = MISSION_GOTO_COORDS_STRAIGHT_ACCURATE;
break;
case MISSION_GOTO_COORDS_STRAIGHT_ACCURATE:
{
float distance = (pVehicle->AutoPilot.m_vecDestinationCoors - pVehicle->GetPosition()).Magnitude2D();
if (distance < 1.0f) {
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
if (pVehicle->bParking) {
TellOccupantsToLeaveCar(pVehicle);
pVehicle->bParking = false;
}
2019-10-06 11:25:13 +00:00
}
2020-05-05 11:40:35 +00:00
else if (distance > FindSwitchDistanceFarNormalVehicle(pVehicle) && !pVehicle->AutoPilot.m_bIgnorePathfinding && (CTimer::GetFrameCounter() & 7) == 0) {
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
pVehicle->AutoPilot.m_nCarMission = (CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, pVehicle->AutoPilot.m_vecDestinationCoors, true)) ?
2019-10-13 17:13:39 +00:00
MISSION_GOTO_COORDS_STRAIGHT_ACCURATE : MISSION_GOTOCOORDS_ACCURATE;
2019-10-06 11:25:13 +00:00
}
break;
}
case MISSION_RAMCAR_FARAWAY:
if (pVehicle->AutoPilot.m_pTargetCar){
if ((pVehicle->GetPosition() - pVehicle->AutoPilot.m_pTargetCar->GetPosition()).Magnitude2D() < FindSwitchDistanceClose(pVehicle) ||
pVehicle->AutoPilot.m_bIgnorePathfinding)
pVehicle->AutoPilot.m_nCarMission = MISSION_RAMCAR_CLOSE;
}else{
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
}
break;
case MISSION_RAMCAR_CLOSE:
if (pVehicle->AutoPilot.m_pTargetCar){
#ifdef FIX_BUGS // btw fixed in SA
if (FindPlayerVehicle() == pVehicle->AutoPilot.m_pTargetCar)
#endif
BackToCruisingIfNoWantedLevel(pVehicle);
2019-10-06 11:25:13 +00:00
if ((pVehicle->AutoPilot.m_pTargetCar->GetPosition() - pVehicle->GetPosition()).Magnitude2D() <= FindSwitchDistanceFar(pVehicle) ||
pVehicle->AutoPilot.m_bIgnorePathfinding){
if (pVehicle->GetHasCollidedWith(pVehicle->AutoPilot.m_pTargetCar)){
if (pVehicle->GetMoveSpeed().Magnitude() < 0.04f){
pVehicle->AutoPilot.m_nTempAction = TEMPACT_REVERSE;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 800;
}
}
}else{
pVehicle->AutoPilot.m_nCarMission = MISSION_RAMCAR_FARAWAY;
CCarCtrl::JoinCarWithRoadSystem(pVehicle);
}
}else{
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
}
break;
case MISSION_BLOCKCAR_FARAWAY:
if (pVehicle->AutoPilot.m_pTargetCar){
if ((pVehicle->AutoPilot.m_pTargetCar->GetPosition() - pVehicle->GetPosition()).Magnitude2D() < FindSwitchDistanceClose(pVehicle) ||
pVehicle->AutoPilot.m_bIgnorePathfinding){
pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKCAR_CLOSE;
if (pVehicle->UsesSiren())
2019-10-06 11:25:13 +00:00
pVehicle->m_bSirenOrAlarm = true;
}
}else{
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
}
break;
case MISSION_BLOCKCAR_CLOSE:
if (pVehicle->AutoPilot.m_pTargetCar){
if ((pVehicle->AutoPilot.m_pTargetCar->GetPosition() - pVehicle->GetPosition()).Magnitude2D() > FindSwitchDistanceFar(pVehicle) &&
!pVehicle->AutoPilot.m_bIgnorePathfinding){
pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKCAR_FARAWAY;
pVehicle->m_bSirenOrAlarm = false;
pVehicle->m_nCarHornTimer = 0;
CCarCtrl::JoinCarWithRoadSystem(pVehicle);
}
}else{
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
}
break;
case MISSION_ATTACKPLAYER:
if (pVehicle->bIsLawEnforcer)
MellowOutChaseSpeedBoat(pVehicle);
BackToCruisingIfNoWantedLevel(pVehicle);
break;
case MISSION_SLOWLY_DRIVE_TOWARDS_PLAYER_1:
if (((CVector2D)(pVehicle->AutoPilot.m_vecDestinationCoors) - pVehicle->GetPosition()).Magnitude() < 1.5f)
pVehicle->AutoPilot.m_nCarMission = MISSION_SLOWLY_DRIVE_TOWARDS_PLAYER_2;
BackToCruisingIfNoWantedLevel(pVehicle);
break;
case MISSION_SLOWLY_DRIVE_TOWARDS_PLAYER_2:
{
float distance = ((CVector2D)FindPlayerCoors() - pVehicle->GetPosition()).Magnitude();
if (distance < 13.0f) {
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCruiseSpeed = 0;
pVehicle->AutoPilot.m_nCarMission = MISSION_STOP_FOREVER;
}
if (distance > 70.0f || FindPlayerPed()->m_pWanted->m_bIgnoredByEveryone ||
(FindPlayerPed()->m_pWanted->m_nWantedLevel == 0 || FindPlayerPed()->m_pWanted->m_bIgnoredByCops || CCullZones::NoPolice())) {
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCruiseSpeed = 0;
pVehicle->AutoPilot.m_nCarMission = MISSION_STOP_FOREVER;
}
break;
}
case MISSION_BLOCKPLAYER_FORWARDANDBACK:
{
CVector2D diff = (CVector2D)FindPlayerCoors() - pVehicle->GetPosition();
float distance = Max(0.001f, diff.Magnitude());
if (!FindPlayerVehicle() || DotProduct2D(CVector2D(diff.x / distance, diff.y / distance), FindPlayerSpeed()) > 0.05f)
pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKPLAYER_CLOSE;
BackToCruisingIfNoWantedLevel(pVehicle);
2020-05-23 17:06:52 +00:00
break;
}
2019-10-06 11:25:13 +00:00
default:
if (pVehicle->bIsLawEnforcer && FindPlayerPed()->m_pWanted->m_nWantedLevel > 0 && !CCullZones::NoPolice()){
if (ABS(FindPlayerCoors().x - pVehicle->GetPosition().x) > 10.0f ||
ABS(FindPlayerCoors().y - pVehicle->GetPosition().y) > 10.0f){
pVehicle->AutoPilot.m_nCruiseSpeed = FindPoliceCarSpeedForWantedLevel(pVehicle);
pVehicle->SetStatus(STATUS_PHYSICS);
2020-05-05 11:40:35 +00:00
pVehicle->AutoPilot.m_nCarMission =
2020-05-17 18:43:11 +00:00
pVehicle->GetVehicleAppearance() == VEHICLE_APPEARANCE_BOAT ? FindPoliceBoatMissionForWantedLevel() : FindPoliceCarMissionForWantedLevel();
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
pVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
}else if (pVehicle->AutoPilot.m_nCarMission == MISSION_CRUISE){
pVehicle->SetStatus(STATUS_PHYSICS);
2019-10-06 11:25:13 +00:00
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCruiseSpeed = 0;
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
if (FindPlayerPed()->m_pWanted->m_nWantedLevel <= 1)
pVehicle->m_bSirenOrAlarm = false;
}
}
break;
}
break;
case STATUS_ABANDONED:
case STATUS_WRECKED:
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
pVehicle->AutoPilot.m_nCruiseSpeed = 0;
break;
}
if (pVehicle->bIsLawEnforcer && FindPlayerPed()->m_pWanted->m_nWantedLevel >= 1 && CCullZones::PoliceAbandonCars()) {
TellOccupantsToLeaveCar(pVehicle);
pVehicle->AutoPilot.m_nCruiseSpeed = 0;
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
}
2019-10-06 11:25:13 +00:00
float flatSpeed = pVehicle->GetMoveSpeed().MagnitudeSqr2D();
if (flatSpeed > SQR(0.018f)){
2019-10-10 21:02:55 +00:00
pVehicle->AutoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds();
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds();
}
if (pVehicle->GetStatus() == STATUS_PHYSICS && pVehicle->AutoPilot.m_nTempAction == TEMPACT_NONE){
2019-10-06 11:25:13 +00:00
if (pVehicle->AutoPilot.m_nCarMission != MISSION_NONE){
if (pVehicle->AutoPilot.m_nCarMission != MISSION_STOP_FOREVER &&
pVehicle->AutoPilot.m_nCarMission != MISSION_BLOCKPLAYER_HANDBRAKESTOP &&
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nCruiseSpeed != 0 &&
(pVehicle->VehicleCreatedBy != RANDOM_VEHICLE || pVehicle->AutoPilot.m_nCarMission != MISSION_CRUISE)){
2020-05-05 11:40:35 +00:00
if (pVehicle->AutoPilot.m_nDrivingStyle != DRIVINGSTYLE_STOP_FOR_CARS
&& pVehicle->AutoPilot.m_nDrivingStyle != DRIVINGSTYLE_STOP_FOR_CARS_IGNORE_LIGHTS ||
pVehicle->VehicleCreatedBy == MISSION_VEHICLE
2020-05-05 11:40:35 +00:00
) {
2019-10-06 11:25:13 +00:00
if (CTimer::GetTimeInMilliseconds() - pVehicle->m_nLastTimeCollided > 500)
pVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds();
if (flatSpeed < SQR(0.018f) && CTimer::GetTimeInMilliseconds() - pVehicle->AutoPilot.m_nAntiReverseTimer > 2000){
pVehicle->AutoPilot.m_nTempAction = TEMPACT_REVERSE;
if (pVehicle->AutoPilot.m_nCarMission != MISSION_NONE &&
pVehicle->AutoPilot.m_nCarMission != MISSION_CRUISE || pVehicle->VehicleCreatedBy == MISSION_VEHICLE)
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 1500;
else
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 750;
pVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds();
if (pVehicle->VehicleCreatedBy == RANDOM_VEHICLE)
2020-04-19 16:34:08 +00:00
pVehicle->AutoPilot.m_nDrivingStyle = Max(DRIVINGSTYLE_AVOID_CARS, pVehicle->AutoPilot.m_nDrivingStyle);
2019-10-06 11:25:13 +00:00
pVehicle->PlayCarHorn();
}
}
}
}
}
if ((pVehicle->m_randomSeed & 7) == 0){
2019-10-10 21:02:55 +00:00
if (CTimer::GetTimeInMilliseconds() - pVehicle->AutoPilot.m_nTimeToStartMission > 30000 &&
CTimer::GetPreviousTimeInMilliseconds() - pVehicle->AutoPilot.m_nTimeToStartMission <= 30000 &&
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nCarMission == MISSION_CRUISE &&
!CTrafficLights::ShouldCarStopForBridge(pVehicle)){
pVehicle->SetStatus(STATUS_PHYSICS);
2019-10-06 11:25:13 +00:00
CCarCtrl::SwitchVehicleToRealPhysics(pVehicle);
pVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
pVehicle->AutoPilot.m_nTempAction = TEMPACT_REVERSE;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 400;
}
}
if (pVehicle->bIsLawEnforcer) {
if (pVehicle->AutoPilot.m_nCarMission == MISSION_RAMPLAYER_FARAWAY ||
pVehicle->AutoPilot.m_nCarMission == MISSION_RAMPLAYER_CLOSE) {
2020-05-17 18:43:11 +00:00
if (FindPlayerVehicle() && FindPlayerVehicle()->GetVehicleAppearance() == VEHICLE_APPEARANCE_BIKE)
pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKPLAYER_FARAWAY;
}
}
if (pVehicle->GetUp().z < -0.7f){
2019-10-06 11:25:13 +00:00
pVehicle->AutoPilot.m_nTempAction = TEMPACT_WAIT;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 1000;
}
if (pVehicle->AutoPilot.m_nTempAction == TEMPACT_NONE){
switch (pVehicle->AutoPilot.m_nCarMission){
case MISSION_RAMPLAYER_FARAWAY:
case MISSION_RAMPLAYER_CLOSE:
case MISSION_BLOCKPLAYER_FARAWAY:
case MISSION_BLOCKPLAYER_CLOSE:
2019-10-10 21:02:55 +00:00
if (FindPlayerVehicle() && FindPlayerSpeed().Magnitude() > pVehicle->GetMoveSpeed().Magnitude()){
2019-10-06 11:25:13 +00:00
if (FindPlayerSpeed().Magnitude() > 0.1f){
if (DotProduct2D(FindPlayerVehicle()->GetForward(), pVehicle->GetForward()) > 0.0f){
CVector2D dist = pVehicle->GetPosition() - FindPlayerCoors();
CVector2D speed = FindPlayerSpeed();
if (0.5f * dist.Magnitude() * speed.Magnitude() < DotProduct2D(dist, speed)){
if ((FindPlayerCoors() - pVehicle->GetPosition()).Magnitude() > 12.0f){
pVehicle->AutoPilot.m_nTempAction = TEMPACT_WAIT;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 500;
}
}
}
}
}
break;
2020-05-11 23:24:57 +00:00
default: break;
2019-10-06 11:25:13 +00:00
}
}
if (pVehicle->pDriver && pVehicle->pDriver->m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS){
if ((pVehicle->GetPosition() - FindPlayerCoors()).Magnitude() < 15.0f){
if (!FindPlayerVehicle() || pVehicle->GetHasCollidedWith(FindPlayerVehicle())){
pVehicle->AutoPilot.m_nTempAction = TEMPACT_WAIT;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 3000;
}
}
}
if (pVehicle->m_bSirenOrAlarm){
if ((uint8)(pVehicle->m_randomSeed ^ CGeneral::GetRandomNumber()) == 0xAD)
pVehicle->m_nCarHornTimer = 45;
}
float target = 1.0f;
if (pVehicle->AutoPilot.m_nCarMission == MISSION_CRUISE)
target = CCarCtrl::FindSpeedMultiplierWithSpeedFromNodes(pVehicle->AutoPilot.m_nCruiseSpeedMultiplierType);
float change = CTimer::GetTimeStep() * 0.01f;
if (Abs(pVehicle->AutoPilot.m_fCruiseSpeedMultiplier - target) < change)
pVehicle->AutoPilot.m_fCruiseSpeedMultiplier = target;
else if (pVehicle->AutoPilot.m_fCruiseSpeedMultiplier > target)
pVehicle->AutoPilot.m_fCruiseSpeedMultiplier -= change;
else
pVehicle->AutoPilot.m_fCruiseSpeedMultiplier += change;
if (pVehicle->bIsLawEnforcer && FindPlayerPed()->m_pWanted->m_nWantedLevel > 0) {
if (!FindPlayerVehicle() ||
2020-05-17 18:43:11 +00:00
FindPlayerVehicle()->GetVehicleAppearance() == VEHICLE_APPEARANCE_CAR ||
FindPlayerVehicle()->GetVehicleAppearance() == VEHICLE_APPEARANCE_BIKE) {
if (pVehicle->GetVehicleAppearance() == VEHICLE_APPEARANCE_BOAT) {
pVehicle->AutoPilot.m_nTempAction = TEMPACT_WAIT;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 1000;
}
}
2020-05-17 18:43:11 +00:00
else if (FindPlayerVehicle()->GetVehicleAppearance() == VEHICLE_APPEARANCE_BOAT) {
if (pVehicle->GetVehicleAppearance() == VEHICLE_APPEARANCE_CAR ||
pVehicle->GetVehicleAppearance() == VEHICLE_APPEARANCE_BIKE) {
pVehicle->AutoPilot.m_nTempAction = TEMPACT_WAIT;
pVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 1000;
}
}
}
2019-10-06 11:25:13 +00:00
}
2019-08-11 17:11:54 +00:00
void CCarAI::CarHasReasonToStop(CVehicle* pVehicle)
{
pVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds();
}
2019-10-10 21:02:55 +00:00
float CCarAI::GetCarToGoToCoors(CVehicle* pVehicle, CVector* pTarget)
{
if (pVehicle->AutoPilot.m_nCarMission != MISSION_GOTOCOORDS && pVehicle->AutoPilot.m_nCarMission != MISSION_GOTOCOORDS_STRAIGHT){
pVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
pVehicle->AutoPilot.m_nCruiseSpeed = 20;
pVehicle->AutoPilot.m_nAntiReverseTimer = CTimer::GetTimeInMilliseconds();
pVehicle->SetStatus(STATUS_PHYSICS);
2019-10-10 21:02:55 +00:00
pVehicle->AutoPilot.m_nCarMission = (CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, *pTarget, false)) ?
MISSION_GOTOCOORDS_STRAIGHT : MISSION_GOTOCOORDS;
}else if (Abs(pTarget->x - pVehicle->AutoPilot.m_vecDestinationCoors.x) > 2.0f ||
2019-10-12 09:16:39 +00:00
Abs(pTarget->y - pVehicle->AutoPilot.m_vecDestinationCoors.y) > 2.0f){
2019-10-10 21:02:55 +00:00
pVehicle->AutoPilot.m_vecDestinationCoors = *pTarget;
}
return (pVehicle->GetPosition() - *pTarget).Magnitude2D();
}
float CCarAI::GetCarToParkAtCoors(CVehicle* pVehicle, CVector* pTarget)
{
GetCarToGoToCoors(pVehicle, pTarget);
pVehicle->bParking = true;
pVehicle->AutoPilot.m_nCruiseSpeed = 10;
return (pVehicle->GetPosition() - *pTarget).Magnitude2D();
}
2020-05-05 11:40:35 +00:00
void CCarAI::AddPoliceCarOccupants(CVehicle* pVehicle)
2019-10-10 21:02:55 +00:00
{
if (pVehicle->bOccupantsHaveBeenGenerated)
return;
2020-05-05 11:40:35 +00:00
pVehicle->bOccupantsHaveBeenGenerated = true;
2019-10-10 21:02:55 +00:00
switch (pVehicle->GetModelIndex()){
case MI_FBIRANCH:
2019-10-10 21:02:55 +00:00
case MI_ENFORCER:
pVehicle->SetUpDriver();
for (int i = 0; i < 3; i++)
pVehicle->SetupPassenger(i);
return;
case MI_POLICE:
case MI_RHINO:
case MI_BARRACKS:
pVehicle->SetUpDriver();
if (FindPlayerPed()->m_pWanted->m_nWantedLevel > 1)
pVehicle->SetupPassenger(0);
return;
case MI_PREDATOR:
pVehicle->SetUpDriver();
return;
case MI_VICECHEE:
{
2020-05-08 20:29:43 +00:00
pVehicle->SetUpDriver()->bMiamiViceCop = true;
pVehicle->SetupPassenger(0)->bMiamiViceCop = true;
CPopulation::NumMiamiViceCops += 2;
CCarCtrl::MiamiViceCycle = (CCarCtrl::MiamiViceCycle + 1) % 4;
CCarCtrl::LastTimeMiamiViceGenerated = CTimer::GetTimeInMilliseconds();
return;
}
2019-10-10 21:02:55 +00:00
default:
return;
}
}
void CCarAI::AddAmbulanceOccupants(CVehicle* pVehicle)
{
pVehicle->SetUpDriver();
pVehicle->SetupPassenger(1);
}
void CCarAI::AddFiretruckOccupants(CVehicle* pVehicle)
{
pVehicle->SetUpDriver();
pVehicle->SetupPassenger(0);
}
void CCarAI::TellOccupantsToLeaveCar(CVehicle* pVehicle)
{
if (pVehicle->pDriver){
pVehicle->pDriver->SetObjective(OBJECTIVE_LEAVE_CAR, pVehicle);
2020-05-05 11:40:35 +00:00
if (pVehicle->GetModelIndex() == MI_AMBULAN)
2019-10-10 21:02:55 +00:00
pVehicle->pDriver->Say(SOUND_PED_LEAVE_VEHICLE);
}
2020-05-05 11:40:35 +00:00
int timer = 100;
2019-10-10 21:02:55 +00:00
for (int i = 0; i < pVehicle->m_nNumMaxPassengers; i++){
2020-05-05 11:40:35 +00:00
if (pVehicle->pPassengers[i]) {
pVehicle->pPassengers[i]->m_leaveCarTimer = timer;
pVehicle->pPassengers[i]->SetObjective(OBJECTIVE_LEAVE_CAR, pVehicle);
timer += CGeneral::GetRandomNumberInRange(200, 400);
}
}
}
void CCarAI::TellOccupantsToFleeCar(CVehicle* pVehicle)
{
if (pVehicle->pDriver && !pVehicle->pDriver->IsPlayer()) {
pVehicle->pDriver->SetObjective(OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE);
if (pVehicle->GetModelIndex() != MI_FIRETRUCK && pVehicle->GetModelIndex() == MI_AMBULAN)
pVehicle->pDriver->Say(SOUND_PED_LEAVE_VEHICLE);
}
int timer = 100;
for (int i = 0; i < pVehicle->m_nNumMaxPassengers; i++) {
if (pVehicle->pPassengers[i]) {
pVehicle->pPassengers[i]->m_leaveCarTimer = timer;
pVehicle->pPassengers[i]->SetObjective(OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE);
timer += CGeneral::GetRandomNumberInRange(200, 400);
2020-05-05 11:40:35 +00:00
}
}
}
2019-10-10 21:02:55 +00:00
void CCarAI::TellCarToRamOtherCar(CVehicle* pVehicle, CVehicle* pTarget)
{
pVehicle->AutoPilot.m_pTargetCar = pTarget;
pTarget->RegisterReference((CEntity**)&pVehicle->AutoPilot.m_pTargetCar);
pVehicle->AutoPilot.m_nCarMission = MISSION_RAMCAR_FARAWAY;
pVehicle->bEngineOn = true;
2020-04-19 16:34:08 +00:00
pVehicle->AutoPilot.m_nCruiseSpeed = Max(6, pVehicle->AutoPilot.m_nCruiseSpeed);
2019-10-10 21:02:55 +00:00
}
void CCarAI::TellCarToBlockOtherCar(CVehicle* pVehicle, CVehicle* pTarget)
{
pVehicle->AutoPilot.m_pTargetCar = pTarget;
pTarget->RegisterReference((CEntity**)&pVehicle->AutoPilot.m_pTargetCar);
pVehicle->AutoPilot.m_nCarMission = MISSION_BLOCKCAR_FARAWAY;
pVehicle->bEngineOn = true;
2020-04-19 16:34:08 +00:00
pVehicle->AutoPilot.m_nCruiseSpeed = Max(6, pVehicle->AutoPilot.m_nCruiseSpeed);
2019-10-10 21:02:55 +00:00
}
2020-05-05 11:40:35 +00:00
2020-12-07 00:59:17 +00:00
uint8 CCarAI::FindPoliceCarMissionForWantedLevel()
2019-10-10 21:02:55 +00:00
{
switch (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->m_nWantedLevel){
case 0:
case 1: return MISSION_BLOCKPLAYER_FARAWAY;
case 2: return (CGeneral::GetRandomNumber() & 3) >= 3 ? MISSION_RAMPLAYER_FARAWAY : MISSION_BLOCKPLAYER_FARAWAY;
case 3: return (CGeneral::GetRandomNumber() & 3) >= 2 ? MISSION_RAMPLAYER_FARAWAY : MISSION_BLOCKPLAYER_FARAWAY;
case 4:
case 5:
case 6: return (CGeneral::GetRandomNumber() & 3) >= 1 ? MISSION_RAMPLAYER_FARAWAY : MISSION_BLOCKPLAYER_FARAWAY;
default: return MISSION_BLOCKPLAYER_FARAWAY;
}
}
2020-12-07 00:59:17 +00:00
uint8 CCarAI::FindPoliceBoatMissionForWantedLevel()
{
switch (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->m_nWantedLevel) {
case 0:
case 1: return MISSION_BLOCKPLAYER_FARAWAY;
case 2:
case 3:
case 4:
case 5:
case 6: return MISSION_ATTACKPLAYER;
default: return MISSION_BLOCKPLAYER_FARAWAY;
}
}
2019-10-10 21:02:55 +00:00
int32 CCarAI::FindPoliceCarSpeedForWantedLevel(CVehicle* pVehicle)
{
switch (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->m_nWantedLevel) {
case 0: return CGeneral::GetRandomNumberInRange(12, 16);
case 1: return 25;
case 2: return 34;
case 3: return GAME_SPEED_TO_CARAI_SPEED * pVehicle->pHandling->Transmission.fMaxVelocity * 0.9f;
case 4: return GAME_SPEED_TO_CARAI_SPEED * pVehicle->pHandling->Transmission.fMaxVelocity * 1.2f;
case 5: return GAME_SPEED_TO_CARAI_SPEED * pVehicle->pHandling->Transmission.fMaxVelocity * 1.25f;
case 6: return GAME_SPEED_TO_CARAI_SPEED * pVehicle->pHandling->Transmission.fMaxVelocity * 1.3f;
default: return 0;
}
}
void CCarAI::MellowOutChaseSpeed(CVehicle* pVehicle)
{
if (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->m_nWantedLevel == 1){
float distanceToPlayer = (pVehicle->GetPosition() - FindPlayerCoors()).Magnitude();
if (FindPlayerVehicle()){
if (distanceToPlayer < 10.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 15;
else if (distanceToPlayer < 20.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 22;
else
pVehicle->AutoPilot.m_nCruiseSpeed = 25;
}else{
if (distanceToPlayer < 20.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 5;
else if (distanceToPlayer < 40.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 13;
else
pVehicle->AutoPilot.m_nCruiseSpeed = 25;
}
}else if (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->m_nWantedLevel == 2){
float distanceToPlayer = (pVehicle->GetPosition() - FindPlayerCoors()).Magnitude();
if (FindPlayerVehicle()) {
if (distanceToPlayer < 10.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 27;
else if (distanceToPlayer < 20.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 30;
else
pVehicle->AutoPilot.m_nCruiseSpeed = 34;
}
else {
if (distanceToPlayer < 20.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 5;
else if (distanceToPlayer < 40.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = 18;
else
pVehicle->AutoPilot.m_nCruiseSpeed = 34;
}
}
if (!FindPlayerVehicle() && FindPlayerPed()->GetMoveSpeed().Magnitude() < 0.07f) {
if ((FindPlayerCoors() - pVehicle->GetPosition()).Magnitude() < 30.0f)
pVehicle->AutoPilot.m_nCruiseSpeed = Min(10, pVehicle->AutoPilot.m_nCruiseSpeed);
}
2019-10-10 21:02:55 +00:00
}
void CCarAI::MellowOutChaseSpeedBoat(CVehicle* pVehicle)
{
switch (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->m_nWantedLevel) {
case 0: pVehicle->AutoPilot.m_nCruiseSpeed = 8; break;
case 1: pVehicle->AutoPilot.m_nCruiseSpeed = 10; break;
case 2: pVehicle->AutoPilot.m_nCruiseSpeed = 15; break;
case 3: pVehicle->AutoPilot.m_nCruiseSpeed = 20; break;
case 4: pVehicle->AutoPilot.m_nCruiseSpeed = 25; break;
case 5: pVehicle->AutoPilot.m_nCruiseSpeed = 30; break;
case 6: pVehicle->AutoPilot.m_nCruiseSpeed = 40; break;
}
}
2019-10-10 21:02:55 +00:00
void CCarAI::MakeWayForCarWithSiren(CVehicle *pVehicle)
{
float flatSpeed = pVehicle->GetMoveSpeed().Magnitude2D();
if (flatSpeed < 0.1f)
return;
CVector2D forward = pVehicle->GetMoveSpeed() / flatSpeed;
float projection = flatSpeed * 45 + 20;
int i = CPools::GetVehiclePool()->GetSize();
while (--i >= 0) {
2019-10-10 21:02:55 +00:00
CVehicle* vehicle = CPools::GetVehiclePool()->GetSlot(i);
if (!vehicle)
continue;
2020-05-05 11:40:35 +00:00
if (!vehicle->IsCar() && !vehicle->IsBike())
2019-10-10 21:02:55 +00:00
continue;
if (vehicle->GetStatus() != STATUS_SIMPLE && vehicle->GetStatus() != STATUS_PHYSICS)
2019-10-10 21:02:55 +00:00
continue;
if (vehicle->VehicleCreatedBy != RANDOM_VEHICLE)
continue;
if (vehicle->bIsLawEnforcer || vehicle->bIsAmbulanceOnDuty || vehicle->bIsFireTruckOnDuty)
continue;
if (vehicle == pVehicle)
continue;
if (vehicle->AutoPilot.m_nDrivingStyle == DRIVINGSTYLE_AVOID_CARS)
return;
2019-10-10 21:02:55 +00:00
if (Abs(pVehicle->GetPosition().z - vehicle->GetPosition().z) >= 5.0f)
continue;
CVector2D distance = vehicle->GetPosition() - pVehicle->GetPosition();
if (distance.Magnitude() >= projection)
continue;
if (vehicle->GetMoveSpeed().Magnitude2D() <= 0.05f)
continue;
float correlation = DotProduct2D(forward, distance) / distance.Magnitude();
if (correlation <= 0.0f)
continue;
if (correlation > 0.8f && DotProduct2D(forward, vehicle->GetForward()) > 0.7f){
if (vehicle->AutoPilot.m_nTempAction != TEMPACT_SWERVELEFT && vehicle->AutoPilot.m_nTempAction != TEMPACT_SWERVERIGHT){
vehicle->AutoPilot.m_nTempAction = (distance.x * forward.y - distance.y * forward.x > 0.0f) ?
TEMPACT_SWERVELEFT : TEMPACT_SWERVERIGHT;
vehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2000;
}
vehicle->SetStatus(STATUS_PHYSICS);
2019-10-10 21:02:55 +00:00
}else{
if (DotProduct2D(vehicle->GetMoveSpeed(), distance) < 0.0f && vehicle->AutoPilot.m_nTempAction != TEMPACT_WAIT){
vehicle->AutoPilot.m_nTempAction = TEMPACT_WAIT;
vehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2000;
}
}
}
}