ScummVM API documentation
darkseed.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 DARKSEED_H
23#define DARKSEED_H
24
25#include "common/error.h"
26#include "common/fs.h"
27#include "common/keyboard.h"
28#include "common/random.h"
29#include "common/scummsys.h"
30#include "common/serializer.h"
31#include "common/system.h"
32#include "common/util.h"
33#include "engines/engine.h"
34#include "graphics/screen.h"
35
36#include "darkseed/animation.h"
37#include "darkseed/console.h"
38#include "darkseed/cursor.h"
39#include "darkseed/cutscene.h"
40#include "darkseed/detection.h"
41#include "darkseed/inventory.h"
42#include "darkseed/menu.h"
43#include "darkseed/nsp.h"
44#include "darkseed/objects.h"
45#include "darkseed/player.h"
46#include "darkseed/room.h"
47#include "darkseed/sound.h"
48#include "darkseed/sprites.h"
49#include "darkseed/tostext.h"
50#include "darkseed/usecode.h"
51
52namespace Darkseed {
53
54struct DarkseedGameDescription;
55
56enum DarkseedAction {
57 kDarkseedActionNone,
58 kDarkseedActionSelect,
59 kDarkseedActionChangeCommand,
60 kDarkseedActionTimeAdvance,
61 kDarkseedActionQuit,
62 kDarkseedActionSkipCutscene
63};
64
65enum ActionMode : uint8 {
66 kPointerAction = 0,
67 kHandAction = 2,
68 kLookAction = 3,
69 kUseStickAction = 19,
70 kUseHammerAction = 27,
71};
72
73enum class FadeDirection : uint8 {
74 NONE,
75 IN,
76 OUT
77};
78
79class DarkseedEngine : public Engine {
80 const ADGameDescription *_gameDescription;
81 Common::RandomSource _randomSource;
82 Pic *_fullscreenPic = nullptr;
83 bool _timeAdvanceEventSelected = false;
84 uint8 _delbertspeech = 0;
85 int16 _yvec = 0; //delbert throw stick related.
86 bool _normalWorldSpritesLoaded = true;
87 bool _redrawFrame = true;
88 bool _restartGame = false;
89 bool _canSaveGame = false;
90
91 FadeDirection _fadeDirection = FadeDirection::NONE;
92 uint8 _fadeStepCounter = 0;
93 Pal _fadeTempPalette;
94 Pal _fadeTargetPalette;
95
96protected:
97 // Engine APIs
98 Common::Error run() override;
99public:
100 Pic _frame;
101
102 bool _ct_voice_status = false;
103 bool _isRightMouseClicked = false;
104 bool _isLeftMouseClicked = false;
105 Common::KeyCode _lastKeyPressed = Common::KeyCode::KEYCODE_INVALID;
106
107 Sound *_sound = nullptr;
108 Nsp _baseSprites;
109 Cursor _cursor;
110 Graphics::Screen *_screen = nullptr;
111 TosText *_tosText = nullptr;
112 Console *_console = nullptr;
113 Room *_room = nullptr;
114 int _actionMode = kPointerAction;
115 Player *_player = nullptr;
116 Sprites _sprites;
117 Objects _objectVar;
118 Inventory _inventory;
119 UseCode *_useCode = nullptr;
120 Cutscene _cutscene;
121 Animation *_animation = nullptr;
122 Menu *_menu = nullptr;
123
124 uint8 _currentDay = 1;
125 int _currentTimeInSeconds = 0x7e8e;
126 int _fttime = 0;
127
128 uint8 _previousRoomNumber = 0;
129 uint16 _targetRoomNumber = 0;
130
131 uint16 _headAcheMessageCounter = 0;
132 uint8 _headacheMessageIdx = 0;
133
134 int _sprite_y_scaling_threshold_maybe = 0xf0;
135 int _scaledWalkSpeed_maybe = 0;
136 uint16 _scaledSpriteWidth = 0;
137 uint16 _scaledSpriteHeight = 0;
138
139 int _frameBottom = 0;
140
141 // Unknown variables
142 bool _doorEnabled = false;
143 bool _useDoorTarget = false;
144
145 int16 _counter_2c85_888b = 0;
146
147 uint8 _targetPlayerDirection = 0; // related to changing rooms.
148
149 uint8 _systemTimerCounter = 0;
150
151 bool _debugShowWalkPath = false;
152 int _phoneStatus = 0;
153
154 int16 _soundTimer = 0;
155 bool _printedcomeheredawson = false;
156 void zeroMouseButtons();
157 void updateEvents();
158
159 void gotoNextMorning();
160
161 void playDayChangeCutscene();
162
163 void removeFullscreenPic();
164
165 void wait();
166
167 void waitForSpeech();
168 void waitForSpeechOrSfx();
169
170 void syncSoundSettings() override;
171 void pauseEngineIntern(bool pause) override;
172
173 DarkseedEngine(OSystem *syst, const ADGameDescription *gameDesc);
174 ~DarkseedEngine() override;
175
176 uint32 getFeatures() const;
177
178 Common::Language getLanguage() const {
179 return _gameDescription->language;
180 }
181
186
190 uint32 getRandomNumber(uint maxNum) {
191 return _randomSource.getRandomNumber(maxNum);
192 }
193
194 bool isDosVersion() const {
195 return _gameDescription->platform == Common::kPlatformDOS;
196 }
197
198 bool isCdVersion() const {
199 return getFeatures() & ADGF_CD;
200 }
201
202 bool isDosFloppy() const {
203 return isDosVersion() && !isCdVersion();
204 }
205
206 bool isDosDemo() const {
207 return isDosVersion() && getFeatures() & ADGF_DEMO;
208 }
209
210 bool hasFeature(EngineFeature f) const override {
211 return
215 };
216
218 return !isDosDemo() && !_animation->_isPlayingAnimation_maybe && !_player->_isAutoWalkingToBed && !_player->_heroWaiting && !_cutscene.isPlaying();
219 }
220
222 return _canSaveGame && !_animation->_isPlayingAnimation_maybe && !_player->_isAutoWalkingToBed && !_player->_heroWaiting && !_cutscene.isPlaying() && !_menu->isOpen();
223 }
224
230
231 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
232 Common::Serializer s(nullptr, stream);
233 return syncGame(s);
234 }
235
237 Common::Serializer s(stream, nullptr);
238 Common::Error syncResult = syncGame(s);
239 if (syncResult.getCode() == Common::kNoError) {
240 changeToRoom(_room->_roomNumber);
241 }
242 _canSaveGame = true;
243 return syncResult;
244 }
245
246 Common::Path getRoomFilePath(const Common::Path &filename) const;
247 Common::Path getPictureFilePath(const Common::Path &filename) const;
248
249 void fadeIn(const Pal &palette);
250 void fadeOut();
251 bool fadeStep();
252
253 void restartGame();
254 void newGame();
255
256 void updateDisplay();
257 void debugTeleportToRoom(int newRoomNumber, int entranceNumber);
258 void showFullscreenPic(const Common::Path &filename);
259 void drawFullscreenPic();
260 void lookCode(int objNum);
261 void handleObjCollision(int targetObjNum);
262 void playSound(uint8 sfxId, uint8 priority, int16 unk2);
263 void nextFrame(int nspAminIdx);
264
265 void throwmikeinjail();
266 void runObjects();
267 void getPackageObj(int packageType);
268 void printTime();
269 void changeToRoom(int newRoomNumber, bool placeDirectly = false);
270 void waitxticks(int ticks);
271
272 void doCircles();
273
274private:
275 void updateBaseSprites();
276 void gameLoop();
277
278 void handleInput();
279 void handlePointerAction();
280 void loadRoom(int roomNumber);
281
282 void gotoSleepInJail();
283
284 void updateHeadache();
285 void closeShops();
286 void initDelbertAtSide();
287 void movePlayerToDelbert();
288 void delbertThrowStick(int16 spriteNum);
289 void leavePackage();
290 void copyLine(const Graphics::Surface &surface, int16 x1, int16 x2, int16 y);
291};
292
293extern DarkseedEngine *g_engine;
294#define SHOULD_QUIT ::Darkseed::g_engine->shouldQuit()
295
296} // End of namespace Darkseed
297
298#endif // DARKSEED_H
Definition: error.h:81
ErrorCode getCode() const
Definition: error.h:112
Definition: path.h:52
Definition: random.h:44
uint getRandomNumber(uint max)
Definition: stream.h:745
Definition: serializer.h:80
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: animation.h:28
Definition: console.h:32
Definition: cursor.h:40
Definition: cutscene.h:34
Definition: darkseed.h:79
void syncSoundSettings() override
Common::Error run() override
Common::Error syncGame(Common::Serializer &s)
Common::String getGameId() const
bool hasFeature(EngineFeature f) const override
Definition: darkseed.h:210
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: darkseed.h:236
bool canLoadGameStateCurrently(Common::U32String *msg) override
Definition: darkseed.h:217
void pauseEngineIntern(bool pause) override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Definition: darkseed.h:231
uint32 getRandomNumber(uint maxNum)
Definition: darkseed.h:190
bool canSaveGameStateCurrently(Common::U32String *msg) override
Definition: darkseed.h:221
Definition: inventory.h:27
Definition: menu.h:30
Definition: nsp.h:61
Definition: objects.h:36
Definition: pal.h:34
Definition: pic.h:31
Definition: player.h:31
Definition: room.h:57
Definition: sound.h:60
Definition: sprites.h:42
Definition: tostext.h:31
Definition: usecode.h:33
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
@ kSupportsReturnToLauncher
Definition: engine.h:296
@ kSupportsSavingDuringRuntime
Definition: engine.h:314
@ kSupportsLoadingDuringRuntime
Definition: engine.h:305
Definition: screen.h:47
Definition: system.h:166
@ kNoError
No error occurred.
Definition: error.h:48
Language
Definition: language.h:45
@ ADGF_DEMO
Add "-demo" to gameid.
Definition: advancedDetector.h:157
@ ADGF_CD
Add "-cd" to gameid.
Definition: advancedDetector.h:155
Engine * g_engine
Definition: advancedDetector.h:164
Common::Platform platform
Definition: advancedDetector.h:199
Common::Language language
Definition: advancedDetector.h:194
Definition: surface.h:67