Changeset 120 for trunk/Protocol.pas


Ignore:
Timestamp:
Feb 3, 2018, 5:03:31 PM (7 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/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.