forked from ericlangedijk/Lemmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Level.Base.pas
257 lines (227 loc) · 7.08 KB
/
Level.Base.pas
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
unit Level.Base;
{$include lem_directives.inc}
interface
uses
Classes, SysUtils,
Base.Utils;
const
// Terrain Drawing Flags
tdf_Erase = 1; // bit 0 use terrain bitmap as eraser
tdf_Invert = 2; // bit 1 invert terrain bitmap
tdf_NoOverwrite = 4; // bit 2 do not overwrite existing terrain pixels
const
// Object Drawing Flags
odf_OnlyOnTerrain = 1; // bit 0
odf_UpsideDown = 2; // bit 1
odf_NoOverwrite = 4; // bit 2
type
TLevelInfo = class(TPersistent)
protected
fReleaseRate : Integer;
fLemmingsCount : Integer;
fRescueCount : Integer;
fTimeLimit : Integer;
fClimberCount : Integer;
fFloaterCount : Integer;
fBomberCount : Integer;
fBlockerCount : Integer;
fBuilderCount : Integer;
fBasherCount : Integer;
fMinerCount : Integer;
fDiggerCount : Integer;
fGraphicSet : Integer;
fGraphicSetEx : Integer;
fSuperLemming : Boolean;
fScreenPosition : Integer;
fTitle : string;
protected
public
constructor Create;
procedure Assign(Source: TPersistent); override;
procedure Clear; virtual;
public
property ReleaseRate : Integer read fReleaseRate write fReleaseRate;
property LemmingsCount : Integer read fLemmingsCount write fLemmingsCount;
property RescueCount : Integer read fRescueCount write fRescueCount;
property TimeLimit : Integer read fTimeLimit write fTimeLimit;
property ClimberCount : Integer read fClimberCount write fClimberCount;
property FloaterCount : Integer read fFloaterCount write fFloaterCount;
property BomberCount : Integer read fBomberCount write fBomberCount;
property BlockerCount : Integer read fBlockerCount write fBlockerCount;
property BuilderCount : Integer read fBuilderCount write fBuilderCount;
property BasherCount : Integer read fBasherCount write fBasherCount;
property MinerCount : Integer read fMinerCount write fMinerCount;
property DiggerCount : Integer read fDiggerCount write fDiggerCount;
property GraphicSet : Integer read fGraphicSet write fGraphicSet;
property GraphicSetEx : Integer read fGraphicSetEx write fGraphicSetEx;
property SuperLemming : Boolean read fSuperLemming write fSuperLemming;
property ScreenPosition : Integer read fScreenPosition write fScreenPosition;
property Title : string read fTitle write fTitle;
end;
// abstract ancestor for object, terrain and steel
TPiece = class
protected
fLeft : Integer;
fTop : Integer;
public
property Left: Integer read fLeft write fLeft;
property Top: Integer read fTop write fTop;
end;
// basic ancestor for object and terrain
TIdentifiedPiece = class(TPiece)
protected
fIdentifier: Integer;
public
property Identifier: Integer read fIdentifier write fIdentifier;
end;
TTerrain = class(TIdentifiedPiece)
protected
fDrawingFlags : Byte;
public
property DrawingFlags: Byte read fDrawingFlags write fDrawingFlags;
end;
TInteractiveObject = class(TIdentifiedPiece)
protected
fDrawingFlags: Byte; // odf_xxxx
public
property DrawingFlags: Byte read fDrawingFlags write fDrawingFlags;
end;
TSteel = class(TPiece)
protected
fHeight: Integer;
fWidth: Integer;
public
property Width: Integer read fWidth write fWidth;
property Height: Integer read fHeight write fHeight;
end;
TInteractiveObjects = class(TFastObjectList<TInteractiveObject>);
TTerrains = class(TFastObjectList<TTerrain>);
TSteels = class(TFastObjectList<TSteel>);
TLevel = class(TPersistent)
protected
fLevelInfo : TLevelInfo;
fTerrains : TTerrains;
fInteractiveObjects : TInteractiveObjects;
fSteels : TSteels;
function DoCreateLevelInfo: TLevelInfo; dynamic;
function DoCreateTerrains: TTerrains; dynamic;
function DoCreateInteractiveObjects: TInteractiveObjects; dynamic;
function DoCreateSteels: TSteels; dynamic;
public
constructor Create;
destructor Destroy; override;
procedure SaveToFile(const aFileName: string);
procedure SaveToStream(S: TStream);
procedure ClearLevel;
property Info: TLevelInfo read fLevelInfo;
property InteractiveObjects: TInteractiveObjects read fInteractiveObjects;
property Terrains: TTerrains read fTerrains;
property Steels: TSteels read fSteels;
end;
implementation
{ TLevelInfo }
procedure TLevelInfo.Assign(Source: TPersistent);
var
L: TLevelInfo absolute Source;
begin
if Source is TLevelInfo then begin
ReleaseRate := L.ReleaseRate;
LemmingsCount := L.LemmingsCount;
RescueCount := L.RescueCount;
TimeLimit := L.TimeLimit;
ClimberCount := L.ClimberCount;
FloaterCount := L.FloaterCount;
BomberCount := L.BomberCount;
BlockerCount := L.BlockerCount;
BuilderCount := L.BuilderCount;
BasherCount := L.BasherCount;
MinerCount := L.MinerCount;
DiggerCount := L.DiggerCount;
GraphicSet := L.GraphicSet;
GraphicSetEx := L.GraphicSetEx;
SuperLemming := L.SuperLemming;
ScreenPosition := L.ScreenPosition;
Title := L.Title;
end
else inherited Assign(Source);
end;
procedure TLevelInfo.Clear;
begin
ReleaseRate := 1;
LemmingsCount := 1;
RescueCount := 1;
TimeLimit := 1;
ClimberCount := 0;
FloaterCount := 0;
BomberCount := 0;
BlockerCount := 0;
BuilderCount := 0;
BasherCount := 0;
MinerCount := 0;
DiggerCount := 0;
GraphicSet := 0;
GraphicSetEx := 0;
SuperLemming := False;
ScreenPosition := 0;
Title := '';
end;
constructor TLevelInfo.Create;
begin
inherited Create;
Clear;
end;
{ TLevel }
procedure TLevel.ClearLevel;
begin
fInteractiveObjects.Clear;
fTerrains.Clear;
fSteels.Clear;
end;
constructor TLevel.Create;
begin
inherited Create;
fLevelInfo := DoCreateLevelInfo;
fInteractiveObjects := DoCreateInteractiveObjects;
fTerrains := DoCreateTerrains;
fSteels := DoCreateSteels;
end;
destructor TLevel.Destroy;
begin
fLevelInfo.Free;
fInteractiveObjects.Free;
fTerrains.Free;
fSteels.Free;
inherited Destroy;
end;
function TLevel.DoCreateInteractiveObjects: TInteractiveObjects;
begin
Result := TInteractiveObjects.Create;
end;
function TLevel.DoCreateLevelInfo: TLevelInfo;
begin
Result := TLevelInfo.Create;
end;
function TLevel.DoCreateSteels: TSteels;
begin
Result := TSteels.Create;
end;
function TLevel.DoCreateTerrains: TTerrains;
begin
Result := TTerrains.Create;
end;
procedure TLevel.SaveToFile(const aFileName: string);
var
F: TBufferedFileStream;
begin
F := TBufferedFileStream.Create(aFileName, fmCreate);
try
SaveToStream(F);
finally
F.Free;
end;
end;
procedure TLevel.SaveToStream(S: TStream);
begin
Throw('SaveToStream not implemented', 'SaveToStream');
end;
end.