Skip to content

Commit 07c1753

Browse files
committed
Load all base car models into memory (as permanent textures are already present)
+ Added MAX_CAR_RESIDENT_MODELS + use custom array for mission residentModels as new additional slot present
1 parent c9b59e1 commit 07c1753

23 files changed

Lines changed: 286 additions & 222 deletions

src_rebuild/Game/C/cars.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,22 @@ DENTUVS *gTempCarUVPtr;
7979
DENTUVS gTempHDCarUVDump[MAX_CARS][MAX_DENTING_UVS];
8080
DENTUVS gTempLDCarUVDump[MAX_CARS][MAX_DENTING_LOD_UVS];
8181

82-
CAR_MODEL NewCarModel[MAX_CAR_MODELS];
83-
CAR_MODEL NewLowCarModel[MAX_CAR_MODELS];
82+
CAR_MODEL NewCarModel[MAX_CAR_RESIDENT_MODELS];
83+
CAR_MODEL NewLowCarModel[MAX_CAR_RESIDENT_MODELS];
8484

85-
MODEL* gCarLowModelPtr[MAX_CAR_MODELS];
86-
MODEL* gCarDamModelPtr[MAX_CAR_MODELS];
87-
MODEL* gCarCleanModelPtr[MAX_CAR_MODELS];
85+
MODEL* gCarLowModelPtr[MAX_CAR_RESIDENT_MODELS];
86+
MODEL* gCarDamModelPtr[MAX_CAR_RESIDENT_MODELS];
87+
MODEL* gCarCleanModelPtr[MAX_CAR_RESIDENT_MODELS];
8888

8989
// pedestrian palette at 0 and next are cars
9090
// model_id, texture_number, palette
9191
u_short civ_clut[8][32][6];
9292

93+
#define MAX_CAR_POLYS (200 * 2) * MAX_CAR_RESIDENT_MODELS
94+
9395
int whichCP = 0;
9496
int baseSpecCP = 0;
95-
CAR_POLY carPolyBuffer[2001];
97+
CAR_POLY carPolyBuffer[MAX_CAR_POLYS + 1];
9698

9799
char LeftLight = 0;
98100
char RightLight = 0;
@@ -1065,7 +1067,7 @@ void buildNewCarFromModel(int index, int detail, char* polySrc, MODEL* model)
10651067

10661068
newNumPolys = whichCP;
10671069

1068-
for (i = 0; newNumPolys < 2000 && i < model->num_polys; i++)
1070+
for (i = 0; newNumPolys < MAX_CAR_POLYS && i < model->num_polys; i++)
10691071
{
10701072
ptype = *polyList;
10711073

src_rebuild/Game/C/cars.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ extern CAR_DATA car_data[MAX_CARS + 2]; // all cars + Tanner cbox + Camera cbox
1313
extern CAR_DATA* active_car_list[MAX_CARS];
1414
extern unsigned char lightsOnDelay[MAX_CARS];
1515

16-
extern CAR_MODEL NewCarModel[MAX_CAR_MODELS];
17-
extern CAR_MODEL NewLowCarModel[MAX_CAR_MODELS];
16+
extern CAR_MODEL NewCarModel[MAX_CAR_RESIDENT_MODELS];
17+
extern CAR_MODEL NewLowCarModel[MAX_CAR_RESIDENT_MODELS];
1818

19-
extern MODEL* gCarLowModelPtr[MAX_CAR_MODELS];
20-
extern MODEL* gCarDamModelPtr[MAX_CAR_MODELS];
21-
extern MODEL* gCarCleanModelPtr[MAX_CAR_MODELS];
19+
extern MODEL* gCarLowModelPtr[MAX_CAR_RESIDENT_MODELS];
20+
extern MODEL* gCarDamModelPtr[MAX_CAR_RESIDENT_MODELS];
21+
extern MODEL* gCarCleanModelPtr[MAX_CAR_RESIDENT_MODELS];
2222

2323
extern int whichCP; // car poly counter
2424
extern int baseSpecCP; // special car poly counter

src_rebuild/Game/C/civ_ai.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct
4444
} civPingTest;
4545
#endif // DEBUG
4646

47-
char modelRandomList[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 0, 1, 0, 4 };
47+
char modelRandomList[16] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 0, 1, 0, 4 };
4848
u_char reservedSlots[MAX_CARS] = { 0 };
4949

5050
int distFurthestCivCarSq = 0;
@@ -1595,7 +1595,7 @@ int PingOutAllSpecialCivCars(void)
15951595

