summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Accident.cpp59
-rw-r--r--src/core/Accident.h29
2 files changed, 88 insertions, 0 deletions
diff --git a/src/core/Accident.cpp b/src/core/Accident.cpp
new file mode 100644
index 00000000..a42280b7
--- /dev/null
+++ b/src/core/Accident.cpp
@@ -0,0 +1,59 @@
+#include "common.h"
+#include "patcher.h"
+#include "AccidentManager.h"
+
+#include "Ped.h"
+
+CAccidentManager& gAccidentManager = *(CAccidentManager*)0x87FD10;
+
+WRAPPER void CAccidentManager::Update(void) { EAXJMP(0x456710); }
+
+uint16
+CAccidentManager::CountActiveAccidents()
+{
+ uint16 accidents = 0;
+ for (int i = 0; i < NUM_ACCIDENTS; i++){
+ if (m_aAccidents[i].m_pVictim)
+ accidents++;
+ }
+ return accidents;
+}
+
+CAccident*
+CAccidentManager::FindNearestAccident(CVector vecPos, float* pDistance)
+{
+ 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;
+}
+
+bool
+CAccidentManager::UnattendedAccidents(void)
+{
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim && m_aAccidents[i].m_nMedicsAttending == 0)
+ return true;
+ }
+ return false;
+} \ No newline at end of file
diff --git a/src/core/Accident.h b/src/core/Accident.h
new file mode 100644
index 00000000..6a3088e7
--- /dev/null
+++ b/src/core/Accident.h
@@ -0,0 +1,29 @@
+#pragma once
+#include "common.h"
+#include "config.h"
+
+class CPed;
+
+class CAccident
+{
+public:
+ CPed *m_pVictim;
+ uint32 m_nMedicsAttending;
+ uint32 m_nMedicsPerformingCPR;
+ CAccident() : m_pVictim(nil), m_nMedicsAttending(0), m_nMedicsPerformingCPR(0) {}
+};
+
+class CAccidentManager
+{
+ CAccident m_aAccidents[NUM_ACCIDENTS];
+ enum {
+ MAX_MEDICS_TO_ATTEND_ACCIDENT = 2
+ };
+public:
+ uint16 CountActiveAccidents();
+ bool UnattendedAccidents();
+ CAccident* FindNearestAccident(CVector, float*);
+ void Update(void);
+};
+
+extern CAccidentManager& gAccidentManager; \ No newline at end of file