Fix CRoadBlocks::GenerateRoadBlocks bugs

This commit is contained in:
saml1er 2020-04-13 05:52:18 +05:00
parent 60898f39f2
commit 28fb1bdde7

View File

@ -113,23 +113,16 @@ CRoadBlocks::GenerateRoadBlocks(void)
for (; nRoadblockNode < numRoadBlocks; nRoadblockNode++) { for (; nRoadblockNode < numRoadBlocks; nRoadblockNode++) {
CTreadable *mapObject = ThePaths.m_mapObjects[CRoadBlocks::RoadBlockObjects[nRoadblockNode]]; CTreadable *mapObject = ThePaths.m_mapObjects[CRoadBlocks::RoadBlockObjects[nRoadblockNode]];
CVector2D direction = FindPlayerCoors() - mapObject->GetPosition(); CVector2D direction = FindPlayerCoors() - mapObject->GetPosition();
if ((direction.x <= -80.0f || direction.x < 80.0f) || (direction.y <= -80.0f || direction.y < 80.0f)) { if (!((direction.x > -80.0f && direction.x < 80.0f) && (direction.y > -80.0f && direction.y < 80.0f))) {
CRoadBlocks::InOrOut[nRoadblockNode] = false; CRoadBlocks::InOrOut[nRoadblockNode] = false;
continue;
} }
if (direction.Magnitude() < 80.0f) { else if (direction.Magnitude() >= 80.0f) {
CRoadBlocks::InOrOut[nRoadblockNode] = false; CRoadBlocks::InOrOut[nRoadblockNode] = false;
continue; }
} else if (!CRoadBlocks::InOrOut[nRoadblockNode]) { else if (!CRoadBlocks::InOrOut[nRoadblockNode]) {
CRoadBlocks::InOrOut[nRoadblockNode] = true; CRoadBlocks::InOrOut[nRoadblockNode] = true;
} else { if (FindPlayerVehicle() && (CGeneral::GetRandomNumber() & 0x7F) < FindPlayerPed()->m_pWanted->m_RoadblockDensity) {
continue;
}
if (!FindPlayerVehicle())
continue;
CWanted *pPlayerWanted = FindPlayerPed()->m_pWanted; CWanted *pPlayerWanted = FindPlayerPed()->m_pWanted;
if ((CGeneral::GetRandomNumber() & 0x7F) >= pPlayerWanted->m_RoadblockDensity)
continue;
float fMapObjectRadius = 2.0f * mapObject->GetColModel()->boundingBox.max.x; float fMapObjectRadius = 2.0f * mapObject->GetColModel()->boundingBox.max.x;
int32 vehicleId = MI_POLICE; int32 vehicleId = MI_POLICE;
if (pPlayerWanted->AreArmyRequired()) if (pPlayerWanted->AreArmyRequired())
@ -143,19 +136,16 @@ CRoadBlocks::GenerateRoadBlocks(void)
CColModel* pVehicleColModel = CModelInfo::GetModelInfo(vehicleId)->GetColModel(); CColModel* pVehicleColModel = CModelInfo::GetModelInfo(vehicleId)->GetColModel();
float fModelRadius = 2.0f * pVehicleColModel->boundingSphere.radius + 0.25f; float fModelRadius = 2.0f * pVehicleColModel->boundingSphere.radius + 0.25f;
int16 radius = (int16)(fMapObjectRadius / fModelRadius); int16 radius = (int16)(fMapObjectRadius / fModelRadius);
if (radius >= 6) if (radius > 0 && radius < 6) {
continue;
CVector2D directionToCamera = TheCamera.m_matrix.GetPosition() - mapObject->m_matrix.GetPosition(); CVector2D directionToCamera = TheCamera.m_matrix.GetPosition() - mapObject->m_matrix.GetPosition();
float fDotProduct = DotProduct2D(directionToCamera, mapObject->m_matrix.GetUp()); float fDotProduct = DotProduct2D(directionToCamera, mapObject->m_matrix.GetUp());
if (radius <= 0)
continue;
float fOffset = 0.5f * fModelRadius * (float)(radius - 1); float fOffset = 0.5f * fModelRadius * (float)(radius - 1);
for (int16 modelId = vehicleId; modelId < nRoadblockNode ; modelId++) { for (int16 i = 0; i < radius; i++) {
uint8 nRoadblockType = fDotProduct >= 0.0f; uint8 nRoadblockType = fDotProduct < 0.0f;
if (CGeneral::GetRandomNumber() & 1) { if (CGeneral::GetRandomNumber() & 1) {
offsetMatrix.SetRotateZ(((CGeneral::GetRandomNumber() & 0xFF) - 128.0f) * 0.003f + HALFPI); offsetMatrix.SetRotateZ(((CGeneral::GetRandomNumber() & 0xFF) - 128.0f) * 0.003f + HALFPI);
} else { } else {
nRoadblockType = fDotProduct < 0.0f; nRoadblockType = !nRoadblockType;
offsetMatrix.SetRotateZ(((CGeneral::GetRandomNumber() & 0xFF) - 128.0f) * 0.003f - HALFPI); offsetMatrix.SetRotateZ(((CGeneral::GetRandomNumber() & 0xFF) - 128.0f) * 0.003f - HALFPI);
} }
if (ThePaths.m_objectFlags[CRoadBlocks::RoadBlockObjects[nRoadblockNode]] & ObjectEastWest) if (ThePaths.m_objectFlags[CRoadBlocks::RoadBlockObjects[nRoadblockNode]] & ObjectEastWest)
@ -163,11 +153,10 @@ CRoadBlocks::GenerateRoadBlocks(void)
else else
offsetMatrix.GetPosition() = CVector(-fOffset, 0.0f, 0.6f); offsetMatrix.GetPosition() = CVector(-fOffset, 0.0f, 0.6f);
CMatrix vehicleMatrix = mapObject->m_matrix * offsetMatrix; CMatrix vehicleMatrix = mapObject->m_matrix * offsetMatrix;
float fModelRadius = CModelInfo::GetModelInfo(modelId)->GetColModel()->boundingSphere.radius - 0.25f; float fModelRadius = CModelInfo::GetModelInfo(vehicleId)->GetColModel()->boundingSphere.radius - 0.25f;
int16 colliding = 0; int16 colliding = 0;
CWorld::FindObjectsKindaColliding(vehicleMatrix.GetPosition(), fModelRadius, 0, &colliding, 2, nil, false, true, true, false, false); CWorld::FindObjectsKindaColliding(vehicleMatrix.GetPosition(), fModelRadius, 0, &colliding, 2, nil, false, true, true, false, false);
if (colliding) if (!colliding) {
continue;
CAutomobile* pVehicle = new CAutomobile(vehicleId, RANDOM_VEHICLE); CAutomobile* pVehicle = new CAutomobile(vehicleId, RANDOM_VEHICLE);
pVehicle->m_status = STATUS_ABANDONED; pVehicle->m_status = STATUS_ABANDONED;
// pVehicle->GetHeightAboveRoad(); // called but return value is ignored? // pVehicle->GetHeightAboveRoad(); // called but return value is ignored?
@ -200,6 +189,10 @@ CRoadBlocks::GenerateRoadBlocks(void)
} }
} }
} }
}
}
}
}
STARTPATCHES STARTPATCHES
InjectHook(0x436F50, &CRoadBlocks::Init, PATCH_JUMP); InjectHook(0x436F50, &CRoadBlocks::Init, PATCH_JUMP);