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