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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef TRECISION_STRUCT_H
24 #define TRECISION_STRUCT_H
25 
26 #include "common/stream.h"
27 #include "common/rect.h"
28 #include "common/scummsys.h"
29 #include "common/serializer.h"
30 #include "graphics/surface.h"
31 #include "trecision/defines.h"
32 
33 namespace Trecision {
34 
35 struct SRoom {
36 	char  _baseName[4];                     // Room name
37 	uint16 _bkgAnim;                        // Background animation
38 	uint16 _object[MAXOBJINROOM];           // Objects in the room
39 	uint16 _sounds[MAXSOUNDSINROOM];        // Sounds of the room
40 	uint16 _actions[MAXACTIONINROOM];       // Character actions in the room
41 
hasExtraSRoom42 	bool hasExtra() { return _flag & kObjFlagExtra; }
isDoneSRoom43 	bool isDone() { return _flag & kObjFlagDone; }
setExtraSRoom44 	void setExtra(bool on) { if (on) _flag |= kObjFlagExtra; else _flag &= ~kObjFlagExtra; }
setDoneSRoom45 	void setDone(bool on) { if (on) _flag |= kObjFlagDone; else _flag &= ~kObjFlagDone; }
46 
47 	void syncGameStream(Common::Serializer &ser);
48 	void loadRoom(Common::SeekableReadStreamEndian *stream);
49 
50 private:
51 	uint8 _flag; // Room visited or not, extra or not
52 };
53 
54 struct SObject {
55 	Common::Rect _rect;
56 	Common::Rect _lim;
57 	int8  _position;						// -1 if no position
58 	uint16 _name;
59 	uint16 _examine;
60 	uint16 _action;
61 	uint8 _goRoom;                          // If direction room num - if person num dialog
62 	uint8 _nbox;                            // Which 3d box the object is associated with
63 	uint8 _ninv;                            // ptr inventory
64 	uint16 _anim;
65 
66 	void readRect(Common::SeekableReadStream *stream);
setFlagDoneSObject67 	void setFlagDone(bool on) { if (on) _flag |= kObjFlagDone; else _flag &= ~kObjFlagDone; }
setFlagExamineSObject68 	void setFlagExamine(bool on) { if (on) _flag |= kObjFlagExamine; else _flag &= ~kObjFlagExamine; }
setFlagExtraSObject69 	void setFlagExtra(bool on) { if (on) _flag |= kObjFlagExtra; else _flag &= ~kObjFlagExtra; }
setFlagPersonSObject70 	void setFlagPerson(bool on) { if (on) _flag |= kObjFlagPerson; else _flag &= ~kObjFlagPerson; }
setFlagRoomOutSObject71 	void setFlagRoomOut(bool on) { if (on) _flag |= kObjFlagRoomOut; else _flag &= ~kObjFlagRoomOut; }
setFlagRoomInSObject72 	void setFlagRoomIn(bool on) { if (on) _flag |= kObjFlagRoomIn; else _flag &= ~kObjFlagRoomIn; }
setFlagTakeSObject73 	void setFlagTake(bool on) { if (on) _flag |= kObjFlagTake; else _flag &= ~kObjFlagTake; }
74 
isFlagDoneSObject75 	bool isFlagDone() { return _flag & kObjFlagDone; }
isFlagExamineSObject76 	bool isFlagExamine() { return _flag & kObjFlagExamine; }
isFlagExtraSObject77 	bool isFlagExtra() { return _flag & kObjFlagExtra; }
isFlagPersonSObject78 	bool isFlagPerson() { return _flag & kObjFlagPerson; }
isFlagRoomInSObject79 	bool isFlagRoomIn() { return _flag & kObjFlagRoomIn; }
isFlagRoomOutSObject80 	bool isFlagRoomOut() { return _flag & kObjFlagRoomOut; }
isFlagTakeSObject81 	bool isFlagTake() { return _flag & kObjFlagTake; }
isFlagUseWithSObject82 	bool isFlagUseWith() { return _flag & kObjFlagUseWith; }
83 
isModeHiddenSObject84 	bool isModeHidden() { return _mode & OBJMODE_HIDDEN; }
isModeFullSObject85 	bool isModeFull() { return _mode & OBJMODE_FULL; }
isModeMaskSObject86 	bool isModeMask() { return _mode & OBJMODE_MASK; }
isModeLimSObject87 	bool isModeLim() { return _mode & OBJMODE_LIM; }
isModeStatusSObject88 	bool isModeStatus() { return _mode & OBJMODE_OBJSTATUS; }
89 
setModeHiddenSObject90 	void setModeHidden(bool on) { if (on) _mode |= OBJMODE_HIDDEN; else _mode &= ~OBJMODE_HIDDEN; }
setModeFullSObject91 	void setModeFull(bool on) { if (on) _mode |= OBJMODE_FULL; else _mode &= ~OBJMODE_FULL; }
setModeMaskSObject92 	void setModeMask(bool on) { if (on) _mode |= OBJMODE_MASK; else _mode &= ~OBJMODE_MASK; }
setModeLimSObject93 	void setModeLim(bool on) { if (on) _mode |= OBJMODE_LIM; else _mode &= ~OBJMODE_LIM; }
setModeStatusSObject94 	void setModeStatus(bool on) { if (on) _mode |= OBJMODE_OBJSTATUS; else _mode &= ~OBJMODE_OBJSTATUS; }
95 
96 	void syncGameStream(Common::Serializer &ser);
97 	void loadObj(Common::SeekableReadStreamEndian *stream);
98 
99 private:
100 	uint8 _flag;
101 	uint8 _mode;
102 };
103 
104 struct SInvObject {
105 	uint16 _name;                            // Object name in the inventory
106 	uint16 _examine;                         // Sentence if examined
107 	uint16 _action;
108 	uint16 _anim;
109 
setFlagExtraSInvObject110 	void setFlagExtra(bool on) { if (on) _flag |= kObjFlagExtra; else _flag &= ~kObjFlagExtra; }
111 
isFlagExtraSInvObject112 	bool isFlagExtra() { return _flag & kObjFlagExtra; }
isUseWithSInvObject113 	bool isUseWith() { return _flag & kObjFlagUseWith; }
114 
115 	void syncGameStream(Common::Serializer &ser);
116 	void loadObj(Common::SeekableReadStreamEndian *stream);
117 
118 private:
119 	uint8 _flag;
120 };
121 
122 struct SAtFrame {
123 	uint8 _type;	   //ATFTEXT, ATFSND, ATFEVENT
124 	uint8 _area;	   // 0 1 2 3 4
125 	uint16 _numFrame;
126 	uint16 _index;
127 };
128 
129 // Shifted left by 1 - 4, depending on the subarea
130 #define SMKANIM_OFF_BASE 16
131 
132 struct SAnim {
133 	char _name[14];
134 	uint16 _flag;		// 1- background 2- icon 3- action 4- active  -  4bits per child
135 	Common::Rect _lim[MAXAREA];
136 	uint8 _nbox;
137 	SAtFrame _atFrame[MAXATFRAME];
138 
139 	/**
140 	 * Toggle the animation of a subarea
141 	 * @param area: 1 - 4
142 	 * @param show: show or hide the animation area
143 	*/
toggleAnimAreaSAnim144 	void toggleAnimArea(uint8 area, bool show) {
145 		assert(area >= 1 && area <= 4);
146 		if (show)
147 			_flag &= ~(SMKANIM_OFF_BASE << area);
148 		else
149 			_flag |= (SMKANIM_OFF_BASE << area);
150 	}
151 
152 	/**
153 	 * Checks if an animation subarea is shown
154 	 * @param area: 1 - 4
155 	 * @return true if the subarea is shown
156 	*/
isAnimAreaShownSAnim157 	bool isAnimAreaShown(uint8 area) {
158 		assert(area >= 1 && area <= 4);
159 		return !(_flag & (SMKANIM_OFF_BASE << area));
160 	}
161 };
162 
163 struct SSortTable {
164 	uint16 _objectId;                        // Object ID
165 	bool  _remove;                           // Whether to copy or remove
166 };
167 
168 class Scheduler;
169 
170 struct SScriptFrame {
171 	uint8 _class;
172 	uint8 _event;
173 
174 	uint8 _u8Param;
175 
176 	uint16 _u16Param1;
177 	uint16 _u16Param2;
178 
179 	uint16 _u32Param;
180 
181 	bool  _noWait;
182 
183 	void clear();
184 	void sendFrame(Scheduler *scheduler);
isEmptyEventSScriptFrame185 	bool isEmptyEvent() const { return _class == 0 && _event == 0;  }
186 };
187 
188 class TrecisionEngine;
189 
190 struct SDText {
191 	Common::Rect _rect;
192 	Common::Rect _subtitleRect;
193 	uint16 _textColor;
194 	Common::String _text;
195 	Common::String _drawTextLines[MAXDTEXTLINES];
196 
197 	void set(SDText *org);
198 	void set(Common::Rect rect, Common::Rect subtitleRect, uint16 textCol, const Common::String &text);
199 
200 	void draw(TrecisionEngine *vm, bool hideLastChar = false, Graphics::Surface *externalSurface = nullptr);
201 	uint16 calcHeight(TrecisionEngine *vm);
202 };
203 
204 struct STexture {
205 	int16 _dx, _dy, _angle;
206 	uint8 *_texture;
207 
208 	void clear();
209 	void set(int16 x, int16 y, uint8 *buffer);
isActiveSTexture210 	bool isActive() { return _active; };
211 
212 private:
213 	bool _active;
214 };
215 
216 struct SVertex {
217 	float _x, _y, _z;
218 	float _nx, _ny, _nz;
219 
220 	void clear();
221 };
222 
223 struct SFace {
224 	uint16 _a, _b, _c;
225 	uint16 _mat;
226 };
227 
228 struct SLight {
229 	float _x, _y, _z;
230 	float _dx, _dy, _dz;
231 	float _inr, _outr;
232 	uint8 _hotspot;
233 	uint8 _fallOff;
234 	int8 _inten;
235 	int8 _position;
236 
237 	void clear();
238 };
239 
240 struct SCamera {
241 	float _ex, _ey, _ez;
242 	float _e1[3];
243 	float _e2[3];
244 	float _e3[3];
245 	float _fovX, _fovY;
246 
247 	void clear();
248 };
249 
250 } // End of namespace Trecision
251 #endif
252