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