close Warning: Can't synchronize with repository "(default)" (No changeset 184 in the repository). Look in the Trac log for more information.

Changeset 47


Ignore:
Timestamp:
Aug 17, 2014, 2:02:43 AM (10 years ago)
Author:
chronos
Message:
  • Modified: Cell neightbors list is now attached to each cell as it will not be possible to easily calucalte it for generic mesh. Neighbour relation will be generated during map generation.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormAbout.lfm

    r43 r47  
    2626    object Memo1: TMemo
    2727      Left = 8
    28       Height = 161
     28      Height = 157
    2929      Top = 8
    30       Width = 281
     30      Width = 277
    3131      Anchors = [akTop, akLeft, akRight, akBottom]
    3232      BorderStyle = bsNone
  • trunk/Forms/UFormAbout.pas

    r43 r47  
    77uses
    88  SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
    9   Buttons, ExtCtrls, UApplicationInfo;
     9  Buttons, ExtCtrls;
    1010
    1111type
  • trunk/Forms/UFormNew.lfm

    r42 r47  
    127127    object CheckBoxVoid: TCheckBox
    128128      Left = 8
    129       Height = 24
     129      Height = 27
    130130      Top = 101
    131       Width = 175
     131      Width = 198
    132132      Caption = 'Inaccessible places'
    133133      OnChange = CheckBoxVoidChange
     
    136136    object Label1: TLabel
    137137      Left = 8
    138       Height = 22
     138      Height = 25
    139139      Top = 9
    140       Width = 88
     140      Width = 104
    141141      Caption = 'Map width:'
    142142      ParentColor = False
     
    144144    object SpinEditMapSizeX: TSpinEdit
    145145      Left = 128
    146       Height = 32
     146      Height = 35
    147147      Top = 4
    148148      Width = 98
     
    154154    object SpinEditMapSizeY: TSpinEdit
    155155      Left = 128
    156       Height = 32
     156      Height = 35
    157157      Top = 55
    158158      Width = 98
     
    164164    object SpinEditVoidPercent: TSpinEdit
    165165      Left = 216
    166       Height = 32
     166      Height = 35
    167167      Top = 97
    168168      Width = 106
     
    173173    object Label3: TLabel
    174174      Left = 331
    175       Height = 22
     175      Height = 25
    176176      Top = 102
    177       Width = 15
     177      Width = 17
    178178      Caption = '%'
    179179      ParentColor = False
     
    181181    object TrackBarSizeX: TTrackBar
    182182      Left = 240
    183       Height = 43
     183      Height = 46
    184184      Top = 1
    185185      Width = 451
     
    194194    object TrackBarSizeY: TTrackBar
    195195      Left = 240
    196       Height = 43
     196      Height = 46
    197197      Top = 49
    198198      Width = 451
     
    207207    object Label2: TLabel
    208208      Left = 8
    209       Height = 22
     209      Height = 25
    210210      Top = 57
    211       Width = 94
     211      Width = 110
    212212      Caption = 'Map height:'
    213213      ParentColor = False
     
    215215    object CheckBoxCity: TCheckBox
    216216      Left = 8
    217       Height = 24
     217      Height = 27
    218218      Top = 141
    219       Width = 68
     219      Width = 73
    220220      Caption = 'Cities'
    221221      OnChange = CheckBoxCityChange
     
    224224    object SpinEditCityPercent: TSpinEdit
    225225      Left = 216
    226       Height = 32
     226      Height = 35
    227227      Top = 137
    228228      Width = 106
     
    233233    object Label4: TLabel
    234234      Left = 331
    235       Height = 22
     235      Height = 25
    236236      Top = 142
    237       Width = 15
     237      Width = 17
    238238      Caption = '%'
    239239      ParentColor = False
     
    253253      ChildSizing.Layout = cclLeftToRightThenTopToBottom
    254254      ChildSizing.ControlsPerLine = 1
    255       ClientHeight = 52
     255      ClientHeight = 49
    256256      ClientWidth = 237
    257257      Items.Strings = (
     
    275275      ChildSizing.Layout = cclLeftToRightThenTopToBottom
    276276      ChildSizing.ControlsPerLine = 1
    277       ClientHeight = 81
     277      ClientHeight = 78
    278278      ClientWidth = 181
    279279      Items.Strings = (
     
    286286    object ComboBoxGridType: TComboBox
    287287      Left = 312
    288       Height = 30
     288      Height = 37
    289289      Top = 201
    290290      Width = 208
     
    293293        'Hexagonal'
    294294        'Square'
     295        'Triangular'
    295296      )
    296297      Style = csDropDownList
     
    299300    object Label5: TLabel
    300301      Left = 216
    301       Height = 22
     302      Height = 25
    302303      Top = 201
    303       Width = 79
     304      Width = 90
    304305      Caption = 'Grid type:'
    305306      ParentColor = False
     
    307308    object Label6: TLabel
    308309      Left = 8
    309       Height = 22
     310      Height = 25
    310311      Top = 313
    311       Width = 114
     312      Width = 129
    312313      Caption = 'Win objective:'
    313314      ParentColor = False
     
    315316    object ComboBoxWinObjective: TComboBox
    316317      Left = 160
    317       Height = 30
     318      Height = 37
    318319      Top = 305
    319320      Width = 208
     
    330331    object Label7: TLabel
    331332      Left = 8
    332       Height = 22
     333      Height = 25
    333334      Top = 348
    334       Width = 211
     335      Width = 245
    335336      Caption = 'Max random neutral units:'
    336337      ParentColor = False
     
    338339    object SpinEditNeutralUnits: TSpinEdit
    339340      Left = 272
    340       Height = 32
     341      Height = 35
    341342      Top = 343
    342343      Width = 98
  • trunk/UGame.pas

    r42 r47  
    4141    MovesFrom: TObjectList; // TList<TMove>
    4242    MovesTo: TObjectList; // TList<TMove>
     43    Neighbors: TObjectList; // TList<TCell>
    4344    function GetColor: TColor;
    4445    function GetAvialPower: Integer;
     
    9899    procedure Grow(APlayer: TPlayer); virtual;
    99100    procedure ComputePlayerStats; virtual;
     101    procedure Generate; virtual;
    100102    constructor Create; virtual;
    101103    destructor Destroy; override;
    102     function GetCellNeighbours(Cell: TCell): TCellArray; virtual;
     104    function GetCellNeighbors(Cell: TCell): TCellArray; virtual;
    103105    procedure Paint(Canvas: TCanvas; View: TView); virtual;
    104106    function GetPixelRect: TRect; virtual;
     
    115117    function GetSize: TPoint; override;
    116118    procedure SetSize(AValue: TPoint); override;
     119    function IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean;
     120    function GetCellNeighbors2(Cell: TCell): TCellArray;
    117121  public
    118122    Cells: array of array of TCell;
    119     function IsCellsNeighbor(Cell1, Cell2: TCell): Boolean; override;
    120     procedure Assign(Source: TMap); virtual;
     123    procedure Assign(Source: TMap); override;
    121124    procedure LoadFromFile(FileName: string); override;
    122125    procedure SaveToFile(FileName: string); override;
    123126    function IsValidIndex(Index: TPoint): Boolean; override;
    124     function GetCellNeighbours(Cell: TCell): TCellArray; override;
    125127    function PosToCell(Pos: TPoint; View: TView): TCell; override;
    126128    function CellToPos(Cell: TCell): TPoint; override;
    127129    function GetHexagonPolygon(Pos: TPoint; HexSize: TPoint): TPointArray;
    128130    procedure Paint(Canvas: TCanvas; View: TView); override;
     131    procedure Generate; override;
    129132    constructor Create; override;
    130133    destructor Destroy; override;
     
    140143    function GetSize: TPoint; override;
    141144    procedure SetSize(AValue: TPoint); override;
     145    function IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean;
     146    function GetCellNeighbours2(Cell: TCell): TCellArray;
    142147  public
    143148    Cells: array of array of TCell;
    144     function IsCellsNeighbor(Cell1, Cell2: TCell): Boolean; override;
    145149    function IsValidIndex(Index: TPoint): Boolean; override;
    146150    function PosToCell(Pos: TPoint; View: TView): TCell; override;
    147151    function CellToPos(Cell: TCell): TPoint; override;
    148     function GetCellNeighbours(Cell: TCell): TCellArray; override;
    149152    function GetAllCells: TCellArray; override;
    150153    function GetPixelRect: TRect; override;
     
    359362end;
    360363
    361 function TSquareMap.IsCellsNeighbor(Cell1, Cell2: TCell): Boolean;
     364function TSquareMap.IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean;
    362365var
    363366  DX: Integer;
     
    427430end;
    428431
    429 function TSquareMap.GetCellNeighbours(Cell: TCell): TCellArray;
     432function TSquareMap.GetCellNeighbours2(Cell: TCell): TCellArray;
    430433var
    431434  X, Y: Integer;
     
    435438  for X := -1 to 1 do
    436439  if IsValidIndex(Point(Cell.Pos.X + X, Cell.Pos.Y + Y)) and
    437   IsCellsNeighbor(Cell, Cells[Cell.Pos.Y + Y, Cell.Pos.X + X]) then begin
     440  IsCellsNeighbor2(Cell, Cells[Cell.Pos.Y + Y, Cell.Pos.X + X]) then begin
    438441    SetLength(Result, Length(Result) + 1);
    439442    Result[Length(Result) - 1] := Cells[Cell.Pos.Y + Y, Cell.Pos.X + X];
     
    608611function TMap.IsCellsNeighbor(Cell1, Cell2: TCell): Boolean;
    609612begin
    610   Result := False;
     613  Result := Cell1.Neighbors.IndexOf(Cell2) <> -1;
    611614end;
    612615
     
    683686end;
    684687
     688procedure TMap.Generate;
     689begin
     690end;
     691
    685692constructor TMap.Create;
    686693begin
     
    695702end;
    696703
    697 function TMap.GetCellNeighbours(Cell: TCell): TCellArray;
    698 begin
    699 
     704function TMap.GetCellNeighbors(Cell: TCell): TCellArray;
     705var
     706  I: Integer;
     707begin
     708  SetLength(Result, Cell.Neighbors.Count);
     709  for I := 0 to Length(Result) - 1 do
     710    Result[I] := TCell(Cell.Neighbors[I]);
    700711end;
    701712
     
    729740function TMap.GetAllCells: TCellArray;
    730741begin
    731 
     742  SetLength(Result, 0);
    732743end;
    733744
     
    861872begin
    862873  Player := nil;
     874  Neighbors := TObjectList.Create;
     875  Neighbors.OwnsObjects := False;
    863876  MovesFrom := TObjectList.Create;
    864877  MovesFrom.OwnsObjects := False;
     
    877890    TUnitMove(MovesTo[I]).Free;
    878891  FreeAndNil(MovesTo);
     892  FreeAndNil(Neighbors);
    879893  inherited Destroy;
    880894end;
     
    940954      // Attack to not owned cell yet
    941955      // Count own possible power
    942       Cells := Game.Map.GetCellNeighbours(AllCells[C]);
     956      Cells := Game.Map.GetCellNeighbors(AllCells[C]);
    943957      TotalPower := 0;
    944958      for I := 0 to Length(Cells) - 1 do
     
    964978      // We need to move available power to borders to be available for attacks
    965979      // or defense
    966       Cells := Game.Map.GetCellNeighbours(AllCells[C]);
     980      Cells := Game.Map.GetCellNeighbors(AllCells[C]);
    967981      CanAttack := 0;
    968982      for I := 0 to Length(Cells) - 1 do
     
    11251139    mtHexagon: Map := THexMap.Create;
    11261140    mtSquare: Map := TSquareMap.Create;
     1141    else Map := TMap.Create;
    11271142  end;
    11281143  Map.Assign(OldMap);
     
    11411156begin
    11421157  I := 0;
     1158  Confirm := True;
    11431159  while (I < Moves.Count) and ((TUnitMove(Moves[I]).CellFrom <> CellFrom) or
    11441160    (TUnitMove(Moves[I]).CellTo <> CellTo)) do Inc(I);
     
    12251241
    12261242procedure TGame.LoadConfig(Config: TXmlConfig; Path: string);
     1243var
     1244  P: TPoint;
    12271245begin
    12281246  with Config do begin
     
    14391457
    14401458procedure THexMap.SetSize(AValue: TPoint);
    1441 var
    1442   X, Y: Integer;
    1443   NewCell: TCell;
    1444   C: Integer;
    14451459begin
    14461460  if (FSize.X <> AValue.X) or (FSize.Y <> AValue.Y) then begin
    1447     // Free previous
    1448     for Y := 0 to FSize.Y - 1 do
    1449     for X := 0 to FSize.X - 1 do begin
    1450       TCell(Cells[Y, X]).Destroy;
    1451     end;
    14521461    FSize := AValue;
    1453     // Allocate and init new
    1454     SetLength(Cells, FSize.Y, FSize.X);
    1455     for Y := 0 to FSize.Y - 1 do
    1456     for X := 0 to FSize.X - 1 do begin
    1457       NewCell := TCell.Create;
    1458       NewCell.Pos := Point(X, Y);
    1459       Cells[Y, X] := NewCell;
    1460     end;
    1461   end;
    1462 end;
    1463 
    1464 function THexMap.IsCellsNeighbor(Cell1, Cell2: TCell): Boolean;
     1462    Generate;
     1463  end;
     1464end;
     1465
     1466function THexMap.IsCellsNeighbor2(Cell1, Cell2: TCell): Boolean;
    14651467var
    14661468  DX: Integer;
     
    14841486procedure THexMap.Assign(Source: TMap);
    14851487begin
     1488  inherited;
    14861489end;
    14871490
     
    15221525end;
    15231526
    1524 function THexMap.GetCellNeighbours(Cell: TCell): TCellArray;
     1527function THexMap.GetCellNeighbors2(Cell: TCell): TCellArray;
    15251528var
    15261529  X, Y: Integer;
     
    15301533  for X := -1 to 1 do
    15311534  if IsValidIndex(Point(Cell.Pos.X + X, Cell.Pos.Y + Y)) and
    1532   IsCellsNeighbor(Cell, Cells[Cell.Pos.Y + Y, Cell.Pos.X + X]) then begin
     1535  IsCellsNeighbor2(Cell, Cells[Cell.Pos.Y + Y, Cell.Pos.X + X]) then begin
    15331536    SetLength(Result, Length(Result) + 1);
    15341537    Result[Length(Result) - 1] := Cells[Cell.Pos.Y + Y, Cell.Pos.X + X];
     
    16861689end;
    16871690
     1691procedure THexMap.Generate;
     1692var
     1693  X, Y: Integer;
     1694  I: Integer;
     1695  NewCell: TCell;
     1696  NeighCells: TCellArray;
     1697begin
     1698  // Free previous
     1699  for Y := 0 to Length(Cells) - 1 do
     1700  for X := 0 to Length(Cells[Y]) - 1 do begin
     1701    TCell(Cells[Y, X]).Destroy;
     1702  end;
     1703  // Allocate and init new
     1704  SetLength(Cells, FSize.Y, FSize.X);
     1705  for Y := 0 to FSize.Y - 1 do
     1706  for X := 0 to FSize.X - 1 do begin
     1707    NewCell := TCell.Create;
     1708    NewCell.Pos := Point(X, Y);
     1709    Cells[Y, X] := NewCell;
     1710  end;
     1711  // Generate neightbours
     1712  for Y := 0 to FSize.Y - 1 do
     1713  for X := 0 to FSize.X - 1 do begin
     1714    NeighCells := GetCellNeighbors2(Cells[Y, X]);
     1715    for I := 0 to Length(NeighCells) - 1 do
     1716      Cells[Y, X].Neighbors.Add(NeighCells[I]);
     1717  end;
     1718end;
     1719
    16881720constructor THexMap.Create;
    16891721begin
  • trunk/xtactics.lpi

    r46 r47  
    163163      <SyntaxOptions>
    164164        <SyntaxMode Value="Delphi"/>
     165        <CStyleOperator Value="False"/>
    165166        <IncludeAssertionCode Value="True"/>
     167        <AllowLabel Value="False"/>
     168        <CPPInline Value="False"/>
    166169      </SyntaxOptions>
    167170    </Parsing>
     
    173176        <StackChecks Value="True"/>
    174177      </Checks>
     178      <VerifyObjMethodCallValidity Value="True"/>
    175179    </CodeGeneration>
    176180    <Linking>
Note: See TracChangeset for help on using the changeset viewer.