Use SDL_rand/SDL_randf (#203)

This commit is contained in:
Anonymous Maarten 2025-05-30 21:01:01 +02:00 committed by GitHub
parent 341d06f997
commit 364844d6d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 67 additions and 68 deletions

View File

@ -453,7 +453,7 @@ MxS32 Act2Actor::VTable0xa0()
assert(!m_grec); assert(!m_grec);
CurrentWorld(); CurrentWorld();
MxU16 randomVal = rand() / (RAND_MAX / 2) + 1; MxU16 randomVal = 1 + SDL_rand(2);
if (m_unk0x48 == 8 && m_unk0x1d != 8) { if (m_unk0x48 == 8 && m_unk0x1d != 8) {
newLocation = 8; newLocation = 8;

View File

@ -413,7 +413,7 @@ MxResult Act3Cop::FUN_10040360()
} }
if (grec == NULL) { if (grec == NULL) {
MxS32 random = rand() % (MxS32) sizeOfArray(g_copDest); MxS32 random = SDL_rand(sizeOfArray(g_copDest));
Vector3 localf8(g_copDest[random].m_unk0x08); Vector3 localf8(g_copDest[random].m_unk0x08);
Vector3 local108(g_copDest[random].m_unk0x14); Vector3 local108(g_copDest[random].m_unk0x14);

View File

@ -477,7 +477,7 @@ void Ambulance::ActivateSceneActions()
else if (m_unk0x16c != 0 && m_unk0x16e != 0) { else if (m_unk0x16c != 0 && m_unk0x16e != 0) {
IsleScript::Script objectId; IsleScript::Script objectId;
switch (rand() % 2) { switch (SDL_rand(2)) {
case 0: case 0:
objectId = IsleScript::c_ham076cl_PlayWav; objectId = IsleScript::c_ham076cl_PlayWav;
break; break;
@ -495,7 +495,7 @@ void Ambulance::ActivateSceneActions()
else { else {
IsleScript::Script objectId; IsleScript::Script objectId;
switch (rand() % 2) { switch (SDL_rand(2)) {
case 0: case 0:
objectId = IsleScript::c_ham075cl_PlayWav; objectId = IsleScript::c_ham075cl_PlayWav;
break; break;
@ -522,7 +522,7 @@ MxResult Ambulance::Tickle()
else if (m_lastAction == IsleScript::c_noneIsle) { else if (m_lastAction == IsleScript::c_noneIsle) {
IsleScript::Script objectId; IsleScript::Script objectId;
switch ((rand() % 12) + 1) { switch (1 + SDL_rand(12)) {
case 1: case 1:
objectId = IsleScript::c_ham034ra_PlayWav; objectId = IsleScript::c_ham034ra_PlayWav;
break; break;

View File

@ -215,17 +215,16 @@ RadioState::RadioState()
{ {
srand(Timer()->GetTime()); srand(Timer()->GetTime());
MxS32 random = rand(); m_unk0x2c = SDL_rand(3);
m_unk0x2c = random % 3;
m_unk0x08[0] = Playlist((MxU32*) g_unk0x100f3218, sizeOfArray(g_unk0x100f3218), Playlist::e_loop); m_unk0x08[0] = Playlist((MxU32*) g_unk0x100f3218, sizeOfArray(g_unk0x100f3218), Playlist::e_loop);
m_unk0x08[0].m_nextIndex = (rand() % sizeOfArray(g_unk0x100f3218)); m_unk0x08[0].m_nextIndex = SDL_rand(sizeOfArray(g_unk0x100f3218));
m_unk0x08[1] = Playlist((MxU32*) g_unk0x100f3230, sizeOfArray(g_unk0x100f3230), Playlist::e_loop); m_unk0x08[1] = Playlist((MxU32*) g_unk0x100f3230, sizeOfArray(g_unk0x100f3230), Playlist::e_loop);
m_unk0x08[1].m_nextIndex = (rand() % sizeOfArray(g_unk0x100f3230)); m_unk0x08[1].m_nextIndex = SDL_rand(sizeOfArray(g_unk0x100f3230));
m_unk0x08[2] = Playlist((MxU32*) g_unk0x100f3268, sizeOfArray(g_unk0x100f3268), Playlist::e_loop); m_unk0x08[2] = Playlist((MxU32*) g_unk0x100f3268, sizeOfArray(g_unk0x100f3268), Playlist::e_loop);
m_unk0x08[2].m_nextIndex = (rand() % sizeOfArray(g_unk0x100f3268)); m_unk0x08[2].m_nextIndex = SDL_rand(sizeOfArray(g_unk0x100f3268));
m_active = FALSE; m_active = FALSE;
} }

View File

@ -174,7 +174,7 @@ MxLong TowTrack::HandleEndAction(MxEndActionNotificationParam& p_param)
m_actorId = LegoActor::c_laura; m_actorId = LegoActor::c_laura;
} }
switch ((rand() % ((m_actorId != 4 ? 4 : 3))) + 1) { switch (1 + SDL_rand(m_actorId != 4 ? 4 : 3)) {
case 1: case 1:
PlayFinalAnimation(IsleScript::c_wrt074sl_RunAnim); PlayFinalAnimation(IsleScript::c_wrt074sl_RunAnim);
break; break;
@ -353,7 +353,7 @@ MxLong TowTrack::HandlePathStruct(LegoPathStructNotificationParam& p_param)
objectId = IsleScript::c_wns034na_PlayWav; objectId = IsleScript::c_wns034na_PlayWav;
break; break;
case c_mama: case c_mama:
switch ((rand() % 2) + 1) { switch (1 + SDL_rand(2)) {
case 1: case 1:
objectId = IsleScript::c_wns037na_PlayWav; objectId = IsleScript::c_wns037na_PlayWav;
break; break;
@ -363,7 +363,7 @@ MxLong TowTrack::HandlePathStruct(LegoPathStructNotificationParam& p_param)
} }
break; break;
case c_papa: case c_papa:
switch ((rand() % 2) + 1) { switch (1 + SDL_rand(2)) {
case 1: case 1:
objectId = IsleScript::c_wns041na_PlayWav; objectId = IsleScript::c_wns041na_PlayWav;
break; break;
@ -373,7 +373,7 @@ MxLong TowTrack::HandlePathStruct(LegoPathStructNotificationParam& p_param)
} }
break; break;
case c_nick: case c_nick:
switch ((rand() % 2) + 1) { switch (1 + SDL_rand(2)) {
case 1: case 1:
objectId = IsleScript::c_wns039na_PlayWav; objectId = IsleScript::c_wns039na_PlayWav;
break; break;
@ -383,7 +383,7 @@ MxLong TowTrack::HandlePathStruct(LegoPathStructNotificationParam& p_param)
} }
break; break;
case c_laura: case c_laura:
switch ((rand() % 2) + 1) { switch (1 + SDL_rand(2)) {
case 1: case 1:
objectId = IsleScript::c_wns043na_PlayWav; objectId = IsleScript::c_wns043na_PlayWav;
break; break;

View File

@ -1502,7 +1502,7 @@ void LegoCarBuild::FUN_10025720(undefined4 p_param)
case 1: case 1:
case 2: case 2:
case 3: case 3:
switch (rand() % 3) { switch (SDL_rand(3)) {
case 0: case 0:
m_unk0x10a = CopterScript::c_ips004d2_RunAnim; m_unk0x10a = CopterScript::c_ips004d2_RunAnim;
StopActionIn0x344(); StopActionIn0x344();

View File

@ -28,8 +28,7 @@
#include "realtime/realtime.h" #include "realtime/realtime.h"
#include "viewmanager/viewmanager.h" #include "viewmanager/viewmanager.h"
#include <SDL3/SDL_filesystem.h> #include <SDL3/SDL.h>
#include <SDL3/SDL_stdinc.h>
#include <stdio.h> #include <stdio.h>
#include <vec.h> #include <vec.h>
@ -1201,7 +1200,7 @@ void LegoAnimationManager::CameraTriggerFire(LegoPathActor* p_actor, MxBool, MxU
return; return;
} }
if (location->m_unk0x5c && location->m_frequency < rand() % 100) { if (location->m_unk0x5c && location->m_frequency < SDL_rand(100)) {
return; return;
} }
} }
@ -1562,7 +1561,7 @@ MxResult LegoAnimationManager::Tickle()
return SUCCESS; return SUCCESS;
} }
m_unk0x410 = (rand() * 10000 / RAND_MAX) + 5000; m_unk0x410 = SDL_rand(10000) + 5000;
m_unk0x408 = time; m_unk0x408 = time;
if (time - m_unk0x404 > 10000) { if (time - m_unk0x404 > 10000) {
@ -1900,7 +1899,7 @@ void LegoAnimationManager::AddExtra(MxS32 p_location, MxBool p_und)
} }
if (i != m_numAllowedExtras) { if (i != m_numAllowedExtras) {
MxU8 und = rand() % 2 != 0 ? 1 : 2; MxU8 und = SDL_rand(2) != 0 ? 1 : 2;
MxBool bool1, bool2; MxBool bool1, bool2;
switch (g_unk0x100f7504 % 4) { switch (g_unk0x100f7504 % 4) {
@ -1957,7 +1956,7 @@ void LegoAnimationManager::AddExtra(MxS32 p_location, MxBool p_und)
active = TRUE; active = TRUE;
} }
else { else {
active = rand() % 100 < 50; active = SDL_rand(100) < 50;
} }
tryNextCharacter: tryNextCharacter:
@ -2002,7 +2001,7 @@ void LegoAnimationManager::AddExtra(MxS32 p_location, MxBool p_und)
MxS32 vehicleId = g_characters[m_lastExtraCharacterId].m_vehicleId; MxS32 vehicleId = g_characters[m_lastExtraCharacterId].m_vehicleId;
if (vehicleId >= 0) { if (vehicleId >= 0) {
g_vehicles[vehicleId].m_unk0x04 = g_vehicles[vehicleId].m_unk0x04 =
rand() % 100 < g_characters[m_lastExtraCharacterId].m_unk0x15; SDL_rand(100) < g_characters[m_lastExtraCharacterId].m_unk0x15;
} }
if (FUN_10063b90( if (FUN_10063b90(
@ -2020,10 +2019,10 @@ void LegoAnimationManager::AddExtra(MxS32 p_location, MxBool p_und)
float speed; float speed;
if (m_extras[i].m_unk0x14) { if (m_extras[i].m_unk0x14) {
speed = ((float) (rand() * 1.5) / RAND_MAX) + 0.9; speed = 0.9f + 1.5f * SDL_randf();
} }
else { else {
speed = ((float) (rand() * 1.4) / RAND_MAX) + 0.6; speed = 0.6f + 1.4f * SDL_randf();
} }
actor->SetWorldSpeed(speed); actor->SetWorldSpeed(speed);
@ -2159,7 +2158,7 @@ MxBool LegoAnimationManager::FUN_10062e20(LegoROI* p_roi, LegoAnimPresenter* p_p
if (!local24) { if (!local24) {
MxU8 unk0x0c; MxU8 unk0x0c;
switch (rand() % 3) { switch (SDL_rand(3)) {
case 0: case 0:
unk0x0c = 1; unk0x0c = 1;
break; break;
@ -2426,10 +2425,10 @@ void LegoAnimationManager::FUN_10063d10()
if (speed < 0.0f) { if (speed < 0.0f) {
if (m_extras[i].m_unk0x14) { if (m_extras[i].m_unk0x14) {
speed = ((float) (rand() * 1.5) / RAND_MAX) + 0.9; speed = 0.9f + 1.5f * SDL_randf();
} }
else { else {
speed = ((float) (rand() * 1.4) / RAND_MAX) + 0.6; speed = 0.6f + 1.4f * SDL_randf();
} }
} }
@ -2513,7 +2512,7 @@ MxBool LegoAnimationManager::FUN_10064010(LegoPathBoundary* p_boundary, LegoOrie
MxBool LegoAnimationManager::FUN_10064120(LegoLocation::Boundary* p_boundary, MxBool p_bool1, MxBool p_bool2) MxBool LegoAnimationManager::FUN_10064120(LegoLocation::Boundary* p_boundary, MxBool p_bool1, MxBool p_bool2)
{ {
MxU32 local2c = 12; MxU32 local2c = 12;
float destScale = ((rand() * 0.5) / RAND_MAX) + 0.25; float destScale = 0.25f + 0.5f * SDL_randf();
LegoPathActor* actor = UserActor(); LegoPathActor* actor = UserActor();
if (actor == NULL) { if (actor == NULL) {
@ -2668,7 +2667,7 @@ MxResult LegoAnimationManager::FUN_10064380(
} }
if (actor != NULL) { if (actor != NULL) {
MxU8 unk0x0c = rand() % 2 != 0 ? 1 : 2; MxU8 unk0x0c = SDL_rand(2) != 0 ? 1 : 2;
actor->SetUnknown0x0c(unk0x0c); actor->SetUnknown0x0c(unk0x0c);
actor->SetWorldSpeed(0.0f); actor->SetWorldSpeed(0.0f);
@ -2724,7 +2723,7 @@ MxResult LegoAnimationManager::FUN_10064670(Vector3* p_position)
} }
if (success) { if (success) {
return FUN_10064380("brickstr", "EDG02_95", 1, 0.5f, 3, 0.5f, rand() % 3 + 14, -1, rand() % 3, -1, 0.5f); return FUN_10064380("brickstr", "EDG02_95", 1, 0.5f, 3, 0.5f, SDL_rand(3) + 14, -1, SDL_rand(3), -1, 0.5f);
} }
return FAILURE; return FAILURE;
@ -2749,11 +2748,11 @@ MxResult LegoAnimationManager::FUN_10064740(Vector3* p_position)
if (success) { if (success) {
if (GameState()->GetActorId() != LegoActor::c_mama) { if (GameState()->GetActorId() != LegoActor::c_mama) {
FUN_10064380("mama", "USR00_47", 1, 0.43f, 3, 0.84f, rand() % 3 + 13, -1, rand() % 3, -1, 0.7f); FUN_10064380("mama", "USR00_47", 1, 0.43f, 3, 0.84f, SDL_rand(3) + 13, -1, SDL_rand(3), -1, 0.7f);
} }
if (GameState()->GetActorId() != LegoActor::c_papa) { if (GameState()->GetActorId() != LegoActor::c_papa) {
FUN_10064380("papa", "USR00_193", 3, 0.55f, 1, 0.4f, rand() % 3 + 13, -1, rand() % 3, -1, 0.9f); FUN_10064380("papa", "USR00_193", 3, 0.55f, 1, 0.4f, SDL_rand(3) + 13, -1, SDL_rand(3), -1, 0.9f);
} }
return SUCCESS; return SUCCESS;

View File

@ -30,7 +30,7 @@ MxU32 LegoState::Playlist::Next()
break; break;
case e_random: case e_random:
m_nextIndex = rand() % m_length; m_nextIndex = SDL_rand(m_length);
objectId = m_objectIds[m_nextIndex]; objectId = m_objectIds[m_nextIndex];
break; break;

View File

@ -191,7 +191,7 @@ void MxTransitionManager::DissolveTransition()
// ...then shuffle the list (to ensure that we hit each column once) // ...then shuffle the list (to ensure that we hit each column once)
for (i = 0; i < 640; i++) { for (i = 0; i < 640; i++) {
MxS32 swap = rand() % 640; MxS32 swap = SDL_rand(640);
MxU16 t = m_columnOrder[i]; MxU16 t = m_columnOrder[i];
m_columnOrder[i] = m_columnOrder[swap]; m_columnOrder[i] = m_columnOrder[swap];
m_columnOrder[swap] = t; m_columnOrder[swap] = t;
@ -199,7 +199,7 @@ void MxTransitionManager::DissolveTransition()
// For each scanline, pick a random X offset // For each scanline, pick a random X offset
for (i = 0; i < 480; i++) { for (i = 0; i < 480; i++) {
m_randomShift[i] = rand() % 640; m_randomShift[i] = SDL_rand(640);
} }
} }
@ -276,7 +276,7 @@ void MxTransitionManager::MosaicTransition()
} }
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
MxS32 swap = rand() % 64; MxS32 swap = SDL_rand(64);
MxU16 t = m_columnOrder[i]; MxU16 t = m_columnOrder[i];
m_columnOrder[i] = m_columnOrder[swap]; m_columnOrder[i] = m_columnOrder[swap];
m_columnOrder[swap] = t; m_columnOrder[swap] = t;
@ -284,7 +284,7 @@ void MxTransitionManager::MosaicTransition()
// The same is true here. We only need 48 rows. // The same is true here. We only need 48 rows.
for (i = 0; i < 48; i++) { for (i = 0; i < 48; i++) {
m_randomShift[i] = rand() % 64; m_randomShift[i] = SDL_rand(64);
} }
} }

View File

@ -122,7 +122,7 @@ void LegoExtraActor::VTable0xa4(MxBool& p_und1, MxS32& p_und2)
break; break;
default: default:
p_und1 = TRUE; p_und1 = TRUE;
p_und2 = rand() % p_und2 + 1; p_und2 = 1 + SDL_rand(p_und2);
break; break;
} }
} }

View File

@ -16,6 +16,7 @@
#include "mxutilities.h" #include "mxutilities.h"
#include "mxvariabletable.h" #include "mxvariabletable.h"
#include <SDL3/SDL.h>
#include <mxdebug.h> #include <mxdebug.h>
#include <vec.h> #include <vec.h>
@ -723,7 +724,7 @@ void LegoPathActor::VTable0xa4(MxBool& p_und1, MxS32& p_und2)
case c_nick: case c_nick:
case c_brickster: case c_brickster:
p_und1 = TRUE; p_und1 = TRUE;
p_und2 = rand() % p_und2 + 1; p_und2 = SDL_rand(p_und2) + 1;
break; break;
case c_laura: case c_laura:
p_und1 = FALSE; p_und1 = FALSE;

View File

@ -128,7 +128,7 @@ void CarRace::ReadyWorld()
AnimationManager()->Resume(); AnimationManager()->Resume();
FUN_10015820(FALSE, LegoOmni::c_disableInput | LegoOmni::c_disable3d | LegoOmni::c_clearScreen); FUN_10015820(FALSE, LegoOmni::c_disableInput | LegoOmni::c_disable3d | LegoOmni::c_clearScreen);
m_unk0x144 = g_unk0x100d5d10[rand() & 7]; m_unk0x144 = g_unk0x100d5d10[SDL_rand(8)];
AnimationManager() AnimationManager()
->FUN_10060dc0(m_unk0x144, NULL, TRUE, LegoAnimationManager::e_unk0, NULL, FALSE, TRUE, FALSE, TRUE); ->FUN_10060dc0(m_unk0x144, NULL, TRUE, LegoAnimationManager::e_unk0, NULL, FALSE, TRUE, FALSE, TRUE);
@ -221,24 +221,24 @@ MxLong CarRace::HandlePathStruct(LegoPathStructNotificationParam& p_param)
if (m_unk0xfc < m_unk0xf8 && m_unk0x100 < m_unk0xf8) { if (m_unk0xfc < m_unk0xf8 && m_unk0x100 < m_unk0xf8) {
position = 3; position = 3;
m_unk0x148 = g_unk0x100d5d40[rand() % 3]; m_unk0x148 = g_unk0x100d5d40[SDL_rand(3)];
m_unk0x14c = g_unk0x100d5d60[rand() % 3]; m_unk0x14c = g_unk0x100d5d60[SDL_rand(3)];
} }
else if (m_unk0xfc < m_unk0xf8 || m_unk0x100 < m_unk0xf8) { else if (m_unk0xfc < m_unk0xf8 || m_unk0x100 < m_unk0xf8) {
position = 2; position = 2;
if (m_unk0xfc == g_unk0x100f0c7c) { if (m_unk0xfc == g_unk0x100f0c7c) {
m_unk0x148 = g_unk0x100d5d30[rand() % 4]; m_unk0x148 = g_unk0x100d5d30[SDL_rand(4)];
m_unk0x14c = g_unk0x100d5d60[rand() % 3]; m_unk0x14c = g_unk0x100d5d60[SDL_rand(3)];
} }
else { else {
m_unk0x148 = g_unk0x100d5d50[rand() % 3]; m_unk0x148 = g_unk0x100d5d50[SDL_rand(3)];
m_unk0x14c = g_unk0x100d5d40[rand() % 3]; m_unk0x14c = g_unk0x100d5d40[SDL_rand(3)];
} }
} }
else { else {
position = 1; position = 1;
m_unk0x148 = g_unk0x100d5d30[rand() % 4]; m_unk0x148 = g_unk0x100d5d30[SDL_rand(4)];
m_unk0x14c = g_unk0x100d5d50[rand() % 3]; m_unk0x14c = g_unk0x100d5d50[SDL_rand(3)];
} }
InputManager()->DisableInputProcessing(); InputManager()->DisableInputProcessing();

View File

@ -218,10 +218,10 @@ void LegoRaceCar::InitSoundIndices()
{ {
// Note the (likely unintentional) order of operations: `%` is executed before `/`, // Note the (likely unintentional) order of operations: `%` is executed before `/`,
// so the division is performed at runtime. // so the division is performed at runtime.
g_playerHitStudsSoundsIndex = rand() % sizeof(g_playerHitStudsSounds) / sizeof(g_playerHitStudsSounds[0]); g_playerHitStudsSoundsIndex = SDL_rand(sizeOfArray(g_playerHitStudsSounds));
g_studsHitPlayerSoundsIndex = rand() % sizeof(g_studsHitPlayerSounds) / sizeof(g_studsHitPlayerSounds[0]); g_studsHitPlayerSoundsIndex = SDL_rand(sizeOfArray(g_studsHitPlayerSounds));
g_playerHitRhodaSoundsIndex = rand() % sizeof(g_playerHitRhodaSounds) / sizeof(g_playerHitRhodaSounds[0]); g_playerHitRhodaSoundsIndex = SDL_rand(sizeOfArray(g_playerHitRhodaSounds));
g_rhodaHitPlayerSoundsIndex = rand() % sizeof(g_rhodaHitPlayerSounds) / sizeof(g_rhodaHitPlayerSounds[0]); g_rhodaHitPlayerSoundsIndex = SDL_rand(sizeOfArray(g_rhodaHitPlayerSounds));
} }
// FUNCTION: LEGO1 0x10012e60 // FUNCTION: LEGO1 0x10012e60
@ -573,8 +573,8 @@ MxResult LegoRaceCar::VTable0x9c()
void LegoJetski::InitSoundIndices() void LegoJetski::InitSoundIndices()
{ {
// See note in LegoRaceCar::InitSoundIndices // See note in LegoRaceCar::InitSoundIndices
g_hitSnapSoundsIndex = rand() % sizeof(g_hitSnapSounds) / sizeof(g_hitSnapSounds[0]); g_hitSnapSoundsIndex = SDL_rand(sizeOfArray(g_hitSnapSounds));
g_hitValerieSoundsIndex = rand() % sizeof(g_hitValerieSounds) / sizeof(g_hitValerieSounds[0]); g_hitValerieSoundsIndex = SDL_rand(sizeOfArray(g_hitValerieSounds));
} }
// FUNCTION: LEGO1 0x100136a0 // FUNCTION: LEGO1 0x100136a0

View File

@ -670,7 +670,7 @@ void Act3::ReadyWorld()
AnimationManager()->FUN_1005f6d0(FALSE); AnimationManager()->FUN_1005f6d0(FALSE);
VideoManager()->Get3DManager()->SetFrustrum(90.0f, 0.1f, 125.0f); VideoManager()->Get3DManager()->SetFrustrum(90.0f, 0.1f, 125.0f);
m_unk0x426c = g_unk0x100d95e8[rand() % 3]; m_unk0x426c = g_unk0x100d95e8[SDL_rand(3)];
AnimationManager() AnimationManager()
->FUN_10060dc0(m_unk0x426c, NULL, TRUE, LegoAnimationManager::e_unk0, NULL, TRUE, FALSE, FALSE, FALSE); ->FUN_10060dc0(m_unk0x426c, NULL, TRUE, LegoAnimationManager::e_unk0, NULL, TRUE, FALSE, FALSE, FALSE);

View File

@ -374,7 +374,7 @@ MxLong Isle::HandleControl(LegoControlManagerNotificationParam& p_param)
break; break;
case IsleScript::c_Observe_Plane_Ctl: case IsleScript::c_Observe_Plane_Ctl:
if (!m_act1state->m_planeActive) { if (!m_act1state->m_planeActive) {
switch (rand() % 3) { switch (SDL_rand(3)) {
case 0: case 0:
InvokeAction(Extra::e_start, *g_isleScript, IsleScript::c_nic002pr_RunAnim, NULL); InvokeAction(Extra::e_start, *g_isleScript, IsleScript::c_nic002pr_RunAnim, NULL);
break; break;
@ -562,7 +562,7 @@ void Isle::Enable(MxBool p_enable)
MxS32 locations[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; MxS32 locations[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (MxU32 i = 0; i < 5; i++) { for (MxU32 i = 0; i < 5; i++) {
MxS32 r = rand() % 5; MxS32 r = SDL_rand(5);
for (MxU32 j = 0; j < sizeOfArray(locations); j++) { for (MxU32 j = 0; j < sizeOfArray(locations); j++) {
if (locations[j] != 0 && r-- == 0) { if (locations[j] != 0 && r-- == 0) {

View File

@ -173,7 +173,7 @@ MxResult LegoAct2::Tickle()
case 1: case 1:
((LegoPathActor*) m_pepper->GetEntity())->SetActorState(LegoPathActor::c_disabled); ((LegoPathActor*) m_pepper->GetEntity())->SetActorState(LegoPathActor::c_disabled);
switch (rand() % 3) { switch (SDL_rand(3)) {
case 0: case 0:
g_unk0x100f4474 = Act2mainScript::c_tns002br_RunAnim; g_unk0x100f4474 = Act2mainScript::c_tns002br_RunAnim;
break; break;
@ -816,7 +816,7 @@ void LegoAct2::SpawnBricks()
// Unused but present in BETA // Unused but present in BETA
LegoEntity* entity; LegoEntity* entity;
if ((MxS16) (rand() % 2) == 1) { if (SDL_rand(2) == 1) {
m_firstBrick = 0; m_firstBrick = 0;
location = infobridge; location = infobridge;
MxTrace("infobridge\n"); MxTrace("infobridge\n");
@ -840,7 +840,7 @@ void LegoAct2::SpawnBricks()
roi = brick->GetROI(); roi = brick->GetROI();
local2world = roi->GetLocal2World(); local2world = roi->GetLocal2World();
if ((MxS16) (rand() % 2) == 1) { if (SDL_rand(2) == 1) {
m_secondBrick = 2; m_secondBrick = 2;
location = store; location = store;
MxTrace("store\n"); MxTrace("store\n");
@ -864,7 +864,7 @@ void LegoAct2::SpawnBricks()
roi = brick->GetROI(); roi = brick->GetROI();
local2world = roi->GetLocal2World(); local2world = roi->GetLocal2World();
if ((MxS16) (rand() % 2) == 1) { if (SDL_rand(2) == 1) {
m_thirdBrick = 4; m_thirdBrick = 4;
location = h3; location = h3;
MxTrace("h3\n"); MxTrace("h3\n");
@ -888,8 +888,8 @@ void LegoAct2::SpawnBricks()
roi = brick->GetROI(); roi = brick->GetROI();
local2world = roi->GetLocal2World(); local2world = roi->GetLocal2World();
if ((MxS16) (rand() % 2) == 1) { if (SDL_rand(2) == 1) {
if ((MxS16) (rand() % 2) == 1) { if (SDL_rand(2) == 1) {
m_fourthBrick = 6; m_fourthBrick = 6;
location = posta; location = posta;
MxTrace("po.sta.\n"); MxTrace("po.sta.\n");
@ -901,7 +901,7 @@ void LegoAct2::SpawnBricks()
} }
} }
else { else {
if ((MxS16) (rand() % 2) == 1) { if (SDL_rand(2) == 1) {
m_fourthBrick = 8; m_fourthBrick = 8;
location = jail; location = jail;
MxTrace("jail\n"); MxTrace("jail\n");
@ -946,7 +946,7 @@ MxResult LegoAct2::BadEnding()
// FUNCTION: BETA10 0x10013fd3 // FUNCTION: BETA10 0x10013fd3
void LegoAct2::FUN_10051fa0(MxS32 p_param1) void LegoAct2::FUN_10051fa0(MxS32 p_param1)
{ {
MxU8 randN = rand() / (RAND_MAX / 3); MxU8 randN = SDL_rand(3);
randN++; randN++;
switch (p_param1) { switch (p_param1) {

View File

@ -198,7 +198,7 @@ MxBool Police::Escape()
PoliceState::PoliceState() PoliceState::PoliceState()
{ {
m_unk0x0c = 0; m_unk0x0c = 0;
m_policeScript = (rand() % 2 == 0) ? PoliceScript::c_nps002la_RunAnim : PoliceScript::c_nps001ni_RunAnim; m_policeScript = (SDL_rand(2) == 0) ? PoliceScript::c_nps002la_RunAnim : PoliceScript::c_nps001ni_RunAnim;
} }
// FUNCTION: LEGO1 0x1005e990 // FUNCTION: LEGO1 0x1005e990

View File

@ -114,7 +114,7 @@ void MxDSSelectAction::Deserialize(MxU8*& p_source, MxS16 p_flags)
MxS16 value = atoi(&m_unk0x9c.GetData()[strlen("RANDOM_")]); MxS16 value = atoi(&m_unk0x9c.GetData()[strlen("RANDOM_")]);
srand(Timer()->GetTime()); srand(Timer()->GetTime());
MxS32 random = rand() % value; MxS32 random = SDL_rand(value);
string = SDL_itoa((MxS16) random, buffer, 10); string = SDL_itoa((MxS16) random, buffer, 10);
} }