ScummVM API documentation
objects.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 SHERLOCK_OBJECTS_H
23 #define SHERLOCK_OBJECTS_H
24 
25 #include "common/scummsys.h"
26 #include "common/rect.h"
27 #include "common/str-array.h"
28 #include "common/str.h"
29 #include "sherlock/image_file.h"
30 #include "sherlock/fixed_text.h"
31 #include "sherlock/saveload.h"
32 
33 namespace Sherlock {
34 
35 class SherlockEngine;
36 
37 enum ObjectAllow {
38  ALLOW_MOVE = 1, ALLOW_OPEN = 2, ALLOW_CLOSE = 4
39 };
40 
41 enum SpriteType {
42  INVALID = 0,
43  CHARACTER = 1,
44  CURSOR = 2,
45  STATIC_BG_SHAPE = 3, // Background shape that doesn't animate
46  ACTIVE_BG_SHAPE = 4, // Background shape that animates
47  REMOVE = 5, // Object should be removed next frame
48  NO_SHAPE = 6, // Background object with no shape
49  HIDDEN = 7, // Hidden backgruond object
50  HIDE_SHAPE = 8, // Object needs to be hidden
51 
52  // Rose Tattoo
53  HIDDEN_CHARACTER = 128
54 };
55 
56 enum AType {
57  OBJECT = 0,
58  PERSON = 1,
59  SOLID = 2,
60  TALK = 3, // Standard talk zone
61  FLAG_SET = 4,
62  DELTA = 5,
63  WALK_AROUND = 6,
64  TALK_EVERY = 7, // Talk zone that turns on every room visit
65  TALK_MOVE = 8, // Talk zone that only activates when Holmes moves
66  PAL_CHANGE = 9, // Changes the palette down so that it gets darker
67  PAL_CHANGE2 = 10, // Same as PAL_CHANGE, except that it goes up
68  SCRIPT_ZONE = 11, // If this is clicked in, it is activated
69  BLANK_ZONE = 12, // This masks out other objects when entered
70  NOWALK_ZONE = 13 // Player cannot walk here
71 };
72 
73 // Different levels for sprites to be at
74 enum {
75  BEHIND = 0, NORMAL_BEHIND = 1, NORMAL_FORWARD = 2, FORWARD = 3
76 };
77 
78 #define MAX_HOLMES_SEQUENCE 16
79 #define MAX_FRAME 30
80 #define FIXED_INT_MULTIPLIER 1000
81 
82 // code put into sequences to defines 1-10 type seqs
83 #define SEQ_TO_CODE 67
84 #define FLIP_CODE (64 + 128)
85 #define SOUND_CODE (34 + 128)
86 #define HIDE_CODE (7+128) // Code for hiding/unhiding an object from a Sequence
87 #define CALL_TALK_CODE (8+128) // Code for call a Talk File from a Sequence
88 #define TELEPORT_CODE (9+128) // Code for setting Teleport Data (X,Y)
89 #define MOVE_CODE (10+128) // Code for setting Movement Delta (X,Y)
90 
91 #define GOTO_CODE 228
92 #define TALK_SEQ_CODE 252 // Code specifying start of talk sequence frames in a Sequence
93 #define TALK_LISTEN_CODE 251 // Code specifying start of talk listen frames in a Sequence
94 #define ALLOW_TALK_CODE 250
95 
96 #define UPPER_LIMIT 0
97 #define LOWER_LIMIT (IS_SERRATED_SCALPEL ? CONTROLS_Y : SHERLOCK_SCREEN_HEIGHT)
98 #define LEFT_LIMIT 0
99 #define RIGHT_LIMIT SHERLOCK_SCREEN_WIDTH
100 
101 class Point32 {
102 public:
103  int x;
104  int y;
105 
106  Point32() : x(0), y(0) {}
107  Point32(int x1, int y1) : x(x1), y(y1) {}
108  Point32(const Common::Point &pt) : x(pt.x), y(pt.y) {}
109 
110  bool operator==(const Point32 &p) const { return x == p.x && y == p.y; }
111  bool operator!=(const Point32 &p) const { return x != p.x || y != p.y; }
112  Point32 operator+(const Point32 &delta) const { return Point32(x + delta.x, y + delta.y); }
113  Point32 operator-(const Point32 &delta) const { return Point32(x - delta.x, y - delta.y); }
114  operator Common::Point() { return Common::Point(x, y); }
115 
116  void operator+=(const Point32 &delta) { x += delta.x; y += delta.y; }
117  void operator-=(const Point32 &delta) { x -= delta.x; y -= delta.y; }
118 };
119 
120 class PositionFacing : public Point32 {
121 public:
122  int _facing;
123 
124  PositionFacing() : Point32(), _facing(0) {}
125  PositionFacing(int xp, int yp, int theFacing) : Point32(xp, yp), _facing(theFacing) {}
126  PositionFacing &operator=(const Point32 &pt) {
127  x = pt.x; y = pt.y;
128  return *this;
129  }
130 };
131 
132 struct WalkSequence {
133  Common::String _vgsName;
134  bool _horizFlip;
135  Common::Array<byte> _sequences;
136 
137  WalkSequence() : _horizFlip(false) {}
138  const byte &operator[](int idx) { return _sequences[idx]; }
139 
143  void load(Common::SeekableReadStream &s);
144 };
145 
146 class WalkSequences : public Common::Array < WalkSequence > {
147 public:
148  WalkSequences &operator=(const WalkSequences &src);
149 };
150 
151 enum { REVERSE_DIRECTION = 0x80 };
152 #define NAMES_COUNT 4
153 
154 struct ActionType {
155  int _cAnimNum;
156  int _cAnimSpeed;
157  Common::String _names[NAMES_COUNT];
158  int _useFlag; // Which flag USE will set (if any)
159 
160  ActionType();
161 
165  void load(Common::SeekableReadStream &s);
166 };
167 
168 struct UseType: public ActionType {
169  Common::String _target;
170  Common::String _verb;
171 
172  UseType();
173 
177  void load(Common::SeekableReadStream &s, bool isRoseTattoo);
178  void load3DO(Common::SeekableReadStream &s);
179 
183  void synchronize(Serializer &s);
184 };
185 
186 class BaseObject {
187 protected:
188  static SherlockEngine *_vm;
189 protected:
195  bool checkEndOfSequence();
196 
201  void setObjSequence(int seq, bool wait);
202 public:
203  static bool _countCAnimFrames;
204 public:
205  SpriteType _type; // Type of object/sprite
206  Common::String _description; // Description lines
207  byte *_sequences; // Holds animation sequences
208  ImageFile *_images; // Sprite images
209  ImageFrame *_imageFrame; // Pointer to shape in the images
210  int _sequenceNumber; // Sequence being used
211  int _startSeq; // Frame sequence starts at
212  int _walkCount; // Walk counter
213  int _allow; // Allowed UI commands
214  int _frameNumber; // Frame number in rame sequence to draw
215  Point32 _position; // Current position
216  Point32 _delta; // Momvement amount
217  Common::Point _oldPosition; // Old position
218  Common::Point _oldSize; // Image's old size
219  Point32 _goto; // Walk destination
220 
221  int _lookFlag; // Which flag LOOK will set (if any)
222  int _requiredFlag[2]; // Object will be hidden if not set
223  Common::Point _noShapeSize; // Size of a NO_SHAPE
224  int _status; // Status (open/closed, moved/not)
225  int8 _misc; // Misc field -- use varies with type
226  int _maxFrames; // Number of frames
227  int _flags; // Tells if object can be walked behind
228  AType _aType; // Tells if this is an object, person, talk, etc.
229  int _lookFrames; // How many frames to play of the look anim before pausing
230  int _seqCounter; // How many times this sequence has been executed
231  PositionFacing _lookPosition; // Where to walk when examining object
232  int _lookcAnim;
233  int _seqStack; // Allows gosubs to return to calling frame
234  int _seqTo; // Allows 1-5, 8-3 type sequences encoded in 2 bytes
235  uint _descOffset; // Tells where description starts in DescText
236  int _seqCounter2; // Counter of calling frame sequence
237  uint _seqSize; // Tells where description starts
238  UseType _use[6]; // Serrated Scalpel uses 4, Rose Tattoo 6
239  int _quickDraw; // Flag telling whether to use quick draw routine or not
240  int _scaleVal; // Tells how to scale the sprite
241  int _gotoSeq; // Used by Talk to tell which sequence to goto when able
242  int _talkSeq; // Tells which talk sequence currently in use (Talk or Listen)
243  int _restoreSlot; // Used when talk returns to the previous sequence
244 public:
245  BaseObject();
246  virtual ~BaseObject() {}
247  static void setVm(SherlockEngine *vm);
248 
255  bool hasAborts() const;
256 
260  void checkObject();
261 
268  int checkNameForCodes(const Common::String &name, FixedTextActionId fixedTextActionId = kFixedTextAction_Invalid);
269 
277  virtual void setObjTalkSequence(int seq) {}
278 };
279 
280 class Sprite: public BaseObject {
281 public:
282  Common::String _name;
283  Common::String _examine; // Examine in-depth description
284  Common::String _pickUp; // Message for if you can't pick up object
285 
286  WalkSequences _walkSequences; // Holds animation sequences
287  Common::Point _noShapeSize; // Size of a NO_SHAPE
288  int _status; // Status: open/closed, moved/not moved
289  int8 _misc; // Miscellaneous use
290 
291  // Rose Tattoo fields
292  ImageFrame *_stopFrames[8]; // Stop/rest frame for each direction
293  ImageFile *_altImages; // Images used for alternate NPC sequences
294  int _altSeq; // Which of the sequences the alt graphics apply to (0: main, 1=NPC seq)
295  int _centerWalk; // Flag telling the walk code to offset the walk destination
296  Common::Point _adjust; // Fine tuning adjustment to position when drawn
297  int _oldWalkSequence;
298 public:
299  Sprite(): BaseObject() { clear(); }
300  ~Sprite() override {}
301 
302  static void setVm(SherlockEngine *vm) { _vm = vm; }
303 
307  void clear();
308 
312  void setImageFrame();
313 
317  void checkSprite();
318 
326  void setObjTalkSequence(int seq) override {}
327 
331  int frameWidth() const { return _imageFrame ? _imageFrame->_frame.w : 0; }
332 
336  int frameHeight() const { return _imageFrame ? _imageFrame->_frame.h : 0; }
337 
341  const Common::Rect getOldBounds() const;
342 
346  virtual void adjustSprite() = 0;
347 
351  virtual void gotoStand() = 0;
352 
357  virtual void setWalking() = 0;
358 };
359 
360 enum { OBJ_BEHIND = 1, OBJ_FLIPPED = 2, OBJ_FORWARD = 4, TURNON_OBJ = 0x20, TURNOFF_OBJ = 0x40 };
361 #define USE_COUNT 4
362 
363 class Object: public BaseObject {
364 public:
365  Common::String _name; // Name
366  Common::String _examine; // Examine in-depth description
367  int _sequenceOffset;
368  int _pickup;
369  int _defaultCommand; // Default right-click command
370 
371  // Serrated Scalpel fields
372  int _pickupFlag; // Which flag PICKUP will set (if any)
373  ActionType _aOpen; // Holds data for moving object
374  ActionType _aClose;
375  ActionType _aMove;
376 
377  Object();
378  ~Object() override {}
379 
383  void load(Common::SeekableReadStream &s, bool isRoseTattoo);
384  void load3DO(Common::SeekableReadStream &s);
385 
389  void toggleHidden();
390 
394  void setFlagsAndToggles();
395 
400  void adjustObject();
401 
406  int pickUpObject(FixedTextActionId fixedTextActionId = kFixedTextAction_Invalid);
407 
411  int frameWidth() const { return _imageFrame ? _imageFrame->_frame.w : 0; }
412 
416  int frameHeight() const { return _imageFrame ? _imageFrame->_frame.h : 0; }
417 
421  const Common::Rect getNewBounds() const;
422 
426  const Common::Rect getNoShapeBounds() const;
427 
431  const Common::Rect getOldBounds() const;
432 
440  void setObjTalkSequence(int seq) override;
441 };
442 
443 struct CAnim {
444  Common::String _name; // Name
445  Common::Point _position; // Position
446  int _dataSize; // Size of uncompressed animation data
447  uint32 _dataOffset; // offset within room file of animation data
448  int _flags; // Tells if can be walked behind
449  PositionFacing _goto[2]; // Position Holmes (and NPC in Rose Tattoo) should walk to before anim starts
450  PositionFacing _teleport[2]; // Location Holmes (and NPC) shoul teleport to after playing canim
451 
452  // Scalpel specific
453  byte _sequences[MAX_FRAME]; // Animation sequences
454  SpriteType _type;
455 
456  // Rose Tattoo specific
457  int _scaleVal; // How much the canim is scaled
458 
462  void load(Common::SeekableReadStream &s, bool isRoseTattoo, uint32 dataOffset);
463  void load3DO(Common::SeekableReadStream &s, uint32 dataOffset);
464 };
465 
466 struct SceneImage {
467  ImageFile *_images; // Object images
468  int _maxFrames; // How many frames in object
469  int _filesize; // File size
470 
471  SceneImage();
472 };
473 
474 } // End of namespace Sherlock
475 
476 #endif
void setObjTalkSequence(int seq) override
Definition: objects.h:326
Definition: objects.h:120
Definition: objects.h:132
Definition: str.h:59
int frameHeight() const
Definition: objects.h:336
int frameWidth() const
Definition: objects.h:411
Definition: animation.h:29
Definition: rect.h:144
Definition: stream.h:745
int frameWidth() const
Definition: objects.h:331
Definition: serializer.h:79
Definition: image_file.h:36
int frameHeight() const
Definition: objects.h:416
Definition: objects.h:466
Definition: objects.h:154
Definition: sherlock.h:76
Definition: rect.h:45
Definition: objects.h:363
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
Definition: image_file.h:78
Definition: objects.h:168
Definition: objects.h:101
Definition: objects.h:146
Definition: objects.h:186
virtual void setObjTalkSequence(int seq)
Definition: objects.h:277
Definition: objects.h:280
Definition: objects.h:443