source: tags/1.4.0/UnitKind.pas

Last change on this file was 344, checked in by chronos, 4 weeks ago
  • Modified: Improved implementation of TItemList class to be generic class to avoid explicit typecasting.
File size: 2.4 KB
Line 
1unit UnitKind;
2
3interface
4
5uses
6 Classes, SysUtils, ItemList;
7
8type
9 { TUnitKind }
10
11 TUnitKind = class(TItem)
12 PowerAttack: Integer;
13 PowerDefense: Integer;
14 Moves: Integer;
15 Cost: Integer;
16 Power: Integer;
17 ViewRange: Integer;
18 class function GetFields: TItemFields; override;
19 procedure GetValue(Index: Integer; out Value); override;
20 procedure SetValue(Index: Integer; var Value); override;
21 class function GetClassSysName: string; override;
22 class function GetClassName: string; override;
23 end;
24
25 { TUnitKinds }
26
27 TUnitKinds = class(TItemList<TUnitKind>)
28 constructor Create(FreeObjects: Boolean = True);
29 end;
30
31
32implementation
33
34resourcestring
35 SStack = 'Stack';
36 SCost = 'Cost';
37 SMoves = 'Moves';
38 SPowerAttack = 'Attack power';
39 SPowerDefense = 'Defense power';
40 SViewRange = 'View range';
41 SUnitKind = 'Unit kind';
42
43{ TUnitKind }
44
45class function TUnitKind.GetFields: TItemFields;
46begin
47 Result := inherited;
48 Result.AddField(2, 'Stack', SStack, dtInteger);
49 Result.AddField(3, 'Cost', SCost, dtInteger);
50 Result.AddField(4, 'Moves', SMoves, dtInteger);
51 Result.AddField(5, 'PowerAttack', SPowerAttack, dtInteger);
52 Result.AddField(6, 'PowerDefense', SPowerDefense, dtInteger);
53 Result.AddField(7, 'ViewRange', SViewRange, dtInteger);
54end;
55
56procedure TUnitKind.GetValue(Index: Integer; out Value);
57begin
58 if Index = 1 then string(Value) := Name
59 else if Index = 2 then Integer(Value) := Power
60 else if Index = 3 then Integer(Value) := Cost
61 else if Index = 4 then Integer(Value) := Moves
62 else if Index = 5 then Integer(Value) := PowerAttack
63 else if Index = 6 then Integer(Value) := PowerDefense
64 else if Index = 7 then Integer(Value) := ViewRange
65 else inherited;
66end;
67
68procedure TUnitKind.SetValue(Index: Integer; var Value);
69begin
70 if Index = 1 then Name := string(Value)
71 else if Index = 2 then Power := Integer(Value)
72 else if Index = 3 then Cost := Integer(Value)
73 else if Index = 4 then Moves := Integer(Value)
74 else if Index = 5 then PowerAttack := Integer(Value)
75 else if Index = 6 then PowerDefense := Integer(Value)
76 else if Index = 7 then ViewRange := Integer(Value)
77 else inherited;
78end;
79
80class function TUnitKind.GetClassSysName: string;
81begin
82 Result := 'UnitKind';
83end;
84
85class function TUnitKind.GetClassName: string;
86begin
87 Result := SUnitKind;
88end;
89
90{ TUnitKinds }
91
92constructor TUnitKinds.Create(FreeObjects: Boolean);
93begin
94 inherited;
95end;
96
97end.
98
Note: See TracBrowser for help on using the repository browser.