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