ScummVM API documentation
object.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) 1994-1998 Revolution Software Ltd.
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 #ifndef SWORD2_OBJECT_H
25 #define SWORD2_OBJECT_H
26 
27 #include "common/endian.h"
28 
29 namespace Sword2 {
30 
31 // these structures represent the broken up compact components
32 // these here declared to the system must be the same as those declared to
33 // LINC (or it won't work)
34 
35 // mouse structure - defines mouse detection area, detection priority &
36 // 'type' flag
37 
38 struct ObjectMouse {
39  int32 x1; // Top-left and bottom-right of mouse
40  int32 y1; // area. (These coords are inclusive.)
41  int32 x2;
42  int32 y2;
43  int32 priority;
44  int32 pointer; // type (or resource id?) of pointer used over this area
45 
46  static int size() {
47  return 24;
48  }
49 
50  void read(const byte *addr);
51  void write(byte *addr);
52 };
53 
54 // logic structure - contains fields used in logic script processing
55 
56 class ObjectLogic {
57  // int32 looping; // 0 when first calling fn<function>;
58  // 1 when calling subsequent times in
59  // same loop
60  // int32 pause; // pause count, used by fnPause()
61 
62 private:
63  byte *_addr;
64 
65 public:
66  ObjectLogic(byte *addr) {
67  _addr = addr;
68  }
69 
70  static int size() {
71  return 8;
72  }
73 
74  byte *data() {
75  return _addr;
76  }
77 
78  int32 getLooping() { return READ_LE_UINT32(_addr); }
79  int32 getPause() { return READ_LE_UINT32(_addr + 4); }
80 
81  void setLooping(int32 x) { WRITE_LE_UINT32(_addr, x); }
82  void setPause(int32 x) { WRITE_LE_UINT32(_addr + 4, x); }
83 };
84 
85 // status bits for 'type' field of ObjectGraphic)
86 
87 // in low word:
88 
89 #define NO_SPRITE 0x00000000 // don't print
90 #define BGP0_SPRITE 0x00000001 // fixed to background parallax[0]
91 #define BGP1_SPRITE 0x00000002 // fixed to background parallax[1]
92 #define BACK_SPRITE 0x00000004 // 'background' sprite, fixed to main background
93 #define SORT_SPRITE 0x00000008 // 'sorted' sprite, fixed to main background
94 #define FORE_SPRITE 0x00000010 // 'foreground' sprite, fixed to main background
95 #define FGP0_SPRITE 0x00000020 // fixed to foreground parallax[0]
96 #define FGP1_SPRITE 0x00000040 // fixed to foreground parallax[0]
97 
98 // in high word:
99 
100 #define UNSHADED_SPRITE 0x00000000 // not to be shaded
101 #define SHADED_SPRITE 0x00010000 // to be shaded, based on shading mask
102 
103 // graphic structure - contains fields appropriate to sprite output
104 
106  // int32 type; // see above
107  // int32 anim_resource; // resource id of animation file
108  // int32 anim_pc; // current frame number of animation
109 
110 private:
111  byte *_addr;
112 
113 public:
114  ObjectGraphic(byte *addr) {
115  _addr = addr;
116  }
117 
118  static int size() {
119  return 12;
120  }
121 
122  byte *data() {
123  return _addr;
124  }
125 
126  int32 getType() { return READ_LE_UINT32(_addr); }
127  int32 getAnimResource() { return READ_LE_UINT32(_addr + 4); }
128  int32 getAnimPc() { return READ_LE_UINT32(_addr + 8); }
129 
130  void setType(int32 x) { WRITE_LE_UINT32(_addr, x); }
131  void setAnimResource(int32 x) { WRITE_LE_UINT32(_addr + 4, x); }
132  void setAnimPc(int32 x) { WRITE_LE_UINT32(_addr + 8, x); }
133 };
134 
135 // speech structure - contains fields used by speech scripts & text output
136 
138  // int32 pen; // color to use for body of characters
139  // int32 width; // max width of text sprite
140  // int32 command; // speech script command id
141  // int32 ins1; // speech script instruction parameters
142  // int32 ins2;
143  // int32 ins3;
144  // int32 ins4;
145  // int32 ins5;
146  // int32 wait_state; // 0 not waiting,
147  // 1 waiting for next speech command
148 
149 private:
150  byte *_addr;
151 
152 public:
153  ObjectSpeech(byte *addr) {
154  _addr = addr;
155  }
156 
157  static int size() {
158  return 36;
159  }
160 
161  byte *data() {
162  return _addr;
163  }
164 
165  int32 getPen() { return READ_LE_UINT32(_addr); }
166  int32 getWidth() { return READ_LE_UINT32(_addr + 4); }
167  int32 getCommand() { return READ_LE_UINT32(_addr + 8); }
168  int32 getIns1() { return READ_LE_UINT32(_addr + 12); }
169  int32 getIns2() { return READ_LE_UINT32(_addr + 16); }
170  int32 getIns3() { return READ_LE_UINT32(_addr + 20); }
171  int32 getIns4() { return READ_LE_UINT32(_addr + 24); }
172  int32 getIns5() { return READ_LE_UINT32(_addr + 28); }
173  int32 getWaitState() { return READ_LE_UINT32(_addr + 32); }
174 
175  void setPen(int32 x) { WRITE_LE_UINT32(_addr, x); }
176  void setWidth(int32 x) { WRITE_LE_UINT32(_addr + 4, x); }
177  void setCommand(int32 x) { WRITE_LE_UINT32(_addr + 8, x); }
178  void setIns1(int32 x) { WRITE_LE_UINT32(_addr + 12, x); }
179  void setIns2(int32 x) { WRITE_LE_UINT32(_addr + 16, x); }
180  void setIns3(int32 x) { WRITE_LE_UINT32(_addr + 20, x); }
181  void setIns4(int32 x) { WRITE_LE_UINT32(_addr + 24, x); }
182  void setIns5(int32 x) { WRITE_LE_UINT32(_addr + 28, x); }
183  void setWaitState(int32 x) { WRITE_LE_UINT32(_addr + 32, x); }
184 };
185 
186 // mega structure - contains fields used for mega-character & mega-set
187 // processing
188 
189 class ObjectMega {
190  // int32 NOT_USED_1; // only free roaming megas need to
191  // check this before registering their
192  // graphics for drawing
193  // int32 NOT_USED_2; // id of floor on which we are standing
194  // int32 NOT_USED_3; // id of object which we are getting to
195  // int32 NOT_USED_4; // pixel distance to stand from player
196  // character when in conversation
197  // int32 currently_walking; // number given us by the auto router
198  // int32 walk_pc; // current frame number of walk-anim
199  // int32 scale_a; // current scale factors, taken from
200  // int32 scale_b; // floor data
201  // int32 feet_x; // mega feet coords - frame-offsets are
202  // int32 feet_y; // added to these position mega frames
203  // int32 current_dir; // current dirction faced by mega; used
204  // by autorouter to determine turns
205  // required
206  // int32 NOT_USED_5; // means were currently avoiding a
207  // collision (see fnWalk)
208  // int32 megaset_res; // resource id of mega-set file
209  // int32 NOT_USED_6; // NOT USED
210 
211 private:
212  byte *_addr;
213 
214 public:
215  ObjectMega(byte *addr) {
216  _addr = addr;
217  }
218 
219  static int size() {
220  return 56;
221  }
222 
223  byte *data() {
224  return _addr;
225  }
226 
227  int32 getIsWalking() { return READ_LE_UINT32(_addr + 16); }
228  int32 getWalkPc() { return READ_LE_UINT32(_addr + 20); }
229  int32 getScaleA() { return READ_LE_UINT32(_addr + 24); }
230  int32 getScaleB() { return READ_LE_UINT32(_addr + 28); }
231  int32 getFeetX() { return READ_LE_UINT32(_addr + 32); }
232  int32 getFeetY() { return READ_LE_UINT32(_addr + 36); }
233  int32 getCurDir() { return READ_LE_UINT32(_addr + 40); }
234  int32 getMegasetRes() { return READ_LE_UINT32(_addr + 48); }
235 
236  void setIsWalking(int32 x) { WRITE_LE_UINT32(_addr + 16, x); }
237  void setWalkPc(int32 x) { WRITE_LE_UINT32(_addr + 20, x); }
238  void setScaleA(int32 x) { WRITE_LE_UINT32(_addr + 24, x); }
239  void setScaleB(int32 x) { WRITE_LE_UINT32(_addr + 28, x); }
240  void setFeetX(int32 x) { WRITE_LE_UINT32(_addr + 32, x); }
241  void setFeetY(int32 x) { WRITE_LE_UINT32(_addr + 36, x); }
242  void setCurDir(int32 x) { WRITE_LE_UINT32(_addr + 40, x); }
243  void setMegasetRes(int32 x) { WRITE_LE_UINT32(_addr + 48, x); }
244 
245  int32 calcScale() {
246  // Calc scale at which to print the sprite, based on feet
247  // y-coord & scaling constants (NB. 'scale' is actually
248  // 256 * true_scale, to maintain accuracy)
249 
250  // Ay+B gives 256 * scale ie. 256 * 256 * true_scale for even
251  // better accuracy, ie. scale = (Ay + B) / 256
252  return (getScaleA() * getFeetY() + getScaleB()) / 256;
253  }
254 };
255 
256 // walk-data structure - contains details of layout of frames in the
257 // mega-set, and how they are to be used
258 
260  int32 nWalkFrames; // no. of frames per walk-cycle
261  int32 usingStandingTurnFrames; // 0 = no 1 = yes
262  int32 usingWalkingTurnFrames; // 0 = no 1 = yes
263  int32 usingSlowInFrames; // 0 = no 1 = yes
264  int32 usingSlowOutFrames; // 0 = no !0 = number of slow-out frames in each direction
265  int32 nSlowInFrames[8]; // no. of slow-in frames in each direction
266  int32 leadingLeg[8]; // leading leg for walk in each direction (0 = left 1 = right)
267  int32 dx[8 * (12 + 1)]; // walk step distances in x direction
268  int32 dy[8 * (12 + 1)]; // walk step distances in y direction
269 
270  static int size() {
271  return 916;
272  }
273 
274  void read(const byte *addr);
275  void write(byte *addr);
276 };
277 
278 } // End of namespace Sword2
279 
280 #endif
Definition: object.h:38
Definition: object.h:105
Definition: animation.h:37
Definition: object.h:259
Definition: object.h:137
Definition: object.h:56
Definition: object.h:189