25#include "common/scummsys.h"
26#include "common/error.h"
27#include "common/util.h"
28#include "common/file.h"
29#include "common/keyboard.h"
30#include "common/rect.h"
31#include "common/rendermode.h"
32#include "common/stack.h"
33#include "common/str.h"
34#include "common/system.h"
35#include "common/text-to-speech.h"
37#include "engines/engine.h"
39#include "gui/debugger.h"
42#include "agi/console.h"
44#include "agi/picture.h"
66#define TITLE "AGI engine"
69#define LOGDIR "logdir"
70#define PICDIR "picdir"
71#define VIEWDIR "viewdir"
72#define SNDDIR "snddir"
73#define OBJECTS "object"
74#define WORDS "words.tok"
76#define MAX_DIRECTORY_ENTRIES 256
77#define MAX_CONTROLLERS 256
79#define MAX_FLAGS (256 >> 3)
80#define SCREENOBJECTS_MAX 255
81#define SCREENOBJECTS_EGO_ENTRY 0
84#define MAX_STRINGLEN 40
85#define MAX_CONTROLLER_KEYMAPPINGS 39
87#define SAVEDGAME_DESCRIPTION_LEN 30
91#define EGO_OWNED_V1 0xf9
93#define CRYPT_KEY_SIERRA "Avis Durgan"
94#define CRYPT_KEY_AGDS "Alex Simkin"
110enum AgiGameFeatures {
111 GF_AGIMOUSE = (1 << 0),
113 GF_AGI256 = (1 << 2),
114 GF_FANMADE = (1 << 3),
115 GF_2GSOLDSOUND = (1 << 5)
155 kDebugLevelResources,
158 kDebugLevelInventory,
171 RESOURCETYPE_LOGIC = 1,
179 RES_COMPRESSED = 0x40,
180 RES_PICTURE_V3_NIBBLE_PARM = 0x80
201 Mouse() : button(0) {}
208 kAgiMouseButtonRight,
209 kAgiMouseButtonMiddle
216 VM_VAR_CURRENT_ROOM = 0,
217 VM_VAR_PREVIOUS_ROOM,
218 VM_VAR_BORDER_TOUCH_EGO,
221 VM_VAR_BORDER_TOUCH_OBJECT,
222 VM_VAR_EGO_DIRECTION,
225 VM_VAR_WORD_NOT_FOUND,
231 VM_VAR_JOYSTICK_SENSITIVITY,
232 VM_VAR_EGO_VIEW_RESOURCE,
233 VM_VAR_AGI_ERROR_CODE,
234 VM_VAR_AGI_ERROR_INFO,
237 VM_VAR_WINDOW_AUTO_CLOSE_TIMER,
238 VM_VAR_SOUNDGENERATOR,
240 VM_VAR_MAX_INPUT_CHARACTERS,
241 VM_VAR_SELECTED_INVENTORY_ITEM,
243 VM_VAR_MOUSE_BUTTONSTATE = 27,
255 kAgiMonitorHercules = 2,
266 kAgiComputerApple2 = 3,
267 kAgiComputerAtariST = 4,
268 kAgiComputerAmiga = 5,
269 kAgiComputerApple2GS = 7
282 VM_FLAG_EGO_WATER = 0,
283 VM_FLAG_EGO_INVISIBLE,
285 VM_FLAG_EGO_TOUCHED_P2,
286 VM_FLAG_SAID_ACCEPTED_INPUT,
287 VM_FLAG_NEW_ROOM_EXEC,
288 VM_FLAG_RESTART_GAME,
289 VM_FLAG_SCRIPT_BLOCKED,
290 VM_FLAG_JOY_SENSITIVITY,
293 VM_FLAG_LOGIC_ZERO_FIRST_TIME,
294 VM_FLAG_RESTORE_JUST_RAN,
295 VM_FLAG_STATUS_SELECTS_ITEMS,
296 VM_FLAG_MENUS_ACCESSIBLE,
342 AgiBlock() : active(
false), x1(0), y1(0), x2(0), y2(0) {}
350enum CycleInnerLoopType {
351 CYCLE_INNERLOOP_GETSTRING = 0,
352 CYCLE_INNERLOOP_GETNUMBER,
353 CYCLE_INNERLOOP_INVENTORY,
354 CYCLE_INNERLOOP_MENU_VIA_KEYBOARD,
355 CYCLE_INNERLOOP_MENU_VIA_MOUSE,
356 CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT,
357 CYCLE_INNERLOOP_SYSTEMUI_VERIFICATION,
358 CYCLE_INNERLOOP_MESSAGEBOX,
359 CYCLE_INNERLOOP_HAVEKEY
364struct AgiAppleIIgsDelayOverwriteGameEntry;
389 bool cycleInnerLoopActive;
390 int16 cycleInnerLoopType;
406 unsigned int numObjects;
414 AgiDir dirLogic[MAX_DIRECTORY_ENTRIES];
415 AgiDir dirPic[MAX_DIRECTORY_ENTRIES];
416 AgiDir dirView[MAX_DIRECTORY_ENTRIES];
417 AgiDir dirSound[MAX_DIRECTORY_ENTRIES];
433 char automaticSaveDescription[SAVEDGAME_DESCRIPTION_LEN + 1];
453 bool nonBlockingTextShown;
454 int16 nonBlockingTextCyclesLeft;
456 bool automaticRestoreGame;
460 uint16 appleIIgsSpeedControllerSlot;
462 const char *getString(
int number);
463 void setString(
int number,
const char *str);
475 memset(
id, 0,
sizeof(
id));
482 cycleInnerLoopActive =
false;
483 cycleInnerLoopType = 0;
522 memset(automaticSaveDescription, 0,
sizeof(automaticSaveDescription));
532 memset(logic_list, 0,
sizeof(logic_list));
534 nonBlockingTextShown =
false;
535 nonBlockingTextCyclesLeft = 0;
537 automaticRestoreGame =
false;
541 appleIIgsSpeedControllerSlot = 0xffff;
554struct AGIGameDescription;
569#define TICK_SECONDS 20
571#define KEY_QUEUE_SIZE 16
587 virtual void initialize() = 0;
589 void initRenderMode();
606 bool _noSaveLoadAllowed;
608 virtual bool promptIsEnabled() {
612 virtual int getKeypress() = 0;
613 virtual bool isKeypress() = 0;
614 virtual void clearKeyQueue() = 0;
619 virtual void clearImageStack() = 0;
620 virtual void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
621 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
622 virtual void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
623 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
624 virtual void releaseImageStack() = 0;
628 bool getFlag(int16 flagNr);
629 void setFlag(int16 flagNr,
bool newState);
630 void flipFlag(int16 flagNr);
636 uint32 _gameFeatures;
639 uint32 getGameID()
const;
640 uint32 getFeatures()
const;
641 uint16 getVersion()
const;
642 uint16 getGameType()
const;
644 bool isLanguageRTL()
const;
646 const char *getGameMD5()
const;
650 const char *getDiskName(uint16
id);
655 const byte *getFontData();
657 void cycleInnerLoopActive(int16 loopType) {
658 _game.cycleInnerLoopActive =
true;
659 _game.cycleInnerLoopType = loopType;
661 void cycleInnerLoopInactive() {
662 _game.cycleInnerLoopActive =
false;
664 bool cycleInnerLoopIsActive() {
665 return _game.cycleInnerLoopActive;
669enum AgiArtificialDelayTriggerType {
670 ARTIFICIALDELAYTYPE_NEWROOM = 0,
671 ARTIFICIALDELAYTYPE_NEWPICTURE = 1,
672 ARTIFICIALDELAYTYPE_END = -1
678 AgiArtificialDelayTriggerType triggerType;
681 uint16 millisecondsDelay;
688 const char *parameters;
689 AgiOpCodeFunction functionPtr;
690 uint16 parameterSize;
695 const char *parameters;
696 AgiOpCodeFunction functionPtr;
704 void initialize()
override;
710 bool promptIsEnabled()
override;
716 int _keyQueue[KEY_QUEUE_SIZE];
720 bool _allowSynthetic;
732 bool getSavegameInformation(int16 slotId,
Common::String &saveDescription, uint32 &saveDate, uint32 &saveTime,
bool &saveIsValid);
735 int loadGame(
const Common::String &fileName,
bool checkId =
true);
736 bool saveGameDialog();
737 bool saveGameAutomatic();
738 bool loadGameDialog();
739 bool loadGameAutomatic();
741 int doLoad(
int slot,
bool showMessages);
742 int scummVMSaveLoadDialog(
bool isSave);
759 int16 _previousDisplayRow;
764 bool _replaceDisplayNewlines;
765 Common::CodePage _ttsEncoding;
768 void clearImageStack()
override;
769 void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
770 int16 p4, int16 p5, int16 p6, int16 p7)
override;
771 void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
772 int16 p4, int16 p5, int16 p6, int16 p7)
override;
773 void releaseImageStack()
override;
775 void wait(uint32 msec,
bool busy =
false);
779 int loadResource(int16 resourceType, int16 resourceNr);
780 void unloadResource(int16 resourceType, int16 resourceNr);
786 int getKeypress()
override;
787 bool isKeypress()
override;
788 void clearKeyQueue()
override;
790 byte getVar(int16 varNr);
791 void setVar(int16 varNr,
byte newValue);
794 void applyVolumeToMixer();
800 void sayText(
const Common::String &text, Common::TextToSpeechManager::Action action = Common::TextToSpeechManager::QUEUE,
801 bool checkPreviousSaid =
true);
802 void stopTextToSpeech(
bool clearPreviousSaid =
true);
806 void decrypt(uint8 *mem,
int len);
807 uint16 processAGIEvents();
810 void newRoom(int16 newRoomNr);
811 void resetControllers();
812 void interpretCycle();
815 void allowSynthetic(
bool);
816 void processScummVMEvents();
817 void checkQuickLoad();
826 int loadObjects(
const char *fname);
828 const char *objectName(uint16 objectNr);
829 int objectGetLocation(uint16 objectNr);
830 void objectSetLocation(uint16 objectNr,
int location);
832 int decodeObjects(uint8 *mem, uint32 flen);
836 int decodeLogic(int16 logicNr);
837 void unloadLogic(int16 logicNr);
838 int runLogic(int16 logicNr);
839 void debugConsole(
int lognum,
int mode,
const char *str);
840 bool testIfCode(int16 logicNr);
841 void executeAgiCommand(uint8 op, uint8 *p);
844 bool _veryFirstInitialCycle;
845 uint32 _instructionCounter;
847 bool _setVolumeBrokenFangame;
849 void resetGetVarSecondsHeuristic();
850 void getVarSecondsHeuristicTrigger();
851 uint32 _getVarSecondsHeuristicLastInstructionCounter;
852 uint16 _getVarSecondsHeuristicCounter;
854 uint32 _playTimeInSecondsAdjust;
856 void setVarSecondsTrigger(
byte newSeconds);
860 void skipInstruction(
byte op);
861 void skipInstructionsUntil(
byte v);
862 bool testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
863 bool testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
864 bool testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
865 bool testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
866 bool testSaid(uint8 nwords, uint8 *cc);
867 bool testController(uint8 cont);
868 bool testCompareStrings(uint8 s1, uint8 s2);
872 void unloadPicture(int16 picNr);
887 void updateScreenObjTable();
888 void unloadView(int16 viewNr);
889 int decodeView(
byte *resourceData, uint16 resourceSize, int16 viewNr);
892 void unpackViewCelData(
AgiViewCel *celData,
byte *compressedData, uint16 compressedSize, int16 viewNr);
893 void unpackViewCelDataAGI256(
AgiViewCel *celData,
byte *compressedData, uint16 compressedSize, int16 viewNr);
900 int checkStep(
int delta,
int step);
901 bool checkBlock(int16 x, int16 y);
912 void checkAllMotions();
915 void fixPosition(int16 screenObjNr);
917 void updatePosition();
918 int getDirection(int16 objX, int16 objY, int16 destX, int16 destY, int16 stepSize);
919 byte egoNearWater(
byte limit);
920 int16 nearWater(
ScreenObjEntry &screenObj,
byte direction, int16 x, int16 y,
byte limit);
923 Common::KeyCode _keyHoldModeLastKey;
926 int doPollKeyboard();
928 bool handleMouseClicks(uint16 &key);
929 bool handleController(uint16 key);
931 bool showPredictiveDialog();
935 void waitAnyKeyOrFinishedSound();
937 void nonBlockingText_IsShown();
938 void nonBlockingText_Forget();
940 void artificialDelay_Reset();
941 void artificialDelay_CycleDone();
943 uint16 artificialDelay_SearchTable(AgiArtificialDelayTriggerType triggerType, int16 orgNr, int16 newNr);
945 void artificialDelayTrigger_NewRoom(int16 newRoomNr);
946 void artificialDelayTrigger_DrawPicture(int16 newPictureNr);
949 int16 _artificialDelayCurrentRoom;
950 int16 _artificialDelayCurrentPicture;
955 void inGameTimerReset(uint32 newPlayTime = 0);
956 void inGameTimerResetPassedCycles();
957 uint32 inGameTimerGet();
958 uint32 inGameTimerGetPassedCycles();
960 void inGameTimerUpdate();
963 uint32 _lastUsedPlayTimeInCycles;
964 uint32 _lastUsedPlayTimeInSeconds;
965 uint32 _passedPlayTimeCycles;
971 void setupOpCodes(uint16 version);
977 void goldRushClockTimeWorkaround_OnReadVar();
978 void goldRushClockTimeWorkaround_OnWriteVar(
byte oldValue);
void setFlagOrVar(int16 flagNr, bool newState)
Common::Error run() override
Definition: agi.h:578
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
bool hasFeature(EngineFeature f) const override
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
void syncSoundSettings() override
Common::Error loadGameState(int slot) override
Common::Error saveGameState(int slot, const Common::String &description, bool isAutosave=false) override
Definition: graphics.h:58
Definition: systemui.h:51
ErrorCode getCode() const
Definition: error.h:112
const Common::String _targetName
Definition: engine.h:192
EngineFeature
Definition: engine.h:293
@ kNoError
No error occurred.
Definition: error.h:48
Language
Definition: language.h:45
RenderMode
Definition: rendermode.h:48
AgiMonitorType
Definition: agi.h:252
AgiComputerType
Definition: agi.h:264
Definition: algorithm.h:29
Definition: detection.h:29
Definition: appleIIgs_timedelay_overwrite.h:36
AgiLogic logics[256]
Definition: agi.h:421
int16 horizon
Definition: agi.h:387
bool pictureShown
Definition: agi.h:398
uint8 flags[(256 > > 3)]
Definition: agi.h:383
bool playerControl
Definition: agi.h:396
uint8 vars[256]
Definition: agi.h:384
bool predictiveDlgOnMouseClick
Definition: agi.h:438
byte speedLevel
Definition: agi.h:458
bool mouseHidden
Definition: agi.h:437
char strings[24+1][40]
Definition: agi.h:411
bool automaticSave
Definition: agi.h:432
bool exitAllLogics
Definition: agi.h:397
int16 curLogicNr
Definition: agi.h:392
AgiView views[256]
Definition: agi.h:422
bool mouseEnabled
Definition: agi.h:436
int adjMouseX
Definition: agi.h:376
AgiSound * sounds[256]
Definition: agi.h:423
bool controllerOccurred[256]
Definition: agi.h:408
Common::Rect mouseFence
Definition: agi.h:435
uint32 crc
Definition: agi.h:380
int adjMouseY
Definition: agi.h:377
AgiPicture pictures[256]
Definition: agi.h:420
void setSpeedLevel(byte s)