Skip to content

Commit

Permalink
ChaosMod: Add second instance of Random
Browse files Browse the repository at this point in the history
Used for purposes outside of non-voting effect weighting and effect logic
  • Loading branch information
pongo1231 committed Feb 16, 2024
1 parent ad9bc47 commit 2a1a3a8
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ChaosMod/Components/DebugSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void OnExecScript(DebugSocket *debugSocket, std::shared_ptr<ix::Connectio
scriptName.resize(8);
for (int i = 0; i < 8; i++)
{
sprintf(scriptName.data() + i, "%x", g_Random.GetRandomInt(0, 16));
sprintf(scriptName.data() + i, "%x", g_RandomNoDeterm.GetRandomInt(0, 16));
}

json json;
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Components/Mp3Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void Mp3Manager::PlayChaosSoundFile(const std::string &soundFileName)
}

auto size = cachedSoundFiles.size();
auto chosenSound = size > 1 ? cachedSoundFiles[g_Random.GetRandomInt(0, size - 1)] : cachedSoundFiles[0];
auto chosenSound = size > 1 ? cachedSoundFiles[g_RandomNoDeterm.GetRandomInt(0, size - 1)] : cachedSoundFiles[0];

int error;
{
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Components/Voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void Voting::OnRun()
totalWeight += effectData.GetEffectWeight();
}

float chosen = g_Random.GetRandomFloat(0.f, totalWeight);
float chosen = g_RandomNoDeterm.GetRandomFloat(0.f, totalWeight);

totalWeight = 0.f;

Expand Down
1 change: 1 addition & 0 deletions ChaosMod/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ static void Init()
g_OptionsManager.GetConfigValue<std::string>({ "EffectTimedTimerColor" }, OPTION_DEFAULT_TIMED_COLOR));

g_Random.SetSeed(g_OptionsManager.GetConfigValue({ "Seed" }, 0));
g_RandomNoDeterm.SetSeed(GetTickCount64());

std::set<std::string> blacklistedComponentNames;
if (DoesFeatureFlagExist("blacklistedcomponents"))
Expand Down
16 changes: 8 additions & 8 deletions ChaosMod/Util/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ struct Color
inline Color GetRandomColorRGB(std::uint8_t min = 0, std::uint8_t max = 255)
{
return {
(std::uint8_t)g_Random.GetRandomInt(min, max), // R
(std::uint8_t)g_Random.GetRandomInt(min, max), // G
(std::uint8_t)g_Random.GetRandomInt(min, max), // B
255 // A
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // R
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // G
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // B
255 // A
};
}

// Returns a random RGBA value with a random alpha.
inline Color GetRandomColorRGBA(std::uint8_t min = 0, std::uint8_t max = 255)
{
return {
(std::uint8_t)g_Random.GetRandomInt(min, max), // R
(std::uint8_t)g_Random.GetRandomInt(min, max), // G
(std::uint8_t)g_Random.GetRandomInt(min, max), // B
(std::uint8_t)g_Random.GetRandomInt(min, max) // A
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // R
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // G
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max), // B
(std::uint8_t)g_RandomNoDeterm.GetRandomInt(min, max) // A
};
}
14 changes: 7 additions & 7 deletions ChaosMod/Util/PoolSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Ped CreateRandomPoolPed(float x, float y, float z, float heading)
Ped ped;
if (!pedModels.empty())
{
Hash model = pedModels[g_Random.GetRandomInt(0, pedModels.size() - 1)];
Hash model = pedModels[g_RandomNoDeterm.GetRandomInt(0, pedModels.size() - 1)];

ped = CreatePoolPed(4, model, x, y, z, heading);
}
Expand All @@ -154,20 +154,20 @@ Ped CreateRandomPoolPed(float x, float y, float z, float heading)
for (int i = 0; i < 12; i++)
{
int drawableAmount = GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(ped, i);
int drawable = drawableAmount == 0 ? 0 : g_Random.GetRandomInt(0, drawableAmount - 1);
int drawable = drawableAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, drawableAmount - 1);

int textureAmount = GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(ped, i, drawable);
int texture = textureAmount == 0 ? 0 : g_Random.GetRandomInt(0, textureAmount - 1);
int texture = textureAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, textureAmount - 1);

SET_PED_COMPONENT_VARIATION(ped, i, drawable, texture, g_Random.GetRandomInt(0, 3));
SET_PED_COMPONENT_VARIATION(ped, i, drawable, texture, g_RandomNoDeterm.GetRandomInt(0, 3));

if (i < 4)
{
int propDrawableAmount = GET_NUMBER_OF_PED_PROP_DRAWABLE_VARIATIONS(ped, i);
int propDrawable = propDrawableAmount == 0 ? 0 : g_Random.GetRandomInt(0, propDrawableAmount - 1);
int propDrawable = propDrawableAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, propDrawableAmount - 1);

