Changeset 271 for trunk/UGame.pas


Ignore:
Timestamp:
Jan 28, 2019, 10:53:09 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Do not generate players in New game map preview.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r270 r271  
    5454    procedure BuildTerrain;
    5555    procedure PlaceCities;
     56    procedure InitPlayers;
    5657    procedure SelectPlayerStartCell(Player: TPlayer);
    5758    procedure CalculatePlayersDistance;
     
    8485    MaxPower: Integer;
    8586    StoredRandSeed: Cardinal;
     87    GeneratePlayers: Boolean;
    8688    procedure PostConfig;
    8789    procedure Assign(Source: TGame);
     
    308310    if (Terrain = ttNormal) and CityEnabled and (Random < CityPercentage / 100) then
    309311      Terrain := ttCity;
     312  end;
     313end;
     314
     315procedure TGame.InitPlayers;
     316var
     317  I: Integer;
     318  Player: TPlayer;
     319begin
     320  if not GeneratePlayers then Exit;
     321
     322  for Player in Players do begin
     323    Player.Reset;
     324    Player.StartCell := nil;
     325  end;
     326  I := 0;
     327  for Player in Players do
     328  with Player do begin
     329    PlayerMap.Update;
     330    if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin
     331      SelectPlayerStartCell(Player);
     332      if Assigned(Player.StartCell) then begin
     333        if SymetricMap and (I = 1) then
     334          StartCell := Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(Players[0].StartCell)];
     335
     336        if CityEnabled then StartCell.Terrain := ttCity;
     337        StartCell.Player := Player;
     338        if not Assigned(StartCell.OneUnit) then
     339          StartCell.OneUnit := Units.AddNew(GameSystem.UnitKinds[0], Player.StartUnits);
     340        StartCell.OneUnit.Power := Player.StartUnits;
     341        StartCell.OneUnit.Kind := GameSystem.UnitKinds[0];
     342      end;
     343    end;
     344    PlayerMap.CheckVisibility;
     345    Inc(I);
    310346  end;
    311347end;
     
    806842  Players.Game := Self;
    807843
     844  GeneratePlayers := True;
    808845  MapImageFileName := 'Images/Maps/WorldMap.png';
    809846  Randomize;
     847  StoredRandSeed := RandSeed;
    810848  InitDefaultPlayers;
    811849
     
    835873
    836874procedure TGame.New;
    837 var
    838   I: Integer;
    839   Player: TPlayer;
    840875begin
    841876  Clear;
     
    859894  end;
    860895
    861   for Player in Players do begin
    862     Player.Reset;
    863     Player.StartCell := nil;
    864   end;
    865   I := 0;
    866   for Player in Players do
    867   with Player do begin
    868     PlayerMap.Update;
    869     if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin
    870       SelectPlayerStartCell(Player);
    871       if Assigned(Player.StartCell) then begin
    872         if SymetricMap and (I = 1) then
    873           StartCell := Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(Players[0].StartCell)];
    874 
    875         StartCell.Terrain := ttCity;
    876         StartCell.Player := Player;
    877         if not Assigned(StartCell.OneUnit) then
    878           StartCell.OneUnit := Units.AddNew(GameSystem.UnitKinds[0], Player.StartUnits);
    879         StartCell.OneUnit.Power := Player.StartUnits;
    880         StartCell.OneUnit.Kind := GameSystem.UnitKinds[0];
    881       end;
    882     end;
    883     PlayerMap.CheckVisibility;
    884     Inc(I);
    885   end;
     896  InitPlayers;
    886897  if Players.Count > 0 then CurrentPlayer := Players[0]
    887898    else CurrentPlayer := nil;
Note: See TracChangeset for help on using the changeset viewer.