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 QUEEN_LOGIC_H
24 #define QUEEN_LOGIC_H
25 
26 #include "common/str-array.h"
27 #include "common/util.h"
28 #include "queen/structs.h"
29 
30 namespace Queen {
31 
32 enum RoomDisplayMode {
33 	RDM_FADE_NOJOE  = 0, // fade in, hide Joe
34 	RDM_FADE_JOE    = 1, // fade in, display Joe
35 	RDM_NOFADE_JOE  = 2, // screen does not dissolve into view
36 	RDM_FADE_JOE_XY = 3  // display Joe at the current X, Y coords
37 };
38 
39 enum JoeWalkMode {
40 	JWM_NORMAL  = 0,
41 	JWM_MOVE    = 1,
42 	JWM_EXECUTE = 2,
43 	JWM_SPEAK   = 3
44 };
45 
46 enum {
47 	JSO_OBJECT_DESCRIPTION = 0,
48 	JSO_OBJECT_NAME,
49 	JSO_ROOM_NAME,
50 	JSO_VERB_NAME,
51 	JSO_JOE_RESPONSE,
52 	JSO_ACTOR_ANIM,
53 	JSO_ACTOR_NAME,
54 	JSO_ACTOR_FILE,
55 	JSO_COUNT
56 };
57 
58 class Credits;
59 class Journal;
60 class QueenEngine;
61 
62 class Logic {
63 public:
64 
65 	Logic(QueenEngine *vm);
66 	virtual ~Logic();
67 
currentRoom()68 	uint16 currentRoom() const { return _currentRoom; }
currentRoom(uint16 room)69 	void currentRoom(uint16 room) {
70 		assert(room >= 1 && room <= _numRooms);
71 		_currentRoom = room;
72 	}
73 
oldRoom()74 	uint16 oldRoom() const { return _oldRoom; }
oldRoom(uint16 room)75 	void oldRoom(uint16 room) {
76 		assert(room <= _numRooms);
77 		_oldRoom = room;
78 	}
79 
newRoom()80 	uint16 newRoom() const { return _newRoom; }
newRoom(uint16 room)81 	void newRoom(uint16 room) {
82 		assert(room <= _numRooms);
83 		_newRoom = room;
84 	}
85 
objectData(int index)86 	ObjectData *objectData(int index) const { return &_objectData[index]; }
roomData(int room)87 	uint16 roomData(int room) const { return _roomData[room]; }
graphicData(int index)88 	GraphicData *graphicData(int index) const { return &_graphicData[index]; }
itemData(int index)89 	ItemData *itemData(int index) const { return &_itemData[index]; }
itemDataCount()90 	uint16 itemDataCount() const { return _numItems; }
91 
92 	uint16 findBob(uint16 obj) const;
93 	uint16 findFrame(uint16 obj) const;
94 	uint16 objectForPerson(uint16 bobnum) const;
95 	WalkOffData *walkOffPointForObject(int16 obj) const;
96 
walkOffCount()97 	uint16 walkOffCount() const { return _numWalkOffs; }
walkOffData(int index)98 	WalkOffData *walkOffData(int index) const { return &_walkOffData[index]; }
currentRoomData()99 	uint16 currentRoomData() const { return _roomData[_currentRoom]; }
graphicAnim(int index)100 	GraphicAnim *graphicAnim(int index) const { return &_graphicAnim[index]; }
graphicAnimCount()101 	uint16 graphicAnimCount() const { return _numGraphicAnim; }
objectDescription(uint16 objNum)102 	ObjectDescription *objectDescription(uint16 objNum) const { return &_objectDescription[objNum]; }
objectDescriptionCount()103 	uint16 objectDescriptionCount() const { return _numObjDesc; }
currentRoomSfx()104 	uint16 currentRoomSfx() const { return _sfxName[_currentRoom]; }
105 
joeFacing()106 	uint16 joeFacing() const { return _joe.facing; }
joeX()107 	uint16 joeX() const { return _joe.x; }
joeY()108 	uint16 joeY() const { return _joe.y; }
joeWalk()109 	JoeWalkMode joeWalk() const { return _joe.walk; }
joeScale()110 	uint16 joeScale() const { return _joe.scale; }
joeCutFacing()111 	uint16 joeCutFacing() const { return _joe.cutFacing; }
joePrevFacing()112 	uint16 joePrevFacing() const { return _joe.prevFacing; }
113 
joeFacing(uint16 dir)114 	void joeFacing(uint16 dir) { _joe.facing = dir; }
joePos(uint16 x,uint16 y)115 	void joePos(uint16 x, uint16 y) { _joe.x = x; _joe.y = y; }
116 	void joeWalk(JoeWalkMode walking);
joeScale(uint16 scale)117 	void joeScale(uint16 scale) { _joe.scale = scale; }
joeCutFacing(uint16 dir)118 	void joeCutFacing(uint16 dir) { _joe.cutFacing = dir; }
joePrevFacing(uint16 dir)119 	void joePrevFacing(uint16 dir) { _joe.prevFacing = dir; }
120 
121 	int16 gameState(int index) const;
122 	void gameState(int index, int16 newValue);
123 
talkSelected(int index)124 	TalkSelected *talkSelected(int index) { return &_talkSelected[index]; }
125 
126 	const char *roomName(uint16 roomNum) const;
127 	const char *objectName(uint16 objNum) const;
128 	const char *objectTextualDescription(uint16 objNum) const;
129 	const char *joeResponse(int i) const;
130 	const char *verbName(Verb v) const;
131 	const char *actorAnim(int num) const;
132 	const char *actorName(int num) const;
133 	const char *actorFile(int num) const;
134 
135 	void eraseRoom();
136 	void setupRoom(const char *room, int comPanel, bool inCutaway);
137 	void displayRoom(uint16 room, RoomDisplayMode mode, uint16 joeScale, int comPanel, bool inCutaway);
138 
entryObj()139 	int16 entryObj() const { return _entryObj; }
entryObj(int16 obj)140 	void entryObj(int16 obj) { _entryObj = obj; }
141 
142 	ActorData *findActor(uint16 noun, const char *name = NULL) const;
143 	bool initPerson(uint16 noun, const char *actorName, bool loadBank, Person *pp);
144 	uint16 findPersonNumber(uint16 obj, uint16 room) const;
145 
146 	//! load banks used for Joe animation
147 	void loadJoeBanks(const char *animBank, const char *standBank);
148 
149 	//! load the various bobs needed to animate Joe
150 	void setupJoe();
151 
152 	//! setup Joe at the right place when entering a room
153 	void setupJoeInRoom(bool autoPosition, uint16 scale);
154 
155 	uint16 joeFace();
156 	void joeGrab(int16 grabState);
157 
158 	//! change Joe clothes to dress
159 	void joeUseDress(bool showCut);
160 
161 	//! restore Joe clothes
162 	void joeUseClothes(bool showCut);
163 
164 	//! change Joe clothes to underwear
165 	void joeUseUnderwear();
166 
167 	void makeJoeSpeak(uint16 descNum, bool objectType = false);
168 	void makePersonSpeak(const char *sentence, Person *person, const char *voiceFilePrefix);
169 
170 	//! start the specified dialogue
171 	void startDialogue(const char *dlgFile, int personInRoom, char *cutaway);
172 
173 	//! play the specified cutaway
174 	void playCutaway(const char *cutFile, char *next = NULL);
175 
176 	//! initialize the inventory
177 	void inventorySetup();
178 
179 	//! get the inventory item for the specified inventory slot
180 	uint16 findInventoryItem(int invSlot) const;
181 
182 	//! refresh inventory contents
183 	void inventoryRefresh();
184 	int16 previousInventoryItem(int16 first) const;
185 	int16 nextInventoryItem(int16 first) const;
186 	void removeDuplicateItems();
187 	uint16 numItemsInventory() const;
188 	void inventoryInsertItem(uint16 itemNum, bool refresh = true);
189 	void inventoryDeleteItem(uint16 itemNum, bool refresh = true);
190 	void inventoryScroll(uint16 count, bool up);
191 	void removeHotelItemsFromInventory();
192 
193 	//! copy data from dummy object to object
194 	void objectCopy(int dummyObjectIndex, int objectIndex);
195 
196 	//! handle a particular event when Joe walks on this area
197 	void handleSpecialArea(Direction facing, uint16 areaNum, uint16 walkDataNum);
198 
199 	//! handle the pinnacle room (== room chooser in the jungle)
200 	void handlePinnacleRoom();
201 
202 	void update();
203 
204 	void saveState(byte *&ptr);
205 	void loadState(uint32 ver, byte *&ptr);
206 
207 	//! called after a save state has been loaded
208 	void setupRestoredGame();
209 
210 	//! ugly hack from original code
sceneReset()211 	void sceneReset() { _scene = 0; }
212 
213 	//! make a scene
214 	void sceneStart();
215 
216 	//! stop making a scene
217 	void sceneStop();
218 
219 	void changeRoom();
220 
221 	//! enter the Journal (save/load, configuration)
222 	virtual void useJournal() = 0;
223 
224 	//! execute a special move
225 	void executeSpecialMove(uint16 sm);
226 
227 	void startCredits(const char *filename);
228 	void stopCredits();
229 
230 	void start();
231 
232 	enum {
233 		JOE_RESPONSE_MAX    = 40,
234 		DEFAULT_TALK_SPEED  = 7 * 3,
235 		GAME_STATE_COUNT    = 211,
236 		TALK_SELECTED_COUNT = 86
237 	};
238 
239 	typedef void (Logic::*SpecialMoveProc)();
240 
241 protected:
242 
243 	void readQueenJas();
244 
245 	void asmMakeJoeUseDress();
246 	void asmMakeJoeUseNormalClothes();
247 	void asmMakeJoeUseUnderwear();
248 	void asmSwitchToDressPalette();
249 	void asmSwitchToNormalPalette();
250 	void asmStartCarAnimation();
251 	void asmStopCarAnimation();
252 	void asmStartFightAnimation();
253 	void asmWaitForFrankPosition();
254 	void asmMakeFrankGrowing();
255 	void asmMakeRobotGrowing();
256 	void asmShrinkRobot();
257 	void asmEndGame();
258 	void asmPutCameraOnDino();
259 	void asmPutCameraOnJoe();
260 	void asmAltIntroPanRight();
261 	void asmAltIntroPanLeft();
262 	void asmSetAzuraInLove();
263 	void asmPanRightFromJoe();
264 	void asmSetLightsOff();
265 	void asmSetLightsOn();
266 	void asmSetManequinAreaOn();
267 	void asmPanToJoe();
268 	void asmTurnGuardOn();
269 	void asmPanLeft320To144();
270 	void asmSmooch();
271 	void asmSmoochNoScroll();
272 	void asmMakeLightningHitPlane();
273 	void asmScaleBlimp();
274 	void asmScaleEnding();
275 	void asmWaitForCarPosition();
276 	void asmShakeScreen();
277 	void asmAttemptPuzzle();
278 	void asmScaleTitle();
279 	void asmScrollTitle();
280 	void asmPanRightToHugh();
281 	void asmMakeWhiteFlash();
282 	void asmPanRightToJoeAndRita();
283 	void asmPanLeftToBomb();
284 	void asmEndDemo();
285 	void asmInterviewIntro();
286 	void asmEndInterview();
287 
288 	virtual bool changeToSpecialRoom() = 0;
289 	virtual void setupSpecialMoveTable() = 0;
290 
291 
292 	uint16 _currentRoom;
293 	uint16 _oldRoom;
294 	uint16 _newRoom;
295 
296 	//! total number of room in game
297 	uint16 _numRooms;
298 
299 	//! first object number in room
300 	uint16 *_roomData;
301 
302 	//! background music to play in room
303 	uint16 *_sfxName;
304 
305 	//! bounding box of object
306 	Box *_objectBox;
307 
308 	//! inventory items
309 	ItemData *_itemData;
310 	uint16 _numItems;
311 
312 	GraphicData *_graphicData;
313 	uint16 _numGraphics;
314 
315 	ObjectData *_objectData;
316 	uint16 _numObjects;
317 
318 	ObjectDescription *_objectDescription;
319 	uint16 _numObjDesc;
320 
321 	ActorData *_actorData;
322 	uint16 _numActors;
323 
324 	//! walk off point for an object
325 	WalkOffData *_walkOffData;
326 	uint16 _numWalkOffs;
327 
328 	FurnitureData *_furnitureData;
329 	uint16 _numFurniture;
330 
331 	GraphicAnim *_graphicAnim;
332 	uint16 _numGraphicAnim;
333 
334 	//! actor initial position in room is _walkOffData[_entryObj]
335 	int16 _entryObj;
336 
337 	Common::StringArray _jasStringList;
338 	int _jasStringOffset[JSO_COUNT];
339 
340 	uint16 _numDescriptions;
341 	uint16 _numNames;
342 	uint16 _numAAnim;
343 	uint16 _numAName;
344 	uint16 _numAFile;
345 
346 	struct {
347 		uint16 x, y;
348 		uint16 facing, cutFacing, prevFacing;
349 		JoeWalkMode walk;
350 		uint16 scale;
351 	} _joe;
352 
353 	int16 _gameState[GAME_STATE_COUNT];
354 
355 	TalkSelected _talkSelected[TALK_SELECTED_COUNT];
356 
357 	//! inventory items
358 	int16 _inventoryItem[4];
359 
360 	//! puzzle counter for room T7
361 	uint8 _puzzleAttemptCount;
362 
363 	//! cutscene counter
364 	int _scene;
365 
366 	SpecialMoveProc _specialMoves[40];
367 
368 	Credits *_credits;
369 	Journal *_journal;
370 
371 	QueenEngine *_vm;
372 };
373 
374 class LogicDemo : public Logic {
375 public:
376 
LogicDemo(QueenEngine * vm)377 	LogicDemo(QueenEngine *vm) : Logic(vm) {}
378 	void useJournal();
379 
380 protected:
381 
382 	bool changeToSpecialRoom();
383 	void setupSpecialMoveTable();
384 };
385 
386 class LogicInterview : public Logic {
387 public:
388 
LogicInterview(QueenEngine * vm)389 	LogicInterview(QueenEngine *vm) : Logic(vm) {}
390 	void useJournal();
391 
392 protected:
393 
394 	bool changeToSpecialRoom();
395 	void setupSpecialMoveTable();
396 };
397 
398 class LogicGame : public Logic {
399 public:
400 
LogicGame(QueenEngine * vm)401 	LogicGame(QueenEngine *vm) : Logic(vm) {}
402 	void useJournal();
403 
404 protected:
405 
406 	bool changeToSpecialRoom();
407 	void setupSpecialMoveTable();
408 };
409 
410 
411 } // End of namespace Queen
412 
413 #endif
414