ScummVM API documentation
neighborhood.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  * Additional copyright for this file:
8  * Copyright (C) 1995-1997 Presto Studios, Inc.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #ifndef PEGASUS_NEIGHBORHOOD_H
26 #define PEGASUS_NEIGHBORHOOD_H
27 
28 #include "common/queue.h"
29 #include "common/str.h"
30 
31 #include "pegasus/fader.h"
32 #include "pegasus/hotspot.h"
33 #include "pegasus/input.h"
34 #include "pegasus/movie.h"
35 #include "pegasus/notification.h"
36 #include "pegasus/sound.h"
37 #include "pegasus/timers.h"
38 #include "pegasus/transition.h"
39 #include "pegasus/util.h"
40 #include "pegasus/neighborhood/door.h"
41 #include "pegasus/neighborhood/exit.h"
42 #include "pegasus/neighborhood/extra.h"
43 #include "pegasus/neighborhood/hotspotinfo.h"
44 #include "pegasus/neighborhood/spot.h"
45 #include "pegasus/neighborhood/turn.h"
46 #include "pegasus/neighborhood/view.h"
47 #include "pegasus/neighborhood/zoom.h"
48 
49 namespace Pegasus {
50 
51 class PegasusEngine;
52 
53 // Pegasus Prime neighborhood id's
54 static const NeighborhoodID kCaldoriaID = 0;
55 static const NeighborhoodID kFullTSAID = 1;
56 static const NeighborhoodID kFinalTSAID = 2;
57 static const NeighborhoodID kTinyTSAID = 3;
58 static const NeighborhoodID kPrehistoricID = 4;
59 static const NeighborhoodID kMarsID = 5;
60 static const NeighborhoodID kWSCID = 6;
61 static const NeighborhoodID kNoradAlphaID = 7;
62 static const NeighborhoodID kNoradDeltaID = 8;
63 // The sub chase is not really a neighborhood, but we define a constant that is used
64 // to allow an easy transition out of Norad Alpha.
65 static const NeighborhoodID kNoradSubChaseID = 1000;
66 
67 static const TimeScale kDefaultLoopFadeScale = kThirtyTicksPerSecond;
68 static const TimeValue kDefaultLoopFadeOut = kHalfSecondPerThirtyTicks;
69 static const TimeValue kDefaultLoopFadeIn = kHalfSecondPerThirtyTicks;
70 
71 enum QueueRequestType {
72  kNavExtraRequest,
73  kSpotSoundRequest,
74  kDelayRequest
75 };
76 
77 // For delay requests, start is interpreted as the total delay and stop is interpreted
78 // as the scale the delay is in.
79 // For extra requests, start and stop are not used.
80 struct QueueRequest {
81  QueueRequestType requestType;
82  ExtraID extra;
83  TimeValue start, stop;
84  InputBits interruptionFilter;
85  bool playing;
86  NotificationFlags flags;
87  Notification *notification;
88 };
89 
90 bool operator==(const QueueRequest &arg1, const QueueRequest &arg2);
91 bool operator!=(const QueueRequest &arg1, const QueueRequest &arg2);
92 
93 class CaldoriaBomb;
94 class GameInteraction;
95 class Item;
96 class Neighborhood;
97 
99 public:
101  ~StriderCallBack() override {}
102 
103 protected:
104  void callBack() override;
105 
106  Neighborhood *_neighborhood;
107 };
108 
110 
111 class Neighborhood : public IDObject, public NotificationReceiver, public InputHandler, public Idler {
112 friend class CaldoriaBomb;
113 friend class StriderCallBack;
114 
115 public:
116  Neighborhood(InputHandler *nextHandler, PegasusEngine *vm, const Common::String &resName, NeighborhoodID id);
117  ~Neighborhood() override;
118 
119  virtual void init();
120  virtual void start();
121  virtual void moveNavTo(const CoordType, const CoordType);
122  virtual void checkContinuePoint(const RoomID, const DirectionConstant) = 0;
123  void makeContinuePoint();
124 
125  void activateHotspots() override;
126  void clickInHotspot(const Input &, const Hotspot *) override;
127 
128  virtual CanMoveForwardReason canMoveForward(ExitTable::Entry &entry);
129  virtual CanTurnReason canTurn(TurnDirection turn, DirectionConstant &nextDir);
130  virtual CanOpenDoorReason canOpenDoor(DoorTable::Entry &entry);
131 
132  virtual void cantMoveThatWay(CanMoveForwardReason);
133  virtual void cantTurnThatWay(CanTurnReason) {}
134  virtual void cantOpenDoor(CanOpenDoorReason);
135  virtual void arriveAt(const RoomID room, const DirectionConstant direction);
136  virtual void turnTo(const DirectionConstant);
137  virtual void spotCompleted();
138  virtual void doorOpened();
139  virtual void closeDoorOffScreen(const RoomID, const DirectionConstant) {}
140 
141  virtual void moveForward();
142  virtual void turn(const TurnDirection);
143  virtual void turnLeft();
144  virtual void turnRight();
145  virtual void turnUp();
146  virtual void turnDown();
147  virtual void openDoor();
148  virtual void zoomTo(const Hotspot *);
149 
150  virtual void updateViewFrame();
151 
152  void requestExtraSequence(const ExtraID, const NotificationFlags, const InputBits interruptionFilter);
153  void requestSpotSound(const TimeValue, const TimeValue, const InputBits interruptionFilter, const NotificationFlags);
154  void playSpotSoundSync(const TimeValue in, const TimeValue out);
155  void requestDelay(const TimeValue, const TimeScale, const InputBits interruptionFilter, const NotificationFlags);
156 
157  Notification *getNeighborhoodNotification() { return &_neighborhoodNotification; }
158 
159  virtual void getExtraEntry(const uint32 id, ExtraTable::Entry &extraEntry);
160  virtual void startSpotLoop(TimeValue, TimeValue, NotificationFlags = 0);
161  virtual bool actionQueueEmpty() { return _actionQueue.empty(); }
162  virtual void showViewFrame(TimeValue);
163  virtual void findSpotEntry(const RoomID room, const DirectionConstant direction, SpotFlags flags, SpotTable::Entry &spotEntry);
164  virtual void startExtraSequence(const ExtraID, const NotificationFlags, const InputBits interruptionFilter);
165  bool startExtraSequenceSync(const ExtraID, const InputBits);
166  virtual void loopExtraSequence(const uint32, NotificationFlags = 0);
167  int32 getLastExtra() const { return _lastExtra; }
168  virtual void scheduleNavCallBack(NotificationFlags);
169 
170  Movie *getNavMovie() { return &_navMovie; }
171  bool navMoviePlaying();
172 
173  void setCurrentAlternate(const AlternateID alt) { _currentAlternate = alt; }
174  AlternateID getCurrentAlternate() const { return _currentAlternate; }
175 
176  void setCurrentActivation(const HotSpotActivationID a) { _currentActivation = a; }
177  HotSpotActivationID getCurrentActivation() { return _currentActivation; }
178 
179  virtual void playDeathExtra(ExtraID, DeathReason);
180  virtual void die(const DeathReason);
181 
182  virtual void setSoundFXLevel(const uint16);
183  virtual void setAmbienceLevel(const uint16);
184 
185  void forceStridingStop(const RoomID, const DirectionConstant, const AlternateID);
186  void restoreStriding(const RoomID, const DirectionConstant, const AlternateID);
187 
188  HotspotInfoTable::Entry *findHotspotEntry(const HotSpotID);
189 
190  Push *getTurnPush() { return &_turnPush; }
191  Picture *getTurnPushPicture() { return &_pushIn; }
192 
193  void hideNav();
194  void showNav();
195 
196  virtual void loadAmbientLoops() {}
197 
198  virtual void flushGameState() {}
199 
200  virtual Common::Path getBriefingMovie();
201  virtual Common::Path getEnvScanMovie();
202  virtual uint getNumHints();
203  virtual Common::Path getHintMovie(uint);
204  virtual bool canSolve();
205  virtual void prepareForAIHint(const Common::Path &) {}
206  virtual void cleanUpAfterAIHint(const Common::Path &) {}
207  virtual void doSolve();
208 
209  virtual bool okayToJump();
210 
211  virtual AirQuality getAirQuality(const RoomID);
212  virtual void checkAirMask() {}
213  virtual void checkFlashlight() {}
214  virtual void shieldOn() {}
215  virtual void shieldOff() {}
216 
217  virtual void loadLoopSound1(const Common::Path &, const uint16 volume = 0x100,
218  const TimeValue fadeOut = kDefaultLoopFadeOut, const TimeValue fadeIn = kDefaultLoopFadeIn,
219  const TimeScale fadeScale = kDefaultLoopFadeScale);
220  virtual void loadLoopSound2(const Common::Path &, const uint16 volume = 0x100,
221  const TimeValue fadeOut = kDefaultLoopFadeOut, const TimeValue fadeIn = kDefaultLoopFadeIn,
222  const TimeScale fadeScale = kDefaultLoopFadeScale);
223  bool loop1Loaded(const Common::Path &soundName) { return _loop1SoundString == soundName; }
224  bool loop2Loaded(const Common::Path &soundName) { return _loop2SoundString == soundName; }
225  void startLoop1Fader(const FaderMoveSpec &);
226  void startLoop2Fader(const FaderMoveSpec &);
227 
228  virtual void takeItemFromRoom(Item *);
229  virtual void dropItemIntoRoom(Item *, Hotspot *);
230  virtual Hotspot *getItemScreenSpot(Item *, DisplayElement *) { return 0; }
231 
232  virtual GameInteraction *makeInteraction(const InteractionID);
233  virtual void requestDeleteCurrentInteraction() { _doneWithInteraction = true; }
234 
235  virtual uint16 getDateResID() const = 0;
236 
237  virtual void showExtraView(uint32);
238  virtual void startExtraLongSequence(const uint32, const uint32, NotificationFlags, const InputBits interruptionFilter);
239 
240  void openCroppedMovie(const Common::Path &, CoordType, CoordType);
241  void loopCroppedMovie(const Common::Path &, CoordType, CoordType);
242  void closeCroppedMovie();
243  void playCroppedMovieOnce(const Common::Path &, CoordType, CoordType, const InputBits interruptionFilter = kFilterNoInput);
244 
245  void playMovieSegment(Movie *, TimeValue = 0, TimeValue = 0xffffffff);
246 
247  virtual void recallToTSASuccess();
248  virtual void recallToTSAFailure();
249 
250  virtual void pickedUpItem(Item *) {}
251 
252  void handleInput(const Input &, const Hotspot *) override;
253 protected:
254  PegasusEngine *_vm;
255  Common::String _resName;
256 
257  virtual Common::Path getSoundSpotsName() = 0;
258  virtual Common::Path getNavMovieName() = 0;
259 
260  // Notification function.
261  void receiveNotification(Notification *, const NotificationFlags) override;
262 
263  // Map info functions.
264  virtual void getExitEntry(const RoomID room, const DirectionConstant direction, ExitTable::Entry &entry);
265  virtual TimeValue getViewTime(const RoomID room, const DirectionConstant direction);
266  virtual void getDoorEntry(const RoomID room, const DirectionConstant direction, DoorTable::Entry &doorEntry);
267  virtual DirectionConstant getTurnEntry(const RoomID room, const DirectionConstant direction, const TurnDirection turn);
268  virtual void getZoomEntry(const HotSpotID id, ZoomTable::Entry &zoomEntry);
269  virtual void getHotspotEntry(const HotSpotID id, HotspotInfoTable::Entry &hotspotEntry);
270 
271  // Nav movie sequences.
272  virtual void startExitMovie(const ExitTable::Entry &);
273  virtual void keepStriding(ExitTable::Entry &);
274  virtual void stopStriding();
275  virtual void checkStriding();
276  virtual bool stillMoveForward();
277  virtual void scheduleStridingCallBack(const TimeValue, NotificationFlags flags);
278  virtual void startZoomMovie(const ZoomTable::Entry &);
279  virtual void startDoorOpenMovie(const TimeValue, const TimeValue);
280  virtual void startTurnPush(const TurnDirection, const TimeValue, const DirectionConstant);
281  virtual void playExtraMovie(const ExtraTable::Entry &, const NotificationFlags, const InputBits interruptionFilter);
282 
283  virtual void activateCurrentView(const RoomID, const DirectionConstant, SpotFlags);
284 
285  virtual void activateOneHotspot(HotspotInfoTable::Entry &, Hotspot *);
286 
287  virtual void startSpotOnceOnly(TimeValue, TimeValue);
288 
289  virtual void startMovieSequence(const TimeValue, const TimeValue, NotificationFlags,
290  bool loopSequence, const InputBits interruptionFilter, const TimeValue strideStop = 0xffffffff);
291 
292  virtual void createNeighborhoodSpots();
293 
294  void resetLastExtra() { _lastExtra = 0xffffffff; }
295 
296  virtual void throwAwayInterface();
297 
298  // Action queue stuff
299  void popActionQueue();
300  void serviceActionQueue();
301  void requestAction(const QueueRequestType, const ExtraID, const TimeValue, const TimeValue, const InputBits, const NotificationFlags);
302 
303  virtual bool prepareExtraSync(const ExtraID);
304  virtual bool waitMovieFinish(Movie *, const InputBits);
305 
306  InputBits getInputFilter() override;
307 
308  // Misc.
309  virtual int16 getStaticCompassAngle(const RoomID, const DirectionConstant dir);
310  virtual void getExitCompassMove(const ExitTable::Entry &, FaderMoveSpec &);
311  virtual void getZoomCompassMove(const ZoomTable::Entry &, FaderMoveSpec&);
312  virtual void getExtraCompassMove(const ExtraTable::Entry &, FaderMoveSpec&);
313 
314  virtual void setUpAIRules();
315  virtual void setHotspotFlags(const HotSpotID, const HotSpotFlags);
316  virtual void setIsItemTaken(const ItemID);
317 
318  virtual void upButton(const Input &);
319  virtual void leftButton(const Input &);
320  virtual void rightButton(const Input &);
321  virtual void downButton(const Input &);
322 
323  void initOnePicture(Picture *, const Common::Path &, DisplayOrder, CoordType, CoordType, bool);
324  void initOneMovie(Movie *, const Common::Path &, DisplayOrder, CoordType, CoordType, bool);
325 
326  void reinstateMonocleInterface();
327 
328  virtual void newInteraction(const InteractionID);
329  void useIdleTime() override;
330  virtual void bumpIntoWall();
331  virtual void zoomUpOrBump();
332 
333  void scheduleEvent(const TimeValue, const TimeScale, const uint32);
334  void cancelEvent();
335  virtual void timerExpired(const uint32) {}
336  bool isEventTimerRunning() { return _eventTimer.isFuseLit(); }
337  uint32 getTimerEvent() { return _timerEvent; }
338  void timerFunction();
339 
340  void pauseTimer();
341  void resumeTimer();
342  bool timerPaused();
343 
344  // Navigation Data
345  DoorTable _doorTable;
346  ExitTable _exitTable;
347  ExtraTable _extraTable;
348  HotspotInfoTable _hotspotInfoTable;
349  SpotTable _spotTable;
350  TurnTable _turnTable;
351  ViewTable _viewTable;
352  ZoomTable _zoomTable;
353  AlternateID _currentAlternate;
354  HotSpotActivationID _currentActivation;
355 
356  ExtraID _lastExtra;
357  DeathReason _extraDeathReason;
358 
359  // Graphics
360  Movie _navMovie;
361  Picture _pushIn;
362  Push _turnPush;
363 
364  // Callbacks
365  Notification _neighborhoodNotification;
366  NotificationCallBack _navMovieCallBack;
367  StriderCallBack _stridingCallBack;
368  NotificationCallBack _turnPushCallBack;
369  NotificationCallBack _spotSoundCallBack;
370  NotificationCallBack _delayCallBack;
371 
372  // Hotspots
373  HotspotList _neighborhoodHotspots;
374 
375  // Sounds
376  SoundTimeBase _spotSounds;
377 
378  // Action queue
379  NeighborhoodActionQueue _actionQueue;
380  TimeBase _delayTimer;
381 
382  // Interruptibility...
383  InputBits _interruptionFilter;
384 
385  // Nav hiding (for info support...)
386  bool _isRunning;
387 
388  GameInteraction *_currentInteraction;
389  bool _doneWithInteraction;
390  Movie _croppedMovie;
391 
392  Sound _soundLoop1;
393  Common::Path _loop1SoundString;
394  SoundFader _loop1Fader;
395 
396  Sound _soundLoop2;
397  Common::Path _loop2SoundString;
398  SoundFader _loop2Fader;
399 
400  // The event timer...
401  FuseFunction _eventTimer;
402  uint32 _timerEvent;
403 };
404 
405 extern Neighborhood *g_neighborhood;
406 
407 } // End of namespace Pegasus
408 
409 #endif
Definition: timers.h:37
Definition: sound.h:91
Definition: transition.h:96
Definition: neighborhood.h:111
Definition: str.h:59
Definition: door.h:60
Definition: movie.h:40
Definition: fader.h:35
Definition: caldoriabomb.h:119
Definition: timers.h:239
Definition: path.h:52
Definition: hotspot.h:85
Definition: timers.h:63
Definition: item.h:294
Definition: hotspotinfo.h:39
Definition: spot.h:66
Definition: input.h:322
Definition: neighborhood.h:80
Definition: timers.h:144
Definition: zoom.h:49
Definition: fader.h:109
Definition: util.h:38
Definition: exit.h:49
Definition: extra.h:39
Definition: door.h:50
Definition: zoom.h:39
Definition: notification.h:53
Definition: neighborhood.h:98
Definition: elements.h:43
Definition: interaction.h:37
Definition: timers.h:191
Definition: spot.h:56
Definition: hotspot.h:119
Definition: pegasus.h:70
Definition: view.h:39
Definition: hotspotinfo.h:49
Definition: exit.h:39
Definition: notification.h:83
Definition: turn.h:39
Definition: extra.h:49
Definition: sound.h:50
Definition: input.h:410
Definition: ai_action.h:33
Definition: surface.h:125