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