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"
35#include "audio/mixer.h"
36#include "audio/softsynth/pcspk.h"
37#include "graphics/framelimiter.h"
39#include "freescape/area.h"
40#include "freescape/font.h"
41#include "freescape/gfx.h"
42#include "freescape/language/variables.h"
43#include "freescape/objects/entrance.h"
44#include "freescape/objects/geometricobject.h"
45#include "freescape/objects/sensor.h"
46#include "freescape/sound.h"
57bool isEncodedCPCDirectColor(uint8 index);
58uint8 encodeCPCDirectColor(uint8 index);
59uint8 decodeCPCDirectColor(uint8 index);
61#define FREESCAPE_DATA_BUNDLE "freescape.dat"
84 kActionChangeStepSize,
85 kActionToggleRiseLower,
87 kActionLowerOrFlyDown,
97 kActionIncreaseStepSize,
98 kActionDecreaseStepSize,
100 kActionToggleClipMode,
102 kActionDeployDrillingRig,
103 kActionCollectDrillingRig,
114 kActionSelectPrincess,
116 kActionToggleFlashlight,
117 kActionToggleStereoscopic,
129 kFreescapeDebugMove = 1,
130 kFreescapeDebugParser,
132 kFreescapeDebugMedia,
133 kFreescapeDebugGroup,
137 kFreescapeDefaultVolume = 192,
140enum GameStateControl {
141 kFreescapeGameStateStart,
142 kFreescapeGameStatePlaying,
143 kFreescapeGameStateDemo,
144 kFreescapeGameStateEnd,
145 kFreescapeGameStateRestart,
148extern byte kEGADefaultPalette[16][3];
149extern byte kCGAPaletteRedGreen[4][3];
150extern byte kCGAPalettePinkBlue[4][3];
151extern byte kCGAPalettePinkBlueBright[4][3];
152extern byte kCGAPaletteRedGreenBright[4][3];
153extern byte kHerculesPaletteGreen[2][3];
169 void purgeKeyboardEvents();
170 void purgeMouseEvents();
172 void clearExitEvents();
179 kKeyRepeatInitialDelay = 400,
180 kKeyRepeatSustainDelay = 100
188 uint32 _keyRepeatTime;
198 GameStateControl _gameStateControl;
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"); }
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; }
218 virtual void beforeStarting();
224 void centerCrossair();
226 virtual void borderScreen();
227 virtual void titleScreen();
230 virtual void loadBorder();
231 virtual void processBorder();
232 void waitInLoop(
int maxWait);
235 virtual void drawBackground();
236 void clearBackground();
238 virtual void drawUI();
239 virtual void drawInfoMenu();
258 virtual void loadAssets();
259 virtual void loadAssetsDemo();
260 virtual void loadAssetsFullGame();
262 virtual void loadAssetsAtariFullGame();
263 virtual void loadAssetsAtariDemo();
265 virtual void loadAssetsAmigaFullGame();
266 virtual void loadAssetsAmigaDemo();
268 virtual void loadAssetsDOSFullGame();
269 virtual void loadAssetsDOSDemo();
271 virtual void loadAssetsZXFullGame();
272 virtual void loadAssetsZXDemo();
274 virtual void loadAssetsCPCFullGame();
275 virtual void loadAssetsCPCDemo();
277 virtual void loadAssetsC64FullGame();
278 virtual void loadAssetsC64Demo();
287 void loadDataBundle();
292 int dataOffset,
int widthWords,
int height,
byte *palette);
300 void swapPalette(uint16 areaID);
301 virtual byte *findCGAPalette(uint16 levelID);
303 void loadColorPalette();
308 int _currentDemoInputCode;
309 int _currentDemoInputRepetition;
313 int decodeAmigaAtariKey(
int code);
314 int decodeDOSKey(
int code);
353 Math::Vector3d _scale;
355 virtual void gotoArea(uint16 areaID,
int entranceID);
357 uint16 _startEntrance;
363 bool _disableDemoMode;
369 bool _smoothMovement;
370 bool _useWASDControls;
371 bool _debugSimulateTouchscreen;
372 bool isTouchscreenActive()
const;
373 void setIOSGamepadControllerEnabled(
bool enabled);
374 void restoreIOSGamepadControllerSettings();
376 struct IOSGamepadControllerSetting {
380 bool _iosGamepadControllerSettingsSaved;
382 IOSGamepadControllerSetting _iosGamepadController;
383 IOSGamepadControllerSetting _iosGamepadControllerMinimalLayout;
384 IOSGamepadControllerSetting _iosGamepadControllerDirectionalInput;
397 virtual bool handleInput(
const Common::Event &event) {
return false; }
400 void generateDemoInput();
401 virtual void pressedKey(
const int keycode);
402 virtual void releasedKey(
const int keycode);
405 virtual void updatePlayerMovement(
float deltaTime);
406 void updatePlayerMovementSmooth(
float deltaTime);
407 void updatePlayerMovementClassic(
float deltaTime);
408 void resolveCollisions(Math::Vector3d newPosition);
409 virtual Math::Vector3d clipPosition(
const Math::Vector3d &position)
const {
return position; }
410 virtual void checkIfStillInArea();
411 void changePlayerHeight(
int index);
412 void increaseStepSize();
413 void decreaseStepSize();
414 void changeStepSize();
416 void changeAngle(
int offset,
bool wrapAround);
419 bool checkFloor(Math::Vector3d currentPosition);
420 bool tryStepUp(Math::Vector3d currentPosition);
421 bool tryStepDown(Math::Vector3d currentPosition);
423 bool _isCollidingWithWall;
425 bool _isSteppingDown;
427 int _maxFallingDistance;
431 void rotate(
float xoffset,
float yoffset,
float zoffset);
438 void traverseEntrance(uint16 entranceID);
444 int _angleRotationIndex;
447 Math::Vector3d directionToVector(
float pitch,
float heading,
bool useTable);
449 virtual void onRotate(
float xoffset,
float yoffset,
float zoffset) {}
453 float _mouseSensitivity;
454 Math::Vector3d _upVector;
455 Math::Vector3d _cameraFront, _cameraRight;
457 Math::Vector3d _position, _rotation, _velocity;
458 Math::Vector3d _lastPosition;
459 int _playerHeightNumber;
460 int _playerHeightMaxNumber;
461 uint16 _playerHeight;
464 uint16 _stepUpDistance;
466 int _playerStepIndex;
467 int _savedPlayerStepIndex;
472 void warpMouseToCrossair(
void);
478 bool runCollisionConditions(Math::Vector3d
const lastPosition, Math::Vector3d
const newPosition);
479 Math::Vector3d _objExecutingCodeSize;
480 bool _executingGlobalCode;
481 virtual void executeMovementConditions();
482 virtual bool executeObjectConditions(GeometricObject *obj,
bool shot,
bool collided,
bool activated);
483 void executeEntranceConditions(Entrance *entrance);
484 virtual void executeLocalGlobalConditions(
bool shot,
bool collided,
bool timer);
485 virtual void updateScripts() {}
486 bool executeCode(FCLInstructionVector &code,
bool shot,
bool collided,
bool timer,
bool activated);
489 bool checkConditional(
const FCLInstruction &instruction,
bool shot,
bool collided,
bool timer,
bool activated);
490 bool checkIfGreaterOrEqual(FCLInstruction &instruction);
491 bool checkIfLessOrEqual(FCLInstruction &instruction);
492 void executeCall(FCLInstruction &instruction);
493 void executeIncrementVariable(FCLInstruction &instruction);
494 void executeDecrementVariable(FCLInstruction &instruction);
495 void executeSetVariable(FCLInstruction &instruction);
496 void executeGoto(FCLInstruction &instruction);
497 virtual void executeMakeInvisible(FCLInstruction &instruction);
498 void executeMakeVisible(FCLInstruction &instruction);
499 void executeToggleVisibility(FCLInstruction &instruction);
500 virtual void executeDestroy(FCLInstruction &instruction);
501 virtual void executeRedraw(FCLInstruction &instruction);
502 void executeSound(FCLInstruction &instruction);
503 void executeDelay(FCLInstruction &instruction);
504 bool executeEndIfNotEqual(FCLInstruction &instruction);
505 void executeSetBit(FCLInstruction &instruction);
506 void executeClearBit(FCLInstruction &instruction);
507 void executeToggleBit(FCLInstruction &instruction);
508 bool executeEndIfBitNotEqual(FCLInstruction &instruction);
509 bool executeEndIfVisibilityIsEqual(FCLInstruction &instruction);
510 void executeSwapJet(FCLInstruction &instruction);
511 virtual void executePrint(FCLInstruction &instruction);
512 void executeSPFX(FCLInstruction &instruction);
513 void executeStartAnim(FCLInstruction &instruction);
522 bool _usePrerecordedSounds;
523 void waitForSounds(Sound::Type type = Sound::kTypeNormal);
524 void stopAllSounds(Sound::Type type = Sound::kTypeNormal);
525 bool isPlayingSound(Sound::Type type = Sound::kTypeNormal);
526 virtual void playSound(
int index,
bool sync, Sound::Type type = Sound::kTypeNormal);
530 virtual void playSoundFx(
int index,
bool sync, Sound::Type type = Sound::kTypeNormal) {}
535 Sound *loadSpeakerFxDrillerZX();
536 Sound *loadSoundsCPC(
Common::SeekableReadStream *file,
int offsetTone,
int sizeTone,
int offsetEnvelope,
int sizeEnvelope,
int offsetSoundDef,
int sizeSoundDef);
542 int _soundIndexShoot;
543 int _soundIndexCollide;
544 int _soundIndexStepDown;
545 int _soundIndexStepUp;
548 int _soundIndexStart;
549 int _soundIndexAreaChange;
552 int _soundIndexNoShield;
553 int _soundIndexNoEnergy;
554 int _soundIndexFallen;
555 int _soundIndexTimeout;
556 int _soundIndexForceEndGame;
557 int _soundIndexCrushed;
558 int _soundIndexMissionComplete;
561 int _screenW, _screenH;
567 int _underFireFrames;
568 int _avoidRenderingFrames;
570 GeometricObject *_delayedShootObject;
572 Math::Vector3d getCameraRenderPosition();
573 void drawFrameStereo(
int farClipPlane);
577 void flashScreen(
int backgroundColor);
579 Math::Vector3d _scaleVector;
581 float _viewAspectRatio;
582 float _nearClipPlane;
586 void insertTemporaryMessage(
const Common::String &message,
int deadline);
588 void clearTemporalMessages();
608 void loadFonts(
byte *font,
int charNumber);
617 virtual void drawStringInSurface(
const Common::String &str,
int x,
int y, uint32 fontColor, uint32 backColor,
Graphics::Surface *surface,
int offset = 0);
618 virtual void drawStringInSurface(
const Common::String &str,
int x,
int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor,
Graphics::Surface *surface,
int offset = 0);
622 virtual void initGameState();
623 void setGameBit(
int index);
624 void clearGameBit(
int index);
625 void toggleGameBit(
int index);
626 uint16 getGameBit(
int index);
628 StateVars _gameStateVars;
629 uint32 _gameStateBits;
630 void checkIfPlayerWasCrushed();
631 virtual bool triggerWinCondition();
632 virtual bool checkIfGameEnded();
633 virtual void endGame();
634 int _endGameDelayTicks;
635 bool _endGameKeyPressed;
636 bool _endGamePlayerEndArea;
638 bool _playerWasCrushed;
640 ObjectArray _sensors;
641 virtual void checkSensors();
642 virtual void drawSensorShoot(Sensor *sensor);
643 void takeDamageFromSensor();
652 bool canSaveGameStateCurrently(
Common::U32String *msg =
nullptr)
override {
return _gameStateControl == kFreescapeGameStatePlaying && _currentArea && !_hasFallen && !_playerWasCrushed && _gameStateVars.getValOrDefault(k8bitVariableShield) > 0; }
662 bool startCountdown(uint32 delay);
665 int _initialCountdown;
673 void getTimeFromCountdown(
int &seconds,
int &minutes,
int &hours);
674 virtual void updateTimeVariables();
677 bool _useExtendedTimer;
678 bool _disableSensors;
679 bool _disableFalling;
690enum GameReleaseFlags {
691 GF_AMIGA_RETAIL = (1 << 0),
692 GF_AMIGA_BUDGET = (1 << 1),
693 GF_ZX_RETAIL = (1 << 2),
694 GF_ZX_BUDGET = (1 << 3),
695 GF_ZX_DISC = (1 << 4),
696 GF_CPC_RETAIL = (1 << 5),
697 GF_CPC_RETAIL_ALT = (1 << 6),
698 GF_CPC_BUDGET = (1 << 7),
699 GF_CPC_VIRTUALWORLDS = (1 << 8),
700 GF_ATARI_RETAIL = (1 << 9),
701 GF_ATARI_BUDGET = (1 << 10),
702 GF_C64_TAPE = (1 << 11),
703 GF_C64_DISC = (1 << 12),
704 GF_C64_PACKED = (1 << 13),
707extern FreescapeEngine *g_freescape;
708extern Debugger *g_debugger;
Definition: archive.h:141
const Common::String _targetName
Definition: engine.h:186
EngineFeature
Definition: engine.h:282
Definition: freescape.h:164
Definition: freescape.h:191
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
void pauseEngineIntern(bool pause) override
bool hasFeature(EngineFeature f) const override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: freescape.h:646
bool canSaveAutosaveCurrently() override
Definition: freescape.h:647
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: freescape.h:652
Common::Error run() override
Definition: framelimiter.h:40
Definition: managed_surface.h:51
uint32 CustomEventType
Definition: events.h:212
Language
Definition: language.h:45
RenderMode
Definition: rendermode.h:48
Definition: algorithm.h:29
Definition: advancedDetector.h:164
Common::Platform platform
Definition: advancedDetector.h:199
Definition: keyboard.h:294
Definition: freescape.h:155