Rev 11 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 11 | Rev 12 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | 6 | ||
7 | const |
7 | const |
8 | SCENEID_PREVDECISION = -1; |
8 | SCENEID_PREVDECISION = -1; |
9 | SCENEID_ENDGAME = 32767; |
9 | SCENEID_ENDGAME = 32767; |
10 | 10 | ||
- | 11 | SEGMENT_BEGINNING = 0; |
|
- | 12 | SEGMENT_DECISION = 1; |
|
- | 13 | ||
11 | type |
14 | type |
12 | PCoord = ^TCoord; |
15 | PCoord = ^TCoord; |
13 | TCoord = packed record |
16 | TCoord = packed record |
14 | x: Word; |
17 | x: Word; |
15 | y: Word; |
18 | y: Word; |
16 | end; |
19 | end; |
17 | 20 | ||
18 | PActionDef = ^TActionDef; |
21 | PActionDef = ^TActionDef; |
19 | TActionDef = packed record |
22 | TActionDef = packed record |
20 | scoreDelta: Integer; |
23 | scoreDelta: Integer; |
21 | nextSceneID: SmallInt; // will jump to the scene with the name "SC<nextSceneID>" |
24 | nextSceneID: SmallInt; // will jump to the scene with the name "SCxx", |
- | 25 | // where xx stands for nextSceneID (2 digits at least) |
|
22 | // 7FFF (32767) = end game |
26 | // 7FFF (32767) = end game |
23 | // FFFF ( -1) = go back to the last decision |
27 | // FFFF ( -1) = go back to the last decision |
24 | sceneSegment: SmallInt; // 0 = scene from beginning, 1 = decision page |
28 | sceneSegment: SmallInt; // 0 = scene from beginning, 1 = decision page |
25 | cHotspotTopLeft: TCoord; |
29 | cHotspotTopLeft: TCoord; |
26 | cHotspotBottomRight: TCoord; |
30 | cHotspotBottomRight: TCoord; |
Line 57... | Line 61... | ||
57 | 61 | ||
58 | class function MaxSceneCount: integer; static; |
62 | class function MaxSceneCount: integer; static; |
59 | class function MaxPictureCount: integer; static; |
63 | class function MaxPictureCount: integer; static; |
60 | 64 | ||
61 | function AddSceneAtEnd(SceneID: integer): PSceneDef; |
65 | function AddSceneAtEnd(SceneID: integer): PSceneDef; |
- | 66 | function FindScene(SceneID: integer): PSceneDef; |
|
- | 67 | function FindSceneIndex(SceneID: integer): integer; |
|
62 | procedure DeleteScene(SceneIndex: integer); |
68 | procedure DeleteScene(SceneIndex: integer); |
63 | procedure SwapScene(IndexA, IndexB: integer); |
69 | procedure SwapScene(IndexA, IndexB: integer); |
64 | procedure DeletePicture(PictureIndex: integer); |
70 | procedure DeletePicture(PictureIndex: integer); |
65 | procedure SwapPicture(IndexA, IndexB: integer); |
71 | procedure SwapPicture(IndexA, IndexB: integer); |
66 | function AddPictureBetween(Index: integer; assignToUpperScene: boolean=true): PPictureDef; |
72 | function AddPictureBetween(Index: integer; assignToUpperScene: boolean=true): PPictureDef; |
Line 81... | Line 87... | ||
81 | begin |
87 | begin |
82 | ZeroMemory(x, Length(x^)); |
88 | ZeroMemory(x, Length(x^)); |
83 | StrPLCopy(x^, s, Length(x^)); |
89 | StrPLCopy(x^, s, Length(x^)); |
84 | end; |
90 | end; |
85 | 91 | ||
- | 92 | { TGameBinFile } |
|
- | 93 | ||
86 | function TGameBinFile.BiggestUsedPictureIndex: integer; |
94 | function TGameBinFile.BiggestUsedPictureIndex: integer; |
87 | var |
95 | var |
88 | iScene, candidate: integer; |
96 | iScene, candidate: integer; |
89 | begin |
97 | begin |
90 | result := -1; |
98 | result := -1; |
Line 93... | Line 101... | ||
93 | candidate := Self.scenes[iScene].pictureIndex + Self.scenes[iScene].numPics - 1; |
101 | candidate := Self.scenes[iScene].pictureIndex + Self.scenes[iScene].numPics - 1; |
94 | if candidate > result then result := candidate; |
102 | if candidate > result then result := candidate; |
95 | end; |
103 | end; |
96 | end; |
104 | end; |
97 | 105 | ||
- | 106 | resourcestring |
|
- | 107 | S_INVALID_SCENE_ID = 'Invalid scene ID'; |
|
- | 108 | ||
98 | function TGameBinFile.AddSceneAtEnd(SceneID: integer): PSceneDef; |
109 | function TGameBinFile.AddSceneAtEnd(SceneID: integer): PSceneDef; |
- | 110 | resourcestring |
|
- | 111 | S_SCENE_FULL = 'Not enough space for another scene'; |
|
99 | begin |
112 | begin |
100 | if Self.numScenes >= Length(Self.scenes) then raise Exception.Create('Not enough space for another scene'); |
113 | if Self.numScenes >= Length(Self.scenes) then raise Exception.Create(S_SCENE_FULL); |
101 | if SceneID < 0 then raise Exception.Create('Invalid scene ID'); |
114 | if SceneID = $7FFF {Terminate program} then raise Exception.Create(S_INVALID_SCENE_ID); |
102 | if sceneID >= Length(Self.scenes) then raise Exception.Create('SceneID is too large.'); // TODO: I think this is not correct. This is the scene *ID* |
115 | if SceneID = $FFFF {Previous decision} then raise Exception.Create(S_INVALID_SCENE_ID); |
103 | result := @Self.scenes[Self.numScenes]; |
116 | result := @Self.scenes[Self.numScenes]; |
104 | ZeroMemory(result, SizeOf(TSceneDef)); |
117 | ZeroMemory(result, SizeOf(TSceneDef)); |
105 | _WriteStringToFilename(@result.szSceneFolder, AnsiString(Format('SC%.2d', [sceneID]))); |
118 | _WriteStringToFilename(@result.szSceneFolder, AnsiString(Format('SC%.2d', [sceneID]))); |
106 | Inc(Self.numScenes); |
119 | Inc(Self.numScenes); |
107 | end; |
120 | end; |
108 | 121 | ||
- | 122 | function TGameBinFile.FindSceneIndex(SceneID: integer): integer; |
|
- | 123 | var |
|
- | 124 | i: integer; |
|
- | 125 | begin |
|
- | 126 | if SceneID = $7FFF {Terminate program} then raise Exception.Create(S_INVALID_SCENE_ID); |
|
- | 127 | if SceneID = $FFFF {Previous decision} then raise Exception.Create(S_INVALID_SCENE_ID); |
|
- | 128 | for i := 0 to Self.numScenes - 1 do |
|
- | 129 | begin |
|
- | 130 | if Self.scenes[i].szSceneFolder = Format('SC%.2d', [SceneID]) then |
|
- | 131 | begin |
|
- | 132 | result := i; |
|
- | 133 | exit; |
|
- | 134 | end; |
|
- | 135 | end; |
|
- | 136 | result := -1; |
|
- | 137 | end; |
|
- | 138 | ||
- | 139 | function TGameBinFile.FindScene(SceneID: integer): PSceneDef; |
|
- | 140 | var |
|
- | 141 | idx: integer; |
|
- | 142 | begin |
|
- | 143 | idx := FindSceneIndex(SceneID); |
|
- | 144 | if idx >= 0 then |
|
- | 145 | result := @Self.scenes[idx] |
|
- | 146 | else |
|
- | 147 | result := nil; |
|
- | 148 | end; |
|
- | 149 | ||
109 | procedure TGameBinFile.DeleteScene(SceneIndex: integer); |
150 | procedure TGameBinFile.DeleteScene(SceneIndex: integer); |
- | 151 | resourcestring |
|
- | 152 | S_INVALID_SC_IDX = 'Invalid scene index'; |
|
110 | begin |
153 | begin |
111 | if ((SceneIndex < 0) or (SceneIndex >= Length(Self.scenes))) then raise Exception.Create('Invalid scene index'); |
154 | if ((SceneIndex < 0) or (SceneIndex >= Length(Self.scenes))) then raise Exception.Create(S_INVALID_SC_IDX); |
112 | If SceneIndex < Length(Self.scenes)-1 then |
155 | If SceneIndex < Length(Self.scenes)-1 then |
113 | begin |
156 | begin |
114 | CopyMemory(@Self.scenes[SceneIndex], @Self.scenes[SceneIndex+1], (Length(Self.scenes)-SceneIndex-1)*SizeOf(TSceneDef)); |
157 | CopyMemory(@Self.scenes[SceneIndex], @Self.scenes[SceneIndex+1], (Length(Self.scenes)-SceneIndex-1)*SizeOf(TSceneDef)); |
115 | end; |
158 | end; |
116 | ZeroMemory(@Self.scenes[Length(Self.scenes)-1], SizeOf(TSceneDef)); |
159 | ZeroMemory(@Self.scenes[Length(Self.scenes)-1], SizeOf(TSceneDef)); |
Line 275... | Line 318... | ||
275 | end; |
318 | end; |
276 | end; |
319 | end; |
277 | result := false; |
320 | result := false; |
278 | end; |
321 | end; |
279 | 322 | ||
- | 323 | resourcestring |
|
- | 324 | S_INVALID_PIC_IDX = 'Invalid picture index'; |
|
- | 325 | S_PIC_FULL_DEFRAG = 'Not enough space for another picture. Please defrag to fill the gaps first.'; |
|
- | 326 | S_PIC_FULL = 'Not enough space for another picture. Maximum limit reached.'; |
|
280 | var |
327 | var |
281 | iScene: integer; |
328 | iScene: integer; |
282 | begin |
329 | begin |
283 | if ((Index < 0) or (Index >= Length(Self.pictures))) then raise Exception.Create('Invalid picture index'); |
330 | if ((Index < 0) or (Index >= Length(Self.pictures))) then raise Exception.Create(S_INVALID_PIC_IDX); |
284 | 331 | ||
285 | if (BiggestUsedPictureIndex = MaxPictureCount-1) and Defrag(true) then |
332 | if (BiggestUsedPictureIndex = MaxPictureCount-1) and Defrag(true) then |
286 | raise Exception.Create('Not enough space for another picture. Please defrag to fill the gaps first.'); |
333 | raise Exception.Create(S_PIC_FULL_DEFRAG); |
287 | 334 | ||
288 | if Self.numPics >= MaxPictureCount then |
335 | if Self.numPics >= MaxPictureCount then |
289 | raise Exception.Create('Not enough space for another picture. Maximum limit reached.'); |
336 | raise Exception.Create(S_PIC_FULL); |
290 | 337 | ||
291 | if assignToUpperScene then |
338 | if assignToUpperScene then |
292 | begin |
339 | begin |
293 | // Sc1 Sc2 Sc1 Sc2 |
340 | // Sc1 Sc2 Sc1 Sc2 |
294 | // A B | C ==> A B | X C |
341 | // A B | C ==> A B | X C |