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  PrivateEngine(OSystem *syst, const ADGameDescription *gd);
261  ~PrivateEngine();
262 
263  const ADGameDescription *_gameDescription;
264  bool isDemo() const;
265  Common::Language _language;
266  Common::Platform _platform;
267 
268  SymbolMaps maps;
269 
270  Video::SmackerDecoder *_videoDecoder;
271  Video::SmackerDecoder *_pausedVideo;
272  Common::String _pausedMovieName;
273 
274  Common::Error run() override;
275  void restartGame();
276  void clearAreas();
277  void initializePath(const Common::FSNode &gamePath) override;
278  void pauseEngineIntern(bool pause) override;
279  Common::SeekableReadStream *loadAssets();
280  Common::Archive *loadMacInstaller();
281 
282  // Functions
283 
284  NameToPtr _functions;
285  void initFuncs();
286 
287  // User input
288  void selectPauseGame(Common::Point);
289  bool selectMask(Common::Point);
290  bool selectExit(Common::Point);
291  bool selectLoadGame(Common::Point);
292  bool selectSaveGame(Common::Point);
293  void resumeGame();
294 
295  // Cursors
296  void updateCursor(Common::Point);
297  bool cursorPauseMovie(Common::Point);
298  bool cursorExit(Common::Point);
299  bool cursorSafeDigit(Common::Point);
300  bool cursorMask(Common::Point);
301 
302  bool hasFeature(EngineFeature f) const override;
303  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
304  return true;
305  }
306  bool canSaveAutosaveCurrently() override {
307  return false;
308  }
309  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
310  return true;
311  }
312 
313  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
314  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
315 
316  static Common::Path convertPath(const Common::String &name);
317  static Common::String getVideoViewScreen(Common::String video);
318  void playVideo(const Common::String &);
319  void skipVideo();
320  void destroyVideo();
321 
322  void loadSubtitles(const Common::Path &path, SubtitleType type, Sound *sound = nullptr);
323  // use to clean up sounds which have finished playing once
324  void updateSubtitles();
325  void destroySubtitles();
326  void adjustSubtitleSize();
327  Video::Subtitles *_videoSubtitles;
328  SubtitleSlot _voiceSlot; // high priority (speech)
329  SubtitleSlot _sfxSlot; // low priority (sfxs)
330  bool _useSubtitles;
331  bool _sfxSubtitles;
332 
333  Graphics::Surface *decodeImage(const Common::String &file, byte **palette, bool *isNewPalette);
334  //byte *decodePalette(const Common::String &name);
335  void remapImage(uint16 ncolors, const Graphics::Surface *oldImage, const byte *oldPalette, Graphics::Surface *newImage, const byte *currentPalette);
336  static uint32 findMaskTransparentColor(const byte *palette, uint32 defaultColor);
337  static void swapImageColors(Graphics::Surface *image, byte *palette, uint32 a, uint32 b);
338  void loadImage(const Common::String &file, int x, int y);
339  void drawScreenFrame(const byte *videoPalette);
340 
341  // Cursors
342  Graphics::Cursor *_defaultCursor;
343  Common::Array<CursorInfo> _cursors;
344  Common::String _currentCursor;
345  void changeCursor(const Common::String &);
346  Common::String getInventoryCursor();
347  Common::String getExitCursor();
348  void loadCursors();
349 
350  // Rendering
351  Graphics::ManagedSurface *_compositeSurface;
352  Graphics::Surface *loadMask(const Common::String &, int, int, bool);
353  void loadMaskAndInfo(MaskInfo *m, const Common::String &name, int x, int y, bool drawn);
354  void drawMask(Graphics::Surface *);
355  void fillRect(uint32, Common::Rect);
356  bool inMask(Graphics::Surface *, Common::Point);
357  uint32 _transparentColor;
358  Common::Rect _screenRect;
359  Common::String _framePath;
360  Graphics::Surface *_frameImage;
361  Graphics::Surface *_mframeImage;
362  byte *_framePalette;
363  Common::String _nextVS;
364  Common::String _currentVS;
365  Common::Point _origin;
366  void drawScreen();
367  bool _needToDrawScreenFrame;
368 
369  // settings
370  Common::String _nextSetting;
371  Common::String _pausedSetting;
372  Common::String _currentSetting;
373  Common::String getPauseMovieSetting();
374  Common::String getGoIntroSetting();
375  Common::String getMainDesktopSetting();
376  Common::String getDiaryTOCSetting();
377  Common::String getDiaryMiddleSetting();
378  Common::String getDiaryLastPageSetting();
379  Common::String getPOGoBustMovieSetting();
380  Common::String getPoliceBustFromMOSetting();
381  Common::String getListenToPhoneSetting();
382  Common::String getAlternateGameVariable();
383  Common::String getPoliceIndexVariable();
384  Common::String getWallSafeValueVariable();
385  Common::String getPoliceArrivedVariable();
386  Common::String getBeenDowntownVariable();
387  Common::String getPoliceStationLocation();
388  const char *getSymbolName(const char *name, const char *strippedName, const char *demoName = nullptr);
389 
390  // movies
391  Common::String _nextMovie;
392  Common::String _currentMovie;
393 
394  // Dossiers
395  DossierArray _dossiers;
396  uint _dossierSuspect;
397  uint _dossierPage;
398  MaskInfo _dossierPageMask;
399  MaskInfo _dossierNextSuspectMask;
400  MaskInfo _dossierPrevSuspectMask;
401  MaskInfo _dossierNextSheetMask;
402  MaskInfo _dossierPrevSheetMask;
403  bool selectDossierPage(Common::Point);
404  bool selectDossierNextSuspect(Common::Point);
405  bool selectDossierPrevSuspect(Common::Point);
406  bool selectDossierNextSheet(Common::Point);
407  bool selectDossierPrevSheet(Common::Point);
408  void addDossier(Common::String &page1, Common::String &page2);
409  void loadDossier();
410 
411  // Police Bust
412  bool _policeBustEnabled;
413  bool _policeSirenPlayed;
414  int _numberOfClicks;
415  int _numberClicksAfterSiren;
416  int _policeBustMovieIndex;
417  Common::String _policeBustMovie;
418  Common::String _policeBustPreviousSetting;
419  void resetPoliceBust();
420  void startPoliceBust();
421  void stopPoliceBust();
422  void wallSafeAlarm();
423  void completePoliceBust();
424  void checkPoliceBust();
425 
426  // Diary
427  InvList inventory;
428  bool inInventory(const Common::String &bmp) const;
429  void addInventory(const Common::String &bmp, Common::String &flag);
430  void removeInventory(const Common::String &bmp);
431  void removeRandomInventory();
432  Common::String _diaryLocPrefix;
433  void loadLocations(const Common::Rect &);
434  void loadInventory(uint32, const Common::Rect &, const Common::Rect &);
435  bool _toTake;
436  bool _haveTakenItem;
437  DiaryPages _diaryPages;
438  int _currentDiaryPage;
439  ExitInfo _diaryNextPageExit;
440  ExitInfo _diaryPrevPageExit;
441  bool selectDiaryNextPage(Common::Point mousePos);
442  bool selectDiaryPrevPage(Common::Point mousePos);
443  void addMemory(const Common::String &path);
444  void loadMemories(const Common::Rect &rect, uint rightPageOffset, uint verticalOffset);
445  bool selectLocation(const Common::Point &mousePos);
446  Common::Array<MaskInfo> _locationMasks;
447  Common::Array<MaskInfo> _memoryMasks;
448  bool selectMemory(const Common::Point &mousePos);
449  void setLocationAsVisited(Symbol *location);
450  int getMaxLocationValue();
451  bool selectSkipMemoryVideo(Common::Point mousePos);
452 
453  // Save/Load games
454  MaskInfo _saveGameMask;
455  MaskInfo _loadGameMask;
456 
457  int _mode;
458  bool _modified;
459 
460  PlayedMediaTable _playedMovies;
461  Common::String _repeatedMovieExit;
462 
463  // Masks/Exits
464  ExitList _exits;
465  MaskList _masks;
466 
467  // Sounds
468  void playBackgroundSound(const Common::String &name);
469  void playForegroundSound(const Common::String &name);
470  void playForegroundSound(Sound &sound, const Common::String &name);
471  void playSound(Sound &sound, const Common::String &name, bool loop);
472  void stopForegroundSounds();
473  void stopSounds();
474  void stopSound(Sound &sound);
475  bool isSoundPlaying();
476  bool isSoundPlaying(Sound &sound);
477  void waitForSoundsToStop();
478  bool consumeEvents();
479  Sound _bgSound;
480  Sound _fgSounds[4];
481  Sound _phoneCallSound;
482  Sound _AMRadioSound;
483  Sound _policeRadioSound;
484  Sound _takeLeaveSound;
485  bool _noStopSounds;
486  Common::String _pausedBackgroundSoundName;
487 
488  Common::String getPaperShuffleSound();
489  Common::String _globalAudioPath;
490 
491  Common::String getTakeSound();
492  Common::String getTakeLeaveSound();
493  Common::String getLeaveSound();
494  Common::String _sirenSound;
495 
496  // Radios
497  MaskInfo _AMRadioArea;
498  MaskInfo _policeRadioArea;
499  Radio _AMRadio;
500  Radio _policeRadio;
501  void addRadioClip(
502  Radio &radio, const Common::String &name, int priority,
503  int disabledPriority1, bool exactPriorityMatch1,
504  int disabledPriority2, bool exactPriorityMatch2,
505  const Common::String &flagName, int flagValue);
506  void initializeAMRadioChannels(uint clipCount);
507  void initializePoliceRadioChannels();
508  void disableRadioClips(Radio &radio, int priority);
509  void playRadio(Radio &radio, bool randomlyDisableClips);
510  bool selectAMRadioArea(Common::Point);
511  bool selectPoliceRadioArea(Common::Point);
512 
513  // Phone
514  MaskInfo _phoneArea;
515  Common::String _phonePrefix;
516  PhoneList _phones;
517  void addPhone(const Common::String &name, bool once, int startIndex, int endIndex, const Common::String &flagName, int flagValue);
518  void initializePhoneOnDesktop();
519  void checkPhoneCall();
520  bool cursorPhoneArea(Common::Point mousePos);
521  bool selectPhoneArea(Common::Point mousePos);
522 
523  // Safe
524  Common::String _safeNumberPath;
525  MaskInfo _safeDigitArea[3];
526  Common::Rect _safeDigitRect[3];
527 
528  void initializeWallSafeValue();
529  bool selectSafeDigit(Common::Point);
530  void addSafeDigit(uint32, Common::Rect*);
531  int getSafeDigit(uint32 d);
532  void incrementSafeDigit(uint32 d);
533 
534  // Random values
535  bool getRandomBool(uint);
536 
537  // Timer
538  Common::String _timerSetting;
539  Common::String _timerSkipSetting;
540  uint32 _timerStartTime;
541  uint32 _timerDelay;
542  void setTimer(uint32 duration, const Common::String &setting, const Common::String &skipSetting);
543  void clearTimer();
544  void skipTimer();
545  void checkTimer();
546 
547  // VM objects
548  RectList _rects; // created by fCRect
549 };
550 
551 extern PrivateEngine *g_private;
552 
553 } // End of namespace Private
554 
555 #endif
#define ARRAYSIZE(x)
Definition: util.h:112
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: 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:524
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:306
Definition: archive.h:141
Definition: private.h:93
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: private.h:303
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:309
Definition: private.h:189
Definition: system.h:164
Definition: private.h:177
Definition: private.h:194
Definition: movie_decoder.h:32
Definition: private.h:207
void setEmpty()
Definition: rect.h:363
Definition: engine.h:144
Platform
Definition: platform.h:93
Language
Definition: language.h:45