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 
115  uint8 version;
116  Common::String saveName;
117  Graphics::Surface *thumbnail;
118  int16 saveYear, saveMonth, saveDay;
119  int16 saveHour, saveMinutes;
120  uint32 playTime;
121 };
122 
123 enum ColorBank { kCBRel, kCBStd, kCBSay, kCBInf, kCBMnu, kCBWar };
124 
125 enum GamePhase { kPhaseInGame, kPhaseIntro, kPhaseOver };
126 
127 // our engine debug channels
128 enum {
129  kCGE2DebugOpcode = 1 << 0
130 };
131 
132 enum CallbackType {
133  kNullCB = 0, kQGame, kXScene
134 };
135 
136 enum Action { kNear, kMTake, kFTake, kActions };
137 
138 typedef void (CGE2Engine::*NotifyFunctionType)();
139 
140 class CGE2Engine : public Engine {
141 private:
142  uint32 _lastFrame, _lastTick;
143  void tick();
144 
145  void init();
146  void deinit();
147 
148  void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header);
149  void saveGame(int slotNumber, const Common::String &desc);
150  bool loadGame(int slotNumber);
151  void syncHeader(Common::Serializer &s);
152  void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream);
153  void resetGame();
154 public:
155  CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription);
156  bool hasFeature(EngineFeature f) const override;
157  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
158  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
159  Common::Language getLanguage() const;
160  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
161  Common::Error loadGameState(int slot) override;
162  Common::Error run() override;
163 
164  WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header, bool skipThumbnail = true);
165 
166  bool showTitle(const char *name);
167  void cge2_main();
168  char *mergeExt(char *buf, const char *name, const char *ext);
169  void inf(const char *text, ColorBank col = kCBInf);
170  void movie(const char *ext);
171  void runGame();
172  void loadHeroes();
173  void loadScript(const char *fname, bool onlyToolbar = false);
174  Sprite *loadSprite(const char *fname, int ref, int scene, V3D &pos);
175  void badLab(const char *fn);
176  void sceneUp(int cav);
177  void sceneDown();
178  void closePocket();
179  void switchScene(int scene);
180  void storeHeroPos();
181  void showBak(int ref);
182  void loadTab();
183  int newRandom(int range);
184  void openPocket();
185  void selectPocket(int n);
186  void busy(bool on);
187  void feedSnail(Sprite *spr, Action snq, Hero *hero);
188  int freePockets(int sx);
189  int findActivePocket(int ref);
190  void pocFul();
191  void killText();
192  void mainLoop();
193  void handleFrame();
194  Sprite *locate(int ref);
195  bool isHero(Sprite *spr);
196  void loadUser();
197  void loadPos();
198  void releasePocket(Sprite *spr);
199  void switchHero(int sex);
200  void offUse();
201  void setAutoColors();
202  bool cross(const V2D &a, const V2D &b, const V2D &c, const V2D &d);
203  bool contain(const V2D &a, const V2D &b, const V2D &p);
204  long det(const V2D &a, const V2D &b, const V2D &c);
205  int sgn(long n);
206  int mapCross(const V2D &a, const V2D &b);
207  Sprite *spriteAt(V2D pos);
208  void keyClick();
209  void swapInPocket(Sprite *spr, Sprite *xspr);
210  void busyStep();
211 
212  void optionTouch(int opt, uint16 mask);
213  void switchColorMode();
214  void switchMusic();
215  void quit();
216  void setVolume(int idx, int cnt);
217  void checkVolumeSwitches();
218  void switchCap();
219  void switchVox();
220  void switchSay();
221  void initToolbar();
222  void initVolumeSwitch(Sprite *volSwitch, int val);
223  void checkMute();
224 
225  void checkSounds();
226 
227  void setEye(const V3D &e);
228  void setEye(const V2D& e2, int z = -kScrWidth);
229  void setEye(const char *s);
230 
231  int number(char *s);
232  char *token(char *s);
233  char *tail(char *s);
234  int takeEnum(const char *const *tab, const char *text);
235  ID ident(const char *s);
236  bool testBool(char *s);
237 
238  void snKill(Sprite *spr);
239  void snHide(Sprite *spr, int val);
240  void snMidi(int val);
241  void snSeq(Sprite *spr, int val);
242  void snRSeq(Sprite *spr, int val);
243  void snSend(Sprite *spr, int val);
244  void snSwap(Sprite *spr, int val);
245  void snCover(Sprite *spr, int val);
246  void snUncover(Sprite *spr, Sprite *spr2);
247  void snKeep(Sprite *spr, int val);
248  void snGive(Sprite *spr, int val);
249  void snGoto(Sprite *spr, int val);
250  void snPort(Sprite *spr, int port);
251  void snMouse(bool on);
252  void snNNext(Sprite *spr, Action act, int val);
253  void snRNNext(Sprite *spr, int val);
254  void snRMTNext(Sprite *spr, int val);
255  void snRFTNext(Sprite *spr, int val);
256  void snRmNear(Sprite *spr);
257  void snRmMTake(Sprite *spr);
258  void snRmFTake(Sprite *spr);
259  void snSetRef(Sprite *spr, int val);
260  void snFlash(bool on);
261  void snCycle(int cnt);
262  void snWalk(Sprite *spr, int val);
263  void snReach(Sprite *spr, int val);
264  void snSound(Sprite *spr, int wav, Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType);
265  void snRoom(Sprite *spr, bool on);
266  void snGhost(Bitmap *bmp);
267  void snSay(Sprite *spr, int val);
268 
269  void hide1(Sprite *spr);
270  Sprite *expandSprite(Sprite *spr);
271  void qGame();
272  void xScene();
273 
274  const ADGameDescription *_gameDescription;
275 
276  Common::RandomSource _randomSource;
277 
278  bool _quitFlag;
279  Dac *_bitmapPalette;
280  GamePhase _gamePhase; // Original name: startupmode
281  int _now;
282  int _sex;
283  int _mouseTop;
284  bool _dark;
285  int _waitSeq;
286  int _waitRef;
287 
288  struct {
289  int *_wait;
290  int _ref[2];
291  } _soundStat;
292 
293  bool _taken;
294  bool _endGame;
295  int _req;
296  NotifyFunctionType _midiNotify;
297  NotifyFunctionType _spriteNotify;
298  int _startGameSlot;
299 
300  bool _sayCap;
301  bool _sayVox;
302  int _oldMusicVolume;
303  int _oldSfxVolume;
304  bool _music;
305  bool _muteAll;
306 
307  ResourceManager *_resman;
308  Vga *_vga;
309  MusicPlayer *_midiPlayer;
310  Fx *_fx;
311  Sound *_sound;
312  Text *_text;
313  HeroTab *_heroTab[2];
314  V3D *_eye;
315  V3D *_eyeTab[kSceneMax];
316  Spare *_spare;
317  CommandHandler *_commandHandler;
318  CommandHandler *_commandHandlerTurbo;
319  Font *_font;
320  InfoLine *_infoLine;
321  Mouse *_mouse;
322  Keyboard *_keyboard;
323  Talk *_talk;
324  V3D *_point[kMaxPoint];
325  System *_sys;
326  Sprite *_busyPtr;
327  Sprite *_vol[2];
328  EventManager *_eventManager;
329  Map *_map;
330 };
331 
332 } // End of namespace CGE2
333 
334 #endif // CGE2_CGE2_H
Definition: vga13h.h:258
Definition: cge2.h:140
Definition: sound.h:64
Definition: str.h:59
Definition: surface.h:66
EngineFeature
Definition: engine.h:250
Definition: events.h:75
Definition: stream.h:77
Definition: savefile.h:54
Definition: error.h:84
Definition: events.h:96
Definition: advancedDetector.h:120
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:114
Definition: hero.h:39
Definition: sound.h:88
Definition: talk.h:79
Definition: fileio.h:82
Definition: map.h:37
Definition: system.h:167
Definition: events.h:51
Definition: engine.h:143
Definition: hero.h:63
Language
Definition: language.h:45