int propTextureAmount = GET_NUMBER_OF_PED_PROP_TEXTURE_VARIATIONS(ped, i, drawable);
int propTexture = propTextureAmount == 0 ? 0 : g_Random.GetRandomInt(0, propTextureAmount - 1);
int propTextureAmount = GET_NUMBER_OF_PED_PROP_TEXTURE_VARIATIONS(ped, i, drawable);
int propTexture = propTextureAmount == 0 ? 0 : g_RandomNoDeterm.GetRandomInt(0, propTextureAmount - 1);

SET_PED_PROP_INDEX(ped, i, propDrawable, propTexture, true);
}
Expand Down
1 change: 1 addition & 0 deletions ChaosMod/Util/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ class Random
};

inline Random g_Random;
inline Random g_RandomNoDeterm;
27 changes: 14 additions & 13 deletions ChaosMod/Util/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ inline Vehicle CreateRandomVehicleWithPeds(Vehicle oldHandle, const std::vector<
Hash newVehModel = 0;
do
{
newVehModel = vehicleModels[g_Random.GetRandomInt(0, vehicleModels.size() - 1)];
newVehModel = vehicleModels[g_RandomNoDeterm.GetRandomInt(0, vehicleModels.size() - 1)];
} while (GET_VEHICLE_MODEL_NUMBER_OF_SEATS(newVehModel) < seatPeds.size() || IS_THIS_MODEL_A_TRAIN(newVehModel)
|| GET_VEHICLE_MODEL_ACCELERATION(newVehModel) <= 0);

Expand Down Expand Up @@ -170,35 +170,36 @@ inline Vehicle CreateRandomVehicleWithPeds(Vehicle oldHandle, const std::vector<
// Also apply random upgrades
SET_VEHICLE_MOD_KIT(newVehicle, 0);

SET_VEHICLE_WHEEL_TYPE(newVehicle, g_Random.GetRandomInt(0, 12));
SET_VEHICLE_WHEEL_TYPE(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 12));

for (int i = 0; i < 50; i++)
{
int max = GET_NUM_VEHICLE_MODS(newVehicle, i);
if (max > 0)
{
SET_VEHICLE_MOD(newVehicle, i, g_Random.GetRandomInt(0, max - 1), g_Random.GetRandomInt(0, 1));
SET_VEHICLE_MOD(newVehicle, i, g_RandomNoDeterm.GetRandomInt(0, max - 1),
g_RandomNoDeterm.GetRandomInt(0, 1));
}

TOGGLE_VEHICLE_MOD(newVehicle, i, g_Random.GetRandomInt(0, 1));
TOGGLE_VEHICLE_MOD(newVehicle, i, g_RandomNoDeterm.GetRandomInt(0, 1));
}

SET_VEHICLE_TYRES_CAN_BURST(newVehicle, g_Random.GetRandomInt(0, 1));
SET_VEHICLE_WINDOW_TINT(newVehicle, g_Random.GetRandomInt(0, 6));
SET_VEHICLE_TYRES_CAN_BURST(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 1));
SET_VEHICLE_WINDOW_TINT(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 6));

SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(newVehicle, g_Random.GetRandomInt(0, 255), g_Random.GetRandomInt(0, 255),
g_Random.GetRandomInt(0, 255));
SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(newVehicle, g_Random.GetRandomInt(0, 255), g_Random.GetRandomInt(0, 255),
g_Random.GetRandomInt(0, 255));
SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 255),
g_RandomNoDeterm.GetRandomInt(0, 255), g_RandomNoDeterm.GetRandomInt(0, 255));
SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 255),
g_RandomNoDeterm.GetRandomInt(0, 255), g_RandomNoDeterm.GetRandomInt(0, 255));

_SET_VEHICLE_NEON_LIGHTS_COLOUR(newVehicle, g_Random.GetRandomInt(0, 255), g_Random.GetRandomInt(0, 255),
g_Random.GetRandomInt(0, 255));
_SET_VEHICLE_NEON_LIGHTS_COLOUR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 255),
g_RandomNoDeterm.GetRandomInt(0, 255), g_RandomNoDeterm.GetRandomInt(0, 255));
for (int i = 0; i < 4; i++)
{
_SET_VEHICLE_NEON_LIGHT_ENABLED(newVehicle, i, true);
}

_SET_VEHICLE_XENON_LIGHTS_COLOR(newVehicle, g_Random.GetRandomInt(0, 12));
_SET_VEHICLE_XENON_LIGHTS_COLOR(newVehicle, g_RandomNoDeterm.GetRandomInt(0, 12));

return newVehicle;
}
Expand Down

0 comments on commit 2a1a3a8

Please sign in to comment.