Changeset 76


Ignore:
Timestamp:
Oct 5, 2014, 1:34:43 PM (10 years ago)
Author:
chronos
Message:
  • Modified: More changes to support game load from file.
  • Fixed: Require at least one player in new game.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r74 r76  
    9191      Style = tbsSeparator
    9292    end
     93    object ToolButton10: TToolButton
     94      Left = 1
     95      Top = 268
     96      Width = 32
     97      Style = tbsSeparator
     98    end
     99    object ToolButton11: TToolButton
     100      Left = 1
     101      Top = 278
     102      Action = Core.AGameLoad
     103    end
     104    object ToolButton12: TToolButton
     105      Left = 1
     106      Top = 310
     107      Action = Core.AGameSave
     108    end
     109    object ToolButton13: TToolButton
     110      Left = 1
     111      Top = 342
     112      Action = Core.AExit
     113    end
    93114  end
    94115  object PaintBox1: TPaintBox
  • trunk/Forms/UFormMain.pas

    r73 r76  
    5353    ToolBar1: TToolBar;
    5454    ToolButton1: TToolButton;
     55    ToolButton10: TToolButton;
     56    ToolButton11: TToolButton;
     57    ToolButton12: TToolButton;
     58    ToolButton13: TToolButton;
    5559    ToolButton2: TToolButton;
    5660    ToolButton3: TToolButton;
  • trunk/Forms/UFormNew.pas

    r75 r76  
    228228  ListView1.Items.Count := Players.Count;
    229229  ListView1.Refresh;
    230   ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected);
     230  ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected) and (Players.Count > 1);
    231231  ButtonPlayerAdd.Enabled := Players.Count < MaxPlayerCount;
    232232  APlayerModify.Enabled := Assigned(ListView1.Selected);
     
    306306  if Players.Count <= (MaxPlayerCount - 1) then begin
    307307    NewPlayer := TPlayer.Create;
    308     NewPlayer.Name := 'Player ' + IntToStr(Players.Count + 1);
     308    NewPlayer.Id := Players.GetNewPlayerId;
     309    NewPlayer.Name := SPlayer + ' ' + IntToStr(NewPlayer.Id);
    309310    NewPlayer.Color := PlayerColors[Players.Count];
    310311    NewPlayer.Mode := pmComputer;
     
    335336    TPlayer(Players[I]).Assign(TPlayer(Game.Players[I]));
    336337  end;
     338  Players.NewPlayerId := Game.Players.NewPlayerId;
     339
    337340  CheckBoxCity.Checked := Game.CityEnabled;
    338341  SpinEditCityPercent.Value := Game.CityPercentage;
     
    362365    TPlayer(Game.Players[I]).Game := Game;
    363366  end;
     367  Game.Players.NewPlayerId := Players.NewPlayerId;
    364368  Game.SymetricMap := CheckBoxSymetricMap.Checked;
    365369  Game.VoidEnabled := CheckBoxVoid.Checked;
  • trunk/Languages/xtactics.cs.po

    r75 r76  
    195195
    196196#: tformnew.aplayeradd.caption
    197 #, fuzzy
    198197#| msgid "Add player"
    199198msgid "Add"
    200 msgstr "Přidat hráče"
     199msgstr "Přidat"
    201200
    202201#: tformnew.aplayermodify.caption
     
    205204
    206205#: tformnew.aplayerremove.caption
    207 #, fuzzy
    208206#| msgid "Remove player"
    209207msgid "Remove"
    210 msgstr "Odstranit hráče"
     208msgstr "Odstranit"
    211209
    212210#: tformnew.buttoncancel.caption
     
    218216msgctxt "tformnew.buttonimagebrowse.caption"
    219217msgid "Browse"
    220 msgstr ""
     218msgstr "Vybrat"
    221219
    222220#: tformnew.buttonok.caption
     
    280278#: tformnew.label8.caption
    281279msgid "Map shape:"
    282 msgstr ""
     280msgstr "Tvar mapy"
    283281
    284282#: tformnew.label9.caption
    285283msgid "Image file:"
    286 msgstr ""
     284msgstr "Soubor obrázku:"
    287285
    288286#: tformnew.listview1.columns[0].caption
     
    312310#: tformnew.tabsheet1.caption
    313311msgid "Players"
    314 msgstr ""
     312msgstr "Hráči"
    315313
    316314#: tformnew.tabsheet2.caption
    317315msgid "Map"
    318 msgstr ""
     316msgstr "Mapa"
    319317
    320318#: tformnew.tabsheet3.caption
    321319msgid "Rules"
    322 msgstr ""
     320msgstr "Pravidla"
    323321
    324322#: tformplayer.buttoncancel.caption
     
    437435#: uformnew.sfromimagefile
    438436msgid "From image file"
    439 msgstr ""
     437msgstr "Obrázek ze souboru"
    440438
    441439#: uformnew.sgridtypehexagon
     
    477475#: uformnew.srectangular
    478476msgid "Rectangular"
    479 msgstr ""
     477msgstr "Obdelníkový"
    480478
    481479#: uformnew.swinobjectivecaptureposition
     
    525523#: ugame.snewgamefile
    526524msgid "New game.xtg"
    527 msgstr "Nová hry.xtg"
     525msgstr "Nová hra.xtg"
    528526
    529527#: ugame.splayer
     
    539537msgid "Wrong file format"
    540538msgstr "Chybný formát souboru"
    541 
  • trunk/UCore.pas

    r74 r76  
    187187    Game.LoadFromFile(OpenDialog1.FileName);
    188188    LastMapFileName := OpenDialog1.FileName;
     189    with Core.Game.CurrentPlayer do
     190      View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
     191    FormMain.AZoomAll.Execute;
    189192    FormMain.Redraw;
    190193  end;
  • trunk/UGame.pas

    r75 r76  
    2424  TView = class;
    2525  TUnitMoves = class;
     26  TCells = class;
    2627
    2728  TFloatPoint = record
     
    4748    MovesFrom: TUnitMoves;
    4849    MovesTo: TUnitMoves;
    49     Neighbors: TObjectList; // TList<TCell>
     50    Neighbors: TCells;
    5051    Mark: Boolean;
     52    procedure LoadFromNode(Node: TDOMNode);
     53    procedure SaveToNode(Node: TDOMNode);
    5154    procedure Assign(Source: TCell);
    5255    function IsVisible(View: TView): Boolean;
     
    6063
    6164  TCellArray = array of TCell;
     65
     66  { TCells }
     67
    6268  TCells = class(TObjectList)
    63 
     69    function FindById(Id: Integer): TCell;
     70    procedure LoadFromNode(Node: TDOMNode);
     71    procedure SaveToNode(Node: TDOMNode);
    6472  end;
    6573
     
    98106  private
    99107    FSize: TPoint;
     108    FNewCellId: Integer;
    100109    function GetSize: TPoint; virtual;
    101110    procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView;
     
    104113      Text: string);
    105114    procedure SetSize(AValue: TPoint); virtual;
     115    function GetNewCellId: Integer; virtual;
    106116  public
    107117    Game: TGame;
    108118    MaxPower: Integer;
    109119    DefaultCellSize: TPoint;
    110     Cells: TObjectList; // TList<TCell>
     120    Cells: TCells;
    111121    Shape: TMapShape;
    112122    Image: TImage;
     
    139149  private
    140150    function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean;
    141     function GetCellPosNeighbors(CellPos: TPoint): TCellArray;
     151    procedure GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells);
    142152    function GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPointArray;
    143153  public
     
    223233
    224234  TPlayers = class(TObjectList)
     235    Game: TGame;
     236    NewPlayerId: Integer;
     237    procedure New(Name: string; Color: TColor; Mode: TPlayerMode);
     238    function GetNewPlayerId: Integer;
    225239    procedure LoadFromNode(Node: TDOMNode);
    226240    procedure SaveToNode(Node: TDOMNode);
     241    constructor Create;
    227242  end;
    228243
     
    236251    procedure SetCellTo(AValue: TCell);
    237252  public
    238     List: TObjectList; // TList<TUnitMove>
     253    List: TUnitMoves;
    239254    CountOnce: Integer;
    240255    CountRepeat: Integer;
     
    250265
    251266  TUnitMoves = class(TObjectList)
     267    Game: TGame;
    252268    procedure LoadFromNode(Node: TDOMNode);
    253269    procedure SaveToNode(Node: TDOMNode);
     
    331347function FloatPoint(AX, AY: Double): TFloatPoint;
    332348
     349resourcestring
     350  SPlayer = 'Player';
     351
    333352
    334353implementation
     
    336355resourcestring
    337356  SMinimumPlayers = 'You need at least two players';
    338   SPlayer = 'Player';
    339357  SHuman = 'Human';
    340358  SComputer = 'Computer';
     
    407425end;
    408426
    409 { TComputer }
     427{ TCells }
     428
     429function TCells.FindById(Id: Integer): TCell;
     430var
     431  I: Integer;
     432begin
     433  I := 0;
     434  while (I < 0) and (TCell(Items[I]).Id <> Id) do Inc(I);
     435  if I < Count then Result := TCell(Items[I])
     436    else Result := nil;
     437end;
     438
     439procedure TCells.LoadFromNode(Node: TDOMNode);
     440var
     441  Node2: TDOMNode;
     442  NewCell: TCell;
     443begin
     444  Count := 0;
     445  Node2 := Node.FirstChild;
     446  while Assigned(Node2) and (Node2.NodeName = 'Cell') do begin
     447    NewCell := TCell.Create;
     448    NewCell.LoadFromNode(Node2);
     449    Add(NewCell);
     450    Node2 := Node2.NextSibling;
     451  end;
     452end;
     453
     454procedure TCells.SaveToNode(Node: TDOMNode);
     455var
     456  I: Integer;
     457  NewNode2: TDOMNode;
     458begin
     459  for I := 0 to Count - 1 do
     460  with TCell(Items[I]) do begin
     461    NewNode2 := Node.OwnerDocument.CreateElement('Cell');
     462    Node.AppendChild(NewNode2);
     463    SaveToNode(NewNode2);
     464  end;
     465end;
    410466
    411467{ TPlayers }
    412468
     469procedure TPlayers.New(Name: string; Color: TColor; Mode: TPlayerMode);
     470var
     471  NewPlayer: TPlayer;
     472begin
     473  NewPlayer := TPlayer.Create;
     474  NewPlayer.Game := Game;
     475  NewPlayer.Name := Name;
     476  NewPlayer.Color := Color;
     477  NewPlayer.Mode := Mode;
     478  NewPlayer.Id := GetNewPlayerId;
     479  Add(NewPlayer);
     480end;
     481
     482function TPlayers.GetNewPlayerId: Integer;
     483begin
     484  Result := NewPlayerId;
     485  Inc(NewPlayerId);
     486end;
     487
    413488procedure TPlayers.LoadFromNode(Node: TDOMNode);
    414 begin
    415 
     489var
     490  Node2: TDOMNode;
     491  NewPlayer: TPlayer;
     492begin
     493  Count := 0;
     494  Node2 := Node.FirstChild;
     495  while Assigned(Node2) and (Node2.NodeName = 'Player') do begin
     496    NewPlayer := TPlayer.Create;
     497    NewPlayer.Game := Game;
     498    NewPlayer.LoadFromNode(Node2);
     499    Add(NewPlayer);
     500    Node2 := Node2.NextSibling;
     501  end;
    416502end;
    417503
     
    428514end;
    429515
     516constructor TPlayers.Create;
     517begin
     518  inherited Create;
     519  NewPlayerId := 1;
     520end;
     521
    430522{ TUnitMoves }
    431523
    432524procedure TUnitMoves.LoadFromNode(Node: TDOMNode);
    433 begin
    434 
     525var
     526  Node2: TDOMNode;
     527  NewUnitMove: TUnitMove;
     528begin
     529  Count := 0;
     530  Node2 := Node.FirstChild;
     531  while Assigned(Node2) and (Node2.NodeName = 'UnitMove') do begin
     532    NewUnitMove := TUnitMove.Create;
     533    NewUnitMove.List := Self;
     534    NewUnitMove.LoadFromNode(Node2);
     535    Add(NewUnitMove);
     536    Node2 := Node2.NextSibling;
     537  end;
    435538end;
    436539
     
    463566  Pos: TPoint;
    464567begin
    465   inherited;
    466568  // Free previous
    467569  Cells.Count := 0;
     570  FNewCellId := 1;
    468571  // Allocate and init new
    469572  Cells.Count := FSize.Y * FSize.X;
     
    474577    SetLength(NewCell.Polygon, 1);
    475578    NewCell.Polygon[0] := NewCell.PosPx;
     579    NewCell.Id := GetNewCellId;
    476580    Cells[Y * FSize.X + X] := NewCell;
    477581  end;
     
    506610  NewCell: TCell;
    507611begin
    508   inherited;
    509612  // Free previous
    510613  Cells.Count := 0;
     614  FNewCellId := 1;
    511615  // Allocate and init new
    512616  Cells.Count := FSize.Y * FSize.X;
     
    520624      Trunc((Y * DefaultCellSize.Y * TriangleCellMulY) - (0.1 * Rev * DefaultCellSize.Y)));
    521625    NewCell.Polygon := GetTrianglePolygon(NewCell.PosPx, DefaultCellSize, Reverse);
     626    NewCell.Id := GetNewCellId;
    522627    Cells[Y * FSize.X + X] := NewCell;
    523628  end;
     
    545650  NewCell: TCell;
    546651begin
    547   inherited;
    548652  // Free previous
    549653  Cells.Count := 0;
     654  FNewCellId := 1;
    550655  // Allocate and init new
    551656  Cells.Count := FSize.Y * FSize.X;
     
    556661      Trunc(Y * DefaultCellSize.Y * SquareCellMulY));
    557662    NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize);
     663    NewCell.Id := GetNewCellId;
    558664    Cells[Y * FSize.X + X] := NewCell;
    559665  end;
     666
    560667  // Generate neighbours
    561668  for Y := 0 to FSize.Y - 1 do
     
    601708    Generate;
    602709  end;
     710end;
     711
     712function TMap.GetNewCellId: Integer;
     713begin
     714  Result := FNewCellId;
     715  Inc(FNewCellId);
    603716end;
    604717
     
    708821
    709822procedure TMap.LoadFromNode(Node: TDOMNode);
    710 begin
     823var
     824  Node2: TDOMNode;
     825begin
     826  Size := Point(ReadInteger(Node, 'SizeX', 0), ReadInteger(Node, 'SizeY', 0));
    711827  DefaultCellSize.X := ReadInteger(Node, 'DefaultCellSizeX', 1);
    712828  DefaultCellSize.Y := ReadInteger(Node, 'DefaultCellSizeY', 1);
    713829  MaxPower := ReadInteger(Node, 'MaxPower', 99);
    714830  Shape := TMapShape(ReadInteger(Node, 'Shape', Integer(msRectangle)));
     831  Node2 := Node.FindNode('Cells');
     832  if Assigned(Node2) then
     833    Cells.LoadFromNode(Node2);
    715834end;
    716835
     
    725844  WriteInteger(Node, 'MaxPower', MaxPower);
    726845  WriteInteger(Node, 'Shape', Integer(Shape));
     846  WriteInteger(Node, 'SizeX', Size.X);
     847  WriteInteger(Node, 'SizeY', Size.Y);
    727848  NewNode := Node.OwnerDocument.CreateElement('Cells');
    728849  Node.AppendChild(NewNode);
    729   for I := 0 to Cells.Count - 1 do
    730   with TCell(Cells[I]) do begin
    731     NewNode2 := Node.OwnerDocument.CreateElement('Cell');
    732     NewNode.AppendChild(NewNode2);
    733     WriteInteger(NewNode2, 'Id', I);
    734     WriteInteger(NewNode2, 'Power', Power);
    735     WriteInteger(NewNode2, 'Terrain', Integer(Terrain));
    736     WriteInteger(NewNode2, 'PosX', PosPx.X);
    737     WriteInteger(NewNode2, 'PosY', PosPx.Y);
    738   end;
     850  Cells.SaveToNode(NewNode);
    739851end;
    740852
     
    840952  NeighCells: TCellArray;
    841953begin
    842   inherited;
    843954  // Free previous
    844955  Cells.Count := 0;
    845956  // Allocate and init new
    846957  Cells.Count := FSize.Y * FSize.X;
     958  FNewCellId := 1;
    847959  for Y := 0 to FSize.Y - 1 do
    848960  for X := 0 to FSize.X - 1 do begin
    849961    NewCell := TCell.Create;
    850962    NewCell.PosPx := Point(X, Y);
     963    NewCell.Id := GetNewCellId;
    851964    Cells[Y * FSize.X + X] := NewCell;
    852965  end;
     
    857970  MaxPower := 99;
    858971  DefaultCellSize := Point(220, 220);
    859   Cells := TObjectList.create;
     972  Cells := TCells.create;
    860973  Size := Point(0, 0);
    861974  Image := TImage.Create(nil);
     
    9421055  CountOnce := ReadInteger(Node, 'CountOnce', 0);
    9431056  CountRepeat := ReadInteger(Node, 'CountRepeat', 0);
    944   //CellFrom := ReadInteger(Node, 'CellFrom', 0);
    945   //CellTo := ReadInteger(Node, 'CellTo', 0);
     1057  CellFrom := List.Game.Map.Cells.FindById(ReadInteger(Node, 'CellFrom', 0));
     1058  CellTo := List.Game.Map.Cells.FindById(ReadInteger(Node, 'CellTo', 0));
    9461059end;
    9471060
     
    9561069constructor TUnitMove.Create;
    9571070begin
     1071  List := nil; // Is later set to parent list owning item
    9581072  FCellFrom := nil;
    9591073  FCellTo := nil;
     
    10311145end;
    10321146
     1147procedure TCell.LoadFromNode(Node: TDOMNode);
     1148var
     1149  Node2: TDOMNode;
     1150  Node3: TDOMNode;
     1151  NewCell: TCell;
     1152begin
     1153  Id := ReadInteger(Node, 'Id', 0);
     1154  Power := ReadInteger(Node, 'Power', 0);
     1155  Terrain := TTerrainType(ReadInteger(Node, 'Terrain', Integer(ttVoid)));
     1156  PosPx.X := ReadInteger(Node, 'PosX', 0);
     1157  PosPx.Y := ReadInteger(Node, 'PosY', 0);
     1158  //Player := Map.Game.Players.FindById(ReadInteger(Node, 'Player', 0));
     1159
     1160  Node3 := Node.FindNode('Polygon');
     1161  if Assigned(Node3) then begin
     1162    SetLength(Polygon, 0);
     1163    Node2 := Node3.FirstChild;
     1164    while Assigned(Node2) and (Node2.NodeName = 'Point') do begin
     1165      SetLength(Polygon, Length(Polygon) + 1);
     1166      Polygon[High(Polygon)].X := ReadInteger(Node2, 'X', 0);
     1167      Polygon[High(Polygon)].Y := ReadInteger(Node2, 'Y', 0);
     1168      Node2 := Node2.NextSibling;
     1169    end;
     1170  end;
     1171end;
     1172
     1173procedure TCell.SaveToNode(Node: TDOMNode);
     1174var
     1175  NewNode: TDOMNode;
     1176  NewNode2: TDOMNode;
     1177  I: Integer;
     1178begin
     1179  WriteInteger(Node, 'Id', Id);
     1180  WriteInteger(Node, 'Power', Power);
     1181  WriteInteger(Node, 'Terrain', Integer(Terrain));
     1182  WriteInteger(Node, 'PosX', PosPx.X);
     1183  WriteInteger(Node, 'PosY', PosPx.Y);
     1184  if Assigned(Player) then
     1185    WriteInteger(Node, 'Player', Player.Id)
     1186    else WriteInteger(Node, 'Player', 0);
     1187  NewNode := Node.OwnerDocument.CreateElement('Neighbours');
     1188  Node.AppendChild(NewNode);
     1189  for I := 0 to Neighbors.Count - 1 do begin
     1190    NewNode2 := NewNode.OwnerDocument.CreateElement('Neighbour');
     1191    NewNode.AppendChild(NewNode2);
     1192    WriteInteger(NewNode2, 'Id', TCell(Neighbors[I]).Id);
     1193  end;
     1194  NewNode := Node.OwnerDocument.CreateElement('Polygon');
     1195  Node.AppendChild(NewNode);
     1196  for I := 0 to Length(Polygon) - 1 do begin
     1197    NewNode2 := NewNode.OwnerDocument.CreateElement('Point');
     1198    NewNode.AppendChild(NewNode2);
     1199    WriteInteger(NewNode2, 'X', Polygon[I].X);
     1200    WriteInteger(NewNode2, 'Y', Polygon[I].Y);
     1201  end;
     1202end;
     1203
    10331204procedure TCell.Assign(Source: TCell);
    10341205begin
     1206  Id := Source.Id;
    10351207  PosPx := Source.PosPx;
    10361208  Terrain := Source.Terrain;
     
    10771249begin
    10781250  Player := nil;
    1079   Neighbors := TObjectList.Create;
     1251  Neighbors := TCells.Create;
    10801252  Neighbors.OwnsObjects := False;
    10811253  MovesFrom := TUnitMoves.Create;
     
    11471319  Color := ReadInteger(Node, 'Color', clSilver);
    11481320  Mode := TPlayerMode(ReadInteger(Node, 'Mode', Integer(pmHuman)));
     1321  StartCell := FGame.Map.Cells.FindById(ReadInteger(Node, 'StartCell', 0));
     1322  StartUnits := ReadInteger(Node, 'StartUnits', 0);
    11491323end;
    11501324
     
    11551329  WriteInteger(Node, 'Color', Color);
    11561330  WriteInteger(Node, 'Mode', Integer(Mode));
     1331  WriteInteger(Node, 'StartCell', StartCell.Id);
     1332  WriteInteger(Node, 'StartUnits', StartUnits);
    11571333end;
    11581334
     
    11731349procedure TComputer.AttackNeutral;
    11741350var
    1175   AllCells: TObjectList;
     1351  AllCells: TCells;
    11761352  Cells, Cells2: TCellArray;
    11771353  TotalPower: Integer;
     
    12381414procedure TComputer.AttackPlayers;
    12391415var
    1240   AllCells: TObjectList;
     1416  AllCells: TCells;
    12411417  Cells, Cells2: TCellArray;
    12421418  TotalPower: Integer;
     
    13031479procedure TComputer.InnerMoves;
    13041480var
    1305   AllCells: TObjectList;
     1481  AllCells: TCells;
    13061482  Cells, Cells2: TCellArray;
    13071483  I, J: Integer;
     
    14471623procedure TPlayer.Assign(Source: TPlayer);
    14481624begin
     1625  Id := Source.Id;
    14491626  Name := Source.Name;
    14501627  Color := Source.Color;
     
    17941971      if Assigned(NewNode) then
    17951972        Players.LoadFromNode(NewNode);
     1973      if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
     1974        else CurrentPlayer := nil;
    17961975
    17971976      NewNode := FindNode('UnitMoves');
     
    18362015      NewNode := OwnerDocument.CreateElement('Players');
    18372016      AppendChild(NewNode);
    1838       for I := 0 to Players.Count - 1 do begin;
    1839         NewNode2 := OwnerDocument.CreateElement('Player');
    1840         NewNode.AppendChild(NewNode2);
    1841         TPlayer(Players[I]).SaveToNode(NewNode2);
    1842       end;
     2017      Players.SaveToNode(NewNode);
    18432018
    18442019      NewNode := OwnerDocument.CreateElement('UnitMoves');
     
    19412116
    19422117constructor TGame.Create;
    1943 var
    1944   Player: TPlayer;
    19452118begin
    19462119  Moves := TUnitMoves.Create;
     2120  Moves.Game := Self;
    19472121  Map := TMap.Create;
    19482122  Players := TPlayers.Create;
     2123  Players.Game := Self;
    19492124
    19502125  MapImageFileName := 'Images/Maps/WorldMap.png';
    1951 
    19522126  Randomize;
    19532127
    1954   Player := TPlayer.Create;
    1955   Player.Name := SPlayer + ' 1';
    1956   Player.Game := Self;
    1957   Player.Color := clBlue;
    1958   Players.Add(Player);
    1959   Player := TPlayer.Create;
    1960   Player.Name := SPlayer + ' 2';
    1961   Player.Game := Self;
    1962   Player.Color := clRed;
    1963   Player.Mode := pmComputer;
    1964   Players.Add(Player);
     2128  Players.New(SPlayer + ' 1', clBlue, pmHuman);
     2129  Players.New(SPlayer + ' 2', clRed, pmComputer);
    19652130
    19662131  VoidEnabled := True;
     
    20422207    View.CenterMap;
    20432208  end;
    2044   CurrentPlayer := TPlayer(Players[0]);
     2209  if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
     2210    else CurrentPlayer := nil;
    20452211end;
    20462212
     
    21232289end;
    21242290
    2125 function THexMap.GetCellPosNeighbors(CellPos: TPoint): TCellArray;
     2291procedure THexMap.GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells);
    21262292var
    21272293  X, Y: Integer;
    21282294begin
    2129   SetLength(Result, 0);
     2295  Neighbours.Count := 0;
    21302296  for Y := -1 to 1 do
    21312297  for X := -1 to 1 do
    21322298  if IsValidIndex(Point(CellPos.X + X, CellPos.Y + Y)) and
    21332299  IsCellsPosNeighbor(CellPos, Point((CellPos.X + X), (CellPos.Y + Y))) then begin
    2134     SetLength(Result, Length(Result) + 1);
    2135     Result[Length(Result) - 1] := TCell(Cells[(CellPos.Y + Y) * FSize.X + (CellPos.X + X)]);
     2300    Neighbours.Add(TCell(Cells[(CellPos.Y + Y) * FSize.X + (CellPos.X + X)]));
    21362301  end;
    21372302end;
     
    21892354  I: Integer;
    21902355  NewCell: TCell;
    2191   NeighCells: TCellArray;
    21922356  PX, PY: Double;
    21932357begin
    2194   inherited;
    21952358  // Free previous
    21962359  Cells.Count := 0;
     2360  FNewCellId := 1;
    21972361  // Allocate and init new
    21982362  Cells.Count := FSize.Y * FSize.X;
     
    22092373      Trunc(PY * DefaultCellSize.Y / HexCellMulY));
    22102374    NewCell.Polygon := GetHexagonPolygon(NewCell.PosPx, DefaultCellSize);
     2375    NewCell.Id := GetNewCellId;
    22112376    Cells[Y * FSize.X + X] := NewCell;
    22122377  end;
     
    22162381  for X := 0 to FSize.X - 1 do
    22172382  with TCell(Cells[Y * FSize.X + X]) do begin
    2218     NeighCells := GetCellPosNeighbors(Point(X, Y));
    2219     Neighbors.Count := Length(NeighCells);
    2220     for I := 0 to Length(NeighCells) - 1 do
    2221       Neighbors[I] := NeighCells[I];
     2383    GetCellPosNeighbors(Point(X, Y), Neighbors);
    22222384  end;
    22232385end;
    22242386
    22252387end.
    2226 
Note: See TracChangeset for help on using the changeset viewer.