From cc16e42f2029955e066450d63bfb666b9ab47109 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 24 Feb 2014 20:05:35 -0500 Subject: MADS: Beginnings of scene-specific data loading --- engines/mads/game.cpp | 4 +- engines/mads/game.h | 6 +-- engines/mads/mads.cpp | 2 +- engines/mads/mads.h | 2 +- engines/mads/resources.cpp | 54 +++++++++++++++----- engines/mads/resources.h | 12 ++++- engines/mads/scene.cpp | 113 +++++++++++++++++++++++++++++++++++++++++- engines/mads/scene.h | 119 ++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 289 insertions(+), 23 deletions(-) diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 4e0be59122..bff0e6e73e 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -132,7 +132,7 @@ void Game::sectionLoop() { _quotes = nullptr; _scene.clearVocab(); - _scene.loadScene(); + _scene.loadSceneLogic(); _v4 = 0; _player._stepEnabled = true; @@ -219,7 +219,7 @@ void Game::addVisitedScene(int sceneId) { } bool Game::visitedScenesExists(int sceneId) { - for (int i = 0; i < _visitedScenes.size(); ++i) { + for (uint i = 0; i < _visitedScenes.size(); ++i) { if (_visitedScenes[i] == sceneId) return true; } diff --git a/engines/mads/game.h b/engines/mads/game.h index e2b8deede5..4735615d7a 100644 --- a/engines/mads/game.h +++ b/engines/mads/game.h @@ -109,9 +109,6 @@ protected: MADSEngine *_vm; MSurface *_surface; Difficulty _difficultyLevel; - Common::Array _globalFlags; - Common::Array _objects; - Common::Array _inventoryList; Player _player; Scene _scene; int _saveSlot; @@ -177,6 +174,9 @@ public: public: int _sectionNumber; int _priorSectionNumber; + Common::Array _globalFlags; + Common::Array _objects; + Common::Array _inventoryList; public: virtual ~Game(); diff --git a/engines/mads/mads.cpp b/engines/mads/mads.cpp index db73ec7d23..f7fe03e2be 100644 --- a/engines/mads/mads.cpp +++ b/engines/mads/mads.cpp @@ -77,7 +77,7 @@ void MADSEngine::initialise() { MSurface::setVm(this); MSprite::setVm(this); - ResourcesManager::init(this); + Resources::init(this); _debugger = new Debugger(this); _dialogs = Dialogs::init(this); _events = new EventsManager(this); diff --git a/engines/mads/mads.h b/engines/mads/mads.h index b3a05dc56c..44630ca135 100644 --- a/engines/mads/mads.h +++ b/engines/mads/mads.h @@ -94,7 +94,7 @@ public: Font *_font; Game *_game; Palette *_palette; - ResourcesManager *_resources; + Resources *_resources; MSurface *_screen; SoundManager *_sound; UserInterface *_userInterface; diff --git a/engines/mads/resources.cpp b/engines/mads/resources.cpp index fe021fcfd8..9f856eeefc 100644 --- a/engines/mads/resources.cpp +++ b/engines/mads/resources.cpp @@ -88,19 +88,6 @@ public: virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; }; -void ResourcesManager::init(MADSEngine *vm) { - SearchMan.add("HAG", new HagArchive()); -} - -/*------------------------------------------------------------------------*/ - -void File::openFile(const Common::String &filename) { - if (!Common::File::open(filename)) - error("Could not open file - %s", filename.c_str()); -} - -/*------------------------------------------------------------------------*/ - const char *const MADSCONCAT_STRING = "MADSCONCAT"; HagArchive::HagArchive() { @@ -282,4 +269,45 @@ ResourceType HagArchive::getResourceType(const Common::String &resourceName) con return RESTYPE_NO_EXT; } +/*------------------------------------------------------------------------*/ + +void Resources::init(MADSEngine *vm) { + SearchMan.add("HAG", new HagArchive()); +} + +Common::String Resources::formatName(RESPREFIX resType, int id, const Common::String &ext) { + Common::String result = "*"; + + if (resType == 3 && !id) { + id = id / 100; + } + + if (!ext.empty()) { + switch (resType) { + case RESPREFIX_GL: + result += "GL000"; + break; + case RESPREFIX_SC: + result += Common::String::format("SC%.3d", id); + break; + case RESPREFIX_RM: + result += Common::String::format("RM%.3d", id); + break; + default: + break; + } + + result += ext; + } + + return result; +} + +/*------------------------------------------------------------------------*/ + +void File::openFile(const Common::String &filename) { + if (!Common::File::open(filename)) + error("Could not open file - %s", filename.c_str()); +} + } // End of namespace MADS diff --git a/engines/mads/resources.h b/engines/mads/resources.h index f4b7009e13..033157ed60 100644 --- a/engines/mads/resources.h +++ b/engines/mads/resources.h @@ -31,12 +31,22 @@ namespace MADS { class MADSEngine; -class ResourcesManager { +enum RESPREFIX { + RESPREFIX_GL = 1, RESPREFIX_SC = 2, RESPREFIX_RM = 3 +}; + +enum EXTTYPE { + EXT_SS = 1, EXT_AA = 2, EXT_DAT = 3, EXT_HH = 4, EXT_ART = 5, EXT_INT = 6 +}; + +class Resources { public: /** * Instantiates the resource manager */ static void init(MADSEngine *vm); + + static Common::String formatName(RESPREFIX resType, int id, const Common::String &ext); }; /** diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index 406c3cc616..19071d1352 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -36,6 +36,17 @@ Scene::Scene(MADSEngine *vm): _vm(vm) { _currentSceneId = 0; _vocabBuffer = nullptr; _sceneLogic = nullptr; + + _verbList.push_back(VerbInit(VERB_LOOK, 2, 0)); + _verbList.push_back(VerbInit(VERB_TAKE, 2, 0)); + _verbList.push_back(VerbInit(VERB_PUSH, 2, 0)); + _verbList.push_back(VerbInit(VERB_OPEN, 2, 0)); + _verbList.push_back(VerbInit(VERB_PUT, 1, -1)); + _verbList.push_back(VerbInit(VERB_TALKTO, 2, 0)); + _verbList.push_back(VerbInit(VERB_GIVE, 1, 2)); + _verbList.push_back(VerbInit(VERB_PULL, 2, 0)); + _verbList.push_back(VerbInit(VERB_CLOSE, 2, 0)); + _verbList.push_back(VerbInit(VERB_THROW, 1, 2)); } Scene::~Scene() { @@ -104,7 +115,17 @@ int Scene::activeVocabIndexOf(int vocabId) { return -1; } -void Scene::loadScene() { +void Scene::clearSequenceList() { + _sequenceList.clear(); +} + +void Scene::clearMessageList() { + _messageList.clear(); + _talkFont = "*FONTCONV.FF"; + _textSpacing = -1; +} + +void Scene::loadSceneLogic() { delete _sceneLogic; switch (_vm->getGameID()) { @@ -116,6 +137,31 @@ void Scene::loadScene() { } } +void Scene::loadHotspots() { + File f(Resources::formatName(RESPREFIX_RM, _currentSceneId, ".HH")); + int count = f.readUint16LE(); + + _hotspotList.clear(); + for (int i = 0; i < count; ++i) + _hotspotList.push_back(Hotspot(f)); +} + +void Scene::loadVocab() { + // Add all the verbs to the active vocab list + for (uint i = 0; i < _verbList.size(); ++i) + addActiveVocab(_verbList[i]._id); + + // Load the vocabs for any object descriptions and custom actions + for (uint objIndex = 0; objIndex < _vm->_game->_objects.size(); ++objIndex) { + InventoryObject &io = _vm->_game->_objects[objIndex]; + addActiveVocab(io._descId); + + if (io._vocabCount > 0) { + // TODO + } + } +} + void Scene::free() { warning("TODO: Scene::free"); } @@ -160,4 +206,69 @@ DynamicHotspot::DynamicHotspot() { _cursor = 0; } +/*------------------------------------------------------------------------*/ + +SequenceEntry::SequenceEntry() { + _spriteListIndex = 0; + _flipped =0; + _frameIndex = 0; + _frameStart = 0; + _numSprites = 0; + _animType = 0; + _frameInc = 0; + _depth = 0; + _scale = 0; + _dynamicHotspotIndex = -1; + _triggerCountdown = 0; + _doneFlag = 0; + _entries._count = 0; + _abortMode = 0; + _actionNouns[0] = _actionNouns[1] = _actionNouns[2] = 0; + _numTicks = 0; + _extraTicks = 0; + _timeout = 0; +} + +KernelMessage::KernelMessage() { + _flags = 0; + _seqInex = 0; + _asciiChar = '\0'; + _asciiChar2 = '\0'; + _colors = 0; + Common::Point _posiition; + _msgOffset = 0; + _numTicks = 0; + _frameTimer2 = 0; + _frameTimer = 0; + _timeout = 0; + _field1C = 0; + _abortMode = 0; + _nounList[0] = _nounList[1] = _nounList[2] = 0; +} + +/*------------------------------------------------------------------------*/ + +Hotspot::Hotspot() { + _facing = 0; + _articleNumber = 0; + _cursor = 0; + _vocabId = 0; + _verbId = 0; +} + +Hotspot::Hotspot(Common::SeekableReadStream &f) { + _bounds.left = f.readSint16LE(); + _bounds.top = f.readSint16LE(); + _bounds.right = f.readSint16LE(); + _bounds.bottom = f.readSint16LE(); + _feetPos.x = f.readSint16LE(); + _feetPos.y = f.readSint16LE(); + _facing = f.readByte(); + _articleNumber = f.readByte(); + f.skip(1); + _cursor = f.readByte(); + _vocabId = f.readUint16LE(); + _verbId = f.readUint16LE(); +} + } // End of namespace MADS diff --git a/engines/mads/scene.h b/engines/mads/scene.h index 775517b2e6..27bcdb118a 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -30,6 +30,30 @@ namespace MADS { +enum { + VERB_LOOK = 3, + VERB_TAKE = 4, + VERB_PUSH = 5, + VERB_OPEN = 6, + VERB_PUT = 7, + VERB_TALKTO = 8, + VERB_GIVE = 9, + VERB_PULL = 10, + VERB_CLOSE = 11, + VERB_THROW = 12, + VERB_WALKTO = 13 +}; + +class VerbInit { +public: + int _id; + int _action1; + int _action2; + + VerbInit() {} + VerbInit(int id, int action1, int action2): _id(id), _action1(action1), _action2(action2) {} +}; + enum SpriteType { ST_NONE = 0, ST_FOREGROUND = 1, ST_BACKGROUND = -4, ST_FULL_SCREEN_REFRESH = -2, ST_EXPIRED = -1 @@ -77,6 +101,73 @@ public: DynamicHotspot(); }; +class SequenceEntry { +public: + int _spriteListIndex; + int _flipped; + int _frameIndex; + int _frameStart; + int _numSprites; + int _animType; + int _frameInc; + int _depth; + int _scale; + int _dynamicHotspotIndex; + + Common::Point _msgPos; + + int _triggerCountdown; + bool _doneFlag; + struct { + int _count; + int _mode[5]; + int _frameIndex[5]; + int _abortVal[5]; + } _entries; + int _abortMode; + int _actionNouns[3]; + int _numTicks; + int _extraTicks; + int _timeout; + + SequenceEntry(); +}; + +class KernelMessage { +public: + int _flags; + int _seqInex; + char _asciiChar; + char _asciiChar2; + int _colors; + Common::Point _posiition; + int _msgOffset; + int _numTicks; + int _frameTimer2; + int _frameTimer; + int _timeout; + int _field1C; + int _abortMode; + int _nounList[3]; + Common::String _msg; + + KernelMessage(); +}; + +class Hotspot { +public: + Common::Rect _bounds; + Common::Point _feetPos; + int _facing; + int _articleNumber; + int _cursor; + int _vocabId; + int _verbId; + + Hotspot(); + Hotspot(Common::SeekableReadStream &f); +}; + #define SPRITE_COUNT 50 #define TEXT_DISPLAY_COUNT 40 #define DYNAMIC_HOTSPOT_COUNT 8 @@ -146,6 +237,7 @@ public: int _priorSceneId; int _nextSceneId; int _currentSceneId; + Common::Array _verbList; TextDisplay _textDisplay[TEXT_DISPLAY_COUNT]; Common::Array _spriteSlots; Common::Array _spriteList; @@ -154,6 +246,11 @@ public: bool _dynamicHotspotsChanged; byte *_vocabBuffer; Common::Array _activeVocabs; + Common::Array _sequenceList; + Common::Array _messageList; + Common::String _talkFont; + int _textSpacing; + Common::Array _hotspotList; /** * Constructor @@ -196,10 +293,30 @@ public: */ void addActiveVocab(int vocabId); + /** + * Clear the sequence list + */ + void clearSequenceList(); + + /** + * Clear the message list + */ + void clearMessageList(); + /** * Loads the scene logic for a given scene */ - void loadScene(); + void loadSceneLogic(); + + /** + * Loads the hotstpots for the scene + */ + void loadHotspots(); + + /** + * Loads the vocab list + */ + void loadVocab(); /** * Clear the data for the scene -- cgit v1.2.3