15961596
do
15971597
{
1598-
if (lcp->controlType == CONTROL_TYPE_CIV_AI && MissionHeader->residentModels[lcp->ap.model] > 4)
1598+
if (lcp->controlType == CONTROL_TYPE_CIV_AI && missionResidentCarModels[lcp->ap.model] > 4)
15991599
PingOutCar(lcp);
16001600

16011601
lcp++;
@@ -1786,22 +1786,19 @@ int CreateStationaryCivCar(int direction, int orientX, int orientZ, LONGVECTOR4*
17861786
unsigned char* slot;
17871787
CAR_DATA* newCar;
17881788
CAR_DATA* carCnt;
1789-
int model;
1789+
int model, i;
17901790
EXTRA_CIV_DATA civDat;
17911791
LONGQUATERNION tmpQ;
17921792

17931793
model = -1;
1794-
1795-
if (MissionHeader->residentModels[0] == externalModel)
1796-
model = 0;
1797-
else if (MissionHeader->residentModels[1] == externalModel)
1798-
model = 1;
1799-
else if (MissionHeader->residentModels[2] == externalModel)
1800-
model = 2;
1801-
else if (MissionHeader->residentModels[3] == externalModel)
1802-
model = 3;
1803-
else if (MissionHeader->residentModels[4] == externalModel)
1804-
model = 4;
1794+
for(i = 0; i < MAX_CAR_RESIDENT_MODELS; ++i)
1795+
{
1796+
if (missionResidentCarModels[i] == externalModel)
1797+
{
1798+
model = i;
1799+
break;
1800+
}
1801+
}
18051802

18061803
if (model != -1)
18071804
{
@@ -2172,18 +2169,27 @@ int PingInCivCar(int minPingInDist)
21722169
}
21732170

21742171
// check if special car is loaded and add it to random list
2175-
if (specModelValid == 0 || allowSpecSpooling == 0 || MissionHeader->residentModels[4] == 12)
2172+
if ((specModelValid == 0 || allowSpecSpooling == 0 || missionResidentCarModels[MAX_CAR_RESIDENT_MODELS-1] == 12) && missionResidentCarModels[MAX_CAR_RESIDENT_MODELS-1] >= 8)
21762173
{
2174+
#if MAX_CAR_RESIDENT_MODELS == 6
2175+
modelRandomList[15] = 4;
2176+
#else
21772177
modelRandomList[15] = 0;
2178+
#endif
21782179
modelRandomList[14] = 1;
21792180
}
21802181
else
21812182
{
21822183
modelRandomList[15] = 4;
2184+
2185+
#if MAX_CAR_RESIDENT_MODELS == 6
2186+
modelRandomList[14] = 4;
2187+
#else
21832188
modelRandomList[14] = 1;
2189+
#endif
21842190

21852191
if ((Random2(0) & 0x100) != 0)
2186-
modelRandomList[14] = 4;
2192+
modelRandomList[14] = MAX_CAR_RESIDENT_MODELS-1;
21872193
}
21882194

21892195
// another change for Caine's compound
@@ -2211,15 +2217,15 @@ int PingInCivCar(int minPingInDist)
22112217
}
22122218
else
22132219
{
2214-
model = modelRandomList[Random2(0) & 0xf];
2220+
model = modelRandomList[Random2(0) & 15];
22152221
}
22162222

22172223
// force spawn limo nearby in Caine's Cash
22182224
if (minPingInDist == 666)
22192225
model = 4;
22202226

22212227
// select car color palette
2222-
if (MissionHeader->residentModels[model] == 0 || MissionHeader->residentModels[model] > 4)
2228+
if (missionResidentCarModels[model] == 0 || missionResidentCarModels[model] > 4)
22232229
{
22242230
civDat.palette = 0;
22252231
}
@@ -2886,12 +2892,7 @@ void SetUpCivCollFlags(void)
28862892
hornchanflag[i] = GetFreeChannel();
28872893
SpuSetVoiceAR(hornchanflag[i], 27);
28882894

2889-
if (cp0->ap.model == 4)
2890-
sample = ResidentModelsBodge();
2891-
else if (cp0->ap.model < 3)
2892-
sample = cp0->ap.model;
2893-
else
2894-
sample = cp0->ap.model - 1;
2895+
sample = GetCarBankSample(cp0->ap.model);
28952896

28962897
// [A] use tracking sound
28972898
Start3DTrackingSound(hornchanflag[i], SOUND_BANK_CARS, sample * 3 + 2,
@@ -3298,7 +3299,7 @@ void CreateRoadblock(void)
32983299
noMoreCars = 0;
32993300
distAlongSegment = -5;
33003301
lbody = car_cosmetics[3].colBox.vz;
3301-
externalCopModel = MissionHeader->residentModels[3];
3302+
externalCopModel = missionResidentCarModels[3];
33023303

33033304
// [A] use player instead of car
33043305
dir = player[0].dir;

src_rebuild/Game/C/cosmetic.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ char* CosmeticFiles[] = {
1717
"LEVELS\\RIO.LCF",
1818
};
1919

20-
CAR_COSMETICS car_cosmetics[MAX_CAR_MODELS];
20+
CAR_COSMETICS car_cosmetics[MAX_CAR_RESIDENT_MODELS];
2121

2222
#if ENABLE_GAME_FIXES
2323
// [A] storage for spooled models
@@ -50,13 +50,13 @@ void ProcessCosmeticsLump(char *lump_ptr, int lump_size)
5050
int i;
5151
int offset;
5252

53-
for (i = 0; i < MAX_CAR_MODELS; i++)
53+
for (i = 0; i < MAX_CAR_RESIDENT_MODELS; i++)
5454
{
55-
model = MissionHeader->residentModels[i];
55+
model = missionResidentCarModels[i];
5656

5757
if (model == 13)
5858
{
59-
model = 10 - (MissionHeader->residentModels[0] + MissionHeader->residentModels[1] + MissionHeader->residentModels[2]);
59+
model = 10 - (missionResidentCarModels[0] + missionResidentCarModels[1] + missionResidentCarModels[2]);
6060

6161
if (model < 1)
6262
model = 1;
@@ -79,7 +79,7 @@ void ProcessCosmeticsLump(char *lump_ptr, int lump_size)
7979

8080
// [A] cache all special vehicle cosmetics
8181
#if ENABLE_GAME_FIXES
82-
for (i = 0; i < MAX_CAR_MODELS; i++)
82+
for (i = 0; i < MAX_CAR_RESIDENT_MODELS; i++)
8383
{
8484
model = 8 + i;
8585

@@ -137,22 +137,22 @@ void AddReverseLight(CAR_DATA *cp)
137137
void SetupSpecCosmetics(char *loadbuffer)
138138
{
139139
int model;
140-
model = MissionHeader->residentModels[4];
140+
model = missionResidentCarModels[MAX_CAR_RESIDENT_MODELS - 1];
141141

142142
#if ENABLE_GAME_FIXES
143143
// [A] always use cached cosmetics
144-
car_cosmetics[4] = levelSpecCosmetics[model - 8];
144+
car_cosmetics[MAX_CAR_RESIDENT_MODELS - 1] = levelSpecCosmetics[model - 8];
145145
#else
146-
car_cosmetics[4] = *(CAR_COSMETICS*)loadbuffer;
146+
car_cosmetics[MAX_CAR_RESIDENT_MODELS - 1] = *(CAR_COSMETICS*)loadbuffer;
147147
#endif
148148

149149
#if USE_PC_FILESYSTEM
150150
if (gContentOverride)
151-
LoadCustomCarCosmetics(&car_cosmetics[4], model);
151+
LoadCustomCarCosmetics(&car_cosmetics[MAX_CAR_RESIDENT_MODELS - 1], model);
152152
#endif
153153

154154
// [A] don't forget
155-
FixCarCos(&car_cosmetics[4], model);
155+
FixCarCos(&car_cosmetics[MAX_CAR_RESIDENT_MODELS - 1], model);
156156
}
157157

158158
// [D] [T]

src_rebuild/Game/C/cosmetic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef COSMETIC_H
22
#define COSMETIC_H
33

4-
extern CAR_COSMETICS car_cosmetics[MAX_CAR_MODELS];
4+
extern CAR_COSMETICS car_cosmetics[MAX_CAR_RESIDENT_MODELS];
55
extern CAR_COSMETICS dummyCosmetics;
66

77
extern int gcar_num;

src_rebuild/Game/C/cutscene.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ int TriggerInGameCutsceneSystem(int cutscene)
609609
if (gCutsceneAtEnd != 0 && player[0].playerType == 1)
610610
{
611611
stream->SourceType.palette = car_data[player[0].playerCarId].ap.palette;
612-
stream->SourceType.model = MissionHeader->residentModels[car_data[player[0].playerCarId].ap.model];
612+
stream->SourceType.model = missionResidentCarModels[car_data[player[0].playerCarId].ap.model];
613613

614614
bDamageOverride = 1;
615615
gCutsceneAtEnd = 0;

src_rebuild/Game/C/debris.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4001,7 +4001,7 @@ int GetDebrisColour(CAR_DATA *cp)
40014001
{
40024002
int car_model;
40034003

4004-
car_model = MissionHeader->residentModels[cp->ap.model];
4004+
car_model = missionResidentCarModels[cp->ap.model];
40054005

40064006
if (car_model == 0)
40074007
return 1;

src_rebuild/Game/C/denting.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ char* DentingFiles[] =
4949
#define MAX_FILE_DAMAGE_ZONE_POLYS 70
5050
#define MAX_FILE_DAMAGE_LEVELS 256
5151

52-
u_char gCarDamageZoneVerts[MAX_CAR_MODELS][NUM_DAMAGE_ZONES][MAX_DAMAGE_ZONE_VERTS];
53-
u_char gHDCarDamageZonePolys[MAX_CAR_MODELS][NUM_DAMAGE_ZONES][MAX_DAMAGE_ZONE_POLYS];
54-
u_char gHDCarDamageLevels[MAX_CAR_MODELS][MAX_DAMAGE_LEVELS]; // the damage level (texture) count for polygons
52+
u_char gCarDamageZoneVerts[MAX_CAR_RESIDENT_MODELS][NUM_DAMAGE_ZONES][MAX_DAMAGE_ZONE_VERTS];
53+
u_char gHDCarDamageZonePolys[MAX_CAR_RESIDENT_MODELS][NUM_DAMAGE_ZONES][MAX_DAMAGE_ZONE_POLYS];
54+
u_char gHDCarDamageLevels[MAX_CAR_RESIDENT_MODELS][MAX_DAMAGE_LEVELS]; // the damage level (texture) count for polygons
5555

5656
// [D] [T]
5757
void InitialiseDenting(void)
@@ -387,7 +387,7 @@ void MoveHubcap()
387387

388388
if (gTimeOfDay == TIME_NIGHT)
389389
{
390-
cmb = (combointensity & 0xffU) / 3;
390+
cmb = (combointensity & 255) / 3;
391391
combointensity = cmb << 0x10 | cmb << 8 | cmb;
392392
}
393393

@@ -408,13 +408,13 @@ void ProcessDentLump(char *lump_ptr, int lump_size)
408408
int offset;
409409
u_char* mem;
410410

411-
for (i = 0; i < MAX_CAR_MODELS; i++)
411+
for (i = 0; i < MAX_CAR_RESIDENT_MODELS; i++)
412412
{
413-
model = MissionHeader->residentModels[i];
413+
model = missionResidentCarModels[i];
414414

415415
if (model == 13)
416416
{
417-
model = 10 - (MissionHeader->residentModels[0] + MissionHeader->residentModels[1] + MissionHeader->residentModels[2]);
417+
model = 10 - (missionResidentCarModels[0] + missionResidentCarModels[1] + missionResidentCarModels[2]);
418418

419419
if (model < 1)
420420
model = 1;
@@ -461,7 +461,7 @@ void SetupSpecDenting(char *loadbuffer)
461461
{
462462
char* newDenting;
463463
int model;
464-
model = MissionHeader->residentModels[4];
464+
model = missionResidentCarModels[MAX_CAR_RESIDENT_MODELS - 1];
465465

466466
newDenting = LoadCustomCarDentingFromFile(NULL, model);
467467
if (newDenting)
@@ -471,13 +471,13 @@ void SetupSpecDenting(char *loadbuffer)
471471
#endif
472472

473473
// [A] this is better
474-
memcpy((u_char*)gCarDamageZoneVerts[4], (u_char*)loadbuffer, NUM_DAMAGE_ZONES * MAX_FILE_DAMAGE_ZONE_VERTS);
474+
memcpy((u_char*)gCarDamageZoneVerts[MAX_CAR_RESIDENT_MODELS - 1], (u_char*)loadbuffer, NUM_DAMAGE_ZONES * MAX_FILE_DAMAGE_ZONE_VERTS);
475475
offset = NUM_DAMAGE_ZONES * MAX_FILE_DAMAGE_ZONE_VERTS;
476476

477-
memcpy((u_char*)gHDCarDamageZonePolys[4], (u_char*)loadbuffer + offset, NUM_DAMAGE_ZONES * MAX_FILE_DAMAGE_ZONE_POLYS);
477+
memcpy((u_char*)gHDCarDamageZonePolys[MAX_CAR_RESIDENT_MODELS - 1], (u_char*)loadbuffer + offset, NUM_DAMAGE_ZONES * MAX_FILE_DAMAGE_ZONE_POLYS);
478478
offset += NUM_DAMAGE_ZONES * MAX_FILE_DAMAGE_ZONE_POLYS;
479479

480-
memcpy((u_char*)gHDCarDamageLevels[4], (u_char*)loadbuffer + offset, MAX_FILE_DAMAGE_LEVELS);
480+
memcpy((u_char*)gHDCarDamageLevels[MAX_CAR_RESIDENT_MODELS - 1], (u_char*)loadbuffer + offset, MAX_FILE_DAMAGE_LEVELS);
481481
}
482482

483483
// [D] [T]

src_rebuild/Game/C/event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ void SetUpEvents(int full)
14571457
firstMissionEvent = &event[cEvents];
14581458
cEvents += 3;
14591459
}
1460-
else if (gCurrentMissionNumber - 39U < 2)
1460+
else if (gCurrentMissionNumber == 40)
14611461
{
14621462
// setup Lenny helicopter
14631463
evt[cEvents].flags = 0xC0;

0 commit comments

Comments
 (0)