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 class MusicPlayer;
25 
26 struct RiddleText {
27  int8 _dx;
28  int8 _dy;
29  Common::String _text;
30 
31  RiddleText(int8 dx, int8 dy, const Common::String &text) : _dx(dx), _dy(dy), _text(text) {}
32 };
33 
34 struct Riddle {
35  Common::Point _origin;
37 };
38 
39 class CastleEngine : public FreescapeEngine {
40 public:
41  CastleEngine(OSystem *syst, const ADGameDescription *gd);
42  ~CastleEngine();
43 
44  // Only in DOS
45  Graphics::ManagedSurface *_option;
46  Graphics::ManagedSurface *_menuButtons;
47  Graphics::ManagedSurface *_menuCrawlIndicator;
48  Graphics::ManagedSurface *_menuWalkIndicator;
49  Graphics::ManagedSurface *_menuRunIndicator;
50  Graphics::ManagedSurface *_menuFxOnIndicator;
51  Graphics::ManagedSurface *_menuFxOffIndicator;
53  byte *_cursorData; // diagonal arrow (outside view area)
54  byte *_crosshairData; // crosshair (# pointer, inside view area)
55  int _cursorW;
56  int _cursorH;
57  void setAmigaCursor(bool crosshair);
58 
59  void beforeStarting() override;
60  void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
61  void initGameState() override;
62  bool triggerWinCondition() override;
63  void endGame() override;
64  void executeEscapeCameraSequence();
65 
66  void drawInfoMenu() override;
67  void loadAssets() override;
68  void loadAssetsDOSFullGame() override;
69  void loadAssetsDOSDemo() override;
70  void loadAssetsAmigaDemo() override;
71  void loadAssetsAmigaFullGame() override;
72  void loadAssetsAtariFullGame() override;
73  void loadAssetsZXFullGame() override;
74  void loadAssetsCPCFullGame() override;
75  void borderScreen() override;
76  void selectCharacterScreen();
77  bool playAmigaIntro();
78  bool playAtariIntro();
79  void drawOption();
80 
81  void initZX();
82  void initDOS();
83  void initCPC();
84  void initC64();
85 
86  void loadAssetsC64FullGame() override;
87  void drawC64UI(Graphics::Surface *surface) override;
88 
89  void drawDOSUI(Graphics::Surface *surface) override;
90  void drawZXUI(Graphics::Surface *surface) override;
91  void drawCPCUI(Graphics::Surface *surface) override;
92  void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
93  void drawEnergyMeter(Graphics::Surface *surface, Common::Point origin);
94  void drawLiftingGate(Graphics::Surface *surface);
95  void drawDroppingGate(Graphics::Surface *surface);
96  void pressedKey(const int keycode) override;
97  void releasedKey(const int keycode) override;
98  void checkSensors() override;
99  void updateTimeVariables() override;
100  void drawBackground() override;
101 
102  bool checkIfGameEnded() override;
103  void drawSensorShoot(Sensor *sensor) override;
104 
105  void executePrint(FCLInstruction &instruction) override;
106  void executeDestroy(FCLInstruction &instruction) override;
107  void executeRedraw(FCLInstruction &instruction) override;
108  void gotoArea(uint16 areaID, int entranceID) override;
109  Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
110  Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
111 
112  Common::Array<Riddle> _riddleList;
113  Common::BitArray _fontPlane1;
114  Common::BitArray _fontPlane2;
115  Common::BitArray _fontPlane3;
116 
117  void drawRiddleStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface);
118  Graphics::ManagedSurface *loadFrameWithHeaderDOS(Common::SeekableReadStream *file);
119  Common::Array <Graphics::ManagedSurface *>loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames);
120 
121  Common::Array<Graphics::ManagedSurface *> loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back);
122  Graphics::ManagedSurface *loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back);
123 
124  // CPC-specific frame loading (Mode 1: 4 pixels per byte)
125  // cpcPalette is a 4-entry array mapping CPC ink numbers (0-3) to ARGB colors
126  Common::Array<Graphics::ManagedSurface *> loadFramesWithHeaderCPC(Common::SeekableReadStream *file, int pos, int numFrames, const uint32 *cpcPalette);
127  Graphics::ManagedSurface *loadFrameWithHeaderCPC(Common::SeekableReadStream *file, int pos, const uint32 *cpcPalette);
128  Graphics::ManagedSurface *loadFrameCPC(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, const uint32 *cpcPalette);
129 
130  Graphics::ManagedSurface *loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height);
131  Graphics::ManagedSurface *loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height);
132 
133  Graphics::ManagedSurface *loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height);
134  Graphics::ManagedSurface *loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane);
135  Graphics::ManagedSurface *loadFrameFromPlanesInterleaved(Common::SeekableReadStream *file, int widthInWords, int height);
136 
139  Graphics::ManagedSurface *_spiritsMeterIndicatorBackgroundFrame;
140  Graphics::ManagedSurface *_spiritsMeterIndicatorFrame;
141  Graphics::ManagedSurface *_spiritsMeterIndicatorSideFrame;
142  Graphics::ManagedSurface *_strenghtBackgroundFrame;
143  Graphics::ManagedSurface *_strenghtBarFrame;
144  Common::Array<Graphics::ManagedSurface *> _strenghtWeightsFrames;
147 
148  Graphics::ManagedSurface *_riddleTopFrame;
149  Graphics::ManagedSurface *_riddleBackgroundFrame;
150  Graphics::ManagedSurface *_riddleBottomFrame;
151  Graphics::ManagedSurface *_riddleNailFrame;
152 
153  Graphics::ManagedSurface *_endGameThroneFrame;
154  Graphics::ManagedSurface *_endGameBackgroundFrame;
155  Graphics::ManagedSurface *_gameOverBackgroundFrame;
156 
157  // CPC: CLUT8 versions of UI sprites (indexed by ink 0-3). On area change,
158  // we setPalette + convert to ARGB, like the border does in swapPalette.
159  Graphics::ManagedSurface *_strenghtBackgroundCLUT8;
160  Graphics::ManagedSurface *_strenghtBarCLUT8;
161  Common::Array<Graphics::ManagedSurface *> _strenghtWeightsCLUT8;
162  Graphics::ManagedSurface *_spiritsMeterBgCLUT8;
163  Graphics::ManagedSurface *_spiritsMeterIndCLUT8;
164  Graphics::ManagedSurface *_keysBorderCLUT8;
166  uint32 _cpcUIPalette[4]; // used by gate rendering
167  void convertCPCSprite(Graphics::ManagedSurface *clut8, Graphics::ManagedSurface *&argb, bool transparentInk0 = false);
168  Graphics::ManagedSurface *loadFrameWithHeaderCPCIndexed(Common::SeekableReadStream *file, int pos);
169  Common::Array<Graphics::ManagedSurface *> loadFramesWithHeaderCPCIndexed(Common::SeekableReadStream *file, int pos, int numFrames);
170  void updateCPCSpritesPalette();
171 
172  Common::String _notEnoughRoomMessage;
173  Common::String _tooWeakMessage;
174  Common::String _crawlSelectedMessage;
175  Common::String _walkSelectedMessage;
176  Common::String _runSelectedMessage;
177  Common::String _ghostInAreaMessage;
178 
179  Common::Array<byte> _modData; // Embedded ProTracker module (Amiga demo)
180  MusicPlayer *_playerMusic;
181  Common::Array<int> _keysCollected;
182  bool _useRockTravel;
183  int _spiritsMeter;
184  int _spiritsMeterPosition;
185  int _spiritsMeterMax;
186  int _spiritsToKill;
187 
188  int _lastTenSeconds;
189  int _soundIndexStartFalling;
190  bool _selectedPrincess;
191 
192 private:
193  Common::SeekableReadStream *decryptFile(const Common::Path &filename);
194  Common::SeekableReadStream *decompressAtari(const Common::Path &filename);
195  void loadRiddles(Common::SeekableReadStream *file, int offset, int number);
196  void loadMessagesC64(Common::SeekableReadStream *file, int offset, int number);
197  void loadRiddlesC64(Common::SeekableReadStream *file, int offset, int number);
198  void loadDOSFonts(Common::SeekableReadStream *file, int pos);
199  void drawFullscreenRiddleAndWait(uint16 riddle);
200  void drawFullscreenEndGameAndWait();
201  void drawFullscreenAmigaEndGameAndWait();
202  void drawFullscreenGameOverAndWait();
203  void drawRiddle(uint16 riddle, uint32 front, uint32 back, Graphics::Surface *surface);
204  void tryToCollectKey();
205  void addGhosts();
206  bool hasEscaped();
207  bool ghostInArea();
208  void updateThunder();
209 
210  Audio::SoundHandle _soundFxGhostHandle;
211  Texture *_optionTexture;
212  Font _fontRiddle;
213  int _droppingGateStartTicks;
214  int _thunderTicks;
215  int _thunderFrameDuration;
216  int _thunderFrameIndex;
217  Math::Vector3d _thunderOffset;
218  Common::Array<Texture *>_thunderTextures;
219 };
220 
221 }
Definition: managed_surface.h:51
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: path.h:52
Definition: stream.h:745
Definition: freescape.h:191
Definition: mixer.h:49
Definition: castle.h:34
Definition: sensor.h:34
Definition: bitarray.h:29
Definition: rect.h:144
Definition: music.h:29
Definition: castle.h:26
Definition: font.h:32
Definition: system.h:165
Definition: instruction.h:36
Definition: castle.h:39
Definition: gfx.h:50