ScummVM API documentation
ngi.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 NGI_FULLPIPE_H
23 #define NGI_FULLPIPE_H
24 
25 #include "audio/mixer.h"
26 #include "common/scummsys.h"
27 #include "common/events.h"
28 #include "common/keyboard.h"
29 #include "common/ptr.h"
30 #include "common/random.h"
31 #include "common/savefile.h"
32 #include "common/system.h"
33 #include "graphics/managed_surface.h"
34 
35 #include "engines/engine.h"
36 #include "ngi/console.h"
37 
38 namespace Audio {
39 class SoundHandle;
40 }
41 
42 namespace NGI {
43 
44 enum {
45  kDebugPathfinding = 1,
46  kDebugDrawing,
47  kDebugLoading,
48  kDebugAnimation,
49  kDebugMemory,
50  kDebugEvents,
51  kDebugBehavior,
52  kDebugInventory,
53  kDebugSceneLogic,
54  kDebugInteractions,
55  kDebugXML,
56 };
57 
58 enum NGIActions {
59  kActionNone,
60  kActionPause,
61  kActionStopSounds,
62  kActionToggleMute,
63  kActionMapOpen,
64  kActionMapClose,
65  kActionHelp,
66  kActionInventory,
67  kActionSkipIntro,
68  kActionSkipCredits,
69  kActionCloseDialog,
70 };
71 
72 #define MAXGAMEOBJH 10000
73 
74 struct NGIGameDescription;
75 
76 
77 class BehaviorManager;
78 class BaseModalObject;
79 class GameLoader;
80 class GameVar;
81 class InputController;
82 class Inventory2;
83 struct CursorInfo;
84 struct EntranceInfo;
85 class ExCommand;
86 class Floaters;
87 class GameProject;
88 class GameObject;
89 class GlobalMessageQueueList;
90 struct MessageHandler;
91 class MessageQueue;
92 class AniHandler;
93 class NGIArchive;
94 class PictureObject;
95 struct PreloadItem;
96 class Scene;
97 class SoundList;
98 class StaticANIObject;
99 class Vars;
100 typedef Common::Array<int16> MovTable;
101 typedef Common::Array<Common::Point> PointList;
102 
103 struct Palette {
104  uint32 pal[256];
105  uint size;
106 
107  Palette() {
108  size = 0;
109  memset(pal, 0, 256 * 4);
110  }
111 
112  void copy(const Palette &src) {
113  size = src.size;
114  memcpy(pal, src.pal, 256 * 4);
115  }
116 };
117 
119 
120 int global_messageHandler1(ExCommand *cmd);
121 int global_messageHandler2(ExCommand *cmd);
122 int global_messageHandler3(ExCommand *cmd);
123 int global_messageHandler4(ExCommand *cmd);
124 void global_messageHandler_handleSound(ExCommand *cmd);
125 
126 
127 class NGIEngine : public ::Engine {
128 protected:
129 
130  Common::Error run() override;
131 
132 public:
133  NGIEngine(OSystem *syst, const NGIGameDescription *gameDesc);
134  ~NGIEngine() override;
135 
136  void initialize();
137  void restartGame();
138  bool shouldQuit();
139 
140  void setMusicAllowed(int val) { _musicAllowed = val; }
141 
142  // Detection related functions
143  const NGIGameDescription *_gameDescription;
144  uint32 getFeatures() const;
145  bool isDemo();
146  Common::Language getLanguage() const;
147  const char *getGameId() const;
148  int getGameGID() const;
149 
151 
152  Common::KeyCode _keyState;
153  uint16 _buttonState;
154 
155  void updateEvents();
156 
157  Graphics::ManagedSurface _backgroundSurface;
158  Graphics::PixelFormat _origFormat;
159 
160  Common::ScopedPtr<GameLoader> _gameLoader;
161  GameProject *_gameProject;
162  bool loadGam(const char *fname, int scene = 0);
163 
164  void loadGameObjH();
165  Common::String gameIdToStr(uint16 id);
166 
167  GameVar *getGameLoaderGameVar();
168  InputController *getGameLoaderInputController();
169 
170  int _gameProjectVersion;
171  int _pictureScale;
172  int _scrollSpeed;
173  bool _updateFlag;
174  bool _flgCanOpenMap;
175  bool _gamePaused;
176  bool _flgGameIsRunning;
177  bool _inputArFlag;
178  bool _recordEvents;
179  bool _mainMenu_debugEnabled;
180 
181  Common::Rect _sceneRect;
182  int _sceneWidth;
183  int _sceneHeight;
184  Scene *_currentScene;
185  Scene *_loaderScene;
186  Scene *_scene2;
187  Scene *_scene3;
188  StaticANIObject *_aniMan;
189  StaticANIObject *_aniMan2;
190  Palette _defaultPalette;
191  const Palette *_globalPalette;
192 
193  InputController *_inputController;
194  bool _inputDisabled;
195 
196  int _currentCheat;
197  int _currentCheatPos;
198 
199  void defHandleKeyDown(int key);
200 
201  SoundList *_currSoundList1[11];
202  int _currSoundListCount;
203  bool _soundEnabled;
204  bool _flgSoundList;
205  Common::Path _sceneTracks[10];
206  int _numSceneTracks;
207  bool _sceneTrackHasSequence;
208  int _musicMinDelay;
209  int _musicMaxDelay;
210  int _musicLocal;
211  Common::String _trackName;
212  int _trackStartDelay;
213  Common::Path _sceneTracksCurrentTrack;
214  bool _sceneTrackIsPlaying;
215 
216  void stopAllSounds();
217  void toggleMute();
218  void playSound(int id, int flag);
219  void playTrack(GameVar *sceneVar, const char *name, bool delayed);
220  int getSceneTrack();
221  void updateTrackDelay();
222  void startSceneTrack();
223  void startSoundStream1(const Common::Path &trackName);
224  void playOggSound(const Common::Path &trackName, Audio::SoundHandle &stream);
225  void stopSoundStream2();
226  void stopAllSoundStreams();
227  void stopAllSoundInstances(int id);
228  void updateSoundVolume();
229  void setMusicVolume(int vol);
230 
231  int _sfxVolume;
232  int _musicVolume;
233 
234  Common::ScopedPtr<GlobalMessageQueueList> _globalMessageQueueList;
235  MessageHandler *_messageHandlers;
236 
237  int _msgX;
238  int _msgY;
239  int _msgObjectId2;
240  int _msgId;
241 
242  Common::List<ExCommand *> _exCommandList;
243  bool _isProcessingMessages;
244 
245  int _mouseVirtX;
246  int _mouseVirtY;
247  Common::Point _mouseScreenPos;
248 
249  Common::ScopedPtr<BehaviorManager> _behaviorManager;
250 
251  Common::ScopedPtr<MovTable> _movTable;
252 
253  Common::ScopedPtr<Floaters> _floaters;
254  Common::ScopedPtr<AniHandler> _aniHandler;
255 
256  Common::Array<Common::Point> _arcadeKeys;
257 
258  void deleteModalObject();
259 
260  void initMap();
261  void updateMap(PreloadItem *pre);
262  void updateMapPiece(int mapId, int update);
263  void updateScreen();
264 
265  void freeGameLoader();
266  void cleanup();
267 
268  bool _gameContinue;
269  bool _needRestart;
270  bool _flgPlayIntro;
271  int _musicAllowed;
272  bool _normalSpeed;
273 
274  void enableSaves() { _isSaveAllowed = true; }
275  void disableSaves(ExCommand *ex);
276  bool isSaveAllowed();
277 
278  void initObjectStates();
279  void setLevelStates();
280  void setSwallowedEggsState();
281  void loadAllScenes();
282 
283  void initCursors();
284  void addCursor(CursorInfo *cursorInfo, Scene *inv, int pictureId, int hotspotX, int hotspotY, int itemPictureOffsX, int itemPictureOffsY);
285 
286  int32 _mapTable[200];
287 
288  Scene *_inventoryScene;
289  Inventory2 *_inventory;
290  int _currSelectedInventoryItemId;
291 
292  int32 _updateTicks;
293  int32 _lastInputTicks;
294  int32 _lastButtonUpTicks;
295 
296  BaseModalObject *_modalObject;
297 
298  int (*_updateScreenCallback)();
299  int (*_updateCursorCallback)();
300 
301  void drawAlphaRectangle(int x1, int y1, int x2, int y2, int alpha);
302  void sceneFade(Scene *sc, bool direction);
303 
304  int _cursorId;
305  int _minCursorId;
306  int _maxCursorId;
307  Common::Array<int> _objectIdCursors;
308  GameObject *_objectAtCursor;
309  int _objectIdAtCursor;
310 
311  void setCursor(int id);
312  void updateCursorCommon();
313 
314  int getObjectState(const Common::String &objname);
315  void setObjectState(const Common::String &name, int state);
316  int getObjectEnumState(const Common::String &name, const char *state);
317 
318  void sceneAutoScrolling();
319  bool sceneSwitcher(const EntranceInfo &entrance);
320  Scene *accessScene(int sceneId);
321  void setSceneMusicParameters(GameVar *var);
322  int convertScene(int scene);
323  int getSceneEntrance(int scene);
324  int getSceneFromTag(int tag);
325 
326  NGIArchive *_currArchive;
327 
328  void openMap();
329  void openHelp();
330  void openMainMenu();
331 
332  PictureObject *_arcadeOverlay;
333  PictureObject *_arcadeOverlayHelper;
334  int _arcadeOverlayX;
335  int _arcadeOverlayY;
336  int _arcadeOverlayMidX;
337  int _arcadeOverlayMidY;
338 
339  void initArcadeKeys(const char *varname);
340  void processArcade(ExCommand *ex);
341  void winArcade();
342  void setArcadeOverlay(int picId);
343  int drawArcadeOverlay(int adjust);
344 
345  void getAllInventory();
346 
347  StaticANIObject *_lastLiftButton;
348  MessageQueue *_liftEnterMQ;
349  MessageQueue *_liftExitMQ;
350  StaticANIObject *_lift;
351  int _liftX;
352  int _liftY;
353 
354  int lift_getButtonIdP(int objid);
355  int lift_getButtonIdH(int objid);
356  int lift_getButtonIdN(int objid);
357  void lift_setButton(const char *name, int state);
358  void lift_init(Scene *sc, int qu1, int qu2);
359  void lift_setButtonStatics(Scene *sc, int buttonId);
360  void lift_exitSeq(ExCommand *ex);
361  void lift_closedoorSeq();
362  void lift_clickButton();
363  void lift_walkAndGo();
364  void lift_goAnimation();
365  void lift_animateButton(StaticANIObject *button);
366  void lift_startExitQueue();
367  void lift_hoverButton(ExCommand *ex);
368  bool lift_checkButton(const char *varname);
369  void lift_openLift();
370 
371  GameVar *_musicGameVar;
372  Audio::SoundHandle _soundStream1;
373  Audio::SoundHandle _soundStream2;
374  Audio::SoundHandle _soundStream3;
375  Audio::SoundHandle _soundStream4;
376 
377  bool _stream2playing;
378 
379  GameObjHMap _gameObjH;
380 
381 public:
382 
383  bool _isSaveAllowed;
384 
385  Common::Error loadGameState(int slot) override;
386  Common::Error saveGameState(int slot, const Common::String &description, bool isAutosave = false) override;
387  Common::String getSaveStateName(int slot) const override;
388 
389  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
390  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _isSaveAllowed; }
391  bool hasFeature(EngineFeature f) const override;
392 
393 };
394 
395 extern NGIEngine *g_nmi;
396 extern Vars *g_vars;
397 
398 } // End of namespace NGI
399 
400 #endif /* NGI_FULLPIPE_H */
Definition: managed_surface.h:51
Definition: gfx.h:137
Definition: messages.h:177
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: ngi.h:390
Definition: str.h:59
EngineFeature
Definition: engine.h:260
Definition: detection.h:34
Definition: interaction.h:90
Definition: gameloader.h:64
Definition: error.h:81
Definition: pixelformat.h:138
Definition: random.h:44
Definition: inventory.h:82
Definition: modal.h:43
Definition: list.h:44
Definition: rect.h:524
Definition: path.h:52
Definition: ngiarchive.h:45
Definition: gfx.h:166
Definition: sound.h:61
Definition: ptr.h:572
Definition: objects.h:33
Definition: input.h:46
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
Definition: ngi.h:127
Definition: mixer.h:49
Definition: messages.h:108
Definition: ustr.h:57
Definition: input.h:31
Definition: scenes.h:216
Definition: rect.h:144
Definition: objects.h:76
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: ngi.h:389
Definition: statics.h:172
Definition: messages.h:59
Definition: scene.h:32
Definition: ngi.h:103
Definition: anihandler.h:25
Definition: system.h:163
Definition: engine.h:146
Definition: system.h:38
Language
Definition: language.h:45