Changeset 270 for trunk/UGame.pas


Ignore:
Timestamp:
Jan 28, 2019, 10:38:17 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Keep randseed for randomly generated map preview inside New game form.
  • Modified: Resize map preview with form resize.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r268 r270  
    5353    procedure SetRunning(AValue: Boolean);
    5454    procedure BuildTerrain;
     55    procedure PlaceCities;
    5556    procedure SelectPlayerStartCell(Player: TPlayer);
    5657    procedure CalculatePlayersDistance;
     
    8283    BridgeEnabled: Boolean;
    8384    MaxPower: Integer;
     85    StoredRandSeed: Cardinal;
    8486    procedure PostConfig;
    8587    procedure Assign(Source: TGame);
     
    291293    if (VoidEnabled and (Random < VoidPercentage / 100)) or
    292294    (Map.IsOutsideShape(PosPx)) then Terrain := ttVoid
    293       else begin
    294         if CityEnabled and (Random < CityPercentage / 100) then Terrain := ttCity
    295           else Terrain := ttNormal;
    296       end;
     295      else Terrain := ttNormal;
    297296    if not Assigned(OneUnit) then
    298297      OneUnit := Units.AddNew(GameSystem.UnitKinds[0], Random(MaxNeutralUnits + 1));
    299298    Player := nil;
     299  end;
     300end;
     301
     302procedure TGame.PlaceCities;
     303var
     304  Cell: TCell;
     305begin
     306  for Cell in Map.Cells do
     307  with Cell do begin
     308    if (Terrain = ttNormal) and CityEnabled and (Random < CityPercentage / 100) then
     309      Terrain := ttCity;
    300310  end;
    301311end;
     
    418428procedure TGame.Assign(Source: TGame);
    419429begin
     430  StoredRandSeed := Source.StoredRandSeed;
    420431  DevelMode := Source.DevelMode;
    421432  Players.Assign(Source.Players);
     
    446457begin
    447458  with Config do begin
     459    SetValue(DOMString(Path + '/RandSeed'), Integer(StoredRandSeed));
    448460    SetValue(DOMString(Path + '/GridType'), Integer(MapType));
    449461    SetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName));
     
    473485begin
    474486  with Config do begin
     487    StoredRandSeed := GetValue(DOMString(Path + '/RandSeed'), 0);
    475488    MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagon)));
    476489    Map.Size := TPoint.Create(GetValue(DOMString(Path + '/MapSizeX'), 10),
     
    518531    RootNode := Doc.DocumentElement;
    519532    with RootNode do begin
     533      StoredRandSeed := ReadInteger(RootNode, 'RandSeed', 0);
    520534      MapType := TMapType(ReadInteger(RootNode, 'MapType', Integer(mtNone)));
    521535      SymetricMap := ReadBoolean(RootNode, 'SymetricMap', False);
     
    580594    AppendChild(RootNode);
    581595    with RootNode do begin
     596      WriteInteger(RootNode, 'RandSeed', Integer(StoredRandSeed));
    582597      WriteInteger(RootNode, 'MapType', Integer(MapType));
    583598      WriteBoolean(RootNode, 'SymetricMap', SymetricMap);
     
    825840begin
    826841  Clear;
     842  RandSeed := StoredRandSeed;
    827843  FileName := SNewGameFile;
    828844  TurnCounter := 1;
     
    832848  Map.MaxPower := MaxPower;
    833849  BuildTerrain;
     850  PlaceCities;
    834851  WinObjectiveMapPrepare;
    835852
Note: See TracChangeset for help on using the changeset viewer.