- Timestamp:
- Oct 5, 2014, 1:34:43 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r74 r76 91 91 Style = tbsSeparator 92 92 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 93 114 end 94 115 object PaintBox1: TPaintBox -
trunk/Forms/UFormMain.pas
r73 r76 53 53 ToolBar1: TToolBar; 54 54 ToolButton1: TToolButton; 55 ToolButton10: TToolButton; 56 ToolButton11: TToolButton; 57 ToolButton12: TToolButton; 58 ToolButton13: TToolButton; 55 59 ToolButton2: TToolButton; 56 60 ToolButton3: TToolButton; -
trunk/Forms/UFormNew.pas
r75 r76 228 228 ListView1.Items.Count := Players.Count; 229 229 ListView1.Refresh; 230 ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected) ;230 ButtonPlayerRemove.Enabled := Assigned(ListView1.Selected) and (Players.Count > 1); 231 231 ButtonPlayerAdd.Enabled := Players.Count < MaxPlayerCount; 232 232 APlayerModify.Enabled := Assigned(ListView1.Selected); … … 306 306 if Players.Count <= (MaxPlayerCount - 1) then begin 307 307 NewPlayer := TPlayer.Create; 308 NewPlayer.Name := 'Player ' + IntToStr(Players.Count + 1); 308 NewPlayer.Id := Players.GetNewPlayerId; 309 NewPlayer.Name := SPlayer + ' ' + IntToStr(NewPlayer.Id); 309 310 NewPlayer.Color := PlayerColors[Players.Count]; 310 311 NewPlayer.Mode := pmComputer; … … 335 336 TPlayer(Players[I]).Assign(TPlayer(Game.Players[I])); 336 337 end; 338 Players.NewPlayerId := Game.Players.NewPlayerId; 339 337 340 CheckBoxCity.Checked := Game.CityEnabled; 338 341 SpinEditCityPercent.Value := Game.CityPercentage; … … 362 365 TPlayer(Game.Players[I]).Game := Game; 363 366 end; 367 Game.Players.NewPlayerId := Players.NewPlayerId; 364 368 Game.SymetricMap := CheckBoxSymetricMap.Checked; 365 369 Game.VoidEnabled := CheckBoxVoid.Checked; -
trunk/Languages/xtactics.cs.po
r75 r76 195 195 196 196 #: tformnew.aplayeradd.caption 197 #, fuzzy198 197 #| msgid "Add player" 199 198 msgid "Add" 200 msgstr "Přidat hráče"199 msgstr "Přidat" 201 200 202 201 #: tformnew.aplayermodify.caption … … 205 204 206 205 #: tformnew.aplayerremove.caption 207 #, fuzzy208 206 #| msgid "Remove player" 209 207 msgid "Remove" 210 msgstr "Odstranit hráče"208 msgstr "Odstranit" 211 209 212 210 #: tformnew.buttoncancel.caption … … 218 216 msgctxt "tformnew.buttonimagebrowse.caption" 219 217 msgid "Browse" 220 msgstr " "218 msgstr "Vybrat" 221 219 222 220 #: tformnew.buttonok.caption … … 280 278 #: tformnew.label8.caption 281 279 msgid "Map shape:" 282 msgstr " "280 msgstr "Tvar mapy" 283 281 284 282 #: tformnew.label9.caption 285 283 msgid "Image file:" 286 msgstr " "284 msgstr "Soubor obrázku:" 287 285 288 286 #: tformnew.listview1.columns[0].caption … … 312 310 #: tformnew.tabsheet1.caption 313 311 msgid "Players" 314 msgstr " "312 msgstr "Hráči" 315 313 316 314 #: tformnew.tabsheet2.caption 317 315 msgid "Map" 318 msgstr " "316 msgstr "Mapa" 319 317 320 318 #: tformnew.tabsheet3.caption 321 319 msgid "Rules" 322 msgstr " "320 msgstr "Pravidla" 323 321 324 322 #: tformplayer.buttoncancel.caption … … 437 435 #: uformnew.sfromimagefile 438 436 msgid "From image file" 439 msgstr " "437 msgstr "Obrázek ze souboru" 440 438 441 439 #: uformnew.sgridtypehexagon … … 477 475 #: uformnew.srectangular 478 476 msgid "Rectangular" 479 msgstr " "477 msgstr "Obdelníkový" 480 478 481 479 #: uformnew.swinobjectivecaptureposition … … 525 523 #: ugame.snewgamefile 526 524 msgid "New game.xtg" 527 msgstr "Nová hr y.xtg"525 msgstr "Nová hra.xtg" 528 526 529 527 #: ugame.splayer … … 539 537 msgid "Wrong file format" 540 538 msgstr "Chybný formát souboru" 541 -
trunk/UCore.pas
r74 r76 187 187 Game.LoadFromFile(OpenDialog1.FileName); 188 188 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; 189 192 FormMain.Redraw; 190 193 end; -
trunk/UGame.pas
r75 r76 24 24 TView = class; 25 25 TUnitMoves = class; 26 TCells = class; 26 27 27 28 TFloatPoint = record … … 47 48 MovesFrom: TUnitMoves; 48 49 MovesTo: TUnitMoves; 49 Neighbors: T ObjectList; // TList<TCell>50 Neighbors: TCells; 50 51 Mark: Boolean; 52 procedure LoadFromNode(Node: TDOMNode); 53 procedure SaveToNode(Node: TDOMNode); 51 54 procedure Assign(Source: TCell); 52 55 function IsVisible(View: TView): Boolean; … … 60 63 61 64 TCellArray = array of TCell; 65 66 { TCells } 67 62 68 TCells = class(TObjectList) 63 69 function FindById(Id: Integer): TCell; 70 procedure LoadFromNode(Node: TDOMNode); 71 procedure SaveToNode(Node: TDOMNode); 64 72 end; 65 73 … … 98 106 private 99 107 FSize: TPoint; 108 FNewCellId: Integer; 100 109 function GetSize: TPoint; virtual; 101 110 procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView; … … 104 113 Text: string); 105 114 procedure SetSize(AValue: TPoint); virtual; 115 function GetNewCellId: Integer; virtual; 106 116 public 107 117 Game: TGame; 108 118 MaxPower: Integer; 109 119 DefaultCellSize: TPoint; 110 Cells: T ObjectList; // TList<TCell>120 Cells: TCells; 111 121 Shape: TMapShape; 112 122 Image: TImage; … … 139 149 private 140 150 function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean; 141 function GetCellPosNeighbors(CellPos: TPoint): TCellArray;151 procedure GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells); 142 152 function GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPointArray; 143 153 public … … 223 233 224 234 TPlayers = class(TObjectList) 235 Game: TGame; 236 NewPlayerId: Integer; 237 procedure New(Name: string; Color: TColor; Mode: TPlayerMode); 238 function GetNewPlayerId: Integer; 225 239 procedure LoadFromNode(Node: TDOMNode); 226 240 procedure SaveToNode(Node: TDOMNode); 241 constructor Create; 227 242 end; 228 243 … … 236 251 procedure SetCellTo(AValue: TCell); 237 252 public 238 List: T ObjectList; // TList<TUnitMove>253 List: TUnitMoves; 239 254 CountOnce: Integer; 240 255 CountRepeat: Integer; … … 250 265 251 266 TUnitMoves = class(TObjectList) 267 Game: TGame; 252 268 procedure LoadFromNode(Node: TDOMNode); 253 269 procedure SaveToNode(Node: TDOMNode); … … 331 347 function FloatPoint(AX, AY: Double): TFloatPoint; 332 348 349 resourcestring 350 SPlayer = 'Player'; 351 333 352 334 353 implementation … … 336 355 resourcestring 337 356 SMinimumPlayers = 'You need at least two players'; 338 SPlayer = 'Player';339 357 SHuman = 'Human'; 340 358 SComputer = 'Computer'; … … 407 425 end; 408 426 409 { TComputer } 427 { TCells } 428 429 function TCells.FindById(Id: Integer): TCell; 430 var 431 I: Integer; 432 begin 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; 437 end; 438 439 procedure TCells.LoadFromNode(Node: TDOMNode); 440 var 441 Node2: TDOMNode; 442 NewCell: TCell; 443 begin 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; 452 end; 453 454 procedure TCells.SaveToNode(Node: TDOMNode); 455 var 456 I: Integer; 457 NewNode2: TDOMNode; 458 begin 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; 465 end; 410 466 411 467 { TPlayers } 412 468 469 procedure TPlayers.New(Name: string; Color: TColor; Mode: TPlayerMode); 470 var 471 NewPlayer: TPlayer; 472 begin 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); 480 end; 481 482 function TPlayers.GetNewPlayerId: Integer; 483 begin 484 Result := NewPlayerId; 485 Inc(NewPlayerId); 486 end; 487 413 488 procedure TPlayers.LoadFromNode(Node: TDOMNode); 414 begin 415 489 var 490 Node2: TDOMNode; 491 NewPlayer: TPlayer; 492 begin 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; 416 502 end; 417 503 … … 428 514 end; 429 515 516 constructor TPlayers.Create; 517 begin 518 inherited Create; 519 NewPlayerId := 1; 520 end; 521 430 522 { TUnitMoves } 431 523 432 524 procedure TUnitMoves.LoadFromNode(Node: TDOMNode); 433 begin 434 525 var 526 Node2: TDOMNode; 527 NewUnitMove: TUnitMove; 528 begin 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; 435 538 end; 436 539 … … 463 566 Pos: TPoint; 464 567 begin 465 inherited;466 568 // Free previous 467 569 Cells.Count := 0; 570 FNewCellId := 1; 468 571 // Allocate and init new 469 572 Cells.Count := FSize.Y * FSize.X; … … 474 577 SetLength(NewCell.Polygon, 1); 475 578 NewCell.Polygon[0] := NewCell.PosPx; 579 NewCell.Id := GetNewCellId; 476 580 Cells[Y * FSize.X + X] := NewCell; 477 581 end; … … 506 610 NewCell: TCell; 507 611 begin 508 inherited;509 612 // Free previous 510 613 Cells.Count := 0; 614 FNewCellId := 1; 511 615 // Allocate and init new 512 616 Cells.Count := FSize.Y * FSize.X; … … 520 624 Trunc((Y * DefaultCellSize.Y * TriangleCellMulY) - (0.1 * Rev * DefaultCellSize.Y))); 521 625 NewCell.Polygon := GetTrianglePolygon(NewCell.PosPx, DefaultCellSize, Reverse); 626 NewCell.Id := GetNewCellId; 522 627 Cells[Y * FSize.X + X] := NewCell; 523 628 end; … … 545 650 NewCell: TCell; 546 651 begin 547 inherited;548 652 // Free previous 549 653 Cells.Count := 0; 654 FNewCellId := 1; 550 655 // Allocate and init new 551 656 Cells.Count := FSize.Y * FSize.X; … … 556 661 Trunc(Y * DefaultCellSize.Y * SquareCellMulY)); 557 662 NewCell.Polygon := GetSquarePolygon(NewCell.PosPx, DefaultCellSize); 663 NewCell.Id := GetNewCellId; 558 664 Cells[Y * FSize.X + X] := NewCell; 559 665 end; 666 560 667 // Generate neighbours 561 668 for Y := 0 to FSize.Y - 1 do … … 601 708 Generate; 602 709 end; 710 end; 711 712 function TMap.GetNewCellId: Integer; 713 begin 714 Result := FNewCellId; 715 Inc(FNewCellId); 603 716 end; 604 717 … … 708 821 709 822 procedure TMap.LoadFromNode(Node: TDOMNode); 710 begin 823 var 824 Node2: TDOMNode; 825 begin 826 Size := Point(ReadInteger(Node, 'SizeX', 0), ReadInteger(Node, 'SizeY', 0)); 711 827 DefaultCellSize.X := ReadInteger(Node, 'DefaultCellSizeX', 1); 712 828 DefaultCellSize.Y := ReadInteger(Node, 'DefaultCellSizeY', 1); 713 829 MaxPower := ReadInteger(Node, 'MaxPower', 99); 714 830 Shape := TMapShape(ReadInteger(Node, 'Shape', Integer(msRectangle))); 831 Node2 := Node.FindNode('Cells'); 832 if Assigned(Node2) then 833 Cells.LoadFromNode(Node2); 715 834 end; 716 835 … … 725 844 WriteInteger(Node, 'MaxPower', MaxPower); 726 845 WriteInteger(Node, 'Shape', Integer(Shape)); 846 WriteInteger(Node, 'SizeX', Size.X); 847 WriteInteger(Node, 'SizeY', Size.Y); 727 848 NewNode := Node.OwnerDocument.CreateElement('Cells'); 728 849 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); 739 851 end; 740 852 … … 840 952 NeighCells: TCellArray; 841 953 begin 842 inherited;843 954 // Free previous 844 955 Cells.Count := 0; 845 956 // Allocate and init new 846 957 Cells.Count := FSize.Y * FSize.X; 958 FNewCellId := 1; 847 959 for Y := 0 to FSize.Y - 1 do 848 960 for X := 0 to FSize.X - 1 do begin 849 961 NewCell := TCell.Create; 850 962 NewCell.PosPx := Point(X, Y); 963 NewCell.Id := GetNewCellId; 851 964 Cells[Y * FSize.X + X] := NewCell; 852 965 end; … … 857 970 MaxPower := 99; 858 971 DefaultCellSize := Point(220, 220); 859 Cells := T ObjectList.create;972 Cells := TCells.create; 860 973 Size := Point(0, 0); 861 974 Image := TImage.Create(nil); … … 942 1055 CountOnce := ReadInteger(Node, 'CountOnce', 0); 943 1056 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)); 946 1059 end; 947 1060 … … 956 1069 constructor TUnitMove.Create; 957 1070 begin 1071 List := nil; // Is later set to parent list owning item 958 1072 FCellFrom := nil; 959 1073 FCellTo := nil; … … 1031 1145 end; 1032 1146 1147 procedure TCell.LoadFromNode(Node: TDOMNode); 1148 var 1149 Node2: TDOMNode; 1150 Node3: TDOMNode; 1151 NewCell: TCell; 1152 begin 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; 1171 end; 1172 1173 procedure TCell.SaveToNode(Node: TDOMNode); 1174 var 1175 NewNode: TDOMNode; 1176 NewNode2: TDOMNode; 1177 I: Integer; 1178 begin 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; 1202 end; 1203 1033 1204 procedure TCell.Assign(Source: TCell); 1034 1205 begin 1206 Id := Source.Id; 1035 1207 PosPx := Source.PosPx; 1036 1208 Terrain := Source.Terrain; … … 1077 1249 begin 1078 1250 Player := nil; 1079 Neighbors := T ObjectList.Create;1251 Neighbors := TCells.Create; 1080 1252 Neighbors.OwnsObjects := False; 1081 1253 MovesFrom := TUnitMoves.Create; … … 1147 1319 Color := ReadInteger(Node, 'Color', clSilver); 1148 1320 Mode := TPlayerMode(ReadInteger(Node, 'Mode', Integer(pmHuman))); 1321 StartCell := FGame.Map.Cells.FindById(ReadInteger(Node, 'StartCell', 0)); 1322 StartUnits := ReadInteger(Node, 'StartUnits', 0); 1149 1323 end; 1150 1324 … … 1155 1329 WriteInteger(Node, 'Color', Color); 1156 1330 WriteInteger(Node, 'Mode', Integer(Mode)); 1331 WriteInteger(Node, 'StartCell', StartCell.Id); 1332 WriteInteger(Node, 'StartUnits', StartUnits); 1157 1333 end; 1158 1334 … … 1173 1349 procedure TComputer.AttackNeutral; 1174 1350 var 1175 AllCells: T ObjectList;1351 AllCells: TCells; 1176 1352 Cells, Cells2: TCellArray; 1177 1353 TotalPower: Integer; … … 1238 1414 procedure TComputer.AttackPlayers; 1239 1415 var 1240 AllCells: T ObjectList;1416 AllCells: TCells; 1241 1417 Cells, Cells2: TCellArray; 1242 1418 TotalPower: Integer; … … 1303 1479 procedure TComputer.InnerMoves; 1304 1480 var 1305 AllCells: T ObjectList;1481 AllCells: TCells; 1306 1482 Cells, Cells2: TCellArray; 1307 1483 I, J: Integer; … … 1447 1623 procedure TPlayer.Assign(Source: TPlayer); 1448 1624 begin 1625 Id := Source.Id; 1449 1626 Name := Source.Name; 1450 1627 Color := Source.Color; … … 1794 1971 if Assigned(NewNode) then 1795 1972 Players.LoadFromNode(NewNode); 1973 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0]) 1974 else CurrentPlayer := nil; 1796 1975 1797 1976 NewNode := FindNode('UnitMoves'); … … 1836 2015 NewNode := OwnerDocument.CreateElement('Players'); 1837 2016 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); 1843 2018 1844 2019 NewNode := OwnerDocument.CreateElement('UnitMoves'); … … 1941 2116 1942 2117 constructor TGame.Create; 1943 var1944 Player: TPlayer;1945 2118 begin 1946 2119 Moves := TUnitMoves.Create; 2120 Moves.Game := Self; 1947 2121 Map := TMap.Create; 1948 2122 Players := TPlayers.Create; 2123 Players.Game := Self; 1949 2124 1950 2125 MapImageFileName := 'Images/Maps/WorldMap.png'; 1951 1952 2126 Randomize; 1953 2127 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); 1965 2130 1966 2131 VoidEnabled := True; … … 2042 2207 View.CenterMap; 2043 2208 end; 2044 CurrentPlayer := TPlayer(Players[0]); 2209 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0]) 2210 else CurrentPlayer := nil; 2045 2211 end; 2046 2212 … … 2123 2289 end; 2124 2290 2125 function THexMap.GetCellPosNeighbors(CellPos: TPoint): TCellArray;2291 procedure THexMap.GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells); 2126 2292 var 2127 2293 X, Y: Integer; 2128 2294 begin 2129 SetLength(Result, 0);2295 Neighbours.Count := 0; 2130 2296 for Y := -1 to 1 do 2131 2297 for X := -1 to 1 do 2132 2298 if IsValidIndex(Point(CellPos.X + X, CellPos.Y + Y)) and 2133 2299 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)])); 2136 2301 end; 2137 2302 end; … … 2189 2354 I: Integer; 2190 2355 NewCell: TCell; 2191 NeighCells: TCellArray;2192 2356 PX, PY: Double; 2193 2357 begin 2194 inherited;2195 2358 // Free previous 2196 2359 Cells.Count := 0; 2360 FNewCellId := 1; 2197 2361 // Allocate and init new 2198 2362 Cells.Count := FSize.Y * FSize.X; … … 2209 2373 Trunc(PY * DefaultCellSize.Y / HexCellMulY)); 2210 2374 NewCell.Polygon := GetHexagonPolygon(NewCell.PosPx, DefaultCellSize); 2375 NewCell.Id := GetNewCellId; 2211 2376 Cells[Y * FSize.X + X] := NewCell; 2212 2377 end; … … 2216 2381 for X := 0 to FSize.X - 1 do 2217 2382 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); 2222 2384 end; 2223 2385 end; 2224 2386 2225 2387 end. 2226
Note:
See TracChangeset
for help on using the changeset viewer.