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" 45 #include "agi/logic.h" 46 #include "agi/sound.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 // KQ3 uses o255! 81 #define SCREENOBJECTS_EGO_ENTRY 0 // first entry is ego 83 #define MAX_STRINGS 24 // MAX_STRINGS + 1 used for get.num 84 #define MAX_STRINGLEN 40 85 #define MAX_CONTROLLER_KEYMAPPINGS 39 87 #define SAVEDGAME_DESCRIPTION_LEN 30 89 #define _EMPTY 0xfffff 90 #define EGO_OWNED 0xff 91 #define EGO_OWNED_V1 0xf9 93 #define CRYPT_KEY_SIERRA "Avis Durgan" 94 #define CRYPT_KEY_AGDS "Alex Simkin" 110 enum AgiGameFeatures {
111 GF_AGIMOUSE = (1 << 0),
113 GF_AGI256 = (1 << 2),
114 GF_FANMADE = (1 << 3),
115 GF_2GSOLDSOUND = (1 << 5),
116 GF_EXTCHAR = (1 << 6)
156 kDebugLevelResources,
159 kDebugLevelInventory,
172 RESOURCETYPE_LOGIC = 1,
180 RES_COMPRESSED = 0x40,
181 RES_PICTURE_V3_NIBBLE_PARM = 0x80
202 Mouse() : button(0) {}
206 enum AgiMouseButton {
209 kAgiMouseButtonRight,
210 kAgiMouseButtonMiddle
217 VM_VAR_CURRENT_ROOM = 0,
218 VM_VAR_PREVIOUS_ROOM,
219 VM_VAR_BORDER_TOUCH_EGO,
222 VM_VAR_BORDER_TOUCH_OBJECT,
223 VM_VAR_EGO_DIRECTION,
226 VM_VAR_WORD_NOT_FOUND,
232 VM_VAR_JOYSTICK_SENSITIVITY,
233 VM_VAR_EGO_VIEW_RESOURCE,
234 VM_VAR_AGI_ERROR_CODE,
235 VM_VAR_AGI_ERROR_INFO,
238 VM_VAR_WINDOW_AUTO_CLOSE_TIMER,
239 VM_VAR_SOUNDGENERATOR,
241 VM_VAR_MAX_INPUT_CHARACTERS,
242 VM_VAR_SELECTED_INVENTORY_ITEM,
244 VM_VAR_MOUSE_BUTTONSTATE = 27,
256 kAgiMonitorHercules = 2,
267 kAgiComputerApple2 = 3,
268 kAgiComputerAtariST = 4,
269 kAgiComputerAmiga = 5,
270 kAgiComputerApple2GS = 7
283 VM_FLAG_EGO_WATER = 0,
284 VM_FLAG_EGO_INVISIBLE,
286 VM_FLAG_EGO_TOUCHED_P2,
287 VM_FLAG_SAID_ACCEPTED_INPUT,
288 VM_FLAG_NEW_ROOM_EXEC,
289 VM_FLAG_RESTART_GAME,
290 VM_FLAG_SCRIPT_BLOCKED,
291 VM_FLAG_JOY_SENSITIVITY,
294 VM_FLAG_LOGIC_ZERO_FIRST_TIME,
295 VM_FLAG_RESTORE_JUST_RAN,
296 VM_FLAG_STATUS_SELECTS_ITEMS,
297 VM_FLAG_MENUS_ACCESSIBLE,
343 AgiBlock() : active(
false), x1(0), y1(0), x2(0), y2(0) {}
351 enum CycleInnerLoopType {
352 CYCLE_INNERLOOP_GETSTRING = 0,
353 CYCLE_INNERLOOP_GETNUMBER,
354 CYCLE_INNERLOOP_INVENTORY,
355 CYCLE_INNERLOOP_MENU_VIA_KEYBOARD,
356 CYCLE_INNERLOOP_MENU_VIA_MOUSE,
357 CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT,
358 CYCLE_INNERLOOP_SYSTEMUI_VERIFICATION,
359 CYCLE_INNERLOOP_MESSAGEBOX,
360 CYCLE_INNERLOOP_HAVEKEY
384 uint8 flags[MAX_FLAGS];
385 uint8 vars[MAX_VARS];
390 bool cycleInnerLoopActive;
391 int16 cycleInnerLoopType;
407 unsigned int numObjects;
409 bool controllerOccurred[MAX_CONTROLLERS];
412 char strings[MAX_STRINGS + 1][MAX_STRINGLEN];
415 AgiDir dirLogic[MAX_DIRECTORY_ENTRIES];
416 AgiDir dirPic[MAX_DIRECTORY_ENTRIES];
417 AgiDir dirView[MAX_DIRECTORY_ENTRIES];
418 AgiDir dirSound[MAX_DIRECTORY_ENTRIES];
434 char automaticSaveDescription[SAVEDGAME_DESCRIPTION_LEN + 1];
454 bool nonBlockingTextShown;
455 int16 nonBlockingTextCyclesLeft;
457 bool automaticRestoreGame;
461 uint16 appleIIgsSpeedControllerSlot;
463 const char *getString(
int number);
464 void setString(
int number,
const char *str);
468 void setSpeedLevel(byte s);
476 memset(
id, 0,
sizeof(
id));
478 memset(flags, 0,
sizeof(flags));
479 memset(vars, 0,
sizeof(vars));
483 cycleInnerLoopActive =
false;
484 cycleInnerLoopType = 0;
490 playerControl =
false;
491 exitAllLogics =
false;
492 pictureShown =
false;
500 memset(controllerOccurred, 0,
sizeof(controllerOccurred));
504 memset(strings, 0,
sizeof(strings));
514 memset(sounds, 0,
sizeof(sounds));
522 automaticSave =
false;
523 memset(automaticSaveDescription, 0,
sizeof(automaticSaveDescription));
526 mouseEnabled =
false;
528 predictiveDlgOnMouseClick =
false;
533 memset(logic_list, 0,
sizeof(logic_list));
535 nonBlockingTextShown =
false;
536 nonBlockingTextCyclesLeft = 0;
538 automaticRestoreGame =
false;
542 appleIIgsSpeedControllerSlot = 0xffff;
570 #define TICK_SECONDS 20 572 #define KEY_QUEUE_SIZE 16 588 virtual void initialize() = 0;
590 void initRenderMode();
607 bool _noSaveLoadAllowed;
609 virtual bool promptIsEnabled() {
613 virtual int getKeypress() = 0;
614 virtual bool isKeypress() = 0;
615 virtual void clearKeyQueue() = 0;
620 virtual void clearImageStack() = 0;
621 virtual void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
622 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
623 virtual void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
624 int16 p4, int16 p5, int16 p6, int16 p7) = 0;
625 virtual void releaseImageStack() = 0;
629 bool getFlag(int16 flagNr);
630 void setFlag(int16 flagNr,
bool newState);
631 void flipFlag(int16 flagNr);
633 void setFlagOrVar(int16 flagNr,
bool newState);
637 uint32 _gameFeatures;
640 uint32 getGameID()
const;
641 uint32 getFeatures()
const;
642 uint16 getVersion()
const;
643 uint16 getGameType()
const;
645 bool isLanguageRTL()
const;
647 const char *getGameMD5()
const;
651 const char *getDiskName(uint16
id);
656 const byte *getFontData();
658 void cycleInnerLoopActive(int16 loopType) {
659 _game.cycleInnerLoopActive =
true;
660 _game.cycleInnerLoopType = loopType;
662 void cycleInnerLoopInactive() {
663 _game.cycleInnerLoopActive =
false;
665 bool cycleInnerLoopIsActive() {
666 return _game.cycleInnerLoopActive;
670 enum AgiArtificialDelayTriggerType {
671 ARTIFICIALDELAYTYPE_NEWROOM = 0,
672 ARTIFICIALDELAYTYPE_NEWPICTURE = 1,
673 ARTIFICIALDELAYTYPE_END = -1
679 AgiArtificialDelayTriggerType triggerType;
682 uint16 millisecondsDelay;
689 const char *parameters;
690 AgiOpCodeFunction functionPtr;
691 uint16 parameterSize;
696 const char *parameters;
697 AgiOpCodeFunction functionPtr;
705 void initialize()
override;
711 bool promptIsEnabled()
override;
717 int _keyQueue[KEY_QUEUE_SIZE];
721 bool _allowSynthetic;
732 SavedGameSlotIdArray getSavegameSlotIds();
733 bool getSavegameInformation(int16 slotId,
Common::String &saveDescription, uint32 &saveDate, uint32 &saveTime,
bool &saveIsValid);
736 int loadGame(
const Common::String &fileName,
bool checkId =
true);
737 bool saveGameDialog();
738 bool saveGameAutomatic();
739 bool loadGameDialog();
740 bool loadGameAutomatic();
742 int doLoad(
int slot,
bool showMessages);
743 int scummVMSaveLoadDialog(
bool isSave);
760 int16 _previousDisplayRow;
765 bool _replaceDisplayNewlines;
766 Common::CodePage _ttsEncoding;
769 void clearImageStack()
override;
770 void recordImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
771 int16 p4, int16 p5, int16 p6, int16 p7)
override;
772 void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
773 int16 p4, int16 p5, int16 p6, int16 p7)
override;
774 void releaseImageStack()
override;
776 void wait(uint32 msec,
bool busy =
false);
780 int loadResource(int16 resourceType, int16 resourceNr);
781 void unloadResource(int16 resourceType, int16 resourceNr);
785 void unloadResources();
787 int getKeypress()
override;
788 bool isKeypress()
override;
789 void clearKeyQueue()
override;
791 byte getVar(int16 varNr);
792 void setVar(int16 varNr, byte newValue);
795 void applyVolumeToMixer();
798 void syncSoundSettings()
override;
801 void sayText(
const Common::String &text, Common::TextToSpeechManager::Action action = Common::TextToSpeechManager::QUEUE,
802 bool checkPreviousSaid =
true);
803 void stopTextToSpeech(
bool clearPreviousSaid =
true);
807 void decrypt(uint8 *mem,
int len);
808 uint16 processAGIEvents();
811 void newRoom(int16 newRoomNr);
812 void resetControllers();
813 void interpretCycle();
816 void allowSynthetic(
bool);
817 void processScummVMEvents();
818 void checkQuickLoad();
820 const Common::String getTargetName()
const {
return _targetName; }
827 int loadObjects(
const char *fname);
829 const char *objectName(uint16 objectNr);
830 int objectGetLocation(uint16 objectNr);
831 void objectSetLocation(uint16 objectNr,
int location);
833 int decodeObjects(uint8 *mem, uint32 flen);
837 int decodeLogic(int16 logicNr);
838 void unloadLogic(int16 logicNr);
839 int runLogic(int16 logicNr);
840 void debugConsole(
int lognum,
int mode,
const char *str);
841 bool testIfCode(int16 logicNr);
842 void executeAgiCommand(uint8 op, uint8 *p);
845 bool _veryFirstInitialCycle;
846 uint32 _instructionCounter;
848 bool _setVolumeBrokenFangame;
850 void resetGetVarSecondsHeuristic();
851 void getVarSecondsHeuristicTrigger();
852 uint32 _getVarSecondsHeuristicLastInstructionCounter;
853 uint16 _getVarSecondsHeuristicCounter;
855 uint32 _playTimeInSecondsAdjust;
857 void setVarSecondsTrigger(byte newSeconds);
861 void skipInstruction(byte op);
862 void skipInstructionsUntil(byte v);
863 bool testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
864 bool testObjCenter(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
865 bool testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
866 bool testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2);
867 bool testSaid(uint8 nwords, uint8 *cc);
868 bool testController(uint8 cont);
869 bool testCompareStrings(uint8 s1, uint8 s2);
873 void unloadPicture(int16 picNr);
888 void updateScreenObjTable();
889 void unloadView(int16 viewNr);
890 int decodeView(byte *resourceData, uint16 resourceSize, int16 viewNr);
893 void unpackViewCelData(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize, int16 viewNr);
894 void unpackViewCelDataAGI256(
AgiViewCel *celData, byte *compressedData, uint16 compressedSize, int16 viewNr);
901 int checkStep(
int delta,
int step);
902 bool checkBlock(int16 x, int16 y);
913 void checkAllMotions();
916 void fixPosition(int16 screenObjNr);
918 void updatePosition();
919 int getDirection(int16 objX, int16 objY, int16 destX, int16 destY, int16 stepSize);
920 byte egoNearWater(byte limit);
921 int16 nearWater(
ScreenObjEntry &screenObj, byte direction, int16 x, int16 y, byte limit);
924 Common::KeyCode _keyHoldModeLastKey;
927 int doPollKeyboard();
929 bool handleMouseClicks(uint16 &key);
930 bool handleController(uint16 key);
932 bool showPredictiveDialog();
936 void waitAnyKeyOrFinishedSound();
938 void nonBlockingText_IsShown();
939 void nonBlockingText_Forget();
941 void artificialDelay_Reset();
942 void artificialDelay_CycleDone();
944 uint16 artificialDelay_SearchTable(AgiArtificialDelayTriggerType triggerType, int16 orgNr, int16 newNr);
946 void artificialDelayTrigger_NewRoom(int16 newRoomNr);
947 void artificialDelayTrigger_DrawPicture(int16 newPictureNr);
950 int16 _artificialDelayCurrentRoom;
951 int16 _artificialDelayCurrentPicture;
956 void inGameTimerReset(uint32 newPlayTime = 0);
957 void inGameTimerResetPassedCycles();
958 uint32 inGameTimerGet();
959 uint32 inGameTimerGetPassedCycles();
961 void inGameTimerUpdate();
964 uint32 _lastUsedPlayTimeInCycles;
965 uint32 _lastUsedPlayTimeInSeconds;
966 uint32 _passedPlayTimeCycles;
972 void setupOpCodes(uint16 version);
978 void goldRushClockTimeWorkaround_OnReadVar();
979 void goldRushClockTimeWorkaround_OnWriteVar(byte oldValue);
bool pictureShown
Definition: agi.h:399
int adjMouseX
Definition: agi.h:377
EngineFeature
Definition: engine.h:260
ErrorCode getCode() const
Definition: error.h:112
bool playerControl
Definition: agi.h:397
RenderMode
Definition: rendermode.h:48
No error occurred.
Definition: error.h:48
bool predictiveDlgOnMouseClick
Definition: agi.h:439
Definition: systemui.h:51
AgiMonitorType
Definition: agi.h:253
int adjMouseY
Definition: agi.h:378
byte speedLevel
Definition: agi.h:459
bool mouseEnabled
Definition: agi.h:437
Definition: graphics.h:58
int16 curLogicNr
Definition: agi.h:393
uint32 crc
Definition: agi.h:381
Definition: algorithm.h:29
bool automaticSave
Definition: agi.h:433
bool mouseHidden
Definition: agi.h:438
bool exitAllLogics
Definition: agi.h:398
Common::Error run() override
Definition: agi.h:579
AgiComputerType
Definition: agi.h:265
Definition: appleIIgs_timedelay_overwrite.h:36
int16 horizon
Definition: agi.h:388
Common::Rect mouseFence
Definition: agi.h:436
Definition: detection.h:29
Language
Definition: language.h:45