| 1 | unit Building;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, ItemList;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TBuildingSpecialType = (stNone, stCity);
|
|---|
| 10 |
|
|---|
| 11 | { TBuildingKind }
|
|---|
| 12 |
|
|---|
| 13 | TBuildingKind = class(TItem)
|
|---|
| 14 | Cost: Integer;
|
|---|
| 15 | SpecialType: TBuildingSpecialType;
|
|---|
| 16 | BonusAttack: Integer;
|
|---|
| 17 | BonusDefense: Integer;
|
|---|
| 18 | BonusViewRange: Integer;
|
|---|
| 19 | BonusGrow: Integer;
|
|---|
| 20 | class function GetFields: TItemFields; override;
|
|---|
| 21 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 22 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 23 | class function GetClassSysName: string; override;
|
|---|
| 24 | class function GetClassName: string; override;
|
|---|
| 25 | end;
|
|---|
| 26 |
|
|---|
| 27 | { TBuildingKinds }
|
|---|
| 28 |
|
|---|
| 29 | TBuildingKinds = class(TItemList<TBuildingKind>)
|
|---|
| 30 | function FindBySpecialType(SpecialType: TBuildingSpecialType): TBuildingKind;
|
|---|
| 31 | end;
|
|---|
| 32 |
|
|---|
| 33 | { TBuilding }
|
|---|
| 34 |
|
|---|
| 35 | TBuilding = class(TItem)
|
|---|
| 36 | private
|
|---|
| 37 | FMapCell: TObject;
|
|---|
| 38 | procedure SetMapCell(AValue: TObject);
|
|---|
| 39 | public
|
|---|
| 40 | Kind: TBuildingKind;
|
|---|
| 41 | Game: TObject; // TGame
|
|---|
| 42 | class function GetFields: TItemFields; override;
|
|---|
| 43 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 44 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 45 | function GetReferenceList(Index: Integer): TBaseItemList; override;
|
|---|
| 46 | procedure Assign(Source: TItem); override;
|
|---|
| 47 | property MapCell: TObject read FMapCell write SetMapCell; // TMapCell;
|
|---|
| 48 | end;
|
|---|
| 49 |
|
|---|
| 50 | { TBuildings }
|
|---|
| 51 |
|
|---|
| 52 | TBuildings = class(TItemList<TBuilding>)
|
|---|
| 53 | Game: TObject; // TGame;
|
|---|
| 54 | function CreateItem(Name: string = ''): TBuilding; override;
|
|---|
| 55 | procedure Assign(Source: TItemList<TBuilding>); override;
|
|---|
| 56 | end;
|
|---|
| 57 |
|
|---|
| 58 | resourcestring
|
|---|
| 59 | SBuildingKind = 'Building';
|
|---|
| 60 | SCost = 'Cost';
|
|---|
| 61 | SSpecialType = 'Special type';
|
|---|
| 62 | SNone = 'None';
|
|---|
| 63 | SCity = 'City';
|
|---|
| 64 | SBonusAttack = 'Unit attack bonus';
|
|---|
| 65 | SBonusDefense = 'Unit defense bonus';
|
|---|
| 66 | SBonusViewRange = 'Unit view range bonus';
|
|---|
| 67 | SBonusGrow = 'Unit grow bonus';
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | implementation
|
|---|
| 71 |
|
|---|
| 72 | uses
|
|---|
| 73 | Map, Game;
|
|---|
| 74 |
|
|---|
| 75 | { TBuilding }
|
|---|
| 76 |
|
|---|
| 77 | procedure TBuilding.SetMapCell(AValue: TObject);
|
|---|
| 78 | var
|
|---|
| 79 | OldValue: TCell;
|
|---|
| 80 | begin
|
|---|
| 81 | if FMapCell = AValue then Exit;
|
|---|
| 82 | OldValue := TCell(FMapCell);
|
|---|
| 83 | FMapCell := nil;
|
|---|
| 84 | if Assigned(OldValue) then TCell(OldValue).Building := nil;
|
|---|
| 85 | FMapCell := AValue;
|
|---|
| 86 | if Assigned(FMapCell) then TCell(FMapCell).Building := Self;
|
|---|
| 87 | end;
|
|---|
| 88 |
|
|---|
| 89 | class function TBuilding.GetFields: TItemFields;
|
|---|
| 90 | var
|
|---|
| 91 | Field: TItemField;
|
|---|
| 92 | begin
|
|---|
| 93 | Result := inherited;
|
|---|
| 94 | Field := Result.AddField(2, 'Kind', SBuildingKind, dtReference);
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TBuilding.GetValue(Index: Integer; out Value);
|
|---|
| 98 | begin
|
|---|
| 99 | if Index = 1 then string(Value) := Name
|
|---|
| 100 | else if Index = 2 then TBuildingKind(Value) := Kind
|
|---|
| 101 | else inherited;
|
|---|
| 102 | end;
|
|---|
| 103 |
|
|---|
| 104 | procedure TBuilding.SetValue(Index: Integer; var Value);
|
|---|
| 105 | begin
|
|---|
| 106 | if Index = 1 then Name := string(Value)
|
|---|
| 107 | else if Index = 2 then Kind := TBuildingKind(Value)
|
|---|
| 108 | else inherited;
|
|---|
| 109 | end;
|
|---|
| 110 |
|
|---|
| 111 | function TBuilding.GetReferenceList(Index: Integer): TBaseItemList;
|
|---|
| 112 | begin
|
|---|
| 113 | if Index = 2 then Result := TGame(Game).GameSystem.BuildingKinds.BaseItemList
|
|---|
| 114 | else Result := nil;
|
|---|
| 115 | end;
|
|---|
| 116 |
|
|---|
| 117 | procedure TBuilding.Assign(Source: TItem);
|
|---|
| 118 | begin
|
|---|
| 119 | inherited;
|
|---|
| 120 | Kind := TBuilding(Source).Kind;
|
|---|
| 121 | end;
|
|---|
| 122 |
|
|---|
| 123 | { TBuildings }
|
|---|
| 124 |
|
|---|
| 125 | function TBuildings.CreateItem(Name: string): TBuilding;
|
|---|
| 126 | begin
|
|---|
| 127 | Result := inherited;
|
|---|
| 128 | Result.Game := Game;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | procedure TBuildings.Assign(Source: TItemList<TBuilding>);
|
|---|
| 132 | var
|
|---|
| 133 | I: Integer;
|
|---|
| 134 | begin
|
|---|
| 135 | inherited;
|
|---|
| 136 | for I := 0 to Count - 1 do
|
|---|
| 137 | Items[I].Game := Game;
|
|---|
| 138 | end;
|
|---|
| 139 |
|
|---|
| 140 | { TBuildingKind }
|
|---|
| 141 |
|
|---|
| 142 | class function TBuildingKind.GetFields: TItemFields;
|
|---|
| 143 | var
|
|---|
| 144 | Field: TItemField;
|
|---|
| 145 | begin
|
|---|
| 146 | Result := inherited;
|
|---|
| 147 | Result.AddField(2, 'Cost', SCost, dtInteger);
|
|---|
| 148 | Field := Result.AddField(3, 'SpecialType', SSpecialType, dtEnumeration);
|
|---|
| 149 | Field.EnumStates.Add(SNone);
|
|---|
| 150 | Field.EnumStates.Add(SCity);
|
|---|
| 151 | Result.AddField(4, 'BonusAttack', SBonusAttack, dtInteger);
|
|---|
| 152 | Result.AddField(5, 'BonusDefense', SBonusDefense, dtInteger);
|
|---|
| 153 | Result.AddField(6, 'BonusViewRange', SBonusViewRange, dtInteger);
|
|---|
| 154 | Result.AddField(7, 'BonusGrow', SBonusGrow, dtInteger);
|
|---|
| 155 | end;
|
|---|
| 156 |
|
|---|
| 157 | procedure TBuildingKind.GetValue(Index: Integer; out Value);
|
|---|
| 158 | begin
|
|---|
| 159 | if Index = 1 then string(Value) := Name
|
|---|
| 160 | else if Index = 2 then Integer(Value) := Cost
|
|---|
| 161 | else if Index = 3 then TBuildingSpecialType(Value) := SpecialType
|
|---|
| 162 | else if Index = 4 then Integer(Value) := BonusAttack
|
|---|
| 163 | else if Index = 5 then Integer(Value) := BonusDefense
|
|---|
| 164 | else if Index = 6 then Integer(Value) := BonusViewRange
|
|---|
| 165 | else if Index = 7 then Integer(Value) := BonusGrow
|
|---|
| 166 | else inherited;
|
|---|
| 167 | end;
|
|---|
| 168 |
|
|---|
| 169 | procedure TBuildingKind.SetValue(Index: Integer; var Value);
|
|---|
| 170 | begin
|
|---|
| 171 | if Index = 1 then Name := string(Value)
|
|---|
| 172 | else if Index = 2 then Cost := Integer(Value)
|
|---|
| 173 | else if Index = 3 then SpecialType := TBuildingSpecialType(Value)
|
|---|
| 174 | else if Index = 4 then BonusAttack := Integer(Value)
|
|---|
| 175 | else if Index = 5 then BonusDefense := Integer(Value)
|
|---|
| 176 | else if Index = 6 then BonusViewRange := Integer(Value)
|
|---|
| 177 | else if Index = 7 then BonusGrow := Integer(Value)
|
|---|
| 178 | else inherited;
|
|---|
| 179 | end;
|
|---|
| 180 |
|
|---|
| 181 | class function TBuildingKind.GetClassSysName: string;
|
|---|
| 182 | begin
|
|---|
| 183 | Result := 'BuildingKind';
|
|---|
| 184 | end;
|
|---|
| 185 |
|
|---|
| 186 | class function TBuildingKind.GetClassName: string;
|
|---|
| 187 | begin
|
|---|
| 188 | Result := SBuildingKind;
|
|---|
| 189 | end;
|
|---|
| 190 |
|
|---|
| 191 | { TBuildingKinds }
|
|---|
| 192 |
|
|---|
| 193 | function TBuildingKinds.FindBySpecialType(SpecialType: TBuildingSpecialType
|
|---|
| 194 | ): TBuildingKind;
|
|---|
| 195 | var
|
|---|
| 196 | I: Integer;
|
|---|
| 197 | begin
|
|---|
| 198 | I := 0;
|
|---|
| 199 | while (I < Count) and (Items[I].SpecialType <> SpecialType) do Inc(I);
|
|---|
| 200 | if I < Count then Result := Items[I]
|
|---|
| 201 | else Result := nil;
|
|---|
| 202 | end;
|
|---|
| 203 |
|
|---|
| 204 | end.
|
|---|
| 205 |
|
|---|