Changeset 342 for trunk/Game.pas


Ignore:
Timestamp:
Dec 22, 2024, 10:52:26 AM (10 hours ago)
Author:
chronos
Message:
  • Added: More tests.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Game.pas

    r339 r342  
    66  Classes, SysUtils, ExtCtrls, Graphics, XMLConf, XMLRead, XMLWrite, Forms,
    77  DOM, Math, LazFileUtils, XML, Dialogs, LCLType, LCLIntf, Building, Geometry,
    8   Player, Map, MapType, &Unit, GameSystem;
     8  Player, Map, MapType, Units, GameSystem;
    99
    1010const
     
    4949    procedure SetRunning(AValue: Boolean);
    5050    procedure BuildTerrain;
     51    procedure PlaceUnits;
    5152    procedure PlaceCities;
    5253    procedure InitPlayers;
     
    9192    procedure LoadFromFile(FileName: string);
    9293    procedure SaveToFile(FileName: string);
     94    function ToString: string; override;
    9395    procedure ComputePlayerStats;
    9496    procedure NextPlayer;
     
    301303    (Map.IsOutsideShape(PosPx)) then Terrain := ttVoid
    302304      else Terrain := ttNormal;
     305  end;
     306end;
     307
     308procedure TGame.PlaceUnits;
     309var
     310  Cell: TCell;
     311  NewPower: Integer;
     312begin
     313  if GameSystem.UnitKinds.Count = 0 then Exit;
     314
     315  for Cell in Map.Cells do
     316  with Cell do begin
    303317    NewPower := Random(MaxNeutralUnits + 1);
    304318    if (NewPower > 0) and not Assigned(OneUnit) then begin
     
    348362        end;
    349363        StartCell.Player := Player;
    350         if not Assigned(StartCell.OneUnit) then
    351           StartCell.OneUnit := Self.Units.AddNew(TUnitKind(GameSystem.UnitKinds[0]), Player.StartUnits);
    352         StartCell.OneUnit.Power := Player.StartUnits;
    353         StartCell.OneUnit.Kind := TUnitKind(GameSystem.UnitKinds[0]);
    354         StartCell.OneUnit.Player := Player;
     364        if GameSystem.UnitKinds.Count > 0 then begin
     365          if not Assigned(StartCell.OneUnit) then
     366            StartCell.OneUnit := Self.Units.AddNew(TUnitKind(GameSystem.UnitKinds[0]), Player.StartUnits);
     367          StartCell.OneUnit.Power := Player.StartUnits;
     368          StartCell.OneUnit.Kind := TUnitKind(GameSystem.UnitKinds[0]);
     369          StartCell.OneUnit.Player := Player;
     370        end;
    355371      end;
    356372    end;
     
    694710end;
    695711
     712function TGame.ToString: string;
     713begin
     714  Result := 'StoredRandSeed: ' + IntToStr(StoredRandSeed) + LineEnding;
     715  Result := Result + 'MapType: ' + IntToStr(Integer(MapType)) + LineEnding;
     716  Result := Result + 'SymetricMap: ' + BoolToStr(SymetricMap) + LineEnding;
     717  Result := Result + 'CyclicMap: ' + BoolToStr(CyclicMap) + LineEnding;
     718  Result := Result + 'FogOfWar: ' + BoolToStr(FogOfWar) + LineEnding;
     719  Result := Result + 'VoidEnabled: ' + BoolToStr(VoidEnabled) + LineEnding;
     720  Result := Result + 'VoidPercentage: ' + IntToStr(VoidPercentage) + LineEnding;
     721  Result := Result + 'MaxNeutralUnits: ' + IntToStr(MaxNeutralUnits) + LineEnding;
     722  Result := Result + 'MaxPower: ' + IntToStr(MaxPower) + LineEnding;
     723  Result := Result + 'GrowCells: ' + IntToStr(Integer(GrowCells)) + LineEnding;
     724  Result := Result + 'GrowAmount: ' + IntToStr(Integer(GrowAmount)) + LineEnding;
     725  Result := Result + 'CityEnabled: ' + BoolToStr(CityEnabled) + LineEnding;
     726  Result := Result + 'CityPercentage: ' + IntToStr(CityPercentage) + LineEnding;
     727  Result := Result + 'BridgeEnabled: ' + BoolToStr(BridgeEnabled) + LineEnding;
     728  Result := Result + 'TurnCounter: ' + IntToStr(TurnCounter) + LineEnding;
     729  Result := Result + 'WinObjective: ' + IntToStr(Integer(WinObjective)) + LineEnding;
     730  Result := Result + 'StayAliveForDefinedTurns: ' + IntToStr(StayAliveForDefinedTurns) + LineEnding;
     731  Result := Result + 'Running: ' + BoolToStr(Running) + LineEnding;
     732  Result := Result + 'GameSystem: ' + LineEnding + GameSystem.ToString + LineEnding;
     733  Result := Result + 'Map: ' + LineEnding + Map.ToString + LineEnding;
     734  Result := Result + 'Players: ' + LineEnding + Players.ToString + LineEnding;
     735  Result := Result + 'Units: ' + LineEnding + Units.ToString + LineEnding;
     736end;
     737
    696738procedure TGame.ComputePlayerStats;
    697739var
     
    905947  Map.MaxPower := MaxPower;
    906948  BuildTerrain;
     949  PlaceUnits;
    907950  PlaceCities;
    908951  WinObjectiveMapPrepare;
     
    931974function TGame.Compare(Game: TGame): Boolean;
    932975begin
    933   Result := BridgeEnabled = Game.BridgeEnabled;
     976  Result := (StoredRandSeed = Game.StoredRandSeed) and
     977    (DevelMode = Game.DevelMode) and
     978    Players.Compare(Game.Players) and
     979    (MapType = Game.MapType) and
     980    Map.Compare(Game.Map) and
     981    (MapImageFileName = Game.MapImageFileName) and
     982    (VoidEnabled = Game.VoidEnabled) and
     983    (VoidPercentage = Game.VoidPercentage) and
     984    (SymetricMap = Game.SymetricMap) and
     985    (CyclicMap = Game.CyclicMap) and
     986    (GrowCells = Game.GrowCells) and
     987    (GrowAmount = Game.GrowAmount) and
     988    (CityEnabled = Game.CityEnabled) and
     989    (CityPercentage = Game.CityPercentage) and
     990    (TurnCounter = Game.TurnCounter) and
     991    (WinObjective = Game.WinObjective) and
     992    (SpecialCaptureCellCount = Game.SpecialCaptureCellCount) and
     993    (StayAliveForDefinedTurns = Game.StayAliveForDefinedTurns) and
     994    (MaxNeutralUnits = Game.MaxNeutralUnits) and
     995    (FileName = Game.FileName) and
     996    (FogOfWar = Game.FogOfWar) and
     997    (BridgeEnabled = Game.BridgeEnabled) and
     998    (MaxPower = Game.MaxPower) and
     999    GameSystem.Compare(Game.GameSystem);
    9341000end;
    9351001
Note: See TracChangeset for help on using the changeset viewer.