commit
2d00d7b3e2
@ -39,7 +39,6 @@ to reverse at the time, calling the original functions is acceptable.
|
|||||||
### Unreversed / incomplete classes (at least the ones we know)
|
### Unreversed / incomplete classes (at least the ones we know)
|
||||||
```
|
```
|
||||||
CAudioManager, cDMAudio, cSampleManager and all audio - being worked on
|
CAudioManager, cDMAudio, cSampleManager and all audio - being worked on
|
||||||
CAccidentManager
|
|
||||||
CBoat
|
CBoat
|
||||||
CBrightLights
|
CBrightLights
|
||||||
CBulletInfo
|
CBulletInfo
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
#include "patcher.h"
|
#include "patcher.h"
|
||||||
#include "CarAI.h"
|
#include "CarAI.h"
|
||||||
|
|
||||||
#include "AccidentManager.h"
|
#include "Accident.h"
|
||||||
#include "AutoPilot.h"
|
#include "AutoPilot.h"
|
||||||
#include "CarCtrl.h"
|
#include "CarCtrl.h"
|
||||||
#include "General.h"
|
#include "General.h"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "patcher.h"
|
#include "patcher.h"
|
||||||
#include "CarCtrl.h"
|
#include "CarCtrl.h"
|
||||||
|
|
||||||
#include "AccidentManager.h"
|
#include "Accident.h"
|
||||||
#include "Automobile.h"
|
#include "Automobile.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "CarAI.h"
|
#include "CarAI.h"
|
||||||
|
134
src/core/Accident.cpp
Normal file
134
src/core/Accident.cpp
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include "patcher.h"
|
||||||
|
#include "Accident.h"
|
||||||
|
|
||||||
|
#include "Ped.h"
|
||||||
|
#include "Pools.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
CAccidentManager& gAccidentManager = *(CAccidentManager*)0x87FD10;
|
||||||
|
|
||||||
|
CAccident*
|
||||||
|
CAccidentManager::GetNextFreeAccident()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < NUM_ACCIDENTS; i++) {
|
||||||
|
if (m_aAccidents[i].m_pVictim == nil)
|
||||||
|
return &m_aAccidents[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CAccidentManager::ReportAccident(CPed *ped)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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::WorkToDoForMedics()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < NUM_ACCIDENTS; i++) {
|
||||||
|
if (m_aAccidents[i].m_pVictim != nil && m_aAccidents[i].m_nMedicsAttending < MAX_MEDICS_TO_ATTEND_ACCIDENT)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
@ -20,10 +20,13 @@ class CAccidentManager
|
|||||||
MAX_MEDICS_TO_ATTEND_ACCIDENT = 2
|
MAX_MEDICS_TO_ATTEND_ACCIDENT = 2
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
|
CAccident *GetNextFreeAccident();
|
||||||
|
void ReportAccident(CPed *ped);
|
||||||
|
void Update();
|
||||||
|
CAccident *FindNearestAccident(CVector vecPos, float *pDistance);
|
||||||
uint16 CountActiveAccidents();
|
uint16 CountActiveAccidents();
|
||||||
bool UnattendedAccidents();
|
bool UnattendedAccidents();
|
||||||
CAccident* FindNearestAccident(CVector, float*);
|
bool WorkToDoForMedics();
|
||||||
void Update(void);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CAccidentManager& gAccidentManager;
|
extern CAccidentManager& gAccidentManager;
|
@ -2,7 +2,7 @@
|
|||||||
#include "patcher.h"
|
#include "patcher.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "AccidentManager.h"
|
#include "Accident.h"
|
||||||
#include "Antennas.h"
|
#include "Antennas.h"
|
||||||
#include "Bridge.h"
|
#include "Bridge.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "Fire.h"
|
#include "Fire.h"
|
||||||
#include "General.h"
|
#include "General.h"
|
||||||
#include "CarCtrl.h"
|
#include "CarCtrl.h"
|
||||||
#include "AccidentManager.h"
|
#include "Accident.h"
|
||||||
|
|
||||||
CEmergencyPed::CEmergencyPed(uint32 type) : CPed(type)
|
CEmergencyPed::CEmergencyPed(uint32 type) : CPed(type)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user