From e8725ae068a51fb6ccdfd9f7d2bd4e8e7a12f40a Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Fri, 17 Jun 2016 21:47:40 +0200 Subject: [PATCH] MACVENTURE: Add attribute set function --- engines/macventure/macventure.cpp | 12 +++++++ engines/macventure/macventure.h | 1 + engines/macventure/world.cpp | 52 ++++++++++++++++++++++++++++++- engines/macventure/world.h | 5 +++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index da192628fe5..75f2c337119 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -99,6 +99,14 @@ Common::Error MacVentureEngine::run() { _cmdReady = false; _haltedAtEnd = false; _haltedInSelection = false; + + //if !savegame + _cmdReady = true; + _selectedControl = kStartOrResume; + ObjID playerParent = _world->getObjAttr(1, kAttrParentObject); + _currentSelection.push_back(playerParent);// Push the parent of the player + _world->setObjAttr(playerParent, 6, 1); + _prepared = true; while (!(_gameState == kGameStateQuitting)) { processEvents(); @@ -181,6 +189,10 @@ void MacVentureEngine::preparedToRun() { _prepared = true; } +void MacVentureEngine::gameChanged() { + _gameChanged = true; +} + void MacVentureEngine::enqueueObject(ObjID id) { QueuedObject obj; obj.parent = _world->getObjAttr(id, kAttrParentObject); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index a4340bf2bcc..457d6859925 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -151,6 +151,7 @@ public: void activateCommand(ControlReference id); void refreshReady(); void preparedToRun(); + void gameChanged(); void enqueueObject(ObjID id); diff --git a/engines/macventure/world.cpp b/engines/macventure/world.cpp index abb0c55c041..feb8c0b7be9 100644 --- a/engines/macventure/world.cpp +++ b/engines/macventure/world.cpp @@ -46,7 +46,7 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { uint32 res; uint32 index = _engine->getGlobalSettings().attrIndices[attrID]; if (!(index & 0x80)) { // It's not a constant - res = _saveGame->getGroups()[attrID][objID]; + res = _saveGame->getAttr(objID, index); } else { Common::SeekableReadStream *objStream = _objectConstants->getItem(objID); index &= 0x7F; @@ -59,6 +59,25 @@ uint32 World::getObjAttr(ObjID objID, uint32 attrID) { return res; } +void World::setObjAttr(ObjID objID, uint32 attrID, Attribute value) { + if (attrID == kAttrPosX || attrID == kAttrPosY) {} + // Round to scale + + if (attrID == kAttrParentObject) + setParent(objID, value); + + if (attrID < kAttrOtherDoor) + _engine->enqueueObject(objID); + + uint32 idx = _engine->getGlobalSettings().attrIndices[attrID]; + value <<= _engine->getGlobalSettings().attrShifts[attrID]; + value &= _engine->getGlobalSettings().attrMasks[attrID]; + Attribute oldVal = _saveGame->getAttr(objID, idx); + oldVal &= ~_engine->getGlobalSettings().attrMasks[attrID]; + _saveGame->setAttr(idx, objID, (value | oldVal)); + _engine->gameChanged(); +} + bool MacVenture::World::isObjActive(ObjID obj) { return false; } @@ -94,6 +113,28 @@ void World::calculateObjectRelations() { } } +void World::setParent(ObjID child, ObjID newParent) { + ObjID old = _saveGame->getAttr(child, kAttrParentObject); + if (newParent == child) + return; + + ObjID oldNdx = old * 2; + old = _relations[oldNdx]; + while (old != child) { + oldNdx = (old * 2) + 1; + old = _relations[oldNdx]; + } + _relations[oldNdx] = _relations[(old * 2) + 1]; + oldNdx = newParent * 2; + old = _relations[oldNdx]; + while (old && old <= child) { + oldNdx = (old * 2) + 1; + old = _relations[oldNdx]; + } + _relations[child * 2 + 1] = old; + _relations[oldNdx] = child; +} + // SaveGame SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { _groups = Common::Array(); @@ -107,6 +148,15 @@ SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) { SaveGame::~SaveGame() { } + +Attribute SaveGame::getAttr(ObjID objID, uint32 attrID) { + return _groups[attrID][objID]; +} + +void SaveGame::setAttr(uint32 attrID, ObjID objID, Attribute value) { + _groups[attrID][objID] = value; +} + const Common::Array& MacVenture::SaveGame::getGroups() { return _groups; } diff --git a/engines/macventure/world.h b/engines/macventure/world.h index fe93ef13950..58e9fc5ce50 100644 --- a/engines/macventure/world.h +++ b/engines/macventure/world.h @@ -65,6 +65,9 @@ public: SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res); ~SaveGame(); + Attribute getAttr(ObjID objID, uint32 attrID); + void setAttr(uint32 attrID, ObjID objID, Attribute value); + const Common::Array &getGroups(); const AttributeGroup *getGroup(uint32 groupID); const Common::Array &getGlobals(); @@ -87,11 +90,13 @@ public: ~World(); uint32 getObjAttr(ObjID objID, uint32 attrID); + void setObjAttr(ObjID objID, uint32 attrID, Attribute value); bool isObjActive(ObjID obj); private: bool loadStartGameFileName(); void calculateObjectRelations(); + void setParent(ObjID child, ObjID newParent); private: MacVentureEngine *_engine;