2019-08-11 19:11:54 +02:00
|
|
|
#include "common.h"
|
2020-04-17 15:31:11 +02:00
|
|
|
|
2019-08-11 19:11:54 +02:00
|
|
|
#include "RoadBlocks.h"
|
2020-03-25 15:13:06 +01:00
|
|
|
#include "PathFind.h"
|
2020-04-11 18:45:49 +02:00
|
|
|
#include "ModelIndices.h"
|
|
|
|
#include "Streaming.h"
|
|
|
|
#include "World.h"
|
|
|
|
#include "PedPlacement.h"
|
|
|
|
#include "Automobile.h"
|
|
|
|
#include "CopPed.h"
|
|
|
|
#include "VisibilityPlugins.h"
|
|
|
|
#include "PlayerPed.h"
|
|
|
|
#include "Wanted.h"
|
|
|
|
#include "Camera.h"
|
|
|
|
#include "CarCtrl.h"
|
|
|
|
#include "General.h"
|
2020-03-25 15:13:06 +01:00
|
|
|
|
2020-05-05 17:04:43 +02:00
|
|
|
#define ROADBLOCKDIST (90.0f)
|
2020-05-03 15:57:57 +02:00
|
|
|
|
2020-04-17 07:54:14 +02:00
|
|
|
int16 CRoadBlocks::NumRoadBlocks;
|
2020-05-05 17:04:43 +02:00
|
|
|
int16 CRoadBlocks::RoadBlockNodes[NUMROADBLOCKS];
|
2020-04-17 07:54:14 +02:00
|
|
|
bool CRoadBlocks::InOrOut[NUMROADBLOCKS];
|
2019-08-11 19:11:54 +02:00
|
|
|
|
2020-05-05 18:06:38 +02:00
|
|
|
//--MIAMI: TODO
|
2020-03-25 15:13:06 +01:00
|
|
|
void
|
|
|
|
CRoadBlocks::Init(void)
|
|
|
|
{
|
2020-05-03 15:57:57 +02:00
|
|
|
int i;
|
2020-04-11 18:45:49 +02:00
|
|
|
NumRoadBlocks = 0;
|
2020-05-05 17:04:43 +02:00
|
|
|
for(i = 0; i < ThePaths.m_numCarPathNodes; i++){
|
|
|
|
if(ThePaths.m_pathNodes[i].bUseInRoadBlock && ThePaths.m_pathNodes[i].numLinks == 2){
|
2020-04-13 23:13:00 +02:00
|
|
|
if (NumRoadBlocks < NUMROADBLOCKS) {
|
2020-04-11 18:45:49 +02:00
|
|
|
InOrOut[NumRoadBlocks] = true;
|
2020-05-05 17:04:43 +02:00
|
|
|
RoadBlockNodes[NumRoadBlocks] = i;
|
2020-04-11 18:45:49 +02:00
|
|
|
NumRoadBlocks++;
|
|
|
|
} else {
|
2020-03-25 15:13:06 +01:00
|
|
|
#ifndef MASTER
|
2020-04-11 18:45:49 +02:00
|
|
|
printf("Not enough room for the potential roadblocks\n");
|
2020-03-25 15:13:06 +01:00
|
|
|
#endif
|
2020-04-11 18:45:49 +02:00
|
|
|
// FIX: Don't iterate loop after NUMROADBLOCKS
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-05 18:06:38 +02:00
|
|
|
|
|
|
|
// TODO(MIAMI): script roadblocks
|
2020-04-11 18:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CRoadBlocks::GenerateRoadBlockCopsForCar(CVehicle* pVehicle, int32 roadBlockType, int16 roadBlockNode)
|
|
|
|
{
|
2020-04-11 23:08:16 +02:00
|
|
|
static const CVector vecRoadBlockOffets[6] = { {-1.5, 1.8f, 0.0f}, {-1.5f, -1.8f, 0.0f}, {1.5f, 1.8f, 0.0f},
|
2020-04-11 18:45:49 +02:00
|
|
|
{1.5f, -1.8f, 0.0f}, {-1.5f, 0.0f, 0.0f}, {1.5, 0.0, 0.0} };
|
|
|
|
CEntity* pEntityToAttack = (CEntity*)FindPlayerVehicle();
|
|
|
|
if (!pEntityToAttack)
|
|
|
|
pEntityToAttack = (CEntity*)FindPlayerPed();
|
|
|
|
CColModel* pPoliceColModel = CModelInfo::GetModelInfo(MI_POLICE)->GetColModel();
|
|
|
|
float fRadius = pVehicle->GetBoundRadius() / pPoliceColModel->boundingSphere.radius;
|
|
|
|
for (int32 i = 0; i < 2; i++) {
|
|
|
|
const int32 roadBlockIndex = i + 2 * roadBlockType;
|
|
|
|
CVector posForZ = pVehicle->m_matrix * (fRadius * vecRoadBlockOffets[roadBlockIndex]);
|
2020-04-11 23:08:16 +02:00
|
|
|
int32 modelInfoId = MI_COP;
|
2020-04-11 18:45:49 +02:00
|
|
|
eCopType copType = COP_STREET;
|
|
|
|
switch (pVehicle->GetModelIndex())
|
|
|
|
{
|
|
|
|
case MI_FBICAR:
|
|
|
|
modelInfoId = MI_FBI;
|
|
|
|
copType = COP_FBI;
|
|
|
|
break;
|
|
|
|
case MI_ENFORCER:
|
|
|
|
modelInfoId = MI_SWAT;
|
|
|
|
copType = COP_SWAT;
|
|
|
|
break;
|
|
|
|
case MI_BARRACKS:
|
|
|
|
modelInfoId = MI_ARMY;
|
|
|
|
copType = COP_ARMY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!CStreaming::HasModelLoaded(modelInfoId))
|
|
|
|
copType = COP_STREET;
|
|
|
|
CCopPed* pCopPed = new CCopPed(copType);
|
|
|
|
if (copType == COP_STREET)
|
|
|
|
pCopPed->SetCurrentWeapon(WEAPONTYPE_COLT45);
|
|
|
|
CPedPlacement::FindZCoorForPed(&posForZ);
|
2020-05-07 09:38:07 +02:00
|
|
|
pCopPed->SetPosition(posForZ);
|
|
|
|
CVector vecSavedPos = pCopPed->GetPosition();
|
2020-04-11 18:45:49 +02:00
|
|
|
pCopPed->m_matrix.SetRotate(0.0f, 0.0f, -HALFPI);
|
|
|
|
pCopPed->m_matrix.GetPosition() += vecSavedPos;
|
|
|
|
pCopPed->m_bIsDisabledCop = true;
|
|
|
|
pCopPed->SetIdle();
|
|
|
|
pCopPed->bKindaStayInSamePlace = true;
|
|
|
|
pCopPed->bNotAllowedToDuck = false;
|
2020-05-03 15:57:57 +02:00
|
|
|
pCopPed->m_nRoadblockNode = roadBlockNode;
|
2020-04-11 18:45:49 +02:00
|
|
|
pCopPed->bCrouchWhenShooting = roadBlockType != 2;
|
|
|
|
if (pEntityToAttack) {
|
|
|
|
pCopPed->m_pPointGunAt = pEntityToAttack;
|
|
|
|
pEntityToAttack->RegisterReference(&pCopPed->m_pPointGunAt);
|
|
|
|
pCopPed->SetAttack(pEntityToAttack);
|
|
|
|
}
|
|
|
|
pCopPed->m_pMyVehicle = pVehicle;
|
|
|
|
pVehicle->RegisterReference((CEntity**)&pCopPed->m_pMyVehicle);
|
|
|
|
pCopPed->bCullExtraFarAway = true;
|
|
|
|
CVisibilityPlugins::SetClumpAlpha(pCopPed->GetClump(), 0);
|
|
|
|
CWorld::Add(pCopPed);
|
|
|
|
}
|
|
|
|
}
|
2020-03-25 15:13:06 +01:00
|
|
|
|
2020-05-05 18:06:38 +02:00
|
|
|
//--MIAMI: TODO: implement this
|
2020-04-11 18:45:49 +02:00
|
|
|
void
|
|
|
|
CRoadBlocks::GenerateRoadBlocks(void)
|
|
|
|
{
|
|
|
|
CMatrix offsetMatrix;
|
2020-04-11 23:08:16 +02:00
|
|
|
uint32 frame = CTimer::GetFrameCounter() & 0xF;
|
2020-04-13 23:13:00 +02:00
|
|
|
int16 nRoadblockNode = (int16)(NUMROADBLOCKS * frame) / 16;
|
|
|
|
const int16 maxRoadBlocks = (int16)(NUMROADBLOCKS * (frame + 1)) / 16;
|
2020-05-03 15:57:57 +02:00
|
|
|
for (; nRoadblockNode < Min(NumRoadBlocks, maxRoadBlocks); nRoadblockNode++) {
|
2020-05-05 17:04:43 +02:00
|
|
|
CVector2D vecDistance = FindPlayerCoors() - ThePaths.m_pathNodes[nRoadblockNode].GetPosition();
|
2020-05-03 15:57:57 +02:00
|
|
|
if (vecDistance.x > -ROADBLOCKDIST && vecDistance.x < ROADBLOCKDIST &&
|
|
|
|
vecDistance.y > -ROADBLOCKDIST && vecDistance.y < ROADBLOCKDIST &&
|
|
|
|
vecDistance.Magnitude() < ROADBLOCKDIST) {
|
|
|
|
if (!InOrOut[nRoadblockNode]) {
|
|
|
|
InOrOut[nRoadblockNode] = true;
|
2020-04-13 12:21:39 +02:00
|
|
|
if (FindPlayerVehicle() && (CGeneral::GetRandomNumber() & 0x7F) < FindPlayerPed()->m_pWanted->m_RoadblockDensity) {
|
2020-05-05 17:04:43 +02:00
|
|
|
#ifndef MIAMI
|
2020-04-13 12:21:39 +02:00
|
|
|
CWanted *pPlayerWanted = FindPlayerPed()->m_pWanted;
|
|
|
|
float fMapObjectRadius = 2.0f * mapObject->GetColModel()->boundingBox.max.x;
|
|
|
|
int32 vehicleId = MI_POLICE;
|
|
|
|
if (pPlayerWanted->AreArmyRequired())
|
|
|
|
vehicleId = MI_BARRACKS;
|
|
|
|
else if (pPlayerWanted->AreFbiRequired())
|
|
|
|
vehicleId = MI_FBICAR;
|
|
|
|
else if (pPlayerWanted->AreSwatRequired())
|
|
|
|
vehicleId = MI_ENFORCER;
|
|
|
|
if (!CStreaming::HasModelLoaded(vehicleId))
|
|
|
|
vehicleId = MI_POLICE;
|
|
|
|
CColModel *pVehicleColModel = CModelInfo::GetModelInfo(vehicleId)->GetColModel();
|
|
|
|
float fModelRadius = 2.0f * pVehicleColModel->boundingSphere.radius + 0.25f;
|
|
|
|
int16 radius = (int16)(fMapObjectRadius / fModelRadius);
|
|
|
|
if (radius > 0 && radius < 6) {
|
2020-05-07 09:38:07 +02:00
|
|
|
CVector2D vecDistanceToCamera = TheCamera.GetPosition() - mapObject->GetPosition();
|
|
|
|
float fDotProduct = DotProduct2D(vecDistanceToCamera, mapObject->GetForward());
|
2020-04-13 12:21:39 +02:00
|
|
|
float fOffset = 0.5f * fModelRadius * (float)(radius - 1);
|
|
|
|
for (int16 i = 0; i < radius; i++) {
|
|
|
|
uint8 nRoadblockType = fDotProduct < 0.0f;
|
|
|
|
if (CGeneral::GetRandomNumber() & 1) {
|
|
|
|
offsetMatrix.SetRotateZ(((CGeneral::GetRandomNumber() & 0xFF) - 128.0f) * 0.003f + HALFPI);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nRoadblockType = !nRoadblockType;
|
|
|
|
offsetMatrix.SetRotateZ(((CGeneral::GetRandomNumber() & 0xFF) - 128.0f) * 0.003f - HALFPI);
|
|
|
|
}
|
2020-05-03 15:57:57 +02:00
|
|
|
if (ThePaths.m_objectFlags[RoadBlockObjects[nRoadblockNode]] & ObjectEastWest)
|
2020-04-13 12:21:39 +02:00
|
|
|
offsetMatrix.GetPosition() = CVector(0.0f, -fOffset, 0.6f);
|
|
|
|
else
|
|
|
|
offsetMatrix.GetPosition() = CVector(-fOffset, 0.0f, 0.6f);
|
|
|
|
CMatrix vehicleMatrix = mapObject->m_matrix * offsetMatrix;
|
|
|
|
float fModelRadius = CModelInfo::GetModelInfo(vehicleId)->GetColModel()->boundingSphere.radius - 0.25f;
|
|
|
|
int16 colliding = 0;
|
|
|
|
CWorld::FindObjectsKindaColliding(vehicleMatrix.GetPosition(), fModelRadius, 0, &colliding, 2, nil, false, true, true, false, false);
|
|
|
|
if (!colliding) {
|
|
|
|
CAutomobile *pVehicle = new CAutomobile(vehicleId, RANDOM_VEHICLE);
|
2020-04-30 15:45:45 +02:00
|
|
|
pVehicle->SetStatus(STATUS_ABANDONED);
|
2020-04-13 12:21:39 +02:00
|
|
|
// pVehicle->GetHeightAboveRoad(); // called but return value is ignored?
|
|
|
|
vehicleMatrix.GetPosition().z += fModelRadius - 0.6f;
|
|
|
|
pVehicle->m_matrix = vehicleMatrix;
|
|
|
|
pVehicle->PlaceOnRoadProperly();
|
|
|
|
pVehicle->bIsStatic = false;
|
|
|
|
pVehicle->m_matrix.UpdateRW();
|
|
|
|
pVehicle->m_nDoorLock = CARLOCK_UNLOCKED;
|
|
|
|
CCarCtrl::JoinCarWithRoadSystem(pVehicle);
|
|
|
|
pVehicle->bIsLocked = false;
|
|
|
|
pVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
|
|
|
|
pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE;
|
|
|
|
pVehicle->AutoPilot.m_nCurrentLane = 0;
|
|
|
|
pVehicle->AutoPilot.m_nNextLane = 0;
|
|
|
|
pVehicle->AutoPilot.m_fMaxTrafficSpeed = 0.0f;
|
|
|
|
pVehicle->AutoPilot.m_nCruiseSpeed = 0.0f;
|
|
|
|
pVehicle->bExtendedRange = true;
|
|
|
|
if (pVehicle->UsesSiren(pVehicle->GetModelIndex()) && CGeneral::GetRandomNumber() & 1)
|
|
|
|
pVehicle->m_bSirenOrAlarm = true;
|
2020-05-07 09:38:07 +02:00
|
|
|
if (pVehicle->GetForward().z > 0.94f) {
|
2020-04-13 12:21:39 +02:00
|
|
|
CVisibilityPlugins::SetClumpAlpha(pVehicle->GetClump(), 0);
|
|
|
|
CWorld::Add(pVehicle);
|
|
|
|
pVehicle->bCreateRoadBlockPeds = true;
|
|
|
|
pVehicle->m_nRoadblockType = nRoadblockType;
|
|
|
|
pVehicle->m_nRoadblockNode = nRoadblockNode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete pVehicle;
|
|
|
|
}
|
2020-04-13 02:52:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-05 17:04:43 +02:00
|
|
|
#endif
|
2020-04-13 02:52:18 +02:00
|
|
|
}
|
2020-04-11 18:45:49 +02:00
|
|
|
}
|
2020-04-13 12:21:39 +02:00
|
|
|
} else {
|
2020-05-03 15:57:57 +02:00
|
|
|
InOrOut[nRoadblockNode] = false;
|
2020-04-11 18:45:49 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-05 17:04:43 +02:00
|
|
|
|
2020-05-05 18:06:38 +02:00
|
|
|
// TODO(MIAMI): script roadblocks
|
2020-03-25 15:13:06 +01:00
|
|
|
}
|