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