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

Changeset 145 for trunk/UGame.pas


Ignore:
Timestamp:
Nov 12, 2017, 1:47:20 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Do not create settings form on application start but just if form is opened.
  • Fixed: Removed various compilation warnings.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r142 r145  
    77uses
    88  Classes, SysUtils, ExtCtrls, Graphics, Contnrs, XMLConf, XMLRead, XMLWrite,
    9   DOM, Math, LazFileUtils, UXMLUtils, Dialogs, Types, LCLType, LCLIntf;
     9  DOM, Math, LazFileUtils, UXMLUtils, Dialogs, Types, LCLType, LCLIntf, fgl;
    1010
    1111const
     
    417417    procedure BuildMapAreas;
    418418    procedure InitClients;
     419    procedure SelectPlayerStartCell(Player: TPlayer);
    419420  public
    420421    Players: TPlayers;
     
    13021303
    13031304procedure TMap.Assign(Source: TMap);
    1304 var
    1305   I: Integer;
     1305//var
     1306//  I: Integer;
    13061307begin
    13071308  MaxPower := Source.MaxPower;
     
    13541355var
    13551356  NewNode: TDOMNode;
    1356   NewNode2: TDOMNode;
    1357   I: Integer;
    13581357begin
    13591358  WriteInteger(Node, 'DefaultCellSizeX', DefaultCellSize.X);
     
    14891488var
    14901489  X, Y: Integer;
    1491   I: Integer;
    14921490  NewCell: TCell;
    14931491begin
     
    17121710  Node2: TDOMNode;
    17131711  Node3: TDOMNode;
    1714   NewCell: TCell;
    17151712begin
    17161713  Id := ReadInteger(Node, 'Id', 0);
     
    19791976  AttackPower: Integer;
    19801977  TotalAttackPower: Integer;
    1981   I, J: Integer;
     1978  I: Integer;
    19821979  C: Integer;
    19831980  CanAttack: Integer;
    19841981  TargetCells: TCells;
    1985   S: string;
    19861982const
    19871983  AttackDiff = 1;
     
    20412037  AttackPower: Integer;
    20422038  TotalAttackPower: Integer;
    2043   I, J: Integer;
     2039  I: Integer;
    20442040  C: Integer;
    20452041  CanAttack: Integer;
    20462042  TargetCells: TCells;
    2047   S: string;
    2048 const
    2049   AttackDiff = 2;
    20502043begin
    20512044  if Game.CurrentPlayer.Defensive then Exit;
     
    23712364{ TGame }
    23722365
    2373 function ComparePointer(Item1, Item2: Pointer): Integer;
    2374 begin
    2375   Result := -CompareValue(Integer(Item1), Integer(Item2));
     2366function ComparePointer(const Item1, Item2: Integer): Integer;
     2367begin
     2368  Result := -CompareValue(Item1, Item2);
    23762369end;
    23772370
     
    23822375  S: string;
    23832376  I: Integer;
    2384   AttackRolls: TList;
    2385   DefendRolls: TList;
    2386 begin
    2387   AttackRolls := TList.Create;
    2388   DefendRolls := TList.Create;
     2377  AttackRolls: TFPGList<Integer>;
     2378  DefendRolls: TFPGList<Integer>;
     2379begin
     2380  AttackRolls := TFPGList<Integer>.Create;
     2381  DefendRolls := TFPGList<Integer>.Create;
    23892382  if AttackPower < 1 then
    23902383    raise Exception.Create('Attacker power have to be higher then 0.');
     
    24002393    AttackRolls.Count := AttackerDiceCount;
    24012394    for I := 0 to AttackerDiceCount - 1 do begin
    2402       AttackRolls[I] := Pointer(Random(7));
     2395      AttackRolls[I] := Random(7);
    24032396    end;
    24042397    AttackRolls.Sort(ComparePointer);
     
    24082401    DefendRolls.Count := DefenderDiceCount;
    24092402    for I := 0 to DefenderDiceCount - 1 do begin
    2410       DefendRolls[I] := Pointer(Random(7));
     2403      DefendRolls[I] := Random(7);
    24112404    end;
    24122405    DefendRolls.Sort(ComparePointer);
     
    28252818end;
    28262819
     2820procedure TGame.SelectPlayerStartCell(Player: TPlayer);
     2821var
     2822  Counter: Integer;
     2823begin
     2824  with Player do begin
     2825    // Try to obtain start cell for each player
     2826    StartCell := nil;
     2827    Counter := 0;
     2828    while not Assigned(StartCell) or Assigned(StartCell.Player) or
     2829    (StartCell.Terrain = ttVoid) do begin
     2830      StartCell := TCell(Map.Cells[Random(Map.Cells.Count)]);
     2831      Inc(Counter);
     2832      if Counter > 100 then
     2833        raise Exception.Create(SCannotSetPlayerStartCells);
     2834    end;
     2835  end;
     2836end;
     2837
    28272838procedure TGame.SaveConfig(Config: TXmlConfig; Path: string);
    28282839begin
    28292840  with Config do begin
    2830     SetValue(Path + '/GridType', Integer(MapType));
    2831     SetValue(Path + '/MapImage', MapImageFileName);
    2832     SetValue(Path + '/SymetricMap', SymetricMap);
    2833     SetValue(Path + '/FogOfWar', FogOfWar);
    2834     SetValue(Path + '/VoidEnabled', VoidEnabled);
    2835     SetValue(Path + '/VoidPercentage', VoidPercentage);
    2836     SetValue(Path + '/MapSizeX', Map.Size.X);
    2837     SetValue(Path + '/MapSizeY', Map.Size.Y);
    2838     SetValue(Path + '/MapShape', Integer(Map.Shape));
    2839     SetValue(Path + '/CityEnabled', CityEnabled);
    2840     SetValue(Path + '/CityPercentage', CityPercentage);
    2841     SetValue(Path + '/BridgeEnabled', BridgeEnabled);
    2842     SetValue(Path + '/GrowAmount', Integer(GrowAmount));
    2843     SetValue(Path + '/GrowCells', Integer(GrowCells));
    2844     SetValue(Path + '/WinObjective', Integer(WinObjective));
     2841    SetValue(DOMString(Path + '/GridType'), Integer(MapType));
     2842    SetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName));
     2843    SetValue(DOMString(Path + '/SymetricMap'), SymetricMap);
     2844    SetValue(DOMString(Path + '/FogOfWar'), FogOfWar);
     2845    SetValue(DOMString(Path + '/VoidEnabled'), VoidEnabled);
     2846    SetValue(DOMString(Path + '/VoidPercentage'), VoidPercentage);
     2847    SetValue(DOMString(Path + '/MapSizeX'), Map.Size.X);
     2848    SetValue(DOMString(Path + '/MapSizeY'), Map.Size.Y);
     2849    SetValue(DOMString(Path + '/MapShape'), Integer(Map.Shape));
     2850    SetValue(DOMString(Path + '/CityEnabled'), CityEnabled);
     2851    SetValue(DOMString(Path + '/CityPercentage'), CityPercentage);
     2852    SetValue(DOMString(Path + '/BridgeEnabled'), BridgeEnabled);
     2853    SetValue(DOMString(Path + '/GrowAmount'), Integer(GrowAmount));
     2854    SetValue(DOMString(Path + '/GrowCells'), Integer(GrowCells));
     2855    SetValue(DOMString(Path + '/WinObjective'), Integer(WinObjective));
    28452856  end;
    28462857end;
     
    28512862begin
    28522863  with Config do begin
    2853     MapType := TMapType(GetValue(Path + '/GridType', Integer(mtHexagon)));
    2854     MapImageFileName := GetValue(Path + '/MapImage', MapImageFileName);
    2855     SymetricMap := GetValue(Path + '/SymetricMap', False);
    2856     FogOfWar := GetValue(Path + '/FogOfWar', False);
    2857     VoidEnabled := GetValue(Path + '/VoidEnabled', True);
    2858     VoidPercentage := GetValue(Path + '/VoidPercentage', 20);
    2859     Map.Size := Point(GetValue(Path + '/MapSizeX', 10),
    2860       GetValue(Path + '/MapSizeY', 10));
    2861     Value := GetValue(Path + '/MapShape', 0);
     2864    MapType := TMapType(GetValue(DOMString(Path + '/GridType'), Integer(mtHexagon)));
     2865    MapImageFileName := string(GetValue(DOMString(Path + '/MapImage'), DOMString(MapImageFileName)));
     2866    SymetricMap := GetValue(DOMString(Path + '/SymetricMap'), False);
     2867    FogOfWar := GetValue(DOMString(Path + '/FogOfWar'), False);
     2868    VoidEnabled := GetValue(DOMString(Path + '/VoidEnabled'), True);
     2869    VoidPercentage := GetValue(DOMString(Path + '/VoidPercentage'), 20);
     2870    Map.Size := Point(GetValue(DOMString(Path + '/MapSizeX'), 10),
     2871      GetValue(DOMString(Path + '/MapSizeY'), 10));
     2872    Value := GetValue(DOMString(Path + '/MapShape'), 0);
    28622873    if (Value >= Integer(Low(TMapShape))) and (Value <= Integer(High(TMapShape))) then
    28632874      Map.Shape := TMapShape(Value) else Map.Shape := Low(TMapShape);
    2864     CityEnabled := GetValue(Path + '/CityEnabled', False);
    2865     CityPercentage := GetValue(Path + '/CityPercentage', 10);
    2866     BridgeEnabled := GetValue(Path + '/BridgeEnabled', True);
    2867     Value := GetValue(Path + '/GrowAmount', Integer(gaBySquareRoot));
     2875    CityEnabled := GetValue(DOMString(Path + '/CityEnabled'), False);
     2876    CityPercentage := GetValue(DOMString(Path + '/CityPercentage'), 10);
     2877    BridgeEnabled := GetValue(DOMString(Path + '/BridgeEnabled'), True);
     2878    Value := GetValue(DOMString(Path + '/GrowAmount'), Integer(gaBySquareRoot));
    28682879    if (Value >= Integer(Low(TGrowAmount))) and (Value <= Integer(High(TGrowAmount))) then
    28692880      GrowAmount := TGrowAmount(Value) else GrowAmount := Low(TGrowAmount);
    2870     Value := GetValue(Path + '/GrowCells', Integer(gcPlayerAll));
     2881    Value := GetValue(DOMString(Path + '/GrowCells'), Integer(gcPlayerAll));
    28712882    if (Value >= Integer(Low(TGrowCells))) and (Value <= Integer(High(TGrowCells))) then
    28722883      GrowCells := TGrowCells(Value) else GrowCells := Low(TGrowCells);
    2873     Value := GetValue(Path + '/WinObjective', Integer(woDefeatAllOponents));
     2884    Value := GetValue(DOMString(Path + '/WinObjective'), Integer(woDefeatAllOponents));
    28742885    if (Value >= Integer(Low(TWinObjective))) and (Value <= Integer(High(TWinObjective))) then
    28752886      WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective);
     
    28852896begin
    28862897  Self.FileName := FileName;
    2887   ReadXMLFile(Doc, UTF8Decode(FileName));
     2898  ReadXMLFile(Doc, FileName);
    28882899  with Doc do try
    28892900    if Doc.DocumentElement.NodeName <> 'XtacticsGame' then
     
    29742985  end;
    29752986    ForceDirectoriesUTF8(ExtractFileDir(FileName));
    2976     WriteXMLFile(Doc, UTF8Decode(FileName));
     2987    WriteXMLFile(Doc, FileName);
    29772988  finally
    29782989    Doc.Free;
     
    31363147var
    31373148  I: Integer;
    3138   Counter: Integer;
    31393149  C: Integer;
    31403150  LastAreaCount: Integer;
     
    31723182    PlayerMap.Update;
    31733183    if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin
    3174       // Try to obtain start cell for each player
    3175       StartCell := nil;
    3176       Counter := 0;
    3177       while not Assigned(StartCell) or Assigned(StartCell.Player) or
    3178      (StartCell.Terrain = ttVoid) do begin
    3179         StartCell := TCell(Map.Cells[Random(Map.Cells.Count)]);
    3180         Inc(Counter);
    3181         if Counter > 100 then
    3182           raise Exception.Create(SCannotSetPlayerStartCells);
    3183       end;
     3184      SelectPlayerStartCell(TPlayer(Players[I]));
    31843185      if SymetricMap and (I = 1) then
    31853186        StartCell := TCell(Map.Cells[Map.Cells.Count - 1 - Map.Cells.IndexOf(TPlayer(Players[0]).StartCell)]);
Note: See TracChangeset for help on using the changeset viewer.