re3/src/core/Wanted.cpp

506 lines
10 KiB
C++
Raw Normal View History

2019-06-14 23:34:19 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2019-07-12 16:01:22 +00:00
#include "Pools.h"
#include "ModelIndices.h"
#include "Timer.h"
#include "World.h"
#include "ZoneCull.h"
#include "Darkel.h"
#include "DMAudio.h"
2020-03-29 15:26:23 +00:00
#include "CopPed.h"
2019-06-14 23:34:19 +00:00
#include "Wanted.h"
2020-03-29 15:26:23 +00:00
#include "General.h"
2019-06-26 21:31:12 +00:00
2020-04-17 05:54:14 +00:00
int32 CWanted::MaximumWantedLevel = 6;
int32 CWanted::nMaximumWantedLevel = 9600;
// --MIAMI: File done except stats
2019-07-04 20:31:21 +00:00
2019-07-12 16:01:22 +00:00
void
CWanted::Initialise()
{
m_nChaos = 0;
m_nMinChaos = 0;
2019-07-12 16:01:22 +00:00
m_nLastUpdateTime = 0;
m_nLastWantedLevelChange = 0;
m_nLastTimeSuspended = 0;
2019-07-12 16:01:22 +00:00
m_CurrentCops = 0;
m_MaxCops = 0;
m_MaximumLawEnforcerVehicles = 0;
m_RoadblockDensity = 0;
m_bIgnoredByCops = false;
m_bIgnoredByEveryone = false;
m_bSwatRequired = false;
m_bFbiRequired = false;
m_bArmyRequired = false;
m_fCrimeSensitivity = 1.0f;
m_nWantedLevel = 0;
m_nMinWantedLevel = 0;
2020-03-29 15:26:23 +00:00
m_CopsBeatingSuspect = 0;
for (int i = 0; i < ARRAY_SIZE(m_pCops); i++)
2019-07-12 16:01:22 +00:00
m_pCops[i] = nil;
2020-03-29 15:26:23 +00:00
ClearQdCrimes();
2019-07-12 16:01:22 +00:00
}
2020-05-08 20:29:43 +00:00
bool
CWanted::AreMiamiViceRequired()
{
return m_nWantedLevel >= 3;
}
2019-07-12 16:01:22 +00:00
bool
CWanted::AreSwatRequired()
2019-06-26 21:31:12 +00:00
{
2019-07-26 14:29:28 +00:00
return m_nWantedLevel == 4 || m_bSwatRequired;
2019-06-26 21:31:12 +00:00
}
2019-07-12 16:01:22 +00:00
bool
CWanted::AreFbiRequired()
2019-06-26 21:31:12 +00:00
{
2019-07-26 14:29:28 +00:00
return m_nWantedLevel == 5 || m_bFbiRequired;
2019-06-26 21:31:12 +00:00
}
2019-07-12 16:01:22 +00:00
bool
CWanted::AreArmyRequired()
2019-06-26 21:31:12 +00:00
{
2019-07-26 14:29:28 +00:00
return m_nWantedLevel == 6 || m_bArmyRequired;
2019-06-26 21:31:12 +00:00
}
2019-07-12 16:01:22 +00:00
int32
CWanted::NumOfHelisRequired()
2019-06-26 21:31:12 +00:00
{
2020-03-29 15:26:23 +00:00
if (m_bIgnoredByCops || m_bIgnoredByEveryone)
2019-06-26 21:31:12 +00:00
return 0;
switch (m_nWantedLevel) {
2019-07-12 16:01:22 +00:00
case 3:
case 4:
2019-06-26 21:31:12 +00:00
return 1;
2019-07-12 16:01:22 +00:00
case 5:
case 6:
return 1;
2019-06-26 21:31:12 +00:00
default:
return 0;
2019-07-09 16:50:35 +00:00
}
2019-07-04 20:31:21 +00:00
}
2019-07-12 16:01:22 +00:00
void
CWanted::SetWantedLevel(int32 level)
2019-07-04 20:31:21 +00:00
{
2019-07-26 14:29:28 +00:00
if (level > MaximumWantedLevel)
level = MaximumWantedLevel;
2020-03-29 15:26:23 +00:00
ClearQdCrimes();
2019-07-04 20:31:21 +00:00
switch (level) {
2019-07-12 16:01:22 +00:00
case 0:
2019-07-04 20:31:21 +00:00
m_nChaos = 0;
break;
2019-07-12 16:01:22 +00:00
case 1:
m_nChaos = 70;
2019-07-04 20:31:21 +00:00
break;
2019-07-12 16:01:22 +00:00
case 2:
m_nChaos = 200;
2019-07-04 20:31:21 +00:00
break;
2019-07-12 16:01:22 +00:00
case 3:
m_nChaos = 570;
2019-07-04 20:31:21 +00:00
break;
2019-07-12 16:01:22 +00:00
case 4:
m_nChaos = 1220;
2019-07-04 20:31:21 +00:00
break;
2019-07-12 16:01:22 +00:00
case 5:
m_nChaos = 2420;
2019-07-04 20:31:21 +00:00
break;
2019-07-12 16:01:22 +00:00
case 6:
m_nChaos = 4820;
2019-07-04 20:31:21 +00:00
break;
default:
break;
}
UpdateWantedLevel();
}
2019-07-12 16:01:22 +00:00
void
CWanted::SetWantedLevelNoDrop(int32 level)
2019-07-09 16:50:35 +00:00
{
if (m_nWantedLevel < m_nMinWantedLevel)
SetWantedLevel(m_nMinWantedLevel);
2019-07-09 16:50:35 +00:00
if (level > m_nWantedLevel)
SetWantedLevel(level);
}
void
CWanted::CheatWantedLevel(int32 level)
{
SetWantedLevel(level);
UpdateWantedLevel();
}
2019-07-12 16:01:22 +00:00
void
CWanted::SetMaximumWantedLevel(int32 level)
2019-07-04 20:31:21 +00:00
{
2019-07-12 16:01:22 +00:00
switch(level){
case 0:
nMaximumWantedLevel = 0;
MaximumWantedLevel = 0;
break;
case 1:
nMaximumWantedLevel = 115;
2019-07-12 16:01:22 +00:00
MaximumWantedLevel = 1;
break;
case 2:
nMaximumWantedLevel = 365;
2019-07-12 16:01:22 +00:00
MaximumWantedLevel = 2;
break;
case 3:
nMaximumWantedLevel = 875;
2019-07-12 16:01:22 +00:00
MaximumWantedLevel = 3;
break;
case 4:
nMaximumWantedLevel = 1800;
2019-07-12 16:01:22 +00:00
MaximumWantedLevel = 4;
break;
case 5:
nMaximumWantedLevel = 3600;
2019-07-12 16:01:22 +00:00
MaximumWantedLevel = 5;
break;
case 6:
nMaximumWantedLevel = 7200;
2019-07-12 16:01:22 +00:00
MaximumWantedLevel = 6;
break;
2019-07-09 16:50:35 +00:00
}
2019-07-04 20:31:21 +00:00
}
2019-07-12 16:01:22 +00:00
void
CWanted::RegisterCrime(eCrimeType type, const CVector &coors, uint32 id, bool policeDoesntCare)
{
AddCrimeToQ(type, id, coors, false, policeDoesntCare);
}
void
CWanted::RegisterCrime_Immediately(eCrimeType type, const CVector &coors, uint32 id, bool policeDoesntCare)
{
#ifdef FIX_BUGS
if(!AddCrimeToQ(type, id, coors, true, policeDoesntCare))
#else
2019-07-12 16:01:22 +00:00
if(!AddCrimeToQ(type, id, coors, false, policeDoesntCare))
#endif
2019-07-12 16:01:22 +00:00
ReportCrimeNow(type, coors, policeDoesntCare);
}
void
CWanted::ClearQdCrimes()
{
for (int i = 0; i < 16; i++)
m_aCrimes[i].m_nType = CRIME_NONE;
}
// returns whether the crime had been reported already
bool
CWanted::AddCrimeToQ(eCrimeType type, int32 id, const CVector &coors, bool reported, bool policeDoesntCare)
{
int i;
for(i = 0; i < 16; i++)
if(m_aCrimes[i].m_nType == type && m_aCrimes[i].m_nId == id){
if(m_aCrimes[i].m_bReported)
return true;
if(reported)
m_aCrimes[i].m_bReported = reported;
return false;
}
for(i = 0; i < 16; i++)
if(m_aCrimes[i].m_nType == CRIME_NONE)
break;
if(i < 16){
m_aCrimes[i].m_nType = type;
m_aCrimes[i].m_nId = id;
m_aCrimes[i].m_vecPosn = coors;
m_aCrimes[i].m_nTime = CTimer::GetTimeInMilliseconds();
m_aCrimes[i].m_bReported = reported;
m_aCrimes[i].m_bPoliceDoesntCare = policeDoesntCare;
}
return false;
}
void
CWanted::ReportCrimeNow(eCrimeType type, const CVector &coors, bool policeDoesntCare)
{
float sensitivity, chaos;
int wantedLevelDrop;
if(CDarkel::FrenzyOnGoing())
sensitivity = m_fCrimeSensitivity*0.3f;
else
sensitivity = m_fCrimeSensitivity;
2020-04-19 16:34:08 +00:00
wantedLevelDrop = Min(CCullZones::GetWantedLevelDrop(), 100);
2019-07-12 16:01:22 +00:00
chaos = (1.0f - wantedLevelDrop/100.0f) * sensitivity;
2019-07-13 16:12:51 +00:00
if (policeDoesntCare)
chaos *= 0.333f;
2019-07-12 16:01:22 +00:00
switch(type){
case CRIME_POSSESSION_GUN:
break;
case CRIME_HIT_PED:
m_nChaos += 5.0f*chaos;
break;
case CRIME_HIT_COP:
m_nChaos += 45.0f*chaos;
break;
case CRIME_SHOOT_PED:
m_nChaos += 30.0f*chaos;
break;
case CRIME_SHOOT_COP:
m_nChaos += 80.0f*chaos;
break;
case CRIME_STEAL_CAR:
m_nChaos += 15.0f*chaos;
break;
case CRIME_RUN_REDLIGHT:
m_nChaos += 10.0f*chaos;
break;
case CRIME_RECKLESS_DRIVING:
m_nChaos += 5.0f*chaos;
break;
case CRIME_SPEEDING:
m_nChaos += 5.0f*chaos;
break;
case CRIME_RUNOVER_PED:
m_nChaos += 18.0f*chaos;
break;
case CRIME_RUNOVER_COP:
m_nChaos += 80.0f*chaos;
break;
case CRIME_SHOOT_HELI:
m_nChaos += 400.0f*chaos;
break;
case CRIME_PED_BURNED:
m_nChaos += 20.0f*chaos;
break;
case CRIME_COP_BURNED:
m_nChaos += 80.0f*chaos;
break;
case CRIME_VEHICLE_BURNED:
m_nChaos += 20.0f*chaos;
break;
case CRIME_DESTROYED_CESSNA:
m_nChaos += 500.0f*chaos;
break;
case CRIME_EXPLOSION:
m_nChaos += 25.0f * chaos;
break;
case CRIME_HIT_PED_NASTYWEAPON:
m_nChaos += 35.0f * chaos;
break;
case CRIME_HIT_COP_NASTYWEAPON:
m_nChaos += 100.0f * chaos;
break;
2019-07-12 16:01:22 +00:00
default:
// Error("Undefined crime type, RegisterCrime, Crime.cpp"); // different file for some reason
Error("Undefined crime type, RegisterCrime, Wanted.cpp");
}
m_nChaos = Max(m_nChaos, m_nMinChaos);
2019-07-12 16:01:22 +00:00
DMAudio.ReportCrime(type, coors);
UpdateWantedLevel();
}
// TODO(Miami): Stats
2019-07-12 16:01:22 +00:00
void
CWanted::UpdateWantedLevel()
2019-07-04 20:31:21 +00:00
{
int32 CurrWantedLevel = m_nWantedLevel;
2019-07-28 10:35:24 +00:00
if (m_nChaos > nMaximumWantedLevel)
m_nChaos = nMaximumWantedLevel;
if (m_nChaos >= 0 && m_nChaos < 50) {
2019-07-12 16:01:22 +00:00
m_nWantedLevel = 0;
2019-07-04 20:31:21 +00:00
m_MaximumLawEnforcerVehicles = 0;
m_MaxCops = 0;
m_RoadblockDensity = 0;
} else if (m_nChaos >= 50 && m_nChaos < 180) {
2019-07-12 16:01:22 +00:00
m_nWantedLevel = 1;
2019-07-04 20:31:21 +00:00
m_MaximumLawEnforcerVehicles = 1;
m_MaxCops = 1;
m_RoadblockDensity = 0;
} else if (m_nChaos >= 180 && m_nChaos < 550) {
2019-07-12 16:01:22 +00:00
m_nWantedLevel = 2;
2019-07-04 20:31:21 +00:00
m_MaximumLawEnforcerVehicles = 2;
m_MaxCops = 3;
m_RoadblockDensity = 0;
} else if (m_nChaos >= 550 && m_nChaos < 1200) {
2019-07-12 16:01:22 +00:00
m_nWantedLevel = 3;
2019-07-04 20:31:21 +00:00
m_MaximumLawEnforcerVehicles = 2;
m_MaxCops = 4;
m_RoadblockDensity = 12;
} else if (m_nChaos >= 1200 && m_nChaos < 2400) {
2019-07-12 16:01:22 +00:00
m_nWantedLevel = 4;
2019-07-04 20:31:21 +00:00
m_MaximumLawEnforcerVehicles = 2;
m_MaxCops = 6;
m_RoadblockDensity = 18;
} else if (m_nChaos >= 2400 && m_nChaos < 4800) {
2019-07-12 16:01:22 +00:00
m_nWantedLevel = 5;
2019-07-04 20:31:21 +00:00
m_MaximumLawEnforcerVehicles = 3;
m_MaxCops = 8;
m_RoadblockDensity = 24;
} else if (m_nChaos >= 4800) {
2019-07-12 16:01:22 +00:00
m_nWantedLevel = 6;
2019-07-04 20:31:21 +00:00
m_MaximumLawEnforcerVehicles = 3;
m_MaxCops = 10;
m_RoadblockDensity = 30;
2019-07-04 20:31:21 +00:00
}
if (CurrWantedLevel != m_nWantedLevel)
m_nLastWantedLevelChange = CTimer::GetTimeInMilliseconds();
2019-07-12 16:01:22 +00:00
}
int32
CWanted::WorkOutPolicePresence(CVector posn, float radius)
{
int i;
CPed *ped;
CVehicle *vehicle;
int numPolice = 0;
i = CPools::GetPedPool()->GetSize();
while(--i >= 0){
ped = CPools::GetPedPool()->GetSlot(i);
if(ped &&
IsPolicePedModel(ped->GetModelIndex()) &&
(posn - ped->GetPosition()).Magnitude() < radius)
numPolice++;
}
i = CPools::GetVehiclePool()->GetSize();
while(--i >= 0){
vehicle = CPools::GetVehiclePool()->GetSlot(i);
if(vehicle &&
vehicle->bIsLawEnforcer &&
IsPoliceVehicleModel(vehicle->GetModelIndex()) &&
vehicle != FindPlayerVehicle() &&
vehicle->GetStatus() != STATUS_ABANDONED && vehicle->GetStatus() != STATUS_WRECKED &&
2019-07-12 16:01:22 +00:00
(posn - vehicle->GetPosition()).Magnitude() < radius)
numPolice++;
}
return numPolice;
}
2020-03-29 15:26:23 +00:00
void
CWanted::Update(void)
{
if (CTimer::GetTimeInMilliseconds() > m_nLastTimeSuspended + 20000) {
m_nMinChaos = 0;
m_nMinWantedLevel = 0;
}
2020-03-29 15:26:23 +00:00
if (CTimer::GetTimeInMilliseconds() - m_nLastUpdateTime > 1000) {
if (m_nWantedLevel > 1) {
m_nLastUpdateTime = CTimer::GetTimeInMilliseconds();
} else {
float radius = 18.0f;
CVector playerPos = FindPlayerCoors();
if (WorkOutPolicePresence(playerPos, radius) == 0) {
m_nLastUpdateTime = CTimer::GetTimeInMilliseconds();
2020-04-19 16:34:08 +00:00
m_nChaos = Max(0, m_nChaos - 1);
2020-03-29 15:26:23 +00:00
UpdateWantedLevel();
}
}
UpdateCrimesQ();
bool orderMessedUp = false;
int currCopNum = 0;
bool foundEmptySlot = false;
for (int i = 0; i < ARRAY_SIZE(m_pCops); i++) {
if (m_pCops[i]) {
++currCopNum;
if (foundEmptySlot)
orderMessedUp = true;
} else {
foundEmptySlot = true;
}
}
if (currCopNum != m_CurrentCops) {
printf("CopPursuit total messed up: re-setting\n");
m_CurrentCops = currCopNum;
}
if (orderMessedUp) {
printf("CopPursuit pointer list messed up: re-sorting\n");
bool fixed = true;
for (int i = 0; i < ARRAY_SIZE(m_pCops); i++) {
if (!m_pCops[i]) {
for (int j = i; j < ARRAY_SIZE(m_pCops); j++) {
if (m_pCops[j]) {
m_pCops[i] = m_pCops[j];
m_pCops[j] = nil;
fixed = false;
break;
}
}
if (fixed)
break;
}
}
}
}
}
void
CWanted::ResetPolicePursuit(void)
{
for(int i = 0; i < ARRAY_SIZE(m_pCops); i++) {
CCopPed *cop = m_pCops[i];
if (!cop)
continue;
cop->m_bIsInPursuit = false;
cop->m_objective = OBJECTIVE_NONE;
cop->m_prevObjective = OBJECTIVE_NONE;
cop->m_nLastPedState = PED_NONE;
if (!cop->DyingOrDead()) {
cop->SetWanderPath(CGeneral::GetRandomNumberInRange(0.0f, 8.0f));
}
m_pCops[i] = nil;
}
m_CurrentCops = 0;
}
void
CWanted::Reset(void)
{
ResetPolicePursuit();
Initialise();
}
void
CWanted::UpdateCrimesQ(void)
{
for(int i = 0; i < ARRAY_SIZE(m_aCrimes); i++) {
CCrimeBeingQd &crime = m_aCrimes[i];
if (crime.m_nType != CRIME_NONE) {
if (CTimer::GetTimeInMilliseconds() > crime.m_nTime + 500 && !crime.m_bReported) {
ReportCrimeNow(crime.m_nType, crime.m_vecPosn, crime.m_bPoliceDoesntCare);
crime.m_bReported = true;
}
if (CTimer::GetTimeInMilliseconds() > crime.m_nTime + 10000)
crime.m_nType = CRIME_NONE;
}
}
}
2020-05-11 18:04:35 +00:00
void
CWanted::Suspend(void)
{
// TODO(Miami): Stats
// dwStarsEvaded += m_nWantedLevel;
m_nMinChaos = m_nChaos;
m_nMinWantedLevel = m_nWantedLevel;
m_nLastTimeSuspended = CTimer::GetTimeInMilliseconds();
m_nChaos = 0;
m_nWantedLevel = 0;
ResetPolicePursuit();
2020-05-11 18:04:35 +00:00
}