ScummVM API documentation
private.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 PRIVATE_H
23 #define PRIVATE_H
24 
25 #include "common/random.h"
26 #include "common/serializer.h"
27 #include "engines/engine.h"
28 #include "graphics/managed_surface.h"
29 #include "graphics/wincursor.h"
30 #include "video/smk_decoder.h"
31 #include "video/subtitles.h"
32 
33 #include "private/grammar.h"
34 
35 namespace Common {
36 class Archive;
37 }
38 
39 namespace Image {
40 class ImageDecoder;
41 }
42 
43 namespace Graphics {
44 class ManagedSurface;
45 }
46 
47 struct ADGameDescription;
48 
49 namespace Private {
50 
51 enum PRIVATEActions {
52  kActionSkip,
53 };
54 
55 // debug channels
56 enum {
57  kPrivateDebugFunction = 1,
58  kPrivateDebugCode,
59  kPrivateDebugScript,
60 };
61 
62 // sounds
63 
64 const int kPaperShuffleSound[7] = {32, 33, 34, 35, 36, 37, 39};
65 
66 // police
67 
68 const int kPoliceBustVideos[6] = {1, 2, 4, 5, 7, 8};
69 
70 // points
71 
72 const int kOriginZero[2] = {0, 0};
73 const int kOriginOne[2] = {64, 48};
74 
75 // vm
76 
77 extern Gen::VM *Gen::g_vm;
78 
79 // structs
80 
81 typedef struct ExitInfo {
82  Common::String nextSetting;
83  Common::Rect rect;
84  Common::String cursor;
85 
86  void clear() {
87  nextSetting.clear();
88  rect.setEmpty();
89  cursor.clear();
90  }
91 } ExitInfo;
92 
93 typedef struct MaskInfo {
94  Graphics::Surface *surf;
95  Common::String nextSetting;
96  Common::Point point;
97  Symbol *flag1;
98  Symbol *flag2;
99  Common::String cursor;
100  Common::String inventoryItem;
101  bool useBoxCollision;
102  Common::Rect box;
103 
104  MaskInfo() {
105  clear();
106  }
107 
108  void clear() {
109  surf = nullptr;
110  useBoxCollision = false;
111  box = Common::Rect();
112  flag1 = nullptr;
113  flag2 = nullptr;
114  nextSetting.clear();
115  cursor.clear();
116  point = Common::Point();
117  inventoryItem.clear();
118  }
119 } MaskInfo;
120 
121 enum PhoneStatus : byte {
122  kPhoneStatusWaiting,
123  kPhoneStatusAvailable,
124  kPhoneStatusCalling,
125  kPhoneStatusMissed,
126  kPhoneStatusAnswered
127 };
128 
129 typedef struct PhoneInfo {
130  Common::String name;
131  bool once;
132  int startIndex;
133  int endIndex;
134  Common::String flagName;
135  int flagValue;
136  PhoneStatus status;
137  int callCount;
138  uint32 soundIndex;
140 } PhoneInfo;
141 
142 typedef struct DossierInfo {
143  Common::String page1;
144  Common::String page2;
145 } DossierInfo;
146 
147 typedef struct CursorInfo {
148  Common::String name;
149  Common::String aname;
150  Graphics::Cursor *cursor;
151  Graphics::WinCursorGroup *winCursorGroup;
152 } CursorInfo;
153 
154 typedef struct MemoryInfo {
155  Common::String image;
156  Common::String movie;
157 } MemoryInfo;
158 
159 typedef struct DiaryPage {
160  Common::String locationName;
161  Common::Array<MemoryInfo> memories;
162  int locationID;
163 } DiaryPage;
164 
165 typedef struct InventoryItem {
166  Common::String diaryImage;
167  Common::String flag;
168 } InventoryItem;
169 
170 // funcs
171 
172 typedef struct FuncTable {
173  void (*func)(Private::ArgArray);
174  const char *name;
175 } FunctTable;
176 
178 extern const FuncTable funcTable[];
179 
180 // lists
181 
188 
189 // arrays
190 
193 
194 // hash tables
195 
197 
198 
199 class PrivateEngine : public Engine {
200 private:
201  Common::RandomSource *_rnd;
202  Graphics::PixelFormat _pixelFormat;
203  Image::ImageDecoder *_image;
204  int _screenW, _screenH;
205 
206 public:
207  bool _shouldHighlightMasks;
208  bool _highlightMasks;
209  PrivateEngine(OSystem *syst, const ADGameDescription *gd);
210  ~PrivateEngine();
211 
212  const ADGameDescription *_gameDescription;
213  bool isDemo() const;
214  Common::Language _language;
215  Common::Platform _platform;
216 
217  SymbolMaps maps;
218 
219  Audio::SoundHandle _fgSoundHandle;
220  Audio::SoundHandle _bgSoundHandle;
221  Audio::SoundHandle _phoneCallSoundHandle;
222  Video::SmackerDecoder *_videoDecoder;
223  Video::SmackerDecoder *_pausedVideo;
224 
225  Common::Error run() override;
226  void restartGame();
227  void clearAreas();
228  void initializePath(const Common::FSNode &gamePath) override;
229  Common::SeekableReadStream *loadAssets();
230  Common::Archive *loadMacInstaller();
231 
232  // Functions
233 
234  NameToPtr _functions;
235  void initFuncs();
236 
237  // User input
238  void selectPauseGame(Common::Point);
239  void selectMask(Common::Point);
240  void selectExit(Common::Point);
241  void selectLoadGame(Common::Point);
242  void selectSaveGame(Common::Point);
243  void resumeGame();
244 
245  // Cursors
246  void updateCursor(Common::Point);
247  bool cursorPauseMovie(Common::Point);
248  bool cursorExit(Common::Point);
249  bool cursorSafeDigit(Common::Point);
250  bool cursorMask(Common::Point);
251 
252  bool hasFeature(EngineFeature f) const override;
253  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
254  return true;
255  }
256  bool canSaveAutosaveCurrently() override {
257  return false;
258  }
259  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
260  return true;
261  }
262 
263  void ignoreEvents();
264  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
265  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
266 
267  static Common::Path convertPath(const Common::String &name);
268  static Common::String getVideoViewScreen(Common::String video);
269  void playVideo(const Common::String &);
270  void skipVideo();
271  void destroyVideo();
272 
273  void loadSubtitles(const Common::Path &path);
274  void adjustSubtitleSize();
275  Video::Subtitles *_subtitles;
276  bool _useSubtitles;
277  bool _sfxSubtitles;
278 
279  Graphics::Surface *decodeImage(const Common::String &file, byte **palette, bool *isNewPalette);
280  //byte *decodePalette(const Common::String &name);
281  void remapImage(uint16 ncolors, const Graphics::Surface *oldImage, const byte *oldPalette, Graphics::Surface *newImage, const byte *currentPalette);
282  static uint32 findMaskTransparentColor(const byte *palette, uint32 defaultColor);
283  static void swapImageColors(Graphics::Surface *image, byte *palette, uint32 a, uint32 b);
284  void loadImage(const Common::String &file, int x, int y);
285  void drawScreenFrame(const byte *videoPalette);
286 
287  // Cursors
288  Graphics::Cursor *_defaultCursor;
289  Common::Array<CursorInfo> _cursors;
290  Common::String _currentCursor;
291  void changeCursor(const Common::String &);
292  Common::String getInventoryCursor();
293  Common::String getExitCursor();
294  void loadCursors();
295 
296  // Rendering
297  Graphics::ManagedSurface *_compositeSurface;
298  Graphics::Surface *loadMask(const Common::String &, int, int, bool);
299  void loadMaskAndInfo(MaskInfo *m, const Common::String &name, int x, int y, bool drawn);
300  void drawMask(Graphics::Surface *);
301  void fillRect(uint32, Common::Rect);
302  bool inMask(Graphics::Surface *, Common::Point);
303  uint32 _transparentColor;
304  Common::Rect _screenRect;
305  Common::String _framePath;
306  Graphics::Surface *_frameImage;
307  Graphics::Surface *_mframeImage;
308  byte *_framePalette;
309  Common::String _nextVS;
310  Common::String _currentVS;
311  Common::Point _origin;
312  void drawScreen();
313  bool _needToDrawScreenFrame;
314 
315  // settings
316  Common::String _nextSetting;
317  Common::String _pausedSetting;
318  Common::String _currentSetting;
319  Common::String getPauseMovieSetting();
320  Common::String getGoIntroSetting();
321  Common::String getMainDesktopSetting();
322  Common::String getDiaryTOCSetting();
323  Common::String getDiaryMiddleSetting();
324  Common::String getDiaryLastPageSetting();
325  Common::String getPOGoBustMovieSetting();
326  Common::String getPoliceBustFromMOSetting();
327  Common::String getListenToPhoneSetting();
328  Common::String getAlternateGameVariable();
329  Common::String getPoliceIndexVariable();
330  Common::String getWallSafeValueVariable();
331  Common::String getPoliceArrivedVariable();
332  Common::String getBeenDowntownVariable();
333  Common::String getPoliceStationLocation();
334  const char *getSymbolName(const char *name, const char *strippedName, const char *demoName = nullptr);
335 
336  // movies
337  Common::String _nextMovie;
338  Common::String _currentMovie;
339 
340  // Dossiers
341  DossierArray _dossiers;
342  uint _dossierSuspect;
343  uint _dossierPage;
344  MaskInfo _dossierPageMask;
345  MaskInfo _dossierNextSuspectMask;
346  MaskInfo _dossierPrevSuspectMask;
347  MaskInfo _dossierNextSheetMask;
348  MaskInfo _dossierPrevSheetMask;
349  bool selectDossierPage(Common::Point);
350  bool selectDossierNextSuspect(Common::Point);
351  bool selectDossierPrevSuspect(Common::Point);
352  bool selectDossierNextSheet(Common::Point);
353  bool selectDossierPrevSheet(Common::Point);
354  void addDossier(Common::String &page1, Common::String &page2);
355  void loadDossier();
356 
357  // Police Bust
358  bool _policeBustEnabled;
359  bool _policeSirenPlayed;
360  int _numberOfClicks;
361  int _numberClicksAfterSiren;
362  int _policeBustMovieIndex;
363  Common::String _policeBustMovie;
364  Common::String _policeBustPreviousSetting;
365  void resetPoliceBust();
366  void startPoliceBust();
367  void stopPoliceBust();
368  void wallSafeAlarm();
369  void completePoliceBust();
370  void checkPoliceBust();
371 
372  // Diary
373  InvList inventory;
374  bool inInventory(const Common::String &bmp) const;
375  void addInventory(const Common::String &bmp, Common::String &flag);
376  void removeInventory(const Common::String &bmp);
377  void removeRandomInventory();
378  Common::String _diaryLocPrefix;
379  void loadLocations(const Common::Rect &);
380  void loadInventory(uint32, const Common::Rect &, const Common::Rect &);
381  bool _toTake;
382  bool _haveTakenItem;
383  DiaryPages _diaryPages;
384  int _currentDiaryPage;
385  ExitInfo _diaryNextPageExit;
386  ExitInfo _diaryPrevPageExit;
387  bool selectDiaryNextPage(Common::Point mousePos);
388  bool selectDiaryPrevPage(Common::Point mousePos);
389  void addMemory(const Common::String &path);
390  void loadMemories(const Common::Rect &rect, uint rightPageOffset, uint verticalOffset);
391  bool selectLocation(const Common::Point &mousePos);
392  Common::Array<MaskInfo> _locationMasks;
393  Common::Array<MaskInfo> _memoryMasks;
394  bool selectMemory(const Common::Point &mousePos);
395  void setLocationAsVisited(Symbol *location);
396  int getMaxLocationValue();
397 
398  // Save/Load games
399  MaskInfo _saveGameMask;
400  MaskInfo _loadGameMask;
401 
402  int _mode;
403  bool _modified;
404 
405  PlayedMediaTable _playedMovies;
406  Common::String _repeatedMovieExit;
407 
408  // Masks/Exits
409  ExitList _exits;
410  MaskList _masks;
411 
412  // Sounds
413  void playSound(const Common::String &, uint, bool, bool);
414  void playPhoneCallSound();
415  void stopSound(bool);
416  bool isSoundActive();
417  void waitForSoundToStop();
418  bool _noStopSounds;
419 
420  Common::String getPaperShuffleSound();
421  Common::String _globalAudioPath;
422 
423  Common::String getTakeSound();
424  Common::String getTakeLeaveSound();
425  Common::String getLeaveSound();
426  Common::String _sirenSound;
427 
428  // Radios
429  Common::String _infaceRadioPath;
430  MaskInfo _AMRadioArea;
431  MaskInfo _policeRadioArea;
432  SoundList _AMRadio;
433  SoundList _policeRadio;
434  void selectAMRadioArea(Common::Point);
435  void selectPoliceRadioArea(Common::Point);
436 
437  // Phone
438  MaskInfo _phoneArea;
439  Common::String _phonePrefix;
440  Common::String _phoneCallSound;
441  PhoneList _phones;
442  void addPhone(const Common::String &name, bool once, int startIndex, int endIndex, const Common::String &flagName, int flagValue);
443  void initializePhoneOnDesktop();
444  void checkPhoneCall();
445  bool cursorPhoneArea(Common::Point mousePos);
446  void selectPhoneArea(Common::Point mousePos);
447 
448  // Safe
449  Common::String _safeNumberPath;
450  MaskInfo _safeDigitArea[3];
451  Common::Rect _safeDigitRect[3];
452 
453  void initializeWallSafeValue();
454  bool selectSafeDigit(Common::Point);
455  void addSafeDigit(uint32, Common::Rect*);
456  int getSafeDigit(uint32 d);
457  void incrementSafeDigit(uint32 d);
458 
459  // Random values
460  bool getRandomBool(uint);
461 
462  // Timer
463  Common::String _timerSetting;
464  Common::String _timerSkipSetting;
465  uint32 _timerStartTime;
466  uint32 _timerDelay;
467  void setTimer(uint32 duration, const Common::String &setting, const Common::String &skipSetting);
468  void clearTimer();
469  void skipTimer();
470  void checkTimer();
471 
472  // VM objects
473  RectList _rects; // created by fCRect
474 };
475 
476 extern PrivateEngine *g_private;
477 
478 } // End of namespace Private
479 
480 #endif
Definition: managed_surface.h:51
Definition: image_decoder.h:53
Definition: wincursor.h:54
Definition: str.h:59
Definition: surface.h:67
EngineFeature
Definition: engine.h:258
Definition: stream.h:77
Definition: error.h:81
Definition: pixelformat.h:138
Definition: advancedDetector.h:164
Definition: random.h:44
Definition: symbol.h:57
Definition: rect.h:524
Definition: path.h:52
Definition: private.h:129
Definition: stream.h:745
Definition: smk_decoder.h:77
Definition: private.h:81
Definition: symbol.h:35
bool canSaveAutosaveCurrently() override
Definition: private.h:256
Definition: archive.h:141
Definition: private.h:93
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: private.h:253
Definition: subtitles.h:77
Definition: mixer.h:49
Definition: ustr.h:57
Definition: private.h:199
Definition: cursor.h:42
Definition: algorithm.h:29
Definition: fs.h:69
Definition: private.h:165
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: decompiler.h:30
Definition: private.h:147
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: private.h:259
Definition: private.h:154
Definition: system.h:163
Definition: private.h:142
Definition: private.h:159
Definition: movie_decoder.h:32
Definition: private.h:172
void setEmpty()
Definition: rect.h:363
Definition: engine.h:144
Platform
Definition: platform.h:93
Language
Definition: language.h:45