Changeset 198 for trunk/UGame.pas


Ignore:
Timestamp:
May 16, 2018, 1:38:11 PM (6 years ago)
Author:
chronos
Message:
  • Added: Capture all special cells objective is now functional. Number of such cells can be specified. They are randomly spread across map and such cells are marked with "!" symbol after its number of units.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r197 r198  
    3030
    3131  TTerrainType = (ttVoid, ttNormal, ttCity);
     32  TExtraType = (etNone, etObjectiveTarget, etAttack, etDefense, etLookout,
     33    etGrowLow, etGrowMedium, etGrowHigh);
    3234
    3335  { TCell }
     
    5557    Angle: Double; // Temporary value
    5658    Links: TCellLinks;
     59    Extra: TExtraType;
    5760    procedure ConnectTo(Cell: TCell);
    5861    procedure DisconnectFrom(Cell: TCell);
     
    8588    function FindById(Id: Integer): TCell;
    8689    procedure GetCellsWithWeight(List: TCells; Low, High: Integer);
     90    procedure GetCellsWithExtra(List: TCells; Extra: TExtraType);
    8791    procedure LoadFromNode(Node: TDOMNode);
    8892    procedure SaveToNode(Node: TDOMNode);
     
    439443    procedure PropagatePlayerDistance(List: TCells);
    440444    procedure InitDefaultPlayersSetting;
     445    procedure WinObjectiveMapPrepare;
    441446  public
    442447    DevelMode: Boolean;
     
    455460    TurnCounter: Integer;
    456461    WinObjective: TWinObjective;
    457     SpecialCaptureCell: TCell;
     462    SpecialCaptureCellCount: Integer;
    458463    StayAliveForDefinedTurns: Integer;
    459464    MaxNeutralUnits: Integer;
     
    10201025    if (Cell.Terrain <> ttVoid) and (Cell.Weight >= Low) and
    10211026      (Cell.Weight <= High) then List.Add(Cell);
     1027end;
     1028
     1029procedure TCells.GetCellsWithExtra(List: TCells; Extra: TExtraType);
     1030var
     1031  Cell: TCell;
     1032begin
     1033  List.Clear;
     1034  for Cell in Self do
     1035    if Cell.Extra = Extra then List.Add(Cell);
    10221036end;
    10231037
     
    14961510  TextSize: TSize;
    14971511begin
     1512  if Cell.Extra = etObjectiveTarget then begin
     1513    Text := Text + '!';
     1514  end;
    14981515  with Canvas do begin
    14991516    if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin
     
    15261543
    15271544    // Show cell text
    1528     if Text <> '0' then begin
     1545    if Cell.GetAvialPower <> 0 then begin
    15291546      Pen.Style := psSolid;
    15301547      Font.Color := clWhite;
     
    18901907  Power := ReadInteger(Node, 'Power', 0);
    18911908  Terrain := TTerrainType(ReadInteger(Node, 'Terrain', Integer(ttVoid)));
     1909  Extra := TExtraType(ReadInteger(Node, 'Extra', Integer(etNone)));
    18921910  PosPx.X := ReadInteger(Node, 'PosX', 0);
    18931911  PosPx.Y := ReadInteger(Node, 'PosY', 0);
     
    19251943  WriteInteger(Node, 'Power', Power);
    19261944  WriteInteger(Node, 'Terrain', Integer(Terrain));
     1945  WriteInteger(Node, 'Extra', Integer(Extra));
    19271946  WriteInteger(Node, 'PosX', PosPx.X);
    19281947  WriteInteger(Node, 'PosY', PosPx.Y);
     
    29662985        PaintCell(Canvas, Cell.PosPx, IntToStr(Cell.GetAvialPower), View, Cell);
    29672986      end;
    2968 
    29692987    end;
    29702988
     
    31883206end;
    31893207
     3208procedure TGame.WinObjectiveMapPrepare;
     3209var
     3210  Cell: TCell;
     3211  Cells: TCells;
     3212  I: Integer;
     3213begin
     3214  if WinObjective = woSpecialCaptureCell then begin
     3215    Cells := TCells.Create(False);
     3216    for I := 0 to Map.Cells.Count - 1 do
     3217    if (Map.Cells[I].Terrain <> ttVoid) and (Map.Cells[I].Extra <> etObjectiveTarget) then
     3218      Cells.Add(Map.Cells[I]);
     3219
     3220    for I := 0 to SpecialCaptureCellCount - 1 do begin
     3221      if Cells.Count = 0 then Break;
     3222      Cell := Cells[Random(Cells.Count)];
     3223      Cell.Extra := etObjectiveTarget;
     3224      Cells.Remove(Cell);
     3225    end;
     3226    Cells.Free;
     3227  end;
     3228end;
     3229
    31903230procedure TGame.SaveConfig(Config: TXmlConfig; Path: string);
    31913231begin
     
    32073247    SetValue(DOMString(Path + '/WinObjective'), Integer(WinObjective));
    32083248    SetValue(DOMString(Path + '/StayAliveForDefinedTurns'), StayAliveForDefinedTurns);
     3249    SetValue(DOMString(Path + '/SpecialCaptureCellCount'), SpecialCaptureCellCount);
    32093250    PlayersSetting.SaveConfig(Config, Path + '/Players');
    32103251  end;
     
    32403281      WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective);
    32413282    StayAliveForDefinedTurns := GetValue(DOMString(Path + '/StayAliveForDefinedTurns'), 20);
     3283    SpecialCaptureCellCount := GetValue(DOMString(Path + '/SpecialCaptureCellCount'), 1);
    32423284    PlayersSetting.LoadConfig(Config, Path + '/Players');
    32433285  end;
     
    34123454  AlivePlayers: TPlayerArray;
    34133455  Winner: TPlayer;
     3456  Cells: TCells;
     3457  Player: TPlayer;
     3458  R: Boolean;
     3459  I: Integer;
    34143460begin
    34153461  Winner := nil;
     
    34293475  end else
    34303476  if WinObjective = woSpecialCaptureCell then begin
    3431     if Assigned(SpecialCaptureCell) and Assigned(SpecialCaptureCell.Player) then
    3432       EndGame(SpecialCaptureCell.Player);
     3477    Cells := TCells.Create(False);
     3478    Map.Cells.GetCellsWithExtra(Cells, etObjectiveTarget);
     3479    R := True;
     3480    for I := 0 to Cells.Count - 1 do begin
     3481      if I = 0 then Player := Cells[I].Player;
     3482      if not Assigned(Cells[I].Player) or (Cells[I].Player <> Player) then begin
     3483        R := False;
     3484        Break;
     3485      end;
     3486    end;
     3487    if R then EndGame(Player);
     3488    Cells.Free;
    34333489  end else
    34343490  if WinObjective = woStayAliveForDefinedTurns then begin
     
    34853541  Map.MaxPower := MaxPower;
    34863542  BuildTerrain;
     3543  WinObjectiveMapPrepare;
    34873544
    34883545  // Build bridges
Note: See TracChangeset for help on using the changeset viewer.