summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2020-01-11 13:50:11 +0100
committerSergeanur <s.anureev@yandex.ua>2020-01-11 14:14:02 +0100
commitbbc68ffb1c9cc55844f4130e15af75042a0384eb (patch)
tree4f082ffb44987135f2400b831f84b605131829b6 /src/core
parentmove (diff)
downloadre3-bbc68ffb1c9cc55844f4130e15af75042a0384eb.tar
re3-bbc68ffb1c9cc55844f4130e15af75042a0384eb.tar.gz
re3-bbc68ffb1c9cc55844f4130e15af75042a0384eb.tar.bz2
re3-bbc68ffb1c9cc55844f4130e15af75042a0384eb.tar.lz
re3-bbc68ffb1c9cc55844f4130e15af75042a0384eb.tar.xz
re3-bbc68ffb1c9cc55844f4130e15af75042a0384eb.tar.zst
re3-bbc68ffb1c9cc55844f4130e15af75042a0384eb.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Accident.cpp101
-rw-r--r--src/core/Accident.h7
-rw-r--r--src/core/Game.cpp2
3 files changed, 94 insertions, 16 deletions
diff --git a/src/core/Accident.cpp b/src/core/Accident.cpp
index a42280b7..d8313ddc 100644
--- a/src/core/Accident.cpp
+++ b/src/core/Accident.cpp
@@ -1,26 +1,70 @@
#include "common.h"
#include "patcher.h"
-#include "AccidentManager.h"
+#include "Accident.h"
#include "Ped.h"
+#include "Pools.h"
+#include "World.h"
CAccidentManager& gAccidentManager = *(CAccidentManager*)0x87FD10;
-WRAPPER void CAccidentManager::Update(void) { EAXJMP(0x456710); }
+CAccident*
+CAccidentManager::GetNextFreeAccident()
+{
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim == nil)
+ return &m_aAccidents[i];
+ }
-uint16
-CAccidentManager::CountActiveAccidents()
+ return nil;
+}
+
+void
+CAccidentManager::ReportAccident(CPed *ped)
{
- uint16 accidents = 0;
- for (int i = 0; i < NUM_ACCIDENTS; i++){
- if (m_aAccidents[i].m_pVictim)
- accidents++;
+ 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()
+{
+ int32 e;
+ if (CEventList::GetEvent(EVENT_INJURED_PED, &e)) {
+ CPed *ped = CPools::GetPed(gaEvent[e].entityRef);
+ if (ped) {
+ ReportAccident(ped);
+ CEventList::ClearEvent(e);
+ }
}
- return accidents;
}
CAccident*
-CAccidentManager::FindNearestAccident(CVector vecPos, float* pDistance)
+CAccidentManager::FindNearestAccident(CVector vecPos, float *pDistance)
{
for (int i = 0; i < MAX_MEDICS_TO_ATTEND_ACCIDENT; i++){
int accidentId = -1;
@@ -48,12 +92,43 @@ CAccidentManager::FindNearestAccident(CVector vecPos, float* pDistance)
return nil;
}
+uint16
+CAccidentManager::CountActiveAccidents()
+{
+ uint16 accidents = 0;
+ for (int i = 0; i < NUM_ACCIDENTS; i++) {
+ if (m_aAccidents[i].m_pVictim)
+ accidents++;
+ }
+ return accidents;
+}
+
bool
-CAccidentManager::UnattendedAccidents(void)
+CAccidentManager::WorkToDoForMedics()
{
for (int i = 0; i < NUM_ACCIDENTS; i++) {
- if (m_aAccidents[i].m_pVictim && m_aAccidents[i].m_nMedicsAttending == 0)
+ if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_nMedicsAttending < MAX_MEDICS_TO_ATTEND_ACCIDENT)
return true;
}
return false;
-} \ No newline at end of file
+}
+
+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;
+}
+
+STARTPATCHES
+ InjectHook(0x4565A0, &CAccidentManager::GetNextFreeAccident, PATCH_JUMP);
+ InjectHook(0x4565D0, &CAccidentManager::ReportAccident, PATCH_JUMP);
+ InjectHook(0x456710, &CAccidentManager::Update, PATCH_JUMP);
+ InjectHook(0x456760, &CAccidentManager::FindNearestAccident, PATCH_JUMP);
+ InjectHook(0x456880, &CAccidentManager::CountActiveAccidents, PATCH_JUMP);
+ InjectHook(0x4568A0, &CAccidentManager::WorkToDoForMedics, PATCH_JUMP);
+ InjectHook(0x4568D0, &CAccidentManager::UnattendedAccidents, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/core/Accident.h b/src/core/Accident.h
index 6a3088e7..69889645 100644
--- a/src/core/Accident.h
+++ b/src/core/Accident.h
@@ -20,10 +20,13 @@ class CAccidentManager
MAX_MEDICS_TO_ATTEND_ACCIDENT = 2
};
public:
+ CAccident *GetNextFreeAccident();
+ void ReportAccident(CPed *ped);
+ void Update();
+ CAccident *FindNearestAccident(CVector vecPos, float *pDistance);
uint16 CountActiveAccidents();
bool UnattendedAccidents();
- CAccident* FindNearestAccident(CVector, float*);
- void Update(void);
+ bool WorkToDoForMedics();
};
extern CAccidentManager& gAccidentManager; \ No newline at end of file
diff --git a/src/core/Game.cpp b/src/core/Game.cpp
index b2bac8dd..08751cf9 100644
--- a/src/core/Game.cpp
+++ b/src/core/Game.cpp
@@ -2,7 +2,7 @@
#include "patcher.h"
#include "Game.h"
#include "main.h"
-#include "AccidentManager.h"
+#include "Accident.h"
#include "Antennas.h"
#include "Bridge.h"
#include "Camera.h"