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  // Player movement state
373  bool _moveForward;
374  bool _moveBackward;
375  bool _strafeLeft;
376  bool _strafeRight;
377  bool _moveUp;
378  bool _moveDown;
379 
380  virtual void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target);
381  EventManagerWrapper *_eventManager;
382  void processInput();
383  void resetInput();
384  void stopMovement();
385  void generateDemoInput();
386  virtual void pressedKey(const int keycode);
387  virtual void releasedKey(const int keycode);
388  Common::Point getNormalizedPosition(Common::Point position);
389  virtual bool onScreenControls(Common::Point mouse);
390  void updatePlayerMovement(float deltaTime);
391  void updatePlayerMovementSmooth(float deltaTime);
392  void updatePlayerMovementClassic(float deltaTime);
393  void resolveCollisions(Math::Vector3d newPosition);
394  virtual void checkIfStillInArea();
395  void changePlayerHeight(int index);
396  void increaseStepSize();
397  void decreaseStepSize();
398  void changeStepSize();
399 
400  void changeAngle(int offset, bool wrapAround);
401  bool rise();
402  void lower();
403  bool checkFloor(Math::Vector3d currentPosition);
404  bool tryStepUp(Math::Vector3d currentPosition);
405  bool tryStepDown(Math::Vector3d currentPosition);
406  bool _hasFallen;
407  bool _isCollidingWithWall;
408  bool _isSteppingUp;
409  bool _isSteppingDown;
410  bool _isFalling;
411  int _maxFallingDistance;
412  int _maxShield;
413  int _maxEnergy;
414 
415  void rotate(float xoffset, float yoffset, float zoffset);
416  // Input state
417  float _lastFrame;
418 
419  // Interaction
420  void activate();
421  void shoot();
422  void traverseEntrance(uint16 entranceID);
423 
424  // Euler Angles
425  float _yaw;
426  float _pitch;
427  int _roll;
428  int _angleRotationIndex;
429  Common::Array<float> _angleRotations;
430 
431  Math::Vector3d directionToVector(float pitch, float heading, bool useTable);
432  void updateCamera();
433  virtual void onRotate(float xoffset, float yoffset, float zoffset) {}
434 
435  // Camera options
436  Common::Point _crossairPosition;
437  float _mouseSensitivity;
438  Math::Vector3d _upVector; // const
439  Math::Vector3d _cameraFront, _cameraRight;
440  // Spacial attributes
441  Math::Vector3d _position, _rotation, _velocity;
442  Math::Vector3d _lastPosition;
443  int _playerHeightNumber;
444  int _playerHeightMaxNumber;
445  uint16 _playerHeight;
446  uint16 _playerWidth;
447  uint16 _playerDepth;
448  uint16 _stepUpDistance;
449 
450  int _playerStepIndex;
451  int _savedPlayerStepIndex; // saved before shift-to-run, restored on release
452  Common::Array<int> _playerSteps;
453 
454  Common::Point crossairPosToMousePos(const Common::Point &crossairPos);
455  Common::Point mousePosToCrossairPos(const Common::Point &mousePos);
456  void warpMouseToCrossair(void);
457 
458  // Effects
459  Common::Array<Common::String> _conditionSources;
461 
462  bool runCollisionConditions(Math::Vector3d const lastPosition, Math::Vector3d const newPosition);
463  Math::Vector3d _objExecutingCodeSize;
464  bool _executingGlobalCode;
465  virtual void executeMovementConditions();
466  bool executeObjectConditions(GeometricObject *obj, bool shot, bool collided, bool activated);
467  void executeEntranceConditions(Entrance *entrance);
468  void executeLocalGlobalConditions(bool shot, bool collided, bool timer);
469  bool executeCode(FCLInstructionVector &code, bool shot, bool collided, bool timer, bool activated);
470 
471  // Instructions
472  bool checkConditional(FCLInstruction &instruction, bool shot, bool collided, bool timer, bool activated);
473  bool checkIfGreaterOrEqual(FCLInstruction &instruction);
474  bool checkIfLessOrEqual(FCLInstruction &instruction);
475  void executeExecute(FCLInstruction &instruction);
476  void executeIncrementVariable(FCLInstruction &instruction);
477  void executeDecrementVariable(FCLInstruction &instruction);
478  void executeSetVariable(FCLInstruction &instruction);
479  void executeGoto(FCLInstruction &instruction);
480  void executeIfThenElse(FCLInstruction &instruction);
481  virtual void executeMakeInvisible(FCLInstruction &instruction);
482  void executeMakeVisible(FCLInstruction &instruction);
483  void executeToggleVisibility(FCLInstruction &instruction);
484  virtual void executeDestroy(FCLInstruction &instruction);
485  virtual void executeRedraw(FCLInstruction &instruction);
486  void executeSound(FCLInstruction &instruction);
487  void executeDelay(FCLInstruction &instruction);
488  bool executeEndIfNotEqual(FCLInstruction &instruction);
489  void executeSetBit(FCLInstruction &instruction);
490  void executeClearBit(FCLInstruction &instruction);
491  void executeToggleBit(FCLInstruction &instruction);
492  bool executeEndIfBitNotEqual(FCLInstruction &instruction);
493  bool executeEndIfVisibilityIsEqual(FCLInstruction &instruction);
494  void executeSwapJet(FCLInstruction &instruction);
495  virtual void executePrint(FCLInstruction &instruction);
496  void executeSPFX(FCLInstruction &instruction);
497  void executeStartAnim(FCLInstruction &instruction);
498 
499  // Sound
500  Audio::SoundHandle _soundFxHandle;
501  Audio::SoundHandle _musicHandle;
502  Audio::SoundHandle _movementSoundHandle;
503  Freescape::SizedPCSpeaker *_speaker;
504 
505  bool _syncSound;
506  bool _firstSound;
507  bool _usePrerecordedSounds;
508  void waitForSounds();
509  void stopAllSounds(Audio::SoundHandle &handle);
510  bool isPlayingSound();
511  void playSound(int index, bool sync, Audio::SoundHandle &handle);
512  void playWav(const Common::Path &filename);
513  void playMusic(const Common::Path &filename);
514  void queueSoundConst(double hzFreq, int duration);
515  void playSilence(int duration, bool sync);
516  void playSoundConst(double hzFreq, int duration, bool sync);
517  void playSoundSweepIncWL(double hzFreq1, double hzFreq2, double wlStepPerMS, int resolution, bool sync);
518  uint16 playSoundDOSSpeaker(uint16 startFrequency, soundSpeakerFx *speakerFxInfo);
519  void playSoundDOS(soundSpeakerFx *speakerFxInfo, bool sync, Audio::SoundHandle &handle);
520 
521  void playSoundCPC(int index, Audio::SoundHandle &handle);
522  virtual void playSoundC64(int index);
523  virtual void playSoundFx(int index, bool sync);
524  virtual void loadSoundsFx(Common::SeekableReadStream *file, int offset, int number);
526  void loadSpeakerFxDOS(Common::SeekableReadStream *file, int offsetFreq, int offsetDuration, int numberSounds);
527  void loadSpeakerFxZX(Common::SeekableReadStream *file, int sfxTable, int sfxData);
529 
530  virtual void playSoundZX(int index, Audio::SoundHandle &handle);
531  void playSoundZX(Common::Array<soundUnitZX> *data, Audio::SoundHandle &handle);
533 
534  void loadSoundsCPC(Common::SeekableReadStream *file, int offsetTone, int sizeTone, int offsetEnvelope, int sizeEnvelope, int offsetSoundDef, int sizeSoundDef);
535  Common::Array<byte> _soundsCPCToneTable;
536  Common::Array<byte> _soundsCPCEnvelopeTable;
537  Common::Array<byte> _soundsCPCSoundDefTable;
538 
539  void loadSoundsAmigaDemo(Common::SeekableReadStream *file, int offset, int numSounds, int modOffset = 0x3D5A6);
540  void playSoundAmiga(int index, Audio::SoundHandle &handle);
541  Common::Array<AmigaSfxEntry> _amigaSfxTable;
542  Common::Array<AmigaDmaSample> _amigaDmaSamples;
543 
544  int _soundIndexShoot;
545  int _soundIndexCollide;
546  int _soundIndexStepDown;
547  int _soundIndexStepUp;
548  int _soundIndexFall;
549  int _soundIndexMenu;
550  int _soundIndexStart;
551  int _soundIndexAreaChange;
552  int _soundIndexHit;
553 
554  int _soundIndexNoShield;
555  int _soundIndexNoEnergy;
556  int _soundIndexFallen;
557  int _soundIndexTimeout;
558  int _soundIndexForceEndGame;
559  int _soundIndexCrushed;
560  int _soundIndexMissionComplete;
561 
562  // Rendering
563  int _screenW, _screenH;
564  Renderer *_gfx;
565  Graphics::FrameLimiter *_frameLimiter;
566  bool _vsyncEnabled;
567  Common::RenderMode _renderMode;
568  ColorMap _colorMap;
569  int _underFireFrames;
570  int _avoidRenderingFrames;
571  int _shootingFrames;
572  GeometricObject *_delayedShootObject;
573  void drawFrame();
574  void drawFrameStereo(int farClipPlane);
575 
576  // Red/blue anaglyph 3D ("two eyes") effect, toggled with the 3 key.
577  bool _stereoMode;
578  void flashScreen(int backgroundColor);
579  uint8 _colorNumber;
580  Math::Vector3d _scaleVector;
581  float _nearClipPlane;
582  float _farClipPlane;
583 
584  // Text messages and Fonts
585  void insertTemporaryMessage(const Common::String &message, int deadline);
586  void getLatestMessages(Common::String &message, int &deadline);
587  void clearTemporalMessages();
588  Common::StringArray _temporaryMessages;
589  Common::Array<int> _temporaryMessageDeadlines;
590  Common::StringArray _messagesList;
591  Common::String _noShieldMessage;
592  Common::String _noEnergyMessage;
593  Common::String _fallenMessage;
594  Common::String _timeoutMessage;
595  Common::String _forceEndGameMessage;
596  Common::String _crushedMessage;
597  Common::String _outOfReachMessage;
598  Common::String _noEffectMessage;
599 
600  void loadMessagesFixedSize(Common::SeekableReadStream *file, int offset, int size, int number);
601  virtual void loadMessagesVariableSize(Common::SeekableReadStream *file, int offset, int number);
602  void drawFullscreenMessageAndWait(Common::String message);
603  void drawFullscreenMessage(Common::String message, uint32 front, Graphics::Surface *surface);
604 
605  // Font loading and rendering
606  void loadFonts(Common::SeekableReadStream *file, int offset);
607  void loadFonts(byte *font, int charNumber);
608  Common::Array<Graphics::ManagedSurface *> getChars(Common::SeekableReadStream *file, int offset, int charsNumber);
609  Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtariInternal(int sizeX, int sizeY, int additional, int m1, int m2, Common::SeekableReadStream *file, int offset, int charsNumber);
610  Common::Array<Graphics::ManagedSurface *> getCharsAmigaAtari(Common::SeekableReadStream *file, int offset, int charsNumber);
611  Common::Array<Graphics::ManagedSurface *> getChars4Plane(Common::SeekableReadStream *file, int offset, int charsNumber);
612  Common::StringArray _currentAreaMessages;
613  Common::StringArray _currentEphymeralMessages;
614  Font _font;
615  bool _fontLoaded;
616  virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
617  virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0);
618  Graphics::Surface *drawStringsInSurface(const Common::Array<Common::String> &lines, Graphics::Surface *surface);
619 
620  // Game state
621  virtual void initGameState();
622  void setGameBit(int index);
623  void clearGameBit(int index);
624  void toggleGameBit(int index);
625  uint16 getGameBit(int index);
626 
627  StateVars _gameStateVars;
628  uint32 _gameStateBits;
629  void checkIfPlayerWasCrushed();
630  virtual bool triggerWinCondition();
631  virtual bool checkIfGameEnded();
632  virtual void endGame();
633  int _endGameDelayTicks;
634  bool _endGameKeyPressed;
635  bool _endGamePlayerEndArea;
636  bool _forceEndGame;
637  bool _playerWasCrushed;
638  Common::HashMap<uint16, bool> _exploredAreas;
639  ObjectArray _sensors;
640  virtual void checkSensors();
641  virtual void drawSensorShoot(Sensor *sensor);
642  void takeDamageFromSensor();
643 
644  bool hasFeature(EngineFeature f) const override;
645  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
646  bool canSaveAutosaveCurrently() override { return false; }
647  // Disallow saving while the game is not in the playing state, or while the
648  // player is dead/not controllable (fallen out of the world, crushed, or out
649  // of health/shield). Otherwise that transient state would be captured into
650  // the savegame.
651  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _gameStateControl == kFreescapeGameStatePlaying && _currentArea && !_hasFallen && !_playerWasCrushed && _gameStateVars.getValOrDefault(k8bitVariableShield) > 0; }
652  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
653  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
654  virtual Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false);
655  virtual Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream);
656  Graphics::Surface *_savedScreen;
657 
658  void pauseEngineIntern(bool pause) override;
659 
660  // Timers
661  bool startCountdown(uint32 delay);
662  void removeTimers();
663  bool _timerStarted;
664  int _initialCountdown;
665  int _countdown;
666  int _ticks;
667  int _ticksFromEnd;
668  int _lastTick;
669  int _lastMinute;
670  bool _inWaitLoop;
671 
672  void getTimeFromCountdown(int &seconds, int &minutes, int &hours);
673  virtual void updateTimeVariables();
674 
675  // Cheats
676  bool _useExtendedTimer;
677  bool _disableSensors;
678  bool _disableFalling;
679 
680  // Random
681  Common::RandomSource *_rnd;
682 
683  // C64 specifics
684  byte *decompressC64RLE(byte *buffer, int *size, byte marker);
685  byte *_extraBuffer;
686 };
687 
688 enum GameReleaseFlags {
689  GF_AMIGA_RETAIL = (1 << 0),
690  GF_AMIGA_BUDGET = (1 << 1),
691  GF_ZX_RETAIL = (1 << 2),
692  GF_ZX_BUDGET = (1 << 3),
693  GF_ZX_DISC = (1 << 4),
694  GF_CPC_RETAIL = (1 << 5),
695  GF_CPC_RETAIL_ALT = (1 << 6),
696  GF_CPC_BUDGET = (1 << 7),
697  GF_CPC_VIRTUALWORLDS = (1 << 8),
698  GF_ATARI_RETAIL = (1 << 9),
699  GF_ATARI_BUDGET = (1 << 10),
700  GF_C64_TAPE = (1 << 11),
701  GF_C64_DISC = (1 << 12),
702 };
703 
704 extern FreescapeEngine *g_freescape;
705 extern Debugger *g_debugger;
706 
707 } // namespace Freescape
708 
709 #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:646
Definition: area.h:36
Definition: freescape.h:164
Definition: advancedDetector.h:164
Definition: random.h:44
RenderMode
Definition: rendermode.h:48
Definition: rect.h:524
Definition: area.h:41
Definition: path.h:52
uint32 CustomEventType
Definition: events.h:204
Definition: stream.h:745
Definition: archive.h:141
Definition: freescape.h:191
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: freescape.h:651
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:645
Definition: object.h:56
Definition: sound.h:65
Definition: system.h:165
Definition: instruction.h:36
Definition: freescape.h:155
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