ScummVM API documentation
scene.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 NANCY_STATE_SCENE_H
23 #define NANCY_STATE_SCENE_H
24 
25 #include "common/singleton.h"
26 #include "common/queue.h"
27 
28 #include "engines/nancy/commontypes.h"
29 #include "engines/nancy/puzzledata.h"
30 
31 #include "engines/nancy/action/actionmanager.h"
32 
33 #include "engines/nancy/state/state.h"
34 
35 #include "engines/nancy/ui/fullscreenimage.h"
36 #include "engines/nancy/ui/viewport.h"
37 #include "engines/nancy/ui/textbox.h"
38 #include "engines/nancy/ui/inventorybox.h"
39 
40 namespace Common {
41 class SeekableReadStream;
42 class Serializer;
43 }
44 
45 namespace Nancy {
46 
47 class NancyEngine;
48 class NancyConsole;
49 struct SceneChangeDescription;
50 
51 namespace Action {
52 class ConversationSound;
53 class PlaySecondaryMovie;
54 }
55 
56 namespace Misc {
57 class Lightning;
58 class SpecialEffect;
59 }
60 
61 namespace UI {
62 class Button;
63 class ViewportOrnaments;
64 class TextboxOrnaments;
65 class InventoryBoxOrnaments;
66 class Clock;
67 }
68 
69 namespace State {
70 
71 // The game state that handles all of the gameplay
72 class Scene : public State, public Common::Singleton<Scene> {
73  friend class Nancy::Action::ActionRecord;
74  friend class Nancy::Action::ActionManager;
75  friend class Nancy::NancyConsole;
76  friend class Nancy::NancyEngine;
77 
78 public:
79  struct SceneSummary {
80  // SSUM and TSUM
81  // Default values set to match those applied when loading from a TSUM chunk
82  Common::String description;
83  Common::Path videoFile;
84 
85  uint16 videoFormat = kLargeVideoFormat;
87  SoundDescription sound;
88 
89  byte panningType = kPan360;
90  uint16 numberOfVideoFrames = 0;
91  uint16 degreesPerRotation = 18;
92  uint16 totalViewAngle = 0;
93  uint16 horizontalScrollDelta = 1;
94  uint16 verticalScrollDelta = 10;
95  uint16 horizontalEdgeSize = 15;
96  uint16 verticalEdgeSize = 15;
97  Time slowMoveTimeDelta = 400;
98  Time fastMoveTimeDelta = 66;
99 
100  // Sound start vectors, used in nancy3 and up
101  Math::Vector3d listenerPosition;
102 
103  void read(Common::SeekableReadStream &stream);
104  void readTerse(Common::SeekableReadStream &stream);
105  };
106 
107  Scene();
108  virtual ~Scene();
109 
110  // State API
111  void process() override;
112  void onStateEnter(const NancyState::NancyState prevState) override;
113  bool onStateExit(const NancyState::NancyState nextState) override;
114 
115  // Used when winning/losing game
116  void setDestroyOnExit() { _destroyOnExit = true; }
117 
118  bool isRunningAd() const { return _isRunningAd; }
119 
120  void changeScene(const SceneChangeDescription &sceneDescription);
121  void pushScene(int16 itemID = -1);
122  void popScene(bool inventory = false);
123 
124  void setPlayerTime(Time time, byte relative);
125  Time getPlayerTime() const { return _timers.playerTime; }
126  Time getTimerTime() const { return _timers.timerIsActive ? _timers.timerTime : 0; }
127  byte getPlayerTOD() const;
128 
129  void addItemToInventory(int16 id);
130  void removeItemFromInventory(int16 id, bool pickUp = true);
131  int16 getHeldItem() const { return _flags.heldItem; }
132  void setHeldItem(int16 id);
133  void setNoHeldItem();
134  byte hasItem(int16 id) const;
135  byte getItemDisabledState(int16 id) const { return _flags.disabledItems[id]; }
136  void setItemDisabledState(int16 id, byte state) { _flags.disabledItems[id] = state; }
137 
138  void installInventorySoundOverride(byte command, const SoundDescription &sound, const Common::String &caption, uint16 itemID);
139  void playItemCantSound(int16 itemID = -1, bool notHoldingSound = false);
140 
141  void setEventFlag(int16 label, byte flag);
142  void setEventFlag(FlagDescription eventFlag);
143  bool getEventFlag(int16 label, byte flag) const;
144  bool getEventFlag(FlagDescription eventFlag) const;
145 
146  void setLogicCondition(int16 label, byte flag);
147  bool getLogicCondition(int16 label, byte flag) const;
148  void clearLogicConditions();
149 
150  void setDifficulty(uint difficulty) { _difficulty = difficulty; }
151  uint16 getDifficulty() const { return _difficulty; }
152 
153  byte getHintsRemaining() const { return _hintsRemaining[_difficulty]; }
154  void useHint(uint16 characterID, uint16 hintID);
155 
156  void requestStateChange(NancyState::NancyState state) { _gameStateRequested = state; }
157  void resetStateToInit() { _state = kInit; }
158 
159  void resetAndStartTimer() { _timers.timerIsActive = true; _timers.timerTime = 0; }
160  void stopTimer() { _timers.timerIsActive = false; _timers.timerTime = 0; }
161 
162  Time getMovementTimeDelta(bool fast) const { return fast ? _sceneState.summary.fastMoveTimeDelta : _sceneState.summary.slowMoveTimeDelta; }
163 
164  void registerGraphics();
165 
166  void synchronize(Common::Serializer &serializer);
167 
168  UI::FullScreenImage &getFrame() { return _frame; }
169  UI::Viewport &getViewport() { return _viewport; }
170  UI::Textbox &getTextbox() { return _textbox; }
171  UI::InventoryBox &getInventoryBox() { return _inventoryBox; }
172  UI::Clock *getClock();
173 
174  Action::ActionManager &getActionManager() { return _actionManager; }
175 
176  SceneChangeDescription &getSceneInfo() { return _sceneState.currentScene; }
177  SceneChangeDescription &getNextSceneInfo() { return _sceneState.nextScene; }
178  const SceneSummary &getSceneSummary() const { return _sceneState.summary; }
179 
180  void setActiveMovie(Action::PlaySecondaryMovie *activeMovie);
181  Action::PlaySecondaryMovie *getActiveMovie();
182  void setActiveConversation(Action::ConversationSound *activeConversation);
183  Action::ConversationSound *getActiveConversation();
184 
185  Graphics::ManagedSurface &getLastScreenshot() { return _lastScreenshot; }
186 
187  // The Vampire Diaries only;
188  void beginLightning(int16 distance, uint16 pulseTime, int16 rgbPercent);
189 
190  // Used from nancy2 onwards
191  void specialEffect(byte type, uint16 fadeToBlackTime, uint16 frameTime);
192  void specialEffect(byte type, uint16 totalTime, uint16 fadeToBlackTime, Common::Rect rect);
193 
194  // Get the persistent data for a given puzzle type
195  PuzzleData *getPuzzleData(const uint32 tag);
196 
197 private:
198  void init();
199  void load(bool fromSaveFile = false);
200  void run();
201  void handleInput();
202 
203  void initStaticData();
204 
205  void clearSceneData();
206  void clearPuzzleData();
207 
208  enum State {
209  kInit,
210  kLoad,
211  kStartSound,
212  kRun
213  };
214 
215  struct SceneState {
216  SceneSummary summary;
217  SceneChangeDescription currentScene;
218  SceneChangeDescription nextScene;
219  SceneChangeDescription pushedScene;
220  bool isScenePushed = false;
221  SceneChangeDescription pushedInvScene;
222  int16 pushedInvItemID = -1;
223  bool isInvScenePushed = false;
224  };
225 
226  struct Timers {
227  Time pushedPlayTime;
228  Time lastTotalTime;
229  Time sceneTime;
230  Time timerTime;
231  bool timerIsActive = false;
232  Time playerTime; // In-game time of day, adds a minute every 5 seconds
233  Time playerTimeNextMinute; // Stores the next tick count until we add a minute to playerTime
234  };
235 
236  struct PlayFlags {
237  struct LogicCondition {
238  LogicCondition();
239  byte flag;
240  Time timestamp;
241  };
242 
243  LogicCondition logicConditions[30];
244  Common::Array<byte> eventFlags;
246  Common::Array<byte> items;
247  Common::Array<byte> disabledItems;
248  int16 heldItem = -1;
249  int16 primaryVideoResponsePicked = -1;
250  };
251 
252  struct InventorySoundOverride {
253  bool isDefault = false; // When true, other fields are ignored
254  SoundDescription sound;
255  Common::String caption;
256  };
257 
258  // UI
259  UI::FullScreenImage _frame;
260  UI::Viewport _viewport;
261  UI::Textbox _textbox;
262  UI::InventoryBox _inventoryBox;
263 
264  UI::Button *_menuButton;
265  UI::Button *_helpButton;
266  Time _buttonPressActivationTime;
267 
268  UI::ViewportOrnaments *_viewportOrnaments;
269  UI::TextboxOrnaments *_textboxOrnaments;
270  UI::InventoryBoxOrnaments *_inventoryBoxOrnaments;
271  RenderObject *_clock;
272 
273  Common::Rect _mapHotspot;
274 
275  // General data
276  SceneState _sceneState;
277  PlayFlags _flags;
278  Timers _timers;
279  uint16 _difficulty;
280  Common::Array<uint16> _hintsRemaining;
281  int16 _lastHintCharacter;
282  int16 _lastHintID;
283  NancyState::NancyState _gameStateRequested;
284  Common::HashMap<uint16, InventorySoundOverride> _inventorySoundOverrides;
285 
286  Misc::Lightning *_lightning;
287  Common::Queue<Misc::SpecialEffect> _specialEffects;
288 
290 
291  Action::ActionManager _actionManager;
292  Action::PlaySecondaryMovie *_activeMovie;
293  Action::ConversationSound *_activeConversation;
294 
295  // Contains a screenshot of the Scene state from the last time it was exited
296  Graphics::ManagedSurface _lastScreenshot;
297 
298  RenderObject _hotspotDebug;
299 
300  bool _destroyOnExit;
301  bool _isRunningAd;
302 
303  State _state;
304 };
305 
306 #define NancySceneState Nancy::State::Scene::instance()
307 
308 } // End of namespace State
309 } // End of namespace Nancy
310 
311 #endif // NANCY_STATE_SCENE_H
Definition: managed_surface.h:51
Definition: nancy.h:74
Definition: str.h:59
Definition: viewport.h:41
Definition: time.h:30
Definition: commontypes.h:151
Definition: puzzledata.h:36
Definition: inventorybox.h:42
Definition: rect.h:144
Definition: path.h:52
Definition: textbox.h:38
Definition: stream.h:745
Definition: secondarymovie.h:44
Definition: conversation.h:42
Definition: queue.h:42
Definition: serializer.h:79
Definition: actionmanager.h:48
Definition: soundequalizerpuzzle.h:27
Definition: renderobject.h:36
Definition: scene.h:79
Definition: ornaments.h:30
Definition: lightning.h:32
Definition: clock.h:37
Definition: actionrecord.h:97
Definition: button.h:33
Definition: algorithm.h:29
Definition: commontypes.h:254
Definition: ornaments.h:38
Definition: fullscreenimage.h:30
Definition: ornaments.h:46
Definition: scene.h:72
Definition: console.h:36
Definition: input.h:69
Definition: commontypes.h:166
Definition: actionmanager.h:32
Definition: singleton.h:42