re3-wiiu/src/peds/CopPed.cpp

861 lines
26 KiB
C++
Raw Normal View History

#include "common.h"
2020-04-17 15:31:11 +02:00
2020-03-07 20:22:43 +01:00
#include "World.h"
#include "PlayerPed.h"
#include "CopPed.h"
2020-03-28 15:47:52 +01:00
#include "Wanted.h"
#include "DMAudio.h"
2019-07-14 11:49:03 +02:00
#include "ModelIndices.h"
2020-03-07 20:22:43 +01:00
#include "Vehicle.h"
#include "RpAnimBlend.h"
2020-03-28 15:47:52 +01:00
#include "AnimBlendAssociation.h"
2020-03-07 20:22:43 +01:00
#include "General.h"
2020-03-25 15:13:06 +01:00
#include "ZoneCull.h"
#include "PathFind.h"
#include "RoadBlocks.h"
2020-03-28 15:47:52 +01:00
#include "CarCtrl.h"
#include "Renderer.h"
#include "Camera.h"
2020-07-27 15:04:05 +02:00
#include "PedPlacement.h"
#include "Ropes.h"
2020-08-31 20:09:48 +02:00
#include "Stinger.h"
2019-07-14 14:00:36 +02:00
2020-05-10 11:25:30 +02:00
CCopPed::CCopPed(eCopType copType, int32 modifier) : CPed(PEDTYPE_COP)
2019-07-14 11:49:03 +02:00
{
m_nCopType = copType;
switch (copType) {
case COP_STREET:
SetModelIndex(MI_COP);
GiveWeapon(WEAPONTYPE_NIGHTSTICK, 1000, true);
2020-05-15 16:30:25 +02:00
GiveDelayedWeapon(WEAPONTYPE_COLT45, 1000);
2019-07-14 11:49:03 +02:00
m_currentWeapon = WEAPONTYPE_UNARMED;
m_fArmour = 0.0f;
m_wepSkills = 208; /* TODO: what is this? seems unused */
m_wepAccuracy = 60;
break;
case COP_FBI:
SetModelIndex(MI_FBI);
2020-05-15 16:30:25 +02:00
GiveDelayedWeapon(WEAPONTYPE_MP5, 1000);
SetCurrentWeapon(WEAPONTYPE_MP5);
2019-07-14 11:49:03 +02:00
m_fArmour = 100.0f;
m_wepSkills = 176; /* TODO: what is this? seems unused */
m_wepAccuracy = 76;
break;
case COP_SWAT:
2020-07-27 15:04:05 +02:00
case COP_HELI_SWAT:
2019-07-14 11:49:03 +02:00
SetModelIndex(MI_SWAT);
2020-05-15 16:30:25 +02:00
GiveDelayedWeapon(WEAPONTYPE_UZI, 1000);
2019-07-14 11:49:03 +02:00
SetCurrentWeapon(WEAPONTYPE_UZI);
m_fArmour = 50.0f;
m_wepSkills = 32; /* TODO: what is this? seems unused */
2020-07-27 15:04:05 +02:00
m_wepAccuracy = 68;
2019-07-14 11:49:03 +02:00
break;
case COP_ARMY:
SetModelIndex(MI_ARMY);
2020-05-15 16:30:25 +02:00
GiveDelayedWeapon(WEAPONTYPE_MP5, 1000);
SetCurrentWeapon(WEAPONTYPE_MP5);
2019-07-14 11:49:03 +02:00
m_fArmour = 100.0f;
m_wepSkills = 32; /* TODO: what is this? seems unused */
m_wepAccuracy = 84;
break;
2020-05-10 11:25:30 +02:00
case COP_MIAMIVICE:
switch (modifier) {
case 0: SetModelIndex(MI_VICE1); break;
case 1: SetModelIndex(MI_VICE2); break;
case 2: SetModelIndex(MI_VICE3); break;
case 3: SetModelIndex(MI_VICE4); break;
case 4: SetModelIndex(MI_VICE5); break;
case 5: SetModelIndex(MI_VICE6); break;
case 6: SetModelIndex(MI_VICE7); break;
case 7: SetModelIndex(MI_VICE8); break;
default: assert(0); break;
}
2020-05-15 16:30:25 +02:00
GiveDelayedWeapon(WEAPONTYPE_UZI, 1000);
2020-05-10 11:25:30 +02:00
SetCurrentWeapon(WEAPONTYPE_UZI);
m_fArmour = 100.0f;
m_wepSkills = 176;
m_wepAccuracy = 76;
2019-07-14 11:49:03 +02:00
break;
}
m_bIsInPursuit = false;
field_5FE = 1;
2019-07-14 11:49:03 +02:00
m_bIsDisabledCop = false;
m_attackTimer = 0;
2020-07-27 15:04:05 +02:00
m_bBeatingSuspect = false;
2020-03-28 15:47:52 +01:00
m_bStopAndShootDisabledZone = false;
field_601 = false;
2019-07-14 11:49:03 +02:00
m_bZoneDisabled = false;
field_628 = -1;
m_nRoadblockNode = -1; // TODO(Miami): this will be nil
m_bThrowsSpikeTrap = false;
2020-07-26 23:41:01 +02:00
m_pRopeEntity = nil;
m_fAbseilPos = 0.0f;
2020-07-27 15:04:05 +02:00
m_nHassleTimer = 0;
field_61C = 0;
2020-07-04 14:31:28 +02:00
field_624 = 0;
2020-08-31 20:09:48 +02:00
m_pStinger = new CStinger;
2020-07-27 15:04:05 +02:00
if (m_pPointGunAt)
m_pPointGunAt->CleanUpOldReference((CEntity**)&m_pPointGunAt);
m_pPointGunAt = nil;
2019-07-14 11:49:03 +02:00
}
CCopPed::~CCopPed()
{
ClearPursuit();
2020-08-31 20:09:48 +02:00
m_pStinger->Remove();
delete m_pStinger;
}
2020-07-27 15:04:05 +02:00
// --MIAMI: Done
2020-03-07 20:22:43 +01:00
// Parameter should always be CPlayerPed, but it seems they considered making civilians arrestable at some point
void
CCopPed::SetArrestPlayer(CPed *player)
{
if (!IsPedInControl() || !player)
return;
2020-07-27 15:04:05 +02:00
player->Say(SOUND_PED_PLAYER_REACTTOCOP);
Say(SOUND_PED_ARREST_COP);
2020-03-07 20:22:43 +01:00
if (player->EnteringCar()) {
if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer)
return;
// why?
player->bGonnaKillTheCarJacker = true;
// Genius
FindPlayerPed()->m_bCanBeDamaged = false;
((CPlayerPed*)player)->m_pArrestingCop = this;
this->RegisterReference((CEntity**) &((CPlayerPed*)player)->m_pArrestingCop);
} else if (player->m_nPedState != PED_DIE && player->m_nPedState != PED_DEAD && player->m_nPedState != PED_ARRESTED) {
player->m_nLastPedState = player->m_nPedState;
2020-07-27 15:04:05 +02:00
player->SetPedState(PED_ARRESTED);
2020-03-07 20:22:43 +01:00
FindPlayerPed()->m_bCanBeDamaged = false;
((CPlayerPed*)player)->m_pArrestingCop = this;
this->RegisterReference((CEntity**) &((CPlayerPed*)player)->m_pArrestingCop);
}
2020-07-27 15:04:05 +02:00
SetPedState(PED_ARREST_PLAYER);
2020-03-07 20:22:43 +01:00
SetObjective(OBJECTIVE_NONE);
m_prevObjective = OBJECTIVE_NONE;
bIsPointingGunAt = false;
m_pSeekTarget = player;
m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget);
SetCurrentWeapon(WEAPONTYPE_COLT45);
if (player->InVehicle()) {
player->m_pMyVehicle->m_nNumGettingIn = 0;
player->m_pMyVehicle->m_nGettingInFlags = 0;
player->m_pMyVehicle->bIsHandbrakeOn = true;
player->m_pMyVehicle->SetStatus(STATUS_PLAYER_DISABLED);
2020-03-07 20:22:43 +01:00
}
2020-07-27 15:04:05 +02:00
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED || GetWeapon()->m_eWeaponType == WEAPONTYPE_BRASSKNUCKLE)
2020-03-07 20:22:43 +01:00
SetCurrentWeapon(WEAPONTYPE_COLT45);
}
2020-07-27 15:04:05 +02:00
// --MIAMI: Done
2020-03-07 20:22:43 +01:00
void
CCopPed::ClearPursuit(void)
{
CPlayerPed *player = FindPlayerPed();
if (!player)
return;
CWanted *wanted = player->m_pWanted;
int ourCopId = 0;
bool foundMyself = false;
int biggestCopId = 0;
if (!m_bIsInPursuit)
return;
m_bIsInPursuit = false;
2020-04-19 18:34:08 +02:00
for (int i = 0; i < Max(wanted->m_MaxCops, wanted->m_CurrentCops); ++i) {
2020-03-07 20:22:43 +01:00
if (!foundMyself && wanted->m_pCops[i] == this) {
wanted->m_pCops[i] = nil;
--wanted->m_CurrentCops;
foundMyself = true;
ourCopId = i;
biggestCopId = i;
} else {
if (wanted->m_pCops[i])
biggestCopId = i;
}
}
if (foundMyself && biggestCopId > ourCopId) {
wanted->m_pCops[ourCopId] = wanted->m_pCops[biggestCopId];
wanted->m_pCops[biggestCopId] = nil;
}
m_objective = OBJECTIVE_NONE;
m_prevObjective = OBJECTIVE_NONE;
m_nLastPedState = PED_NONE;
bIsRunning = false;
bNotAllowedToDuck = false;
bKindaStayInSamePlace = false;
2020-03-28 15:47:52 +01:00
m_bStopAndShootDisabledZone = false;
2020-07-27 15:04:05 +02:00
field_601 = false;
2020-03-07 20:22:43 +01:00
m_bZoneDisabled = false;
ClearObjective();
if (IsPedInControl()) {
if (!m_pMyVehicle || wanted->m_nWantedLevel != 0) {
if (m_pMyVehicle && (m_pMyVehicle->GetPosition() - GetPosition()).MagnitudeSqr() < sq(5.0f)) {
m_nLastPedState = PED_IDLE;
SetSeek((CEntity*)m_pMyVehicle, 2.5f);
} else {
m_nLastPedState = PED_WANDER_PATH;
SetFindPathAndFlee(FindPlayerPed()->GetPosition(), 10000, true);
}
} else {
SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle);
}
}
}
2020-07-27 15:04:05 +02:00
// --MIAMI: Done
2020-03-25 15:13:06 +01:00
// TODO: I don't know why they needed that parameter.
2020-03-07 20:22:43 +01:00
void
2020-03-25 15:13:06 +01:00
CCopPed::SetPursuit(bool ignoreCopLimit)
2020-03-07 20:22:43 +01:00
{
2020-07-27 15:04:05 +02:00
if (CTimer::GetTimeInMilliseconds() < field_61C)
return;
2020-03-07 20:22:43 +01:00
CWanted *wanted = FindPlayerPed()->m_pWanted;
if (m_bIsInPursuit || !IsPedInControl())
return;
2020-03-25 15:13:06 +01:00
if (wanted->m_CurrentCops < wanted->m_MaxCops || ignoreCopLimit) {
2020-03-07 20:22:43 +01:00
for (int i = 0; i < wanted->m_MaxCops; ++i) {
if (!wanted->m_pCops[i]) {
m_bIsInPursuit = true;
++wanted->m_CurrentCops;
wanted->m_pCops[i] = this;
break;
}
}
if (m_bIsInPursuit) {
ClearObjective();
m_prevObjective = OBJECTIVE_NONE;
SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, FindPlayerPed());
SetObjectiveTimer(0);
bNotAllowedToDuck = true;
bIsRunning = true;
2020-03-28 15:47:52 +01:00
m_bStopAndShootDisabledZone = false;
2020-03-07 20:22:43 +01:00
}
}
}
2020-07-27 15:04:05 +02:00
// --MIAMI: Done
2020-03-07 20:22:43 +01:00
void
CCopPed::ArrestPlayer(void)
{
m_pVehicleAnim = nil;
CPed *suspect = (CPed*)m_pSeekTarget;
if (suspect) {
if (suspect->CanSetPedState())
suspect->m_nPedState = PED_ARRESTED;
if (suspect->bInVehicle && m_pMyVehicle && suspect->m_pMyVehicle == m_pMyVehicle) {
// BUG? I will never understand why they used LINE_UP_TO_CAR_2...
LineUpPedWithCar(LINE_UP_TO_CAR_2);
}
if (suspect && (suspect->m_nPedState == PED_ARRESTED || suspect->DyingOrDead() || suspect->EnteringCar())) {
CAnimBlendAssociation *arrestAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_ARREST_GUN);
if (!arrestAssoc || arrestAssoc->blendDelta < 0.0f)
CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_ARREST_GUN, 4.0f);
CVector suspMidPos;
2020-05-24 17:36:37 +02:00
suspect->m_pedIK.GetComponentPosition(*(RwV3d *)&suspMidPos, PED_MID);
2020-03-07 20:22:43 +01:00
m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(suspMidPos.x, suspMidPos.y,
GetPosition().x, GetPosition().y);
m_fRotationCur = m_fRotationDest;
SetOrientation(0.0f, 0.0f, m_fRotationCur);
} else {
ClearPursuit();
}
} else {
ClearPursuit();
}
}
void
CCopPed::ScanForCrimes(void)
{
CVehicle *playerVeh = FindPlayerVehicle();
// Look for car alarms
if (playerVeh && playerVeh->IsCar()) {
if (playerVeh->IsAlarmOn()) {
if ((playerVeh->GetPosition() - GetPosition()).MagnitudeSqr() < sq(20.0f))
FindPlayerPed()->SetWantedLevelNoDrop(1);
}
}
2020-03-17 19:03:13 +01:00
// Look for stolen cop cars
2020-03-07 20:22:43 +01:00
if (!m_bIsInPursuit) {
CPlayerPed *player = FindPlayerPed();
if ((m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER)
2020-03-17 19:03:13 +01:00
&& player->m_pWanted->m_nWantedLevel == 0) {
2020-03-07 20:22:43 +01:00
2020-03-17 19:03:13 +01:00
if (player->m_pMyVehicle
#ifdef FIX_BUGS
&& m_pMyVehicle == player->m_pMyVehicle
#endif
&& player->m_pMyVehicle->bIsLawEnforcer)
2020-03-07 20:22:43 +01:00
player->SetWantedLevelNoDrop(1);
}
}
}
2020-07-27 15:04:05 +02:00
// --MIAMI: Done
2020-03-25 15:13:06 +01:00
void
CCopPed::CopAI(void)
{
CWanted *wanted = FindPlayerPed()->m_pWanted;
int wantedLevel = wanted->m_nWantedLevel;
CPhysical *playerOrHisVeh = FindPlayerVehicle() ? (CPhysical*)FindPlayerVehicle() : (CPhysical*)FindPlayerPed();
if (wanted->m_bIgnoredByEveryone || wanted->m_bIgnoredByCops) {
if (m_nPedState != PED_ARREST_PLAYER)
ClearPursuit();
return;
}
if (CCullZones::NoPolice() && m_bIsInPursuit && !m_bIsDisabledCop) {
if (bHitSomethingLastFrame) {
m_bZoneDisabled = true;
m_bIsDisabledCop = true;
bKindaStayInSamePlace = true;
bIsRunning = false;
bNotAllowedToDuck = false;
bCrouchWhenShooting = false;
SetIdle();
ClearObjective();
ClearPursuit();
m_prevObjective = OBJECTIVE_NONE;
m_nLastPedState = PED_NONE;
SetAttackTimer(0);
2020-03-28 15:47:52 +01:00
// Safe distance for disabled zone? Or to just make game easier?
2020-03-25 15:13:06 +01:00
if (m_fDistanceToTarget > 15.0f)
2020-03-28 15:47:52 +01:00
m_bStopAndShootDisabledZone = true;
2020-03-25 15:13:06 +01:00
}
} else if (m_bZoneDisabled && !CCullZones::NoPolice()) {
m_bZoneDisabled = false;
m_bIsDisabledCop = false;
2020-03-28 15:47:52 +01:00
m_bStopAndShootDisabledZone = false;
2020-03-25 15:13:06 +01:00
bKindaStayInSamePlace = false;
bCrouchWhenShooting = false;
bDuckAndCover = false;
ClearPursuit();
}
if (wantedLevel > 0) {
if (!m_bIsDisabledCop) {
2020-07-27 15:04:05 +02:00
// Turn and shoot the player's vehicle, if possible
if (!m_bIsInPursuit && !GetWeapon()->IsTypeMelee() && FindPlayerVehicle() && m_fDistanceToTarget < CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_fRange) {
if (FindPlayerVehicle()->m_vecMoveSpeed.Magnitude2D() > 0.1f) {
CVector2D distToVeh = GetPosition() - FindPlayerVehicle()->GetPosition();
distToVeh.Normalise();
CVector2D vehSpeed = FindPlayerVehicle()->m_vecMoveSpeed;
vehSpeed.Normalise();
if (DotProduct2D(distToVeh, vehSpeed) > 0.8f) {
SetLookFlag(playerOrHisVeh, true);
SetMoveState(PEDMOVE_STILL);
if (TurnBody()) {
SetAttack(FindPlayerVehicle());
SetShootTimer(CGeneral::GetRandomNumberInRange(500.0f, 1000.0f));
SetAttackTimer(CGeneral::GetRandomNumberInRange(200.0f, 300.0f));
}
} else if (m_nPedState == PED_ATTACK)
RestorePreviousState();
}
}
2020-03-25 15:13:06 +01:00
if (!m_bIsInPursuit || wanted->m_CurrentCops > wanted->m_MaxCops) {
CCopPed *copFarthestToTarget = nil;
float copFarthestToTargetDist = m_fDistanceToTarget;
int oldCopNum = wanted->m_CurrentCops;
int maxCops = wanted->m_MaxCops;
2020-04-19 18:34:08 +02:00
for (int i = 0; i < Max(maxCops, oldCopNum); i++) {
2020-03-25 15:13:06 +01:00
CCopPed *cop = wanted->m_pCops[i];
if (cop && cop->m_fDistanceToTarget > copFarthestToTargetDist) {
copFarthestToTargetDist = cop->m_fDistanceToTarget;
copFarthestToTarget = wanted->m_pCops[i];
}
}
if (m_bIsInPursuit) {
if (copFarthestToTarget && oldCopNum > maxCops) {
if (copFarthestToTarget == this && m_fDistanceToTarget > 10.0f) {
ClearPursuit();
} else if(copFarthestToTargetDist > 10.0f)
copFarthestToTarget->ClearPursuit();
}
} else {
if (oldCopNum < maxCops) {
SetPursuit(true);
} else {
if (m_fDistanceToTarget <= 10.0f || copFarthestToTarget && m_fDistanceToTarget < copFarthestToTargetDist) {
if (copFarthestToTarget && copFarthestToTargetDist > 10.0f)
copFarthestToTarget->ClearPursuit();
SetPursuit(true);
}
}
}
} else
SetPursuit(false);
if (!m_bIsInPursuit)
return;
if (wantedLevel > 1 && GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED)
SetCurrentWeapon(WEAPONTYPE_COLT45);
2020-07-27 15:04:05 +02:00
else if (wantedLevel == 1 && GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED && !FindPlayerPed()->m_pCurrentPhysSurface) {
2020-03-25 15:13:06 +01:00
// i.e. if player is on top of car, cop will still use colt45.
2020-07-27 15:04:05 +02:00
SetCurrentWeapon(GetWeaponSlot(WEAPONTYPE_NIGHTSTICK) >= 0 ? WEAPONTYPE_NIGHTSTICK : WEAPONTYPE_UNARMED);
2020-03-25 15:13:06 +01:00
}
2020-07-27 15:04:05 +02:00
if (m_bBeatingSuspect && GetWeapon()->m_eWeaponType == WEAPONTYPE_NIGHTSTICK)
Say(SOUND_PED_PULLOUTWEAPON);
2020-03-25 15:13:06 +01:00
if (FindPlayerVehicle()) {
if (m_bBeatingSuspect) {
--wanted->m_CopsBeatingSuspect;
m_bBeatingSuspect = false;
}
if (m_fDistanceToTarget * FindPlayerSpeed().Magnitude() > 4.0f)
ClearPursuit();
}
return;
}
2020-07-27 15:04:05 +02:00
SetCurrentWeapon(WEAPONTYPE_COLT45);
CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
float weaponRange = weaponInfo->m_fRange;
2020-03-25 15:13:06 +01:00
SetLookFlag(playerOrHisVeh, true);
TurnBody();
2020-07-27 15:04:05 +02:00
if (!bIsDucking || bCrouchWhenShooting && GetCrouchFireAnim(weaponInfo)) {
2020-03-25 15:13:06 +01:00
if (m_attackTimer >= CTimer::GetTimeInMilliseconds()) {
if (m_nPedState != PED_ATTACK && m_nPedState != PED_FIGHT && !m_bZoneDisabled) {
CVector targetDist = playerOrHisVeh->GetPosition() - GetPosition();
if (m_fDistanceToTarget > 30.0f) {
2020-07-27 15:04:05 +02:00
if (bIsDucking)
ClearDuck();
2020-03-25 15:13:06 +01:00
// Target is coming onto us
if (DotProduct(playerOrHisVeh->m_vecMoveSpeed, targetDist) > 0.0f) {
m_bIsDisabledCop = false;
bKindaStayInSamePlace = false;
bNotAllowedToDuck = false;
bDuckAndCover = false;
SetPursuit(false);
SetObjective(OBJECTIVE_KILL_CHAR_ANY_MEANS, FindPlayerPed());
}
} else if (m_fDistanceToTarget < 5.0f
&& (!FindPlayerVehicle() || FindPlayerVehicle()->m_vecMoveSpeed.MagnitudeSqr() < sq(1.f/200.f))) {
m_bIsDisabledCop = false;
bKindaStayInSamePlace = false;
bNotAllowedToDuck = false;
bDuckAndCover = false;
} else {
2020-07-27 15:04:05 +02:00
// TODO(Miami): Roadblock system is still III
2020-03-25 15:13:06 +01:00
float dotProd;
if (m_nRoadblockNode != -1) {
CPathNode *roadBlockNode = &ThePaths.m_pathNodes[CRoadBlocks::RoadBlockNodes[m_nRoadblockNode]];
dotProd = DotProduct2D(playerOrHisVeh->GetPosition() - roadBlockNode->GetPosition(), GetPosition() - roadBlockNode->GetPosition());
2020-03-25 15:13:06 +01:00
} else
dotProd = -1.0f;
if(dotProd >= 0.0f) {
bIsPointingGunAt = true;
} else {
2020-07-27 15:04:05 +02:00
if (bIsDucking)
ClearDuck();
2020-03-25 15:13:06 +01:00
m_bIsDisabledCop = false;
bKindaStayInSamePlace = false;
bNotAllowedToDuck = false;
bCrouchWhenShooting = false;
bDuckAndCover = false;
SetPursuit(false);
}
}
}
} else {
if (m_fDistanceToTarget < weaponRange) {
CVector gunPos = weaponInfo->m_vecFireOffset;
TransformToNode(gunPos, PED_HANDR);
2020-03-25 15:13:06 +01:00
CColPoint foundCol;
CEntity *foundEnt;
if (!CWorld::ProcessLineOfSight(gunPos, playerOrHisVeh->GetPosition(), foundCol, foundEnt,
false, true, false, false, true, false, false)
|| foundEnt && foundEnt == playerOrHisVeh) {
2020-07-27 15:04:05 +02:00
if (m_pPointGunAt)
m_pPointGunAt->CleanUpOldReference((CEntity**) &m_pPointGunAt);
2020-03-25 15:13:06 +01:00
m_pPointGunAt = playerOrHisVeh;
if (playerOrHisVeh)
playerOrHisVeh->RegisterReference((CEntity**) &m_pPointGunAt);
SetAttack(playerOrHisVeh);
SetShootTimer(CGeneral::GetRandomNumberInRange(500, 1000));
}
2020-07-27 15:04:05 +02:00
SetAttackTimer(CGeneral::GetRandomNumberInRange(200, 300));
2020-03-25 15:13:06 +01:00
}
SetMoveState(PEDMOVE_STILL);
}
}
} else {
if (!m_bIsDisabledCop || m_bZoneDisabled) {
if (m_nPedState != PED_AIM_GUN) {
if (m_bIsInPursuit)
ClearPursuit();
if (IsPedInControl()) {
// Entering the vehicle
if (m_pMyVehicle && !bInVehicle) {
if (m_pMyVehicle->IsLawEnforcementVehicle()) {
if (m_pMyVehicle->pDriver) {
if (m_pMyVehicle->pDriver->m_nPedType == PEDTYPE_COP) {
if (m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER)
SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_pMyVehicle);
} else if (m_pMyVehicle->pDriver->IsPlayer()) {
FindPlayerPed()->SetWantedLevelNoDrop(1);
}
} else if (m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER) {
SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle);
}
} else {
m_pMyVehicle = nil;
ClearObjective();
SetWanderPath(CGeneral::GetRandomNumber() & 7);
}
2020-07-27 15:04:05 +02:00
} else {
if (m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT && m_objective != OBJECTIVE_HASSLE_CHAR && CharCreatedBy == RANDOM_CHAR) {
2020-03-25 15:13:06 +01:00
for (int i = 0; i < m_numNearPeds; i++) {
CPed *nearPed = m_nearPeds[i];
if (nearPed->CharCreatedBy == RANDOM_CHAR) {
if ((nearPed->m_nPedType == PEDTYPE_CRIMINAL || nearPed->IsGangMember())
&& nearPed->IsPedInControl()) {
bool anotherCopChasesHim = false;
if (nearPed->m_nPedState == PED_FLEE_ENTITY) {
if (nearPed->m_fleeFrom && nearPed->m_fleeFrom->IsPed() &&
((CPed*)nearPed->m_fleeFrom)->m_nPedType == PEDTYPE_COP) {
anotherCopChasesHim = true;
}
}
if (!anotherCopChasesHim) {
SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, nearPed);
nearPed->SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, this);
2020-03-28 15:47:52 +01:00
nearPed->bBeingChasedByPolice = true;
2020-03-25 15:13:06 +01:00
return;
}
2020-07-27 15:04:05 +02:00
} else {
if (nearPed->m_nPedType != PEDTYPE_COP && !nearPed->IsPlayer()
&& nearPed->IsPedInControl() && m_nHassleTimer < CTimer::GetTimeInMilliseconds()) {
if (nearPed->m_objective == OBJECTIVE_NONE && nearPed->m_nPedState == PED_WANDER_PATH
&& !nearPed->m_pLookTarget && nearPed->m_lookTimer < CTimer::GetTimeInMilliseconds()) {
if ((GetPosition() - nearPed->GetPosition()).MagnitudeSqr() < sq(5.0f)) {
if (CWorld::GetIsLineOfSightClear(GetPosition(), nearPed->GetPosition(),
true, false, false, false, false, false, false)) {
Say(SOUND_PED_COP_REACTION);
SetObjective(OBJECTIVE_HASSLE_CHAR, nearPed);
nearPed->SetObjective(OBJECTIVE_WAIT_ON_FOOT_FOR_COP, this);
m_nHassleTimer = CTimer::GetTimeInMilliseconds() + 100000;
}
}
}
}
2020-03-25 15:13:06 +01:00
}
}
}
}
}
}
}
} else {
if (m_bIsInPursuit && m_nPedState != PED_AIM_GUN)
ClearPursuit();
m_bIsDisabledCop = false;
bKindaStayInSamePlace = false;
bNotAllowedToDuck = false;
bCrouchWhenShooting = false;
bDuckAndCover = false;
2020-07-27 15:04:05 +02:00
if (bIsDucking)
ClearDuck();
2020-03-25 15:13:06 +01:00
if (m_pMyVehicle)
SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle);
}
}
}
2020-07-27 15:04:05 +02:00
// --MIAMI: Done except commented things
2020-03-28 15:47:52 +01:00
void
CCopPed::ProcessControl(void)
{
2020-07-27 15:04:05 +02:00
if (m_nCopType == COP_HELI_SWAT)
ProcessHeliSwat();
2020-03-28 15:47:52 +01:00
CPed::ProcessControl();
2020-07-27 15:04:05 +02:00
if (m_bThrowsSpikeTrap) {
// TODO(Miami)
/*
if (CGame::currArea != AREA_MALL)
ProcessStingerCop();
*/
return;
}
// TODO(Miami): CStinger::Process
2020-03-28 15:47:52 +01:00
if (bWasPostponed)
return;
if (m_nPedState == PED_DEAD) {
ClearPursuit();
m_objective = OBJECTIVE_NONE;
return;
}
if (m_nPedState == PED_DIE)
return;
if (m_nPedState == PED_ARREST_PLAYER) {
ArrestPlayer();
return;
}
2020-05-17 19:36:48 +02:00
GetWeapon()->Update(m_audioEntityId, nil);
2020-03-28 15:47:52 +01:00
if (m_moved.Magnitude() > 0.0f)
Avoid();
CPhysical *playerOrHisVeh = FindPlayerVehicle() ? (CPhysical*)FindPlayerVehicle() : (CPhysical*)FindPlayerPed();
CPlayerPed *player = FindPlayerPed();
m_fDistanceToTarget = (playerOrHisVeh->GetPosition() - GetPosition()).Magnitude();
if (player->m_nPedState == PED_ARRESTED || player->DyingOrDead()) {
if (m_fDistanceToTarget < 5.0f) {
SetArrestPlayer(player);
return;
}
if (IsPedInControl())
SetIdle();
}
2020-07-27 15:04:05 +02:00
2020-03-28 15:47:52 +01:00
if (m_bIsInPursuit) {
if (player->m_nPedState != PED_ARRESTED && !player->DyingOrDead()) {
2020-07-27 15:04:05 +02:00
if (player->m_pWanted->m_CurrentCops == 1) {
Say(SOUND_PED_COP_ALONE);
} else {
int numCopsNear = 0;
for (int i = 0; i < player->m_numNearPeds; ++i) {
CPed *nearPed = player->m_nearPeds[i];
if (nearPed->m_nPedType == PEDTYPE_COP && nearPed->m_nPedState != PED_DEAD)
++numCopsNear;
}
if (numCopsNear <= 3) {
Say(SOUND_PED_COP_LITTLECOPSAROUND);
if (!player->bInVehicle) {
CVector distToPlayer = player->GetPosition() - GetPosition();
if (distToPlayer.MagnitudeSqr() < sq(20.0f)) {
player->Say(SOUND_PED_PLAYER_FARFROMCOPS);
if (player->m_nPedState != PED_ATTACK && player->m_nPedState != PED_AIM_GUN) {
player->SetLookFlag(this, false);
player->SetLookTimer(1000);
}
}
}
} else if ((CGeneral::GetRandomNumber() % 16) == 1) {
Say(SOUND_PED_COP_MANYCOPSAROUND);
}
2020-03-28 15:47:52 +01:00
}
}
2020-07-27 15:04:05 +02:00
}
2020-03-28 15:47:52 +01:00
if (IsPedInControl()) {
CopAI();
/* switch (m_nCopType)
{
case COP_FBI:
CopAI();
break;
case COP_SWAT:
CopAI();
break;
case COP_ARMY:
CopAI();
break;
default:
CopAI();
break;
} */
} else if (InVehicle()) {
if (m_pMyVehicle->pDriver == this && m_pMyVehicle->AutoPilot.m_nCarMission == MISSION_NONE &&
CanPedDriveOff() && m_pMyVehicle->VehicleCreatedBy != MISSION_VEHICLE) {
CCarCtrl::JoinCarWithRoadSystem(m_pMyVehicle);
m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_CRUISE;
m_pMyVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_STOP_FOR_CARS;
m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 17;
}
}
if (IsPedInControl() || m_nPedState == PED_DRIVING)
ScanForCrimes();
// They may have used goto to jump here in case of PED_ATTACK.
if (m_nPedState == PED_IDLE || m_nPedState == PED_ATTACK) {
if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT &&
player && player->EnteringCar() && m_fDistanceToTarget < 1.3f) {
SetArrestPlayer(player);
}
} else {
if (m_nPedState == PED_SEEK_POS) {
if (player->m_nPedState == PED_ARRESTED) {
SetIdle();
SetLookFlag(player, false);
SetLookTimer(1000);
RestorePreviousObjective();
} else {
if (player->m_pMyVehicle && player->m_pMyVehicle->m_nNumGettingIn != 0) {
m_distanceToCountSeekDone = 1.3f;
}
2020-07-27 15:04:05 +02:00
if (!bDuckAndCover && Seek()) {
2020-03-28 15:47:52 +01:00
CVehicle *playerVeh = FindPlayerVehicle();
if (!playerVeh && player && player->EnteringCar()) {
SetArrestPlayer(player);
} else if (1.5f + GetPosition().z <= m_vecSeekPos.z || GetPosition().z - 0.3f >= m_vecSeekPos.z) {
SetMoveState(PEDMOVE_STILL);
} else if (playerVeh && playerVeh->CanPedEnterCar() && playerVeh->m_nNumGettingIn == 0) {
SetCarJack(playerVeh);
}
}
}
} else if (m_nPedState == PED_SEEK_ENTITY) {
if (!m_pSeekTarget) {
RestorePreviousState();
} else {
m_vecSeekPos = m_pSeekTarget->GetPosition();
if (Seek()) {
if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT && m_fDistanceToTarget < 2.5f && player) {
if (player->m_nPedState == PED_ARRESTED || player->m_nPedState == PED_ENTER_CAR ||
(player->m_nPedState == PED_CARJACK && m_fDistanceToTarget < 1.3f)) {
SetArrestPlayer(player);
} else
RestorePreviousState();
} else {
RestorePreviousState();
}
}
}
}
}
2020-07-27 15:04:05 +02:00
if (m_pPointGunAt)
Say(SOUND_PED_COP_UNK_129);
if (m_bStopAndShootDisabledZone) {
bool dontShoot = false;
if (GetIsOnScreen()) {
if (((CTimer::GetFrameCounter() + m_randomSeed) & 0x1F) == 17) {
CEntity* foundBuilding = nil;
CColPoint foundCol;
CVector lookPos = GetPosition() + CVector(0.0f, 0.0f, 0.7f);
CVector camPos = TheCamera.GetGameCamPosition();
CWorld::ProcessLineOfSight(camPos, lookPos, foundCol, foundBuilding,
true, false, false, false, false, false, false);
// He's at least 15.0 far, in disabled zone, collided into somewhere (that's why m_bStopAndShootDisabledZone set),
// and now has building on front of him. He's stupid, we don't need him.
if (foundBuilding) {
FlagToDestroyWhenNextProcessed();
dontShoot = true;
}
2020-03-28 15:47:52 +01:00
}
2020-07-27 15:04:05 +02:00
} else {
FlagToDestroyWhenNextProcessed();
dontShoot = true;
2020-03-28 15:47:52 +01:00
}
2020-07-27 15:04:05 +02:00
if (!dontShoot) {
bStopAndShoot = true;
bKindaStayInSamePlace = true;
bIsPointingGunAt = true;
SetAttack(m_pedInObjective);
}
2020-03-28 15:47:52 +01:00
}
2020-07-27 15:04:05 +02:00
if (field_624 >= 2 && m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT) {
CVector centre = GetPosition() + CVector(0.f, 0.f, 0.65f);
if (CWorld::TestSphereAgainstWorld(centre, 0.35f, this, true, false, false, false, false, false)) {
field_624 = 0;
m_bStopAndShootDisabledZone = true;
ClearPursuit();
SetObjective(OBJECTIVE_NONE);
SetWanderPath(CGeneral::GetRandomNumberInRange(0,8));
field_61C = CTimer::GetTimeInMilliseconds() + 30000;
} else {
field_624 = 0;
if (GetWeapon()->IsTypeMelee()) {
// TODO(Miami): enum
for (int i = 3; i < 7; i++) {
if (HasWeaponSlot(i)) {
SetCurrentWeapon(i);
break;
}
}
SetMoveState(PEDMOVE_STILL);
bStopAndShoot = true;
}
}
} else if (CTimer::GetTimeStep() / 100.f <= m_fDistanceTravelled)
field_624 = 0;
2020-03-28 15:47:52 +01:00
}
2020-07-27 15:04:05 +02:00
// --MIAMI: Done
void
CCopPed::ProcessHeliSwat(void)
{
CVector bestPos = GetPosition();
SetPedState(PED_ABSEIL);
CPedPlacement::FindZCoorForPed(&bestPos);
if (GetPosition().z - 2.0f >= bestPos.z && m_pRopeEntity) {
m_fAbseilPos += 0.003f * CTimer::GetTimeStep();
m_vecMoveSpeed.z = -0.03f;
m_vecTurnSpeed = CVector(0.f, 0.f, (m_randomSeed % 32) * 0.003f - 0.05f);
CPhysical::ApplyTurnSpeed();
GetMatrix().Reorthogonalise();
CVector posOnRope;
if (CRopes::FindCoorsAlongRope(m_nRopeID, m_fAbseilPos, &posOnRope)) {
SetPosition(posOnRope);
} else {
bUsesCollision = true;
m_vecMoveSpeed = CVector(0.f, 0.f, 0.f);
SetPedState(PED_IDLE);
m_nCopType = COP_SWAT;
SetInTheAir();
bKnockedUpIntoAir = true;
}
Say(SOUND_PED_COP_HELIPILOTPHRASE);
} else {
bUsesCollision = true;
m_vecMoveSpeed = CVector(0.f, 0.f, 0.f);
SetPedState(PED_IDLE);
m_nCopType = COP_SWAT;
SetInTheAir();
bKnockedUpIntoAir = true;
}
}