[go: up one dir, main page]

Menu

[r29]: / trunk / Core / Aer_Model.pas  Maximize  Restore  History

Download this file

340 lines (284 with data), 8.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
unit Aer_Model; (* Aer_Model.pas *)
{$MODE ObjFPC}
{$H+}
interface
uses
Contnrs, SysUtils,
(* project units *)
Aer_Definitions;
type
TAerModelClass = class (TObject)
private
_id: TAerModelId;
public
property Id: TAerModelId read _id write _id;
public
function ToString: WideString;
end;
TAerModelList = class(TObject)
private
_objectList: TFPObjectList;
private
function GetObjectCount: Integer;
public
constructor Create;
destructor Destroy; override;
public
property Count: Integer read GetObjectCount;
end;
TSiteHeader = class(TAerModelClass)
private
_name: WideString;
private
function GetNameAndId: WideString;
public
property Name: WideString read _name write _name;
property NameAndId: WideString read GetNameAndId;
public
function ToString: WideString;
end;
TSite = class(TSiteHeader)
private
_text: WideString;
_optionFlags: TSiteOptionFlags;
public
property Text: WideString read _text write _text;
property OptionFlags: TSiteOptionFlags read _optionFlags write _optionFlags;
public
function ToString: WideString;
end;
TSites = class(TAerModelList)
protected
function GetItem(index: Integer): TSite;
public
property Items[index: Integer]: TSite read GetItem;
public
function Add(site: TSite): Integer;
procedure Remove(site: TSite);
end;
{ TSiteAction }
TSiteAction = class(TAerModelClass)
private
_siteId: TAerModelId;
_priority: Integer;
_actionType: ESiteActionType;
_actionObject: TAerModelId;
_actionData: WideString;
public
property SiteId: TAerModelId read _siteId write _siteId;
property Priority: Integer read _priority write _priority;
property ActionType: ESiteActionType read _actionType write _actionType;
property ActionObject: TAerModelId read _actionObject write _actionObject;
property ActionData: WideString read _actionData write _actionData;
public
function ToString: WideString;
end;
TSiteActions = class(TAerModelList)
protected
function GetItem(index: Integer): TSiteAction;
public
property Items[index: Integer]: TSiteAction read GetItem;
public
function Add(siteAction: TSiteAction): Integer;
procedure Exchange(index1, index2: Integer);
procedure Remove(siteAction: TSiteAction);
end;
{ TSiteExit }
TSiteExit = class(TAerModelClass)
private
_siteId: TAerModelId;
_gotoSite: TAerModelId;
_title: WideString;
public
property SiteId: TAerModelId read _siteId write _siteId;
property GotoSite: TAerModelId read _gotoSite write _gotoSite;
property Title: WideString read _title write _title;
public
function ToString: WideString;
end;
TSiteExits = class(TAerModelList)
protected
function GetItem(index: Integer): TSiteExit;
public
property Items[index: Integer]: TSiteExit read GetItem;
public
function Add(siteExit: TSiteExit): Integer;
procedure Remove(siteExit: TSiteExit);
end;
{ TSiteExitCondition }
TSiteExitCondition = class(TAerModelClass)
private
_siteExitId: TAerModelId;
_conditionType: ESiteExitConditionType;
_conditionObject: TAerModelId;
_conditionData: WideString;
public
property SiteExitId: TAerModelId read _siteExitId write _siteExitId;
property ConditionType: ESiteExitConditionType read _conditionType write _conditionType;
property ConditionObject: TAerModelId read _conditionObject write _conditionObject;
property ConditionData: WideString read _conditionData write _conditionData;
public
function ToString: WideString;
end;
TSiteExitConditions = class(TAerModelList)
protected
function GetItem(index: Integer): TSiteExitCondition;
public
property Items[index: Integer]: TSiteExitCondition read GetItem;
public
function Add(siteExitCondition: TSiteExitCondition): Integer;
procedure Remove(siteExitCondition: TSiteExitCondition);
end;
(* Inventory not yet implemented *)
(* =============================
TInventoryGroup = class(TAerModelClass)
private
_name: WideString;
_optionFlags: TInventoryGroupOptionFlags;
public
property Name: WideString read _name write _name;
property OptionFlags: TInventoryGroupOptionFlags read _optionFlags write _optionFlags;
end;
TInventoryItem = class(TAerModelClass)
private
_groupId: TAerModelId;
_title: WideString;
_optionFlags: TInventoryItemOptionFlags;
_unitTitle: WideString;
public
property GroupId: TAerModelId read _groupId write _groupId;
property Title: WideString read _title write _title;
property OptionFlags: TInventoryItemOptionFlags read _optionFlags write _optionFlags;
property UnitTitle: WideString read _unitTitle write _unitTitle;
end;
*)
implementation
(* TSiteHeader *)
function TSiteHeader.GetNameAndId: WideString;
var
buildString: WideString;
begin
buildString:= _name + '(' + (_id) + ')';
Result:= buildString;
end;
function TSiteHeader.ToString: WideString;
begin
Result:= (inherited ToString) + System.LineEnding + _name;
end;
(* TAerModelList *)
constructor TAerModelList.Create;
begin
inherited Create;
_objectList:= TFPObjectList.Create;
end;
destructor TAerModelList.Destroy;
begin
FreeAndNil(_objectList);
inherited Destroy;
end;
function TAerModelList.GetObjectCount: Integer;
begin
GetObjectCount:= _objectList.Count;
end;
(* TSites *)
function TSites.GetItem(index: Integer): TSite;
begin
Result:= TSite(_objectList.Items[index]);
end;
function TSites.Add(site: TSite): Integer;
begin
Result:= _objectList.Add(site);
end;
procedure TSites.Remove(site: TSite);
begin
_objectList.Remove(site);
end;
(* TSiteActions *)
function TSiteActions.GetItem(index: Integer): TSiteAction;
begin
Result:= TSiteAction(_objectList.Items[index]);
end;
function TSiteActions.Add(siteAction: TSiteAction): Integer;
begin
Result:= _objectList.Add(siteAction);
siteAction.Priority:= Result;
end;
procedure TSiteActions.Exchange(index1, index2: Integer);
// SiteActions is the only class, which proxy the TFPObjectList.Exchange method.
// This is needed, because of the Priority property, which is equal to the index
// of the SiteAction in the list.
begin
_objectList.Exchange(index1, index2);
// set the Priority field to the new index
TSiteAction(_objectList.Items[index1]).Priority:= index1;
TSiteAction(_objectList.Items[index2]).Priority:= index2;
end;
procedure TSiteActions.Remove(siteAction: TSiteAction);
var
actualCursor: Integer;
begin
_objectList.Remove(siteAction);
// go through all remaining SiteActions an aset the Priority field to their
// actual index
for actualCursor:= 0 to( _objectList.Count-1) do
TSiteAction(_objectList.Items[actualCursor]).Priority:= actualCursor;
end;
(* TSiteExits *)
function TSiteExits.GetItem(index: Integer): TSiteExit;
begin
Result:= TSiteExit(_objectList.Items[index]);
end;
function TSiteExits.Add(siteExit: TSiteExit): Integer;
begin
Result:= _objectList.Add(siteExit);
end;
procedure TSiteExits.Remove(siteExit: TSiteExit);
begin
_objectList.Remove(siteExit);
end;
(* TSiteExitConditions *)
function TSiteExitConditions.GetItem(index: Integer): TSiteExitCondition;
begin
Result:= TSiteExitCondition(_objectList.Items[index]);
end;
function TSiteExitConditions.Add(siteExitCondition: TSiteExitCondition): Integer;
begin
Result:= _objectList.Add(siteExitCondition);
end;
procedure TSiteExitConditions.Remove(siteExitCondition: TSiteExitCondition);
begin
_objectList.Remove(siteExitCondition);
end;
(* TAerModelClass *)
function TAerModelClass.ToString: WideString;
begin
Result:= _id;
end;
(* TSite *)
function TSite.ToString: WideString;
begin
Result:= (inherited ToString) + System.LineEnding + _text;
end;
(* TSiteAction *)
function TSiteAction.ToString: WideString;
begin
Result:= (inherited ToString) + System.LineEnding
+ 'Site: ' + _siteId + System.LineEnding
+ 'Action: ' + EnumToString(_actionType) + '(' + _actionObject + ', ' + _actionData + ');';
end;
(* TSiteExit *)
function TSiteExit.ToString: WideString;
begin
Result:= (inherited ToString) + System.LineEnding
+ 'Title: ' + _title + System.LineEnding
+ 'Site: ' + _siteId + System.LineEnding
+ 'Goto Site:' + _gotoSite;
end;
(* TSiteExitCondition *)
function TSiteExitCondition.ToString: WideString;
begin
Result:= (inherited ToString) + System.LineEnding
+ 'SiteExit: ' + _siteExitId + System.LineEnding
+ 'ConditionType: ' + EnumToString(_conditionType) + '(' + _conditionObject + ',' + _conditionData + ');' + System.LineEnding;
end;
end.