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 #define TITLE "AGI engine" 68 #define LOGDIR "logdir" 69 #define PICDIR "picdir" 70 #define VIEWDIR "viewdir" 71 #define SNDDIR "snddir" 72 #define OBJECTS "object" 73 #define WORDS "words.tok" 75 #define MAX_DIRECTORY_ENTRIES 256 76 #define MAX_CONTROLLERS 256 78 #define MAX_FLAGS (256 >> 3) 79 #define SCREENOBJECTS_MAX 255 // KQ3 uses o255! 80 #define SCREENOBJECTS_EGO_ENTRY 0 // first entry is ego 82 #define MAX_STRINGS 24 // MAX_STRINGS + 1 used for get.num 83 #define MAX_STRINGLEN 40 84 #define MAX_CONTROLLER_KEYMAPPINGS 39 86 #define SAVEDGAME_DESCRIPTION_LEN 30 88 #define _EMPTY 0xfffff 89 #define EGO_OWNED 0xff 90 #define EGO_OWNED_V1 0xf9 92 #define CRYPT_KEY_SIERRA "Avis Durgan" 93 #define CRYPT_KEY_AGDS "Alex Simkin" 109 enum AgiGameFeatures {
110 GF_AGIMOUSE = (1 << 0),
112 GF_AGI256 = (1 << 2),
113 GF_FANMADE = (1 << 3),
114 GF_2GSOLDSOUND = (1 << 5),
115 GF_EXTCHAR = (1 << 6)
154 kDebugLevelMain = 1 << 0,
155 kDebugLevelResources = 1 << 1,
156 kDebugLevelSprites = 1 << 2,
157 kDebugLevelPictures = 1 << 3,
158 kDebugLevelInventory = 1 << 4,
159 kDebugLevelInput = 1 << 5,
160 kDebugLevelMenu = 1 << 6,
161 kDebugLevelScripts = 1 << 7,
162 kDebugLevelSound = 1 << 8,
163 kDebugLevelText = 1 << 9,
164 kDebugLevelSavegame = 1 << 10
171 RESOURCETYPE_LOGIC = 1,
179 RES_COMPRESSED = 0x40,
180 RES_PICTURE_V3_NIBBLE_PARM = 0x80
201 Mouse() : button(0) {}
205 enum AgiMouseButton {
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) {}
350 enum 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
383 uint8 flags[MAX_FLAGS];
384 uint8 vars[MAX_VARS];
389 bool cycleInnerLoopActive;
390 int16 cycleInnerLoopType;
406 unsigned int numObjects;
408 bool controllerOccurred[MAX_CONTROLLERS];
411 char strings[MAX_STRINGS + 1][MAX_STRINGLEN];
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);
467 void setSpeedLevel(byte s);
475 memset(
id, 0,
sizeof(
id));
477 memset(flags, 0,
sizeof(flags));
478 memset(vars, 0,
sizeof(vars));
482 cycleInnerLoopActive =
false;
483 cycleInnerLoopType = 0;
489 playerControl =
false;
490 exitAllLogics =
false;
491 pictureShown =
false;
499 memset(controllerOccurred, 0,
sizeof(controllerOccurred));
503 memset(strings, 0,
sizeof(strings));
513 memset(sounds, 0,
sizeof(sounds));
521 automaticSave =
false;
522 memset(automaticSaveDescription, 0,
sizeof(automaticSaveDescription));
525 mouseEnabled =
false;
527 predictiveDlgOnMouseClick =
false;
532 memset(logic_list, 0,
sizeof(logic_list));
534 nonBlockingTextShown =
false;
535 nonBlockingTextCyclesLeft = 0;
537 automaticRestoreGame =
false;
541 appleIIgsSpeedControllerSlot = 0xffff;
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);
632 void setFlagOrVar(int16 flagNr,
bool newState);
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;
669 enum 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;
731 SavedGameSlotIdArray getSavegameSlotIds();
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);
758 void clearImageStack()
override;
759 void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
760 int16 p4, int16 p5, int16 p6, int16 p7)
override;
761 void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
762 int16 p4, int16 p5, int16 p6, int16 p7)
override;
763 void releaseImageStack()
override;
765 void wait(uint32 msec,
bool busy =
false);
769 int loadResource(int16 resourceType, int16 resourceNr);
770 void unloadResource(int16 resourceType, int16 resourceNr);
774 void unloadResources();
776 int getKeypress()
override;
777 bool isKeypress()
override;
778 void clearKeyQueue()
override;
780 byte getVar(int16 varNr);
781 void setVar(int16 varNr, byte newValue);
784 void applyVolumeToMixer();
787 void syncSoundSettings()
override;
790 void decrypt(uint8 *mem,
int len);
791 uint16 processAGIEvents();
794 void newRoom(int16 newRoomNr);
795 void resetControllers();
796 void interpretCycle();
799 void allowSynthetic(
bool);
800 void processScummVMEvents();
801 void checkQuickLoad();
803 const Common::String getTargetName()
const {
return _targetName; }
810 int loadObjects(
const char *fname);
812 const char *objectName(uint16 objectNr);
813 int objectGetLocation(uint16 objectNr);
814 void objectSetLocation(uint16 objectNr,
int location);
816 int decodeObjects(uint8 *mem, uint32 flen);
820 int decodeLogic(int16 logicNr);
821 void unloadLogic(int16 logicNr);
822 int runLogic(int16 logicNr);
823 void debugConsole(
int lognum,
int mode,
const char *str);
824 bool testIfCode(int16 logicNr);
825 void executeAgiCommand(uint8 op, uint8 *p);
828 bool _veryFirstInitialCycle;
829 uint32 _instructionCounter;
831 bool _setVolumeBrokenFangame;
833 void resetGetVarSecondsHeuristic();
834 void getVarSecondsHeuristicTrigger();
835 uint32 _getVarSecondsHeuristicLastInstructionCounter;
836 uint16 _getVarSecondsHeuristicCounter;
838 uint32 _playTimeInSecondsAdjust;
840 void setVarSecondsTrigger(byte newSeconds);
844 void skipInstruction(byte op);
845 void skipInstructionsUntil(byte v);
846 bool testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
847 bool testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
848 bool testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
849 bool testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
850 bool testSaid(uint8 nwords, uint8 *cc);
851 bool testController(uint8 cont);
852 bool testCompareStrings(uint8 s1, uint8 s2);
856 void unloadPicture(int16 picNr);
871 void updateScreenObjTable();
872 void unloadView(int16 viewNr);
873 int decodeView(byte *resourceData, uint16 resourceSize, int16 viewNr);
876 void unpackViewCelData(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize, int16 viewNr);
877 void unpackViewCelDataAGI256(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize, int16 viewNr);
884 int checkStep(
int delta,
int step);
885 bool checkBlock(int16 x, int16 y);
896 void checkAllMotions();
899 void fixPosition(int16 screenObjNr);
901 void updatePosition();
902 int getDirection(int16 objX, int16 objY, int16 destX, int16 destY, int16 stepSize);
903 byte egoNearWater(byte limit);
904 int16 nearWater(
ScreenObjEntry &screenObj, byte direction, int16 x, int16 y, byte limit);
907 Common::KeyCode _keyHoldModeLastKey;
910 int doPollKeyboard();
912 bool handleMouseClicks(uint16 &key);
913 bool handleController(uint16 key);
915 bool showPredictiveDialog();
919 void waitAnyKeyOrFinishedSound();
921 void nonBlockingText_IsShown();
922 void nonBlockingText_Forget();
924 void artificialDelay_Reset();
925 void artificialDelay_CycleDone();
927 uint16 artificialDelay_SearchTable(AgiArtificialDelayTriggerType triggerType, int16 orgNr, int16 newNr);
929 void artificialDelayTrigger_NewRoom(int16 newRoomNr);
930 void artificialDelayTrigger_DrawPicture(int16 newPictureNr);
933 int16 _artificialDelayCurrentRoom;
934 int16 _artificialDelayCurrentPicture;
939 void inGameTimerReset(uint32 newPlayTime = 0);
940 void inGameTimerResetPassedCycles();
941 uint32 inGameTimerGet();
942 uint32 inGameTimerGetPassedCycles();
944 void inGameTimerUpdate();
947 uint32 _lastUsedPlayTimeInCycles;
948 uint32 _lastUsedPlayTimeInSeconds;
949 uint32 _passedPlayTimeCycles;
955 void setupOpCodes(uint16 version);
961 void goldRushClockTimeWorkaround_OnReadVar();
962 void goldRushClockTimeWorkaround_OnWriteVar(byte oldValue);
bool pictureShown
Definition: agi.h:398
int adjMouseX
Definition: agi.h:376
EngineFeature
Definition: engine.h:253
ErrorCode getCode() const
Definition: error.h:115
bool playerControl
Definition: agi.h:396
RenderMode
Definition: rendermode.h:48
No error occurred.
Definition: error.h:48
bool predictiveDlgOnMouseClick
Definition: agi.h:438
Definition: systemui.h:51
AgiMonitorType
Definition: agi.h:252
int adjMouseY
Definition: agi.h:377
byte speedLevel
Definition: agi.h:458
bool mouseEnabled
Definition: agi.h:436
Definition: graphics.h:58
int16 curLogicNr
Definition: agi.h:392
uint32 crc
Definition: agi.h:380
Definition: algorithm.h:29
bool automaticSave
Definition: agi.h:432
bool mouseHidden
Definition: agi.h:437
bool exitAllLogics
Definition: agi.h:397
Common::Error run() override
Definition: agi.h:578
AgiComputerType
Definition: agi.h:264
Definition: appleIIgs_timedelay_overwrite.h:36
int16 horizon
Definition: agi.h:387
Common::Rect mouseFence
Definition: agi.h:435
Definition: detection.h:29
Language
Definition: language.h:45