Changeset 294 for trunk/UBuilding.pas
- Timestamp:
- Mar 29, 2019, 8:40:42 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UBuilding.pas
r290 r294 9 9 10 10 type 11 TBuildingSpecialType = (stNone, stCity); 11 12 12 13 { TBuildingKind } … … 14 15 TBuildingKind = class(TItem) 15 16 Cost: Integer; 17 SpecialType: TBuildingSpecialType; 16 18 class function GetFields: TItemFields; override; 17 19 procedure GetValue(Index: Integer; out Value); override; … … 25 27 TBuildingKinds = class(TItemList) 26 28 class function GetItemClass: TItemClass; override; 29 function FindBySpecialType(SpecialType: TBuildingSpecialType): TItem; 27 30 end; 28 31 29 TBuilding = class 32 { TBuilding } 33 34 TBuilding = class(TItem) 35 private 36 FMapCell: TObject; 37 procedure SetMapCell(AValue: TObject); 38 public 30 39 Kind: TBuildingKind; 40 property MapCell: TObject read FMapCell write SetMapCell; // TMapCell; 41 end; 42 43 { TBuildings } 44 45 TBuildings = class(TItemList) 46 Game: TObject; // TGame; 47 class function GetItemClass: TItemClass; override; 31 48 end; 32 49 … … 34 51 SBuildingKind = 'Building'; 35 52 SCost = 'Cost'; 53 SSpecialType = 'Special type'; 36 54 37 55 38 56 implementation 57 58 uses 59 UMap; 60 61 { TBuildings } 62 63 class function TBuildings.GetItemClass: TItemClass; 64 begin 65 Result := TBuilding; 66 end; 67 68 { TBuilding } 69 70 procedure TBuilding.SetMapCell(AValue: TObject); 71 var 72 OldValue: TCell; 73 begin 74 if FMapCell = AValue then Exit; 75 OldValue := TCell(FMapCell); 76 FMapCell := nil; 77 if Assigned(OldValue) then TCell(OldValue).Building := nil; 78 FMapCell := AValue; 79 if Assigned(FMapCell) then TCell(FMapCell).Building := Self; 80 end; 39 81 40 82 { TBuildingKind } … … 44 86 Result := inherited; 45 87 Result.AddField(2, 'Cost', SCost, dtInteger); 88 Result.AddField(3, 'SpecialType', SSpecialType, dtInteger); 46 89 end; 47 90 … … 50 93 if Index = 1 then string(Value) := Name 51 94 else if Index = 2 then Integer(Value) := Cost 95 else if Index = 3 then TBuildingSpecialType(Value) := SpecialType 52 96 else raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 53 97 end; … … 57 101 if Index = 1 then Name := string(Value) 58 102 else if Index = 2 then Cost := Integer(Value) 103 else if Index = 3 then SpecialType := TBuildingSpecialType(Value) 59 104 else raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 60 105 end; … … 77 122 end; 78 123 124 function TBuildingKinds.FindBySpecialType(SpecialType: TBuildingSpecialType 125 ): TItem; 126 var 127 I: Integer; 128 begin 129 I := 0; 130 while (I < Count) and (TBuildingKind(Items[I]).SpecialType <> SpecialType) do Inc(I); 131 if I < Count then Result := Items[I] 132 else Result := nil; 133 end; 134 79 135 end. 80 136
Note:
See TracChangeset
for help on using the changeset viewer.