Changeset 38 for trunk/UGame.pas


Ignore:
Timestamp:
Mar 8, 2014, 10:34:55 PM (11 years ago)
Author:
chronos
Message:
  • Added: Support for cities. Cities can be used as only growing cells.
  • Added: Allow to set grow rate as square root of cell power.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r37 r38  
    2424  TPointArray = array of TPoint;
    2525
    26   TTerrainType = (ttVoid, ttNormal);
     26  TTerrainType = (ttVoid, ttNormal, ttCity);
    2727
    2828  { TCell }
     
    160160    Update: Boolean; var Confirm: Boolean) of object;
    161161  TWinEvent = procedure(Player: TPlayer) of object;
     162  TGrowAmount = (gaByOne, gaBySquareRoot);
     163  TGrowCells = (gcNone, gcPlayerCities, gcPlayerAll);
    162164
    163165  TGame = class
     
    177179    VoidEnabled: Boolean;
    178180    VoidPercentage: Integer;
     181    GrowCells: TGrowCells;
     182    GrowAmount: TGrowAmount;
     183    CityEnabled: Boolean;
     184    CityPercentage: Integer;
    179185    CurrentPlayer: TPlayer;
    180186    Moves: TObjectList; // TList<TMove>
     
    499505      CanAttack := 0;
    500506      for I := 0 to Length(Cells) - 1 do
    501       if (Cells[I].Player <> Self) then begin
     507      if (Cells[I].Player <> Self) and (Cells[I].Terrain <> ttVoid) then begin
    502508        Inc(CanAttack);
    503509      end;
     
    729735    SetValue(Path + '/MapSizeX', Map.Size.X);
    730736    SetValue(Path + '/MapSizeY', Map.Size.Y);
     737    SetValue(Path + '/CityEnabled', CityEnabled);
     738    SetValue(Path + '/CityPercentage', CityPercentage);
     739    SetValue(Path + '/GrowAmount', Integer(GrowAmount));
     740    SetValue(Path + '/GrowCells', Integer(GrowCells));
    731741  end;
    732742end;
     
    739749    Map.Size := Point(GetValue(Path + '/MapSizeX', 15),
    740750      GetValue(Path + '/MapSizeY', 15));
     751    CityEnabled := GetValue(Path + '/CityEnabled', True);
     752    CityPercentage := GetValue(Path + '/CityPercentage', 10);
     753    GrowAmount := TGrowAmount(GetValue(Path + '/GrowAmount', Integer(gaBySquareRoot)));
     754    GrowCells := TGrowCells(GetValue(Path + '/GrowCells', Integer(gcPlayerAll)));
    741755  end;
    742756end;
     
    841855  with Map.Cells[Y, X] do begin
    842856    if VoidEnabled and (Random < VoidPercentage / 100) then Terrain := ttVoid
    843       else Terrain := ttNormal;
     857      else begin
     858        if CityEnabled and (Random < CityPercentage / 100) then Terrain := ttCity
     859          else Terrain := ttNormal;
     860      end;
    844861    Power := Random(4);
    845862    Player := nil;
     
    858875          raise Exception.Create('Cannot choose start cell for player');
    859876      end;
    860       StartCell.Terrain := ttNormal;
     877      if CityEnabled then StartCell.Terrain := ttCity
     878        else StartCell.Terrain := ttNormal;
    861879      StartCell.Player := TPlayer(Players[I]);
    862880      StartCell.Power := TPlayer(Players[I]).StartUnits;
     
    950968      end;
    951969      if (CX >= 0) and (CY >= 0) and (CY < Size.Y) and (CX < Size.X) then
    952       if Cells[CY, CX].Terrain = ttNormal then begin
     970      if Cells[CY, CX].Terrain <> ttVoid then begin
    953971        Points := GetHexagonPolygon(Point(Trunc(X * CellSize.X),
    954972          Trunc(Y * CellSize.Y)),
     
    10041022      Pen.Style := psSolid;
    10051023      Pen.Width := 1;
     1024    end else
     1025    if TCell(Cells[CY, CX]).Terrain = ttCity then begin
     1026      // Cannot set clear border as it will display shifted on gtk2
     1027      //Pen.Style := psClear;
     1028      Pen.Color := clBlack;
     1029      Pen.Style := psSolid;
     1030      Pen.Width := 3;
    10061031    end else begin
    1007       Pen.Color := clBlack;
    10081032      // Cannot set clear border as it will display shifted on gtk2
    10091033      //Pen.Style := psClear;
     
    10381062      if (CX >= 0) and (CY >= 0) and (CY < Size.Y) and (CX < Size.X) then begin
    10391063        Cell := Cells[CY, CX];
    1040         if Cell.Terrain = ttNormal then begin
     1064        if Cell.Terrain <> ttVoid then begin
    10411065          if Assigned(SelectedCell) and (SelectedCell = TCell(Cells[CY, CX])) then Brush.Color := clGreen
    10421066            else if Assigned(SelectedCell) and IsCellsNeighbor(SelectedCell, TCell(Cells[CY, CX])) then Brush.Color := clPurple
     
    10821106var
    10831107  X, Y: Integer;
     1108  Addition: Integer;
    10841109begin
    10851110  for Y := 0 to Size.Y - 1 do
    10861111  for X := 0 to Size.X - 1 do
    10871112  with TCell(Cells[Y, X]) do begin
    1088     if Player = APlayer then begin
    1089       Power := Power + 1;
     1113    if (Player = APlayer) and ((Game.GrowCells = gcPlayerAll) or
     1114    ((Game.GrowCells = gcPlayerCities) and (Terrain = ttCity))) then begin
     1115      if Game.GrowAmount = gaByOne then Addition := 1
     1116        else if Game.GrowAmount = gaBySquareRoot then begin
     1117          Addition := Trunc(Sqrt(Power));
     1118          if Addition = 0 then Addition := 1;
     1119        end;
     1120      Power := Power + Addition;
    10901121      if Power > MaxPower then Power := MaxPower;
    10911122    end;
Note: See TracChangeset for help on using the changeset viewer.