ScummVM API documentation
castle.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef FREESCAPE_CASTLE_H
23#define FREESCAPE_CASTLE_H
24
25namespace Freescape {
26
27// Offsets of the assets inside a Castle Master Amiga game image
29 int messages, riddles, colorCycling, fonts, palettes, soundTable, areaDB;
30 int area255, border, mountains, menu, menuButtons, spiritMeterBg, spiritMeter;
31 int indicators, thunder, weights, bar, eyeIcons, flag, riddleMask, riddleTop;
32 int gatePixels, gateMask, mod, keys;
33};
34
35// The same, for a decompressed Atari ST game program. Castle Master and its
36// sequel share the layout; riddles, extraAreas and area255 are zero when the
37// release has no such block.
39 int messages, messageCount, riddles, colorCycling, fonts, palettes, areaDB;
40 int extraAreas, area255, border, mountains, spiritMeterBg, spiritMeter;
41 int thunder, weights, bar, gatePixels, gateMask, eyeIcons, flag;
42 int riddleMask, riddleTop, mod, soundTable, soundBank, keys;
43};
44
45class MusicPlayer;
46
47struct RiddleText {
48 int8 _dx;
49 int8 _dy;
50 Common::String _text;
51
52 RiddleText(int8 dx, int8 dy, const Common::String &text) : _dx(dx), _dy(dy), _text(text) {}
53};
54
55struct Riddle {
56 Common::Point _origin;
58};
59
61public:
62 CastleEngine(OSystem *syst, const ADGameDescription *gd);
64
65 // Only in DOS
67 Graphics::ManagedSurface *_menuButtons;
68 Graphics::ManagedSurface *_menuCrawlIndicator;
69 Graphics::ManagedSurface *_menuWalkIndicator;
70 Graphics::ManagedSurface *_menuRunIndicator;
71 Graphics::ManagedSurface *_menuFxOnIndicator;
72 Graphics::ManagedSurface *_menuFxOffIndicator;
74 byte *_cursorData; // diagonal arrow (outside view area)
75 byte *_crosshairData; // crosshair (# pointer, inside view area)
76 int _cursorW;
77 int _cursorH;
78 void setAmigaCursor(bool crosshair);
79
80 void beforeStarting() override;
81 void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
82 void initGameState() override;
83 bool triggerWinCondition() override;
84 void endGame() override;
85 void executeEscapeCameraSequence();
86
87 void drawInfoMenu() override;
88 void loadAssets() override;
89 void loadAssetsDOSFullGame() override;
90 void loadAssetsDOSDemo() override;
91 void loadAssetsDOSDemoCGA();
92 void loadAssetsAmigaDemo() override;
93 void loadAssetsAmigaFullGame() override;
94 void loadAssetsAtariFullGame() override;
95 void loadAssetsZXFullGame() override;
96 void loadAssetsCPCFullGame() override;
97 void loadMessagesCastleMaster2(Common::SeekableReadStream *file, int offset, int number);
98 void borderScreen() override;
99 void selectCharacterScreen();
100 bool playAmigaIntro();
101 bool playAtariIntro();
102 void drawOption();
103
104 void initZX();
105 void initDOS();
106 void initCPC();
107 void initC64();
108
109 void loadAssetsC64FullGame() override;
110 void drawC64UI(Graphics::Surface *surface) override;
111 void drawC64InfoMenu(Graphics::Surface *surface);
112 void toggleC64AudioMode();
113 void updateC64SpiritPalette();
114 void updateC64BackgroundPalette();
115 void resetC64Lightning();
116 void updateC64Lightning();
117 void drawC64Background();
118 void drawC64HudSurface(Graphics::Surface *surface, const Graphics::Surface &frame, const Common::Point &origin);
119 void liftC64Gate();
120 void dropC64Gate();
121 void drawC64Gate(Graphics::Surface *surface);
122 Graphics::ManagedSurface _c64KeysBackground;
124 Graphics::ManagedSurface _c64MountainBackground;
125 Graphics::ManagedSurface _c64Lightning;
126 Common::Array<uint32> _c64UIColors;
127 Common::Array<byte> _c64GateDropHeights;
128 int _c64LiftingGateStartTicks;
129 bool _c64MusicEnabled;
130 byte _c64SpiritAttackColors[2];
131 int _c64SpiritAttackStartTicks;
132 int _c64NextLightningTicks;
133 int _c64LightningPhase;
134 int _c64LightningPhaseTicks;
135 int _c64LightningX;
136
137 void drawDOSUI(Graphics::Surface *surface) override;
138 void drawZXUI(Graphics::Surface *surface) override;
139 void drawCPCUI(Graphics::Surface *surface) override;
140 void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
141 void drawEnergyMeter(Graphics::Surface *surface, Common::Point origin);
142 void drawStrengthWeight(Graphics::Surface *surface, int frameIdx, const Common::Point &position, int width, uint32 back);
143 void drawLiftingGate(Graphics::Surface *surface);
144 void drawDroppingGate(Graphics::Surface *surface);
145 void pressedKey(const int keycode) override;
146 void releasedKey(const int keycode) override;
147 void checkSensors() override;
148 void updateTimeVariables() override;
149 void drawBackground() override;
150
151 bool checkIfGameEnded() override;
152 void drawSensorShoot(Sensor *sensor) override;
153
154 void executePrint(FCLInstruction &instruction) override;
155 void executeDestroy(FCLInstruction &instruction) override;
156 void executeRedraw(FCLInstruction &instruction) override;
157 void gotoArea(uint16 areaID, int entranceID) override;
158 Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
159 Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
160
161 Common::Array<Riddle> _riddleList;
162 Common::BitArray _fontPlane1;
163 Common::BitArray _fontPlane2;
164 Common::BitArray _fontPlane3;
165
166 void drawRiddleStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface);
167 Graphics::ManagedSurface *loadFrameWithHeaderDOS(Common::SeekableReadStream *file);
168 Common::Array <Graphics::ManagedSurface *>loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames);
169 Graphics::ManagedSurface *loadFrameWithHeaderDOSIndexed(Common::SeekableReadStream *file);
170 Common::Array<Graphics::ManagedSurface *> loadFramesWithHeaderDOSIndexed(Common::SeekableReadStream *file, int numFrames);
171 Graphics::ManagedSurface *loadFrameDOS(Common::SeekableReadStream *file, int widthInBytes, int height);
172 void convertFrameDOS(Graphics::ManagedSurface *frame);
173
174 Common::Array<Graphics::ManagedSurface *> loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back);
175 Graphics::ManagedSurface *loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back);
176
177 // CPC-specific frame loading (Mode 1: 4 pixels per byte)
178 // cpcPalette is a 4-entry array mapping CPC ink numbers (0-3) to ARGB colors
179 Common::Array<Graphics::ManagedSurface *> loadFramesWithHeaderCPC(Common::SeekableReadStream *file, int pos, int numFrames, const uint32 *cpcPalette);
180 Graphics::ManagedSurface *loadFrameWithHeaderCPC(Common::SeekableReadStream *file, int pos, const uint32 *cpcPalette);
181 Graphics::ManagedSurface *loadFrameCPC(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, const uint32 *cpcPalette);
182
183 Graphics::ManagedSurface *loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height);
184 Graphics::ManagedSurface *loadFrameFromPackedPixels(Common::SeekableReadStream *file, int widthInBytes, int height);
185 Graphics::ManagedSurface *loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height);
186
187 Graphics::ManagedSurface *loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height);
188 Graphics::ManagedSurface *loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane);
189 Graphics::ManagedSurface *loadFrameFromPlanesInterleaved(Common::SeekableReadStream *file, int widthInWords, int height);
190 Common::SeekableReadStream *openAmigaGameFile(const struct CastleAmigaLayout *&layout);
191 Common::SeekableReadStream *decompressCastle(Common::SeekableReadStream *file, uint32 packedOffset);
192 void loadThunderFramesAmiga(Common::SeekableReadStream *file, int offset);
193 void updateThunderFramesPalette();
194
197 Graphics::ManagedSurface *_spiritsMeterIndicatorBackgroundFrame;
198 Graphics::ManagedSurface *_spiritsMeterIndicatorFrame;
199 Graphics::ManagedSurface *_spiritsMeterIndicatorSideFrame;
200 Graphics::ManagedSurface *_strenghtBackgroundFrame;
201 Graphics::ManagedSurface *_strenghtBarFrame;
202 Common::Array<Graphics::ManagedSurface *> _strenghtWeightsFrames;
205
206 Graphics::ManagedSurface *_riddleTopFrame;
207 Graphics::ManagedSurface *_riddleBackgroundFrame;
208 Graphics::ManagedSurface *_riddleBottomFrame;
209 Graphics::ManagedSurface *_riddleNailFrame;
210
211 Graphics::ManagedSurface *_endGameThroneFrame;
212 Graphics::ManagedSurface *_endGameBackgroundFrame;
213 Graphics::ManagedSurface *_gameOverBackgroundFrame;
214
215 // CPC: CLUT8 versions of UI sprites (indexed by ink 0-3). On area change,
216 // we setPalette + convert to ARGB, like the border does in swapPalette.
217 Graphics::ManagedSurface *_strenghtBackgroundCLUT8;
218 Graphics::ManagedSurface *_strenghtBarCLUT8;
219 Common::Array<Graphics::ManagedSurface *> _strenghtWeightsCLUT8;
220 Graphics::ManagedSurface *_spiritsMeterBgCLUT8;
221 Graphics::ManagedSurface *_spiritsMeterIndCLUT8;
222 Graphics::ManagedSurface *_keysBorderCLUT8;
223 Graphics::ManagedSurface *_spiritsMeterSideCLUT8;
224 Common::Array<Graphics::ManagedSurface *> _keysBorderCLUT8Frames;
226 Graphics::ManagedSurface *_backgroundCLUT8;
228 uint32 _cpcUIPalette[4]; // used by gate rendering
229 void convertCPCSprite(Graphics::ManagedSurface *clut8, Graphics::ManagedSurface *&argb, bool transparentInk0 = false);
230 Graphics::ManagedSurface *loadFrameWithHeaderCPCIndexed(Common::SeekableReadStream *file, int pos);
231 Common::Array<Graphics::ManagedSurface *> loadFramesWithHeaderCPCIndexed(Common::SeekableReadStream *file, int pos, int numFrames);
232 void updateCPCSpritesPalette();
233 void updateCGASpritesPalette();
234 void updateCGAPalette(const byte *palette);
235 void updateFourColorSpritesPalette(const byte *palette);
236
237 Common::String _notEnoughRoomMessage;
238 Common::String _tooWeakMessage;
239 Common::String _crawlSelectedMessage;
240 Common::String _walkSelectedMessage;
241 Common::String _runSelectedMessage;
242 Common::String _ghostInAreaMessage;
243
244 Common::Array<byte> _modData; // Embedded ProTracker module (Amiga demo)
245 MusicPlayer *_playerMusic;
246 Common::Array<int> _keysCollected;
247 bool _useRockTravel;
248 int _spiritsMeter;
249 int _spiritsMeterPosition;
250 int _spiritsMeterMax;
251 int _spiritsToKill;
252
253 int _lastTenSeconds;
254 int _soundIndexStartFalling;
255 bool _selectedPrincess;
256
257private:
258 Common::SeekableReadStream *decryptFile(const Common::Path &filename);
259 Common::SeekableReadStream *decompressAtari(const Common::Path &filename);
260 void loadAtariLoadingScreen();
261 void loadRiddles(Common::SeekableReadStream *file, int offset, int number);
262 void loadMessagesC64(Common::SeekableReadStream *file, int offset, int number);
263 void loadRiddlesC64(Common::SeekableReadStream *file, int offset, int number);
264 void loadDOSFonts(Common::SeekableReadStream *file, int pos);
265 void drawFullscreenRiddleAndWait(uint16 riddle);
266 void drawFullscreenEndGameAndWait();
267 void drawFullscreenAmigaEndGameAndWait();
268 void drawFullscreenGameOverAndWait();
269 void drawRiddle(uint16 riddle, uint32 front, uint32 back, Graphics::Surface *surface);
270 void tryToCollectKey();
271 void addGhosts();
272 bool hasEscaped();
273 bool ghostInArea();
274 void updateThunder();
275
276 /*Audio::SoundHandle _soundFxGhostHandle;*/
277 Texture *_optionTexture;
278 Font _fontRiddle;
279 int _droppingGateStartTicks;
280 int _thunderTicks;
281 int _thunderFrameDuration;
282 int _thunderFrameIndex;
283 Math::Vector3d _thunderOffset;
284 Common::Array<Texture *>_thunderTextures;
285 // Amiga and Atari ST: kept indexed, to be recolored per area
287};
288
289}
290
291#endif // FREESCAPE_CASTLE_H
Definition: array.h:52
Definition: bitarray.h:29
Definition: error.h:81
Definition: keymap.h:66
Definition: path.h:52
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Definition: castle.h:60
Definition: instruction.h:49
Definition: font.h:32
Definition: freescape.h:191
Definition: music.h:29
Definition: sensor.h:34
Definition: gfx.h:50
Definition: managed_surface.h:51
Definition: system.h:166
Definition: area.h:36
Definition: advancedDetector.h:164
Definition: rect.h:144
Definition: castle.h:28
Definition: castle.h:38
Definition: castle.h:55
Definition: castle.h:47
Definition: surface.h:67