--- a/hedgewars/uRandom.pas Thu Apr 04 14:37:19 2013 +0200
+++ b/hedgewars/uRandom.pas Tue Jun 04 22:28:12 2013 +0200
@@ -1,6 +1,6 @@
(*
* Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,8 +30,8 @@
interface
uses uFloat;
-procedure SetRandomSeed(Seed: shortstring); // Sets the seed that should be used for generating pseudo-random values.
-function GetRandomf: hwFloat; // Returns a pseudo-random hwFloat.
+procedure SetRandomSeed(Seed: shortstring; dropAdditionalPart: boolean); // Sets the seed that should be used for generating pseudo-random values.
+function GetRandomf: hwFloat; overload; // Returns a pseudo-random hwFloat.
function GetRandom(m: LongWord): LongWord; overload; inline; // Returns a positive pseudo-random integer smaller than m.
procedure AddRandomness(r: LongWord); inline;
function rndSign(num: hwFloat): hwFloat; // Returns num with a random chance of having a inverted sign.
@@ -61,18 +61,24 @@
str(GetNext, s);
end;
-procedure SetRandomSeed(Seed: shortstring);
-var i: Longword;
+procedure SetRandomSeed(Seed: shortstring; dropAdditionalPart: boolean);
+var i, t, l: Longword;
begin
n:= 54;
if Length(Seed) > 54 then
Seed:= copy(Seed, 1, 54); // not 55 to ensure we have odd numbers in cirbuf
-for i:= 0 to Pred(Length(Seed)) do
- cirbuf[i]:= byte(Seed[i + 1]);
+t:= 0;
+l:= Length(Seed);
-for i:= Length(Seed) to 54 do
+while (t < l) and ((not dropAdditionalPart) or (Seed[t + 1] <> '|')) do
+ begin
+ cirbuf[t]:= byte(Seed[t + 1]);
+ inc(t)
+ end;
+
+for i:= t to 54 do
cirbuf[i]:= $A98765 + 68; // odd number
for i:= 0 to 1023 do