1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-10-31 23:25:59 +00:00
re3/src/control/Restart.cpp

250 lines
7.2 KiB
C++
Raw Normal View History

2019-08-03 13:01:13 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2019-08-03 13:01:13 +00:00
#include "Restart.h"
2019-10-10 09:20:53 +00:00
#include "Zones.h"
#include "PathFind.h"
2019-08-03 13:01:13 +00:00
2020-04-17 05:54:14 +00:00
uint8 CRestart::OverrideHospitalLevel;
uint8 CRestart::OverridePoliceStationLevel;
bool CRestart::bFadeInAfterNextArrest;
bool CRestart::bFadeInAfterNextDeath;
2019-10-07 21:29:30 +00:00
2020-04-17 05:54:14 +00:00
bool CRestart::bOverrideRestart;
CVector CRestart::OverridePosition;
float CRestart::OverrideHeading;
2019-10-10 09:20:53 +00:00
2020-04-17 05:54:14 +00:00
CVector CRestart::HospitalRestartPoints[NUM_RESTART_POINTS];
float CRestart::HospitalRestartHeadings[NUM_RESTART_POINTS];
uint16 CRestart::NumberOfHospitalRestarts;
2019-10-10 09:20:53 +00:00
2020-04-17 05:54:14 +00:00
CVector CRestart::PoliceRestartPoints[NUM_RESTART_POINTS];
float CRestart::PoliceRestartHeadings[NUM_RESTART_POINTS];
uint16 CRestart::NumberOfPoliceRestarts;
2019-10-10 09:20:53 +00:00
2020-04-09 18:50:24 +00:00
void
CRestart::Initialise()
{
2020-07-13 14:43:09 +00:00
OverridePoliceStationLevel = LEVEL_GENERIC;
OverrideHospitalLevel = LEVEL_GENERIC;
2020-04-09 18:50:24 +00:00
bFadeInAfterNextArrest = true;
bFadeInAfterNextDeath = true;
OverrideHeading = 0.0f;
OverridePosition = CVector(0.0f, 0.0f, 0.0f);
bOverrideRestart = false;
NumberOfPoliceRestarts = 0;
NumberOfHospitalRestarts = 0;
for (int i = 0; i < NUM_RESTART_POINTS; i++) {
HospitalRestartPoints[i] = CVector(0.0f, 0.0f, 0.0f);
HospitalRestartHeadings[i] = 0.0f;
PoliceRestartPoints[i] = CVector(0.0f, 0.0f, 0.0f);
PoliceRestartHeadings[i] = 0.0f;
}
}
void
CRestart::AddHospitalRestartPoint(const CVector &pos, float heading)
{
HospitalRestartPoints[NumberOfHospitalRestarts] = pos;
HospitalRestartHeadings[NumberOfHospitalRestarts++] = heading;
}
void
CRestart::AddPoliceRestartPoint(const CVector &pos, float heading)
{
PoliceRestartPoints[NumberOfPoliceRestarts] = pos;
PoliceRestartHeadings[NumberOfPoliceRestarts++] = heading;
}
void
CRestart::OverrideNextRestart(const CVector &pos, float heading)
{
bOverrideRestart = true;
OverridePosition = pos;
OverrideHeading = heading;
2019-10-10 09:20:53 +00:00
}
2020-04-09 18:50:24 +00:00
void
CRestart::CancelOverrideRestart()
{
bOverrideRestart = false;
2019-10-10 09:20:53 +00:00
}
2020-04-09 18:50:24 +00:00
void
CRestart::FindClosestHospitalRestartPoint(const CVector &pos, CVector *outPos, float *outHeading)
{
if (bOverrideRestart) {
*outPos = OverridePosition;
*outHeading = OverrideHeading;
CancelOverrideRestart();
return;
}
eLevelName curlevel = CTheZones::FindZoneForPoint(pos);
2020-11-21 23:29:17 +00:00
float fMinDist = SQR(4000.0f);
2020-04-09 18:50:24 +00:00
int closestPoint = NUM_RESTART_POINTS;
// find closest point on this level
for (int i = 0; i < NumberOfHospitalRestarts; i++) {
2020-07-13 14:43:09 +00:00
if (CTheZones::FindZoneForPoint(HospitalRestartPoints[i]) == (OverrideHospitalLevel != LEVEL_GENERIC ? OverrideHospitalLevel : curlevel)) {
2020-04-09 18:50:24 +00:00
float dist = (pos - HospitalRestartPoints[i]).MagnitudeSqr();
if (fMinDist >= dist) {
fMinDist = dist;
closestPoint = i;
}
}
}
// if we didn't find anything, find closest point on any level
if (closestPoint == NUM_RESTART_POINTS) {
for (int i = 0; i < NumberOfHospitalRestarts; i++) {
float dist = (pos - HospitalRestartPoints[i]).MagnitudeSqr();
if (fMinDist >= dist) {
fMinDist = dist;
closestPoint = i;
}
}
}
// if we still didn't find anything, find closest path node
if (closestPoint == NUM_RESTART_POINTS) {
*outPos = ThePaths.m_pathNodes[ThePaths.FindNodeClosestToCoors(pos, PATH_PED, 999999.9f)].GetPosition();
2020-04-09 18:50:24 +00:00
*outHeading = 0.0f;
printf("Couldn't find a hospital restart zone near the player %f %f %f->%f %f %f\n", pos.x, pos.y, pos.z, outPos->x, outPos->y, outPos->z);
} else {
*outPos = HospitalRestartPoints[closestPoint];
*outHeading = HospitalRestartHeadings[closestPoint];
}
2019-10-10 09:20:53 +00:00
}
2020-04-09 18:50:24 +00:00
void
CRestart::FindClosestPoliceRestartPoint(const CVector &pos, CVector *outPos, float *outHeading)
{
if (bOverrideRestart) {
*outPos = OverridePosition;
*outHeading = OverrideHeading;
CancelOverrideRestart();
return;
}
eLevelName curlevel = CTheZones::FindZoneForPoint(pos);
2020-11-21 23:31:52 +00:00
float fMinDist = SQR(4000.0f);
2020-04-09 18:50:24 +00:00
int closestPoint = NUM_RESTART_POINTS;
// find closest point on this level
for (int i = 0; i < NumberOfPoliceRestarts; i++) {
2020-07-13 14:43:09 +00:00
if (CTheZones::FindZoneForPoint(PoliceRestartPoints[i]) == (OverridePoliceStationLevel != LEVEL_GENERIC ? OverridePoliceStationLevel : curlevel)) {
2020-04-09 18:50:24 +00:00
float dist = (pos - PoliceRestartPoints[i]).MagnitudeSqr();
if (fMinDist >= dist) {
fMinDist = dist;
closestPoint = i;
}
}
}
// if we didn't find anything, find closest point on any level
if (closestPoint == NUM_RESTART_POINTS) {
for (int i = 0; i < NumberOfPoliceRestarts; i++) {
float dist = (pos - PoliceRestartPoints[i]).MagnitudeSqr();
if (fMinDist >= dist) {
fMinDist = dist;
closestPoint = i;
}
}
}
// if we still didn't find anything, find closest path node
if (closestPoint == NUM_RESTART_POINTS) {
printf("Couldn't find a police restart zone near the player\n");
*outPos = ThePaths.m_pathNodes[ThePaths.FindNodeClosestToCoors(pos, PATH_PED, 999999.9f)].GetPosition();
2020-04-09 18:50:24 +00:00
*outHeading = 0.0f;
} else {
*outPos = PoliceRestartPoints[closestPoint];
*outHeading = PoliceRestartHeadings[closestPoint];
}
2019-10-10 09:20:53 +00:00
}
2020-04-09 18:50:24 +00:00
void
CRestart::LoadAllRestartPoints(uint8 *buf, uint32 size)
{
Initialise();
INITSAVEBUF
CheckSaveHeader(buf, 'R','S','T','\0', size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUM_RESTART_POINTS; i++) {
HospitalRestartPoints[i] = ReadSaveBuf<CVector>(buf);
HospitalRestartHeadings[i] = ReadSaveBuf<float>(buf);
}
for (int i = 0; i < NUM_RESTART_POINTS; i++) {
PoliceRestartPoints[i] = ReadSaveBuf<CVector>(buf);
PoliceRestartHeadings[i] = ReadSaveBuf<float>(buf);
}
NumberOfHospitalRestarts = ReadSaveBuf<uint16>(buf);
NumberOfPoliceRestarts = ReadSaveBuf<uint16>(buf);
bOverrideRestart = ReadSaveBuf<bool>(buf);
// skip something unused
ReadSaveBuf<uint8>(buf);
ReadSaveBuf<uint16>(buf);
OverridePosition = ReadSaveBuf<CVector>(buf);
OverrideHeading = ReadSaveBuf<float>(buf);
bFadeInAfterNextDeath = ReadSaveBuf<bool>(buf);
bFadeInAfterNextArrest = ReadSaveBuf<bool>(buf);
OverrideHospitalLevel = ReadSaveBuf<uint8>(buf);
OverridePoliceStationLevel = ReadSaveBuf<uint8>(buf);
VALIDATESAVEBUF(size);
2019-10-10 09:20:53 +00:00
}
2020-04-09 18:50:24 +00:00
void
CRestart::SaveAllRestartPoints(uint8 *buf, uint32 *size)
{
*size = SAVE_HEADER_SIZE
+ sizeof(HospitalRestartPoints)
+ sizeof(HospitalRestartHeadings)
+ sizeof(PoliceRestartPoints)
+ sizeof(PoliceRestartHeadings)
+ sizeof(NumberOfHospitalRestarts)
+ sizeof(NumberOfPoliceRestarts)
+ sizeof(bOverrideRestart)
+ sizeof(uint8)
+ sizeof(uint16)
+ sizeof(OverridePosition)
+ sizeof(OverrideHeading)
+ sizeof(bFadeInAfterNextDeath)
+ sizeof(bFadeInAfterNextArrest)
+ sizeof(OverrideHospitalLevel)
+ sizeof(OverridePoliceStationLevel); // == 292
INITSAVEBUF
WriteSaveHeader(buf, 'R','S','T','\0', *size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUM_RESTART_POINTS; i++) {
WriteSaveBuf(buf, HospitalRestartPoints[i]);
WriteSaveBuf(buf, HospitalRestartHeadings[i]);
}
for (int i = 0; i < NUM_RESTART_POINTS; i++) {
WriteSaveBuf(buf, PoliceRestartPoints[i]);
WriteSaveBuf(buf, PoliceRestartHeadings[i]);
}
WriteSaveBuf(buf, NumberOfHospitalRestarts);
WriteSaveBuf(buf, NumberOfPoliceRestarts);
WriteSaveBuf(buf, bOverrideRestart);
WriteSaveBuf(buf, (uint8)0);
WriteSaveBuf(buf, (uint16)0);
WriteSaveBuf(buf, OverridePosition);
WriteSaveBuf(buf, OverrideHeading);
WriteSaveBuf(buf, bFadeInAfterNextDeath);
WriteSaveBuf(buf, bFadeInAfterNextArrest);
WriteSaveBuf(buf, OverrideHospitalLevel);
WriteSaveBuf(buf, OverridePoliceStationLevel);
VALIDATESAVEBUF(*size);
2019-10-10 09:20:53 +00:00
}