Changeset 193


Ignore:
Timestamp:
May 14, 2018, 5:02:00 PM (7 years ago)
Author:
chronos
Message:
  • Added: Isometric map type.
  • Modified: Removed unneeded explicit typecast for list items.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.pas

    r184 r193  
    125125  SGridTypeTriangle = 'Triangonal';
    126126  SGridTypeVoronoi = 'Voronoi random';
     127  SGridTypeIsometric = 'Isometric';
    127128  SWinObjectiveDefeatAllOponents = 'Defeat all oponents';
    128129  SWinObjectiveDefeatAllCities = 'Defeat all oponents cities';
     
    143144begin
    144145  if (Item.Index >= 0) and (Item.Index < Players.Count) then
    145   with TPlayer(Players[Item.Index]) do begin
     146  with Players[Item.Index] do begin
    146147    Item.Caption := Name;
    147148    Item.Data := Players[Item.Index];
     
    211212    Items.Add(SGridTypeTriangle);
    212213    Items.Add(SGridTypeVoronoi);
     214    Items.Add(SGridTypeIsometric);
    213215    ItemIndex := LastIndex;
    214216  end;
  • trunk/Languages/xtactics.cs.po

    r190 r193  
    99"MIME-Version: 1.0\n"
    1010"Content-Transfer-Encoding: 8bit\n"
    11 "X-Generator: Poedit 2.0.4\n"
     11"X-Generator: Poedit 1.8.8\n"
    1212"Language: cs\n"
    1313
     
    730730msgstr "Hexagonální"
    731731
     732#: uformnew.sgridtypeisometric
     733msgid "Isometric"
     734msgstr "Izometrický"
     735
    732736#: uformnew.sgridtypesquare
    733737msgid "Square"
  • trunk/Languages/xtactics.po

    r185 r193  
    709709msgstr ""
    710710
     711#: uformnew.sgridtypeisometric
     712msgid "Isometric"
     713msgstr ""
     714
    711715#: uformnew.sgridtypesquare
    712716msgid "Square"
  • trunk/UCore.lfm

    r192 r193  
    33  OnDestroy = DataModuleDestroy
    44  OldCreateOrder = False
    5   Height = 811
    6   HorizontalOffset = 438
    7   VerticalOffset = 341
    8   Width = 1258
    9   PPI = 144
     5  Height = 676
     6  HorizontalOffset = 365
     7  VerticalOffset = 284
     8  Width = 1048
     9  PPI = 120
    1010  object ActionList1: TActionList
    1111    Images = ImageListSmall
    12     left = 136
    13     top = 60
     12    left = 113
     13    top = 50
    1414    object AExit: TAction
    1515      Caption = 'Exit'
     
    9393  end
    9494  object ImageListSmall: TImageList
    95     left = 786
    96     top = 420
     95    left = 655
     96    top = 350
    9797    Bitmap = {
    9898      4C690C00000010000000100000000000000000000000E3AA4BD6E5B35EFFE3B1
     
    486486    POFilesFolder = 'Languages'
    487487    OnTranslate = CoolTranslator1Translate
    488     left = 137
    489     top = 436
     488    left = 114
     489    top = 363
    490490  end
    491491  object ImageListLarge: TImageList
    492492    Height = 32
    493493    Width = 32
    494     left = 786
    495     top = 286
     494    left = 655
     495    top = 238
    496496    Bitmap = {
    497497      4C690C0000002000000020000000000000000000000000000000E2AA4B36E2A9
     
    20382038    RootName = 'CONFIG'
    20392039    ReadOnly = False
    2040     left = 137
    2041     top = 556
     2040    left = 114
     2041    top = 463
    20422042  end
    20432043  object OpenDialog1: TOpenDialog
    20442044    DefaultExt = '.xtmap'
    2045     left = 1126
    2046     top = 292
     2045    left = 938
     2046    top = 243
    20472047  end
    20482048  object SaveDialog1: TSaveDialog
    20492049    DefaultExt = '.xtmap'
    2050     left = 1126
    2051     top = 166
     2050    left = 938
     2051    top = 138
    20522052  end
    20532053  object ApplicationInfo: TApplicationInfo
     
    20622062    AuthorsName = 'Chronos'
    20632063    AppName = 'xTactics'
    2064     ReleaseDate = 43058
     2064    ReleaseDate = 43234
    20652065    RegistryKey = '\Software\xTactics'
    20662066    RegistryRoot = rrKeyCurrentUser
    20672067    License = 'CC0'
    2068     left = 137
    2069     top = 180
     2068    left = 114
     2069    top = 150
    20702070  end
    20712071  object PersistentForm: TPersistentForm
    20722072    MinVisiblePart = 50
    20732073    EntireVisible = False
    2074     left = 780
    2075     top = 600
     2074    left = 650
     2075    top = 500
    20762076  end
    20772077  object ScaleDPI1: TScaleDPI
    20782078    AutoDetect = False
    2079     left = 136
    2080     top = 676
     2079    left = 113
     2080    top = 563
    20812081  end
    20822082  object LastOpenedList1: TLastOpenedList
    20832083    MaxCount = 10
    20842084    OnChange = LastOpenedList1Change
    2085     left = 137
    2086     top = 300
     2085    left = 114
     2086    top = 250
    20872087  end
    20882088end
  • trunk/UCore.pas

    r191 r193  
    533533
    534534    // 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';
    537537
    538538    LoadConfig;
  • trunk/UGame.pas

    r191 r193  
    1212const
    1313  DefaultPlayerStartUnits = 5;
    14   HexCellMulX = 1.12;
    15   HexCellMulY = 1.292;
    1614  SquareCellMulX = 1.05;
    1715  SquareCellMulY = 1.05;
     
    414412  TGrowAmount = (gaByOne, gaBySquareRoot);
    415413  TGrowCells = (gcNone, gcPlayerCities, gcPlayerAll);
    416   TMapType = (mtNone, mtHexagon, mtSquare, mtTriangle, mtVoronoi);
     414  TMapType = (mtNone, mtHexagon, mtSquare, mtTriangle, mtVoronoi, mtIsometric);
    417415  TWinObjective = (woDefeatAllOponents, woDefeatAllOponentsCities,
    418416    woSpecialCaptureCell, woStayAliveForDefinedTurns);
     
    636634begin
    637635  for I := 0 to Cells.Count - 1 do begin
    638     if TCell(Cells[I]).Neighbors.Remove(TCell(Cells[1 - I])) = -1 then
     636    if Cells[I].Neighbors.Remove(Cells[1 - I]) = -1 then
    639637      raise Exception.Create(SCellRemoveNeighborError);
    640     if TCell(Cells[I]).Links.Remove(Self) = -1 then
     638    if Cells[I].Links.Remove(Self) = -1 then
    641639      raise Exception.Create(SCellRemoveNeighborError);
    642640  end;
     
    756754begin
    757755  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]
    760758    else Result := nil;
    761759end;
     
    785783    NewNode := Node.OwnerDocument.CreateElement('Cell');
    786784    Node.AppendChild(NewNode);
    787     TPlayerCell(Items[I]).SaveToNode(NewNode);
     785    Items[I].SaveToNode(NewNode);
    788786  end;
    789787end;
     
    825823
    826824  for I := 0 to Cells.Count - 1 do
    827   with TPlayerCell(Cells[I]) do begin
     825  with Cells[I] do begin
    828826    List := Cells;
    829827    Explored := False;
    830828    InVisibleRange := False;
    831     MapCell := TCell(Player.Game.Map.Cells[I]);
     829    MapCell := Player.Game.Map.Cells[I];
    832830  end;
    833831end;
     
    852850begin
    853851  for I := 0 to Cells.Count - 1 do
    854   with TPlayerCell(Cells[I]) do begin
     852  with Cells[I] do begin
    855853    NeighCount := 0;
    856854    for C := 0 to MapCell.Neighbors.Count - 1 do
    857       if TCell(MapCell.Neighbors[C]).Player = Player then
     855      if MapCell.Neighbors[C].Player = Player then
    858856        Inc(NeighCount);
    859857
    860     InVisibleRange := (NeighCount > 0) or (TCell(MapCell).Player = Player);
     858    InVisibleRange := (NeighCount > 0) or (MapCell.Player = Player);
    861859    if InVisibleRange and not Explored then Explored := True;
    862860  end;
     
    999997begin
    1000998  for I := 0 to Count - 1 do
    1001   TCell(Items[I]).FixRefId;
     999    Items[I].FixRefId;
    10021000end;
    10031001
     
    10071005begin
    10081006  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]
    10111009    else Result := nil;
    10121010end;
     
    10441042begin
    10451043  for I := 0 to Count - 1 do
    1046   with TCell(Items[I]) do begin
     1044  with Items[I] do begin
    10471045    NewNode2 := Node.OwnerDocument.CreateElement('Cell');
    10481046    Node.AppendChild(NewNode2);
     
    10901088begin
    10911089  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]
    10941092    else Result := nil;
    10951093end;
     
    11401138    NewNode := Node.OwnerDocument.CreateElement('Player');
    11411139    Node.AppendChild(NewNode);
    1142     TPlayer(Items[I]).SaveToNode(NewNode);
     1140    Items[I].SaveToNode(NewNode);
    11431141  end;
    11441142end;
     
    11551153begin
    11561154  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]
    11591157    else Result := nil;
    11601158end;
     
    11691167    Add(TPlayer.Create);
    11701168  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;
    11731171  end;
    11741172  NewPlayerId := Source.NewPlayerId;
     
    11881186      for I := 0 to Count - 1 do begin
    11891187        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));
    11931191      end;
    11941192    end;
     
    12011199begin
    12021200  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));
    12041202  with Config do begin
    12051203    SetValue(DOMString(Path + '/Count'), Count);
     
    13851383  for I := 0 to Cells.Count - 1 do begin
    13861384    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]);
    13891387  end;
    13901388  }
     
    14421440  Result := nil;
    14431441  for I := 0 to Cells.Count - 1 do
    1444   if TCell(Cells[I]).Terrain <> ttVoid then begin
    1445     if TCell(Cells[I]).Polygon.IsPointInside(Pos) then begin
    1446       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];
    14471445      Exit;
    14481446    end;
     
    14621460begin
    14631461  for I := 0 to Cells.Count - 1 do
    1464   with TCell(Cells[I]) do begin
     1462  with Cells[I] do begin
    14651463    if (Player = APlayer) and ((Game.GrowCells = gcPlayerAll) or
    14661464    ((Game.GrowCells = gcPlayerCities) and (Terrain = ttCity))) then begin
     
    15881586  // Generic way to create two sides symetric map independent to shape
    15891587  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 begin
    1594       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];
    15951593
    15961594      // Remove cells on first half of the map
     
    16241622  for C := 0 to (Cells.Count div 2) - 1 do begin
    16251623    // Make copy of links from second half
    1626     OppositeCell := TCell(Cells[Cells.Count - 1 - C]);
     1624    OppositeCell := Cells[Cells.Count - 1 - C];
    16271625    for CellLink in OppositeCell.Links do
    16281626      if (Cells.IndexOf(CellLink.Cells[0]) > (Cells.Count div 2)) and
     
    16871685  // This is generic algorithm to determine pixel size of entire map
    16881686  for I := 0 to Cells.Count - 1 do begin
    1689     CellRect := TCell(Cells[I]).Polygon.GetRect;
     1687    CellRect := Cells[I].Polygon.GetRect;
    16901688    if I = 0 then Result := CellRect
    16911689      else begin
     
    19351933    NewNode2 := NewNode.OwnerDocument.CreateElement('Neighbour');
    19361934    NewNode.AppendChild(NewNode2);
    1937     WriteInteger(NewNode2, 'Id', TCell(Neighbors[I]).Id);
     1935    WriteInteger(NewNode2, 'Id', Neighbors[I].Id);
    19381936  end;
    19391937  NewNode := Node.OwnerDocument.CreateElement('Polygon');
     
    20282026  FreeAndNil(Links);
    20292027  for I := Neighbors.Count - 1 downto 0 do
    2030     if TCell(Neighbors[I]).Neighbors.Remove(Self) = -1 then
     2028    if Neighbors[I].Neighbors.Remove(Self) = -1 then
    20312029      raise Exception.Create(SCellRemoveNeighborError);
    20322030  FreeAndNil(Neighbors);
     
    24352433  // Get list of all enemy border cells
    24362434  for C := 0 to AllCells.Count - 1 do
    2437   with TCell(AllCells[C]) do begin
     2435  with AllCells[C] do begin
    24382436    if (Player <> Game.CurrentPlayer) and (Player <> nil) and (Terrain <> ttVoid) then begin
    24392437      CanAttack := 0;
    24402438      for I := 0 to Neighbors.Count - 1 do
    2441       if ((TCell(Neighbors[I]).Player = Game.CurrentPlayer) or
    2442       (TCell(Neighbors[I]).Player = nil)) and (TCell(Neighbors[I]).Terrain <> ttVoid) then begin
     2439      if ((Neighbors[I].Player = Game.CurrentPlayer) or
     2440      (Neighbors[I].Player = nil)) and (Neighbors[I].Terrain <> ttVoid) then begin
    24432441        Inc(CanAttack);
    24442442      end;
     
    24582456    // Set mark for selected border cells
    24592457    for C := 0 to TargetCells.Count - 1 do
    2460       TCell(TargetCells[C]).Mark := True;
     2458      TargetCells[C].Mark := True;
    24612459
    24622460    // Move all power from unmarked cells and mark them
    24632461    NewTargetCells.Count := 0;
    24642462    for C := 0 to TargetCells.Count - 1 do
    2465     with TCell(TargetCells[C]) do begin
     2463    with TargetCells[C] do begin
    24662464      for I := 0 to Neighbors.Count - 1 do begin
    2467         if (TCell(Neighbors[I]).Terrain <> ttVoid) and (not TCell(Neighbors[I]).Mark) then begin
    2468           if (TCell(TargetCells[C]).Player = Game.CurrentPlayer) and
    2469           (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin
     2465        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
    24702468            // Do not take units from front line
    2471             Cells2 := TCell(Neighbors[I]).Neighbors;
     2469            Cells2 := Neighbors[I].Neighbors;
    24722470            CanAttack := 0;
    24732471            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 begin
     2472            if ((Cells2[J].Player <> Game.CurrentPlayer) or (Cells2[J].Player = nil))
     2473            and (Cells2[J].Terrain <> ttVoid) then begin
    24762474              Inc(CanAttack);
    24772475            end;
    24782476            if CanAttack = 0 then begin
    2479               MovedPower := TCell(Neighbors[I]).GetAvialPower;
    2480               if (TCell(TargetCells[C]).GetAvialPower + TCell(TargetCells[C]).GetAttackPower + MovedPower) > Game.Map.MaxPower then
    2481                 MovedPower := Game.Map.MaxPower - TCell(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);
    24832481            end;
    24842482          end;
    2485           TCell(Neighbors[I]).Mark := True;
    2486           NewTargetCells.Add(TCell(Neighbors[I]));
     2483          Neighbors[I].Mark := True;
     2484          NewTargetCells.Add(Neighbors[I]);
    24872485        end;
    24882486      end;
     
    25392537  // Get list of border cells
    25402538  for C := 0 to AllCells.Count - 1 do
    2541   with TCell(AllCells[C]) do begin
     2539  with AllCells[C] do begin
    25422540    if (Terrain <> ttVoid) and (Player = Game.CurrentPlayer)  then begin
    2543       if AttackersCount(TCell(AllCells[C])) > 0 then
     2541      if AttackersCount(AllCells[C]) > 0 then
    25442542        BorderCells.Add(AllCells[C]);
    25452543    end;
     
    25482546  // Move all units back to inner area from weak border cells
    25492547  for C := 0 to BorderCells.Count - 1 do
    2550   with TCell(BorderCells[C]) do begin
     2548  with BorderCells[C] do begin
    25512549    // Calculate enemy power
    25522550    // TODO: Do not sum different enemy power to one value
    25532551    EnemyPower := 0;
    25542552    for I := 0 to Neighbors.Count - 1 do
    2555     if (TCell(Neighbors[I]).Player <> Game.CurrentPlayer) and (TCell(Neighbors[I]).Player <> nil) then begin
    2556       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);
    25572555    end;
    25582556    if EnemyPower > (GetAvialPower + GetAttackPower) then begin
     
    25612559        Player.Moves.Remove(MovesTo[I]);
    25622560      for I := 0 to Neighbors.Count - 1 do
    2563       if (TCell(Neighbors[I]).Player = Player) and (AttackersCount(TCell(Neighbors[I])) = 0) then begin
    2564         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);
    25652563        Break;
    25662564      end;
     
    25772575  Result := 0;
    25782576  for I := 0 to Cell.Neighbors.Count - 1 do
    2579   if (TCell(Cell.Neighbors[I]).Player <> Game.CurrentPlayer) and
    2580     (TCell(Cell.Neighbors[I]).Player <> nil) then begin
     2577  if (Cell.Neighbors[I].Player <> Game.CurrentPlayer) and
     2578    (Cell.Neighbors[I].Player <> nil) then begin
    25812579      Inc(Result);
    25822580  end;
     
    28282826
    28292827  for C := 0 to List.Count - 1 do
    2830   with TCell(List[C]) do begin
     2828  with List[C] do begin
    28312829    for I := 0 to Neighbors.Count - 1 do
    2832     with TCell(Neighbors[I]) do
     2830    with Neighbors[I] do
    28332831    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]);
    28352833      Mark := True;
    28362834    end else
    28372835    if (not Mark) and (Terrain = ttVoid) then begin
    2838       NewListVoid.Add(TCell(TCell(List[C]).Neighbors[I]));
     2836      NewListVoid.Add(List[C].Neighbors[I]);
    28392837      Mark := True;
    28402838    end;
     
    28432841  if NewList.Count > 0 then begin
    28442842    // We found cell with different area
    2845     Result := TCell(NewList[Random(NewList.Count)]);
     2843    Result := NewList[Random(NewList.Count)];
    28462844  end else
    28472845  if NewListVoid.Count > 0 then begin
     
    28782876    for J := 0 to 4 do begin
    28792877
    2880     Cell := TCell(BorderList[Random(BorderList.Count)]);
     2878    Cell := BorderList[Random(BorderList.Count)];
    28812879    List.Clear;
    28822880    List.Add(Cell);
     
    29132911begin
    29142912  for C := 0 to Cells.Count - 1 do
    2915   with TCell(Cells[C]) do
     2913  with Cells[C] do
    29162914    Area := nil;
    29172915  Areas.Clear;
    29182916  for C := 0 to Cells.Count - 1 do
    2919   with TCell(Cells[C]) do
     2917  with Cells[C] do
    29202918  if (Terrain <> ttVoid) and (not Assigned(Area)) then begin
    29212919    NewArea := TMapArea.Create;
     
    30603058    mtTriangle: Map := TTriangleMap.Create;
    30613059    mtVoronoi: Map := TVoronoiMap.Create;
     3060    mtIsometric: Map := TIsometricMap.Create;
    30623061    else Map := TMap.Create;
    30633062  end;
     
    31283127      // Remove cells already allocated to different player
    31293128      for I := List.Count - 1 downto 0 do
    3130         if Assigned(TCell(List[I]).Player) then
     3129        if Assigned(List[I].Player) then
    31313130          List.Delete(I);
    31323131
     
    32773276      if Assigned(NewNode) then
    32783277        Players.LoadFromNode(NewNode);
    3279       if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
     3278      if Players.Count > 0 then CurrentPlayer := Players[0]
    32803279        else CurrentPlayer := nil;
    32813280
     
    32833282
    32843283      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;
    32873286      end;
    32883287      Running := ReadBoolean(RootNode, 'Running', True);
     
    33413340begin
    33423341  for I := 0 to Players.Count - 1 do
    3343   with TPlayer(Players[I]) do begin
     3342  with Players[I] do begin
    33443343    TotalUnits := 0;
    33453344    TotalCells := 0;
     
    33483347    TotalDiscovered := 0;
    33493348    for J := 0 to PlayerMap.Cells.Count - 1 do
    3350     with TPlayerCell(PlayerMap.Cells[J]) do begin
     3349    with PlayerMap.Cells[J] do begin
    33513350      if Explored then Inc(TotalDiscovered);
    33523351    end;
     
    33623361begin
    33633362  for I := 0 to Players.Count - 1 do
    3364   with TPlayer(Players[I]) do begin
     3363  with Players[I] do begin
    33653364    NewStat := TGameTurnStat.Create;
    33663365    NewStat.DiscoveredCells := TotalDiscovered;
     
    33843383  // Skip dead players
    33853384  repeat
    3386     CurrentPlayer := TPlayer(Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]);
     3385    CurrentPlayer := Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count];
    33873386    if Assigned(FOnPlayerChange) then
    33883387      FOnPlayerChange(Self);
     
    34123411    AlivePlayers := Players.GetAlivePlayers;
    34133412    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];
    34153414      EndGame(Winner);
    34163415    end;
     
    34193418    AlivePlayers := Players.GetAlivePlayersWithCities;
    34203419    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];
    34223421      EndGame(Winner);
    34233422    end;
     
    34983497      if Assigned(Player.StartCell) then begin
    34993498        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)];
    35013500
    35023501        StartCell.Terrain := ttCity;
     
    35083507    Inc(I);
    35093508  end;
    3510   if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
     3509  if Players.Count > 0 then CurrentPlayer := Players[0]
    35113510    else CurrentPlayer := nil;
    35123511
  • trunk/UMap.pas

    r187 r193  
    1919  THexMap = class(TMap)
    2020  private
     21    const
     22      CellMulX = 1.12;
     23      CellMulY = 1.292;
    2124    function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean;
    2225    procedure GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells);
     
    5760  end;
    5861
     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
    5976implementation
     77
     78{ TIsometricMap }
     79
     80function TIsometricMap.GetTilePolygon(Pos: TPoint; Size: TPoint): TPolygon;
     81begin
     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);
     87end;
     88
     89function TIsometricMap.IsValidIndex(Index: TPoint): Boolean;
     90begin
     91  Result := (Index.X >= 0) and (Index.X < Size.X) and
     92    (Index.Y >= 0) and (Index.Y < Size.Y);
     93end;
     94
     95procedure TIsometricMap.Generate;
     96var
     97  X, Y: Integer;
     98  NewCell: TCell;
     99  PX, PY: Double;
     100  P: TPoint;
     101begin
     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;
     138end;
    60139
    61140{ THexMap }
     
    136215var
    137216  X, Y: Integer;
     217  P: TPoint;
    138218begin
    139219  Neighbours.Count := 0;
    140220  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;
    145226  end;
    146227end;
     
    166247      //Y := Y + 0.5;
    167248    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));
    170251    NewCell.Polygon := GetHexagonPolygon(NewCell.PosPx, DefaultCellSize);
    171252    NewCell.Id := GetNewCellId;
     
    176257  for Y := 0 to Size.Y - 1 do
    177258  for X := 0 to Size.X - 1 do
    178   with TCell(Cells[Y * Size.X + X]) do begin
     259  with Cells[Y * Size.X + X] do begin
    179260    GetCellPosNeighbors(TPoint.Create(X, Y), Neighbors);
    180261  end;
     
    190271  X, Y: Integer;
    191272  NewCell: TCell;
     273  P: TPoint;
    192274begin
    193275  Clear;
     
    209291  for Y := 0 to Size.Y - 1 do
    210292  for X := 0 to Size.X - 1 do
    211   with TCell(Cells[Y * Size.X + X]) do begin
    212     if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then
    213       Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)]));
    214     if IsValidIndex(TPoint.Create(X + 0, Y + 1)) then
    215       Neighbors.Add(TCell(Cells[(Y + 1) * Size.X + (X + 0)]));
    216     if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then
    217       Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X - 1)]));
    218     if IsValidIndex(TPoint.Create(X + 0, Y - 1)) then
    219       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]);
    220302  end;
    221303
     
    332414  Reverse: Boolean;
    333415  NewCell: TCell;
     416  P: TPoint;
    334417begin
    335418  Clear;
     
    354437  for Y := 0 to Self.Size.Y - 1 do
    355438  for X := 0 to Size.X - 1 do
    356   with TCell(Cells[Y * Size.X + X]) do begin
     439  with Cells[Y * Size.X + X] do begin
    357440    if Boolean(X mod 2) xor Boolean(Y mod 2) then Rev := -1
    358441      else Rev := 1;
    359     if IsValidIndex(TPoint.Create(X + 1, Y + 0)) then
    360       Neighbors.Add(TCell(Cells[(Y + 0) * Size.X + (X + 1)]));
    361     if IsValidIndex(TPoint.Create(X + 0, Y - 1 * Rev)) then
    362       Neighbors.Add(TCell(Cells[(Y - 1 * Rev) * Size.X + (X + 0)]));
    363     if IsValidIndex(TPoint.Create(X - 1, Y + 0)) then
    364       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]);
    365448  end;
    366449
Note: See TracChangeset for help on using the changeset viewer.