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 HOLLYWOOD_RUNAWAY_SCENE_H
23#define HOLLYWOOD_RUNAWAY_SCENE_H
24
25#include "hollywood/hotspots.h"
26#include "hollywood/resource.h"
27#include "hollywood/runaway/animation.h"
28#include "hollywood/runaway/audio.h"
29#include "hollywood/runaway/graphics.h"
30#include "hollywood/runaway/inventory.h"
31#include "hollywood/runaway/navigation.h"
32#include "hollywood/runaway/presentation.h"
33#include "hollywood/runaway/saveload.h"
34#include "hollywood/runaway/scene_data.h"
35#include "hollywood/runaway/sequence.h"
36#include "hollywood/runaway/speech.h"
37#include "hollywood/scene_text_store.h"
38
39namespace Hollywood {
40
42public:
43 struct Transition {
44 uint16 scene = 0; // Preserve entry substates, e.g. 2020..2023, until dispatch.
45 Common::Point position;
46 byte facing = 3;
47 bool door = false;
48 };
49 virtual ~RunawayScene() {}
50 virtual bool load(uint16 entryScene) = 0;
51 virtual void start(uint32 now) = 0;
52 virtual void resume() = 0;
53 const Transition &transition() const { return _transition; }
54 virtual void click(Common::Point mouse, RunawayVerb verb, byte item) = 0;
55 virtual void update(uint32 now, int scrollDirection, bool inventoryOpen) = 0;
56 virtual void draw() = 0;
57 virtual void setCameraX(int x) = 0;
58 virtual int cameraX() const { return 0; }
59 virtual int roomWidth() const = 0;
60 virtual Graphics::ManagedSurface &screen() = 0;
61 byte hotspotAt(Common::Point mouse) const override = 0;
62 virtual bool hasVerbControls() const { return true; }
63 // Cursor tile 3 is talk, 4..7 are exit arrows; zero keeps the usual verbs.
64 virtual byte actionCursor(byte hotspot) const { return 0; }
65 virtual bool preferLook(byte hotspot) const { return false; }
66 virtual Common::U32String actionCaption(byte hotspot, RunawayVerb verb, byte item) const = 0;
67 virtual const Common::U32String &committedCaption() const = 0;
68 virtual const Common::U32String &subtitle() const = 0;
69 virtual bool busy() const = 0;
70 virtual bool speaking() const = 0;
71 virtual byte speechFrame() const { return 0; }
72 virtual void skipSpeech() = 0;
73 virtual const Common::Array<Common::U32String> &dialogueChoices() const { return _noChoices; }
74 virtual void chooseDialogue(uint choice) {}
75 virtual bool playingVideo() const { return false; }
76 virtual bool inventoryPresentation() const { return false; }
77 virtual void skipVideo() {}
78 virtual void sayInventory(const RunawayInventory::Reply &reply) = 0;
79 virtual bool escaped() const { return false; }
80 virtual bool canSave() const { return false; }
81 virtual void captureState(RunawaySaveState &state) const {}
82 // Prepare a replacement scene without changing shared inventory or audio.
83 virtual bool restoreState(const RunawaySaveState &state, uint32 now, bool entering = false) { return false; }
84 virtual void setOptions(bool antialias, bool fastScrolling) = 0;
85
86protected:
87 Common::U32String hotspotName(byte id) const override { return Common::U32String(); }
88 void skipPresentation(uint32 now) override final { skipVideo(); }
89 void skipPresentationSpeech(uint32 now) override final { skipSpeech(); }
90
92 uint16 _entryScene = 0;
93 Transition _transition;
94};
95
96class RunawayStrings;
97struct RunawayHotspot;
98
99// Shared walking, rendering and interaction for the numbered rooms.
101public:
102 RunawayRoomScene(RunawayAudio &audio, RunawayInventory &inventory, const RunawayStrings &strings, RunawayGameType game);
103 bool load(uint16 entryScene) override;
104 void start(uint32 now) override;
105 void resume() override;
106 void click(Common::Point mouse, RunawayVerb verb, byte item) override;
107 void update(uint32 now, int scrollDirection, bool inventoryOpen) override;
108 void draw() override;
109 void setCameraX(int x) override;
110 int cameraX() const override { return _camera.x; }
111 int roomWidth() const override { return _background.w; }
112 Graphics::ManagedSurface &screen() override { return _screen; }
113 byte hotspotAt(Common::Point mouse) const override;
114 byte actionCursor(byte id) const override;
115 bool preferLook(byte id) const override;
116 Common::U32String actionCaption(byte hotspot, RunawayVerb verb, byte item) const override;
117 const Common::U32String &committedCaption() const override { return _caption; }
118 const Common::U32String &subtitle() const override;
119 bool busy() const override { return _sequence.active() || _pendingHotspot != 0 || _transition.scene || _hospitalExit.scene || _arrivalFacing != 0xff || _roomAction || _conversation || speaking(); }
120 bool speaking() const override { return _sequence.active() ? !_sequence.subtitle().empty() : !_speech.subtitle().empty(); }
121 byte speechFrame() const override { return _sequence.active() ? _sequence.speechFrame() : _speech.frame(_now); }
122 bool playingVideo() const override { return _sequence.active(); }
123 void skipVideo() override { _sequence.skip(); }
124 bool escaped() const override { return _chapterComplete; }
125 void skipSpeech() override;
126 void sayInventory(const RunawayInventory::Reply &reply) override;
127 const Common::Array<Common::U32String> &dialogueChoices() const override { return _choices; }
128 void chooseDialogue(uint choice) override;
129 // The hangar contest's animation progress is transient, like a room action.
130 bool canSave() const override { return !busy() && !_walkPath.active() && _desert.guard != 1; }
131 void captureState(RunawaySaveState &state) const override;
132 bool restoreState(const RunawaySaveState &state, uint32 now, bool entering = false) override;
133 void setOptions(bool antialias, bool fastScrolling) override { _antialias = antialias; _fastScrolling = fastScrolling; }
134
135protected:
136 enum ObjectState { kUnexamined, kIdentified, kTaken };
137 enum ActionResult { kUnhandled, kHandled, kBackgroundChanged };
139 constexpr AnimationFootstep(byte frameNumber, int16 position, byte loudness = 255) :
140 frame(frameNumber), x(position), volume(loudness) {}
141 byte frame;
142 int16 x;
143 byte volume;
144 };
145
146 virtual bool loadCustomResources() { return true; }
147 virtual bool loadBackground();
148 virtual bool applyCustomBackgroundPatches() { return true; }
149 virtual void applyCustomHotspotState() {}
150 virtual void prepareCustomGameplayLoop() {}
151 virtual void runCustomEntrySequence() {}
152 virtual void advanceCustomGameplayLoop(uint32 delta) {}
153 virtual void drawCustomBackgroundComposite(Graphics::ManagedSurface &viewport) {}
154 virtual void drawCustomForegroundComposite(Graphics::ManagedSurface &viewport) {}
155 virtual ActionResult dispatchCustomSceneAction(uint16 action) { return kUnhandled; }
156 virtual byte defaultItemAction(byte item, byte hotspot) const { return 1; }
157 // Return true when the scene handles the reply after Brian's dialogue choice.
158 virtual bool handleCustomDialogueReply() { return false; }
159 virtual void handleCustomDialogueChoice(byte effect) {}
160 virtual void runCustomDialogueIntro() {}
161 virtual void finishCustomConversation() {}
162 virtual void resumeAmbientAudio(bool entering);
163 virtual void stopAmbientSpeech() {}
164 virtual void runExitSideEffectsAfterLoop() {}
165 virtual void updateActor(uint elapsed, int scrollDirection, bool inventoryOpen);
166 virtual void findWalkPath(Common::Point target);
167 virtual int sceneViewportYOffset() const;
168
169 virtual uint sceneResourceNumber() const { return (_room % 1000) / 10; }
170 virtual uint sceneTextNumber() const { return finaleChapter() ? (_room - 2000) / 10 : _room / 10; }
171 virtual bool loadWalkMap();
172 virtual bool usesAlternateActor() const { return true; }
173 virtual byte initialActorFacing() const { return 3; }
174 virtual void setupActorDepth(RunawayActor::RenderParams &params) const {}
175 virtual bool drawCustomComposite(Graphics::ManagedSurface &viewport) { return false; }
176 virtual bool shouldDrawActor() const { return true; }
177 virtual bool roomAnimationInForeground() const { return false; }
178 virtual bool shouldUpdateActor() const { return true; }
179 virtual bool shouldPlayGameplayClickPath() const { return true; }
180 virtual int8 customizeSceneActionApproach(byte id, bool use, byte item, int8 approach) const { return approach; }
181 // Accept the adjusted target without the shared floor-mask adjustment.
182 virtual bool adjustCustomWalkTargetToFloorMask(Common::Point &target) const { return false; }
183 // Return true when a scene sequence owns this frame's action updates.
184 virtual bool updateCustomSequence() { return false; }
185 virtual void finishCustomAnimation(uint16 action) {}
186 virtual void handleAnimationFrameHook() {}
187 virtual void finishCustomFilm() {}
188 virtual uint16 dialoguePlayerCue() const { return 80; }
189 virtual uint16 dialogueResponseCue() const { return 90; }
190 virtual uint16 dialogueCue(byte choice, bool response) const { return response ? dialogueResponseCue() : dialoguePlayerCue(); }
191
192 bool enterRoom(uint16 room, Common::Point position, byte facing);
193 bool loadForeground(uint layer, uint chunk, bool pixels = false);
194 void drawForeground(Graphics::ManagedSurface &viewport, uint layer);
195 void drawRoomAnimation(Graphics::ManagedSurface &viewport);
196 void drawAmbientAnimations(Graphics::ManagedSurface &viewport, const RunawayAnimation *animations, uint count);
197 bool rebuildBackground();
198 bool applyPatch(uint chunk);
199 void updateMaps();
200 void walkTo(Common::Point target, byte facing = 0xff, bool scripted = false, bool reserved = false);
201 void arrive();
202 void execute(uint16 action);
203 void executeItemAction(uint16 action);
204 void useItem(byte item, byte hotspot);
205 void say(uint16 cue, byte variation = 0, bool global = false, byte speaker = 0);
206 void showLine();
207 void changeFloor(bool upper, Common::Point position);
208 void updateCamera();
209 void beginRoomAnimation(uint16 action, uint chunk, uint frames, const byte *order = nullptr, uint count = 0, bool hideActor = true, uint frameDuration = 80);
210 void beginActorAnimation(uint16 action, uint bank, uint frames, uint count = 0, uint frameDuration = 60);
211 void beginAnimation(uint16 action, uint frames, const byte *order, uint count, bool hideActor, uint frameDuration);
212 void beginRoomAnimationRange(uint16 action, uint chunk, uint frames, uint first, uint last, bool hideActor = true, uint frameDuration = 80);
213 void holdRoomAnimation(uint16 action, uint chunk, uint frames, uint frame, bool hideActor = true);
214 void loopRoomAnimationDuringSpeech(uint16 action, uint chunk, uint frames, uint first, uint last, bool hideActor = true);
215 void setRoomAnimationOverlay(uint chunk, uint frames, const byte *order, uint count);
216 bool drawingRoomAnimation() const { return !_actionUsesActor && _roomAction && !_actionFrames.empty() && (_actionHoldSpeech || !speaking()) && !_walkPath.active(); }
217 void updateRoomAnimation();
218 void playAnimationFootsteps(uint frame, byte surface, const AnimationFootstep *steps, uint count);
219 virtual float actorHeight() const { return 455; }
220 virtual float actorWalkSpeed() const { return 0.18f * actorHeight() / 455; }
221 virtual const RunawayHotspot *hotspot(byte id) const;
222 Common::U32String hotspotName(byte id) const override;
223 virtual const char *actionCaptionVariant(byte id, bool look, byte item) const { return nullptr; }
224 virtual bool isValidHotspot(byte id) const { return hotspot(id) != nullptr; }
225 virtual Common::Point customizeSceneActionPosition(byte id, byte item, Common::Point position) const { return position; }
226 virtual byte customizeSceneActionFacing(byte id, byte facing) const { return facing; }
227 virtual Common::Point sceneActionLookPosition(byte id) const { return hotspot(id)->lookPosition; }
228
229 byte walkZone() const { return _originalMaps[_mask[_position.y * _background.w + _position.x]]; }
230
231 bool hospitalChapter() const { return _game == kRunawayFullGame && _room / 1000 == 2; }
232 void resumeHospital();
233 void updateHospital(uint elapsed);
234 void updateHospitalAudio();
235 bool sayHospitalInventory(const RunawayInventory::Reply &reply);
236 void leaveHospitalRoom(uint16 scene, Common::Point position, byte facing);
237
238 bool museumChapter() const { return _game == kRunawayFullGame && _room / 1000 == 4; }
239 void startMuseum();
240 void resumeMuseum();
241 void updateMuseum(uint elapsed);
242 bool sayMuseumInventory(const RunawayInventory::Reply &reply);
243 void deferMuseumAction(uint16 action);
244 void refreshMuseum();
245 void leaveMuseumRoom(uint16 scene, Common::Point position, byte facing = 3, bool door = false);
246 enum MuseumFilm { kArrivalFilm, kCliveFilm, kDrillingFilm, kLaserFilm, kRubyFilm,
247 kMobstersFilm, kPhoneFilm, kScannerFilm, kBetrayalFilm, kMuseumExitFilm };
248 void startMuseumFilm(MuseumFilm film);
249 void startConversation(byte character);
250 void updateConversation();
251 void buildDialogueChoices();
252 void finishConversation();
253 byte speaker() const { return speaking() && _lineIndex < _lines.size() ? _lines[_lineIndex].speaker : 0; }
254
255 bool desertChapter() const { return _game == kRunawayFullGame && _room / 1000 == 5; }
256 void startDesert();
257 void resumeDesert();
258 void updateDesert(uint elapsed);
259 void visitDesertRoom(byte index, byte lines);
260 void leaveDesertRoom(uint16 scene);
261 void deferDesertAction(uint16 action);
262
263 bool townChapter() const { return _game == kRunawayFullGame && _room / 1000 == 6; }
264 void resumeTown();
265 bool sayTownInventory(const RunawayInventory::Reply &reply);
266 void leaveTownRoom(uint16 scene);
267 void deferTownAction(uint16 action);
268 void walkTown(Common::Point target);
269
270 bool hopiChapter() const { return _game == kRunawayFullGame && _room / 1000 == 7; }
271 bool sayHopiInventory(const RunawayInventory::Reply &reply);
272 bool finaleChapter() const { return _game == kRunawayFullGame && _room / 1000 == 8; }
273 bool sayFinaleInventory(const RunawayInventory::Reply &reply);
274 void resumeFinaleOutdoorAudio(bool entering, uint16 windCue, byte windVolume);
275 void updateFinaleOutdoorAudio(byte wildlifeVolume = 0);
276 void resumeFinaleJailAudio(bool entering);
277 void updateFinaleJailAudio();
278 void updateOutdoorMusic(byte cueCount = 3);
279 void updateGameplay(uint32 delta);
280 void findGameplayWalkPath(Common::Point target);
281 void deferAction(uint16 action);
282 void leaveRoom(uint16 scene);
283
284 RunawayAudio &_audio;
285 RunawaySequence _sequence;
286 bool _inventorySequence = false;
287 RunawayInventory &_inventory;
288 const RunawayStrings &_strings;
289 const RunawayGameType _game;
290 Common::RandomSource _random;
291 RunawaySpeech _speech;
292 RunawayIdleHead _idleHead;
293 ChunkArchive _archive;
294 SceneTextStore _text;
295 RunawayActor _actor;
296 RunawayAnimation _actionAnimation, _secondaryAnimation;
297 Common::Array<byte> _actionFrames, _secondaryFrames;
298 Graphics::ManagedSurface _background, _screen;
299 Common::Array<byte> _mask, _originalMaps, _maps;
300 Common::Array<Common::Rect> _foreground[5];
301 RunawayWalkPath _walkPath;
302 struct SpeechLine {
304 uint16 sample;
305 bool global;
306 byte speaker;
307 };
309 Common::U32String _caption;
310 Common::Point _position, _camera;
311 uint _lineIndex = 0;
312 const RunawayRoom *_roomData = nullptr;
313 uint16 _room = 0, _pendingAction = 0;
314 byte _facing = 3, _pendingHotspot = 0, _pendingItem = 0;
315 byte _arrivalFacing = 0xff;
316 uint32 _now = 0, _lastUpdate = 0, _walkElapsed = 0;
317 bool _upperFloor = true, _antialias = true, _fastScrolling = true;
318 bool _inventoryOpen = false;
319 ObjectState _books = kUnexamined, _recorder = kUnexamined;
320 bool _moneyIdentified = false, _safeOpen = false;
321 bool _varnishTaken = false, _talcTaken = false, _coffeeTaken = false;
322 byte _keyCount = 0;
323 uint32 _lastFootstep = 0;
330 MuseumFilm _museumFilm = kArrivalFilm;
331 SceneTextStore _filmText;
334 byte enabled, node, transition, player, response, disable, selectable;
335 };
336 DialogueChoice _dialogue[22][8] = {};
338 Common::Array<byte> _choiceIndices;
339 byte _conversation = 0, _dialogueDepth = 0, _dialogueNode = 0, _dialogueIntro = 0;
340 bool _dialogueEnding = false;
341 uint16 _afterConversation = 0;
342 byte _musicCue = 11;
343 uint32 _nextMusic = 0;
344 uint32 _finaleAmbientTick = 0;
345 byte _finaleLastAmbient = 0;
346 bool _entering = false;
347 uint16 _roomAction = 0;
348 bool _actionHidesActor = true;
349 bool _actionUsesActor = false;
350 bool _actionHoldSpeech = false;
351 bool _actionLoopSpeech = false;
352 byte _actionStage = 0;
353 uint _actionStep = 0;
354 uint _actionFrameDuration = 80;
355 uint32 _actionStarted = 0;
356 Transition _hospitalExit;
357 bool _chapterComplete = false;
358};
359
360} // End of namespace Hollywood
361
362#endif // HOLLYWOOD_RUNAWAY_SCENE_H
bool empty() const
Definition: array.h:352
Definition: random.h:44
Definition: ustr.h:57
Definition: managed_surface.h:51
int16 & w
Definition: managed_surface.h:134
Definition: hotspots.h:36
Definition: audio.h:29
Definition: inventory.h:41
Definition: presentation.h:42
Definition: scene.h:100
Definition: scene.h:41
Definition: strings.h:37
Definition: scene_text_store.h:64
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: inventory.h:44
Definition: scene_data.h:78
Definition: saveload.h:62
Definition: saveload.h:143
Definition: saveload.h:129
Definition: saveload.h:33
Definition: saveload.h:40
Definition: saveload.h:88
Definition: saveload.h:32