diff options
6 files changed, 154 insertions, 21 deletions
diff --git a/engines/titanic/game/parrot/parrot_lobby_controller.cpp b/engines/titanic/game/parrot/parrot_lobby_controller.cpp index f1e054a8dd..907e7519b8 100644 --- a/engines/titanic/game/parrot/parrot_lobby_controller.cpp +++ b/engines/titanic/game/parrot/parrot_lobby_controller.cpp @@ -21,9 +21,14 @@ */ #include "titanic/game/parrot/parrot_lobby_controller.h" +#include "titanic/core/room_item.h" namespace Titanic { +BEGIN_MESSAGE_MAP(CParrotLobbyController, CParrotLobbyObject) + ON_MESSAGE(ActMsg) +END_MESSAGE_MAP() + void CParrotLobbyController::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); CParrotLobbyObject::save(file, indent); @@ -34,4 +39,34 @@ void CParrotLobbyController::load(SimpleFile *file) { CParrotLobbyObject::load(file); } +bool CParrotLobbyController::ActMsg(CActMsg *msg) { + if (msg->_action == "Refresh") + return false; + else if (msg->_action == "GainParrot") + _haveParrot = true; + else if (msg->_action == "LoseParrot") + _haveParrot = false; + else if (msg->_action == "GainPerch") + _havePerch = true; + else if (msg->_action == "LosePerch") + _havePerch = false; + else if (msg->_action == "GainStick") + _haveStick = true; + else if (msg->_action == "LoseStick") + _haveStick = false; + + _flags = 0; + if (_haveParrot) + _flags = 4; + if (_havePerch) + _flags |= 2; + if (_haveStick) + _flags |= 1; + + CActMsg actMsg("Refresh"); + actMsg.execute(findRoom(), CParrotLobbyObject::_type, MSGFLAG_CLASS_DEF | MSGFLAG_SCAN); + actMsg.execute("ParrotLobbyUpdater_TOW"); + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/parrot/parrot_lobby_controller.h b/engines/titanic/game/parrot/parrot_lobby_controller.h index d2fa4a1801..896a4e19d2 100644 --- a/engines/titanic/game/parrot/parrot_lobby_controller.h +++ b/engines/titanic/game/parrot/parrot_lobby_controller.h @@ -28,6 +28,8 @@ namespace Titanic { class CParrotLobbyController : public CParrotLobbyObject { + DECLARE_MESSAGE_MAP; + bool ActMsg(CActMsg *msg); public: CLASSDEF; diff --git a/engines/titanic/game/parrot/parrot_lobby_link_updater.cpp b/engines/titanic/game/parrot/parrot_lobby_link_updater.cpp index 25d5ec724b..47311c31f5 100644 --- a/engines/titanic/game/parrot/parrot_lobby_link_updater.cpp +++ b/engines/titanic/game/parrot/parrot_lobby_link_updater.cpp @@ -21,9 +21,46 @@ */ #include "titanic/game/parrot/parrot_lobby_link_updater.h" +#include "titanic/titanic.h" namespace Titanic { +BEGIN_MESSAGE_MAP(CParrotLobbyLinkUpdater, CParrotLobbyObject) + ON_MESSAGE(ActMsg) +END_MESSAGE_MAP() + +/*------------------------------------------------------------------------*/ + +LinkUpdatorEntry::LinkUpdatorEntry() { + Common::fill(&_vals[0], &_vals[8], 0); +} + +void LinkUpdatorEntry::load(Common::SeekableReadStream *s) { + _linkStr = readStringFromStream(s); + for (int idx = 0; idx < 8; ++idx) + _vals[idx] = s->readByte(); +} + +/*------------------------------------------------------------------------*/ + +void LinkUpdatorEntries::load(Common::SeekableReadStream *s, int count) { + resize(count); + for (int idx = 0; idx < count; ++idx) + (*this)[idx].load(s); +} + +/*------------------------------------------------------------------------*/ + +CParrotLobbyLinkUpdater::CParrotLobbyLinkUpdater() : CParrotLobbyObject(), _fieldBC(1) { + Common::SeekableReadStream *s = g_vm->_filesManager->getResource("DATA/PARROT_LOBBY_LINK_UPDATOR"); + _entries[0].load(s, 7); + _entries[1].load(s, 5); + _entries[2].load(s, 6); + _entries[3].load(s, 9); + _entries[4].load(s, 1); + delete s; +} + void CParrotLobbyLinkUpdater::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); CParrotLobbyObject::save(file, indent); @@ -34,4 +71,45 @@ void CParrotLobbyLinkUpdater::load(SimpleFile *file) { CParrotLobbyObject::load(file); } +bool CParrotLobbyLinkUpdater::ActMsg(CActMsg *msg) { + if (msg->_action != "Refresh") + return false; + + CNodeItem *node = findNode(); + LinkUpdatorEntries *entriesP; + if (isEquals("ParrotLobbyUpdater_TOW")) { + entriesP = &_entries[4]; + } else { + if (node->_nodeNumber > 3) + return true; + entriesP = &_entries[node->_nodeNumber]; + } + int count = entriesP->size(); + + for (CTreeItem *item = node->getFirstChild(); item; item = item->scan(node)) { + CLinkItem *link = dynamic_cast<CLinkItem *>(item); + if (!link || count == 0) + continue; + + CString linkName = link->getName(); + char c = linkName.lastChar(); + if (c >= 'a' && c <= 'd') + linkName.deleteLastChar(); + + for (uint idx = 0; idx < entriesP->size(); ++idx) { + const LinkUpdatorEntry &entry = (*entriesP)[idx]; + if (entry._linkStr == linkName) { + int val = entry._vals[CParrotLobbyObject::_flags]; + if (val) + linkName += (char)(0x60 + val); + + link->_name = linkName; + break; + } + } + } + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/parrot/parrot_lobby_link_updater.h b/engines/titanic/game/parrot/parrot_lobby_link_updater.h index 0470a62dee..93db931a53 100644 --- a/engines/titanic/game/parrot/parrot_lobby_link_updater.h +++ b/engines/titanic/game/parrot/parrot_lobby_link_updater.h @@ -23,16 +23,34 @@ #ifndef TITANIC_PARROT_LOBBY_LINK_UPDATER_H #define TITANIC_PARROT_LOBBY_LINK_UPDATER_H +#include "common/stream.h" #include "titanic/game/parrot/parrot_lobby_object.h" namespace Titanic { +struct LinkUpdatorEntry { + CString _linkStr; + int _vals[8]; + + LinkUpdatorEntry(); + void load(Common::SeekableReadStream *s); +}; + +class LinkUpdatorEntries : public Common::Array<LinkUpdatorEntry> { +public: + void load(Common::SeekableReadStream *s, int count); +}; + class CParrotLobbyLinkUpdater : public CParrotLobbyObject { + DECLARE_MESSAGE_MAP; + bool ActMsg(CActMsg *msg); +private: + LinkUpdatorEntries _entries[5]; public: int _fieldBC; public: CLASSDEF; - CParrotLobbyLinkUpdater() : CParrotLobbyObject(), _fieldBC(1) {} + CParrotLobbyLinkUpdater(); /** * Save the data for the class to file diff --git a/engines/titanic/game/parrot/parrot_lobby_object.cpp b/engines/titanic/game/parrot/parrot_lobby_object.cpp index a78ab2b6d9..06222fd063 100644 --- a/engines/titanic/game/parrot/parrot_lobby_object.cpp +++ b/engines/titanic/game/parrot/parrot_lobby_object.cpp @@ -26,34 +26,34 @@ namespace Titanic { EMPTY_MESSAGE_MAP(CParrotLobbyObject, CGameObject); -int CParrotLobbyObject::_v1; -int CParrotLobbyObject::_v2; -int CParrotLobbyObject::_v3; -int CParrotLobbyObject::_v4; +bool CParrotLobbyObject::_haveParrot; +bool CParrotLobbyObject::_havePerch; +bool CParrotLobbyObject::_haveStick; +int CParrotLobbyObject::_flags; void CParrotLobbyObject::init() { - _v1 = 1; - _v2 = 1; - _v3 = 1; - _v4 = 7; + _haveParrot = true; + _havePerch = true; + _haveStick = true; + _flags = 7; } void CParrotLobbyObject::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeNumberLine(_v1, indent); - file->writeNumberLine(_v2, indent); - file->writeNumberLine(_v3, indent); - file->writeNumberLine(_v4, indent); + file->writeNumberLine(_haveParrot, indent); + file->writeNumberLine(_havePerch, indent); + file->writeNumberLine(_haveStick, indent); + file->writeNumberLine(_flags, indent); CGameObject::save(file, indent); } void CParrotLobbyObject::load(SimpleFile *file) { file->readNumber(); - _v1 = file->readNumber(); - _v2 = file->readNumber(); - _v3 = file->readNumber(); - _v4 = file->readNumber(); + _haveParrot = file->readNumber(); + _havePerch = file->readNumber(); + _haveStick = file->readNumber(); + _flags = file->readNumber(); CGameObject::load(file); } diff --git a/engines/titanic/game/parrot/parrot_lobby_object.h b/engines/titanic/game/parrot/parrot_lobby_object.h index 5272303888..a210331399 100644 --- a/engines/titanic/game/parrot/parrot_lobby_object.h +++ b/engines/titanic/game/parrot/parrot_lobby_object.h @@ -30,10 +30,10 @@ namespace Titanic { class CParrotLobbyObject : public CGameObject { DECLARE_MESSAGE_MAP; public: - static int _v1; - static int _v2; - static int _v3; - static int _v4; + static bool _haveParrot; + static bool _havePerch; + static bool _haveStick; + static int _flags; static void init(); public: |