Changeset 120


Ignore:
Timestamp:
Feb 3, 2018, 5:03:31 PM (6 years ago)
Author:
chronos
Message:
  • Added: Special Delphi random number generator algorithm. It is needed to correctly open stored books. Saved games depends on stored randseed and random generator algorithm which is pretty bad design.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Database.pas

    r45 r120  
    652652{$IFNDEF SCR} if x = 1 then
    653653      v := pi / 2 { first wave goes horizontal }
    654     else {$ENDIF} v := Random * 2 * pi;
     654    else {$ENDIF} v := DelphiRandom * 2 * pi;
    655655    sa[x] := sin(v) / lx;
    656656    ca[x] := cos(v) / ly;
     
    786786              begin
    787787                inc(AreaCount[xBlock, yBlock]);
    788                 if Random(AreaCount[xBlock, yBlock]) = 0 then
     788                if DelphiRandom(AreaCount[xBlock, yBlock]) = 0 then
    789789                  RareByArea[xBlock, yBlock] := Loc0
    790790              end
     
    857857          begin
    858858            inc(Cnt);
    859             if Random(Cnt) = 0 then
     859            if DelphiRandom(Cnt) = 0 then
    860860            begin
    861861              xworst := x;
     
    908908              begin
    909909                inc(Cnt);
    910                 if Random(Cnt) = 0 then
     910                if DelphiRandom(Cnt) = 0 then
    911911                begin
    912912                  iBest := i;
     
    996996      p := Zone[z0, i] * (1 - ZPlus) + Zone[z0 + 1, i] * ZPlus;
    997997      { weight between zones z0 and z0+1 }
    998       if Random * p0 < p then
     998      if DelphiRandom * p0 < p then
    999999      begin
    10001000        RndLow := i;
     
    11361136    if plus > MapSize then
    11371137      plus := MapSize;
    1138     Loc0 := Random(MapSize);
     1138    Loc0 := DelphiRandom(MapSize);
    11391139    for n := 0 to plus - 1 do
    11401140    begin
     
    11471147
    11481148  for Loc0 := 0 to MapSize - 1 do
    1149     if (RealMap[Loc0] = fGrass) and (Random(100) < ShRandHills) then
     1149    if (RealMap[Loc0] = fGrass) and (DelphiRandom(100) < ShRandHills) then
    11501150      RealMap[Loc0] := RealMap[Loc0] or fHills;
    11511151
     
    11561156  for n := 0 to unification * MapSize div 100 do
    11571157  begin
    1158     y := Random(ly);
    1159     if abs(y - (ly shr 1)) > ly div 4 + Random(ly * hotunification div 100) then
     1158    y := DelphiRandom(ly);
     1159    if abs(y - (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then
    11601160      if y < ly shr 1 then
    11611161        y := ly shr 1 - y
    11621162      else
    11631163        y := 3 * ly shr 1 - y;
    1164     Loc0 := lx * y + Random(lx);
     1164    Loc0 := lx * y + DelphiRandom(lx);
    11651165    if RealMap[Loc0] and fTerrain = fGrass then
    11661166    begin
    1167       Dir := Random(4);
     1167      Dir := DelphiRandom(4);
    11681168      Loc1 := dLoc(Loc0, Dir and 1 * 2 - 1, Dir shr 1 * 2 - 1);
    11691169      if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain = fGrass) then
     
    11981198    if RealMap[Loc0] and fTerrain = fGrass then
    11991199    begin // change grassland to swamp
    1200       if Random(100) < ShSwamp then
     1200      if DelphiRandom(100) < ShSwamp then
    12011201        RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fSwamp;
    12021202    end;
     
    13731373    end;
    13741374    FillChar(nCityLoc, SizeOf(nCityLoc), 0);
    1375     Loc := Random(MapSize);
     1375    Loc := DelphiRandom(MapSize);
    13761376    for i := 0 to MapSize - 1 do
    13771377    begin
     
    14141414  begin // for all start continents
    14151415    if sccount[c] = 1 then
    1416       StartLoc0[p1] := CityLoc[c, Random(nCityLoc[c])]
     1416      StartLoc0[p1] := CityLoc[c, DelphiRandom(nCityLoc[c])]
    14171417    else
    14181418    begin
     
    14311431          if nRest = 0 then
    14321432            Break;
    1433           j := Random(nRest);
     1433          j := DelphiRandom(nRest);
    14341434          TestStartLoc[i] := RestLoc[j];
    14351435          RestLoc[j] := RestLoc[nRest - 1];
     
    14941494        if (Loc1 >= 0) and (Loc1 < MapSize) and
    14951495          (RealMap[Loc1] and fDeadLands = 0) then
    1496           if IsGoodTile(Loc1) and (Random(CntGood) < MinGood - CntGoodGrass + 1)
     1496          if IsGoodTile(Loc1) and (DelphiRandom(CntGood) < MinGood - CntGoodGrass + 1)
    14971497          then
    14981498          begin
     
    15041504            RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fPrairie
    15051505          else if (RealMap[Loc1] and fTerrain in [fPrairie, fTundra, fSwamp])
    1506             and (Random(2) = 0) then
     1506            and (DelphiRandom(2) = 0) then
    15071507            RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fForest;
    15081508      end;
     
    15261526    while i > 0 do
    15271527    begin
    1528       j := Random(nIrrLoc);
     1528      j := DelphiRandom(nIrrLoc);
    15291529      RealMap[IrrLoc[j]] := RealMap[IrrLoc[j]] or tiIrrigation;
    15301530      IrrLoc[j] := IrrLoc[nIrrLoc - 1];
     
    15391539    begin
    15401540      repeat
    1541         i := Random(nAlive) + 1
     1541        i := DelphiRandom(nAlive) + 1
    15421542      until StartLoc0[i] >= 0;
    15431543      StartLoc[p1] := StartLoc0[i];
     
    15801580        begin
    15811581          inc(n);
    1582           if Random(n) = 0 then
     1582          if DelphiRandom(n) = 0 then
    15831583            StartLoc2[p1] := Loc1;
    15841584        end;
     
    16371637          imax := nPrefStartLoc0;
    16381638        end;
    1639         i := Random(imax + 1);
     1639        i := DelphiRandom(imax + 1);
    16401640        StartLoc[p1] := StartLoc0[i];
    16411641        StartLoc2[p1] := StartLoc0[i];
     
    16571657  { !!!for Loc1:=0 to MapSize-1 do
    16581658    if RealMap[Loc1] and fterrain>=fGrass then
    1659     if random(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRoad
    1660     else if random(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR;
     1659    if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRoad
     1660    else if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR;
    16611661    {random Road and Railroad }
    16621662  { !!!for Loc1:=0 to MapSize-1 do
    1663     if (RealMap[Loc1] and fterrain>=fGrass) and (random(20)=0) then
     1663    if (RealMap[Loc1] and fterrain>=fGrass) and (Delphirandom(20)=0) then
    16641664    RealMap[Loc1]:=RealMap[Loc1] or fPoll; }
    16651665
     
    17821782procedure InitRandomGame;
    17831783begin
    1784   RandSeed := RND;
     1784  DelphiRandSeed := RND;
    17851785  CalculatePrimitive;
    17861786  CreateElevation;
     
    17921792procedure InitMapGame(Human: integer);
    17931793begin
    1794   RandSeed := RND;
     1794  DelphiRandSeed := RND;
    17951795  FindContinents;
    17961796  PredefinedStartPositions(Human);
     
    27702770  i, dx, dy, dxMax, dyMax, Loc, NewOwner: integer;
    27712771begin
     2772  if OriginLoc = -1 then
     2773    raise Exception.Create('Location error');
    27722774  i := 0;
    27732775  dyMax := 0;
  • trunk/GameServer.pas

    r105 r120  
    295295  MapSize := lx * ly;
    296296  LandMass := lm;
    297   RandSeed := PreviewRND;
     297  DelphiRandSeed := PreviewRND;
    298298  if not PreviewElevation then
    299299  begin
     
    714714        bix[p1] := -1
    715715      else
    716         bix[p1] := bixFirstAI + random(nBrain - bixFirstAI)
     716        bix[p1] := bixFirstAI + Delphirandom(nBrain - bixFirstAI)
    717717    else
    718718      bix[p1] := bixView[p1];
     
    838838          RW[p].DefaultDebugMap := nil;
    839839
    840         { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=random((3-i)*2);{ }
     840        { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2);{ }
    841841      end;
    842842
     
    13711371    LandMass := NewLandMass;
    13721372  MaxTurn := NewMaxTurn;
    1373   Randomize;
    1374   RND := RandSeed;
     1373  DelphiRandomize;
     1374  RND := DelphiRandSeed;
    13751375  Mode := moPlaying;
    13761376  CL := TCmdList.Create;
     
    14161416  InitBrain(bixTerm);
    14171417
    1418   Randomize;
     1418  DelphiRandomize;
    14191419  GAlive := 0;
    14201420  GWatching := 1;
  • trunk/LocalPlayer/Diagram.pas

    r113 r120  
    6868
    6969    // stars
    70     RandSeed := Player * 11111;
     70    DelphiRandSeed := Player * 11111;
    7171    for i := 1 to Width - 16 do
    7272    begin
    73       x := Random((Width - 16) * 200);
    74       r := Random(13) + 28;
     73      x := DelphiRandom((Width - 16) * 200);
     74      r := DelphiRandom(13) + 28;
    7575      Canvas.Pixels[x div 200 + 8, x mod 200 + Top] :=
    7676        (r * r * r * r div 10001) * $10101;
  • trunk/LocalPlayer/Term.pas

    r118 r120  
    13221322      begin
    13231323        inc(CountBest);
    1324         if random(CountBest) = 0 then
     1324        if DelphiRandom(CountBest) = 0 then
    13251325          result := j
    13261326      end
     
    35023502    AILogo[i] := nil;
    35033503  Canvas.Font.Assign(UniFont[ftSmall]);
    3504   InitButtons();
     3504  InitButtons;
    35053505  EOT.Template := Templates;
    35063506end;
  • trunk/Protocol.pas

    r117 r120  
    12831283  end;
    12841284
     1285  { TCity }
     1286
    12851287  TCity = packed record
    12861288    Loc, { location }
     
    16321634    { preLeo,preLighthouse, } preLeo);
    16331635
     1636var
     1637  DelphiRandSeed: Integer;
     1638
    16341639procedure MakeUnitInfo(p: integer; const u: TUn; var ui: TUnitInfo);
    16351640procedure MakeModelInfo(p, mix: integer; const m: TModel; var mi: TModelInfo);
    16361641function IsSameModel(const mi1, mi2: TModelInfo): boolean;
    16371642function SpecialTile(Loc, TerrType, lx: integer): integer;
     1643function DelphiRandom(const pi_Max: Integer): Integer; overload;
     1644function DelphiRandom: Extended; overload;
     1645procedure DelphiRandomize;
    16381646
    16391647implementation
     
    17571765end;
    17581766
     1767function DelphiRandom(const pi_Max: Integer): Integer;
     1768var
     1769  Temp: LongInt;
     1770begin
     1771  Temp := LongInt(134775813 * DelphiRandSeed + 1);
     1772  DelphiRandSeed := Temp;
     1773  Result := (UInt64(Cardinal(pi_Max)) * UInt64(Cardinal(Temp))) shr 32;
     1774end;
     1775
     1776function DelphiRandom: Extended; overload;
     1777begin
     1778  Result := DelphiRandom(High(LongInt)) / High(LongInt);
     1779end;
     1780
     1781procedure DelphiRandomize;
     1782begin
     1783  Randomize;
     1784  DelphiRandSeed := RandSeed;
     1785end;
     1786
    17591787initialization
    17601788
Note: See TracChangeset for help on using the changeset viewer.