Changeset 120 for trunk/Database.pas


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.
File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.