ScummVM API documentation
thunks.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 MADS_NEBULAR_ROOMS_THUNKS_H
23 #define MADS_NEBULAR_ROOMS_THUNKS_H
24 
25 #include "common/rect.h"
26 #include "mads/core/config.h"
27 #include "mads/core/game.h"
28 #include "mads/core/inter.h"
29 #include "mads/core/kernel.h"
30 #include "mads/core/mcga.h"
31 #include "mads/core/object.h"
32 #include "mads/core/player.h"
33 #include "mads/core/sprite.h"
34 #include "mads/core/text.h"
35 #include "mads/nebular/global.h"
36 
37 namespace MADS {
38 namespace RexNebular {
39 namespace Rooms {
40 
41 #define CURSOR_ARROW CURSOR_NORMAL
42 #define CURSOR_GO_DOWN CURSOR_DOWN
43 #define CURSOR_GO_UP CURSOR_UP
44 #define CURSOR_GO_LEFT CURSOR_LEFT
45 #define CURSOR_GO_RIGHT CURSOR_RIGHT
46 
47 enum EXTTYPE {
48  EXT_NONE = -1, EXT_SS = 1, EXT_AA = 2, EXT_DAT = 3, EXT_HH = 4,
49  EXT_ART = 5, EXT_INT = 6
50 };
51 
52 enum InputMode {
53  kInputBuildingSentences = INTER_BUILDING_SENTENCES,
54  kInputConversation = INTER_CONVERSATION,
55  kInputLimitedSentences = INTER_LIMITED_SENTENCES
56 };
57 
58 enum SequenceTrigger {
59  SEQUENCE_TRIGGER_EXPIRE = KERNEL_TRIGGER_EXPIRE, // Trigger when the sequence finishes
60  SEQUENCE_TRIGGER_LOOP = KERNEL_TRIGGER_LOOP, // Trigger when the sequence loops
61  SEQUENCE_TRIGGER_SPRITE = KERNEL_TRIGGER_SPRITE // Trigger when sequence reaches specific sprite
62 };
63 
64 enum TriggerMode {
65  SEQUENCE_TRIGGER_NONE = -1,
66  SEQUENCE_TRIGGER_PARSER = KERNEL_TRIGGER_PARSER, // Triggers parser
67  SEQUENCE_TRIGGER_DAEMON = KERNEL_TRIGGER_DAEMON, // Triggers step/daemon code
68  SEQUENCE_TRIGGER_PREPARE = KERNEL_TRIGGER_PREPARSE // Triggers preparser
69 };
70 
71 enum SpriteAnimType {
72  ANIMTYPE_NONE = 0,
73  ANIMTYPE_CYCLED = AA_LINEAR,
74  ANIMTYPE_PING_PONG = AA_PINGPONG,
75  ANIMTYPE_STAMP = AA_STAMP
76 };
77 
78 enum ScrCategory {
79  CAT_NONE = 0, CAT_COMMAND = 1, CAT_INV_LIST = 2, CAT_INV_VOCAB = 3,
80  CAT_HOTSPOT = 4, CAT_INV_ANIM = 5, CAT_TALK_ENTRY = 6, CAT_INV_SCROLLER = 7,
81  CAT_12 = 12
82 };
83 
84 enum ScreenTransition {
85  kTransitionNone = 0,
86  kTransitionFadeIn,
87  kTransitionFadeOutIn,
88  kTransitionBoxInBottomLeft,
89  kTransitionBoxInBottomRight,
90  kTransitionBoxInTopLeft,
91  kTransitionBoxInTopRight,
92  kTransitionPanLeftToRight,
93  kTransitionPanRightToLeft,
94  kTransitionCircleIn1,
95  kTransitionCircleIn2,
96  kTransitionCircleIn3,
97  kTransitionCircleIn4,
98  kVertTransition1,
99  kVertTransition2,
100  kVertTransition3,
101  kVertTransition4,
102  kVertTransition5,
103  kVertTransition6,
104  kVertTransition7,
105  kNullPaletteCopy
106 };
107 
108 enum StoryMode {
109  STORYMODE_NAUGHTY = NAUGHTY, STORYMODE_NICE = NICE
110 };
111 
112 // These original constants may be useful when cleaning up room logic
113 #ifdef old_animation
114 #define kernel_animation kernel_anim[0].anim
115 #define kernel_animation_cycled kernel_anim[0].cycled
116 #define kernel_repeat_animation kernel_anim[0].repeat
117 #define kernel_animation_sprite_loaded kernel_anim[0].sprite_loaded
118 #define kernel_animation_buffer_id kernel_anim[0].buffer_id
119 #define kernel_animation_buffer kernel_anim[0].buffer
120 #define kernel_animation_frame kernel_anim[0].frame
121 #define kernel_animation_image kernel_anim[0].image
122 #define kernel_animation_doomed kernel_anim[0].doomed
123 #define kernel_animation_trigger_code kernel_anim[0].trigger_code
124 #define kernel_animation_trigger_mode kernel_anim[0].trigger_mode
125 #define kernel_animation_trigger_words kernel_anim[0].trigger_words
126 #define kernel_animation_next_clock kernel_anim[0].next_clock
127 #endif
128 
129 struct Action {
130  struct ActiveAction {
131  int &_verbId = player2.words[0];
132  int &_objectNameId = player2.words[1];
133  int &_indirectObjectId = player2.words[2];
134  };
135  ActiveAction _activeAction;
136 
137  struct SavedFields {
138  int &_lookFlag = player.look_around;
139  int &_mainObjectSource = player.main_object_source;
140  };
141  SavedFields _savedFields;
142 
143  int &_mainObjectSource = player.main_object_source;
144  int &_lookFlag = player.look_around;
145  int &_inProgress = player.command_ready;
146  int &_commandSource = player.command_source;
147 };
148 extern Action _action;
149 
150 struct Globals {
151  int16 _spriteIndexes[30];
152  int16 _sequenceIndexes[30];
153 
154  int16 &operator[](int idx);
155 };
156 extern Globals _globals;
157 
158 struct Scene {
159  Scene *operator->() {
160  return this;
161  }
162  const Scene *operator->() const {
163  return this;
164  }
165 
166  struct Animation {
167  int16 _id;
168  int &_currentFrame;
169  int &_repeatFlag;
170  int *const _spriteListIndexes;
171  int &_oldFrameEntry;
172  uint16 &_frameEntriesCount;
173  Image *const _frameEntries;
174 
175  Animation(int anim_id);
176 
177  Animation *operator->() {
178  return this;
179  }
180  const Animation *operator->() const {
181  return this;
182  }
183 
184  bool operator!() const {
185  return kernel_anim[_id].anim == nullptr;
186  }
187  bool operator!=(std::nullptr_t) const {
188  return kernel_anim[_id].anim != nullptr;
189  }
190  bool operator==(std::nullptr_t) const {
191  return kernel_anim[_id].anim == nullptr;
192  }
193  explicit operator bool() const {
194  return kernel_anim[_id].anim != nullptr;
195  }
196 
197 
198  int getCurrentFrame() const;
199  void setNextFrameTimer(long time);
200  long getNextFrameTimer();
201  void setCurrentFrame(int frameNum);
202  void resetSpriteSetsCount();
203  };
204  struct Animations {
205  Animation operator[](int anim_id) {
206  return Animation(anim_id);
207  }
208  };
209  Animations _animation;
210 
211  struct CustomDest {
212  int &x = inter_point_x;
213  int &y = inter_point_y;
214  };
215  CustomDest _customDest;
216 
217  struct DynamicHotspot {
218  byte &_articleNumber;
219 
220  DynamicHotspot(int index);
221  };
222 
224  int add(int vocab_id, int verb_id, int auto_sequence, const Common::Rect &r);
225  void remove(int dyn_id);
226  int setPosition(int id, const Common::Point &pt, int facing);
227  int setCursor(int id, int cursor);
228 
229  DynamicHotspot operator[](int idx);
230  };
231  DynamicHotspots _dynamicHotspots;
232 
233  struct Hotspots {
234  void activate(int hotspot, int active);
235  };
236  Hotspots _hotspots;
237 
238  struct KernelMessages {
239  struct TalkFont {
240  TalkFont *operator->() {
241  return this;
242  }
243  const TalkFont *operator->() const {
244  return this;
245  }
246  TalkFont &operator=(FontPtr font);
247  int getWidth(const Common::String &message, int spacing) const;
248  };
249  TalkFont _talkFont;
250 
252  long &_frameTimer;
253 
254  KernelMessageProxy(KernelMessagePtr kmsg) : _frameTimer(kmsg->update_time) {
255  }
256  };
257  struct Entries {
258  KernelMessageProxy operator[](uint handle);
259  };
260  Entries _entries;
261 
262  int add(const Common::Point &pt, uint fontColor, uint8 flags, int endTrigger,
263  uint32 timeout, const char *msg);
264  int addQuote(int quoteId, int endTrigger, uint32 timeout);
265  void remove(int msgIndex);
266  void reset();
267  void setQuoted(int msgIndex, int numTicks, bool quoted);
268  void setSeqIndex(int msgIndex, int seqIndex);
269 
270  void initRandomMessages(int maxSimultaneousMessages,
271  const Common::Rect &bounds, int minYSpacing, int scrollRate,
272  int color, int duration, int quoteId, ...);
273  void randomServer();
274  int checkRandom();
275  bool generateRandom(int major, int minor);
276  };
277  KernelMessages _kernelMessages;
278 
279  struct PaletteCycles {
280  int size() const;
281 
282  };
283  PaletteCycles _paletteCycles;
284 
285  struct Rails {
286  int getNext() const;
287  void resetNext();
288  };
289  Rails _rails;
290 
291  struct SequenceProxy {
293  int &x;
294  int &y;
295  SequencePosition(int &sx, int &sy) : x(sx), y(sy) {}
296  };
297  SequencePosition _position;
298  byte &_doneFlag;
299 
300  SequenceProxy(SequencePtr seqPtr) : _position(seqPtr->x, seqPtr->y), _doneFlag(seqPtr->expired) {
301  }
302  };
303 
304  struct Sequences {
305  int16 addSpriteCycle(int series_id, int mirror, word ticks, word expire = 0,
306  word start_ticks = 0, int interval_ticks = 0); // ***WARNING***: Last 3 params reversed
307  int16 addReverseSpriteCycle(int series_id, int mirror, word ticks, word expire = 0,
308  word start_ticks = 0, int interval_ticks = 0); // ***WARNING***: Last 3 params reversed
309  int startPingPongCycle(int series_id, int mirror, word ticks, word expire = 0,
310  word start_ticks = 0, int interval_ticks = 0); // ***WARNING***: Last 3 params reversed
311 
312  void remove(int sequence_id);
313  SequenceProxy operator[](uint sequence_id);
314 
315  int16 addSubEntry(int sequence_id, int trigger_type, int trigger_sprite, int trigger_code);
316  void setDepth(int sequence_id, int depth);
317  void setScale(int sequence_id, int scale);
318  void setAnimRange(int sequence_id, int first, int last);
319  void addTimer(int ticks, int trigger_code);
320  void setMsgLayout(int sequence_id);
321  void setPosition(int sequence_id, const Common::Point &pt);
322  void setMotion(int sequence_id, int flags, int delta_x_times_100, int delta_y_times_100);
323  void updateTimeout(int new_sequence_id, int old_sequence_id); // ***WARNING***: params reversed
324  void scan();
325  int startCycle(int srcSpriteIdx, bool flipped, int cycleIndex);
326  void setDone(int sequence_id);
327  int findByTrigger(int trigger);
328  };
329  Sequences _sequences;
330 
331  struct Sprite {
332  struct CharInfo {
333  CharInfo *operator->() {
334  return this;
335  }
336  const CharInfo *operator->() const {
337  return this;
338  }
339 
340  int16 &_velocity;
341 
342  CharInfo(WalkerInfoPtr info) : _velocity(info->velocity) {
343  }
344  };
345  CharInfo _charInfo;
346 
347  Sprite(SeriesPtr series) : _charInfo(series->walker) {
348  }
349  Sprite *operator->() {
350  return this;
351  }
352  const Sprite *operator->() const {
353  return this;
354  }
355  };
356 
357  struct Sprites {
358  int16 addSprites(const char *name, int load_flags = 0);
359  void remove(int sprite_id);
360  Sprite operator[](int idx);
361  };
362  Sprites _sprites;
363 
364  struct SpriteSlots {
365  void clear();
366  void fullRefresh();
367  };
368  SpriteSlots _spriteSlots;
369 
370  struct UserInterface {
371  int &_selectedInvIndex = active_inven;
372  void emptyConversationList();
373  void setup(int inputMode);
374  void selectObject(int item_id);
375  };
376  UserInterface _userInterface;
377 
378  int16 &_priorSceneId = previous_room;
379  int16 &_nextSceneId = new_room;
380  long &_frameStartTime = kernel.clock;
381  byte &_reloadSceneFlag = kernel.force_restart;
382  byte &_roomChanged = kernel.teleported_in;
383  int &_currentSceneId = room_id;
384  int &_textSpacing = kernel_message_spacing;
385 
386  int loadAnimation(const char *name, int trigger_code = 0);
387  void freeAnimation();
388  void changeVariant(int num);
389  void drawElements(int transitionType, bool surfaceFlag);
390  void resetScene();
391  void clearSequenceList();
392  void addActiveVocab(int vocab_id);
393 };
394 extern Scene _scene;
395 
396 struct Game {
397  Game *operator->() {
398  return this;
399  }
400  const Game *operator->() const {
401  return this;
402  }
403 
404  Globals &_globals = Rooms::_globals;
405 
406  struct Object {
407  int _object_id;
408  int16 &_roomNumber;
409 
410  Object(int objectNum);
411  int getQuality(int quality_id);
412  void setQuality(int quality_id, long quality_value);
413  bool hasQuality(int quality_id);
414  };
415 
416  struct Objects {
417  struct InventoryList {
418  int size() const {
419  return inven_num_objects;
420  }
421  int &operator[](int index) {
422  return inven[index];
423  }
424  };
425  InventoryList _inventoryList;
426 
427  void addToInventory(int object_id);
428  bool isInRoom(int object_id) const;
429  bool isInInventory(int object_id) const;
430  int getIdFromDesc(int desc_id) const;
431  void setRoom(int object_id, int roomNum);
432  void removeFromInventory(int objectId, int newScene);
433  int size() const;
434 
435  Object operator[](int idx);
436  };
437  Objects _objects;
438 
439  struct Player {
440  struct PlayerPoint {
441  int &x = player.x;
442  int &y = player.y;
443 
444  PlayerPoint &operator=(const Common::Point &pt) {
445  x = pt.x;
446  y = pt.y;
447  return *this;
448  }
449  operator Common::Point() {
450  return Common::Point(x, y);
451  }
452 
453  bool operator==(const Common::Point &rhs) const {
454  return x == rhs.x && y == rhs.y;
455  }
456  bool operator!=(const Common::Point &rhs) const {
457  return x != rhs.x || y != rhs.y;
458  }
459  };
460  PlayerPoint _playerPos;
461 
462  struct PlayerPrepare {
463  int &x = player.prepare_walk_x;
464  int &y = player.prepare_walk_y;
465 
466  PlayerPrepare &operator=(const Common::Point &pt) {
467  x = pt.x;
468  y = pt.y;
469  return *this;
470  }
471  operator Common::Point() {
472  return Common::Point(x, y);
473  }
474 
475  bool operator==(const Common::Point &rhs) const {
476  return x == rhs.x && y == rhs.y;
477  }
478  };
479  PlayerPrepare _prepareWalkPos;
480 
481  struct TargetPos {
482  int &x = player.target_x;
483  int &y = player.target_y;
484 
485  TargetPos &operator=(const Common::Point &pt) {
486  x = pt.x;
487  y = pt.y;
488  return *this;
489  }
490  operator Common::Point() {
491  return Common::Point(x, y);
492  }
493 
494  bool operator==(const Common::Point &rhs) const {
495  return x == rhs.x && y == rhs.y;
496  }
497  };
498  TargetPos _targetPos;
499 
500  int &_facing = player.facing;
501  int &_prepareFacing = player.prepare_walk_facing;
502  bool &_visible = player.walker_visible;
503  bool &_stepEnabled = player.commands_allowed;
504  int &_turnToFacing = player.turn_to_facing;
505  char *const q = &player.series_name[0];
506  byte &_spritesChanged = player.walker_must_reload;
507  bool &_beenVisible = player.walker_been_visible;
508  byte &_loadsFirst = player.walker_loads_first;
509  int &_needToWalk = player.need_to_walk;
510  int &_readyToWalk = player.ready_to_walk;
511  int &_special = player.special_code;
512  long &_priorTimer = player.clock;
513  int &_ticksAmount = player.frame_delay;
514  char *const _spritesPrefix = &player.series_name[0];
515  int &_moving = player.walking;
516  int &_walkOffScreenSceneId = player.walk_off_edge_to_room;
517  int &_prepareWalkFacing = player.prepare_walk_facing;
518  int &_spritesStart = player.series_base;
519  int &_frameNumber = player.sprite;
520  int &_forceRefresh = player.sprite_changed;
521  int &_walkAnywhere = player.walk_anywhere;
522 
523  void startWalking(const Common::Point &pt, int facing);
524  void walk(const Common::Point &pt, int facing);
525  void cancelCommand();
526  void update();
527  void removePlayerSprites();
528  void selectSeries();
529  };
530  Player _player;
531 
532  Scene &_scene = Rooms::_scene;
533 
534  struct ScreenObjects {
535  int &_inputMode = inter_input_mode;
536  };
537  ScreenObjects _screenObjects;
538 
539  struct VisitedScenes {
540  byte &_sceneRevisited = player.been_here_before;
541 
542  void add(int roomNum);
543  bool exists(int roomNum) const;
544  void pop_back();
545  };
546  VisitedScenes _visitedScenes;
547 
548  int &_trigger = kernel.trigger;
549  int &_triggerSetupMode = kernel.trigger_setup_mode;
550  char *const _aaName = kernel.interface;
551  int8 &_difficulty = game.difficulty;
552  byte &_widepipeCtr = kernel.cheating;
553  int &_storyMode = config_file.naughtiness;
554  int &_winStatus = win_status;
555 
556  void loadQuoteSet(int quote1, ...);
557  char *getQuote(int quote_id);
558  void splitQuote(const char *source, char *line1, char *line2);
559 };
560 extern Game _game;
561 
562 struct Resources {
563  static char *formatName(int my_room, char type, int num, int ext, const char *text);
564  static char *formatAAName(int num);
565 };
566 
567 struct VM {
568  VM *operator->() {
569  return this;
570  }
571  const VM *operator->() const {
572  return this;
573  }
574 
575  struct Dialogs {
577  int &x = text_default_x;
578  int &y = text_default_y;
579 
580  DefaultPosition &operator=(const Common::Point &pt) {
581  x = pt.x;
582  y = pt.y;
583  return *this;
584  }
585  operator Common::Point() {
586  return Common::Point(x, y);
587  }
588 
589  bool operator==(const Common::Point &rhs) const {
590  return x == rhs.x && y == rhs.y;
591  }
592  };
593  DefaultPosition _defaultPosition;
594 
595  Dialogs *operator->() {
596  return this;
597  }
598  const Dialogs *operator->() const {
599  return this;
600  }
601 
602  void show(int id);
603  void show(int object_id, int id);
604  void showItem(int object_id, int message, int speech = 0);
605  };
606  Dialogs _dialogs;
607 
608  struct Events {
609  Events *operator->() {
610  return this;
611  }
612  const Events *operator->() const {
613  return this;
614  }
615 
616  void setCursor2(int cursorNum);
617  void showCursor();
618  void hideCursor();
619  int32 getFrameCounter();
620  };
621  Events _events;
622 
623  Scene::KernelMessages::TalkFont &_font = _scene._kernelMessages._talkFont;
624  Game &_game = Rooms::_game;
625 
626  struct PaletteProxy {
627  PaletteProxy *operator->() {
628  return this;
629  }
630  const PaletteProxy *operator->() const {
631  return this;
632  }
633 
634  void setEntry(int color, int r, int g, int b);
635  void refreshSceneColors();
636  void lock();
637  void setColorFlags(byte r, byte g, byte b);
638  void setColorValues(byte r, byte g, byte b);
639  void fadeOut(Palette palette, byte *paletteMap, int baseColor, int numColors,
640  int baseGrey, int numGreys, int tickDelay, int steps);
641  };
642  PaletteProxy _palette;
643 
644  struct Screen {
645  Screen *operator->() {
646  return this;
647  }
648  const Screen *operator->() const {
649  return this;
650  }
651 
652  word &_shakeCountdown = mcga_shakes;
653  };
654  Screen _screen;
655 
656  struct Sound {
657  Sound *operator->() {
658  return this;
659  }
660  const Sound *operator->() const {
661  return this;
662  }
663 
664  void command(int num, int distance = 0);
665  };
666  Sound _sound;
667 
668  int &_musicFlag = config_file.music_flag;
669 
670  int getRandomNumber(int min, int max);
671  int getRandomNumber(int max);
672 };
673 extern VM _vm;
674 
675 extern char *formAnimName(char type, int num);
676 
677 enum {
678  RETURNING_FROM_DIALOG = KERNEL_RESTORING_GAME,
679  RETURNING_FROM_LOADING = KERNEL_STARTING_GAME
680 };
681 
682 } // namespace Rooms
683 } // namespace RexNebular
684 } // namespace MADS
685 
686 #endif /* MADS_NEBULAR_SCENES8_H */
Definition: font.h:33
Definition: str.h:59
Definition: thunks.h:158
Definition: thunks.h:150
Definition: thunks.h:562
Definition: thunks.h:396
Definition: rect.h:536
Definition: sprite.h:249
Definition: thunks.h:644
Definition: thunks.h:608
T y
Definition: rect.h:49
Definition: kernel.h:150
Definition: thunks.h:567
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: kernel.h:198
Definition: anim_timer.h:27
Definition: thunks.h:575
Definition: movie_decoder.h:32
Definition: thunks.h:129
Definition: thunks.h:656
Definition: sprite.h:87
Definition: atari-screen.h:42