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