- Timestamp:
- May 14, 2018, 5:02:00 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormNew.pas
r184 r193 125 125 SGridTypeTriangle = 'Triangonal'; 126 126 SGridTypeVoronoi = 'Voronoi random'; 127 SGridTypeIsometric = 'Isometric'; 127 128 SWinObjectiveDefeatAllOponents = 'Defeat all oponents'; 128 129 SWinObjectiveDefeatAllCities = 'Defeat all oponents cities'; … … 143 144 begin 144 145 if (Item.Index >= 0) and (Item.Index < Players.Count) then 145 with TPlayer(Players[Item.Index])do begin146 with Players[Item.Index] do begin 146 147 Item.Caption := Name; 147 148 Item.Data := Players[Item.Index]; … … 211 212 Items.Add(SGridTypeTriangle); 212 213 Items.Add(SGridTypeVoronoi); 214 Items.Add(SGridTypeIsometric); 213 215 ItemIndex := LastIndex; 214 216 end; -
trunk/Languages/xtactics.cs.po
r190 r193 9 9 "MIME-Version: 1.0\n" 10 10 "Content-Transfer-Encoding: 8bit\n" 11 "X-Generator: Poedit 2.0.4\n"11 "X-Generator: Poedit 1.8.8\n" 12 12 "Language: cs\n" 13 13 … … 730 730 msgstr "Hexagonální" 731 731 732 #: uformnew.sgridtypeisometric 733 msgid "Isometric" 734 msgstr "Izometrický" 735 732 736 #: uformnew.sgridtypesquare 733 737 msgid "Square" -
trunk/Languages/xtactics.po
r185 r193 709 709 msgstr "" 710 710 711 #: uformnew.sgridtypeisometric 712 msgid "Isometric" 713 msgstr "" 714 711 715 #: uformnew.sgridtypesquare 712 716 msgid "Square" -
trunk/UCore.lfm
r192 r193 3 3 OnDestroy = DataModuleDestroy 4 4 OldCreateOrder = False 5 Height = 8116 HorizontalOffset = 4387 VerticalOffset = 3418 Width = 1 2589 PPI = 1 445 Height = 676 6 HorizontalOffset = 365 7 VerticalOffset = 284 8 Width = 1048 9 PPI = 120 10 10 object ActionList1: TActionList 11 11 Images = ImageListSmall 12 left = 1 3613 top = 6012 left = 113 13 top = 50 14 14 object AExit: TAction 15 15 Caption = 'Exit' … … 93 93 end 94 94 object ImageListSmall: TImageList 95 left = 78696 top = 42095 left = 655 96 top = 350 97 97 Bitmap = { 98 98 4C690C00000010000000100000000000000000000000E3AA4BD6E5B35EFFE3B1 … … 486 486 POFilesFolder = 'Languages' 487 487 OnTranslate = CoolTranslator1Translate 488 left = 1 37489 top = 436488 left = 114 489 top = 363 490 490 end 491 491 object ImageListLarge: TImageList 492 492 Height = 32 493 493 Width = 32 494 left = 786495 top = 2 86494 left = 655 495 top = 238 496 496 Bitmap = { 497 497 4C690C0000002000000020000000000000000000000000000000E2AA4B36E2A9 … … 2038 2038 RootName = 'CONFIG' 2039 2039 ReadOnly = False 2040 left = 1 372041 top = 5562040 left = 114 2041 top = 463 2042 2042 end 2043 2043 object OpenDialog1: TOpenDialog 2044 2044 DefaultExt = '.xtmap' 2045 left = 11262046 top = 2 922045 left = 938 2046 top = 243 2047 2047 end 2048 2048 object SaveDialog1: TSaveDialog 2049 2049 DefaultExt = '.xtmap' 2050 left = 11262051 top = 1 662050 left = 938 2051 top = 138 2052 2052 end 2053 2053 object ApplicationInfo: TApplicationInfo … … 2062 2062 AuthorsName = 'Chronos' 2063 2063 AppName = 'xTactics' 2064 ReleaseDate = 43 0582064 ReleaseDate = 43234 2065 2065 RegistryKey = '\Software\xTactics' 2066 2066 RegistryRoot = rrKeyCurrentUser 2067 2067 License = 'CC0' 2068 left = 1 372069 top = 1 802068 left = 114 2069 top = 150 2070 2070 end 2071 2071 object PersistentForm: TPersistentForm 2072 2072 MinVisiblePart = 50 2073 2073 EntireVisible = False 2074 left = 7802075 top = 6002074 left = 650 2075 top = 500 2076 2076 end 2077 2077 object ScaleDPI1: TScaleDPI 2078 2078 AutoDetect = False 2079 left = 1 362080 top = 6762079 left = 113 2080 top = 563 2081 2081 end 2082 2082 object LastOpenedList1: TLastOpenedList 2083 2083 MaxCount = 10 2084 2084 OnChange = LastOpenedList1Change 2085 left = 1 372086 top = 3002085 left = 114 2086 top = 250 2087 2087 end 2088 2088 end -
trunk/UCore.pas
r191 r193 533 533 534 534 // Update translated default player names 535 TPlayer(Game.PlayersSetting[0]).Name := SPlayer + ' 1';536 TPlayer(Game.PlayersSetting[1]).Name := SPlayer + ' 2';535 Game.PlayersSetting[0].Name := SPlayer + ' 1'; 536 Game.PlayersSetting[1].Name := SPlayer + ' 2'; 537 537 538 538 LoadConfig; -
trunk/UGame.pas
r191 r193 12 12 const 13 13 DefaultPlayerStartUnits = 5; 14 HexCellMulX = 1.12;15 HexCellMulY = 1.292;16 14 SquareCellMulX = 1.05; 17 15 SquareCellMulY = 1.05; … … 414 412 TGrowAmount = (gaByOne, gaBySquareRoot); 415 413 TGrowCells = (gcNone, gcPlayerCities, gcPlayerAll); 416 TMapType = (mtNone, mtHexagon, mtSquare, mtTriangle, mtVoronoi );414 TMapType = (mtNone, mtHexagon, mtSquare, mtTriangle, mtVoronoi, mtIsometric); 417 415 TWinObjective = (woDefeatAllOponents, woDefeatAllOponentsCities, 418 416 woSpecialCaptureCell, woStayAliveForDefinedTurns); … … 636 634 begin 637 635 for I := 0 to Cells.Count - 1 do begin 638 if TCell(Cells[I]).Neighbors.Remove(TCell(Cells[1 - I])) = -1 then636 if Cells[I].Neighbors.Remove(Cells[1 - I]) = -1 then 639 637 raise Exception.Create(SCellRemoveNeighborError); 640 if TCell(Cells[I]).Links.Remove(Self) = -1 then638 if Cells[I].Links.Remove(Self) = -1 then 641 639 raise Exception.Create(SCellRemoveNeighborError); 642 640 end; … … 756 754 begin 757 755 I := 0; 758 while (I < Count) and ( TPlayerCell(Items[I]).MapCell <> Cell) do Inc(I);759 if I < Count then Result := TPlayerCell(Items[I])756 while (I < Count) and (Items[I].MapCell <> Cell) do Inc(I); 757 if I < Count then Result := Items[I] 760 758 else Result := nil; 761 759 end; … … 785 783 NewNode := Node.OwnerDocument.CreateElement('Cell'); 786 784 Node.AppendChild(NewNode); 787 TPlayerCell(Items[I]).SaveToNode(NewNode);785 Items[I].SaveToNode(NewNode); 788 786 end; 789 787 end; … … 825 823 826 824 for I := 0 to Cells.Count - 1 do 827 with TPlayerCell(Cells[I])do begin825 with Cells[I] do begin 828 826 List := Cells; 829 827 Explored := False; 830 828 InVisibleRange := False; 831 MapCell := TCell(Player.Game.Map.Cells[I]);829 MapCell := Player.Game.Map.Cells[I]; 832 830 end; 833 831 end; … … 852 850 begin 853 851 for I := 0 to Cells.Count - 1 do 854 with TPlayerCell(Cells[I])do begin852 with Cells[I] do begin 855 853 NeighCount := 0; 856 854 for C := 0 to MapCell.Neighbors.Count - 1 do 857 if TCell(MapCell.Neighbors[C]).Player = Player then855 if MapCell.Neighbors[C].Player = Player then 858 856 Inc(NeighCount); 859 857 860 InVisibleRange := (NeighCount > 0) or ( TCell(MapCell).Player = Player);858 InVisibleRange := (NeighCount > 0) or (MapCell.Player = Player); 861 859 if InVisibleRange and not Explored then Explored := True; 862 860 end; … … 999 997 begin 1000 998 for I := 0 to Count - 1 do 1001 TCell(Items[I]).FixRefId;999 Items[I].FixRefId; 1002 1000 end; 1003 1001 … … 1007 1005 begin 1008 1006 I := 0; 1009 while (I < Count) and ( TCell(Items[I]).Id <> Id) do Inc(I);1010 if I < Count then Result := TCell(Items[I])1007 while (I < Count) and (Items[I].Id <> Id) do Inc(I); 1008 if I < Count then Result := Items[I] 1011 1009 else Result := nil; 1012 1010 end; … … 1044 1042 begin 1045 1043 for I := 0 to Count - 1 do 1046 with TCell(Items[I])do begin1044 with Items[I] do begin 1047 1045 NewNode2 := Node.OwnerDocument.CreateElement('Cell'); 1048 1046 Node.AppendChild(NewNode2); … … 1090 1088 begin 1091 1089 I := 0; 1092 while (I < Count) and ( TPlayer(Items[I]).Id <> Id) do Inc(I);1093 if I < Count then Result := TPlayer(Items[I])1090 while (I < Count) and (Items[I].Id <> Id) do Inc(I); 1091 if I < Count then Result := Items[I] 1094 1092 else Result := nil; 1095 1093 end; … … 1140 1138 NewNode := Node.OwnerDocument.CreateElement('Player'); 1141 1139 Node.AppendChild(NewNode); 1142 TPlayer(Items[I]).SaveToNode(NewNode);1140 Items[I].SaveToNode(NewNode); 1143 1141 end; 1144 1142 end; … … 1155 1153 begin 1156 1154 I := 0; 1157 while (I < Count) and ( TPlayer(Items[I]).Mode <> pmHuman) do Inc(I);1158 if I < Count then Result := TPlayer(Items[I])1155 while (I < Count) and (Items[I].Mode <> pmHuman) do Inc(I); 1156 if I < Count then Result := Items[I] 1159 1157 else Result := nil; 1160 1158 end; … … 1169 1167 Add(TPlayer.Create); 1170 1168 for I := 0 to Count - 1 do begin 1171 TPlayer(Items[I]).Assign(TPlayer(Source[I]));1172 TPlayer(Items[I]).Game := Game;1169 Items[I].Assign(Source[I]); 1170 Items[I].Game := Game; 1173 1171 end; 1174 1172 NewPlayerId := Source.NewPlayerId; … … 1188 1186 for I := 0 to Count - 1 do begin 1189 1187 Items[I] := TPlayer.Create; 1190 TPlayer(Items[I]).Id := GetNewPlayerId;1191 TPlayer(Items[I]).Game := Game;1192 TPlayer(Items[I]).LoadConfig(Config, Path + '/Player' + IntToStr(I));1188 Items[I].Id := GetNewPlayerId; 1189 Items[I].Game := Game; 1190 Items[I].LoadConfig(Config, Path + '/Player' + IntToStr(I)); 1193 1191 end; 1194 1192 end; … … 1201 1199 begin 1202 1200 for I := 0 to Count - 1 do 1203 TPlayer(Items[I]).SaveConfig(Config, Path + '/Player' + IntToStr(I));1201 Items[I].SaveConfig(Config, Path + '/Player' + IntToStr(I)); 1204 1202 with Config do begin 1205 1203 SetValue(DOMString(Path + '/Count'), Count); … … 1385 1383 for I := 0 to Cells.Count - 1 do begin 1386 1384 Cells[I] := TCell.Create; 1387 TCell(Cells[I]).Map := Self;1388 TCell(Cells[I]).Assign(TCell(Source.Cells[I]));1385 Cells[I].Map := Self; 1386 Cells[I].Assign(Source.Cells[I]); 1389 1387 end; 1390 1388 } … … 1442 1440 Result := nil; 1443 1441 for I := 0 to Cells.Count - 1 do 1444 if TCell(Cells[I]).Terrain <> ttVoid then begin1445 if TCell(Cells[I]).Polygon.IsPointInside(Pos) then begin1446 Result := TCell(Cells[I]);1442 if Cells[I].Terrain <> ttVoid then begin 1443 if Cells[I].Polygon.IsPointInside(Pos) then begin 1444 Result := Cells[I]; 1447 1445 Exit; 1448 1446 end; … … 1462 1460 begin 1463 1461 for I := 0 to Cells.Count - 1 do 1464 with TCell(Cells[I])do begin1462 with Cells[I] do begin 1465 1463 if (Player = APlayer) and ((Game.GrowCells = gcPlayerAll) or 1466 1464 ((Game.GrowCells = gcPlayerCities) and (Terrain = ttCity))) then begin … … 1588 1586 // Generic way to create two sides symetric map independent to shape 1589 1587 for C := 0 to (Cells.Count div 2) - 1 do begin 1590 TCell(Cells[C]).Terrain := TCell(Cells[Cells.Count - 1 - C]).Terrain;1591 TCell(Cells[C]).Power := TCell(Cells[Cells.Count - 1 - C]).Power;1592 1593 for I := TCell(Cells[C]).Links.Count - 1 downto 0 do begin1594 CellLink := TCell(Cells[C]).Links[I];1588 Cells[C].Terrain := Cells[Cells.Count - 1 - C].Terrain; 1589 Cells[C].Power := Cells[Cells.Count - 1 - C].Power; 1590 1591 for I := Cells[C].Links.Count - 1 downto 0 do begin 1592 CellLink := Cells[C].Links[I]; 1595 1593 1596 1594 // Remove cells on first half of the map … … 1624 1622 for C := 0 to (Cells.Count div 2) - 1 do begin 1625 1623 // Make copy of links from second half 1626 OppositeCell := TCell(Cells[Cells.Count - 1 - C]);1624 OppositeCell := Cells[Cells.Count - 1 - C]; 1627 1625 for CellLink in OppositeCell.Links do 1628 1626 if (Cells.IndexOf(CellLink.Cells[0]) > (Cells.Count div 2)) and … … 1687 1685 // This is generic algorithm to determine pixel size of entire map 1688 1686 for I := 0 to Cells.Count - 1 do begin 1689 CellRect := TCell(Cells[I]).Polygon.GetRect;1687 CellRect := Cells[I].Polygon.GetRect; 1690 1688 if I = 0 then Result := CellRect 1691 1689 else begin … … 1935 1933 NewNode2 := NewNode.OwnerDocument.CreateElement('Neighbour'); 1936 1934 NewNode.AppendChild(NewNode2); 1937 WriteInteger(NewNode2, 'Id', TCell(Neighbors[I]).Id);1935 WriteInteger(NewNode2, 'Id', Neighbors[I].Id); 1938 1936 end; 1939 1937 NewNode := Node.OwnerDocument.CreateElement('Polygon'); … … 2028 2026 FreeAndNil(Links); 2029 2027 for I := Neighbors.Count - 1 downto 0 do 2030 if TCell(Neighbors[I]).Neighbors.Remove(Self) = -1 then2028 if Neighbors[I].Neighbors.Remove(Self) = -1 then 2031 2029 raise Exception.Create(SCellRemoveNeighborError); 2032 2030 FreeAndNil(Neighbors); … … 2435 2433 // Get list of all enemy border cells 2436 2434 for C := 0 to AllCells.Count - 1 do 2437 with TCell(AllCells[C])do begin2435 with AllCells[C] do begin 2438 2436 if (Player <> Game.CurrentPlayer) and (Player <> nil) and (Terrain <> ttVoid) then begin 2439 2437 CanAttack := 0; 2440 2438 for I := 0 to Neighbors.Count - 1 do 2441 if (( TCell(Neighbors[I]).Player = Game.CurrentPlayer) or2442 ( TCell(Neighbors[I]).Player = nil)) and (TCell(Neighbors[I]).Terrain <> ttVoid) then begin2439 if ((Neighbors[I].Player = Game.CurrentPlayer) or 2440 (Neighbors[I].Player = nil)) and (Neighbors[I].Terrain <> ttVoid) then begin 2443 2441 Inc(CanAttack); 2444 2442 end; … … 2458 2456 // Set mark for selected border cells 2459 2457 for C := 0 to TargetCells.Count - 1 do 2460 T Cell(TargetCells[C]).Mark := True;2458 TargetCells[C].Mark := True; 2461 2459 2462 2460 // Move all power from unmarked cells and mark them 2463 2461 NewTargetCells.Count := 0; 2464 2462 for C := 0 to TargetCells.Count - 1 do 2465 with T Cell(TargetCells[C])do begin2463 with TargetCells[C] do begin 2466 2464 for I := 0 to Neighbors.Count - 1 do begin 2467 if ( TCell(Neighbors[I]).Terrain <> ttVoid) and (not TCell(Neighbors[I]).Mark) then begin2468 if (T Cell(TargetCells[C]).Player = Game.CurrentPlayer) and2469 ( TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin2465 if (Neighbors[I].Terrain <> ttVoid) and (not Neighbors[I].Mark) then begin 2466 if (TargetCells[C].Player = Game.CurrentPlayer) and 2467 (Neighbors[I].Player = Game.CurrentPlayer) then begin 2470 2468 // Do not take units from front line 2471 Cells2 := TCell(Neighbors[I]).Neighbors;2469 Cells2 := Neighbors[I].Neighbors; 2472 2470 CanAttack := 0; 2473 2471 for J := 0 to Cells2.Count - 1 do 2474 if (( TCell(Cells2[J]).Player <> Game.CurrentPlayer) or (TCell(Cells2[J]).Player = nil))2475 and ( TCell(Cells2[J]).Terrain <> ttVoid) then begin2472 if ((Cells2[J].Player <> Game.CurrentPlayer) or (Cells2[J].Player = nil)) 2473 and (Cells2[J].Terrain <> ttVoid) then begin 2476 2474 Inc(CanAttack); 2477 2475 end; 2478 2476 if CanAttack = 0 then begin 2479 MovedPower := TCell(Neighbors[I]).GetAvialPower;2480 if (T Cell(TargetCells[C]).GetAvialPower + TCell(TargetCells[C]).GetAttackPower + MovedPower) > Game.Map.MaxPower then2481 MovedPower := Game.Map.MaxPower - T Cell(TargetCells[C]).GetAvialPower - TCell(TargetCells[C]).GetAttackPower;2482 Player.SetMove( TCell(Neighbors[I]), TCell(TargetCells[C]), MovedPower, False);2477 MovedPower := Neighbors[I].GetAvialPower; 2478 if (TargetCells[C].GetAvialPower + TargetCells[C].GetAttackPower + MovedPower) > Game.Map.MaxPower then 2479 MovedPower := Game.Map.MaxPower - TargetCells[C].GetAvialPower - TargetCells[C].GetAttackPower; 2480 Player.SetMove(Neighbors[I], TargetCells[C], MovedPower, False); 2483 2481 end; 2484 2482 end; 2485 TCell(Neighbors[I]).Mark := True;2486 NewTargetCells.Add( TCell(Neighbors[I]));2483 Neighbors[I].Mark := True; 2484 NewTargetCells.Add(Neighbors[I]); 2487 2485 end; 2488 2486 end; … … 2539 2537 // Get list of border cells 2540 2538 for C := 0 to AllCells.Count - 1 do 2541 with TCell(AllCells[C])do begin2539 with AllCells[C] do begin 2542 2540 if (Terrain <> ttVoid) and (Player = Game.CurrentPlayer) then begin 2543 if AttackersCount( TCell(AllCells[C])) > 0 then2541 if AttackersCount(AllCells[C]) > 0 then 2544 2542 BorderCells.Add(AllCells[C]); 2545 2543 end; … … 2548 2546 // Move all units back to inner area from weak border cells 2549 2547 for C := 0 to BorderCells.Count - 1 do 2550 with TCell(BorderCells[C])do begin2548 with BorderCells[C] do begin 2551 2549 // Calculate enemy power 2552 2550 // TODO: Do not sum different enemy power to one value 2553 2551 EnemyPower := 0; 2554 2552 for I := 0 to Neighbors.Count - 1 do 2555 if ( TCell(Neighbors[I]).Player <> Game.CurrentPlayer) and (TCell(Neighbors[I]).Player <> nil) then begin2556 Inc(EnemyPower, TCell(Neighbors[I]).Power);2553 if (Neighbors[I].Player <> Game.CurrentPlayer) and (Neighbors[I].Player <> nil) then begin 2554 Inc(EnemyPower, Neighbors[I].Power); 2557 2555 end; 2558 2556 if EnemyPower > (GetAvialPower + GetAttackPower) then begin … … 2561 2559 Player.Moves.Remove(MovesTo[I]); 2562 2560 for I := 0 to Neighbors.Count - 1 do 2563 if ( TCell(Neighbors[I]).Player = Player) and (AttackersCount(TCell(Neighbors[I])) = 0) then begin2564 Player.SetMove( TCell(BorderCells[C]), TCell(Neighbors[I]), GetAvialPower, False);2561 if (Neighbors[I].Player = Player) and (AttackersCount(Neighbors[I]) = 0) then begin 2562 Player.SetMove(BorderCells[C], Neighbors[I], GetAvialPower, False); 2565 2563 Break; 2566 2564 end; … … 2577 2575 Result := 0; 2578 2576 for I := 0 to Cell.Neighbors.Count - 1 do 2579 if ( TCell(Cell.Neighbors[I]).Player <> Game.CurrentPlayer) and2580 ( TCell(Cell.Neighbors[I]).Player <> nil) then begin2577 if (Cell.Neighbors[I].Player <> Game.CurrentPlayer) and 2578 (Cell.Neighbors[I].Player <> nil) then begin 2581 2579 Inc(Result); 2582 2580 end; … … 2828 2826 2829 2827 for C := 0 to List.Count - 1 do 2830 with TCell(List[C])do begin2828 with List[C] do begin 2831 2829 for I := 0 to Neighbors.Count - 1 do 2832 with TCell(Neighbors[I])do2830 with Neighbors[I] do 2833 2831 if (not Mark) and (Terrain <> ttVoid) and (Area <> SourceArea) and ((DestArea = nil) or (DestArea = Area)) then begin 2834 NewList.Add( TCell(TCell(List[C]).Neighbors[I]));2832 NewList.Add(List[C].Neighbors[I]); 2835 2833 Mark := True; 2836 2834 end else 2837 2835 if (not Mark) and (Terrain = ttVoid) then begin 2838 NewListVoid.Add( TCell(TCell(List[C]).Neighbors[I]));2836 NewListVoid.Add(List[C].Neighbors[I]); 2839 2837 Mark := True; 2840 2838 end; … … 2843 2841 if NewList.Count > 0 then begin 2844 2842 // We found cell with different area 2845 Result := TCell(NewList[Random(NewList.Count)]);2843 Result := NewList[Random(NewList.Count)]; 2846 2844 end else 2847 2845 if NewListVoid.Count > 0 then begin … … 2878 2876 for J := 0 to 4 do begin 2879 2877 2880 Cell := TCell(BorderList[Random(BorderList.Count)]);2878 Cell := BorderList[Random(BorderList.Count)]; 2881 2879 List.Clear; 2882 2880 List.Add(Cell); … … 2913 2911 begin 2914 2912 for C := 0 to Cells.Count - 1 do 2915 with TCell(Cells[C])do2913 with Cells[C] do 2916 2914 Area := nil; 2917 2915 Areas.Clear; 2918 2916 for C := 0 to Cells.Count - 1 do 2919 with TCell(Cells[C])do2917 with Cells[C] do 2920 2918 if (Terrain <> ttVoid) and (not Assigned(Area)) then begin 2921 2919 NewArea := TMapArea.Create; … … 3060 3058 mtTriangle: Map := TTriangleMap.Create; 3061 3059 mtVoronoi: Map := TVoronoiMap.Create; 3060 mtIsometric: Map := TIsometricMap.Create; 3062 3061 else Map := TMap.Create; 3063 3062 end; … … 3128 3127 // Remove cells already allocated to different player 3129 3128 for I := List.Count - 1 downto 0 do 3130 if Assigned( TCell(List[I]).Player) then3129 if Assigned(List[I].Player) then 3131 3130 List.Delete(I); 3132 3131 … … 3277 3276 if Assigned(NewNode) then 3278 3277 Players.LoadFromNode(NewNode); 3279 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])3278 if Players.Count > 0 then CurrentPlayer := Players[0] 3280 3279 else CurrentPlayer := nil; 3281 3280 … … 3283 3282 3284 3283 for I := 0 to Players.Count - 1 do begin 3285 TPlayer(Players[I]).PlayerMap.Update;3286 TPlayer(Players[I]).PlayerMap.CheckVisibility;3284 Players[I].PlayerMap.Update; 3285 Players[I].PlayerMap.CheckVisibility; 3287 3286 end; 3288 3287 Running := ReadBoolean(RootNode, 'Running', True); … … 3341 3340 begin 3342 3341 for I := 0 to Players.Count - 1 do 3343 with TPlayer(Players[I])do begin3342 with Players[I] do begin 3344 3343 TotalUnits := 0; 3345 3344 TotalCells := 0; … … 3348 3347 TotalDiscovered := 0; 3349 3348 for J := 0 to PlayerMap.Cells.Count - 1 do 3350 with TPlayerCell(PlayerMap.Cells[J])do begin3349 with PlayerMap.Cells[J] do begin 3351 3350 if Explored then Inc(TotalDiscovered); 3352 3351 end; … … 3362 3361 begin 3363 3362 for I := 0 to Players.Count - 1 do 3364 with TPlayer(Players[I])do begin3363 with Players[I] do begin 3365 3364 NewStat := TGameTurnStat.Create; 3366 3365 NewStat.DiscoveredCells := TotalDiscovered; … … 3384 3383 // Skip dead players 3385 3384 repeat 3386 CurrentPlayer := TPlayer(Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]);3385 CurrentPlayer := Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]; 3387 3386 if Assigned(FOnPlayerChange) then 3388 3387 FOnPlayerChange(Self); … … 3412 3411 AlivePlayers := Players.GetAlivePlayers; 3413 3412 if (Length(AlivePlayers) <= 1) then begin 3414 if Length(AlivePlayers) > 0 then Winner := TPlayer(AlivePlayers[0]);3413 if Length(AlivePlayers) > 0 then Winner := AlivePlayers[0]; 3415 3414 EndGame(Winner); 3416 3415 end; … … 3419 3418 AlivePlayers := Players.GetAlivePlayersWithCities; 3420 3419 if (Length(AlivePlayers) <= 1) then begin 3421 if Length(AlivePlayers) > 0 then Winner := TPlayer(AlivePlayers[0]);3420 if Length(AlivePlayers) > 0 then Winner := AlivePlayers[0]; 3422 3421 EndGame(Winner); 3423 3422 end; … … 3498 3497 if Assigned(Player.StartCell) then begin 3499 3498 if SymetricMap and (I = 1) then 3500 StartCell := TCell(Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(TPlayer(Players[0]).StartCell)]);3499 StartCell := Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(Players[0].StartCell)]; 3501 3500 3502 3501 StartCell.Terrain := ttCity; … … 3508 3507 Inc(I); 3509 3508 end; 3510 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])3509 if Players.Count > 0 then CurrentPlayer := Players[0] 3511 3510 else CurrentPlayer := nil; 3512 3511 -
trunk/UMap.pas
r187 r193 19 19 THexMap = class(TMap) 20 20 private 21 const 22 CellMulX = 1.12; 23 CellMulY = 1.292; 21 24 function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean; 22 25 procedure GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells); … … 57 60 end; 58 61 62 { TIsometricMap } 63 64 TIsometricMap = class(TMap) 65 private 66 const 67 CellMulX = 0.95; 68 CellMulY = 3.35; 69 function GetTilePolygon(Pos: TPoint; Size: TPoint): TPolygon; 70 public 71 function IsValidIndex(Index: TPoint): Boolean; override; 72 procedure Generate; override; 73 end; 74 75 59 76 implementation 77 78 { TIsometricMap } 79 80 function TIsometricMap.GetTilePolygon(Pos: TPoint; Size: TPoint): TPolygon; 81 begin 82 SetLength(Result.Points, 4); 83 Result.Points[0] := TPoint.Create(Pos.X, Trunc(Pos.Y - Size.Y / 3.5)); 84 Result.Points[1] := TPoint.Create(Trunc(Pos.X + Size.X / 2), Pos.Y); 85 Result.Points[2] := TPoint.Create(Pos.X, Trunc(Pos.Y + Size.Y / 3.5)); 86 Result.Points[3] := TPoint.Create(Trunc(Pos.X - Size.X / 2), Pos.Y); 87 end; 88 89 function TIsometricMap.IsValidIndex(Index: TPoint): Boolean; 90 begin 91 Result := (Index.X >= 0) and (Index.X < Size.X) and 92 (Index.Y >= 0) and (Index.Y < Size.Y); 93 end; 94 95 procedure TIsometricMap.Generate; 96 var 97 X, Y: Integer; 98 NewCell: TCell; 99 PX, PY: Double; 100 P: TPoint; 101 begin 102 Clear; 103 104 // Allocate and init new 105 Cells.Count := Size.Y * Size.X; 106 for Y := 0 to Size.Y - 1 do 107 for X := 0 to Size.X - 1 do begin 108 NewCell := TCell.Create; 109 NewCell.Map := Self; 110 PX := X; 111 PY := Y; 112 if (Y and 1) = 1 then begin 113 PX := PX + 0.5; 114 //Y := Y + 0.5; 115 end; 116 NewCell.PosPx := TPoint.Create(Trunc(PX * DefaultCellSize.X / CellMulX), 117 Trunc(PY * DefaultCellSize.Y / CellMulY)); 118 NewCell.Polygon := GetTilePolygon(NewCell.PosPx, DefaultCellSize); 119 NewCell.Id := GetNewCellId; 120 Cells[Y * Size.X + X] := NewCell; 121 end; 122 123 // Generate neightbours 124 for Y := 0 to Size.Y - 1 do 125 for X := 0 to Size.X - 1 do 126 with Cells[Y * Size.X + X] do begin 127 P := TPoint.Create(X + 0 + (Y mod 2), Y + 1); 128 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 129 P := TPoint.Create(X - 1 + (Y mod 2), Y + 1); 130 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 131 P := TPoint.Create(X + 0 + (Y mod 2), Y - 1); 132 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 133 P := TPoint.Create(X - 1 + (Y mod 2), Y - 1); 134 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 135 end; 136 137 FPixelRect := CalculatePixelRect; 138 end; 60 139 61 140 { THexMap } … … 136 215 var 137 216 X, Y: Integer; 217 P: TPoint; 138 218 begin 139 219 Neighbours.Count := 0; 140 220 for Y := -1 to 1 do 141 for X := -1 to 1 do 142 if IsValidIndex(TPoint.Create(CellPos.X + X, CellPos.Y + Y)) and 143 IsCellsPosNeighbor(CellPos, TPoint.Create((CellPos.X + X), (CellPos.Y + Y))) then begin 144 Neighbours.Add(TCell(Cells[(CellPos.Y + Y) * Size.X + (CellPos.X + X)])); 221 for X := -1 to 1 do begin 222 P := TPoint.Create(CellPos.X + X, CellPos.Y + Y); 223 if IsValidIndex(P) and IsCellsPosNeighbor(CellPos, P) then begin 224 Neighbours.Add(Cells[P.Y * Size.X + P.X]); 225 end; 145 226 end; 146 227 end; … … 166 247 //Y := Y + 0.5; 167 248 end; 168 NewCell.PosPx := TPoint.Create(Trunc(PX * DefaultCellSize.X / HexCellMulX),169 Trunc(PY * DefaultCellSize.Y / HexCellMulY));249 NewCell.PosPx := TPoint.Create(Trunc(PX * DefaultCellSize.X / CellMulX), 250 Trunc(PY * DefaultCellSize.Y / CellMulY)); 170 251 NewCell.Polygon := GetHexagonPolygon(NewCell.PosPx, DefaultCellSize); 171 252 NewCell.Id := GetNewCellId; … … 176 257 for Y := 0 to Size.Y - 1 do 177 258 for X := 0 to Size.X - 1 do 178 with TCell(Cells[Y * Size.X + X])do begin259 with Cells[Y * Size.X + X] do begin 179 260 GetCellPosNeighbors(TPoint.Create(X, Y), Neighbors); 180 261 end; … … 190 271 X, Y: Integer; 191 272 NewCell: TCell; 273 P: TPoint; 192 274 begin 193 275 Clear; … … 209 291 for Y := 0 to Size.Y - 1 do 210 292 for X := 0 to Size.X - 1 do 211 with TCell(Cells[Y * Size.X + X])do begin212 if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then213 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)]));214 if IsValidIndex(TPoint.Create(X + 0, Y + 1)) then215 Neighbors.Add(TCell(Cells[(Y + 1) * Size.X + (X + 0)]));216 if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then217 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X - 1)]));218 if IsValidIndex(TPoint.Create(X + 0, Y - 1)) then219 Neighbors.Add(TCell(Cells[(Y - 1) * Size.X + (X + 0)]));293 with Cells[Y * Size.X + X] do begin 294 P := TPoint.Create(X + 1, Y + 0); 295 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 296 P := TPoint.Create(X + 0, Y + 1); 297 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 298 P := TPoint.Create(X - 1, Y + 0); 299 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 300 P := TPoint.Create(X + 0, Y - 1); 301 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 220 302 end; 221 303 … … 332 414 Reverse: Boolean; 333 415 NewCell: TCell; 416 P: TPoint; 334 417 begin 335 418 Clear; … … 354 437 for Y := 0 to Self.Size.Y - 1 do 355 438 for X := 0 to Size.X - 1 do 356 with TCell(Cells[Y * Size.X + X])do begin439 with Cells[Y * Size.X + X] do begin 357 440 if Boolean(X mod 2) xor Boolean(Y mod 2) then Rev := -1 358 441 else Rev := 1; 359 if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then360 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)]));361 if IsValidIndex(TPoint.Create(X + 0, Y - 1 * Rev)) then362 Neighbors.Add(TCell(Cells[(Y - 1 * Rev) * Size.X + (X + 0)]));363 if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then364 Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X - 1)]));442 P := TPoint.Create(X + 1, Y + 0); 443 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 444 P := TPoint.Create(X + 0, Y - 1 * Rev); 445 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 446 P := TPoint.Create(X - 1, Y + 0); 447 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]); 365 448 end; 366 449
Note:
See TracChangeset
for help on using the changeset viewer.