ScummVM API documentation
twine.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 TWINE_TWINE_H
23#define TWINE_TWINE_H
24
25#include "common/platform.h"
26#include "common/random.h"
27#include "common/rect.h"
28#include "engines/advancedDetector.h"
29#include "engines/engine.h"
30
31#include "engines/metaengine.h"
32#include "graphics/managed_surface.h"
33#include "graphics/screen.h"
34#include "graphics/surface.h"
35#include "twine/detection.h"
36#include "twine/input.h"
37#include "twine/scene/actor.h"
38#include "twine/script/script_life.h"
39#include "twine/script/script_move.h"
40#include "twine/shared.h"
41
42namespace TwinE {
43
45#define EUROPE_VERSION 0
47#define USA_VERSION 1
49#define MODIFICATION_VERSION 2
50
52#define DEFAULT_FRAMES_PER_SECOND 20
53#define DEFAULT_HZ (1000 / DEFAULT_FRAMES_PER_SECOND)
54
55#define ORIGINAL_WIDTH 640
56#define ORIGINAL_HEIGHT 480
57
58static const struct TwinELanguage {
59 const char *name;
60 const char *id;
61 const int voice;
62} ListLanguage[] = { // TabLanguage
63 {"English", "EN_", 1},
64 {"French", "FR_", 2},
65 {"German", "DE_", 3},
66 {"Spanish", "SP_", 1},
67 {"Italian", "IT_", 1},
68 {"Portuguese", "", 1}};
69
70enum MidiFileType {
71 MIDIFILE_NONE,
72 MIDIFILE_DOS,
73 MIDIFILE_WIN
74};
75
77enum MovieType {
78 CONF_MOVIE_NONE = 0,
79 CONF_MOVIE_FLA = 1,
80 CONF_MOVIE_FLAWIDE = 2,
81 CONF_MOVIE_FLAGIF = 3
82};
83
88struct ConfigFile {
90 int32 _languageId = 0;
92 bool FlagDisplayText = false;
94 MidiFileType MidiType = MIDIFILE_NONE;
96 int32 Version = EUROPE_VERSION;
98 int32 Sound = 0;
100 int32 Movie = CONF_MOVIE_FLA;
102 int32 Fps = 0;
103
104 // these settings are not available in the original version
106 bool WallCollision = false;
108 bool UseAutoSaving = false;
109 bool Mouse = true;
110
111 // these settings can be changed in-game - and must be persisted
113 int32 ShadowMode = 0;
114 int32 PolygonDetails = 2;
116 bool SceZoom = false;
117};
118
119class Actor;
120class Animations;
121class Collision;
122class Extra;
123class GameState;
124class Grid;
125class Movements;
126class Interface;
127class Menu;
128class Movies;
129class MenuOptions;
130class Music;
131class Redraw;
132class Renderer;
133class Resources;
134class Scene;
135class Screens;
136class ScriptLifeV1;
137class ScriptMoveV1;
138class Holomap;
139class Sound;
140class Text;
141class DebugGrid;
142struct Keyboard;
143class Debug;
144class DebugState;
145
146// lba2
147class Buggy;
148class Dart;
149class Rain;
150class Wagon;
151
152enum class EngineState {
153 Menu,
154 GameLoop,
155 LoadedGame,
156 QuitGame
157};
158
159enum class SceneLoopState {
160 Continue = -1,
161 ReturnToMenu = 0,
162 Finished = 1
163};
164
166 TwinEEngine *_engine;
167 ScopedCursor(TwinEEngine *engine);
169};
170
172private:
173 TwinEEngine *_engine;
174 uint32 _fps;
175 uint32 _start;
176public:
177 FrameMarker(TwinEEngine *engine, uint32 fps = DEFAULT_FRAMES_PER_SECOND);
178 ~FrameMarker();
179};
180
182private:
183 using Super = Graphics::Screen;
184 TwinEEngine *_engine;
185 int _lastFrame = -1;
186
187public:
188 TwineScreen(TwinEEngine *engine);
189
190 void update() override;
191};
192
193
194int32 boundRuleThree(int32 val1, int32 val2, int32 nbstep, int32 step);
195
205int32 ruleThree32(int32 value, int32 start, int32 end, int32 t);
206
207class TwinEEngine : public Engine {
208private:
209 int32 _isTimeFreezed = 0;
210 int32 _saveFreezedTime = 0;
211 int32 _mouseCursorState = 0;
212 RealValue _realFalling; // mainLoopVar1
213 PauseToken _pauseToken;
214 TwineGameType _gameType;
215 EngineState _state = EngineState::Menu;
216 Common::String _queuedFlaMovie;
217
219 Common::Language _gameLang;
220
221 void processBookOfBu();
222 void processBonusList();
223 void processInventoryAction();
224 void processOptionsMenu();
225
226 void initConfigurations();
228 void initAll();
229 void introduction();
230 void processActorSamplePosition(int32 actorIdx);
232 void allocVideoMemory(int32 w, int32 h);
233
238 bool runGameEngine();
239public:
240 TwinEEngine(OSystem *system, Common::Language language, uint32 flagsTwineGameType, Common::Platform platform, TwineGameType gameType);
241 ~TwinEEngine() override;
242
243 Common::Error run() override;
244 bool hasFeature(EngineFeature f) const override;
245
246 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
247 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
248
250 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
251
252 int32 toSeconds(int x) const;
253 void wipeSaveSlot(int slot);
254 SaveStateList getSaveSlots() const;
255 void autoSave();
256
257 void pushMouseCursorVisible();
258 void popMouseCursorVisible();
259
260 bool isCDROM() const { return true; /* TODO */}
261 bool isLBA1() const { return _gameType == TwineGameType::GType_LBA; }
262 bool isLBA2() const { return _gameType == TwineGameType::GType_LBA2; }
263 bool isLBASlideShow() const { return _gameType == TwineGameType::GType_LBASHOW; }
264 bool isPreview() const { return (_gameFlags & TwinE::TF_PREVIEW) != 0; }
265 bool isMod() const { return (_gameFlags & TwinE::TF_MOD) != 0; }
266 bool isDotEmuEnhanced() const { return (_gameFlags & TwinE::TF_DOTEMU_ENHANCED) != 0; }
267 bool isLba1Classic() const { return (_gameFlags & TwinE::TF_LBA1_CLASSIC) != 0; }
268 bool isDemo() const { return (_gameFlags & ADGF_DEMO) != 0; };
269 bool isAndroid() const { return _platform == Common::Platform::kPlatformAndroid; };
270 const char *getGameId() const;
271 Common::Language getGameLang() const;
272
273 inline int numHoloPos() const {
274 const int maxLocations = isLBA1() ? MAX_HOLO_POS : MAX_HOLO_POS_2;
275 return maxLocations;
276 }
277
278 inline int getMaxLife() const {
279 return isLBA1() ? 50 : 255;
280 }
281
282 bool unlockAchievement(const Common::String &id);
283
284 Actor *_actor;
285 Animations *_animations;
286 Collision *_collision;
287 Extra *_extra;
288 GameState *_gameState;
289 Grid *_grid;
290 Movements *_movements;
291 Interface *_interface;
292 Menu *_menu;
293 Movies *_movie;
294 MenuOptions *_menuOptions;
295 Music *_music;
296 Redraw *_redraw;
297 Renderer *_renderer;
298 Resources *_resources;
299 Scene *_scene;
300 Screens *_screens;
301 Holomap *_holomap;
302 Sound *_sound;
303 Text *_text;
304 Input *_input;
305 Buggy *_buggy; // lba2
306 Dart *_dart; // lba2
307 Rain *_rain; // lba2
308 Wagon *_wagon; // lba2
309 DebugState *_debugState;
310
311 ScriptLife *_scriptLife;
312 ScriptMove *_scriptMove;
313
317
318 int32 _frameCounter = 0;
319 SceneLoopState _sceneLoopState = SceneLoopState::ReturnToMenu; // FlagTheEnd
320 int32 timerRef = 0;
321
322 int32 _loopInventoryItem = 0;
323 int32 _stepFalling = 0;
324 uint32 _gameFlags = 0u;
325 Common::Platform _platform;
326 bool _flagRain = false;
327
329 bool _cameraZone = false;
330
331 Graphics::ManagedSurface _imageBuffer;
336
337 int width() const;
338 int height() const;
339
340 // the resolution the game was meant to be played with
341 int originalWidth() const;
342 int originalHeight() const;
343
344 Common::Rect rect() const;
345 Common::Rect centerOnScreen(int32 w, int32 h) const;
346 Common::Rect centerOnScreenX(int32 w, int32 y, int32 h) const;
347
348 void extInitMcga();
349 void extInitSvga();
350 void testRestoreModeSVGA(bool redraw);
351
352 void queueMovie(const char *filename);
353
354 void clearScreenMinMax(Common::Rect &rect);
355 void adjustScreenMax(Common::Rect &rect, int16 x, int16 y);
356
360 int getRandomNumber(uint max = 0x7FFF);
361
362 void blitWorkToFront(const Common::Rect &rect);
363 void copyBlock(const Common::Rect &rect);
364 void restoreFrontBuffer();
365 void saveFrontBuffer();
366
367 void saveTimer(bool pause);
368 void restoreTimer();
369
374 bool mainLoop();
375
381 bool delaySkip(uint32 time);
382
387 void setPalette(const Graphics::Palette &palette, uint startColor = 0u);
388
396 void setPalette(uint startColor, uint numColors, const byte *palette);
397
405 void copyBlockPhys(int32 left, int32 top, int32 right, int32 bottom);
406 void copyBlockPhys(const Common::Rect &rect);
407
409 void readKeys();
410
418 void drawText(int32 x, int32 y, const Common::String &text, bool center = false, bool bigFont = false, int width = 100);
419};
420
421inline int TwinEEngine::width() const {
422 return _frontVideoBuffer.w;
423}
424
425inline int TwinEEngine::height() const {
426 return _frontVideoBuffer.h;
427}
428
429inline Common::Rect TwinEEngine::rect() const {
430 return Common::Rect(0, 0, _frontVideoBuffer.w - 1, _frontVideoBuffer.h - 1);
431}
432
433inline int TwinEEngine::originalWidth() const {
434 return 640;
435}
436
437inline int TwinEEngine::originalHeight() const {
438 return 480;
439}
440
441
442} // namespace TwinE
443
444#endif
Definition: error.h:81
Definition: random.h:44
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: managed_surface.h:51
int16 & w
Definition: managed_surface.h:134
int16 & h
Definition: managed_surface.h:135
Simple class for handling a palette data.
Definition: palette.h:61
Definition: screen.h:47
Definition: system.h:166
Definition: engine.h:110
Definition: actor.h:267
Definition: animations.h:34
Definition: buggy.h:35
Definition: collision.h:34
Definition: dart.h:35
Definition: debug_state.h:35
Definition: extra.h:87
Definition: twine.h:171
Definition: gamestate.h:42
Definition: grid.h:95
Definition: holomap.h:45
Definition: interface.h:36
Definition: menu.h:137
Definition: menuoptions.h:34
Definition: movements.h:34
Definition: movies.h:59
Definition: music.h:41
Definition: rain.h:32
Definition: redraw.h:93
Definition: renderer.h:100
Definition: resources.h:130
Definition: scene.h:115
Definition: screens.h:34
Definition: script_life_v1.h:31
Definition: script_move_v1.h:31
Definition: sound.h:53
Definition: text.h:48
Definition: twine.h:207
Graphics::ManagedSurface _workVideoBuffer
Definition: twine.h:333
int getRandomNumber(uint max=0x7FFF)
ConfigFile _cfgfile
Definition: twine.h:316
bool _cameraZone
Definition: twine.h:329
void drawText(int32 x, int32 y, const Common::String &text, bool center=false, bool bigFont=false, int width=100)
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: twine.h:246
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
TwineScreen _frontVideoBuffer
Definition: twine.h:335
void setPalette(const Graphics::Palette &palette, uint startColor=0u)
Common::Error run() override
bool delaySkip(uint32 time)
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
void copyBlockPhys(int32 left, int32 top, int32 right, int32 bottom)
void setPalette(uint startColor, uint numColors, const byte *palette)
Set the Palette object.
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
bool hasFeature(EngineFeature f) const override
Definition: twine.h:181
void update() override
Definition: wagon.h:30
Language
Definition: language.h:45
Platform
Definition: platform.h:93
@ ADGF_DEMO
Add "-demo" to gameid.
Definition: advancedDetector.h:157
Definition: rect.h:536
Definition: twine.h:88
int32 Fps
Definition: twine.h:102
bool FlagDisplayText
Definition: twine.h:92
int32 Movie
Definition: twine.h:100
bool UseAutoSaving
Definition: twine.h:108
MidiFileType MidiType
Definition: twine.h:94
bool WallCollision
Definition: twine.h:106
int32 _languageId
Definition: twine.h:90
bool SceZoom
Definition: twine.h:116
int32 Version
Definition: twine.h:96
int32 ShadowMode
Definition: twine.h:113
Definition: actor.h:40
Definition: twine.h:165