diff options
author | Walter van Niftrik | 2016-03-20 07:56:53 +0100 |
---|---|---|
committer | Walter van Niftrik | 2016-06-06 20:35:49 +0200 |
commit | a7a371c63d1570714c7b5cb766f6acc3fd26f5fc (patch) | |
tree | d6186ca34ee6c5c85665e86523f7b0dd26a51d22 /engines | |
parent | e7c93489e4f6055c988d048c9c479de3eff94ece (diff) | |
download | scummvm-rg350-a7a371c63d1570714c7b5cb766f6acc3fd26f5fc.tar.gz scummvm-rg350-a7a371c63d1570714c7b5cb766f6acc3fd26f5fc.tar.bz2 scummvm-rg350-a7a371c63d1570714c7b5cb766f6acc3fd26f5fc.zip |
ADL: Implement time opcode
Diffstat (limited to 'engines')
-rw-r--r-- | engines/adl/adl.cpp | 1 | ||||
-rw-r--r-- | engines/adl/adl.h | 8 | ||||
-rw-r--r-- | engines/adl/adl_v2.cpp | 93 | ||||
-rw-r--r-- | engines/adl/adl_v2.h | 14 | ||||
-rw-r--r-- | engines/adl/hires2.cpp | 61 | ||||
-rw-r--r-- | engines/adl/hires2.h | 6 |
6 files changed, 117 insertions, 66 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index 715d7a8087..e2025b9b3d 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -552,6 +552,7 @@ Common::Error AdlEngine::run() { } doAllCommands(_globalCommands, verb, noun); + advanceClock(); _state.moves++; } diff --git a/engines/adl/adl.h b/engines/adl/adl.h index 595386cb29..5aba30eeab 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -136,6 +136,12 @@ struct Item { Common::Array<byte> roomPictures; }; +struct Time { + byte hours, minutes; + + Time() : hours(12), minutes(0) { } +}; + struct State { Common::Array<Room> rooms; Common::Array<Item> items; @@ -144,6 +150,7 @@ struct State { byte room; uint16 moves; bool isDark; + Time time; State() : room(1), moves(1), isDark(false) { } }; @@ -177,6 +184,7 @@ protected: virtual void setupOpcodeTables(); virtual bool matchesCurrentPic(byte pic) const; virtual byte roomArg(byte room) const; + virtual void advanceClock() { } // Opcodes int o1_isItemInRoom(ScriptEnv &e); diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp index 1a07d0e9ab..e5e02d20fd 100644 --- a/engines/adl/adl_v2.cpp +++ b/engines/adl/adl_v2.cpp @@ -23,6 +23,7 @@ #include "common/random.h" #include "adl/adl_v2.h" +#include "adl/display.h" namespace Adl { @@ -31,7 +32,8 @@ AdlEngine_v2::~AdlEngine_v2() { } AdlEngine_v2::AdlEngine_v2(OSystem *syst, const AdlGameDescription *gd) : - AdlEngine(syst, gd) { + AdlEngine(syst, gd), + _linesPrinted(0) { _random = new Common::RandomSource("adl"); } @@ -98,6 +100,7 @@ void AdlEngine_v2::setupOpcodeTables() { // 0x1c Opcode(o1_dropItem); Opcode(o1_setRoomPic); + Opcode(o2_tellTime); } bool AdlEngine_v2::matchesCurrentPic(byte pic) const { @@ -110,6 +113,81 @@ byte AdlEngine_v2::roomArg(byte room) const { return room; } +void AdlEngine_v2::advanceClock() { + Time &time = _state.time; + + time.minutes += 5; + + if (time.minutes == 60) { + time.minutes = 0; + + ++time.hours; + + if (time.hours == 13) + time.hours = 1; + } +} + +void AdlEngine_v2::checkTextOverflow(char c) { + if (c != APPLECHAR('\r')) + return; + + ++_linesPrinted; + + if (_linesPrinted < 4) + return; + + _linesPrinted = 0; + _display->updateTextScreen(); + bell(); + + while (true) { + char key = inputKey(false); + + if (shouldQuit()) + return; + + if (key == APPLECHAR('\r')) + break; + + bell(3); + } +} + +void AdlEngine_v2::printString(const Common::String &str) { + Common::String s(str); + byte endPos = TEXT_WIDTH - 1; + byte pos = 0; + + while (true) { + while (pos != endPos && pos != s.size()) { + s.setChar(APPLECHAR(s[pos]), pos); + ++pos; + } + + if (pos == s.size()) + break; + + while (s[pos] != APPLECHAR(' ') && s[pos] != APPLECHAR('\r')) + --pos; + + s.setChar(APPLECHAR('\r'), pos); + endPos = pos + TEXT_WIDTH; + ++pos; + } + + pos = 0; + while (pos != s.size()) { + checkTextOverflow(s[pos]); + _display->printChar(s[pos]); + ++pos; + } + + checkTextOverflow(APPLECHAR('\r')); + _display->printChar(APPLECHAR('\r')); + _display->updateTextScreen(); +} + int AdlEngine_v2::o2_isFirstTime(ScriptEnv &e) { bool oldFlag = getCurRoom().isFirstTime; @@ -189,4 +267,17 @@ int AdlEngine_v2::o2_placeItem(ScriptEnv &e) { return 4; } +int AdlEngine_v2::o2_tellTime(ScriptEnv &e) { + Common::String time = _strings_v2.time; + + time.setChar(APPLECHAR('0') + _state.time.hours / 10, 12); + time.setChar(APPLECHAR('0') + _state.time.hours % 10, 13); + time.setChar(APPLECHAR('0') + _state.time.minutes / 10, 15); + time.setChar(APPLECHAR('0') + _state.time.minutes % 10, 16); + + printString(time); + + return 0; +} + } // End of namespace Adl diff --git a/engines/adl/adl_v2.h b/engines/adl/adl_v2.h index e21c43c107..d4847193d0 100644 --- a/engines/adl/adl_v2.h +++ b/engines/adl/adl_v2.h @@ -44,18 +44,30 @@ public: protected: AdlEngine_v2(OSystem *syst, const AdlGameDescription *gd); + // AdlEngine virtual void setupOpcodeTables(); bool matchesCurrentPic(byte pic) const; byte roomArg(byte room) const; + void advanceClock(); + + void checkTextOverflow(char c); + void printString(const Common::String &str); int o2_isFirstTime(ScriptEnv &e); int o2_isRandomGT(ScriptEnv &e); int o2_isNounNotInRoom(ScriptEnv &e); int o2_isCarryingSomething(ScriptEnv &e); + + int o2_moveItem(ScriptEnv &e); int o2_moveAllItems(ScriptEnv &e); int o2_placeItem(ScriptEnv &e); + int o2_tellTime(ScriptEnv &e); - int o2_moveItem(ScriptEnv &e); + struct { + Common::String time; + } _strings_v2; + + uint _linesPrinted; private: Common::RandomSource *_random; diff --git a/engines/adl/hires2.cpp b/engines/adl/hires2.cpp index 6f517dacdb..49e70a1631 100644 --- a/engines/adl/hires2.cpp +++ b/engines/adl/hires2.cpp @@ -84,6 +84,7 @@ void HiRes2Engine::init() { _strings.nounError = readStringAt(f, IDI_HR2_OFS_STR_NOUN_ERROR); _strings.playAgain = readStringAt(f, IDI_HR2_OFS_STR_PLAY_AGAIN); _strings.pressReturn = readStringAt(f, IDI_HR2_OFS_STR_PRESS_RETURN); + _strings_v2.time = readStringAt(f, IDI_HR2_OFS_STR_TIME, 0xff); _messageIds.cantGoThere = IDI_HR2_MSG_CANT_GO_THERE; _messageIds.dontUnderstand = IDI_HR2_MSG_DONT_UNDERSTAND; @@ -248,66 +249,6 @@ void HiRes2Engine::checkInput(byte verb, byte noun) { AdlEngine::checkInput(verb, noun); } -void HiRes2Engine::checkTextOverflow(char c) { - if (c != APPLECHAR('\r')) - return; - - ++_linesPrinted; - - if (_linesPrinted < 4) - return; - - _linesPrinted = 0; - _display->updateTextScreen(); - bell(); - - while (true) { - char key = inputKey(false); - - if (shouldQuit()) - return; - - if (key == APPLECHAR('\r')) - break; - - bell(3); - } -} - -void HiRes2Engine::printString(const Common::String &str) { - Common::String s(str); - byte endPos = TEXT_WIDTH - 1; - byte pos = 0; - - while (true) { - while (pos != endPos && pos != s.size()) { - s.setChar(APPLECHAR(s[pos]), pos); - ++pos; - } - - if (pos == s.size()) - break; - - while (s[pos] != APPLECHAR(' ') && s[pos] != APPLECHAR('\r')) - --pos; - - s.setChar(APPLECHAR('\r'), pos); - endPos = pos + TEXT_WIDTH; - ++pos; - } - - pos = 0; - while (pos != s.size()) { - checkTextOverflow(s[pos]); - _display->printChar(s[pos]); - ++pos; - } - - checkTextOverflow(APPLECHAR('\r')); - _display->printChar(APPLECHAR('\r')); - _display->updateTextScreen(); -} - Engine *HiRes2Engine_create(OSystem *syst, const AdlGameDescription *gd) { return new HiRes2Engine(syst, gd); } diff --git a/engines/adl/hires2.h b/engines/adl/hires2.h index 8ed51b80c8..121a1f6739 100644 --- a/engines/adl/hires2.h +++ b/engines/adl/hires2.h @@ -71,6 +71,7 @@ namespace Adl { #define IDI_HR2_OFS_STR_NOUN_ERROR TSO(0x1a, 0x1, 0x8e) #define IDI_HR2_OFS_STR_PLAY_AGAIN TSO(0x1a, 0x8, 0x25) #define IDI_HR2_OFS_STR_PRESS_RETURN TSO(0x1a, 0x8, 0x5f) +#define IDI_HR2_OFS_STR_TIME TSO(0x19, 0x7, 0xd7) struct Picture2 { byte nr; @@ -87,7 +88,7 @@ struct RoomData { class HiRes2Engine : public AdlEngine_v2 { public: - HiRes2Engine(OSystem *syst, const AdlGameDescription *gd) : AdlEngine_v2(syst, gd), _linesPrinted(0) { } + HiRes2Engine(OSystem *syst, const AdlGameDescription *gd) : AdlEngine_v2(syst, gd) { } private: // AdlEngine @@ -102,12 +103,9 @@ private: void checkInput(byte verb, byte noun); void loadRoom(byte roomNr); - void checkTextOverflow(char c); - void printString(const Common::String &str); RoomData _roomData; Common::Array<Picture2> _itemPics; - uint _linesPrinted; }; } // End of namespace Adl |