ScummVM API documentation
freescape.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 FREESCAPE_H
23#define FREESCAPE_H
24
25#include "common/bitarray.h"
26#include "common/events.h"
27#include "common/file.h"
28#include "common/memstream.h"
29#include "engines/advancedDetector.h"
30#include "graphics/managed_surface.h"
31#include "graphics/surface.h"
32
33
34#include "audio/decoders/wave.h"
35#include "audio/mixer.h"
36#include "audio/softsynth/pcspk.h"
37#include "graphics/framelimiter.h"
38
39#include "freescape/area.h"
40#include "freescape/font.h"
41#include "freescape/gfx.h"
42#include "freescape/language/variables.h"
43#include "freescape/objects/entrance.h"
44#include "freescape/objects/geometricobject.h"
45#include "freescape/objects/sensor.h"
46#include "freescape/sound.h"
47
48namespace Common {
49class RandomSource;
50}
51
52namespace Freescape {
53
54class Renderer;
55class Debugger;
56
57bool isEncodedCPCDirectColor(uint8 index);
58uint8 encodeCPCDirectColor(uint8 index);
59uint8 decodeCPCDirectColor(uint8 index);
60
61#define FREESCAPE_DATA_BUNDLE "freescape.dat"
62
63enum CameraMovement {
64 kForwardMovement,
65 kBackwardMovement,
66 kLeftMovement,
67 kRightMovement
68};
69
70enum FreescapeAction {
71 kActionNone,
72 kActionEscape,
73 kActionSave,
74 kActionLoad,
75 kActionToggleSound,
76 kActionMoveUp,
77 kActionMoveDown,
78 kActionMoveLeft,
79 kActionMoveRight,
80 kActionShoot,
81 kActionActivate,
82 kActionIncreaseAngle,
83 kActionDecreaseAngle,
84 kActionChangeStepSize,
85 kActionToggleRiseLower,
86 kActionRiseOrFlyUp,
87 kActionLowerOrFlyDown,
88 kActionChangeMode,
89 kActionSkip,
90 kActionFaceForward,
91 kActionRotateUp,
92 kActionRotateDown,
93 kActionRotateLeft,
94 kActionRotateRight,
95 kActionTurnBack,
96 kActionInfoMenu,
97 kActionIncreaseStepSize,
98 kActionDecreaseStepSize,
99 kActionToggleFlyMode,
100 kActionToggleClipMode,
101 // Driller
102 kActionDeployDrillingRig,
103 kActionCollectDrillingRig,
104 kActionRollLeft,
105 kActionRollRight,
106 // Total Eclipse
107 kActionRest,
108 // Castle
109 kActionRunMode,
110 kActionWalkMode,
111 kActionCrawlMode,
112 kActionRunModifier, // Shift-to-run: held = run, released = walk
113 kActionSelectPrince,
114 kActionSelectPrincess,
115 kActionQuit,
116 kActionToggleFlashlight,
117 kActionToggleStereoscopic,
118
119 // Demo actions
120 kActionUnknownKey,
121 kActionWait
122};
123
124typedef Common::HashMap<uint16, Area *> AreaMap;
125typedef Common::Array<byte *> ColorMap;
126typedef Common::HashMap<uint16, int32> StateVars;
127
128enum {
129 kFreescapeDebugMove = 1,
130 kFreescapeDebugParser,
131 kFreescapeDebugCode,
132 kFreescapeDebugMedia,
133 kFreescapeDebugGroup,
134};
135
136enum {
137 kFreescapeDefaultVolume = 192,
138};
139
140enum GameStateControl {
141 kFreescapeGameStateStart,
142 kFreescapeGameStatePlaying,
143 kFreescapeGameStateDemo,
144 kFreescapeGameStateEnd,
145 kFreescapeGameStateRestart,
146};
147
148extern byte kEGADefaultPalette[16][3];
149extern byte kCGAPaletteRedGreen[4][3];
150extern byte kCGAPalettePinkBlue[4][3];
151extern byte kCGAPalettePinkBlueBright[4][3];
152extern byte kCGAPaletteRedGreenBright[4][3];
153extern byte kHerculesPaletteGreen[2][3];
154
156 int areaId;
157 byte *palette;
158};
159
160extern Common::String shiftStr(const Common::String &str, int shift);
161extern Common::String centerAndPadString(const Common::String &str, int size);
162extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode1);
163
165public:
167 // EventManager API
168 bool pollEvent(Common::Event &event);
169 void purgeKeyboardEvents();
170 void purgeMouseEvents();
171 void pushEvent(Common::Event &event);
172 void clearExitEvents();
173 bool isActionActive(const Common::CustomEventType &action);
174 bool isKeyPressed();
175
176private:
177 // for continuous events (keyDown)
178 enum {
179 kKeyRepeatInitialDelay = 400,
180 kKeyRepeatSustainDelay = 100
181 };
182
183 Common::EventManager *_delegate;
184
185 Common::KeyState _currentKeyDown;
186 Common::CustomEventType _currentActionDown; // last action for key repeat
187 Common::Array<Common::CustomEventType> _activeActions; // all currently held actions
188 uint32 _keyRepeatTime;
189};
190
191class FreescapeEngine : public Engine {
192
193public:
194 FreescapeEngine(OSystem *syst, const ADGameDescription *gd);
196
197 const ADGameDescription *_gameDescription;
198 GameStateControl _gameStateControl;
199 bool isDemo() const;
200
201 // Game selection
202 uint32 _variant;
203 Common::Language _language;
204 bool isSpaceStationOblivion() { return _targetName.hasPrefix("spacestationoblivion"); }
205 bool isDriller() { return _targetName.hasPrefix("driller") || _targetName.hasPrefix("spacestationoblivion"); }
206 bool isDark() { return _targetName.hasPrefix("darkside"); }
207 bool isEclipse() { return _targetName.hasPrefix("totaleclipse"); } // This will match Total Eclipse 1 and 2.
208 bool isEclipse2() { return _targetName.hasPrefix("totaleclipse2"); }
209 bool isCastle() { return _targetName.hasPrefix("castle"); }
210 bool isCastleMaster2() { return _targetName.hasPrefix("castlemaster2"); }
211 bool isAmiga() { return _gameDescription->platform == Common::kPlatformAmiga; }
212 bool isAtariST() { return _gameDescription->platform == Common::kPlatformAtariST; }
213 bool isDOS() { return _gameDescription->platform == Common::kPlatformDOS; }
214 bool isSpectrum() { return _gameDescription->platform == Common::kPlatformZX; }
215 bool isCPC() { return _gameDescription->platform == Common::kPlatformAmstradCPC; }
216 bool isC64() { return _gameDescription->platform == Common::kPlatformC64; }
217
218 virtual void beforeStarting();
219 Common::Error run() override;
220
221 // UI
222 Common::Rect _viewArea;
223 Common::Rect _fullscreenViewArea;
224 void centerCrossair();
225
226 virtual void borderScreen();
227 virtual void titleScreen();
228
229 void drawFullscreenSurface(Graphics::Surface *surface);
230 virtual void loadBorder();
231 virtual void processBorder();
232 void waitInLoop(int maxWait);
233 void drawBorder();
234 void drawTitle();
235 virtual void drawBackground();
236 void clearBackground();
237 void drawPlatformUI(Graphics::Surface *surface);
238 virtual void drawUI();
239 virtual void drawInfoMenu();
240 void drawBorderScreenAndWait(Graphics::Surface *surface, int maxWait = INT_MAX);
241
242 virtual void drawCrossair(Graphics::Surface *surface);
245 Graphics::ManagedSurface *_background;
246
247 Texture *_borderTexture;
248 Texture *_titleTexture;
249 Texture *_uiTexture;
250 Texture *_skyTexture;
251
253 Common::HashMap<uint16, Texture *> _borderCGAByArea;
254 Common::HashMap<uint16, byte *> _paletteCGAByArea;
255
256 // Parsing assets
257 uint8 _binaryBits;
258 virtual void loadAssets();
259 virtual void loadAssetsDemo();
260 virtual void loadAssetsFullGame();
261
262 virtual void loadAssetsAtariFullGame();
263 virtual void loadAssetsAtariDemo();
264
265 virtual void loadAssetsAmigaFullGame();
266 virtual void loadAssetsAmigaDemo();
267
268 virtual void loadAssetsDOSFullGame();
269 virtual void loadAssetsDOSDemo();
270
271 virtual void loadAssetsZXFullGame();
272 virtual void loadAssetsZXDemo();
273
274 virtual void loadAssetsCPCFullGame();
275 virtual void loadAssetsCPCDemo();
276
277 virtual void loadAssetsC64FullGame();
278 virtual void loadAssetsC64Demo();
279
280 virtual void drawDOSUI(Graphics::Surface *surface);
281 virtual void drawZXUI(Graphics::Surface *surface);
282 virtual void drawCPCUI(Graphics::Surface *surface);
283 virtual void drawC64UI(Graphics::Surface *surface);
284 virtual void drawAmigaAtariSTUI(Graphics::Surface *surface);
285
286 Common::Archive *_dataBundle;
287 void loadDataBundle();
288 Graphics::Surface *loadBundledImage(const Common::String &name, bool appendRenderMode = true);
289 byte *getPaletteFromNeoImage(Common::SeekableReadStream *stream, int offset);
290 Graphics::ManagedSurface *loadAndConvertNeoImage(Common::SeekableReadStream *stream, int offset, byte *palette = nullptr);
291 void decodeAmigaSprite(Common::SeekableReadStream *file, Graphics::ManagedSurface *surf,
292 int dataOffset, int widthWords, int height, byte *palette);
293 Graphics::ManagedSurface *loadAndConvertScrImage(Common::SeekableReadStream *stream);
294 Graphics::ManagedSurface *loadFrame(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, uint32 front);
295 Graphics::ManagedSurface *loadFrameCPCIndexed(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int widthBytes, int height);
296 Graphics::ManagedSurface *loadAndConvertDoodleImage(Common::SeekableReadStream *bitmap, Common::SeekableReadStream *color1, Common::SeekableReadStream *color2, byte *palette);
297
298 void loadPalettes(Common::SeekableReadStream *file, int offset);
299 byte *loadPalette(Common::SeekableReadStream *file);
300 void swapPalette(uint16 areaID);
301 virtual byte *findCGAPalette(uint16 levelID);
302 Common::HashMap<uint16, byte *> _paletteByArea;
303 void loadColorPalette();
304
305 // Demo
306 Common::Array<byte> _demoData;
307 int _demoIndex;
308 int _currentDemoInputCode;
309 int _currentDemoInputRepetition;
311 Common::Point _currentDemoMousePosition;
312 void loadDemoData(Common::SeekableReadStream *file, int offset, int size);
313 int decodeAmigaAtariKey(int code);
314 int decodeDOSKey(int code);
315 Common::Event decodeDOSMouseEvent(int code, int repetition);
316
317 uint16 readField(Common::SeekableReadStream *file, int nbits);
318 uint16 readPtr(Common::SeekableReadStream *file);
319 Common::Array<uint16> readArray(Common::SeekableReadStream *file, int size);
320
321 // 8-bit
322 void load8bitBinary(Common::SeekableReadStream *file, int offset, int ncolors);
323 Area *load8bitArea(Common::SeekableReadStream *file, uint16 ncolors);
324 Object *load8bitObject(Common::SeekableReadStream *file);
325 Group *load8bitGroup(Common::SeekableReadStream *file, byte rawFlagsAndType);
326 Group *load8bitGroupV1(Common::SeekableReadStream *file, byte rawFlagsAndType);
327 Group *load8bitGroupV2(Common::SeekableReadStream *file, byte rawFlagsAndType);
328
329 void loadGlobalObjects(Common::SeekableReadStream *file, int offset, int size);
330 void renderPixels8bitBinImage(Graphics::ManagedSurface *surface, int row, int column, int bit, int count);
331
332 void renderPixels8bitBinCGAImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color);
333 void renderPixels8bitBinEGAImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color);
334
335 Graphics::ManagedSurface *load8bitBinImage(Common::SeekableReadStream *file, int offset);
336 void load8bitBinImageRow(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row);
337 void load8bitBinImageRowIteration(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int bit);
338 int execute8bitBinImageCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int pixels, int bit);
339 int execute8bitBinImageSingleCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int pixels, int bit, int count);
340 int execute8bitBinImageMultiCommand(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int row, int pixels, int bit, int count);
341
342 void parseAmigaAtariHeader(Common::SeekableReadStream *file);
343 Common::SeekableReadStream *decryptFileAmigaAtari(const Common::Path &packed, const Common::Path &unpacker, uint32 unpackArrayOffset);
344 Common::SeekableReadStream *decryptFileAmigaAtari(const Common::Path &packed, Common::SeekableReadStream *unpacker, uint32 unpackArrayOffset);
345 Common::SeekableReadStream *decryptFileAtariVirtualWorlds(const Common::Path &filename);
346
347 // Areas
348 uint16 _startArea;
349 uint16 _endArea;
350 AreaMap _areaMap;
351 Area *_currentArea;
352 bool _gotoExecuted;
353 Math::Vector3d _scale;
354
355 virtual void gotoArea(uint16 areaID, int entranceID);
356 // Entrance
357 uint16 _startEntrance;
358 uint16 _endEntrance;
360
361 // Input
362 bool _demoMode;
363 bool _disableDemoMode;
364 bool _flyMode;
365 bool _shootMode;
366 bool _noClipMode;
367 bool _invertY;
368
369 bool _smoothMovement;
370 bool _useWASDControls;
371 bool _debugSimulateTouchscreen;
372 bool isTouchscreenActive() const;
373 void setIOSGamepadControllerEnabled(bool enabled);
374 void restoreIOSGamepadControllerSettings();
375#ifdef IPHONE
376 struct IOSGamepadControllerSetting {
377 bool present;
378 Common::String value;
379 };
380 bool _iosGamepadControllerSettingsSaved;
381 Common::String _iosGamepadControllerDomain;
382 IOSGamepadControllerSetting _iosGamepadController;
383 IOSGamepadControllerSetting _iosGamepadControllerMinimalLayout;
384 IOSGamepadControllerSetting _iosGamepadControllerDirectionalInput;
385#endif
386 // Player movement state
387 bool _moveForward;
388 bool _moveBackward;
389 bool _strafeLeft;
390 bool _strafeRight;
391 bool _moveUp;
392 bool _moveDown;
393
394 virtual void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target);
395 EventManagerWrapper *_eventManager;
396 void processInput();
397 virtual bool handleInput(const Common::Event &event) { return false; }
398 void resetInput();
399 void stopMovement();
400 void generateDemoInput();
401 virtual void pressedKey(const int keycode);
402 virtual void releasedKey(const int keycode);
403 Common::Point getNormalizedPosition(Common::Point position);
404 virtual bool onScreenControls(Common::Point mouse);
405 virtual void updatePlayerMovement(float deltaTime);
406 void updatePlayerMovementSmooth(float deltaTime);
407 void updatePlayerMovementClassic(float deltaTime);
408 void resolveCollisions(Math::Vector3d newPosition);
409 virtual Math::Vector3d clipPosition(const Math::Vector3d &position) const { return position; }
410 virtual void checkIfStillInArea();
411 void changePlayerHeight(int index);
412 void increaseStepSize();
413 void decreaseStepSize();
414 void changeStepSize();
415
416 void changeAngle(int offset, bool wrapAround);
417 bool rise();
418 void lower();
419 bool checkFloor(Math::Vector3d currentPosition);
420 bool tryStepUp(Math::Vector3d currentPosition);
421 bool tryStepDown(Math::Vector3d currentPosition);
422 bool _hasFallen;
423 bool _isCollidingWithWall;
424 bool _isSteppingUp;
425 bool _isSteppingDown;
426 bool _isFalling;
427 int _maxFallingDistance;
428 int _maxShield;
429 int _maxEnergy;
430
431 void rotate(float xoffset, float yoffset, float zoffset);
432 // Input state
433 float _lastFrame;
434
435 // Interaction
436 void activate();
437 void shoot();
438 void traverseEntrance(uint16 entranceID);
439
440 // Euler Angles
441 float _yaw;
442 float _pitch;
443 int _roll;
444 int _angleRotationIndex;
445 Common::Array<float> _angleRotations;
446
447 Math::Vector3d directionToVector(float pitch, float heading, bool useTable);
448 void updateCamera();
449 virtual void onRotate(float xoffset, float yoffset, float zoffset) {}
450
451 // Camera options
452 Common::Point _crossairPosition;
453 float _mouseSensitivity;
454 Math::Vector3d _upVector; // const
455 Math::Vector3d _cameraFront, _cameraRight;
456 // Spacial attributes
457 Math::Vector3d _position, _rotation, _velocity;
458 Math::Vector3d _lastPosition;
459 int _playerHeightNumber;
460 int _playerHeightMaxNumber;
461 uint16 _playerHeight;
462 uint16 _playerWidth;
463 uint16 _playerDepth;
464 uint16 _stepUpDistance;
465
466 int _playerStepIndex;
467 int _savedPlayerStepIndex; // saved before shift-to-run, restored on release
468 Common::Array<int> _playerSteps;
469
470 Common::Point crossairPosToMousePos(const Common::Point &crossairPos);
471 Common::Point mousePosToCrossairPos(const Common::Point &mousePos);
472 void warpMouseToCrossair(void);
473
474 // Effects
475 Common::Array<Common::String> _conditionSources;
477
478 bool runCollisionConditions(Math::Vector3d const lastPosition, Math::Vector3d const newPosition);
479 Math::Vector3d _objExecutingCodeSize;
480 bool _executingGlobalCode;
481 virtual void executeMovementConditions();
482 virtual bool executeObjectConditions(GeometricObject *obj, bool shot, bool collided, bool activated);
483 void executeEntranceConditions(Entrance *entrance);
484 virtual void executeLocalGlobalConditions(bool shot, bool collided, bool timer);
485 virtual void updateScripts() {}
486 bool executeCode(FCLInstructionVector &code, bool shot, bool collided, bool timer, bool activated);
487
488 // Instructions
489 bool checkConditional(const FCLInstruction &instruction, bool shot, bool collided, bool timer, bool activated);
490 bool checkIfGreaterOrEqual(FCLInstruction &instruction);
491 bool checkIfLessOrEqual(FCLInstruction &instruction);
492 void executeCall(FCLInstruction &instruction);
493 void executeIncrementVariable(FCLInstruction &instruction);
494 void executeDecrementVariable(FCLInstruction &instruction);
495 void executeSetVariable(FCLInstruction &instruction);
496 void executeGoto(FCLInstruction &instruction);
497 virtual void executeMakeInvisible(FCLInstruction &instruction);
498 void executeMakeVisible(FCLInstruction &instruction);
499 void executeToggleVisibility(FCLInstruction &instruction);
500 virtual void executeDestroy(FCLInstruction &instruction);
501 virtual void executeRedraw(FCLInstruction &instruction);
502 void executeSound(FCLInstruction &instruction);
503 void executeDelay(FCLInstruction &instruction);
504 bool executeEndIfNotEqual(FCLInstruction &instruction);
505 void executeSetBit(FCLInstruction &instruction);
506 void executeClearBit(FCLInstruction &instruction);
507 void executeToggleBit(FCLInstruction &instruction);
508 bool executeEndIfBitNotEqual(FCLInstruction &instruction);
509 bool executeEndIfVisibilityIsEqual(FCLInstruction &instruction);
510 void executeSwapJet(FCLInstruction &instruction);
511 virtual void executePrint(FCLInstruction &instruction);
512 void executeSPFX(FCLInstruction &instruction);
513 void executeStartAnim(FCLInstruction &instruction);
514
515 // Sound
516 Audio::SoundHandle _soundFxHandle;
517 Audio::SoundHandle _musicHandle;
518 Sound *_sound;
519
520 bool _syncSound;
521 bool _firstSound;
522 bool _usePrerecordedSounds;
523 void waitForSounds(Sound::Type type = Sound::kTypeNormal);
524 void stopAllSounds(Sound::Type type = Sound::kTypeNormal);
525 bool isPlayingSound(Sound::Type type = Sound::kTypeNormal);
526 virtual void playSound(int index, bool sync, Sound::Type type = Sound::kTypeNormal);
527 void playWav(const Common::Path &filename);
528 void playMusic(const Common::Path &filename);
529
530 virtual void playSoundFx(int index, bool sync, Sound::Type type = Sound::kTypeNormal) {}
531 Sound *loadSoundsFx(Common::SeekableReadStream *file, int offset, int number);
532 Sound *loadSoundsFxDOS(Common::SeekableReadStream *file, int offset, int number);
533 Sound *loadSpeakerFxDOS(Common::SeekableReadStream *file, int offsetFreq, int offsetDuration, int numberSounds);
534 Sound *loadSpeakerFxZX(Common::SeekableReadStream *file, int sfxTable, int sfxData, int numberSounds);
535 Sound *loadSpeakerFxDrillerZX();
536 Sound *loadSoundsCPC(Common::SeekableReadStream *file, int offsetTone, int sizeTone, int offsetEnvelope, int sizeEnvelope, int offsetSoundDef, int sizeSoundDef);
537 // sampleBank names the external PCM bank, modOffset points at the embedded
538 // module used for one extra sample; both are optional (empty path, -1)
539 Sound *loadSoundsAmiga(Common::SeekableReadStream *file, int offset, int numSounds, const Common::Path &sampleBank, int modOffset);
540 Sound *loadSoundsAtariCastle(Common::SeekableReadStream *file, int offset, int numSounds, int bankOffset);
541
542 int _soundIndexShoot;
543 int _soundIndexCollide;
544 int _soundIndexStepDown;
545 int _soundIndexStepUp;
546 int _soundIndexFall;
547 int _soundIndexMenu;
548 int _soundIndexStart;
549 int _soundIndexAreaChange;
550 int _soundIndexHit;
551
552 int _soundIndexNoShield;
553 int _soundIndexNoEnergy;
554 int _soundIndexFallen;
555 int _soundIndexTimeout;
556 int _soundIndexForceEndGame;
557 int _soundIndexCrushed;
558 int _soundIndexMissionComplete;
559
560 // Rendering
561 int _screenW, _screenH;
562 Renderer *_gfx;
563 Graphics::FrameLimiter *_frameLimiter;
564 bool _vsyncEnabled;
565 Common::RenderMode _renderMode;
566 ColorMap _colorMap;
567 int _underFireFrames;
568 int _avoidRenderingFrames;
569 int _shootingFrames;
570 GeometricObject *_delayedShootObject;
571 void drawFrame();
572 Math::Vector3d getCameraRenderPosition();
573 void drawFrameStereo(int farClipPlane);
574
575 // Red/blue anaglyph 3D ("two eyes") effect, toggled with the 3 key.
576 bool _stereoMode;
577 void flashScreen(int backgroundColor);
578 uint8 _colorNumber;
579 Math::Vector3d _scaleVector;
580 float _fieldOfView;
581 float _viewAspectRatio;
582 float _nearClipPlane;
583 float _farClipPlane;
584
585 // Text messages and Fonts
586 void insertTemporaryMessage(const Common::String &message, int deadline);
587 void getLatestMessages(Common::String &message, int &deadline);
588 void clearTemporalMessages();
589 Common::StringArray _temporaryMessages;
590 Common::Array<int> _temporaryMessageDeadlines;
591 Common::StringArray _messagesList;
592 Common::String _noShieldMessage;
593 Common::String _noEnergyMessage;
594 Common::String _fallenMessage;
595 Common::String _timeoutMessage;
596 Common::String _forceEndGameMessage;
597 Common::String _crushedMessage;
598 Common::String _outOfReachMessage;
599 Common::String _noEffectMessage;
600
601 void loadMessagesFixedSize(Common::SeekableReadStream *file, int offset, int size, int number);
602 virtual void loadMessagesVariableSize(Common::SeekableReadStream *file, int offset, int number);
603 void drawFullscreenMessageAndWait(Common::String message);
604 void drawFullscreenMessage(Common::String message, uint32 front, Graphics::Surface *surface);
605
606 // Font loading and rendering
607 void loadFonts(Common::SeekableReadStream *file, int offset);
608 void loadFonts(byte *font, int charNumber);
609 Common::Array<Graphics::ManagedSurface *> getChars(Common::SeekableReadStream *file, int offset, int charsNumber);
610 Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtariInternal(int sizeX, int sizeY, int additional, int m1, int m2, Common::SeekableReadStream *file, int offset, int charsNumber);
611 Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtari(Common::SeekableReadStream *file, int offset, int charsNumber);
612 Common::Array<Graphics::ManagedSurface *> getChars4Plane(Common::SeekableReadStream *file, int offset, int charsNumber);
613 Common::StringArray _currentAreaMessages;
614 Common::StringArray _currentEphymeralMessages;
615 Font _font;
616 bool _fontLoaded;
617 virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
618 virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
619 Graphics::Surface *drawStringsInSurface(const Common::Array<Common::String> &lines, Graphics::Surface *surface);
620
621 // Game state
622 virtual void initGameState();
623 void setGameBit(int index);
624 void clearGameBit(int index);
625 void toggleGameBit(int index);
626 uint16 getGameBit(int index);
627
628 StateVars _gameStateVars;
629 uint32 _gameStateBits;
630 void checkIfPlayerWasCrushed();
631 virtual bool triggerWinCondition();
632 virtual bool checkIfGameEnded();
633 virtual void endGame();
634 int _endGameDelayTicks;
635 bool _endGameKeyPressed;
636 bool _endGamePlayerEndArea;
637 bool _forceEndGame;
638 bool _playerWasCrushed;
639 Common::HashMap<uint16, bool> _exploredAreas;
640 ObjectArray _sensors;
641 virtual void checkSensors();
642 virtual void drawSensorShoot(Sensor *sensor);
643 void takeDamageFromSensor();
644
645 bool hasFeature(EngineFeature f) const override;
646 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
647 bool canSaveAutosaveCurrently() override { return false; }
648 // Disallow saving while the game is not in the playing state, or while the
649 // player is dead/not controllable (fallen out of the world, crushed, or out
650 // of health/shield). Otherwise that transient state would be captured into
651 // the savegame.
652 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _gameStateControl == kFreescapeGameStatePlaying && _currentArea && !_hasFallen && !_playerWasCrushed && _gameStateVars.getValOrDefault(k8bitVariableShield) > 0; }
654 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
655 virtual Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false);
656 virtual Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream);
657 Graphics::Surface *_savedScreen;
658
659 void pauseEngineIntern(bool pause) override;
660
661 // Timers
662 bool startCountdown(uint32 delay);
663 void removeTimers();
664 bool _timerStarted;
665 int _initialCountdown;
666 int _countdown;
667 int _ticks;
668 int _ticksFromEnd;
669 int _lastTick;
670 int _lastMinute;
671 bool _inWaitLoop;
672
673 void getTimeFromCountdown(int &seconds, int &minutes, int &hours);
674 virtual void updateTimeVariables();
675
676 // Cheats
677 bool _useExtendedTimer;
678 bool _disableSensors;
679 bool _disableFalling;
680
681 // Random
683
684 // C64 specifics
685 Common::Array<byte> unpackC64Snapshot(const Common::Array<byte> &packed);
686 Common::Array<byte> unpackC64Snapshot(Common::SeekableReadStream *file, const Common::Path &continuation);
687 byte *_extraBuffer;
688};
689
690enum GameReleaseFlags {
691 GF_AMIGA_RETAIL = (1 << 0),
692 GF_AMIGA_BUDGET = (1 << 1),
693 GF_ZX_RETAIL = (1 << 2),
694 GF_ZX_BUDGET = (1 << 3),
695 GF_ZX_DISC = (1 << 4),
696 GF_CPC_RETAIL = (1 << 5),
697 GF_CPC_RETAIL_ALT = (1 << 6),
698 GF_CPC_BUDGET = (1 << 7),
699 GF_CPC_VIRTUALWORLDS = (1 << 8),
700 GF_ATARI_RETAIL = (1 << 9),
701 GF_ATARI_BUDGET = (1 << 10),
702 GF_C64_TAPE = (1 << 11),
703 GF_C64_DISC = (1 << 12),
704 GF_C64_PACKED = (1 << 13),
705};
706
707extern FreescapeEngine *g_freescape;
708extern Debugger *g_debugger;
709
710} // namespace Freescape
711
712#endif // FREESCAPE_H
Definition: mixer.h:49
Definition: archive.h:141
Definition: error.h:81
Definition: events.h:491
Definition: keymap.h:66
Definition: path.h:52
Definition: random.h:44
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
const Common::String _targetName
Definition: engine.h:186
EngineFeature
Definition: engine.h:282
Definition: area.h:41
Definition: freescape.h:164
Definition: freescape.h:191
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
void pauseEngineIntern(bool pause) override
bool hasFeature(EngineFeature f) const override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: freescape.h:646
bool canSaveAutosaveCurrently() override
Definition: freescape.h:647
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: freescape.h:652
Common::Error run() override
Definition: group.h:40
Definition: object.h:56
Definition: gfx.h:50
Definition: framelimiter.h:40
Definition: managed_surface.h:51
Definition: system.h:166
uint32 CustomEventType
Definition: events.h:212
Language
Definition: language.h:45
RenderMode
Definition: rendermode.h:48
Definition: algorithm.h:29
Definition: area.h:36
Definition: advancedDetector.h:164
Common::Platform platform
Definition: advancedDetector.h:199
Definition: events.h:218
Definition: keyboard.h:294
Definition: rect.h:144
Definition: rect.h:536
Definition: freescape.h:155
Definition: surface.h:67