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" 36 #include "engines/engine.h" 38 #include "gui/debugger.h" 41 #include "agi/console.h" 43 #include "agi/picture.h" 44 #include "agi/logic.h" 45 #include "agi/sound.h" 65 typedef signed int Err;
71 #define TITLE "AGI engine" 74 #define LOGDIR "logdir" 75 #define PICDIR "picdir" 76 #define VIEWDIR "viewdir" 77 #define SNDDIR "snddir" 78 #define OBJECTS "object" 79 #define WORDS "words.tok" 81 #define MAX_DIRECTORY_ENTRIES 256 82 #define MAX_CONTROLLERS 256 84 #define MAX_FLAGS (256 >> 3) 85 #define SCREENOBJECTS_MAX 255 // KQ3 uses o255! 86 #define SCREENOBJECTS_EGO_ENTRY 0 // first entry is ego 88 #define MAX_STRINGS 24 // MAX_STRINGS + 1 used for get.num 89 #define MAX_STRINGLEN 40 90 #define MAX_CONTROLLER_KEYMAPPINGS 39 92 #define SAVEDGAME_DESCRIPTION_LEN 30 94 #define _EMPTY 0xfffff 95 #define EGO_OWNED 0xff 96 #define EGO_OWNED_V1 0xf9 98 #define CRYPT_KEY_SIERRA "Avis Durgan" 99 #define CRYPT_KEY_AGDS "Alex Simkin" 118 enum AgiGameFeatures {
119 GF_AGIMOUSE = (1 << 0),
121 GF_AGI256 = (1 << 2),
122 GF_FANMADE = (1 << 3),
123 GF_2GSOLDSOUND = (1 << 5),
124 GF_EXTCHAR = (1 << 6)
164 errUnknownAGIVersion,
174 kDebugLevelMain = 1 << 0,
175 kDebugLevelResources = 1 << 1,
176 kDebugLevelSprites = 1 << 2,
177 kDebugLevelInventory = 1 << 3,
178 kDebugLevelInput = 1 << 4,
179 kDebugLevelMenu = 1 << 5,
180 kDebugLevelScripts = 1 << 6,
181 kDebugLevelSound = 1 << 7,
182 kDebugLevelText = 1 << 8,
183 kDebugLevelSavegame = 1 << 9
190 RESOURCETYPE_LOGIC = 1,
198 RES_COMPRESSED = 0x40,
199 RES_PICTURE_V3_NIBBLE_PARM = 0x80
220 Mouse() : button(0) {}
224 enum AgiMouseButton {
227 kAgiMouseButtonRight,
228 kAgiMouseButtonMiddle
235 VM_VAR_CURRENT_ROOM = 0,
236 VM_VAR_PREVIOUS_ROOM,
237 VM_VAR_BORDER_TOUCH_EGO,
240 VM_VAR_BORDER_TOUCH_OBJECT,
241 VM_VAR_EGO_DIRECTION,
244 VM_VAR_WORD_NOT_FOUND,
250 VM_VAR_JOYSTICK_SENSITIVITY,
251 VM_VAR_EGO_VIEW_RESOURCE,
252 VM_VAR_AGI_ERROR_CODE,
253 VM_VAR_AGI_ERROR_INFO,
256 VM_VAR_WINDOW_AUTO_CLOSE_TIMER,
257 VM_VAR_SOUNDGENERATOR,
259 VM_VAR_MAX_INPUT_CHARACTERS,
260 VM_VAR_SELECTED_INVENTORY_ITEM,
262 VM_VAR_MOUSE_BUTTONSTATE = 27,
274 kAgiMonitorHercules = 2,
285 kAgiComputerAtariST = 4,
286 kAgiComputerAmiga = 5,
287 kAgiComputerApple2GS = 7
300 VM_FLAG_EGO_WATER = 0,
301 VM_FLAG_EGO_INVISIBLE,
303 VM_FLAG_EGO_TOUCHED_P2,
304 VM_FLAG_SAID_ACCEPTED_INPUT,
305 VM_FLAG_NEW_ROOM_EXEC,
306 VM_FLAG_RESTART_GAME,
307 VM_FLAG_SCRIPT_BLOCKED,
308 VM_FLAG_JOY_SENSITIVITY,
311 VM_FLAG_LOGIC_ZERO_FIRST_TIME,
312 VM_FLAG_RESTORE_JUST_RAN,
313 VM_FLAG_STATUS_SELECTS_ITEMS,
314 VM_FLAG_MENUS_ACCESSIBLE,
360 AgiBlock() : active(
false), x1(0), y1(0), x2(0), y2(0) {}
368 enum CycleInnerLoopType {
369 CYCLE_INNERLOOP_GETSTRING = 0,
370 CYCLE_INNERLOOP_GETNUMBER,
371 CYCLE_INNERLOOP_INVENTORY,
372 CYCLE_INNERLOOP_MENU_VIA_KEYBOARD,
373 CYCLE_INNERLOOP_MENU_VIA_MOUSE,
374 CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT,
375 CYCLE_INNERLOOP_SYSTEMUI_VERIFICATION,
376 CYCLE_INNERLOOP_MESSAGEBOX,
377 CYCLE_INNERLOOP_HAVEKEY
400 uint8 flags[MAX_FLAGS];
401 uint8 vars[MAX_VARS];
406 bool cycleInnerLoopActive;
407 int16 cycleInnerLoopType;
423 unsigned int numObjects;
425 bool controllerOccurred[MAX_CONTROLLERS];
428 char strings[MAX_STRINGS + 1][MAX_STRINGLEN];
431 AgiDir dirLogic[MAX_DIRECTORY_ENTRIES];
432 AgiDir dirPic[MAX_DIRECTORY_ENTRIES];
433 AgiDir dirView[MAX_DIRECTORY_ENTRIES];
434 AgiDir dirSound[MAX_DIRECTORY_ENTRIES];
450 char automaticSaveDescription[SAVEDGAME_DESCRIPTION_LEN + 1];
469 bool nonBlockingTextShown;
470 int16 nonBlockingTextCyclesLeft;
472 bool automaticRestoreGame;
474 uint16 appleIIgsSpeedControllerSlot;
475 int appleIIgsSpeedLevel;
477 void setAppleIIgsSpeedLevel(
int appleIIgsSpeedLevel);
485 for (uint16 i = 0; i <
ARRAYSIZE(name); i++) {
488 for (uint16 i = 0; i <
ARRAYSIZE(
id); i++) {
493 for (uint16 i = 0; i <
ARRAYSIZE(flags); i++) {
496 for (uint16 i = 0; i <
ARRAYSIZE(vars); i++) {
502 cycleInnerLoopActive =
false;
503 cycleInnerLoopType = 0;
509 playerControl =
false;
510 exitAllLogics =
false;
511 pictureShown =
false;
519 for (uint16 i = 0; i <
ARRAYSIZE(controllerOccurred); i++) {
520 controllerOccurred[i] =
false;
525 for (uint16 i = 0; i < MAX_STRINGS + 1; i++) {
526 for (uint16 j = 0; j < MAX_STRINGLEN; j++) {
539 for (uint16 i = 0; i <
ARRAYSIZE(sounds); i++) {
549 automaticSave =
false;
550 for (uint16 i = 0; i <
ARRAYSIZE(automaticSaveDescription); i++) {
551 automaticSaveDescription[i] = 0;
555 mouseEnabled =
false;
561 for (uint16 i = 0; i <
ARRAYSIZE(logic_list); i++) {
565 nonBlockingTextShown =
false;
566 nonBlockingTextCyclesLeft = 0;
568 automaticRestoreGame =
false;
570 appleIIgsSpeedControllerSlot = 0xffff;
571 appleIIgsSpeedLevel = 2;
581 virtual int init() = 0;
582 virtual int detectGame() = 0;
583 virtual int loadResource(int16 resourceType, int16 resourceNr) = 0;
584 virtual void unloadResource(int16 resourceType, int16 resourceNr) = 0;
585 virtual int loadObjects(
const char *fname) = 0;
586 virtual int loadWords(
const char *fname) = 0;
595 int loadDir_DDP(
AgiDir *agid,
int offset,
int max);
596 int loadDir_BC(
AgiDir *agid,
int offset,
int max);
597 uint8 *loadVolRes(
AgiDir *agid);
603 int detectGame()
override;
604 int loadResource(int16 resourceType, int16 resourceNr)
override;
605 void unloadResource(int16 resourceType, int16 resourceNr)
override;
606 int loadObjects(
const char *fname)
override;
607 int loadWords(
const char *fname)
override;
613 bool _hasV3VolumeFormat;
615 int loadDir(
AgiDir *agid,
const char *fname);
616 uint8 *loadVolRes(
AgiDir *agid);
617 bool detectV3VolumeFormat();
623 _hasV3VolumeFormat =
false;
627 int detectGame()
override;
628 int loadResource(int16 resourceType, int16 resourceNr)
override;
629 void unloadResource(int16 resourceType, int16 resourceNr)
override;
630 int loadObjects(
const char *fname)
override;
631 int loadWords(
const char *fname)
override;
639 uint8 *loadVolRes(
AgiDir *agid);
648 int detectGame()
override;
649 int loadResource(int16 resourceType, int16 resourceNr)
override;
650 void unloadResource(int16 resourceType, int16 resourceNr)
override;
651 int loadObjects(
const char *fname)
override;
652 int loadWords(
const char *fname)
override;
678 #define TICK_SECONDS 20 680 #define KEY_QUEUE_SIZE 16 696 virtual void initialize() = 0;
698 void initRenderMode();
715 bool _noSaveLoadAllowed;
717 virtual bool promptIsEnabled() {
721 virtual int getKeypress() = 0;
722 virtual bool isKeypress() = 0;
723 virtual void clearKeyQueue() = 0;
728 virtual void clearImageStack() = 0;
729 virtual void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
730 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
731 virtual void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
732 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
733 virtual void releaseImageStack() = 0;
737 bool getFlag(int16 flagNr);
738 void setFlag(int16 flagNr,
bool newState);
739 void flipFlag(int16 flagNr);
743 uint32 _gameFeatures;
746 uint32 getGameID()
const;
747 uint32 getFeatures()
const;
748 uint16 getVersion()
const;
749 uint16 getGameType()
const;
751 bool isLanguageRTL()
const;
753 const char *getGameMD5()
const;
757 const char *getDiskName(uint16
id);
762 const byte *getFontData();
764 void cycleInnerLoopActive(int16 loopType) {
765 _game.cycleInnerLoopActive =
true;
766 _game.cycleInnerLoopType = loopType;
768 void cycleInnerLoopInactive() {
769 _game.cycleInnerLoopActive =
false;
771 bool cycleInnerLoopIsActive() {
772 return _game.cycleInnerLoopActive;
776 enum AgiArtificialDelayTriggerType {
777 ARTIFICIALDELAYTYPE_NEWROOM = 0,
778 ARTIFICIALDELAYTYPE_NEWPICTURE = 1,
779 ARTIFICIALDELAYTYPE_END = -1
785 AgiArtificialDelayTriggerType triggerType;
788 uint16 millisecondsDelay;
795 const char *parameters;
796 AgiOpCodeFunction functionPtr;
797 uint16 parameterSize;
802 const char *parameters;
803 AgiOpCodeFunction functionPtr;
811 void initialize()
override;
817 bool promptIsEnabled()
override;
823 int _keyQueue[KEY_QUEUE_SIZE];
827 bool _allowSynthetic;
838 SavedGameSlotIdArray getSavegameSlotIds();
839 bool getSavegameInformation(int16 slotId,
Common::String &saveDescription, uint32 &saveDate, uint32 &saveTime,
bool &saveIsValid);
842 int loadGame(
const Common::String &fileName,
bool checkId =
true);
843 bool saveGameDialog();
844 bool saveGameAutomatic();
845 bool loadGameDialog();
846 bool loadGameAutomatic();
848 int doLoad(
int slot,
bool showMessages);
849 int scummVMSaveLoadDialog(
bool isSave);
865 void clearImageStack()
override;
866 void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
867 int16 p4, int16 p5, int16 p6, int16 p7)
override;
868 void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
869 int16 p4, int16 p5, int16 p6, int16 p7)
override;
870 void releaseImageStack()
override;
872 void wait(uint32 msec,
bool busy =
false);
876 int agiLoadResource(int16 resourceType, int16 resourceNr);
877 void agiUnloadResource(int16 resourceType, int16 resourceNr);
878 void agiUnloadResources();
880 int getKeypress()
override;
881 bool isKeypress()
override;
882 void clearKeyQueue()
override;
884 byte getVar(int16 varNr);
885 void setVar(int16 varNr, byte newValue);
888 void applyVolumeToMixer();
891 void syncSoundSettings()
override;
894 void decrypt(uint8 *mem,
int len);
895 uint16 processAGIEvents();
898 void newRoom(int16 newRoomNr);
899 void resetControllers();
900 void interpretCycle();
903 void allowSynthetic(
bool);
904 void processScummVMEvents();
905 void checkQuickLoad();
907 const Common::String getTargetName()
const {
return _targetName; }
911 int loadObjects(
const char *fname);
913 const char *objectName(uint16 objectNr);
914 int objectGetLocation(uint16 objectNr);
915 void objectSetLocation(uint16 objectNr,
int location);
917 int decodeObjects(uint8 *mem, uint32 flen);
922 int decodeLogic(int16 logicNr);
923 void unloadLogic(int16 logicNr);
924 int runLogic(int16 logicNr);
925 void debugConsole(
int lognum,
int mode,
const char *str);
926 bool testIfCode(int16 logicNr);
927 void executeAgiCommand(uint8 op, uint8 *p);
930 bool _veryFirstInitialCycle;
931 uint32 _instructionCounter;
933 bool _setVolumeBrokenFangame;
935 void resetGetVarSecondsHeuristic();
936 void getVarSecondsHeuristicTrigger();
937 uint32 _getVarSecondsHeuristicLastInstructionCounter;
938 uint16 _getVarSecondsHeuristicCounter;
940 uint32 _playTimeInSecondsAdjust;
942 void setVarSecondsTrigger(byte newSeconds);
946 void skipInstruction(byte op);
947 void skipInstructionsUntil(byte v);
948 bool testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
949 bool testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
950 bool testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
951 bool testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
952 bool testSaid(uint8 nwords, uint8 *cc);
953 bool testController(uint8 cont);
954 bool testCompareStrings(uint8 s1, uint8 s2);
969 void updateScreenObjTable();
970 void unloadView(int16 viewNr);
971 int decodeView(byte *resourceData, uint16 resourceSize, int16 viewNr);
974 void unpackViewCelData(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize);
975 void unpackViewCelDataAGI256(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize);
982 int checkStep(
int delta,
int step);
983 bool checkBlock(int16 x, int16 y);
994 void checkAllMotions();
997 void fixPosition(int16 screenObjNr);
999 void updatePosition();
1000 int getDirection(int16 objX, int16 objY, int16 destX, int16 destY, int16 stepSize);
1003 Common::KeyCode _keyHoldModeLastKey;
1006 int doPollKeyboard();
1008 bool handleMouseClicks(uint16 &key);
1009 bool handleController(uint16 key);
1011 bool showPredictiveDialog();
1016 void nonBlockingText_IsShown();
1017 void nonBlockingText_Forget();
1019 void artificialDelay_Reset();
1020 void artificialDelay_CycleDone();
1022 uint16 artificialDelay_SearchTable(AgiArtificialDelayTriggerType triggerType, int16 orgNr, int16 newNr);
1024 void artificialDelayTrigger_NewRoom(int16 newRoomNr);
1025 void artificialDelayTrigger_DrawPicture(int16 newPictureNr);
1028 int16 _artificialDelayCurrentRoom;
1029 int16 _artificialDelayCurrentPicture;
1032 void redrawScreen();
1034 void inGameTimerReset(uint32 newPlayTime = 0);
1035 void inGameTimerResetPassedCycles();
1036 uint32 inGameTimerGet();
1037 uint32 inGameTimerGetPassedCycles();
1039 void inGameTimerUpdate();
1042 uint32 _lastUsedPlayTimeInCycles;
1043 uint32 _lastUsedPlayTimeInSeconds;
1044 uint32 _passedPlayTimeCycles;
1050 void setupOpCodes(uint16 version);
#define ARRAYSIZE(x)
Definition: util.h:91
bool pictureShown
Definition: agi.h:415
int adjMouseX
Definition: agi.h:392
EngineFeature
Definition: engine.h:250
ErrorCode getCode() const
Definition: error.h:115
bool playerControl
Definition: agi.h:413
RenderMode
Definition: rendermode.h:48
No error occurred.
Definition: error.h:48
Definition: systemui.h:51
AgiMonitorType
Definition: agi.h:271
int adjMouseY
Definition: agi.h:393
bool mouseEnabled
Definition: agi.h:453
Definition: graphics.h:58
int16 curLogicNr
Definition: agi.h:409
uint32 crc
Definition: agi.h:397
Definition: algorithm.h:29
bool automaticSave
Definition: agi.h:449
bool mouseHidden
Definition: agi.h:454
bool exitAllLogics
Definition: agi.h:414
Common::Error run() override
Definition: agi.h:687
AgiComputerType
Definition: agi.h:283
int16 horizon
Definition: agi.h:404
Common::Rect mouseFence
Definition: agi.h:452
Definition: detection.h:29
Language
Definition: language.h:45