Changeset 145 for trunk/UGame.pas
- Timestamp:
- Nov 12, 2017, 1:47:20 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r142 r145 7 7 uses 8 8 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; 10 10 11 11 const … … 417 417 procedure BuildMapAreas; 418 418 procedure InitClients; 419 procedure SelectPlayerStartCell(Player: TPlayer); 419 420 public 420 421 Players: TPlayers; … … 1302 1303 1303 1304 procedure TMap.Assign(Source: TMap); 1304 var1305 I: Integer;1305 //var 1306 // I: Integer; 1306 1307 begin 1307 1308 MaxPower := Source.MaxPower; … … 1354 1355 var 1355 1356 NewNode: TDOMNode; 1356 NewNode2: TDOMNode;1357 I: Integer;1358 1357 begin 1359 1358 WriteInteger(Node, 'DefaultCellSizeX', DefaultCellSize.X); … … 1489 1488 var 1490 1489 X, Y: Integer; 1491 I: Integer;1492 1490 NewCell: TCell; 1493 1491 begin … … 1712 1710 Node2: TDOMNode; 1713 1711 Node3: TDOMNode; 1714 NewCell: TCell;1715 1712 begin 1716 1713 Id := ReadInteger(Node, 'Id', 0); … … 1979 1976 AttackPower: Integer; 1980 1977 TotalAttackPower: Integer; 1981 I , J: Integer;1978 I: Integer; 1982 1979 C: Integer; 1983 1980 CanAttack: Integer; 1984 1981 TargetCells: TCells; 1985 S: string;1986 1982 const 1987 1983 AttackDiff = 1; … … 2041 2037 AttackPower: Integer; 2042 2038 TotalAttackPower: Integer; 2043 I , J: Integer;2039 I: Integer; 2044 2040 C: Integer; 2045 2041 CanAttack: Integer; 2046 2042 TargetCells: TCells; 2047 S: string;2048 const2049 AttackDiff = 2;2050 2043 begin 2051 2044 if Game.CurrentPlayer.Defensive then Exit; … … 2371 2364 { TGame } 2372 2365 2373 function ComparePointer( Item1, Item2: Pointer): Integer;2374 begin 2375 Result := -CompareValue(I nteger(Item1), Integer(Item2));2366 function ComparePointer(const Item1, Item2: Integer): Integer; 2367 begin 2368 Result := -CompareValue(Item1, Item2); 2376 2369 end; 2377 2370 … … 2382 2375 S: string; 2383 2376 I: Integer; 2384 AttackRolls: T List;2385 DefendRolls: T List;2386 begin 2387 AttackRolls := T List.Create;2388 DefendRolls := T List.Create;2377 AttackRolls: TFPGList<Integer>; 2378 DefendRolls: TFPGList<Integer>; 2379 begin 2380 AttackRolls := TFPGList<Integer>.Create; 2381 DefendRolls := TFPGList<Integer>.Create; 2389 2382 if AttackPower < 1 then 2390 2383 raise Exception.Create('Attacker power have to be higher then 0.'); … … 2400 2393 AttackRolls.Count := AttackerDiceCount; 2401 2394 for I := 0 to AttackerDiceCount - 1 do begin 2402 AttackRolls[I] := Pointer(Random(7));2395 AttackRolls[I] := Random(7); 2403 2396 end; 2404 2397 AttackRolls.Sort(ComparePointer); … … 2408 2401 DefendRolls.Count := DefenderDiceCount; 2409 2402 for I := 0 to DefenderDiceCount - 1 do begin 2410 DefendRolls[I] := Pointer(Random(7));2403 DefendRolls[I] := Random(7); 2411 2404 end; 2412 2405 DefendRolls.Sort(ComparePointer); … … 2825 2818 end; 2826 2819 2820 procedure TGame.SelectPlayerStartCell(Player: TPlayer); 2821 var 2822 Counter: Integer; 2823 begin 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; 2836 end; 2837 2827 2838 procedure TGame.SaveConfig(Config: TXmlConfig; Path: string); 2828 2839 begin 2829 2840 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)); 2845 2856 end; 2846 2857 end; … … 2851 2862 begin 2852 2863 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); 2862 2873 if (Value >= Integer(Low(TMapShape))) and (Value <= Integer(High(TMapShape))) then 2863 2874 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)); 2868 2879 if (Value >= Integer(Low(TGrowAmount))) and (Value <= Integer(High(TGrowAmount))) then 2869 2880 GrowAmount := TGrowAmount(Value) else GrowAmount := Low(TGrowAmount); 2870 Value := GetValue( Path + '/GrowCells', Integer(gcPlayerAll));2881 Value := GetValue(DOMString(Path + '/GrowCells'), Integer(gcPlayerAll)); 2871 2882 if (Value >= Integer(Low(TGrowCells))) and (Value <= Integer(High(TGrowCells))) then 2872 2883 GrowCells := TGrowCells(Value) else GrowCells := Low(TGrowCells); 2873 Value := GetValue( Path + '/WinObjective', Integer(woDefeatAllOponents));2884 Value := GetValue(DOMString(Path + '/WinObjective'), Integer(woDefeatAllOponents)); 2874 2885 if (Value >= Integer(Low(TWinObjective))) and (Value <= Integer(High(TWinObjective))) then 2875 2886 WinObjective := TWinObjective(Value) else WinObjective := Low(TWinObjective); … … 2885 2896 begin 2886 2897 Self.FileName := FileName; 2887 ReadXMLFile(Doc, UTF8Decode(FileName));2898 ReadXMLFile(Doc, FileName); 2888 2899 with Doc do try 2889 2900 if Doc.DocumentElement.NodeName <> 'XtacticsGame' then … … 2974 2985 end; 2975 2986 ForceDirectoriesUTF8(ExtractFileDir(FileName)); 2976 WriteXMLFile(Doc, UTF8Decode(FileName));2987 WriteXMLFile(Doc, FileName); 2977 2988 finally 2978 2989 Doc.Free; … … 3136 3147 var 3137 3148 I: Integer; 3138 Counter: Integer;3139 3149 C: Integer; 3140 3150 LastAreaCount: Integer; … … 3172 3182 PlayerMap.Update; 3173 3183 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])); 3184 3185 if SymetricMap and (I = 1) then 3185 3186 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.