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 Sound {
130  Common::String name;
131  Audio::SoundHandle handle;
132 } Sound;
133 
134 typedef struct PhoneInfo {
135  Common::String name;
136  bool once;
137  int startIndex;
138  int endIndex;
139  Common::String flagName;
140  int flagValue;
141  PhoneStatus status;
142  int callCount;
143  uint32 soundIndex;
145 } PhoneInfo;
146 
147 typedef struct RadioClip {
148  Common::String name;
149  bool played;
150  int priority;
151  int disabledPriority1; // 0 == none
152  bool exactPriorityMatch1;
153  int disabledPriority2; // 0 == none
154  bool exactPriorityMatch2;
155  Common::String flagName;
156  int flagValue;
157 } RadioClip;
158 
159 typedef struct Radio {
160  Common::String path;
161  Sound *sound;
163  int channels[3];
164 
165  Radio() : sound(nullptr) {
166  clear();
167  }
168 
169  void clear() {
170  clips.clear();
171  for (uint i = 0; i < ARRAYSIZE(channels); i++) {
172  channels[i] = -1;
173  }
174  }
175 } Radio;
176 
177 typedef struct DossierInfo {
178  Common::String page1;
179  Common::String page2;
180 } DossierInfo;
181 
182 typedef struct CursorInfo {
183  Common::String name;
184  Common::String aname;
185  Graphics::Cursor *cursor;
186  Graphics::WinCursorGroup *winCursorGroup;
187 } CursorInfo;
188 
189 typedef struct MemoryInfo {
190  Common::String image;
191  Common::String movie;
192 } MemoryInfo;
193 
194 typedef struct DiaryPage {
195  Common::String locationName;
196  Common::Array<MemoryInfo> memories;
197  int locationID;
198 } DiaryPage;
199 
200 typedef struct InventoryItem {
201  Common::String diaryImage;
202  Common::String flag;
203 } InventoryItem;
204 
205 // funcs
206 
207 typedef struct FuncTable {
208  void (*func)(Private::ArgArray);
209  const char *name;
210 } FunctTable;
211 
213 extern const FuncTable funcTable[];
214 
215 // lists
216 
222 
223 // arrays
224 
227 
228 // hash tables
229 
231 
232 enum SubtitleType {
233  kSubtitleAudio,
234  kSubtitleVideo
235 };
236 
237 struct SubtitleSlot {
238  Audio::SoundHandle handle;
239  Video::Subtitles *subs;
240 
241  SubtitleSlot() : subs(nullptr) {}
242 };
243 
244 class PrivateEngine : public Engine {
245 private:
246  Common::RandomSource *_rnd;
247  Graphics::PixelFormat _pixelFormat;
248  Image::ImageDecoder *_image;
249  int _screenW, _screenH;
250 
251  // helper to generate the correct subtitle path
252  Common::Path getSubtitlePath(const Common::String &soundName);
253 
254  bool isSfxSubtitle(const Video::Subtitles *subs);
255  bool isSlotActive(const SubtitleSlot &slot);
256 
257 public:
258  bool _shouldHighlightMasks;
259  bool _highlightMasks;
260  bool _readingMaterialContrast;
261  PrivateEngine(OSystem *syst, const ADGameDescription *gd);
262  ~PrivateEngine();
263 
264  const ADGameDescription *_gameDescription;
265  bool isDemo() const;
266  Common::Language _language;
267  Common::Platform _platform;
268 
269  SymbolMaps maps;
270 
271  Video::SmackerDecoder *_videoDecoder;
272  Video::SmackerDecoder *_pausedVideo;
273  Common::String _pausedMovieName;
274 
275  Common::Error run() override;
276  void restartGame();
277  void clearAreas();
278  void initializePath(const Common::FSNode &gamePath) override;
279  void pauseEngineIntern(bool pause) override;
280  Common::SeekableReadStream *loadAssets();
281  Common::Archive *loadMacInstaller();
282 
283  // Functions
284 
285  NameToPtr _functions;
286  void initFuncs();
287 
288  // User input
289  void selectPauseGame(Common::Point);
290  bool selectMask(Common::Point);
291  bool selectExit(Common::Point);
292  bool selectLoadGame(Common::Point);
293  bool selectSaveGame(Common::Point);
294  void resumeGame();
295 
296  // Cursors
297  void updateCursor(Common::Point);
298  bool cursorPauseMovie(Common::Point);
299  bool cursorExit(Common::Point);
300  bool cursorSafeDigit(Common::Point);
301  bool cursorMask(Common::Point);
302 
303  bool hasFeature(EngineFeature f) const override;
304  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
305  return true;
306  }
307  bool canSaveAutosaveCurrently() override {
308  return false;
309  }
310  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
311  return true;
312  }
313 
314  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
315  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
316 
317  static Common::Path convertPath(const Common::String &name);
318  static Common::String getVideoViewScreen(Common::String video);
319  void playVideo(const Common::String &);
320  void skipVideo();
321  void destroyVideo();
322 
323  void loadSubtitles(const Common::Path &path, SubtitleType type, Sound *sound = nullptr);
324  // use to clean up sounds which have finished playing once
325  void updateSubtitles();
326  void destroySubtitles();
327  void adjustSubtitleSize();
328  Video::Subtitles *_videoSubtitles;
329  SubtitleSlot _voiceSlot; // high priority (speech)
330  SubtitleSlot _sfxSlot; // low priority (sfxs)
331  bool _useSubtitles;
332  bool _sfxSubtitles;
333 
334  Graphics::Surface *decodeImage(const Common::String &file, byte **palette, bool *isNewPalette);
335  //byte *decodePalette(const Common::String &name);
336  void remapImage(uint16 ncolors, const Graphics::Surface *oldImage, const byte *oldPalette, Graphics::Surface *newImage, const byte *currentPalette);
337  static uint32 findMaskTransparentColor(const byte *palette, uint32 defaultColor);
338  static void swapImageColors(Graphics::Surface *image, byte *palette, uint32 a, uint32 b);
339  void setPaperScanFiltering(bool enabled);
340  void loadImage(const Common::String &file, int x, int y);
341  void drawScreenFrame(const byte *videoPalette);
342 
343  // Cursors
344  Graphics::Cursor *_defaultCursor;
345  Common::Array<CursorInfo> _cursors;
346  Common::String _currentCursor;
347  void changeCursor(const Common::String &);
348  Common::String getInventoryCursor();
349  Common::String getExitCursor();
350  void loadCursors();
351 
352  // Rendering
353  Graphics::ManagedSurface *_compositeSurface;
354  Graphics::Surface *loadMask(const Common::String &, int, int, bool);
355  void loadMaskAndInfo(MaskInfo *m, const Common::String &name, int x, int y, bool drawn);
356  void drawMask(Graphics::Surface *);
357  void fillRect(uint32, Common::Rect);
358  bool inMask(Graphics::Surface *, Common::Point);
359  uint32 _transparentColor;
360  Common::Rect _screenRect;
361  Common::String _framePath;
362  Graphics::Surface *_frameImage;
363  Graphics::Surface *_mframeImage;
364  byte *_framePalette;
365  Common::String _nextVS;
366  Common::String _currentVS;
367  Common::Point _origin;
368  void drawScreen();
369  bool _needToDrawScreenFrame;
370  bool _paperScanFilteringActive;
371  bool _paperScanPreviousFiltering;
372 
373  // settings
374  Common::String _nextSetting;
375  Common::String _pausedSetting;
376  Common::String _currentSetting;
377  Common::String getPauseMovieSetting();
378  Common::String getGoIntroSetting();
379  Common::String getMainDesktopSetting();
380  Common::String getDiaryTOCSetting();
381  Common::String getDiaryMiddleSetting();
382  Common::String getDiaryLastPageSetting();
383  Common::String getPOGoBustMovieSetting();
384  Common::String getPoliceBustFromMOSetting();
385  Common::String getListenToPhoneSetting();
386  Common::String getAlternateGameVariable();
387  Common::String getPoliceIndexVariable();
388  Common::String getWallSafeValueVariable();
389  Common::String getPoliceArrivedVariable();
390  Common::String getBeenDowntownVariable();
391  Common::String getPoliceStationLocation();
392  const char *getSymbolName(const char *name, const char *strippedName, const char *demoName = nullptr);
393 
394  // movies
395  Common::String _nextMovie;
396  Common::String _currentMovie;
397 
398  // Dossiers
399  DossierArray _dossiers;
400  uint _dossierSuspect;
401  uint _dossierPage;
402  MaskInfo _dossierPageMask;
403  MaskInfo _dossierNextSuspectMask;
404  MaskInfo _dossierPrevSuspectMask;
405  MaskInfo _dossierNextSheetMask;
406  MaskInfo _dossierPrevSheetMask;
407  bool selectDossierPage(Common::Point);
408  bool selectDossierNextSuspect(Common::Point);
409  bool selectDossierPrevSuspect(Common::Point);
410  bool selectDossierNextSheet(Common::Point);
411  bool selectDossierPrevSheet(Common::Point);
412  void addDossier(Common::String &page1, Common::String &page2);
413  void loadDossier();
414 
415  // Police Bust
416  bool _policeBustEnabled;
417  bool _policeSirenPlayed;
418  int _numberOfClicks;
419  int _numberClicksAfterSiren;
420  int _policeBustMovieIndex;
421  Common::String _policeBustMovie;
422  Common::String _policeBustPreviousSetting;
423  void resetPoliceBust();
424  void startPoliceBust();
425  void stopPoliceBust();
426  void wallSafeAlarm();
427  void completePoliceBust();
428  void checkPoliceBust();
429 
430  // Diary
431  InvList inventory;
432  bool inInventory(const Common::String &bmp) const;
433  void addInventory(const Common::String &bmp, Common::String &flag);
434  void removeInventory(const Common::String &bmp);
435  void removeRandomInventory();
436  Common::String _diaryLocPrefix;
437  void loadLocations(const Common::Rect &);
438  void loadInventory(uint32, const Common::Rect &, const Common::Rect &);
439  bool _toTake;
440  bool _haveTakenItem;
441  DiaryPages _diaryPages;
442  int _currentDiaryPage;
443  ExitInfo _diaryNextPageExit;
444  ExitInfo _diaryPrevPageExit;
445  bool selectDiaryNextPage(Common::Point mousePos);
446  bool selectDiaryPrevPage(Common::Point mousePos);
447  void addMemory(const Common::String &path);
448  void loadMemories(const Common::Rect &rect, uint rightPageOffset, uint verticalOffset);
449  bool selectLocation(const Common::Point &mousePos);
450  Common::Array<MaskInfo> _locationMasks;
451  Common::Array<MaskInfo> _memoryMasks;
452  bool selectMemory(const Common::Point &mousePos);
453  void setLocationAsVisited(Symbol *location);
454  int getMaxLocationValue();
455  bool selectSkipMemoryVideo(Common::Point mousePos);
456 
457  // Save/Load games
458  MaskInfo _saveGameMask;
459  MaskInfo _loadGameMask;
460 
461  int _mode;
462  bool _modified;
463 
464  PlayedMediaTable _playedMovies;
465  Common::String _repeatedMovieExit;
466 
467  // Masks/Exits
468  ExitList _exits;
469  MaskList _masks;
470 
471  // Sounds
472  void playBackgroundSound(const Common::String &name);
473  void playForegroundSound(const Common::String &name);
474  void playForegroundSound(Sound &sound, const Common::String &name);
475  void playSound(Sound &sound, const Common::String &name, bool loop);
476  void stopForegroundSounds();
477  void stopSounds();
478  void stopSound(Sound &sound);
479  bool isSoundPlaying();
480  bool isSoundPlaying(Sound &sound);
481  void waitForSoundsToStop();
482  bool consumeEvents();
483  Sound _bgSound;
484  Sound _fgSounds[4];
485  Sound _phoneCallSound;
486  Sound _AMRadioSound;
487  Sound _policeRadioSound;
488  Sound _takeLeaveSound;
489  bool _noStopSounds;
490  Common::String _pausedBackgroundSoundName;
491 
492  Common::String getPaperShuffleSound();
493  Common::String _globalAudioPath;
494 
495  Common::String getTakeSound();
496  Common::String getTakeLeaveSound();
497  Common::String getLeaveSound();
498  Common::String _sirenSound;
499 
500  // Radios
501  MaskInfo _AMRadioArea;
502  MaskInfo _policeRadioArea;
503  Radio _AMRadio;
504  Radio _policeRadio;
505  void addRadioClip(
506  Radio &radio, const Common::String &name, int priority,
507  int disabledPriority1, bool exactPriorityMatch1,
508  int disabledPriority2, bool exactPriorityMatch2,
509  const Common::String &flagName, int flagValue);
510  void initializeAMRadioChannels(uint clipCount);
511  void initializePoliceRadioChannels();
512  void disableRadioClips(Radio &radio, int priority);
513  void playRadio(Radio &radio, bool randomlyDisableClips);
514  bool selectAMRadioArea(Common::Point);
515  bool selectPoliceRadioArea(Common::Point);
516 
517  // Phone
518  MaskInfo _phoneArea;
519  Common::String _phonePrefix;
520  PhoneList _phones;
521  void addPhone(const Common::String &name, bool once, int startIndex, int endIndex, const Common::String &flagName, int flagValue);
522  void initializePhoneOnDesktop();
523  void checkPhoneCall();
524  bool cursorPhoneArea(Common::Point mousePos);
525  bool selectPhoneArea(Common::Point mousePos);
526 
527  // Safe
528  Common::String _safeNumberPath;
529  MaskInfo _safeDigitArea[3];
530  Common::Rect _safeDigitRect[3];
531 
532  void initializeWallSafeValue();
533  bool selectSafeDigit(Common::Point);
534  void addSafeDigit(uint32, Common::Rect*);
535  int getSafeDigit(uint32 d);
536  void incrementSafeDigit(uint32 d);
537 
538  // Random values
539  bool getRandomBool(uint);
540 
541  // Timer
542  Common::String _timerSetting;
543  Common::String _timerSkipSetting;
544  uint32 _timerStartTime;
545  uint32 _timerDelay;
546  void setTimer(uint32 duration, const Common::String &setting, const Common::String &skipSetting);
547  void clearTimer();
548  void skipTimer();
549  void checkTimer();
550 
551  // VM objects
552  RectList _rects; // created by fCRect
553 };
554 
555 extern PrivateEngine *g_private;
556 
557 } // End of namespace Private
558 
559 #endif
#define ARRAYSIZE(x)
Definition: util.h:114
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:282
Definition: stream.h:77
Definition: error.h:81
Definition: private.h:159
Definition: pixelformat.h:138
Definition: advancedDetector.h:164
void clear()
Definition: array.h:321
Definition: random.h:44
Definition: symbol.h:57
Definition: rect.h:536
Definition: path.h:52
Definition: private.h:134
Definition: stream.h:745
Definition: smk_decoder.h:77
Definition: private.h:81
Definition: symbol.h:35
bool canSaveAutosaveCurrently() override
Definition: private.h:307
Definition: archive.h:141
Definition: private.h:93
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: private.h:304
Definition: subtitles.h:78
Definition: mixer.h:49
Definition: private.h:129
Definition: ustr.h:57
Definition: private.h:244
Definition: private.h:237
Definition: cursor.h:42
Definition: algorithm.h:29
Definition: fs.h:69
Definition: private.h:200
Definition: private.h:147
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: decompiler.h:30
Definition: private.h:182
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: private.h:310
Definition: private.h:189
Definition: system.h:166
Definition: private.h:177
Definition: private.h:194
Definition: movie_decoder.h:32
Definition: private.h:207
void setEmpty()
Definition: rect.h:375
Definition: engine.h:149
Platform
Definition: platform.h:93
Language
Definition: language.h:45