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