ScummVM API documentation
waynesworld.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 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef WAYNESWORLD_H
23#define WAYNESWORLD_H
24
25#include "common/events.h"
26#include "common/file.h"
27#include "common/random.h"
28#include "common/str.h"
29#include "common/system.h"
30#include "engines/engine.h"
31#include "engines/advancedDetector.h"
32
33#include "image/pcx.h"
34
35#include "waynesworld/sound.h"
36#include "wwintro.h"
37
38#define kWWSavegameVersion 1
39#define kWWSavegameStrSize 14
40#define kWWSavegameStr "SCUMMVM_WAYNES"
41
42namespace WaynesWorld {
43class GxlArchive;
44
45enum {
46 GF_GUILANGSWITCH = (1 << 0) // If GUI language switch is required for menus
47};
48
49class Screen;
50class WWSurface;
51class GFTFont;
52class GameLogic;
53
55 uint8 version;
56 Common::String saveName;
57 Graphics::Surface *thumbnail;
58 int16 saveYear, saveMonth, saveDay;
59 int16 saveHour, saveMinutes;
60 uint32 playTime;
61};
62
63struct RoomObject {
64 int roomNumber;
65 const char *name;
66 int x1, y1, x2, y2;
67 int direction;
68 int walkX, walkY;
69};
70
72 int index, count;
73};
74
76 const char *name;
77 int x1, y1, x2, y2;
78};
79
80struct WalkPoint {
81 int x, y, direction;
82};
83
85 uint32 nextUpdateTicks;
86 uint32 delay;
87 int counter;
88 bool expired;
89 AnimationTimer() : nextUpdateTicks(0), delay(0), counter(0), expired(false) {}
90};
91
92enum {
93 kLeftButtonClicked = 1 << 0,
94 kRightButtonClicked = 1 << 1,
95 kKeyPressed = 1 << 2
96};
97
98const int kRoomObjectsCount = 404;
99const int kWalkPointsCount = 300;
100const uint kWalkMapSize = (320 * 150) / 8;
101const uint kRoomAnimationsCount = 20;
102const uint kStaticRoomObjectsMapCount = 40;
103const uint kStaticRoomObjectsCount = 58;
104const uint kStaticRoomObjectSpritesCount = 4;
105const uint kAnimationTimersCount = 4;
106const int kInventorySize = 50;
107const int kFirstInventoryObjectId = 28;
108const int kLastInventoryObjectId = 77;
109
110extern const char *savegameStr;
111
112class WaynesWorldEngine : public Engine {
113protected:
114 Common::Error run() override;
115 bool hasFeature(EngineFeature f) const override;
116
117public:
119 ~WaynesWorldEngine() override;
120 const Common::String getTargetName() { return _targetName; }
121 static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header, bool skipThumbnail = true);
122
123 // _gameState 0 = game, 4 = menu
124 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
125 return _isSaveAllowed && (_gameState == 0 || _gameState == 4);
126 }
127 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
128 return _isSaveAllowed && (_gameState == 0 || _gameState == 4);
129 }
130
131 Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
132 Common::Error loadGameState(int slot) override;
133
134 const ADGameDescription *_gameDescription;
135 bool _isSoundEnabled = true;
136 bool _isMusicEnabled = true;
137
138 bool _introOngoing = true;
139 bool _escPressed = false;
140 bool _useOriginalSaveLoad = true;
141
142private:
143 Graphics::PixelFormat _pixelFormat;
144
145 int _loadSaveSlot = -1;
146
147public:
148 Common::RandomSource *_random = nullptr;
149 GameLogic *_logic = nullptr;
150
151 void updateEvents();
152
153 // Graphics
154 byte _palette2[768] = {0};
155 Screen *_screen = nullptr;
156 WWSurface *_backgroundSurface = nullptr;
157 WWSurface *_backgroundScrollSurface = nullptr;
158 GFTFont *_fontWW = nullptr;
159 GFTFont *_fontWWInv = nullptr;
160 GFTFont *_fontBit5x7 = nullptr;
161 WWSurface *_roomAnimations[kRoomAnimationsCount] = {nullptr};
162 GxlArchive *_m00Gxl = nullptr;
163 GxlArchive *_m01Gxl = nullptr;
164 GxlArchive *_m02Gxl = nullptr;
165 GxlArchive *_m03Gxl = nullptr;
166 GxlArchive *_m05Gxl = nullptr;
167
168 GxlArchive *_r10Gxl = nullptr;
169
170 // Sound and Music
171 SoundManager *_sound = nullptr;
172 MusicManager *_midi = nullptr;
173
174 // Room
175 Common::String _roomName;
176 GxlArchive *_roomGxl = nullptr;
177 byte *_walkMap = nullptr;
178 int _scrollWidth = 0;
179 int _scrollRemaining = 0;
180 int _roomChangeCtr = 0;
181 int _scrollPosition = 0;
182 bool _doScrollRight = false;
183 bool _hasRoomAnimationCallback = false;
184
185 // Room animations
186 AnimationTimer _animationTimers[kAnimationTimersCount];
187
188 // Input
189 int _mouseX = 0, _mouseY = 0;
190 int _mouseClickY = 0, _mouseClickX = 0;
191 Common::Rect _mouseZone = {0, 0, 319, 199};
192 uint _mouseClickButtons = 0;
193 Common::KeyCode _keyCode = Common::KEYCODE_INVALID;
194
195 // Text
196 Common::String _currentText;
197 int _currentTextX = 0, _currentTextY = 0;
198 bool _isTextVisible = false;
199
200 // Audio
201 int _musicIndex = 0;
202
203 // Game
204 int _gameState; // TODO Use enum
205 int _currentActorNum;
206 int _currentRoomNumber;
207 int _verbNumber;
208 int _verbNumber2;
209 int _objectNumber;
210 int _hoverObjectNumber;
211 int _firstObjectNumber;
212 Common::String _firstObjectName;
213 int _roomEventNum;
214 int _animationsCtr;
215 bool _animationsRedrawBackground;
216
217 // Actors
218 int _wayneSpriteX, _wayneSpriteY, _wayneKind, _wayneActorScale;
219 int _garthSpriteX, _garthSpriteY, _garthKind, _garthActorScale;
220 int _actorSpriteValue;
221 int _actorSpriteIndex;
222 WWSurface *_wayneSprites[8], *_wayneWalkSprites[8][4], *_wayneReachRightSprite, *_wayneReachLeftSprite;
223 WWSurface *_garthSprites[8], *_garthWalkSprites[8][4], *_garthReachRightSprite, *_garthReachLeftSprite;
224 WalkPoint _wayneWalkPoints[kWalkPointsCount];
225 WalkPoint _garthWalkPoints[kWalkPointsCount];
226
227 // Inventory
228 WWSurface *_inventorySprite;
229 int _inventoryItemsCount;
230 int _inventoryItemsObjectMap[kInventorySize];
231 int _wayneInventory[kInventorySize];
232 int _garthInventory[kInventorySize];
233
234 // Dialog
235 int _selectedDialogChoice;
236 int _dialogChoices[5];
237
238 // Room objects
239 static const RoomObject kRoomObjects[kRoomObjectsCount];
240 // _roomObjects is a writable copy of kRoomObjects
241 RoomObject _roomObjects[kRoomObjectsCount];
242
243 // Static room objects
244 static const StaticRoomObjectMapEntry kStaticRoomObjectsMap[kStaticRoomObjectsMapCount];
245 static const StaticRoomObject kStaticRoomObjects[kStaticRoomObjectsCount];
246 // _staticRoomObjects is a writable copy of kStaticRoomObjects
247 StaticRoomObject _staticRoomObjects[kStaticRoomObjectsCount];
248 WWSurface *_staticRoomObjectSprites[kStaticRoomObjectSpritesCount];
249
250 // Game map
251 int _gameMapRoomNumber;
252 int _gameMapWayneSpriteX, _gameMapGarthSpriteX;
253 int _currentMapItemIndex;
254 int _gameMapDestinationRoomNum;
255 bool _gameMapFlag;
256 bool _gameMapHasPaletteHandler = false;
257 int _gameMapCtr = 0;
258 uint32 _gameMapLastTicks = 0;
259
260 // Intro
261 WWIntro *intro = nullptr;
262
263 // Utils
264 int getRandom(int max);
265 void waitMillis(uint millis);
266 void waitSeconds(uint seconds);
267
268 // Input handling
269 void initMouseCursor();
270 bool isPointAtWayne(int x, int y);
271 bool isPointAtGarth(int x, int y);
272 void updateMouseMove();
273 void handleMouseClick();
274 void handleMouseLeftClick();
275 void handleMouseRightClick();
276
277 // Palette loading
278 void loadPalette(GxlArchive *lib, const char *filename);
279
280 void paletteFadeIn(int index, int count, int stepsSize);
281 void paletteFadeOut(int index, int count, int stepsSize);
282 void paletteFadeColor(int index, byte r, byte g, byte b, int steps);
283 void handleMapPalette();
284
285 // Image drawing
286 void drawImageToSurfaceIntern(GxlArchive *lib, const char *filename, WWSurface *destSurface, int x, int y, bool transparent);
287 void drawImageToScreenIntern(GxlArchive *lib, const char *filename, int x, int y, bool transparent);
288 void drawImageToScreen(GxlArchive *lib, const char *filename, int x, int y);
289 void drawImageToSurface(GxlArchive *lib, const char *filename, WWSurface *destSurface, int x, int y);
290 void drawRoomImageToBackground(const char *filename, int x, int y);
291 void drawRoomImageToBackgroundTransparent(const char *filename, int x, int y);
292 void drawRoomImageToScreen(const char *filename, int x, int y);
293 void drawRoomImageToSurface(const char *filename, WWSurface *destSurface, int x, int y);
294
295 void drawSpiralEffect(Graphics::Surface *surface, int x, int y, int grainWidth, int grainHeight);
296 void drawRandomEffect(Graphics::Surface *surface, int x, int y, int grainWidth, int grainHeight);
297
298 // Text
299 Common::String loadString(const char *filename, int index, int flag);
300 void drawCurrentTextToSurface(WWSurface *destSurface, int x, int y);
301 void drawCurrentText(int x, int y, WWSurface *destSurface);
302 void displayText(const char *filename, int index, int flag, int x, int y, int drawToVirtual);
303 void displayTextLines(const char *filename, int baseIndex, int x, int y, int count);
304
305 // Audio
306 void playSound(const char *filename, int flag);
307 void changeMusic();
308 void stopMusic();
309
310 // Interface
311 void drawInterface(int verbNum);
312 void selectVerbNumber2(int x);
313 void selectVerbNumber(int x);
314 void changeActor();
315 void drawVerbLine(int verbNumber, int objectNumber, const char *objectName);
316 void rememberFirstObjectName(int objectId);
317
318 // Inventory
319 void redrawInventory();
320 void refreshInventory(bool doRefresh);
321 void drawInventory();
322 void setWayneInventoryItemQuantity(int objectId, int quantity);
323 void setGarthInventoryItemQuantity(int objectId, int quantity);
324 int getWayneInventoryItemQuantity(int objectId);
325 int getGarthInventoryItemQuantity(int objectId);
326
327 // Actors and animations
328 void loadMainActorSprites();
329 void unloadMainActorSprites();
330 int getActorScaleFromY(int actorY);
331 void drawActorReachObject(int objectId, int spriteIndex);
332 int drawActors(int direction, int wayneKind, int garthKind, int spriteIndex, int wayneX, int wayneY, int garthX, int garthY);
333 void refreshActors();
334 void pickupObject(int objectId, byte &flags, byte flagsSet, int inventoryObjectId);
335 void playAnimation(const char *prefix, int startIndex, int count, int x, int y, int flag, uint ticks);
336 void playAnimationLoops(const char *prefix, int startIndex, int count, int x, int y, int flag, uint ticks, int loopCount);
337 void setWaynePosition(int x, int y);
338 void setGarthPosition(int x, int y);
339 bool isActorWayne();
340 bool isActorGarth();
341 void selectActorWayne();
342 void selectActorGarth();
343 void toggleActor();
344
345 // Pathfinding
346 bool walkIsPixelWalkable(int x, int y);
347 bool walkAdjustDestPoint(int &x, int &y);
348 void walkGetNextPoint(int sourceX, int sourceY, int destX, int destY, int &nextX, int &nextY);
349 void walkCalcOtherActorDest(int flag, int &x, int &y);
350 int walkCalcPath(int flag, int sourceX, int sourceY, int destX, int destY, int pointsCount);
351 bool walkFindPoint(int flag, int &sourceX, int &sourceY, int &nextSourceX, int &nextSourceY, int destX, int destY, int pointsCount);
352 int walkAddWalkLine(int flag, int x1, int y1, int x2, int y2, int pointsCount);
353 bool walkTestPoint(int sourceX, int sourceY, int nextSourceX, int nextSourceY, int destX, int destY);
354 bool walkIsLineWalkable(int sourceX, int sourceY, int destX, int destY);
355 int walkCalcDirection(int deltaX, int deltaY);
356 bool walkTo(int actor1_destX, int actor1_destY, int direction, int actor2_destX, int actor2_destY);
357
358 void gxCloseLib(GxlArchive *lib);
359 void setMouseBounds(int x1, int x2, int y1, int y2);
360 // Room
361 void openRoomLibrary(int roomNum);
362 void openAlternateRoomLibrary(const char *name);
363 void loadRoomBackground();
364 void changeRoom(int roomNum);
365 void refreshRoomBackground(int roomNum);
366 void handleRoomEvent();
367 void changeRoomScrolling();
368 void loadScrollSprite();
369 void scrollRoom();
370 void loadRoomMask(int roomNum);
371 void fillRoomMaskArea(int x1, int y1, int x2, int y2, bool blocked);
372
373 // Room animations
374 void loadAnimationSpriteRange(int baseIndex, const char *filename, int count);
375 void loadAnimationSprite(int index, const char *filename);
376 void drawAnimationSprite(int index, int x, int y);
377 void drawAnimationSpriteTransparent(int index, int x, int y);
378 void updateRoomAnimations();
379 void startRoomAnimations();
380 void stopRoomAnimations();
381 void updateAnimationTimers();
382 void setAnimationTimer(uint index, uint32 delay, int initialCounter = 0);
383 bool isAnimationTimerExpired(uint index);
384 int getAnimationTimerCounter(uint index);
385
386 // Static room objects
387 void initStaticRoomObjects();
388 void loadStaticRoomObjects(int roomNum);
389 void unloadStaticRoomObjects();
390 void setStaticRoomObjectPosition(int roomNum, int fromIndex, int toIndex, int x, int y);
391 void drawStaticRoomObjects(int roomNum, int x, int y, int actorHeight, int actorWidth, WWSurface *surface);
392
393 // Room objects
394 void initRoomObjects();
395 void moveObjectToRoom(int objectId, int roomNum);
396 void moveObjectToNowhere(int objectId);
397 const RoomObject *getRoomObject(int objectId);
398 const char *getRoomObjectName(int objectId);
399 int getObjectRoom(int objectId);
400 int getObjectDirection(int objectId);
401 int findRoomObjectIdAtPoint(int x, int y);
402 void walkToObject();
403
404 // Dialog
405 void startDialog();
406 void setDialogChoices(int choice1, int choice2, int choice3, int choice4, int choice5);
407 void drawDialogChoices(int choiceIndex);
408 void handleDialogMouseClick();
409
410 // Verb handlers
411 void handleVerb(int verbFlag);
412 void handleVerbPickUp();
413 void handleVerbLookAt();
414 void handleVerbUse();
415 void handleVerbTalkTo();
416 void handleVerbPush();
417 void handleVerbPull();
418 void handleVerbExtremeCloseupOf();
419 void handleVerbGive();
420 void handleVerbOpen();
421 void handleVerbClose();
422
423 void lookAtUnusedTicket();
424 void unusedTicketHandleMouseMove();
425 void unusedTicketHandleMouseClick();
426
427 void extremeCloseUpHandleMouseClick();
428
429 void gameMapOpen();
430 void gameMapFinish();
431 void gameMapHandleMouseMove(int objectNumber);
432 void gameMapHandleMouseClick();
433 void gameMapSelectItem(const char *prefix, int animX, int animY);
434
435 void gameMapPaletteHandlerStart();
436 void gameMapPaletteHandlerStop();
437
438 // Savegame API
439
440 enum kReadSaveHeaderError {
441 kRSHENoError = 0,
442 kRSHEInvalidType = 1,
443 kRSHEInvalidVersion = 2,
444 kRSHEIoError = 3
445 };
446
447 struct SaveHeader {
448 Common::String description;
449 uint32 version;
450 byte gameID;
451 uint32 flags;
452 uint32 saveDate;
453 uint32 saveTime;
454 uint32 playTime;
455 Graphics::Surface *thumbnail;
456 };
457 void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header);
458
459 bool _isSaveAllowed; // not properly handled yet
460
461};
462
463} // End of namespace WaynesWorld
464
465#endif // WAYNESWORLD_H
Definition: error.h:81
Definition: savefile.h:54
Definition: random.h:44
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: engine.h:149
const Common::String _targetName
Definition: engine.h:186
EngineFeature
Definition: engine.h:282
Definition: musicplugin.h:131
Definition: system.h:166
Definition: graphics.h:45
Definition: gamelogic.h:30
Definition: graphics.h:65
Definition: graphics.h:30
Definition: waynesworld.h:112
Common::Error loadGameState(int slot) override
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
bool hasFeature(EngineFeature f) const override
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: waynesworld.h:127
Common::Error run() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: waynesworld.h:124
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: advancedDetector.h:164
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: atari-screen.h:58
Definition: waynesworld.h:84
Definition: waynesworld.h:63
Definition: waynesworld.h:54
Definition: waynesworld.h:75
Definition: waynesworld.h:71
Definition: waynesworld.h:80
Definition: waynesworld.h:447