Skip to content

Commit f614670

Browse files
committed
Fixed bugs, added features (27 DEC 21)
Fixed behaviour when cop cars are added as variations Fixed news chopper appearing at wanted level 3 Added ini option ChangeCarGenerators Added ini option LoadAllVehicles
1 parent c4e2cd3 commit f614670

4 files changed

Lines changed: 67 additions & 5 deletions

File tree

ModelVariations/ModelVariations.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ std::map<short, std::vector<short>> vehPassengers;
6161
std::array<std::vector<short>, 16> vehWantedVariations[212];
6262

6363
std::vector<short> vehCurrentVariations[212];
64+
std::vector<short> vehCarGenExclude;
6465

6566
std::map<short, BYTE> pedWepVariationTypes;
6667

@@ -69,9 +70,34 @@ std::stack<CPed*> pedStack;
6970
BYTE dealersFixed = 0;
7071
short modelIndex = -1;
7172

73+
int changeCarGenerators = 0;
7274
bool isPlayerInTaxi = false;
7375
bool enableSideMissions = false;
7476
int enableVehicles = 0;
77+
int loadAllVehicles = 0;
78+
79+
bool isGameModelPolice(int model)
80+
{
81+
switch (model)
82+
{
83+
case 427: //Enforcer
84+
case 430: //Predator
85+
case 432: //Rhino
86+
case 433: //Barracks
87+
case 470: //Patriot
88+
case 490: //FBI Rancher
89+
case 496: //Police Maverick
90+
case 523: //HPV1000
91+
case 528: //FBI Truck
92+
case 596: //Police LS
93+
case 597: //Police SF
94+
case 598: //Police LV
95+
case 599: //Police Ranger
96+
case 601: //S.W.A.T.
97+
return true;
98+
}
99+
return false;
100+
}
75101

76102
void vectorUnion(std::vector<short> &vec1, std::vector<short> &vec2, std::vector<short> &dest)
77103
{
@@ -158,10 +184,14 @@ std::vector<short> iniLineParser(eVariationType type, int section, const char ke
158184
if (ini == NULL)
159185
return retVector;
160186

161-
std::string sectionString = std::to_string(section);
187+
std::string sectionString;
188+
if (type == MODEL_SETTINGS)
189+
sectionString = (char*)section;
190+
else
191+
sectionString = std::to_string(section);
162192

163193
std::string keyString;
164-
if (type == PED_VARIATION || type == VEHICLE_VARIATION)
194+
if (type == PED_VARIATION || type == VEHICLE_VARIATION || type == MODEL_SETTINGS)
165195
keyString = key;
166196
else
167197
keyString = std::to_string((int)(key));
@@ -309,7 +339,7 @@ class ModelVariations {
309339

310340
if (!vec.empty()) //if veh id 'j+400' has variations in zone 'i'
311341
for (auto& k : vec) //for every variation 'k' of veh id 'j+400' in zone 'i'
312-
if (j + 400 != k)
342+
if (j + 400 != k && !(isGameModelPolice(j+400) && isGameModelPolice(k)))
313343
vehOriginalModels.insert({k, j+400});
314344
}
315345
}
@@ -417,6 +447,10 @@ class ModelVariations {
417447

418448
Events::initScriptsEvent += []
419449
{
450+
if (loadAllVehicles)
451+
for (int i = 400; i < 612; i++)
452+
CStreaming::RequestModel(i, KEEP_IN_MEMORY);
453+
420454
dealersFixed = 0;
421455
};
422456

ModelVariations/Vehicles.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ void readVehicleIni()
204204

205205
for (int j = 0; j < 16; j++)
206206
for (int k = 0; k < (int)(vehVariations[i-400][j].size()); k++)
207-
if (vehVariations[i-400][j][k] > 0 && vehVariations[i-400][j][k] < 30000 && vehVariations[i-400][j][k] != i)
207+
if (vehVariations[i-400][j][k] > 0 && vehVariations[i-400][j][k] < 30000 && vehVariations[i-400][j][k] != i &&
208+
!(isGameModelPolice(i) && isGameModelPolice(vehVariations[i - 400][j][k])))
208209
vehOriginalModels.insert({ vehVariations[i - 400][j][k], i });
209210
}
210211

@@ -218,6 +219,10 @@ void readVehicleIni()
218219
if (!vec.empty())
219220
vehPassengers.insert({ i, vec });
220221
}
222+
223+
changeCarGenerators = iniVeh.ReadInteger("Settings", "ChangeCarGenerators", 0);
224+
vehCarGenExclude = iniLineParser(MODEL_SETTINGS, (int)"Settings", "ExcludeCarGeneratorVehicles", &iniVeh);
225+
loadAllVehicles = iniVeh.ReadInteger("Settings", "LoadAllVehicles", 0);
221226
}
222227

223228
///////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -303,6 +308,21 @@ void __fastcall DoInternalProcessingHooked(CCarGenerator* park) //for non-random
303308
if (park != NULL)
304309
{
305310
int model = park->m_nModelId;
311+
if (changeCarGenerators == 1)
312+
{
313+
if (!vehCarGenExclude.empty())
314+
if (std::find(vehCarGenExclude.begin(), vehCarGenExclude.end(), model) != vehCarGenExclude.end())
315+
{
316+
park->DoInternalProcessing();
317+
return;
318+
}
319+
320+
park->m_nModelId = getRandomVariation(park->m_nModelId);
321+
park->DoInternalProcessing();
322+
park->m_nModelId = model;
323+
return;
324+
}
325+
306326
switch (park->m_nModelId)
307327
{
308328
case 416: //Ambulance
@@ -528,6 +548,9 @@ void __cdecl SetUpDriverAndPassengersForVehicleHooked(CVehicle* car, int a3, int
528548

529549
CHeli* __cdecl GenerateHeliHooked(CPed* ped, char newsHeli)
530550
{
551+
if (FindPlayerWanted(-1)->m_nWantedLevel < 4)
552+
return CHeli::GenerateHeli(ped, 0);
553+
531554
if (CHeli::pHelis)
532555
{
533556
CStreaming::RequestModel(488, 2);

ModelVariations/Vehicles.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ extern std::map<short, std::vector<short>> vehPassengers;
1717

1818
extern std::vector<short> vehCurrentVariations[212];
1919
extern std::map<short, short> vehOriginalModels;
20+
extern std::vector<short> vehCarGenExclude;
21+
extern int loadAllVehicles;
2022

23+
extern int changeCarGenerators;
2124
extern bool isPlayerInTaxi;
2225
extern bool enableSideMissions;
2326

2427
extern std::vector<short> iniLineParser(eVariationType type, int section, const char key[12], CIniReader* ini);
2528
extern void vectorUnion(std::vector<short>& vec1, std::vector<short>& vec2, std::vector<short>& dest);
29+
extern bool isGameModelPolice(int model);
2630

2731
void installVehicleHooks();
2832
void readVehicleIni();

ModelVariations/commonDef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ enum eVariationType
1414
{
1515
PED_VARIATION,
1616
VEHICLE_VARIATION,
17-
PED_WEAPON_VARIATION
17+
PED_WEAPON_VARIATION,
18+
MODEL_SETTINGS
1819
};

0 commit comments

Comments
 (0)