fixes to zones and vehicle comp rules

This commit is contained in:
aap 2020-08-24 17:21:45 +02:00
parent 0a19925e99
commit 56b80cb0ab
3 changed files with 28 additions and 40 deletions

View File

@ -9,6 +9,8 @@
#include "World.h" #include "World.h"
#include "Timer.h" #include "Timer.h"
//--MIAMI: file almost done (loading/saving will perhaps stay different)
eLevelName CTheZones::m_CurrLevel; eLevelName CTheZones::m_CurrLevel;
int16 CTheZones::FindIndex; int16 CTheZones::FindIndex;
@ -26,14 +28,12 @@ CZoneInfo CTheZones::ZoneInfoArray[2*NUMINFOZONES];
#define SWAPF(a, b) { float t; t = a; a = b; b = t; } #define SWAPF(a, b) { float t; t = a; a = b; b = t; }
//--MIAMI: done
wchar* wchar*
CZone::GetTranslatedName(void) CZone::GetTranslatedName(void)
{ {
return TheText.Get(name); return TheText.Get(name);
} }
//--MIAMI: done
void void
CTheZones::Init(void) CTheZones::Init(void)
{ {
@ -124,7 +124,6 @@ CTheZones::Init(void)
MapZoneArray[0].level = LEVEL_GENERIC; MapZoneArray[0].level = LEVEL_GENERIC;
} }
//--MIAMI: done
void void
CTheZones::Update(void) CTheZones::Update(void)
{ {
@ -137,7 +136,6 @@ CTheZones::Update(void)
m_CurrLevel = GetLevelFromPosition(&pos); m_CurrLevel = GetLevelFromPosition(&pos);
} }
//--MIAMI: done
void void
CTheZones::CreateZone(char *name, eZoneType type, CTheZones::CreateZone(char *name, eZoneType type,
float minx, float miny, float minz, float minx, float miny, float minz,
@ -204,7 +202,6 @@ CTheZones::CreateZone(char *name, eZoneType type,
} }
} }
//--MIAMI: done
void void
CTheZones::PostZoneCreation(void) CTheZones::PostZoneCreation(void)
{ {
@ -214,7 +211,6 @@ CTheZones::PostZoneCreation(void)
InitialiseAudioZoneArray(); InitialiseAudioZoneArray();
} }
//--MIAMI: done, but does nothing
void void
CTheZones::CheckZonesForOverlap(void) CTheZones::CheckZonesForOverlap(void)
{ {
@ -231,7 +227,6 @@ CTheZones::CheckZonesForOverlap(void)
} }
} }
//--MIAMI: done
void void
CTheZones::InsertZoneIntoZoneHierarchy(CZone *zone) CTheZones::InsertZoneIntoZoneHierarchy(CZone *zone)
{ {
@ -241,7 +236,6 @@ CTheZones::InsertZoneIntoZoneHierarchy(CZone *zone)
InsertZoneIntoZoneHierRecursive(zone, &NavigationZoneArray[0]); InsertZoneIntoZoneHierRecursive(zone, &NavigationZoneArray[0]);
} }
//--MIAMI: done
bool bool
CTheZones::InsertZoneIntoZoneHierRecursive(CZone *inner, CZone *outer) CTheZones::InsertZoneIntoZoneHierRecursive(CZone *inner, CZone *outer)
{ {
@ -285,7 +279,6 @@ CTheZones::InsertZoneIntoZoneHierRecursive(CZone *inner, CZone *outer)
return true; return true;
} }
//--MIAMI: done
bool bool
CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer) CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer)
{ {
@ -310,7 +303,6 @@ CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer)
return true; return true;
} }
//--MIAMI: done
bool bool
CTheZones::PointLiesWithinZone(const CVector *v, CZone *zone) CTheZones::PointLiesWithinZone(const CVector *v, CZone *zone)
{ {
@ -319,7 +311,6 @@ CTheZones::PointLiesWithinZone(const CVector *v, CZone *zone)
zone->minz <= v->z && v->z <= zone->maxz; zone->minz <= v->z && v->z <= zone->maxz;
} }
//--MIAMI: done
eLevelName eLevelName
CTheZones::GetLevelFromPosition(CVector const *v) CTheZones::GetLevelFromPosition(CVector const *v)
{ {
@ -333,7 +324,6 @@ CTheZones::GetLevelFromPosition(CVector const *v)
return MapZoneArray[0].level; return MapZoneArray[0].level;
} }
//--MIAMI: done
CZone* CZone*
CTheZones::FindInformationZoneForPosition(const CVector *v) CTheZones::FindInformationZoneForPosition(const CVector *v)
{ {
@ -347,7 +337,6 @@ CTheZones::FindInformationZoneForPosition(const CVector *v)
return &InfoZoneArray[0]; return &InfoZoneArray[0];
} }
//--MIAMI: done
CZone* CZone*
CTheZones::FindSmallestNavigationZoneForPosition(const CVector *v, bool findDefault, bool findNavig) CTheZones::FindSmallestNavigationZoneForPosition(const CVector *v, bool findDefault, bool findNavig)
{ {
@ -370,7 +359,6 @@ CTheZones::FindSmallestNavigationZoneForPosition(const CVector *v, bool findDefa
return best; return best;
} }
//--MIAMI: done
int16 int16
CTheZones::FindZoneByLabelAndReturnIndex(char *name, eZoneType type) CTheZones::FindZoneByLabelAndReturnIndex(char *name, eZoneType type)
{ {
@ -400,7 +388,6 @@ CTheZones::FindZoneByLabelAndReturnIndex(char *name, eZoneType type)
return -1; return -1;
} }
//--MIAMI: done
int16 int16
CTheZones::FindNextZoneByLabelAndReturnIndex(char *name, eZoneType type) CTheZones::FindNextZoneByLabelAndReturnIndex(char *name, eZoneType type)
{ {
@ -431,7 +418,6 @@ CTheZones::FindNextZoneByLabelAndReturnIndex(char *name, eZoneType type)
return -1; return -1;
} }
//--MIAMI: done
CZoneInfo* CZoneInfo*
CTheZones::GetZoneInfo(const CVector *v, uint8 day) CTheZones::GetZoneInfo(const CVector *v, uint8 day)
{ {
@ -556,7 +542,7 @@ CTheZones::SetZonePedInfo(uint16 zoneid, uint8 day, int16 pedDensity,
info->gangPedThreshold[8] = info->gangPedThreshold[7]; info->gangPedThreshold[8] = info->gangPedThreshold[7];
} }
//--MIAMI: done, unused //--MIAMI: unused
void void
CTheZones::SetCarDensity(uint16 zoneid, uint8 day, uint16 cardensity) CTheZones::SetCarDensity(uint16 zoneid, uint8 day, uint16 cardensity)
{ {
@ -565,7 +551,7 @@ CTheZones::SetCarDensity(uint16 zoneid, uint8 day, uint16 cardensity)
ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].carDensity = cardensity; ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].carDensity = cardensity;
} }
//--MIAMI: done, unused //--MIAMI: unused
void void
CTheZones::SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity) CTheZones::SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity)
{ {
@ -574,7 +560,6 @@ CTheZones::SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity)
ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedDensity = peddensity; ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedDensity = peddensity;
} }
//--MIAMI: done
void void
CTheZones::SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup) CTheZones::SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup)
{ {
@ -583,7 +568,6 @@ CTheZones::SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup)
ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedGroup = pedgroup; ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedGroup = pedgroup;
} }
//--MIAMI: done
int16 int16
CTheZones::FindAudioZone(CVector *pos) CTheZones::FindAudioZone(CVector *pos)
{ {
@ -595,7 +579,6 @@ CTheZones::FindAudioZone(CVector *pos)
return -1; return -1;
} }
//--MIAMI: done
void void
CTheZones::AddZoneToAudioZoneArray(CZone *zone) CTheZones::AddZoneToAudioZoneArray(CZone *zone)
{ {
@ -613,7 +596,6 @@ CTheZones::AddZoneToAudioZoneArray(CZone *zone)
AudioZoneArray[NumberOfAudioZones++] = z; AudioZoneArray[NumberOfAudioZones++] = z;
} }
//--MIAMI: done
void void
CTheZones::InitialiseAudioZoneArray(void) CTheZones::InitialiseAudioZoneArray(void)
{ {
@ -645,7 +627,6 @@ CTheZones::InitialiseAudioZoneArray(void)
} }
} }
//--MIAMI: TODO
void void
CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) CTheZones::SaveAllZones(uint8 *buffer, uint32 *size)
{ {
@ -666,7 +647,7 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size)
WriteSaveBuf(buffer, FindIndex); WriteSaveBuf(buffer, FindIndex);
WriteSaveBuf(buffer, (int16)0); // padding WriteSaveBuf(buffer, (int16)0); // padding
// TODO(MIAMI): implement SaveOneZone // TODO(MIAMI) ? implement SaveOneZone
for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){ for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){
CZone *zone = WriteSaveBuf(buffer, NavigationZoneArray[i]); CZone *zone = WriteSaveBuf(buffer, NavigationZoneArray[i]);
zone->child = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].child); zone->child = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].child);
@ -676,6 +657,14 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size)
for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){ for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){
CZone *zone = WriteSaveBuf(buffer, InfoZoneArray[i]); CZone *zone = WriteSaveBuf(buffer, InfoZoneArray[i]);
/*
The call of GetIndexForZonePointer is wrong, as it is
meant for a different array, but the game doesn't brake
if those fields are nil. Let's make sure they are.
*/
assert(InfoZoneArray[i].child == nil);
assert(InfoZoneArray[i].parent == nil);
assert(InfoZoneArray[i].next == nil);
zone->child = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].child); zone->child = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].child);
zone->parent = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].parent); zone->parent = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].parent);
zone->next = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].next); zone->next = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].next);
@ -691,11 +680,7 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size)
for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) { for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) {
CZone* zone = WriteSaveBuf(buffer, MapZoneArray[i]); CZone* zone = WriteSaveBuf(buffer, MapZoneArray[i]);
/* // see above
The call of GetIndexForZonePointer is wrong, as it is
meant for a different array, but the game doesn't brake
if those fields are nil. Let's make sure they are.
*/
assert(MapZoneArray[i].child == nil); assert(MapZoneArray[i].child == nil);
assert(MapZoneArray[i].parent == nil); assert(MapZoneArray[i].parent == nil);
assert(MapZoneArray[i].next == nil); assert(MapZoneArray[i].next == nil);
@ -713,7 +698,6 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size)
VALIDATESAVEBUF(*size) VALIDATESAVEBUF(*size)
} }
//--MIAMI: TODO
void void
CTheZones::LoadAllZones(uint8 *buffer, uint32 size) CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
{ {
@ -726,7 +710,7 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
FindIndex = ReadSaveBuf<int16>(buffer); FindIndex = ReadSaveBuf<int16>(buffer);
ReadSaveBuf<int16>(buffer); ReadSaveBuf<int16>(buffer);
// TODO(MIAMI): implement LoadOneZone // TODO(MIAMI) ? implement LoadOneZone
for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){ for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){
NavigationZoneArray[i] = ReadSaveBuf<CZone>(buffer); NavigationZoneArray[i] = ReadSaveBuf<CZone>(buffer);
@ -738,6 +722,14 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){ for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){
InfoZoneArray[i] = ReadSaveBuf<CZone>(buffer); InfoZoneArray[i] = ReadSaveBuf<CZone>(buffer);
/*
The call of GetPointerForZoneIndex is wrong, as it is
meant for a different array, but the game doesn't brake
if save data stored is -1.
*/
InfoZoneArray[i].child = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].child);
InfoZoneArray[i].parent = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].parent);
InfoZoneArray[i].next = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].next);
InfoZoneArray[i].child = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].child); InfoZoneArray[i].child = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].child);
InfoZoneArray[i].parent = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].parent); InfoZoneArray[i].parent = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].parent);
InfoZoneArray[i].next = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].next); InfoZoneArray[i].next = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].next);
@ -753,11 +745,7 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){ for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){
MapZoneArray[i] = ReadSaveBuf<CZone>(buffer); MapZoneArray[i] = ReadSaveBuf<CZone>(buffer);
/* // see above
The call of GetPointerForZoneIndex is wrong, as it is
meant for a different array, but the game doesn't brake
if save data stored is -1.
*/
MapZoneArray[i].child = GetPointerForZoneIndex((uintptr)MapZoneArray[i].child); MapZoneArray[i].child = GetPointerForZoneIndex((uintptr)MapZoneArray[i].child);
MapZoneArray[i].parent = GetPointerForZoneIndex((uintptr)MapZoneArray[i].parent); MapZoneArray[i].parent = GetPointerForZoneIndex((uintptr)MapZoneArray[i].parent);
MapZoneArray[i].next = GetPointerForZoneIndex((uintptr)MapZoneArray[i].next); MapZoneArray[i].next = GetPointerForZoneIndex((uintptr)MapZoneArray[i].next);

View File

@ -103,8 +103,8 @@ public:
static void SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity); static void SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity);
static void SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup); static void SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup);
static int16 FindAudioZone(CVector *pos); static int16 FindAudioZone(CVector *pos);
static CZone *GetPointerForZoneIndex(int32 i) { return i == -1 ? nil : &InfoZoneArray[i]; } static CZone *GetPointerForZoneIndex(int32 i) { return i == -1 ? nil : &NavigationZoneArray[i]; }
static int32 GetIndexForZonePointer(CZone *zone) { return zone == nil ? -1 : zone - InfoZoneArray; } static int32 GetIndexForZonePointer(CZone *zone) { return zone == nil ? -1 : zone - NavigationZoneArray; }
static void AddZoneToAudioZoneArray(CZone *zone); static void AddZoneToAudioZoneArray(CZone *zone);
static void InitialiseAudioZoneArray(void); static void InitialiseAudioZoneArray(void);
static void SaveAllZones(uint8 *buffer, uint32 *length); static void SaveAllZones(uint8 *buffer, uint32 *length);

View File

@ -211,7 +211,7 @@ CVehicleModelInfo::CreateInstance(void)
clumpframe = RpClumpGetFrame(clump); clumpframe = RpClumpGetFrame(clump);
comp1 = ChooseComponent(); comp1 = ChooseComponent();
if(comp1 != -1){ if(comp1 != -1 && m_comps[comp1]){
atomic = RpAtomicClone(m_comps[comp1]); atomic = RpAtomicClone(m_comps[comp1]);
f = RwFrameCreate(); f = RwFrameCreate();
RwFrameTransform(f, RwFrameTransform(f,
@ -224,7 +224,7 @@ CVehicleModelInfo::CreateInstance(void)
ms_compsUsed[0] = comp1; ms_compsUsed[0] = comp1;
comp2 = ChooseSecondComponent(); comp2 = ChooseSecondComponent();
if(comp2 != -1){ if(comp2 != -1 && m_comps[comp2]){
atomic = RpAtomicClone(m_comps[comp2]); atomic = RpAtomicClone(m_comps[comp2]);
f = RwFrameCreate(); f = RwFrameCreate();
RwFrameTransform(f, RwFrameTransform(f,