Changeset 265 for trunk/UMap.pas


Ignore:
Timestamp:
Jan 15, 2019, 1:03:40 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Cell power is now internally represented as unit power (TUnit class).
  • Modified: Allow to have only one player in the game.
  • Added: New win objective None to just play freely without any win objective.
  • Added: New win objective to capture entire map.
  • Added: TGameSystem class to represent various game play systems of other existing games.
  • Fixed: Clear correctly defender player from unit moves if his cell is captured.
  • Fixed: Do not allow to remove too many players to have at least minimum players.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMap.pas

    r258 r265  
    77uses
    88  Classes, SysUtils, Graphics, ExtCtrls, UGeometry, DOM, fgl,
    9   UXMLUtils;
     9  UXMLUtils, UUnit;
    1010
    1111const
     
    3030    FMap: TMap;
    3131    FPower: Integer;
     32    FUnit: TUnit;
     33    function GetPower: Integer;
    3234    procedure SetArea(AValue: TMapArea);
    3335    procedure SetId(AValue: Integer);
    3436    procedure SetPower(AValue: Integer);
     37    procedure SetUnit(AValue: TUnit);
    3538  public
    3639    PosPx: TPoint;
    3740    Polygon: TPolygon;
    3841    Terrain: TTerrainType;
    39     PlayerId: Integer;
     42    PlayerId: Integer; // Temporary value
    4043    Player: TObject; // TPlayer;
    4144    NeighborsId: array of Integer;
     
    4447    Weight: Integer; // Temporary value
    4548    Angle: Double; // Temporary value
    46     PlayerCell: Pointer; // Temporary value
     49    PlayerCell: TObject; // Temporary value
    4750    Links: TCellLinks;
    4851    Extra: TExtraType;
    49     property Id: Integer read FId write SetId;
     52    OneUnitId: Integer; // Temporary value
    5053    procedure ConnectTo(Cell: TCell);
    5154    procedure DisconnectFrom(Cell: TCell);
     
    6063    constructor Create;
    6164    destructor Destroy; override;
    62     property Power: Integer read FPower write SetPower;
     65    property Id: Integer read FId write SetId;
    6366    property Map: TMap read FMap write FMap;
    6467    property Area: TMapArea read FArea write SetArea;
     68    property OneUnit: TUnit read FUnit write SetUnit;
     69    //property Power: Integer read GetPower;
    6570  end;
    6671
     
    612617    with TPlayer(Player) do begin
    613618      Inc(TotalCells);
    614       Inc(TotalUnits, Power);
     619      if Assigned(OneUnit) then
     620        Inc(TotalUnits, OneUnit.Power);
    615621      if Terrain = ttCity then
    616622        Inc(TotalCities);
     
    656662  for C := 0 to (Cells.Count div 2) - 1 do begin
    657663    Cells[C].Terrain := Cells[Cells.Count - 1 - C].Terrain;
    658     Cells[C].Power := Cells[Cells.Count - 1 - C].Power;
     664    Cells[C].OneUnit.Power := Cells[Cells.Count - 1 - C].OneUnit.Power;
    659665
    660666    for I := Cells[C].Links.Count - 1 downto 0 do begin
     
    908914end;
    909915
     916procedure TCell.SetUnit(AValue: TUnit);
     917var
     918  OldValue: TUnit;
     919begin
     920  if FUnit = AValue then Exit;
     921  OldValue := FUnit;
     922  FUnit := nil;
     923  if Assigned(OldValue) then OldValue.MapCell := nil;
     924  FUnit := AValue;
     925  if Assigned(FUnit) then FUnit.MapCell := Self;
     926end;
     927
    910928procedure TCell.ConnectTo(Cell: TCell);
    911929begin
     
    950968end;
    951969
     970function TCell.GetPower: Integer;
     971begin
     972  if Assigned(OneUnit) then Result := OneUnit.Power
     973    else Result := 0;
     974end;
     975
    952976procedure TCell.SetId(AValue: Integer);
    953977begin
     
    973997begin
    974998  Player := TGame(Map.Game).Players.FindById(PlayerId);
     999  OneUnit := TGame(Map.Game).Units.FindById(OneUnitId);
    9751000
    9761001  Neighbors.Count := Length(NeighborsId);
     
    9931018begin
    9941019  Id := ReadInteger(Node, 'Id', 0);
    995   Power := ReadInteger(Node, 'Power', 0);
     1020  OneUnitId := ReadInteger(Node, 'Unit', 0);
    9961021  Terrain := TTerrainType(ReadInteger(Node, 'Terrain', Integer(ttVoid)));
    9971022  Extra := TExtraType(ReadInteger(Node, 'Extra', Integer(etNone)));
     
    10291054begin
    10301055  WriteInteger(Node, 'Id', Id);
    1031   WriteInteger(Node, 'Power', Power);
     1056  if Assigned(OneUnit) then
     1057    WriteInteger(Node, 'Unit', OneUnit.Id)
     1058    else WriteInteger(Node, 'Unit', 0);
    10321059  WriteInteger(Node, 'Terrain', Integer(Terrain));
    10331060  WriteInteger(Node, 'Extra', Integer(Extra));
     
    10901117  I: Integer;
    10911118begin
     1119  OneUnit := nil;
    10921120  for I := Links.Count - 1 downto 0 do
    10931121    FMap.CellLinks.Remove(Links[I]);
Note: See TracChangeset for help on using the changeset viewer.