Changeset 265 for trunk/UMap.pas
- Timestamp:
- Jan 15, 2019, 1:03:40 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMap.pas
r258 r265 7 7 uses 8 8 Classes, SysUtils, Graphics, ExtCtrls, UGeometry, DOM, fgl, 9 UXMLUtils ;9 UXMLUtils, UUnit; 10 10 11 11 const … … 30 30 FMap: TMap; 31 31 FPower: Integer; 32 FUnit: TUnit; 33 function GetPower: Integer; 32 34 procedure SetArea(AValue: TMapArea); 33 35 procedure SetId(AValue: Integer); 34 36 procedure SetPower(AValue: Integer); 37 procedure SetUnit(AValue: TUnit); 35 38 public 36 39 PosPx: TPoint; 37 40 Polygon: TPolygon; 38 41 Terrain: TTerrainType; 39 PlayerId: Integer; 42 PlayerId: Integer; // Temporary value 40 43 Player: TObject; // TPlayer; 41 44 NeighborsId: array of Integer; … … 44 47 Weight: Integer; // Temporary value 45 48 Angle: Double; // Temporary value 46 PlayerCell: Pointer; // Temporary value49 PlayerCell: TObject; // Temporary value 47 50 Links: TCellLinks; 48 51 Extra: TExtraType; 49 property Id: Integer read FId write SetId;52 OneUnitId: Integer; // Temporary value 50 53 procedure ConnectTo(Cell: TCell); 51 54 procedure DisconnectFrom(Cell: TCell); … … 60 63 constructor Create; 61 64 destructor Destroy; override; 62 property Power: Integer read FPower write SetPower;65 property Id: Integer read FId write SetId; 63 66 property Map: TMap read FMap write FMap; 64 67 property Area: TMapArea read FArea write SetArea; 68 property OneUnit: TUnit read FUnit write SetUnit; 69 //property Power: Integer read GetPower; 65 70 end; 66 71 … … 612 617 with TPlayer(Player) do begin 613 618 Inc(TotalCells); 614 Inc(TotalUnits, Power); 619 if Assigned(OneUnit) then 620 Inc(TotalUnits, OneUnit.Power); 615 621 if Terrain = ttCity then 616 622 Inc(TotalCities); … … 656 662 for C := 0 to (Cells.Count div 2) - 1 do begin 657 663 Cells[C].Terrain := Cells[Cells.Count - 1 - C].Terrain; 658 Cells[C]. Power := Cells[Cells.Count - 1 - C].Power;664 Cells[C].OneUnit.Power := Cells[Cells.Count - 1 - C].OneUnit.Power; 659 665 660 666 for I := Cells[C].Links.Count - 1 downto 0 do begin … … 908 914 end; 909 915 916 procedure TCell.SetUnit(AValue: TUnit); 917 var 918 OldValue: TUnit; 919 begin 920 if FUnit = AValue then Exit; 921 OldValue := FUnit; 922 FUnit := nil; 923 if Assigned(OldValue) then OldValue.MapCell := nil; 924 FUnit := AValue; 925 if Assigned(FUnit) then FUnit.MapCell := Self; 926 end; 927 910 928 procedure TCell.ConnectTo(Cell: TCell); 911 929 begin … … 950 968 end; 951 969 970 function TCell.GetPower: Integer; 971 begin 972 if Assigned(OneUnit) then Result := OneUnit.Power 973 else Result := 0; 974 end; 975 952 976 procedure TCell.SetId(AValue: Integer); 953 977 begin … … 973 997 begin 974 998 Player := TGame(Map.Game).Players.FindById(PlayerId); 999 OneUnit := TGame(Map.Game).Units.FindById(OneUnitId); 975 1000 976 1001 Neighbors.Count := Length(NeighborsId); … … 993 1018 begin 994 1019 Id := ReadInteger(Node, 'Id', 0); 995 Power := ReadInteger(Node, 'Power', 0);1020 OneUnitId := ReadInteger(Node, 'Unit', 0); 996 1021 Terrain := TTerrainType(ReadInteger(Node, 'Terrain', Integer(ttVoid))); 997 1022 Extra := TExtraType(ReadInteger(Node, 'Extra', Integer(etNone))); … … 1029 1054 begin 1030 1055 WriteInteger(Node, 'Id', Id); 1031 WriteInteger(Node, 'Power', Power); 1056 if Assigned(OneUnit) then 1057 WriteInteger(Node, 'Unit', OneUnit.Id) 1058 else WriteInteger(Node, 'Unit', 0); 1032 1059 WriteInteger(Node, 'Terrain', Integer(Terrain)); 1033 1060 WriteInteger(Node, 'Extra', Integer(Extra)); … … 1090 1117 I: Integer; 1091 1118 begin 1119 OneUnit := nil; 1092 1120 for I := Links.Count - 1 downto 0 do 1093 1121 FMap.CellLinks.Remove(Links[I]);
Note:
See TracChangeset
for help on using the changeset viewer.