ScummVM API documentation
cge.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 CGE_CGE_H
23 #define CGE_CGE_H
24 
25 #include "common/random.h"
26 #include "common/savefile.h"
27 #include "common/serializer.h"
28 #include "common/str.h"
29 #include "common/rect.h"
30 #include "engines/engine.h"
31 #include "gui/debugger.h"
32 #include "graphics/surface.h"
33 #include "cge/console.h"
34 #include "cge/bitmap.h"
35 #include "cge/sound.h"
36 
37 struct ADGameDescription;
38 
39 namespace CGE {
40 
41 class Console;
42 class Sprite;
43 class Cluster;
44 class Vga;
45 class System;
46 class Keyboard;
47 class Mouse;
48 class HorizLine;
49 class InfoLine;
50 class SceneLight;
51 class CommandHandler;
52 class EventManager;
53 class ResourceManager;
54 class Walk;
55 class Text;
56 class Talk;
57 
58 #define kSavegameVersion 3
59 #define kSavegameStrSize 11
60 #define kPocketX 174
61 #define kPocketY 176
62 #define kPocketDX 18
63 #define kPocketDY 22
64 #define kPocketNX 8
65 #define kPocketNY 1
66 #define kPocketSX 8
67 #define kPocketSY 3
68 #define kSceneDx 9
69 #define kSceneDy 10
70 #define kSceneNx 8
71 #define kSceneNy 3
72 #define kSceneMax kSceneNx * kSceneNy
73 #define kPathMax 128
74 #define kCryptSeed 0xA5
75 #define kMaxFile 128
76 #define kMapXCnt 40
77 #define kMapZCnt 20
78 #define kMapTop 80
79 
80 #define kSayTheEnd 41
81 
82 enum CGEAction {
83  kActionNone,
84  kActionInfo,
85  kActionEscape,
86  kActionSave,
87  kActionLoad,
88  kActionQuit,
89  kActionInv1,
90  kActionInv2,
91  kActionInv3,
92  kActionInv4,
93  kActionInv5,
94  kActionInv6,
95  kActionInv7,
96  kActionInv8,
97  kActionAltDice,
98  kActionLevel0,
99  kActionLevel1,
100  kActionLevel2,
101  kActionLevel3,
102  kActionLevel4
103 };
104 
105 // our engine debug channels
106 enum {
107  kCGEDebugBitmap = 1 << 0,
108  kCGEDebugFile = 1 << 1,
109  kCGEDebugEngine = 1 << 2
110 };
111 
112 enum SnList {
113  kNear, kTake
114 };
115 
116 enum CallbackType {
117  kNullCB = 0, kQGame, kMiniStep, kXScene, kSoundSetVolume
118 };
119 
121  uint8 version;
122  Common::String saveName;
123  Graphics::Surface *thumbnail;
124  int16 saveYear, saveMonth, saveDay;
125  int16 saveHour, saveMinutes;
126  uint32 playTime;
127 };
128 
129 extern const char *savegameStr;
130 
131 struct Bar {
132  uint8 _horz;
133  uint8 _vert;
134 };
135 
136 class Font {
137  char _path[kPathMax];
138  void load();
139  CGEEngine *_vm;
140 public:
141  uint8 *_widthArr;
142  uint16 *_pos;
143  uint8 *_map;
144  Font(CGEEngine *vm, const char *name);
145  ~Font();
146  uint16 width(const char *text);
147  void save();
148 };
149 
150 class CGEEngine : public Engine {
151 private:
152  uint32 _lastFrame, _lastTick;
153  void tick();
154  void syncHeader(Common::Serializer &s);
155  void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header);
156  void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream, bool tiny);
157  bool savegameExists(int slotNumber);
158 public:
159  CGEEngine(OSystem *syst, const ADGameDescription *gameDescription);
160  ~CGEEngine() override;
161  bool hasFeature(EngineFeature f) const override;
162  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
163  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
164  Common::Error loadGameState(int slot) override;
165  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
166 
167  static const int _maxSceneArr[5];
168  bool _quitFlag;
169  bool _showBoundariesFl;
170 
171  const ADGameDescription *_gameDescription;
172  int _startupMode;
173  int _oldLev;
174  int _pocPtr;
175  bool _music;
176  int _pocref[kPocketNX];
177  uint8 _volume[2];
178  int _maxScene;
179  bool _flag[4];
180  bool _dark;
181  bool _game;
182  bool _endGame;
183  int _now;
184  int _lev;
185  int _mode;
186  int _gameCase2Cpt;
187  int _offUseCount;
188  Dac *_bitmapPalette;
189  uint8 _clusterMap[kMapZCnt][kMapXCnt];
190 
191  Sprite *_sprTv;
192  Sprite *_sprK1;
193  Sprite *_sprK2;
194  Sprite *_sprK3;
195 
196  Common::Point _heroXY[kSceneMax];
197  Bar _barriers[kSceneMax + 1];
198  Font *_font;
199  Vga *_vga;
200  System *_sys;
201  Sprite *_pocLight;
202  Keyboard *_keyboard;
203  Mouse *_mouse;
204  Sprite *_sprite;
205  Sprite *_miniScene;
206  Sprite *_shadow;
207  HorizLine *_horzLine;
208  InfoLine *_infoLine;
209  InfoLine *_debugLine;
210  SceneLight *_sceneLight;
211  CommandHandler *_commandHandler;
212  CommandHandler *_commandHandlerTurbo;
213  EventManager *_eventManager;
214  Fx *_fx;
215  Sound *_sound;
216  ResourceManager *_resman;
217  Sprite *_pocket[kPocketNX];
218  Walk *_hero;
219  Text *_text;
220  Talk *_talk;
221 
222 
223  Common::RandomSource _randomSource;
224  MusicPlayer *_midiPlayer;
225  BitmapPtr *_miniShp;
226  BitmapPtr *_miniShpList;
227  int _startGameSlot;
228 
229  Common::Error run() override;
230 
231  void cge_main();
232  void switchScene(int newScene);
233  void startCountDown();
234  void quit();
235  void resetQSwitch();
236  void optionTouch(int opt, uint16 mask);
237  void resetGame();
238  bool loadGame(int slotNumber, SavegameHeader *header = NULL, bool tiny = false);
239  void setMapBrick(int x, int z);
240  void switchMapping();
241  void loadSprite(const char *fname, int ref, int scene, int col, int row, int pos);
242  void loadScript(const char *fname);
243  void loadUser();
244  void runGame();
245  bool showTitle(const char *name);
246  void movie(const char *ext);
247  void inf(const char *text, bool wideSpace = false);
248  void selectSound();
249  void dummy() {}
250  void NONE();
251  void SB();
252  void sceneDown();
253  void sceneUp();
254  void xScene();
255  void qGame();
256  void SBM();
257  void GUS();
258  void GUSM();
259  void MIDI();
260  void AUTO();
261  void setPortD();
262  void setPortM();
263  void setIRQ();
264  void setDMA();
265  void mainLoop();
266  void handleFrame();
267  void saveGame(int slotNumber, const Common::String &desc);
268  WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header, bool skipThumbnail = true);
269  void switchMusic();
270  void selectPocket(int n);
271  void expandSprite(Sprite *spr);
272  void contractSprite(Sprite *spr);
273  int findPocket(Sprite *spr);
274  void feedSnail(Sprite *spr, SnList snq);
275  void pocFul();
276  void hide1(Sprite *spr);
277  void loadMapping();
278  void heroCover(int cvr);
279  void trouble(int seq, int text);
280  void offUse();
281  void tooFar();
282  void loadHeroXY();
283  void keyClick();
284  void switchColorMode();
285  void killSprite();
286  void switchDebug();
287  void miniStep(int stp);
288  void postMiniStep(int stp);
289  void showBak(int ref);
290  void initSceneValues();
291  char *mergeExt(char *buf, const char *name, const char *ext);
292  int takeEnum(const char **tab, const char *text);
293  int newRandom(int range);
294  void sndSetVolume();
295  Sprite *locate(int ref);
296  Sprite *spriteAt(int x, int y);
297  Cluster XZ(int16 x, int16 y);
298  void killText();
299 
300  void snBackPt(Sprite *spr, int stp);
301  void snHBarrier(const int scene, const int barX);
302  void snVBarrier(const int scene, const int barY);
303  void snCover(Sprite *spr, int xref);
304  void snFlag(int indx, bool v);
305  void snFlash(bool on);
306  void snGame(Sprite *spr, int num);
307  void snGhost(Bitmap *bmp);
308  void snGive(Sprite *spr, int stp);
309  void snHide(Sprite *spr, int val);
310  void snKeep(Sprite *spr, int stp);
311  void snKill(Sprite *spr);
312  void snLevel(Sprite *spr, int lev);
313  void snLight(bool in);
314  void snMouse(bool on);
315  void snNNext(Sprite *spr, int p);
316  void snPort(Sprite *spr, int port);
317  void snReach(Sprite *spr, int mode);
318  void snRelZ(Sprite *spr, int z);
319  void snRNNext(Sprite *spr, int p);
320  void snRTNext(Sprite *spr, int p);
321  void snSend(Sprite *spr, int val);
322  void snRelX(Sprite *spr, int x);
323  void snRelY(Sprite *spr, int y);
324  void snRmNear(Sprite *spr);
325  void snRmTake(Sprite *spr);
326  void snRSeq(Sprite *spr, int val);
327  void snSeq(Sprite *spr, int val);
328  void snSetRef(Sprite *spr, int nr);
329  void snSetX(Sprite *spr, int x);
330  void snSetX0(int scene, int x0);
331  void snSetXY(Sprite *spr, uint16 xy);
332  void snSetY(Sprite *spr, int y);
333  void snSetY0(int scene, int y0);
334  void snSetZ(Sprite *spr, int z);
335  void snSlave(Sprite *spr, int ref);
336  void snSound(Sprite *spr, int wav);
337  void snSwap(Sprite *spr, int xref);
338  void snTNext(Sprite *spr, int p);
339  void snTrans(Sprite *spr, int trans);
340  void snUncover(Sprite *spr, Sprite *xspr);
341  void snWalk(Sprite *spr, int x, int y);
342  void snZTrim(Sprite *spr);
343 protected:
344  int _recentStep;
345 
346 private:
347  void init();
348  void deinit();
349 };
350 
351 } // End of namespace CGE
352 
353 #endif
Definition: fileio.h:75
Definition: str.h:59
Definition: surface.h:67
EngineFeature
Definition: engine.h:253
Definition: stream.h:77
Definition: savefile.h:54
Definition: error.h:84
Definition: advancedDetector.h:163
Definition: walk.h:44
Definition: random.h:44
Definition: vga13h.h:217
Definition: events.h:74
Definition: sound.h:87
Definition: text.h:43
Definition: stream.h:745
Definition: cge.h:150
Definition: events.h:51
Definition: serializer.h:79
Definition: talk.h:65
Definition: bitmap.h:55
Definition: ustr.h:57
Definition: snail.h:53
Definition: cge.h:136
Definition: walk.h:56
Definition: talk.h:49
Definition: rect.h:45
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: sound.h:108
Definition: vga13h.h:83
Definition: cge.h:131
Definition: cge.h:120
Definition: cge_main.h:86
Definition: system.h:161
Definition: events.h:94
Definition: bitmap.h:33
Definition: sound.h:65
Definition: engine.h:144
Definition: vga13h.h:223
Definition: general.h:34
Definition: vga13h.h:179