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