Changeset 229


Ignore:
Timestamp:
Sep 18, 2018, 6:11:18 PM (6 years ago)
Author:
chronos
Message:
  • Added: Support for cyclic map. Movement across map borders will take player units to opposite map border.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormNew.lfm

    r221 r229  
    11object FormNew: TFormNew
    2   Left = 554
     2  Left = 365
    33  Height = 748
    4   Top = 149
     4  Top = 167
    55  Width = 1154
    66  Caption = 'New game'
     
    2121    Top = 4
    2222    Width = 749
    23     ActivePage = TabSheetMode
     23    ActivePage = TabSheetMap
    2424    Align = alClient
    2525    BorderSpacing.Around = 4
    26     TabIndex = 0
     26    TabIndex = 2
    2727    TabOrder = 0
    2828    object TabSheetMode: TTabSheet
     
    459459        Caption = 'Max units per cell:'
    460460        ParentColor = False
     461      end
     462      object CheckBoxCyclicMap: TCheckBox
     463        Left = 472
     464        Height = 27
     465        Top = 137
     466        Width = 253
     467        Anchors = [akTop, akLeft, akRight]
     468        AutoSize = False
     469        Caption = 'Cyclic map'
     470        TabOrder = 16
    461471      end
    462472    end
  • trunk/Forms/UFormNew.pas

    r221 r229  
    3535    CheckBoxCity: TCheckBox;
    3636    CheckBoxSymetricMap: TCheckBox;
     37    CheckBoxCyclicMap: TCheckBox;
    3738    CheckBoxVoid: TCheckBox;
    3839    ComboBoxGridType: TComboBox;
     
    510511  with Core.GameSettings do begin
    511512    CheckBoxSymetricMap.Checked := SymetricMap;
     513    CheckBoxCyclicMap.Checked := CyclicMap;
    512514    CheckBoxVoid.Checked := VoidEnabled;
    513515    SpinEditVoidPercent.Value := VoidPercentage;
     
    554556  with Core.GameSettings do begin
    555557    SymetricMap := CheckBoxSymetricMap.Checked;
     558    CyclicMap := CheckBoxCyclicMap.Checked;
    556559    VoidEnabled := CheckBoxVoid.Checked;
    557560    VoidPercentage := SpinEditVoidPercent.Value;
  • trunk/Forms/UFormPlayersStats.lfm

    r208 r229  
    11object FormPlayersStats: TFormPlayersStats
    2   Left = 709
     2  Left = 468
    33  Height = 300
    4   Top = 637
     4  Top = 477
    55  Width = 746
    66  Caption = 'Players stats'
  • trunk/Forms/UFormUnitMoves.lfm

    r150 r229  
    77  ClientHeight = 418
    88  ClientWidth = 802
     9  DesignTimePPI = 120
    910  OnClose = FormClose
    1011  OnShow = FormShow
    11   LCLVersion = '1.8.0.4'
     12  LCLVersion = '1.8.2.0'
    1213  object ListView1: TListView
    1314    Left = 0
  • trunk/Languages/xtactics.cs.po

    r222 r229  
    407407msgid "Cities"
    408408msgstr "Města"
     409
     410#: tformnew.checkboxcyclicmap.caption
     411msgid "Cyclic map"
     412msgstr ""
    409413
    410414#: tformnew.checkboxfogofwar.caption
  • trunk/Languages/xtactics.po

    r221 r229  
    393393msgctxt "tformnew.checkboxcity.caption"
    394394msgid "Cities"
     395msgstr ""
     396
     397#: tformnew.checkboxcyclicmap.caption
     398msgid "Cyclic map"
    395399msgstr ""
    396400
  • trunk/UGame.pas

    r224 r229  
    456456    VoidPercentage: Integer;
    457457    SymetricMap: Boolean;
     458    CyclicMap: Boolean;
    458459    GrowCells: TGrowCells;
    459460    GrowAmount: TGrowAmount;
     
    16131614function TMap.IsValidIndex(Index: TPoint): Boolean;
    16141615begin
    1615   Result := False;
     1616  Result := (Index.X >= 0) and (Index.X < Size.X) and
     1617    (Index.Y >= 0) and (Index.Y < Size.Y);
    16161618end;
    16171619
     
    20852087procedure TCell.ConnectTo(Cell: TCell);
    20862088begin
    2087   Cell.Neighbors.Add(Self);
    2088   Neighbors.Add(Cell);
     2089  // Connect only if already not connected
     2090  if Neighbors.IndexOf(Cell) < 0 then begin
     2091    Cell.Neighbors.Add(Self);
     2092    Neighbors.Add(Cell);
     2093  end;
    20892094end;
    20902095
     
    31363141  VoidPercentage := Source.VoidPercentage;
    31373142  SymetricMap := Source.SymetricMap;
     3143  CyclicMap := Source.CyclicMap;
    31383144  GrowCells := Source.GrowCells;
    31393145  GrowAmount := Source.GrowAmount;
     
    31573163    SetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName));
    31583164    SetValue(DOMString(Path + '/SymetricMap'), SymetricMap);
     3165    SetValue(DOMString(Path + '/CyclicMap'), CyclicMap);
    31593166    SetValue(DOMString(Path + '/FogOfWar'), FogOfWar);
    31603167    SetValue(DOMString(Path + '/VoidEnabled'), VoidEnabled);
     
    31853192    MapImageFileName := string(GetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName)));
    31863193    SymetricMap := GetValue(DOMString(Path + '/SymetricMap'), False);
     3194    CyclicMap := GetValue(DOMString(Path + '/CyclicMap'), False);
    31873195    FogOfWar := GetValue(DOMString(Path + '/FogOfWar'), False);
    31883196    VoidEnabled := GetValue(DOMString(Path + '/VoidEnabled'), True);
     
    32253233    with RootNode do begin
    32263234      SymetricMap := ReadBoolean(RootNode, 'SymetricMap', False);
     3235      CyclicMap := ReadBoolean(RootNode, 'CyclicMap', False);
    32273236      FogOfWar := ReadBoolean(RootNode, 'FogOfWar', False);
    32283237      VoidEnabled := ReadBoolean(RootNode, 'VoidEnabled', False);
     
    32763285    with RootNode do begin
    32773286      WriteBoolean(RootNode, 'SymetricMap', SymetricMap);
     3287      WriteBoolean(RootNode, 'CyclicMap', CyclicMap);
    32783288      WriteBoolean(RootNode, 'FogOfWar', FogOfWar);
    32793289      WriteBoolean(RootNode, 'VoidEnabled', VoidEnabled);
     
    34783488  TurnCounter := 1;
    34793489
     3490  Map.Cyclic := CyclicMap;
    34803491  Map.Generate;
    34813492  Map.MaxPower := MaxPower;
  • trunk/UMap.pas

    r193 r229  
    2323      CellMulY = 1.292;
    2424    function IsCellsPosNeighbor(CellPos1, CellPos2: TPoint): Boolean;
    25     procedure GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells);
     25    procedure GetCellPosNeighbors(CellPos: TPoint; Cell: TCell);
    2626    function GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPolygon;
    2727  public
    2828    procedure LoadFromFile(FileName: string); override;
    2929    procedure SaveToFile(FileName: string); override;
    30     function IsValidIndex(Index: TPoint): Boolean; override;
    3130    procedure Generate; override;
    3231  end;
     
    3837    function GetSquarePolygon(Pos: TPoint; Size: TPoint): TPolygon;
    3938  public
    40     function IsValidIndex(Index: TPoint): Boolean; override;
    4139    procedure Generate; override;
    4240  end;
     
    4846    function GetTrianglePolygon(Pos: TPoint; Size: TPoint; Reverse: Boolean): TPolygon;
    4947  public
    50     function IsValidIndex(Index: TPoint): Boolean; override;
    5148    procedure Generate; override;
    5249  end;
     
    6966    function GetTilePolygon(Pos: TPoint; Size: TPoint): TPolygon;
    7067  public
    71     function IsValidIndex(Index: TPoint): Boolean; override;
    7268    procedure Generate; override;
    7369  end;
     
    8581  Result.Points[2] := TPoint.Create(Pos.X, Trunc(Pos.Y + Size.Y / 3.5));
    8682  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);
    9383end;
    9484
     
    125115  for X := 0 to Size.X - 1 do
    126116  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]);
     117    if Cyclic then begin
     118      P := TPoint.Create(X + 0 + (Y mod 2), Y + 1);
     119      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     120      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     121      P := TPoint.Create(X - 1 + (Y mod 2), Y + 1);
     122      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     123      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     124      P := TPoint.Create(X + 0 + (Y mod 2), Y - 1);
     125      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     126      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     127      P := TPoint.Create(X - 1 + (Y mod 2), Y - 1);
     128      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     129      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     130    end else begin
     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      P := TPoint.Create(X + 0 + (Y mod 2), Y - 1);
     136      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     137      P := TPoint.Create(X - 1 + (Y mod 2), Y - 1);
     138      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     139    end;
    135140  end;
    136141
     
    206211end;
    207212
    208 function THexMap.IsValidIndex(Index: TPoint): Boolean;
    209 begin
    210   Result := (Index.X >= 0) and (Index.X < Size.X) and
    211     (Index.Y >= 0) and (Index.Y < Size.Y);
    212 end;
    213 
    214 procedure THexMap.GetCellPosNeighbors(CellPos: TPoint; Neighbours: TCells);
     213procedure THexMap.GetCellPosNeighbors(CellPos: TPoint; Cell: TCell);
    215214var
    216215  X, Y: Integer;
    217216  P: TPoint;
    218 begin
    219   Neighbours.Count := 0;
     217  PMod: TPoint;
     218begin
    220219  for Y := -1 to 1 do
    221220  for X := -1 to 1 do begin
    222221    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]);
     222    PMod := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     223    if Cyclic then begin
     224      if IsValidIndex(PMod) and IsCellsPosNeighbor(CellPos, P) then begin
     225        Cell.ConnectTo(Cells[PMod.Y * Size.X + PMod.X]);
     226      end;
     227    end else begin
     228      if IsValidIndex(P) and IsCellsPosNeighbor(CellPos, P) then begin
     229        Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
     230      end;
    225231    end;
    226232  end;
     
    258264  for X := 0 to Size.X - 1 do
    259265  with Cells[Y * Size.X + X] do begin
    260     GetCellPosNeighbors(TPoint.Create(X, Y), Neighbors);
     266    GetCellPosNeighbors(TPoint.Create(X, Y), Cells[Y * Size.X + X]);
    261267  end;
    262268
     
    292298  for X := 0 to Size.X - 1 do
    293299  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]);
     300    if Cyclic then begin
     301      P := TPoint.Create(X + 1, Y + 0);
     302      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     303      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     304      P := TPoint.Create(X + 0, Y + 1);
     305      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     306      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     307      P := TPoint.Create(X - 1, Y + 0);
     308      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     309      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     310      P := TPoint.Create(X + 0, Y - 1);
     311      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     312      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     313    end else begin
     314      P := TPoint.Create(X + 1, Y + 0);
     315      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     316      P := TPoint.Create(X + 0, Y + 1);
     317      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     318      P := TPoint.Create(X - 1, Y + 0);
     319      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     320      P := TPoint.Create(X + 0, Y - 1);
     321      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     322    end;
    302323  end;
    303324
    304325  FPixelRect := CalculatePixelRect;
    305 end;
    306 
    307 function TSquareMap.IsValidIndex(Index: TPoint): Boolean;
    308 begin
    309   Result := (Index.X >= 0) and (Index.X < Size.X) and
    310     (Index.Y >= 0) and (Index.Y < Size.Y);
    311326end;
    312327
     
    402417end;
    403418
    404 function TTriangleMap.IsValidIndex(Index: TPoint): Boolean;
    405 begin
    406   Result := (Index.X >= 0) and (Index.X < Size.X) and
    407     (Index.Y >= 0) and (Index.Y < Size.Y);
    408 end;
    409 
    410419procedure TTriangleMap.Generate;
    411420var
     
    440449    if Boolean(X mod 2) xor Boolean(Y mod 2) then Rev := -1
    441450      else Rev := 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]);
     451    if Cyclic then begin
     452      P := TPoint.Create(X + 1, Y + 0);
     453      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     454      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     455      P := TPoint.Create(X + 0, Y - 1 * Rev);
     456      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     457      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     458      P := TPoint.Create(X - 1, Y + 0);
     459      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
     460      Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     461    end else begin
     462      P := TPoint.Create(X + 1, Y + 0);
     463      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     464      P := TPoint.Create(X + 0, Y - 1 * Rev);
     465      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     466      P := TPoint.Create(X - 1, Y + 0);
     467      if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     468    end;
    448469  end;
    449470
Note: See TracChangeset for help on using the changeset viewer.