2019-09-15 01:28:07 +02:00
|
|
|
#include "common.h"
|
2020-04-17 15:31:11 +02:00
|
|
|
|
2020-01-11 13:50:11 +01:00
|
|
|
#include "Accident.h"
|
2019-09-15 01:28:07 +02:00
|
|
|
|
|
|
|
#include "Ped.h"
|
2020-01-11 13:50:11 +01:00
|
|
|
#include "Pools.h"
|
|
|
|
#include "World.h"
|
2019-09-15 01:28:07 +02:00
|
|
|
|
2020-04-17 07:54:14 +02:00
|
|
|
CAccidentManager gAccidentManager;
|
2019-09-15 01:28:07 +02:00
|
|
|
|
2020-01-11 13:50:11 +01:00
|
|
|
CAccident*
|
|
|
|
CAccidentManager::GetNextFreeAccident()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_ACCIDENTS; i++) {
|
|
|
|
if (m_aAccidents[i].m_pVictim == nil)
|
|
|
|
return &m_aAccidents[i];
|
|
|
|
}
|
2019-10-19 00:23:40 +02:00
|
|
|
|
2020-01-11 13:50:11 +01:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CAccidentManager::ReportAccident(CPed *ped)
|
2019-09-15 01:28:07 +02:00
|
|
|
{
|
2020-01-11 13:50:11 +01:00
|
|
|
if (!ped->IsPlayer() && ped->CharCreatedBy != MISSION_CHAR && !ped->bRenderScorched && !ped->bBodyPartJustCameOff && ped->bAllowMedicsToReviveMe && !ped->bIsInWater) {
|
|
|
|
for (int i = 0; i < NUM_ACCIDENTS; i++) {
|
|
|
|
if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_pVictim == ped)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ped->m_pCurrentPhysSurface == nil) {
|
|
|
|
CVector point = ped->GetPosition();
|
|
|
|
point.z -= 2.0f;
|
|
|
|
|
|
|
|
CColPoint colPoint;
|
|
|
|
CEntity *pEntity;
|
|
|
|
|
|
|
|
if (!CWorld::ProcessVerticalLine(point, -100.0f, colPoint, pEntity, true, false, false, false, false, false, nil)) {
|
|
|
|
CAccident *accident = GetNextFreeAccident();
|
|
|
|
if (accident != nil) {
|
|
|
|
accident->m_pVictim = ped;
|
|
|
|
ped->RegisterReference((CEntity**)&accident->m_pVictim);
|
|
|
|
accident->m_nMedicsPerformingCPR = 0;
|
|
|
|
accident->m_nMedicsAttending = 0;
|
|
|
|
ped->m_lastAccident = accident;
|
|
|
|
WorkToDoForMedics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CAccidentManager::Update()
|
|
|
|
{
|
2020-08-03 03:00:12 +02:00
|
|
|
#ifdef SQUEEZE_PERFORMANCE
|
|
|
|
// Handled after injury registered.
|
|
|
|
return;
|
|
|
|
#endif
|
2020-01-11 13:50:11 +01:00
|
|
|
int32 e;
|
|
|
|
if (CEventList::GetEvent(EVENT_INJURED_PED, &e)) {
|
|
|
|
CPed *ped = CPools::GetPed(gaEvent[e].entityRef);
|
|
|
|
if (ped) {
|
|
|
|
ReportAccident(ped);
|
|
|
|
CEventList::ClearEvent(e);
|
|
|
|
}
|
2019-09-15 01:28:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-22 16:28:16 +01:00
|
|
|
CAccident*
|
2020-01-11 13:50:11 +01:00
|
|
|
CAccidentManager::FindNearestAccident(CVector vecPos, float *pDistance)
|
2019-09-15 01:28:07 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_MEDICS_TO_ATTEND_ACCIDENT; i++){
|
|
|
|
int accidentId = -1;
|
|
|
|
float minDistance = 999999;
|
|
|
|
for (int j = 0; j < NUM_ACCIDENTS; j++){
|
|
|
|
CPed* pVictim = m_aAccidents[j].m_pVictim;
|
|
|
|
if (!pVictim)
|
|
|
|
continue;
|
|
|
|
if (pVictim->CharCreatedBy == MISSION_CHAR)
|
|
|
|
continue;
|
|
|
|
if (pVictim->m_fHealth != 0.0f)
|
|
|
|
continue;
|
|
|
|
if (m_aAccidents[j].m_nMedicsPerformingCPR != i)
|
|
|
|
continue;
|
|
|
|
float distance = (pVictim->GetPosition() - vecPos).Magnitude2D();
|
|
|
|
if (distance / 2 > pVictim->GetPosition().z - vecPos.z && distance < minDistance){
|
|
|
|
minDistance = distance;
|
|
|
|
accidentId = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pDistance = minDistance;
|
|
|
|
if (accidentId != -1)
|
|
|
|
return &m_aAccidents[accidentId];
|
|
|
|
}
|
|
|
|
return nil;
|
2019-12-22 16:28:16 +01:00
|
|
|
}
|
|
|
|
|
2020-01-11 13:50:11 +01:00
|
|
|
uint16
|
|
|
|
CAccidentManager::CountActiveAccidents()
|
|
|
|
{
|
|
|
|
uint16 accidents = 0;
|
|
|
|
for (int i = 0; i < NUM_ACCIDENTS; i++) {
|
|
|
|
if (m_aAccidents[i].m_pVictim)
|
|
|
|
accidents++;
|
|
|
|
}
|
|
|
|
return accidents;
|
|
|
|
}
|
|
|
|
|
2019-12-22 16:28:16 +01:00
|
|
|
bool
|
2020-01-11 13:50:11 +01:00
|
|
|
CAccidentManager::WorkToDoForMedics()
|
2019-12-22 16:28:16 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_ACCIDENTS; i++) {
|
2020-01-11 13:50:11 +01:00
|
|
|
if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_nMedicsAttending < MAX_MEDICS_TO_ATTEND_ACCIDENT)
|
2019-12-22 16:28:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-01-11 13:50:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CAccidentManager::UnattendedAccidents()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_ACCIDENTS; i++) {
|
|
|
|
if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_nMedicsAttending == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|