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 HOPKINS_OBJECTS_H
24 #define HOPKINS_OBJECTS_H
25 
26 #include "hopkins/globals.h"
27 
28 #include "common/scummsys.h"
29 #include "common/endian.h"
30 #include "common/str.h"
31 
32 #define MAX_SPRITE 5
33 namespace Hopkins {
34 
35 struct ObjectAuthIcon {
36 	byte _objectFileNum;
37 	byte _idx;
38 	byte _flag1;
39 	byte _flag2;
40 	byte _flag3;
41 	byte _flag4;
42 	byte _flag5;
43 	byte _flag6;
44 };
45 
46 struct SpriteItem {
47 	int _animationType;
48 	const byte *_spriteData;
49 	Common::Point _spritePos;
50 	int _zoomFactor;
51 	bool _flipFl;
52 	int _spriteIndex;
53 	int _deltaX;
54 	int _deltaY;
55 	bool _rleFl;
56 	bool _activeFl;
57 	int _destX;
58 	int _destY;
59 	int _width;
60 	int _height;
61 	int _zoomPct;
62 	int _reducePct;
63 };
64 
65 struct BobItem {
66 	int _bobMode;
67 	byte *_spriteData;
68 	int _xp;
69 	int _yp;
70 	int _frameIndex;
71 	int _animDataIdx;
72 	int _moveChange1;
73 	int _moveChange2;
74 	bool _disabledAnimationFl;
75 	byte *_animData;
76 	bool _bobMode10;
77 	int _bobModeChange;
78 	int _modeChangeCtr;
79 	int _modeChangeUnused;
80 	bool _disableFl; // Set to true in B_CACHE_OFF()
81 	int _zoomFactor;
82 	bool _flipFl;
83 	bool _isSpriteFl;
84 	bool _activeFl;
85 	int _oldX;
86 	int _oldY;
87 	int _oldWidth;
88 	int _oldHeight;
89 	int _oldX2;
90 	int _zooInmFactor;
91 	int _zoomOutFactor;
92 };
93 
94 struct HidingItem {
95 	int _x;
96 	int _y;
97 	int _spriteIndex;
98 	int _width;
99 	int _height;
100 	int _useCount;
101 	byte *_spriteData;
102 	bool _resetUseCount;
103 	int _yOffset;
104 };
105 
106 struct LockAnimItem {
107 	bool _enableFl;
108 	int _posX;
109 };
110 
111 struct VBobItem {
112 	const byte *_spriteData;
113 	int _displayMode;
114 	int _xp;
115 	int _yp;
116 	int _frameIndex;
117 	byte *_surface;
118 	int _oldX;
119 	int _oldY;
120 	int _oldFrameIndex;
121 	const byte *_oldSpriteData;
122 };
123 
124 struct ListeItem {
125 	bool _visibleFl;
126 	int _posX;
127 	int _posY;
128 	int _width;
129 	int _height;
130 };
131 
132 /**
133  * Mode for SortItem records
134  */
135 enum SortMode { SORT_NONE = 0, SORT_BOB = 1, SORT_SPRITE = 2, SORT_HIDING = 3 };
136 
137 /**
138  * Structure to represent a pending display of either a Bob, Sprite, or Cache Item.
139  */
140 struct SortItem {
141 	SortMode _sortMode;
142 	int _index;
143 	int _priority;
144 };
145 
146 class HopkinsEngine;
147 
148 class ObjectsManager {
149 private:
150 	HopkinsEngine *_vm;
151 
152 	int _objectWidth, _objectHeight;
153 	int _oldBorderSpriteIndex;
154 	int _borderSpriteIndex;
155 	byte *_spritePtr;
156 	const byte *_oldSpriteData;
157 	int _verb;
158 	int _oldSpriteIndex;
159 	int _oldFrameIndex;
160 	int _oldDirectionSpriteIdx;
161 	Directions _oldDirection;
162 	Directions _lastDirection;
163 	bool _oldFlipFl;
164 	int _curGestureFile;
165 	byte *_gestureBuf;
166 	int _homeRateCounter;
167 	int _sortedDisplayCount;
168 	SortItem _sortedDisplay[51];
169 	byte *_hidingItemData[6];
170 	HidingItem _hidingItem[25];
171 	bool _hidingActiveFl;
172 	ObjectAuthIcon _objectAuthIcons[300];
173 	int _curObjectFileNum;
174 	byte *_objectDataBuf;
175 
176 	VBobItem _vBob[30];
177 	ListeItem _liste[6];
178 	ListeItem _liste2[35];
179 
180 	void initVBob();
181 	void clearVBob();
182 
183 	void sprite_alone(const byte *objectData, byte *sprite, int objIndex);
184 	void removeObjectDataBuf();
185 
186 	int getOffsetX(const byte *spriteData, int spriteIndex, bool isSize);
187 	int getOffsetY(const byte *spriteData, int spriteIndex, bool isSize);
188 
189 	void capture_mem_sprite(const byte *objectData, byte *sprite, int objIndex);
190 	void setBobInfo(int idx);
191 	void computeHideCounter(int idx);
192 	void initBobVariables(int idx);
193 
194 	void checkHidingItem();
195 	void displayHiding(int idx);
196 	void computeSprite(int idx);
197 	void beforeSort(SortMode sortMode, int index, int priority);
198 	void displayBobAnim();
199 	void displayVBob();
200 	void showSprite(int idx);
201 	void clearSprite();
202 	void setSpriteZoom(int idx, int zoomFactor);
203 
204 	void loadZone(const Common::String &file);
205 	void changeCharacterHead(PlayerCharacter oldCharacter, PlayerCharacter newCharacter);
206 	void goHome2();
207 
208 	void nextVerbIcon();
209 	void handleForest(int screenId, int minX, int maxX, int minY, int maxY, int idx);
210 
211 	void sceneSpecialIni();
212 	void showActionAnimation(const byte *spriteData, const Common::String &actionStr, int speed, bool flipFl);
213 public:
214 	bool _disableFl;
215 	bool _forestFl;
216 	bool _visibleFl;
217 	bool _saveLoadFl;
218 	bool _forceZoneFl;
219 	bool _changeVerbFl;
220 	bool _helicopterFl;
221 	bool _twoCharactersFl;
222 	bool _changeHeadFl;
223 	bool _priorityFl;
224 	int _jumpVerb;
225 	int _jumpZone;
226 	int _zoneNum;
227 	int _eraseVisibleCounter;
228 	int _curObjectIndex;
229 	int _startSpriteIndex;
230 	int _saveLoadX, _saveLoadY;
231 	int _mapCarPosX, _mapCarPosY;
232 	int _oldCharacterPosX, _oldCharacterPosY;
233 	Common::Point _borderPos;
234 	Common::Point _oldBorderPos;
235 	Common::Point _characterPos;
236 	byte *_forestSprite;
237 	byte *_saveLoadSprite;
238 	byte *_saveLoadSprite2;
239 	byte *_headSprites;
240 	SpriteItem _sprite[6];
241 	BobItem _bob[36];
242 	LockAnimItem _lockedAnims[36];
243 	bool _charactersEnabledFl;
244 	bool _refreshBobMode10Fl;
245 
246 	ObjectsManager(HopkinsEngine *vm);
247 	~ObjectsManager();
248 
249 	void clearAll();
250 
251 	int getWidth(const byte *objectData, int idx);
252 	int getHeight(const byte *objectData, int idx);
253 	byte *loadSprite(const Common::String &file);
254 	void loadLinkFile(const Common::String &file, bool OBSSEUL = false);
255 	void addStaticSprite(const byte *spriteData, Common::Point pos, int idx, int spriteIndex, int zoomFactor, bool flipFl, int deltaX, int deltaY);
256 	void animateSprite(int idx);
257 	void removeSprite(int idx);
258 	void setSpriteX(int idx, int xp);
259 	void setSpriteY(int idx, int yp);
260 	int getSpriteX(int idx);
261 	int getSpriteY(int idx);
262 	void setSpriteIndex(int idx, int spriteIndex);
263 	void displaySprite();
264 	void computeAndSetSpriteSize();
265 	void setFlipSprite(int idx, bool flip);
266 
267 	int getBobAnimDataIdx(int idx);
268 	void initBorder(int zoneIdx);
269 	void nextObjectIcon(int idx);
270 	void takeInventoryObject(int idx);
271 	void handleSpecialGames();
272 
273 	void addObject(int objIndex);
274 	void changeObject(int objIndex);
275 	void removeObject(int objIndex);
276 
277 	void resetBob(int idx);
278 	void hideBob(int idx);
279 	void displayBob(int idx);
280 	void setBobOffset(int idx, int offset);
281 	void setBobAnimDataIdx(int idx, int animIdx);
282 	void setBobAnimation(int idx);
283 	void stopBobAnimation(int idx);
284 	int getBobPosX(int idx);
285 
286 	void handleCityMap();
287 	void clearScreen();
288 	void disableVerb(int idx, int a2);
289 	void enableVerb(int idx, int a2);
290 	void lockAnimX(int idx, int x);
291 	void handleLeftButton();
292 	void handleRightButton();
293 	void setOffsetXY(byte *data, int idx, int xp, int yp, bool isSize);
294 	void setVerb(int id);
295 
296 	void doActionBack(int idx);
297 	void doActionRight(int idx);
298 	void doActionFront(int idx);
299 	void doActionLeft(int idx);
300 	void doActionDiagRight(int idx);
301 	void doActionDiagLeft(int idx);
302 	void loadObjects();
303 	byte *loadObjectFromFile(int objIndex, bool mode);
304 	void resetHidingItems();
305 	void resetHidingUseCount(int idx);
306 	void setHidingUseCount(int idx);
307 	void loadHidingItems(const Common::String &file);
308 	void enableHidingBehavior();
309 	void disableHidingBehavior();
310 	void disableHidingItem(int idx);
311 
resetHomeRateCounter()312 	void resetHomeRateCounter() { _homeRateCounter = 0; }
resetOldFrameIndex()313 	void resetOldFrameIndex() { _oldFrameIndex = -1; }
resetOldDirection()314 	void resetOldDirection()  { _oldDirection = DIR_NONE; }
getObjectWidth()315 	int getObjectWidth()  { return _objectWidth; }
getObjectHeight()316 	int getObjectHeight() { return _objectHeight; }
317 
318 	void showSpecialActionAnimationWithFlip(const byte *spriteData, const Common::String &animationSeq, int speed, bool flipFl);
319 	void showSpecialActionAnimation(const byte *spriteData, const Common::String &animString, int speed);
320 	void checkEventBobAnim(int idx, int animIdx, int animDataIdx, int a4);
321 	void setMultiBobAnim(int idx1, int idx2, int anim1Idx, int anim2Idx);
322 	void loadObjectIniFile();
323 	void quickDisplayBobSprite(int idx);
324 	void initVbob(const byte *src, int idx, int xp, int yp, int frameIndex);
325 	void disableVbob(int idx);
326 	void setAndPlayAnim(int idx, int animIdx, int destPosi, bool animAction);
327 
328 	void sceneControl(const Common::String &backgroundFile, const Common::String &linkFile,
329 		const Common::String &animFile, const Common::String &s4, int soundNum, bool initializeScreen);
330 	void sceneControl2(const Common::String &backgroundFile, const Common::String &linkFile,
331 		const Common::String &animFile, const Common::String &s4, int soundNum, bool initializeScreen);
332 	void goHome();
333 	void paradise();
334 };
335 
336 } // End of namespace Hopkins
337 
338 #endif /* HOPKINS_OBJECTS_H */
339