ScummVM API documentation
cge2.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 /*
23  * This code is based on original Sfinx source code
24  * Copyright (c) 1994-1997 Janusz B. Wisniewski and L.K. Avalon
25  */
26 
27 #ifndef CGE2_CGE2_H
28 #define CGE2_CGE2_H
29 
30 #include "common/random.h"
31 #include "common/savefile.h"
32 #include "common/serializer.h"
33 #include "engines/engine.h"
34 #include "common/system.h"
35 #include "cge2/fileio.h"
36 #include "cge2/console.h"
37 #include "audio/mixer.h"
38 
39 struct ADGameDescription;
40 
41 namespace CGE2 {
42 
43 class Vga;
44 class Sprite;
45 class MusicPlayer;
46 class Fx;
47 class Sound;
48 class Text;
49 struct HeroTab;
50 class FXP;
51 class V3D;
52 class V2D;
53 struct Dac;
54 class Spare;
55 class CommandHandler;
56 class InfoLine;
57 class Mouse;
58 class Keyboard;
59 class Talk;
60 class Hero;
61 class Bitmap;
62 class System;
63 class EventManager;
64 class Font;
65 class Map;
66 struct SavegameHeader;
67 
68 #define kScrWidth 320
69 #define kScrHeight 240
70 #define kScrDepth 480
71 #define kPanHeight 40
72 #define kWorldHeight (kScrHeight - kPanHeight)
73 #define kMaxFile 128
74 #define kPathMax 128
75 #define kDimMax 8
76 #define kWayMax 10
77 #define kPocketMax 4
78 #define kSceneMax 100
79 #define kMaxPoint 4
80 #define kInfoX 160
81 #define kInfoY -11
82 #define kInfoW 180
83 #define kPocketsWidth 59
84 #define kLineMax 512
85 
86 #define kIntroExt ".I80"
87 #define kTabName "CGE.TAB"
88 #define kPocketFull 170
89 #define kGameFrameDelay (750 / 50)
90 #define kGameTickDelay (750 / 62)
91 
92 #define kMusicRef 122
93 #define kPowerRef 123
94 #define kDvolRef 124
95 #define kMvolRef 125
96 #define kBusyRef 127
97 
98 #define kOffUseCount 130
99 #define kOffUseText 131
100 
101 #define kSysTimeRate 6 // 12 Hz
102 #define kBlinkRate 4 // 3 Hz
103 
104 #define kQuitTitle 200
105 #define kQuitText 201
106 #define kNoQuitText 202
107 
108 #define kSavegameVersion 2
109 #define kSavegameStrSize 12
110 #define kSavegameStr "SCUMMVM_CGE2"
111 
112 #define kColorNum 6
113 
114 enum CGEAction {
115  kActionNone,
116  kActionInfo,
117  kActionEscape,
118  kActionSave,
119  kActionLoad,
120  kActionQuit
121 };
122 
124  uint8 version;
125  Common::String saveName;
126  Graphics::Surface *thumbnail;
127  int16 saveYear, saveMonth, saveDay;
128  int16 saveHour, saveMinutes;
129  uint32 playTime;
130 };
131 
132 enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar };
133 
134 enum GamePhase { kPhaseInGame, kPhaseIntro, kPhaseOver };
135 
136 // our engine debug channels
137 enum {
138  kCGE2DebugOpcode = 1 << 0
139 };
140 
141 enum CallbackType {
142  kNullCB = 0, kQGame, kXScene
143 };
144 
145 enum Action { kNear, kMTake, kFTake, kActions };
146 
147 typedef void (CGE2Engine::*NotifyFunctionType)();
148 
149 class CGE2Engine : public Engine {
150 private:
151  uint32 _lastFrame, _lastTick;
152  void tick();
153 
154  void init();
155  void deinit();
156 
157  void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header);
158  void saveGame(int slotNumber, const Common::String &desc);
159  bool loadGame(int slotNumber);
160  void syncHeader(Common::Serializer &s);
161  void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream);
162  void resetGame();
163 public:
164  CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription);
165  bool hasFeature(EngineFeature f) const override;
166  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
167  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
168  Common::Language getLanguage() const;
169  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
170  Common::Error loadGameState(int slot) override;
171  Common::Error run() override;
172 
173  WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header, bool skipThumbnail = true);
174 
175  bool showTitle(const char *name);
176  void cge2_main();
177  char *mergeExt(char *buf, const char *name, const char *ext);
178  void inf(const char *text, ColorBank col = kCBInf);
179  void movie(const char *ext);
180  void runGame();
181  void loadHeroes();
182  void loadScript(const char *fname, bool onlyToolbar = false);
183  Sprite *loadSprite(const char *fname, int ref, int scene, V3D &pos);
184  void badLab(const char *fn);
185  void sceneUp(int cav);
186  void sceneDown();
187  void closePocket();
188  void switchScene(int scene);
189  void storeHeroPos();
190  void showBak(int ref);
191  void loadTab();
192  int newRandom(int range);
193  void openPocket();
194  void selectPocket(int n);
195  void busy(bool on);
196  void feedSnail(Sprite *spr, Action snq, Hero *hero);
197  int freePockets(int sx);
198  int findActivePocket(int ref);
199  void pocFul();
200  void killText();
201  void mainLoop();
202  void handleFrame();
203  Sprite *locate(int ref);
204  bool isHero(Sprite *spr);
205  void loadUser();
206  void loadPos();
207  void releasePocket(Sprite *spr);
208  void switchHero(int sex);
209  void offUse();
210  void setAutoColors();
211  bool cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d);
212  bool contain(const V2D &a, const V2D &b, const V2D &p);
213  long det(const V2D &a, const V2D &b, const V2D &c);
214  int sgn(long n);
215  int mapCross(const V2D &a, const V2D &b);
216  Sprite *spriteAt(V2D pos);
217  void keyClick();
218  void swapInPocket(Sprite *spr, Sprite *xspr);
219  void busyStep();
220 
221  void optionTouch(int opt, uint16 mask);
222  void switchColorMode();
223  void switchMusic();
224  void quit();
225  void setVolume(int idx, int cnt);
226  void checkVolumeSwitches();
227  void switchCap();
228  void switchVox();
229  void switchSay();
230  void initToolbar();
231  void initVolumeSwitch(Sprite *volSwitch, int val);
232  void checkMute();
233 
234  void checkSounds();
235 
236  void setEye(const V3D &e);
237  void setEye(const V2D& e2, int z = -kScrWidth);
238  void setEye(const char *s);
239 
240  int number(char *s);
241  char *token(char *s);
242  char *tail(char *s);
243  int takeEnum(const char *const *tab, const char *text);
244  ID ident(const char *s);
245  bool testBool(char *s);
246 
247  void snKill(Sprite *spr);
248  void snHide(Sprite *spr, int val);
249  void snMidi(int val);
250  void snSeq(Sprite *spr, int val);
251  void snRSeq(Sprite *spr, int val);
252  void snSend(Sprite *spr, int val);
253  void snSwap(Sprite *spr, int val);
254  void snCover(Sprite *spr, int val);
255  void snUncover(Sprite *spr, Sprite *spr2);
256  void snKeep(Sprite *spr, int val);
257  void snGive(Sprite *spr, int val);
258  void snGoto(Sprite *spr, int val);
259  void snPort(Sprite *spr, int port);
260  void snMouse(bool on);
261  void snNNext(Sprite *spr, Action act, int val);
262  void snRNNext(Sprite *spr, int val);
263  void snRMTNext(Sprite *spr, int val);
264  void snRFTNext(Sprite *spr, int val);
265  void snRmNear(Sprite *spr);
266  void snRmMTake(Sprite *spr);
267  void snRmFTake(Sprite *spr);
268  void snSetRef(Sprite *spr, int val);
269  void snFlash(bool on);
270  void snCycle(int cnt);
271  void snWalk(Sprite *spr, int val);
272  void snReach(Sprite *spr, int val);
273  void snSound(Sprite *spr, int wav, Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType);
274  void snRoom(Sprite *spr, bool on);
275  void snGhost(Bitmap *bmp);
276  void snSay(Sprite *spr, int val);
277 
278  void hide1(Sprite *spr);
279  Sprite *expandSprite(Sprite *spr);
280  void qGame();
281  void xScene();
282 
283  const ADGameDescription *_gameDescription;
284 
285  Common::RandomSource _randomSource;
286 
287  bool _quitFlag;
288  Dac *_bitmapPalette;
289  GamePhase _gamePhase; // Original name: startupmode
290  int _now;
291  int _sex;
292  int _mouseTop;
293  bool _dark;
294  int _waitSeq;
295  int _waitRef;
296 
297  struct {
298  int *_wait;
299  int _ref[2];
300  } _soundStat;
301 
302  bool _taken;
303  bool _endGame;
304  int _req;
305  NotifyFunctionType _midiNotify;
306  NotifyFunctionType _spriteNotify;
307  int _startGameSlot;
308 
309  bool _sayCap;
310  bool _sayVox;
311  int _oldMusicVolume;
312  int _oldSfxVolume;
313  bool _music;
314  bool _muteAll;
315 
316  ResourceManager *_resman;
317  Vga *_vga;
318  MusicPlayer *_midiPlayer;
319  Fx *_fx;
320  Sound *_sound;
321  Text *_text;
322  HeroTab *_heroTab[2];
323  V3D *_eye;
324  V3D *_eyeTab[kSceneMax];
325  Spare *_spare;
326  CommandHandler *_commandHandler;
327  CommandHandler *_commandHandlerTurbo;
328  Font *_font;
329  InfoLine *_infoLine;
330  Mouse *_mouse;
331  Keyboard *_keyboard;
332  Talk *_talk;
333  V3D *_point[kMaxPoint];
334  System *_sys;
335  Sprite *_busyPtr;
336  Sprite *_vol[2];
337  EventManager *_eventManager;
338  Map *_map;
339 };
340 
341 } // End of namespace CGE2
342 
343 #endif // CGE2_CGE2_H
Definition: vga13h.h:258
Definition: cge2.h:149
Definition: sound.h:64
Definition: str.h:59
Definition: surface.h:67
EngineFeature
Definition: engine.h:253
Definition: events.h:73
Definition: stream.h:77
Definition: savefile.h:54
Definition: error.h:84
Definition: events.h:94
Definition: advancedDetector.h:163
Definition: general.h:36
Definition: vga13h.h:152
Definition: random.h:44
Definition: mixer.h:66
Definition: vga13h.h:94
Definition: cge2_main.h:36
Definition: vga13h.h:78
Definition: stream.h:745
Definition: serializer.h:79
Definition: talk.h:47
SoundType
Definition: mixer.h:62
Definition: spare.h:34
Definition: talk.h:62
Definition: ustr.h:57
Definition: bitmap.h:33
Definition: sound.h:103
Definition: bitmap.h:57
Definition: text.h:44
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: snail.h:94
Definition: cge2.h:123
Definition: hero.h:39
Definition: sound.h:88
Definition: talk.h:79
Definition: fileio.h:82
Definition: map.h:37
Definition: system.h:161
Definition: events.h:51
Definition: engine.h:144
Definition: hero.h:63
Language
Definition: language.h:45