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)
|
---|
30 | class function GetItemClass: TItemClass; override;
|
---|
31 | function FindBySpecialType(SpecialType: TBuildingSpecialType): TItem;
|
---|
32 | end;
|
---|
33 |
|
---|
34 | { TBuilding }
|
---|
35 |
|
---|
36 | TBuilding = class(TItem)
|
---|
37 | private
|
---|
38 | FMapCell: TObject;
|
---|
39 | procedure SetMapCell(AValue: TObject);
|
---|
40 | public
|
---|
41 | Kind: TBuildingKind;
|
---|
42 | procedure Assign(Source: TItem); override;
|
---|
43 | property MapCell: TObject read FMapCell write SetMapCell; // TMapCell;
|
---|
44 | end;
|
---|
45 |
|
---|
46 | { TBuildings }
|
---|
47 |
|
---|
48 | TBuildings = class(TItemList)
|
---|
49 | Game: TObject; // TGame;
|
---|
50 | class function GetItemClass: TItemClass; override;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | resourcestring
|
---|
54 | SBuildingKind = 'Building';
|
---|
55 | SCost = 'Cost';
|
---|
56 | SSpecialType = 'Special type';
|
---|
57 | SNone = 'None';
|
---|
58 | SCity = 'City';
|
---|
59 | SBonusAttack = 'Unit attack bonus';
|
---|
60 | SBonusDefense = 'Unit defense bonus';
|
---|
61 | SBonusViewRange = 'Unit view range bonus';
|
---|
62 | SBonusGrow = 'Unit grow bonus';
|
---|
63 |
|
---|
64 |
|
---|
65 | implementation
|
---|
66 |
|
---|
67 | uses
|
---|
68 | Map;
|
---|
69 |
|
---|
70 | { TBuildings }
|
---|
71 |
|
---|
72 | class function TBuildings.GetItemClass: TItemClass;
|
---|
73 | begin
|
---|
74 | Result := TBuilding;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | { TBuilding }
|
---|
78 |
|
---|
79 | procedure TBuilding.SetMapCell(AValue: TObject);
|
---|
80 | var
|
---|
81 | OldValue: TCell;
|
---|
82 | begin
|
---|
83 | if FMapCell = AValue then Exit;
|
---|
84 | OldValue := TCell(FMapCell);
|
---|
85 | FMapCell := nil;
|
---|
86 | if Assigned(OldValue) then TCell(OldValue).Building := nil;
|
---|
87 | FMapCell := AValue;
|
---|
88 | if Assigned(FMapCell) then TCell(FMapCell).Building := Self;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | procedure TBuilding.Assign(Source: TItem);
|
---|
92 | begin
|
---|
93 | inherited;
|
---|
94 | Kind := TBuilding(Source).Kind;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | { TBuildingKind }
|
---|
98 |
|
---|
99 | class function TBuildingKind.GetFields: TItemFields;
|
---|
100 | var
|
---|
101 | Field: TItemField;
|
---|
102 | begin
|
---|
103 | Result := inherited;
|
---|
104 | Result.AddField(2, 'Cost', SCost, dtInteger);
|
---|
105 | Field := Result.AddField(3, 'SpecialType', SSpecialType, dtEnumeration);
|
---|
106 | Field.EnumStates.Add(SNone);
|
---|
107 | Field.EnumStates.Add(SCity);
|
---|
108 | Result.AddField(4, 'BonusAttack', SBonusAttack, dtInteger);
|
---|
109 | Result.AddField(5, 'BonusDefense', SBonusDefense, dtInteger);
|
---|
110 | Result.AddField(6, 'BonusViewRange', SBonusViewRange, dtInteger);
|
---|
111 | Result.AddField(7, 'BonusGrow', SBonusGrow, dtInteger);
|
---|
112 | end;
|
---|
113 |
|
---|
114 | procedure TBuildingKind.GetValue(Index: Integer; out Value);
|
---|
115 | begin
|
---|
116 | if Index = 1 then string(Value) := Name
|
---|
117 | else if Index = 2 then Integer(Value) := Cost
|
---|
118 | else if Index = 3 then TBuildingSpecialType(Value) := SpecialType
|
---|
119 | else if Index = 4 then Integer(Value) := BonusAttack
|
---|
120 | else if Index = 5 then Integer(Value) := BonusDefense
|
---|
121 | else if Index = 6 then Integer(Value) := BonusViewRange
|
---|
122 | else if Index = 7 then Integer(Value) := BonusGrow
|
---|
123 | else inherited;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TBuildingKind.SetValue(Index: Integer; var Value);
|
---|
127 | begin
|
---|
128 | if Index = 1 then Name := string(Value)
|
---|
129 | else if Index = 2 then Cost := Integer(Value)
|
---|
130 | else if Index = 3 then SpecialType := TBuildingSpecialType(Value)
|
---|
131 | else if Index = 4 then BonusAttack := Integer(Value)
|
---|
132 | else if Index = 5 then BonusDefense := Integer(Value)
|
---|
133 | else if Index = 6 then BonusViewRange := Integer(Value)
|
---|
134 | else if Index = 7 then BonusGrow := Integer(Value)
|
---|
135 | else inherited;
|
---|
136 | end;
|
---|
137 |
|
---|
138 | class function TBuildingKind.GetClassSysName: string;
|
---|
139 | begin
|
---|
140 | Result := 'BuildingKind';
|
---|
141 | end;
|
---|
142 |
|
---|
143 | class function TBuildingKind.GetClassName: string;
|
---|
144 | begin
|
---|
145 | Result := SBuildingKind;
|
---|
146 | end;
|
---|
147 |
|
---|
148 | { TBuildingKinds }
|
---|
149 |
|
---|
150 | class function TBuildingKinds.GetItemClass: TItemClass;
|
---|
151 | begin
|
---|
152 | Result := TBuildingKind;
|
---|
153 | end;
|
---|
154 |
|
---|
155 | function TBuildingKinds.FindBySpecialType(SpecialType: TBuildingSpecialType
|
---|
156 | ): TItem;
|
---|
157 | var
|
---|
158 | I: Integer;
|
---|
159 | begin
|
---|
160 | I := 0;
|
---|
161 | while (I < Count) and (TBuildingKind(Items[I]).SpecialType <> SpecialType) do Inc(I);
|
---|
162 | if I < Count then Result := Items[I]
|
---|
163 | else Result := nil;
|
---|
164 | end;
|
---|
165 |
|
---|
166 | end.
|
---|
167 |
|
---|