Changeset 397 for trunk/Game.pas


Ignore:
Timestamp:
Jan 6, 2025, 9:04:30 AM (2 days ago)
Author:
chronos
Message:
  • Fixed: Run Randomize only once at startup.
  • Fixed: Store current state of RandSeed to game save.
  • Fixed: Load/store RandSeed as its Cardinal type instead of Integer.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Game.pas

    r377 r397  
    529529begin
    530530  with Config do begin
    531     SetValue(DOMString(Path + '/RandSeed'), Integer(StoredRandSeed));
     531    SetValue(DOMString(Path + '/RandSeed'), DOMString(IntToStr(StoredRandSeed)));
    532532    SetValue(DOMString(Path + '/GridType'), Integer(MapType));
    533533    SetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName));
     
    558558var
    559559  Value: Integer;
     560  ValueInt64: Int64;
    560561begin
    561562  with Config do begin
    562     StoredRandSeed := GetValue(DOMString(Path + '/RandSeed'), 0);
    563     MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagonVertical)));
    564     Map.Size := TPoint.Create(GetValue(DOMString(Path + '/MapSizeX'), 10),
    565       GetValue(DOMString(Path + '/MapSizeY'), 10));
     563    if TryStrToInt64(string(GetValue(DOMString(Path + '/RandSeed'), DOMString(IntToStr(StoredRandSeed)))), ValueInt64) then
     564      StoredRandSeed := ValueInt64;
     565    MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(MapType)));
     566    Map.Size := TPoint.Create(GetValue(DOMString(Path + '/MapSizeX'), Map.Size.X),
     567      GetValue(DOMString(Path + '/MapSizeY'), Map.Size.Y));
    566568    MapImageFileName := string(GetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName)));
    567     SymetricMap := GetValue(DOMString(Path + '/SymetricMap'), False);
    568     CyclicMap := GetValue(DOMString(Path + '/CyclicMap'), False);
    569     FogOfWar := GetValue(DOMString(Path + '/FogOfWar'), False);
    570     VoidEnabled := GetValue(DOMString(Path + '/VoidEnabled'), True);
    571     VoidPercentage := GetValue(DOMString(Path + '/VoidPercentage'), 20);
    572     Value := GetValue(DOMString(Path + '/MapShape'), 0);
     569    SymetricMap := GetValue(DOMString(Path + '/SymetricMap'), SymetricMap);
     570    CyclicMap := GetValue(DOMString(Path + '/CyclicMap'), CyclicMap);
     571    FogOfWar := GetValue(DOMString(Path + '/FogOfWar'), FogOfWar);
     572    VoidEnabled := GetValue(DOMString(Path + '/VoidEnabled'), VoidEnabled);
     573    VoidPercentage := GetValue(DOMString(Path + '/VoidPercentage'), VoidPercentage);
     574    Value := GetValue(DOMString(Path + '/MapShape'), Integer(Map.Shape));
    573575    if (Value >= Integer(Low(TMapShape))) and (Value <= Integer(High(TMapShape))) then
    574576      Map.Shape := TMapShape(Value) else Map.Shape := Low(TMapShape);
    575     CityEnabled := GetValue(DOMString(Path + '/CityEnabled'), False);
    576     CityPercentage := GetValue(DOMString(Path + '/CityPercentage'), 10);
    577     BridgeEnabled := GetValue(DOMString(Path + '/BridgeEnabled'), True);
    578     Value := GetValue(DOMString(Path + '/GrowAmount'), Integer(gaBySquareRoot));
     577    CityEnabled := GetValue(DOMString(Path + '/CityEnabled'), CityEnabled);
     578    CityPercentage := GetValue(DOMString(Path + '/CityPercentage'), CityPercentage);
     579    BridgeEnabled := GetValue(DOMString(Path + '/BridgeEnabled'), BridgeEnabled);
     580    Value := GetValue(DOMString(Path + '/GrowAmount'), Integer(GrowAmount));
    579581    if (Value >= Integer(Low(TGrowAmount))) and (Value <= Integer(High(TGrowAmount))) then
    580582      GrowAmount := TGrowAmount(Value) else GrowAmount := Low(TGrowAmount);
    581     Value := GetValue(DOMString(Path + '/GrowCells'), Integer(gcPlayerAll));
     583    Value := GetValue(DOMString(Path + '/GrowCells'), Integer(GrowCells));
    582584    if (Value >= Integer(Low(TGrowCells))) and (Value <= Integer(High(TGrowCells))) then
    583585      GrowCells := TGrowCells(Value) else GrowCells := Low(TGrowCells);
    584     Value := GetValue(DOMString(Path + '/WinObjective'), Integer(woDefeatAllOponents));
     586    Value := GetValue(DOMString(Path + '/WinObjective'), Integer(WinObjective));
    585587    if (Value >= Integer(Low(TWinObjective))) and (Value <= Integer(High(TWinObjective))) then
    586588      WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective);
    587     StayAliveForDefinedTurns := GetValue(DOMString(Path + '/StayAliveForDefinedTurns'), 20);
    588     SpecialCaptureCellCount := GetValue(DOMString(Path + '/SpecialCaptureCellCount'), 1);
    589     MaxNeutralUnits := GetValue(DOMString(Path + '/MaxNeutralUnits'), 5);
    590     MaxPower := GetValue(DOMString(Path + '/MaxPower'), 99);
     589    StayAliveForDefinedTurns := GetValue(DOMString(Path + '/StayAliveForDefinedTurns'), StayAliveForDefinedTurns);
     590    SpecialCaptureCellCount := GetValue(DOMString(Path + '/SpecialCaptureCellCount'), SpecialCaptureCellCount);
     591    MaxNeutralUnits := GetValue(DOMString(Path + '/MaxNeutralUnits'), MaxNeutralUnits);
     592    MaxPower := GetValue(DOMString(Path + '/MaxPower'), MaxPower);
    591593    Players.LoadConfig(Config, Path + '/Players');
    592594  end;
     
    608610    RootNode := Doc.DocumentElement;
    609611    with RootNode do begin
    610       StoredRandSeed := ReadInteger(RootNode, 'RandSeed', 0);
     612      StoredRandSeed := ReadInt64(RootNode, 'RandSeed', 0);
    611613      MapType := TMapType(ReadInteger(RootNode, 'MapType', Integer(mtNone)));
    612614      SymetricMap := ReadBoolean(RootNode, 'SymetricMap', False);
     
    672674    AppendChild(RootNode);
    673675    with RootNode do begin
    674       WriteInteger(RootNode, 'RandSeed', Integer(StoredRandSeed));
     676      StoredRandSeed := RandSeed;
     677      WriteInt64(RootNode, 'RandSeed', StoredRandSeed);
    675678      WriteInteger(RootNode, 'MapType', Integer(MapType));
    676679      WriteBoolean(RootNode, 'SymetricMap', SymetricMap);
     
    910913
    911914  GeneratePlayers := True;
     915  StoredRandSeed := RandSeed;
    912916  MapImageFileName := '';
    913   Randomize;
    914   StoredRandSeed := RandSeed;
    915   InitDefaultPlayers;
    916 
     917  MapType := mtHexagonVertical;
     918  Map.Size := TPoint.Create(10, 10);
     919
     920  CityPercentage := 20;
    917921  VoidEnabled := True;
    918922  VoidPercentage := 20;
    919923  MaxPower := DefaultMaxPower;
    920924  MaxNeutralUnits := Min(4, MaxPower);
    921 
    922   Map.Size := TPoint.Create(3, 3);
     925  BridgeEnabled := True;
     926  MaxNeutralUnits := 5;
     927  MaxPower := 99;
     928  SpecialCaptureCellCount := 1;
     929  StayAliveForDefinedTurns := 20;
     930  WinObjective := woDefeatAllOponents;
     931  GrowCells := gcPlayerAll;
     932  GrowAmount := gaBySquareRoot;
     933
     934  InitDefaultPlayers;
    923935end;
    924936
Note: See TracChangeset for help on using the changeset viewer.