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