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