@@ -228,6 +228,37 @@ DEBUG_LOG(( "%d: GetGameLogicRandomValue = %d (%d - %d), %s line %d",
228228 return rval;
229229}
230230
231+ //
232+ // TheSuperHackers @info This function does not change the seed values with retail compability disabled.
233+ // Consecutive calls always return the same value for the same combination of min / max values, assuming the seed values haven't changed in between.
234+ // The intended use case for this function are randomized values that are desirable to be synchronized across clients,
235+ // but should not result in a mismatch if they aren't synchronized; e.g. for scripted audio events.
236+ //
237+ Int GetGameLogicRandomValueUnchanged ( int lo, int hi, const char *file, int line )
238+ {
239+ #if RETAIL_COMPATIBLE_CRC
240+ return GetGameLogicRandomValue (lo, hi, file, line);
241+ #endif
242+
243+ if (lo >= hi)
244+ return lo;
245+
246+ UnsignedInt seed[ARRAY_SIZE (theGameLogicSeed)];
247+ memcpy (&seed[0 ], &theGameLogicSeed[0 ], sizeof (seed));
248+
249+ const UnsignedInt delta = hi - lo + 1 ;
250+ const Int rval = ((Int)(randomValue (seed) % delta)) + lo;
251+
252+ DEBUG_ASSERTCRASH (rval >= lo && rval <= hi, (" Bad random val" ));
253+
254+ #ifdef DEBUG_RANDOM_LOGIC
255+ DEBUG_LOG (( " %d: GetGameLogicRandomValueUnchanged = %d (%d - %d), %s line %d" ,
256+ TheGameLogic->getFrame (), rval, lo, hi, file, line ));
257+ #endif
258+
259+ return rval;
260+ }
261+
231262//
232263// Integer random value
233264//
@@ -298,6 +329,37 @@ DEBUG_LOG(( "%d: GetGameLogicRandomValueReal = %f, %s line %d",
298329 return rval;
299330}
300331
332+ //
333+ // TheSuperHackers @info This function does not change the seed values with retail compability disabled.
334+ // Consecutive calls always return the same value for the same combination of min / max values, assuming the seed values haven't changed in between.
335+ // The intended use case for this function are randomized values that are desirable to be synchronized across clients,
336+ // but should not result in a mismatch if they aren't synchronized; e.g. for scripted audio events.
337+ //
338+ Real GetGameLogicRandomValueRealUnchanged ( Real lo, Real hi, const char *file, int line )
339+ {
340+ #if RETAIL_COMPATIBLE_CRC
341+ return GetGameLogicRandomValueReal (lo, hi, file, line);
342+ #endif
343+
344+ if (lo >= hi)
345+ return lo;
346+
347+ UnsignedInt seed[ARRAY_SIZE (theGameLogicSeed)];
348+ memcpy (&seed[0 ], &theGameLogicSeed[0 ], sizeof (seed));
349+
350+ const Real delta = hi - lo;
351+ const Real rval = ((Real)(randomValue (seed)) * theMultFactor) * delta + lo;
352+
353+ DEBUG_ASSERTCRASH (rval >= lo && rval <= hi, (" Bad random val" ));
354+
355+ #ifdef DEBUG_RANDOM_LOGIC
356+ DEBUG_LOG (( " %d: GetGameLogicRandomValueRealUnchanged = %f, %s line %d" ,
357+ TheGameLogic->getFrame (), rval, file, line ));
358+ #endif
359+
360+ return rval;
361+ }
362+
301363//
302364// Real valued random value
303365//
0 commit comments