ScummVM API documentation
agds.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 AGDS_H
23 #define AGDS_H
24 
25 #include "agds/database.h"
26 #include "agds/detection.h"
27 #include "agds/dialog.h"
28 #include "agds/inventory.h"
29 #include "agds/mouseMap.h"
30 #include "agds/processExitCode.h"
31 #include "agds/resourceManager.h"
32 #include "agds/screen.h"
33 #include "agds/soundManager.h"
34 #include "agds/textLayout.h"
35 #include "common/array.h"
36 #include "common/hashmap.h"
37 #include "common/ptr.h"
38 #include "common/random.h"
39 #include "common/rect.h"
40 #include "common/scummsys.h"
41 #include "engines/advancedDetector.h"
42 #include "graphics/pixelformat.h"
43 #include "video/flic_decoder.h"
44 
54 namespace Graphics {
55 class Font;
56 class ManagedSurface;
57 } // namespace Graphics
58 
59 namespace AGDS {
60 
61 class Animation;
62 using AnimationPtr = Common::SharedPtr<Animation>;
63 class Character;
64 class Font;
65 class Object;
66 using ObjectPtr = Common::SharedPtr<Object>;
67 struct ObjectPatch;
68 using ObjectPatchPtr = Common::SharedPtr<ObjectPatch>;
69 struct Patch;
70 using PatchPtr = Common::SharedPtr<Patch>;
71 class Process;
72 using ProcessPtr = Common::SharedPtr<Process>;
73 struct Region;
74 using RegionPtr = Common::SharedPtr<Region>;
75 struct MouseRegion;
76 
77 class MJPGPlayer;
78 class Screen;
79 class SystemVariable;
80 class Console;
81 
82 class AGDSEngine : public Engine {
83  friend class Process;
85  static constexpr uint MaxProcesses = 100;
86 
87 public:
88  struct Color {
89  uint8 r = 0;
90  uint8 g = 0;
91  uint8 b = 0;
92 
93  void FromString(const Common::String &rgb);
94  Common::String ToString() const;
95 
96  uint32 map(const Graphics::PixelFormat &format) const;
97  };
98 
99  AGDSEngine(OSystem *syst, const ADGameDescription *gameDesc);
100  AGDSEngine(const AGDSEngine &) = delete;
101  ~AGDSEngine();
102 
103  Common::Error run() override;
104 
105  void setGlobal(const Common::String &name, int value);
106  int getGlobal(const Common::String &name) const;
107  bool hasGlobal(const Common::String &name) const {
108  return _globals.contains(name);
109  }
110 
111 private:
112  void addSystemVar(const Common::String &name, SystemVariable *var);
113  bool initGraphics(int w, int h);
114  bool load();
115  void runProcesses();
116  void tick();
117  void fadeAndReactivate();
118 
119 public:
120  bool hasFeature(EngineFeature f) const override;
121  Common::Error loadGameState(int slot) override;
122  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
123  bool canLoadGameStateCurrently(Common::U32String *msg) override { return true; }
124  bool canSaveGameStateCurrently(Common::U32String *msg) override { return false; }
125 
126  ObjectPtr loadObject(const Common::String &name, const Common::String &prototype = Common::String(), bool allowInitialise = true);
127  ObjectPtr runObject(const Common::String &name, const Common::String &prototype = Common::String(), bool allowInitialise = true);
128  void runObject(const ObjectPtr &object);
129  void runProcess(const ObjectPtr &object, uint ip = 0);
130  ProcessPtr findProcess(const Common::String &name) const;
131  void reactivate(const Common::String &name, const Common::String &where, bool runNow = false);
132  bool hasActiveProcesses(const Common::String &name) const;
133  void runPendingReactivatedProcesses();
134 
135  void resetCurrentScreen();
136  void loadScreen(const Common::String &name, ScreenLoadingType type, bool savePatch = true);
137  void loadNextScreen();
138  void saveScreenPatch();
139 
140  RegionPtr loadRegion(const Common::String &name);
141  Common::String loadText(const Common::String &name);
142 
143  int appendToSharedStorage(const Common::String &value);
144  const Common::String &getSharedStorage(int id) const;
145 
146  bool active() const { return !_mjpgPlayer; }
147  void playFilm(Process &process, const Common::String &video, const Common::String &audio, const Common::String &subtitles);
148  void skipFilm();
149 
150  ResourceManager &resourceManager() {
151  return _resourceManager;
152  }
153 
154  SoundManager &soundManager() {
155  return _soundManager;
156  }
157 
158  Inventory &inventory() {
159  return _inventory;
160  }
161 
162  Dialog &dialog() {
163  return _dialog;
164  }
165 
166  const ProcessListType &processes() const {
167  return _processes;
168  }
169 
170  TextLayout &textLayout() {
171  return _textLayout;
172  }
173 
174  Screen *getCurrentScreen() {
175  return _currentScreen.get();
176  }
177  Console *getConsole();
178 
179  Common::String &getCurrentScreenName() {
180  return _currentScreenName;
181  }
182  ObjectPtr getCurrentScreenObject(const Common::String &name);
183 
184  const Graphics::PixelFormat &pixelFormat() const {
185  return _pixelFormat;
186  }
187 
188  Graphics::ManagedSurface *loadPicture(const Common::String &name);
189  Graphics::Surface *createSurface(int w, int h);
190  Graphics::ManagedSurface *convertToTransparent(Graphics::Surface *surface); // destroys surface!
191 
192  int loadFromCache(const Common::String &name) const;
193  Graphics::ManagedSurface *loadFromCache(int id) const;
194  int saveToCache(const Common::String &name, Graphics::ManagedSurface *surface);
195 
196  void loadFont(int id, const Common::String &name, int gw, int gh);
197  const Graphics::Font *getFont(int id) const;
198 
199  AnimationPtr loadAnimation(const Common::String &name);
200  AnimationPtr loadMouseCursor(const Common::String &name);
201  AnimationPtr findAnimationByPhaseVar(const Common::String &phaseVar);
202  void loadCharacter(const Common::String &id, const Common::String &name, const Common::String &object);
203  Character *getCharacter(const Common::String &name) {
204  return _currentCharacterName == name ? _currentCharacter.get() : nullptr;
205  }
206  Character *currentCharacter() const {
207  return _currentCharacter.get();
208  }
209  Character *jokes() const {
210  return _jokes.get();
211  }
212 
213  void loadDefaultMouseCursor(const Common::String &name) {
214  _defaultMouseCursorName = name;
215  _defaultMouseCursor = loadMouseCursor(name);
216  }
217 
218  void changeMouseArea(int id, int enabled);
219 
220  void enableUser(bool enabled) {
221  _userEnabled = enabled;
222  }
223  void enableSystemUser(bool enabled) {
224  _systemUserEnabled = enabled;
225  }
226 
227  bool userEnabled() const {
228  return _userEnabled && _systemUserEnabled && !_mjpgPlayer;
229  }
230 
231  void newGame();
232  void initSystemVariables();
233  SystemVariable *getSystemVariable(const Common::String &name);
234 
235  void setNextScreenName(const Common::String &nextScreenName, ScreenLoadingType type);
236  void returnToPreviousScreen();
237 
238  void tickInventory();
239 
240  void playSoundSync(int syncSoundId) {
241  _syncSoundId = syncSoundId;
242  }
243 
244  void setAmbientSoundId(int id) {
245  stopAmbientSound();
246  _ambientSoundId = id;
247  }
248 
249  void tell(Process &process, const Common::String &region, Common::String text, Common::String sound, bool npc);
250 
251  bool fastMode() const {
252  return _fastMode;
253  }
254 
255  Common::Point mousePosition() const {
256  return _mouse;
257  }
258 
259  void currentInventoryObject(const ObjectPtr &object);
260  void resetCurrentInventoryObject();
261  ObjectPtr popCurrentInventoryObject();
262  const ObjectPtr &currentInventoryObject() const {
263  return _currentInventoryObject;
264  }
265 
266  bool showHints() const {
267  return _hintMode;
268  }
269 
270  PatchPtr getPatch(const Common::String &screenName) const;
271  PatchPtr createPatch(const Common::String &screenName);
272  ObjectPatchPtr getObjectPatch(const Common::String &screenName) const;
273  ObjectPatchPtr createObjectPatch(const Common::String &screenName);
274 
275  void shadowIntensity(int intensity) {
276  _shadowIntensity = intensity;
277  }
278  int getRandomNumber(int max);
279 
280  void curtain(const Common::String &process, int screen, int sound, int music, bool updateGlobals);
281  bool activeCurtain() const {
282  return _curtainTimer >= 0;
283  }
284 
285  int version() const;
286  bool versionAtLeast(int target) const;
287  Common::Language language() const;
288 
289 private:
290  void stopAmbientSound();
291  void loadPatches(Common::SeekableReadStream &file, Database &db);
292 
302 
303  const ADGameDescription *_gameDescription;
304  ResourceManager _resourceManager;
305  SoundManager _soundManager;
306  Database _data;
307  PictureCacheType _pictureCache;
308  PictureCacheLookup _pictureCacheLookup;
309  int _pictureCacheId;
310  FontsType _fonts;
311  ProcessListType _processes;
312  ProcessListType _pendingReactivatedProcesses;
313  PatchesType _patches;
314  ObjectPatchesType _objectPatches;
315  int _sharedStorageIndex;
316  Common::String _sharedStorage[10];
317  GlobalsType _globals;
318  SystemVariablesListType _systemVarList;
319  SystemVariablesType _systemVars;
320  Graphics::PixelFormat _pixelFormat;
321  Color _colorKey;
322  Color _minShadowColor;
323  Color _maxShadowColor;
324  int _shadowIntensity;
325  Common::ScopedPtr<MJPGPlayer> _mjpgPlayer;
326  uint32 _filmStarted;
327  Common::String _filmProcess;
328  Common::ScopedPtr<Screen> _currentScreen;
329  Common::String _currentScreenName;
330  Common::ScopedPtr<Character> _currentCharacter;
332  Common::String _currentCharacterName, _currentCharacterFilename, _currentCharacterObject;
333  Common::String _nextScreenName;
334  ScreenLoadingType _nextScreenType;
335  Common::String _defaultMouseCursorName;
336  AnimationPtr _defaultMouseCursor;
337  Common::Point _mouse;
338  bool _userEnabled;
339  bool _systemUserEnabled;
340  MouseMap _mouseMap;
341  Common::RandomSource _random;
342 
343  Inventory _inventory;
344  Common::String _inventoryRegionName;
345  RegionPtr _inventoryRegion;
346  ObjectPtr _currentInventoryObject;
347 
348  Dialog _dialog;
349 
350  // Original engine use weird names for the vars, I keep them.
351  int _tellTextTimer;
352  TextLayout _textLayout;
353 
354  int _syncSoundId;
355  int _ambientSoundId;
356 
357  Common::String _curtainProcess;
358  int _curtainTimer;
359  int _curtainScreen;
360 
361  bool _fastMode;
362  bool _hintMode;
363 };
364 
365 } // End of namespace AGDS
366 
367 #endif /* AGDS_AGDS_H */
Definition: managed_surface.h:51
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
EngineFeature
Definition: engine.h:282
Definition: error.h:81
Definition: agds.h:88
Definition: pixelformat.h:138
Definition: advancedDetector.h:164
Definition: random.h:44
Definition: character.h:48
Definition: textLayout.h:39
Definition: atari-screen.h:58
Definition: stream.h:745
Definition: ptr.h:572
Definition: resourceManager.h:40
Definition: database.h:33
bool canSaveGameStateCurrently(Common::U32String *msg) override
Definition: agds.h:124
Definition: inventory.h:41
Definition: agds.h:59
Definition: ustr.h:57
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: console.h:31
Definition: screen.h:55
Definition: dialog.h:33
void initGraphics(int width, int height)
Definition: systemVariable.h:35
Definition: soundManager.h:64
Definition: system.h:166
bool canLoadGameStateCurrently(Common::U32String *msg) override
Definition: agds.h:123
Definition: mouseMap.h:63
Definition: agds.h:82
Definition: engine.h:149
Definition: process.h:40
Language
Definition: language.h:45