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/8bitDetokeniser.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 
48 namespace Common {
49 class RandomSource;
50 }
51 
52 namespace Freescape {
53 
54 class Renderer;
55 class Debugger;
56 
57 bool isEncodedCPCDirectColor(uint8 index);
58 uint8 encodeCPCDirectColor(uint8 index);
59 uint8 decodeCPCDirectColor(uint8 index);
60 
61 #define FREESCAPE_DATA_BUNDLE "freescape.dat"
62 
63 enum CameraMovement {
64  kForwardMovement,
65  kBackwardMovement,
66  kLeftMovement,
67  kRightMovement
68 };
69 
70 enum 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 
124 typedef Common::HashMap<uint16, Area *> AreaMap;
125 typedef Common::Array<byte *> ColorMap;
126 typedef Common::HashMap<uint16, int32> StateVars;
127 
128 enum {
129  kFreescapeDebugMove = 1,
130  kFreescapeDebugParser,
131  kFreescapeDebugCode,
132  kFreescapeDebugMedia,
133  kFreescapeDebugGroup,
134 };
135 
136 enum {
137  kFreescapeDefaultVolume = 192,
138 };
139 
140 enum GameStateControl {
141  kFreescapeGameStateStart,
142  kFreescapeGameStatePlaying,
143  kFreescapeGameStateDemo,
144  kFreescapeGameStateEnd,
145  kFreescapeGameStateRestart,
146 };
147 
148 extern byte kEGADefaultPalette[16][3];
149 extern byte kCGAPaletteRedGreen[4][3];
150 extern byte kCGAPalettePinkBlue[4][3];
151 extern byte kCGAPalettePinkBlueBright[4][3];
152 extern byte kCGAPaletteRedGreenBright[4][3];
153 extern byte kHerculesPaletteGreen[2][3];
154 
156  int areaId;
157  byte *palette;
158 };
159 
160 extern Common::String shiftStr(const Common::String &str, int shift);
161 extern Common::String centerAndPadString(const Common::String &str, int size);
162 extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode1);
163 
165 public:
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 
176 private:
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 
191 class FreescapeEngine : public Engine {
192 
193 public:
194  FreescapeEngine(OSystem *syst, const ADGameDescription *gd);
195  ~FreescapeEngine();
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);
243  Graphics::ManagedSurface *_border;
244  Graphics::ManagedSurface *_title;
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;
310  Common::Array<Common::Event> _demoEvents;
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 *decryptFileAtariVirtualWorlds(const Common::Path &filename);
345 
346  // Areas
347  uint16 _startArea;
348  uint16 _endArea;
349  AreaMap _areaMap;
350  Area *_currentArea;
351  bool _gotoExecuted;
352  Math::Vector3d _scale;
353 
354  virtual void gotoArea(uint16 areaID, int entranceID);
355  // Entrance
356  uint16 _startEntrance;
357  uint16 _endEntrance;
359 
360  // Input
361  bool _demoMode;
362  bool _disableDemoMode;
363  bool _flyMode;
364  bool _shootMode;
365  bool _noClipMode;
366  bool _invertY;
367 
368  bool _smoothMovement;
369  bool _useWASDControls;
370  bool _debugSimulateTouchscreen;
371  bool isTouchscreenActive() const;
372  void setIOSGamepadControllerEnabled(bool enabled);
373  void restoreIOSGamepadControllerSettings();
374 #ifdef IPHONE
375  struct IOSGamepadControllerSetting {
376  bool present;
377  Common::String value;
378  };
379  bool _iosGamepadControllerSettingsSaved;
380  Common::String _iosGamepadControllerDomain;
381  IOSGamepadControllerSetting _iosGamepadController;
382  IOSGamepadControllerSetting _iosGamepadControllerMinimalLayout;
383  IOSGamepadControllerSetting _iosGamepadControllerDirectionalInput;
384 #endif
385  // Player movement state
386  bool _moveForward;
387  bool _moveBackward;
388  bool _strafeLeft;
389  bool _strafeRight;
390  bool _moveUp;
391  bool _moveDown;
392 
393  virtual void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target);
394  EventManagerWrapper *_eventManager;
395  void processInput();
396  void resetInput();
397  void stopMovement();
398  void generateDemoInput();
399  virtual void pressedKey(const int keycode);
400  virtual void releasedKey(const int keycode);
401  Common::Point getNormalizedPosition(Common::Point position);
402  virtual bool onScreenControls(Common::Point mouse);
403  void updatePlayerMovement(float deltaTime);
404  void updatePlayerMovementSmooth(float deltaTime);
405  void updatePlayerMovementClassic(float deltaTime);
406  void resolveCollisions(Math::Vector3d newPosition);
407  virtual void checkIfStillInArea();
408  void changePlayerHeight(int index);
409  void increaseStepSize();
410  void decreaseStepSize();
411  void changeStepSize();
412 
413  void changeAngle(int offset, bool wrapAround);
414  bool rise();
415  void lower();
416  bool checkFloor(Math::Vector3d currentPosition);
417  bool tryStepUp(Math::Vector3d currentPosition);
418  bool tryStepDown(Math::Vector3d currentPosition);
419  bool _hasFallen;
420  bool _isCollidingWithWall;
421  bool _isSteppingUp;
422  bool _isSteppingDown;
423  bool _isFalling;
424  int _maxFallingDistance;
425  int _maxShield;
426  int _maxEnergy;
427 
428  void rotate(float xoffset, float yoffset, float zoffset);
429  // Input state
430  float _lastFrame;
431 
432  // Interaction
433  void activate();
434  void shoot();
435  void traverseEntrance(uint16 entranceID);
436 
437  // Euler Angles
438  float _yaw;
439  float _pitch;
440  int _roll;
441  int _angleRotationIndex;
442  Common::Array<float> _angleRotations;
443 
444  Math::Vector3d directionToVector(float pitch, float heading, bool useTable);
445  void updateCamera();
446  virtual void onRotate(float xoffset, float yoffset, float zoffset) {}
447 
448  // Camera options
449  Common::Point _crossairPosition;
450  float _mouseSensitivity;
451  Math::Vector3d _upVector; // const
452  Math::Vector3d _cameraFront, _cameraRight;
453  // Spacial attributes
454  Math::Vector3d _position, _rotation, _velocity;
455  Math::Vector3d _lastPosition;
456  int _playerHeightNumber;
457  int _playerHeightMaxNumber;
458  uint16 _playerHeight;
459  uint16 _playerWidth;
460  uint16 _playerDepth;
461  uint16 _stepUpDistance;
462 
463  int _playerStepIndex;
464  int _savedPlayerStepIndex; // saved before shift-to-run, restored on release
465  Common::Array<int> _playerSteps;
466 
467  Common::Point crossairPosToMousePos(const Common::Point &crossairPos);
468  Common::Point mousePosToCrossairPos(const Common::Point &mousePos);
469  void warpMouseToCrossair(void);
470 
471  // Effects
472  Common::Array<Common::String> _conditionSources;
474 
475  bool runCollisionConditions(Math::Vector3d const lastPosition, Math::Vector3d const newPosition);
476  Math::Vector3d _objExecutingCodeSize;
477  bool _executingGlobalCode;
478  virtual void executeMovementConditions();
479  bool executeObjectConditions(GeometricObject *obj, bool shot, bool collided, bool activated);
480  void executeEntranceConditions(Entrance *entrance);
481  void executeLocalGlobalConditions(bool shot, bool collided, bool timer);
482  bool executeCode(FCLInstructionVector &code, bool shot, bool collided, bool timer, bool activated);
483 
484  // Instructions
485  bool checkConditional(FCLInstruction &instruction, bool shot, bool collided, bool timer, bool activated);
486  bool checkIfGreaterOrEqual(FCLInstruction &instruction);
487  bool checkIfLessOrEqual(FCLInstruction &instruction);
488  void executeExecute(FCLInstruction &instruction);
489  void executeIncrementVariable(FCLInstruction &instruction);
490  void executeDecrementVariable(FCLInstruction &instruction);
491  void executeSetVariable(FCLInstruction &instruction);
492  void executeGoto(FCLInstruction &instruction);
493  void executeIfThenElse(FCLInstruction &instruction);
494  virtual void executeMakeInvisible(FCLInstruction &instruction);
495  void executeMakeVisible(FCLInstruction &instruction);
496  void executeToggleVisibility(FCLInstruction &instruction);
497  virtual void executeDestroy(FCLInstruction &instruction);
498  virtual void executeRedraw(FCLInstruction &instruction);
499  void executeSound(FCLInstruction &instruction);
500  void executeDelay(FCLInstruction &instruction);
501  bool executeEndIfNotEqual(FCLInstruction &instruction);
502  void executeSetBit(FCLInstruction &instruction);
503  void executeClearBit(FCLInstruction &instruction);
504  void executeToggleBit(FCLInstruction &instruction);
505  bool executeEndIfBitNotEqual(FCLInstruction &instruction);
506  bool executeEndIfVisibilityIsEqual(FCLInstruction &instruction);
507  void executeSwapJet(FCLInstruction &instruction);
508  virtual void executePrint(FCLInstruction &instruction);
509  void executeSPFX(FCLInstruction &instruction);
510  void executeStartAnim(FCLInstruction &instruction);
511 
512  // Sound
513  Audio::SoundHandle _soundFxHandle;
514  Audio::SoundHandle _musicHandle;
515  Sound *_sound;
516 
517  bool _syncSound;
518  bool _firstSound;
519  bool _usePrerecordedSounds;
520  void waitForSounds(Sound::Type type = Sound::kTypeNormal);
521  void stopAllSounds(Sound::Type type = Sound::kTypeNormal);
522  bool isPlayingSound(Sound::Type type = Sound::kTypeNormal);
523  void playSound(int index, bool sync, Sound::Type type = Sound::kTypeNormal);
524  void playWav(const Common::Path &filename);
525  void playMusic(const Common::Path &filename);
526 
527  virtual void playSoundFx(int index, bool sync, Sound::Type type = Sound::kTypeNormal) {}
528  Sound *loadSoundsFx(Common::SeekableReadStream *file, int offset, int number);
529  Sound *loadSoundsFxDOS(Common::SeekableReadStream *file, int offset, int number);
530  Sound *loadSpeakerFxDOS(Common::SeekableReadStream *file, int offsetFreq, int offsetDuration, int numberSounds);
531  Sound *loadSpeakerFxZX(Common::SeekableReadStream *file, int sfxTable, int sfxData, int numberSounds);
532  Sound *loadSpeakerFxDrillerZX();
533  Sound *loadSoundsCPC(Common::SeekableReadStream *file, int offsetTone, int sizeTone, int offsetEnvelope, int sizeEnvelope, int offsetSoundDef, int sizeSoundDef);
534  Sound *loadSoundsAmigaDemo(Common::SeekableReadStream *file, int offset, int numSounds, int modOffset);
535 
536  int _soundIndexShoot;
537  int _soundIndexCollide;
538  int _soundIndexStepDown;
539  int _soundIndexStepUp;
540  int _soundIndexFall;
541  int _soundIndexMenu;
542  int _soundIndexStart;
543  int _soundIndexAreaChange;
544  int _soundIndexHit;
545 
546  int _soundIndexNoShield;
547  int _soundIndexNoEnergy;
548  int _soundIndexFallen;
549  int _soundIndexTimeout;
550  int _soundIndexForceEndGame;
551  int _soundIndexCrushed;
552  int _soundIndexMissionComplete;
553 
554  // Rendering
555  int _screenW, _screenH;
556  Renderer *_gfx;
557  Graphics::FrameLimiter *_frameLimiter;
558  bool _vsyncEnabled;
559  Common::RenderMode _renderMode;
560  ColorMap _colorMap;
561  int _underFireFrames;
562  int _avoidRenderingFrames;
563  int _shootingFrames;
564  GeometricObject *_delayedShootObject;
565  void drawFrame();
566  Math::Vector3d getCameraRenderPosition();
567  void drawFrameStereo(int farClipPlane);
568 
569  // Red/blue anaglyph 3D ("two eyes") effect, toggled with the 3 key.
570  bool _stereoMode;
571  void flashScreen(int backgroundColor);
572  uint8 _colorNumber;
573  Math::Vector3d _scaleVector;
574  float _nearClipPlane;
575  float _farClipPlane;
576 
577  // Text messages and Fonts
578  void insertTemporaryMessage(const Common::String &message, int deadline);
579  void getLatestMessages(Common::String &message, int &deadline);
580  void clearTemporalMessages();
581  Common::StringArray _temporaryMessages;
582  Common::Array<int> _temporaryMessageDeadlines;
583  Common::StringArray _messagesList;
584  Common::String _noShieldMessage;
585  Common::String _noEnergyMessage;
586  Common::String _fallenMessage;
587  Common::String _timeoutMessage;
588  Common::String _forceEndGameMessage;
589  Common::String _crushedMessage;
590  Common::String _outOfReachMessage;
591  Common::String _noEffectMessage;
592 
593  void loadMessagesFixedSize(Common::SeekableReadStream *file, int offset, int size, int number);
594  virtual void loadMessagesVariableSize(Common::SeekableReadStream *file, int offset, int number);
595  void drawFullscreenMessageAndWait(Common::String message);
596  void drawFullscreenMessage(Common::String message, uint32 front, Graphics::Surface *surface);
597 
598  // Font loading and rendering
599  void loadFonts(Common::SeekableReadStream *file, int offset);
600  void loadFonts(byte *font, int charNumber);
601  Common::Array<Graphics::ManagedSurface *> getChars(Common::SeekableReadStream *file, int offset, int charsNumber);
602  Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtariInternal(int sizeX, int sizeY, int additional, int m1, int m2, Common::SeekableReadStream *file, int offset, int charsNumber);
603  Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtari(Common::SeekableReadStream *file, int offset, int charsNumber);
604  Common::Array<Graphics::ManagedSurface *> getChars4Plane(Common::SeekableReadStream *file, int offset, int charsNumber);
605  Common::StringArray _currentAreaMessages;
606  Common::StringArray _currentEphymeralMessages;
607  Font _font;
608  bool _fontLoaded;
609  virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
610  virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
611  Graphics::Surface *drawStringsInSurface(const Common::Array<Common::String> &lines, Graphics::Surface *surface);
612 
613  // Game state
614  virtual void initGameState();
615  void setGameBit(int index);
616  void clearGameBit(int index);
617  void toggleGameBit(int index);
618  uint16 getGameBit(int index);
619 
620  StateVars _gameStateVars;
621  uint32 _gameStateBits;
622  void checkIfPlayerWasCrushed();
623  virtual bool triggerWinCondition();
624  virtual bool checkIfGameEnded();
625  virtual void endGame();
626  int _endGameDelayTicks;
627  bool _endGameKeyPressed;
628  bool _endGamePlayerEndArea;
629  bool _forceEndGame;
630  bool _playerWasCrushed;
631  Common::HashMap<uint16, bool> _exploredAreas;
632  ObjectArray _sensors;
633  virtual void checkSensors();
634  virtual void drawSensorShoot(Sensor *sensor);
635  void takeDamageFromSensor();
636 
637  bool hasFeature(EngineFeature f) const override;
638  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
639  bool canSaveAutosaveCurrently() override { return false; }
640  // Disallow saving while the game is not in the playing state, or while the
641  // player is dead/not controllable (fallen out of the world, crushed, or out
642  // of health/shield). Otherwise that transient state would be captured into
643  // the savegame.
644  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _gameStateControl == kFreescapeGameStatePlaying && _currentArea && !_hasFallen && !_playerWasCrushed && _gameStateVars.getValOrDefault(k8bitVariableShield) > 0; }
645  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
646  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
647  virtual Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false);
648  virtual Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream);
649  Graphics::Surface *_savedScreen;
650 
651  void pauseEngineIntern(bool pause) override;
652 
653  // Timers
654  bool startCountdown(uint32 delay);
655  void removeTimers();
656  bool _timerStarted;
657  int _initialCountdown;
658  int _countdown;
659  int _ticks;
660  int _ticksFromEnd;
661  int _lastTick;
662  int _lastMinute;
663  bool _inWaitLoop;
664 
665  void getTimeFromCountdown(int &seconds, int &minutes, int &hours);
666  virtual void updateTimeVariables();
667 
668  // Cheats
669  bool _useExtendedTimer;
670  bool _disableSensors;
671  bool _disableFalling;
672 
673  // Random
674  Common::RandomSource *_rnd;
675 
676  // C64 specifics
677  byte *decompressC64RLE(byte *buffer, int *size, byte marker);
678  byte *_extraBuffer;
679 };
680 
681 enum GameReleaseFlags {
682  GF_AMIGA_RETAIL = (1 << 0),
683  GF_AMIGA_BUDGET = (1 << 1),
684  GF_ZX_RETAIL = (1 << 2),
685  GF_ZX_BUDGET = (1 << 3),
686  GF_ZX_DISC = (1 << 4),
687  GF_CPC_RETAIL = (1 << 5),
688  GF_CPC_RETAIL_ALT = (1 << 6),
689  GF_CPC_BUDGET = (1 << 7),
690  GF_CPC_VIRTUALWORLDS = (1 << 8),
691  GF_ATARI_RETAIL = (1 << 9),
692  GF_ATARI_BUDGET = (1 << 10),
693  GF_C64_TAPE = (1 << 11),
694  GF_C64_DISC = (1 << 12),
695 };
696 
697 extern FreescapeEngine *g_freescape;
698 extern Debugger *g_debugger;
699 
700 } // namespace Freescape
701 
702 #endif // FREESCAPE_H
Definition: geometricobject.h:34
Definition: managed_surface.h:51
Definition: group.h:40
Definition: framelimiter.h:40
Definition: keymap.h:66
Definition: str.h:59
Definition: surface.h:67
EngineFeature
Definition: engine.h:282
Definition: stream.h:77
Definition: error.h:81
bool canSaveAutosaveCurrently() override
Definition: freescape.h:639
Definition: area.h:36
Definition: freescape.h:164
Definition: advancedDetector.h:164
Definition: random.h:44
RenderMode
Definition: rendermode.h:48
Definition: rect.h:536
Definition: area.h:41
Definition: path.h:52
uint32 CustomEventType
Definition: events.h:212
Definition: stream.h:745
Definition: archive.h:141
Definition: freescape.h:191
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: freescape.h:644
Definition: mixer.h:49
Definition: gfx.h:63
Definition: sensor.h:34
Definition: ustr.h:57
Definition: events.h:218
Definition: algorithm.h:29
Definition: rect.h:144
Definition: entrance.h:34
Definition: sound.h:35
Definition: font.h:32
Definition: keyboard.h:294
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: freescape.h:638
Definition: object.h:56
Definition: system.h:166
Definition: instruction.h:36
Definition: freescape.h:155
Common::Platform platform
Definition: advancedDetector.h:199
Definition: events.h:491
Definition: engine.h:149
Definition: debugger.h:31
Definition: gfx.h:50
Language
Definition: language.h:45