ScummVM API documentation
structs.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 QUEEN_STRUCTS_H
23 #define QUEEN_STRUCTS_H
24 
25 #include "queen/defs.h"
26 #include "common/endian.h"
27 
28 namespace Queen {
29 
30 struct Box {
31  int16 x1, y1, x2, y2;
32 
33  Box()
34  : x1(0), y1(0), x2(0), y2(0) {
35  }
36 
37  Box(int16 xx1, int16 yy1, int16 xx2, int16 yy2)
38  : x1(xx1), y1(yy1), x2(xx2), y2(yy2) {
39  }
40 
41  void readFromBE(byte *&ptr) {
42  x1 = (int16)READ_BE_UINT16(ptr); ptr += 2;
43  y1 = (int16)READ_BE_UINT16(ptr); ptr += 2;
44  x2 = (int16)READ_BE_UINT16(ptr); ptr += 2;
45  y2 = (int16)READ_BE_UINT16(ptr); ptr += 2;
46  }
47 
48  void writeToBE(byte *&ptr) {
49  WRITE_BE_UINT16(ptr, x1); ptr += 2;
50  WRITE_BE_UINT16(ptr, y1); ptr += 2;
51  WRITE_BE_UINT16(ptr, x2); ptr += 2;
52  WRITE_BE_UINT16(ptr, y2); ptr += 2;
53  }
54 
55  int16 xDiff() const {
56  return x2 - x1;
57  }
58 
59  int16 yDiff() const {
60  return y2 - y1;
61  }
62 
63  bool intersects(int16 x, int16 y, uint16 w, uint16 h) const {
64  return (x + w > x1) && (y + h > y1) && (x <= x2) && (y <= y2);
65  }
66 
67  bool contains(int16 x, int16 y) const {
68  return (x >= x1) && (x <= x2) && (y >= y1) && (y <= y2);
69  }
70 
71  bool operator==(const Box &b) const {
72  return (x1 == b.x1) && (x2 == b.x2) && (y1 == b.y1) && (y2 == b.y2);
73  }
74 };
75 
76 
77 struct Area {
79  int16 mapNeighbors;
83  uint16 bottomScaleFactor, topScaleFactor;
85  uint16 object;
86 
87  Area()
88  : mapNeighbors(0), bottomScaleFactor(0), topScaleFactor(0), object(0) {
89  }
90 
91  void readFromBE(byte *&ptr) {
92  mapNeighbors = (int16)READ_BE_UINT16(ptr); ptr += 2;
93  box.readFromBE(ptr);
94  bottomScaleFactor = READ_BE_UINT16(ptr); ptr += 2;
95  topScaleFactor = READ_BE_UINT16(ptr); ptr += 2;
96  object = READ_BE_UINT16(ptr); ptr += 2;
97  }
98 
99  void writeToBE(byte *&ptr) {
100  WRITE_BE_UINT16(ptr, mapNeighbors); ptr += 2;
101  box.writeToBE(ptr);
102  WRITE_BE_UINT16(ptr, bottomScaleFactor); ptr += 2;
103  WRITE_BE_UINT16(ptr, topScaleFactor); ptr += 2;
104  WRITE_BE_UINT16(ptr, object); ptr += 2;
105  }
106 
107  uint16 calcScale(int16 y) const {
108  uint16 dy = box.yDiff();
109  int16 ds = scaleDiff();
110  uint16 scale = 0;
111 
112  if (dy) // Prevent division-by-zero
113  scale = ((((y - box.y1) * 100) / dy) * ds) / 100 + bottomScaleFactor;
114 
115  if (scale == 0)
116  scale = 100;
117 
118  return scale;
119  }
120 
121  int16 scaleDiff() const {
122  return (int16)(topScaleFactor - bottomScaleFactor);
123  }
124 };
125 
126 
127 struct WalkOffData {
129  int16 entryObj;
131  uint16 x, y;
132 
133  void readFromBE(byte *&ptr) {
134  entryObj = (int16)READ_BE_UINT16(ptr); ptr += 2;
135  x = READ_BE_UINT16(ptr); ptr += 2;
136  y = READ_BE_UINT16(ptr); ptr += 2;
137  }
138 
139  void writeToBE(byte *&ptr) {
140  WRITE_BE_UINT16(ptr, entryObj); ptr += 2;
141  WRITE_BE_UINT16(ptr, x); ptr += 2;
142  WRITE_BE_UINT16(ptr, y); ptr += 2;
143  }
144 };
145 
146 
147 struct GraphicData {
149  uint16 x, y;
151 
171  int16 firstFrame, lastFrame;
173  uint16 speed;
174 
175  void readFromBE(byte *&ptr) {
176  x = READ_BE_UINT16(ptr); ptr += 2;
177  y = READ_BE_UINT16(ptr); ptr += 2;
178  firstFrame = (int16)READ_BE_UINT16(ptr); ptr += 2;
179  lastFrame = (int16)READ_BE_UINT16(ptr); ptr += 2;
180  speed = READ_BE_UINT16(ptr); ptr += 2;
181  }
182 };
183 
184 
185 struct ObjectData {
187  int16 name;
189  uint16 x, y;
191  uint16 description;
193  int16 entryObj;
195  uint16 room;
197  uint16 state;
199 
239  int16 image;
240 
241  void readFromBE(byte *&ptr) {
242  name = (int16)READ_BE_UINT16(ptr); ptr += 2;
243  x = READ_BE_UINT16(ptr); ptr += 2;
244  y = READ_BE_UINT16(ptr); ptr += 2;
245  description = READ_BE_UINT16(ptr); ptr += 2;
246  entryObj = (int16)READ_BE_UINT16(ptr); ptr += 2;
247  room = READ_BE_UINT16(ptr); ptr += 2;
248  state = READ_BE_UINT16(ptr); ptr += 2;
249  image = (int16)READ_BE_UINT16(ptr); ptr += 2;
250  }
251 
252  void writeToBE(byte *&ptr) {
253  WRITE_BE_UINT16(ptr, name); ptr += 2;
254  WRITE_BE_UINT16(ptr, x); ptr += 2;
255  WRITE_BE_UINT16(ptr, y); ptr += 2;
256  WRITE_BE_UINT16(ptr, description); ptr += 2;
257  WRITE_BE_UINT16(ptr, entryObj); ptr += 2;
258  WRITE_BE_UINT16(ptr, room); ptr += 2;
259  WRITE_BE_UINT16(ptr, state); ptr += 2;
260  WRITE_BE_UINT16(ptr, image); ptr += 2;
261  }
262 };
263 
264 
267  uint16 object;
269 
293  uint16 type;
298 
299  void readFromBE(byte *&ptr) {
300  object = READ_BE_UINT16(ptr); ptr += 2;
301  type = READ_BE_UINT16(ptr); ptr += 2;
302  lastDescription = READ_BE_UINT16(ptr); ptr += 2;
303  lastSeenNumber = READ_BE_UINT16(ptr); ptr += 2;
304  }
305 
306  void writeToBE(byte *&ptr) {
307  WRITE_BE_UINT16(ptr, object); ptr += 2;
308  WRITE_BE_UINT16(ptr, type); ptr += 2;
309  WRITE_BE_UINT16(ptr, lastDescription); ptr += 2;
310  WRITE_BE_UINT16(ptr, lastSeenNumber); ptr += 2;
311  }
312 };
313 
314 
315 struct ItemData {
317  int16 name;
319  uint16 description;
321  uint16 state;
323  uint16 frame;
326 
327  void readFromBE(byte *&ptr) {
328  name = (int16)READ_BE_UINT16(ptr); ptr += 2;
329  description = READ_BE_UINT16(ptr); ptr += 2;
330  state = READ_BE_UINT16(ptr); ptr += 2;
331  frame = READ_BE_UINT16(ptr); ptr += 2;
332  sfxDescription = (int16)READ_BE_UINT16(ptr); ptr += 2;
333  }
334 
335  void writeToBE(byte *&ptr) {
336  WRITE_BE_UINT16(ptr, name); ptr += 2;
337  WRITE_BE_UINT16(ptr, description); ptr += 2;
338  WRITE_BE_UINT16(ptr, state); ptr += 2;
339  WRITE_BE_UINT16(ptr, frame); ptr += 2;
340  WRITE_BE_UINT16(ptr, sfxDescription); ptr += 2;
341  }
342 };
343 
344 
345 struct ActorData {
347  int16 room;
349  int16 bobNum;
351  uint16 name;
353  int16 gsSlot, gsValue;
355  uint16 color;
359  uint16 x, y;
361  uint16 anim;
363  uint16 bankNum;
365  uint16 file;
366 
367  void readFromBE(byte *&ptr) {
368  room = (int16)READ_BE_UINT16(ptr); ptr += 2;
369  bobNum = (int16)READ_BE_UINT16(ptr); ptr += 2;
370  name = READ_BE_UINT16(ptr); ptr += 2;
371  gsSlot = (int16)READ_BE_UINT16(ptr); ptr += 2;
372  gsValue = (int16)READ_BE_UINT16(ptr); ptr += 2;
373  color = READ_BE_UINT16(ptr); ptr += 2;
374  bobFrameStanding = READ_BE_UINT16(ptr); ptr += 2;
375  x = READ_BE_UINT16(ptr); ptr += 2;
376  y = READ_BE_UINT16(ptr); ptr += 2;
377  anim = READ_BE_UINT16(ptr); ptr += 2;
378  bankNum = READ_BE_UINT16(ptr); ptr += 2;
379  file = READ_BE_UINT16(ptr); ptr += 2;
380  // Fix the actor data (see queen.c - l.1518-1519). When there is no
381  // valid actor file, we must load the data from the objects room bank.
382  // This bank has number 15 (not 10 as in the data files).
383  if (file == 0) {
384  bankNum = 15;
385  }
386  }
387 };
388 
389 
390 struct CmdListData {
392  Verb verb;
394  int16 nounObj1;
396  int16 nounObj2;
398  int16 song;
400  bool setAreas;
404  bool setItems;
408  int16 imageOrder;
411 
412  void readFromBE(byte *&ptr) {
413  verb = (Verb)READ_BE_UINT16(ptr); ptr += 2;
414  nounObj1 = (int16)READ_BE_UINT16(ptr); ptr += 2;
415  nounObj2 = (int16)READ_BE_UINT16(ptr); ptr += 2;
416  song = (int16)READ_BE_UINT16(ptr); ptr += 2;
417  setAreas = READ_BE_UINT16(ptr) != 0; ptr += 2;
418  setObjects = READ_BE_UINT16(ptr) != 0; ptr += 2;
419  setItems = READ_BE_UINT16(ptr) != 0; ptr += 2;
420  setConditions = READ_BE_UINT16(ptr) != 0; ptr += 2;
421  imageOrder = (int16)READ_BE_UINT16(ptr); ptr += 2;
422  specialSection = (int16)READ_BE_UINT16(ptr); ptr += 2;
423  }
424 
425  bool match(const Verb& v, int16 obj1, int16 obj2) const {
426  return verb == v && nounObj1 == obj1 && nounObj2 == obj2;
427  }
428 };
429 
430 
431 struct CmdArea {
433  int16 id;
435  int16 area;
437  uint16 room;
438 
439  void readFromBE(byte *&ptr) {
440  id = (int16)READ_BE_UINT16(ptr); ptr += 2;
441  area = (int16)READ_BE_UINT16(ptr); ptr += 2;
442  room = READ_BE_UINT16(ptr); ptr += 2;
443  }
444 };
445 
446 
447 struct CmdObject {
449  int16 id;
451  int16 dstObj;
453  int16 srcObj;
454 
455  void readFromBE(byte *&ptr) {
456  id = (int16)READ_BE_UINT16(ptr); ptr += 2;
457  dstObj = (int16)READ_BE_UINT16(ptr); ptr += 2;
458  srcObj = (int16)READ_BE_UINT16(ptr); ptr += 2;
459  }
460 };
461 
462 
463 struct CmdInventory {
465  int16 id;
467  int16 dstItem;
469  int16 srcItem;
470 
471  void readFromBE(byte *&ptr) {
472  id = (int16)READ_BE_UINT16(ptr); ptr += 2;
473  dstItem = (int16)READ_BE_UINT16(ptr); ptr += 2;
474  srcItem = (int16)READ_BE_UINT16(ptr); ptr += 2;
475  }
476 };
477 
478 
479 struct CmdGameState {
481  int16 id;
482  int16 gameStateSlot;
483  int16 gameStateValue;
484  uint16 speakValue;
485 
486  void readFromBE(byte *&ptr) {
487  id = (int16)READ_BE_UINT16(ptr); ptr += 2;
488  gameStateSlot = (int16)READ_BE_UINT16(ptr); ptr += 2;
489  gameStateValue = (int16)READ_BE_UINT16(ptr); ptr += 2;
490  speakValue = READ_BE_UINT16(ptr); ptr += 2;
491  }
492 };
493 
494 
497  int16 room;
499 
515  int16 objNum;
516 
517  void readFromBE(byte *&ptr) {
518  room = (int16)READ_BE_UINT16(ptr); ptr += 2;
519  objNum = (int16)READ_BE_UINT16(ptr); ptr += 2;
520  }
521 };
522 
523 
524 struct GraphicAnim {
525  int16 keyFrame;
526  int16 frame;
527  uint16 speed;
528 
529  void readFromBE(byte *&ptr) {
530  keyFrame = (int16)READ_BE_UINT16(ptr); ptr += 2;
531  frame = (int16)READ_BE_UINT16(ptr); ptr += 2;
532  speed = READ_BE_UINT16(ptr); ptr += 2;
533  }
534 };
535 
536 
537 struct AnimFrame {
538  uint16 frame;
539  uint16 speed;
540 };
541 
542 
543 struct Person {
545  const ActorData *actor;
547  const char *name;
549  const char *anim;
551  uint16 bobFrame;
552 };
553 
554 
555 struct TalkSelected {
556  bool hasTalkedTo;
557  int16 values[4];
558 
559  void readFromBE(byte *&ptr) {
560  hasTalkedTo = READ_BE_UINT16(ptr) != 0; ptr += 2;
561  for (int i = 0; i < 4; i++) {
562  values[i] = (int16)READ_BE_UINT16(ptr); ptr += 2;
563  }
564  }
565 
566  void writeToBE(byte *&ptr) {
567  WRITE_BE_UINT16(ptr, (uint16)hasTalkedTo); ptr += 2;
568  for (int i = 0; i < 4; i++) {
569  WRITE_BE_UINT16(ptr, values[i]); ptr += 2;
570  }
571  }
572 };
573 
574 
575 struct BobFrame {
576  uint16 width, height;
577  uint16 xhotspot, yhotspot;
578  uint8 *data;
579 };
580 
581 
582 } // End of namespace Queen
583 
584 #endif
uint16 bobFrame
current frame
Definition: structs.h:551
int16 id
CmdListData number.
Definition: structs.h:433
bool setConditions
if set, P1_SET_CONDITIONS must be called (using CmdGameState)
Definition: structs.h:406
bool setObjects
if set, P3_SET_OBJECTS must be called (using CmdObject)
Definition: structs.h:402
Definition: structs.h:479
const char * anim
animation string
Definition: structs.h:549
Definition: structs.h:543
uint16 file
entry in ACTOR_FILE
Definition: structs.h:365
int16 area
area to turn off/on (<0: off, >0: on)
Definition: structs.h:435
uint16 description
entry in OBJECT_DESCR
Definition: structs.h:191
int16 id
CmdListData number.
Definition: structs.h:465
const char * name
actor name
Definition: structs.h:547
int16 dstItem
<0: delete, >0: add
Definition: structs.h:467
uint16 object
entry in ObjectData, object lying in this area
Definition: structs.h:85
uint16 bobFrameStanding
bank bobframe for standing position of the actor
Definition: structs.h:357
bool setItems
if set, P4_SET_ITEMS must be called (using CmdInventory)
Definition: structs.h:404
Definition: structs.h:30
uint16 x
coordinates of object
Definition: structs.h:149
uint16 type
type of the description
Definition: structs.h:293
uint16 room
room in which the area must be changed
Definition: structs.h:437
uint16 name
entry in ACTOR_NAME
Definition: structs.h:351
uint16 color
spoken text color
Definition: structs.h:355
int16 room
room in which the actor is
Definition: structs.h:347
const ActorData * actor
actor settings to use
Definition: structs.h:545
int16 nounObj2
second object used in the action
Definition: structs.h:396
int16 song
song to play (>0: playbefore, <0: playafter)
Definition: structs.h:398
int16 srcItem
>0: valid
Definition: structs.h:469
int16 name
entry in OBJECT_NAME
Definition: structs.h:317
int16 srcObj
>0: copy from srcObj, 0: nothing, -1: delete dstObj
Definition: structs.h:453
int16 nounObj1
first object used in the action
Definition: structs.h:394
uint16 object
entry in ObjectData or ItemData
Definition: structs.h:267
Definition: structs.h:524
uint16 room
room in which this object is available
Definition: structs.h:195
uint16 lastDescription
last entry possible in OBJECT_DESCR for this object
Definition: structs.h:295
int16 dstObj
>0: show, <0: hide
Definition: structs.h:451
int16 sfxDescription
entry in OBJECT_DESCR (>0 if available)
Definition: structs.h:325
Definition: structs.h:390
Definition: structs.h:77
int16 entryObj
entry in ObjectData
Definition: structs.h:129
uint16 x
initial coordinates in the room
Definition: structs.h:359
Definition: structs.h:345
Definition: structs.h:265
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: bankman.h:28
int16 entryObj
associated object
Definition: structs.h:193
Definition: structs.h:495
Verb verb
action to perform
Definition: structs.h:392
int16 mapNeighbors
bitmask of connected areas
Definition: structs.h:79
Definition: structs.h:315
uint16 x
coordinates of object
Definition: structs.h:189
int16 gsSlot
gamestate entry/value, actor is valid if GAMESTATE[slot] == value
Definition: structs.h:353
uint16 anim
entry in ACTOR_ANIM
Definition: structs.h:361
int16 objNum
furniture object number
Definition: structs.h:515
uint16 bankNum
bank to use to load the actor file
Definition: structs.h:363
Definition: structs.h:575
Definition: structs.h:147
Definition: structs.h:127
int16 specialSection
special section to execute (refer to execute.c l.423-451)
Definition: structs.h:410
int16 image
entry in GraphicData
Definition: structs.h:239
int16 id
CmdListData number.
Definition: structs.h:481
int16 bobNum
bob number associated to this actor
Definition: structs.h:349
Definition: structs.h:431
uint16 lastSeenNumber
last description number used (in order to avoid re-using it)
Definition: structs.h:297
uint16 state
state of the object (grab direction, on/off, default command...)
Definition: structs.h:197
Definition: structs.h:555
bool setAreas
if set, P2_SET_AREAS must be called (using CmdArea)
Definition: structs.h:400
int16 id
CmdListData number.
Definition: structs.h:449
Definition: structs.h:185
int16 firstFrame
bank bobframes
Definition: structs.h:171
int16 imageOrder
graphic image order
Definition: structs.h:408
uint16 state
state of the object
Definition: structs.h:321
Box box
coordinates defining area limits
Definition: structs.h:81
Definition: structs.h:447
uint16 x
coordinates to reach
Definition: structs.h:131
Definition: structs.h:463
int16 room
room in which the furniture are
Definition: structs.h:497
Definition: structs.h:537
int16 name
entry in OBJECT_NAME (<0: object is hidden, 0: object has been deleted)
Definition: structs.h:187
uint16 description
entry in OBJECT_DESCR
Definition: structs.h:319
uint16 frame
bank bobframe
Definition: structs.h:323
uint16 speed
moving speed of object
Definition: structs.h:173
uint16 bottomScaleFactor
scaling factors for bobs actors
Definition: structs.h:83