From 86a1926c19bf32f4a0b315c6f7d7d1f3567e555d Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Tue, 31 Mar 2009 15:45:44 +0000 Subject: Added basic multiple inventory support. This will be used for the GIVE and SWAP commands. svn-id: r39773 --- engines/parallaction/inventory.cpp | 79 +++++++++++++++++++------------- engines/parallaction/inventory.h | 1 + engines/parallaction/parallaction.cpp | 4 -- engines/parallaction/parallaction.h | 11 +++-- engines/parallaction/parallaction_br.cpp | 8 ++++ engines/parallaction/parallaction_ns.cpp | 4 ++ 6 files changed, 67 insertions(+), 40 deletions(-) (limited to 'engines') diff --git a/engines/parallaction/inventory.cpp b/engines/parallaction/inventory.cpp index b701f12ac1..c7fc6b9cf2 100644 --- a/engines/parallaction/inventory.cpp +++ b/engines/parallaction/inventory.cpp @@ -102,56 +102,31 @@ void Parallaction::highlightInventoryItem(ItemPosition pos) { } int Parallaction::addInventoryItem(ItemName item) { - return _inventory->addItem(item); + return getActiveInventory()->addItem(item); } int Parallaction::addInventoryItem(ItemName item, uint32 value) { - return _inventory->addItem(item, value); + return getActiveInventory()->addItem(item, value); } void Parallaction::dropItem(uint16 v) { - _inventory->removeItem(v); + getActiveInventory()->removeItem(v); } bool Parallaction::isItemInInventory(int32 v) { - return (_inventory->findItem(v) != -1); + return (getActiveInventory()->findItem(v) != -1); } const InventoryItem* Parallaction::getInventoryItem(int16 pos) { - return _inventory->getItem(pos); + return getActiveInventory()->getItem(pos); } int16 Parallaction::getInventoryItemIndex(int16 pos) { - return _inventory->getItemName(pos); -} - -void Parallaction::initInventory() { - InventoryProperties *props; - InventoryItem *verbs; - - if (getGameType() == GType_Nippon) { - props = &_invProps_NS; - verbs = _verbs_NS; - } else { - props = &_invProps_BR; - verbs = _verbs_BR; - } - - _inventory = new Inventory(props, verbs); - _inventoryRenderer = new InventoryRenderer(this, props); - _inventoryRenderer->bindInventory(_inventory); -} - -void Parallaction::destroyInventory() { - delete _inventory; - delete _inventoryRenderer; - - _inventory = 0; - _inventoryRenderer = 0; + return getActiveInventory()->getItemName(pos); } void Parallaction::cleanInventory(bool keepVerbs) { - _inventory->clear(keepVerbs); + getActiveInventory()->clear(keepVerbs); } void Parallaction::openInventory() { @@ -361,7 +336,47 @@ const InventoryItem* Inventory::getItem(ItemPosition pos) const { return &_items[pos]; } +Inventory *Parallaction::getActiveInventory() { + return _inventoryRenderer->getBoundInventory(); +} + + +void Parallaction_ns::initInventory() { + _inventory = new Inventory(&_invProps_NS, _verbs_NS); + assert(_inventory); + _inventoryRenderer = new InventoryRenderer(this, &_invProps_NS); + assert(_inventoryRenderer); + _inventoryRenderer->bindInventory(_inventory); +} + +void Parallaction_br::initInventory() { + for (int i = 0; i < 3; ++i) { + _inventory[i] = new Inventory(&_invProps_BR, _verbs_BR); + assert(_inventory[i]); + } + _inventoryRenderer = new InventoryRenderer(this, &_invProps_BR); + assert(_inventoryRenderer); + // don't bind here, wait for changeCharacter() +} + +void Parallaction_ns::destroyInventory() { + delete _inventoryRenderer; + delete _inventory; + _inventory = 0; + _inventoryRenderer = 0; +} + +void Parallaction_br::destroyInventory() { + delete _inventoryRenderer; + delete _inventory[0]; + delete _inventory[1]; + delete _inventory[2]; + _inventory[0] = 0; + _inventory[1] = 0; + _inventory[2] = 0; + _inventoryRenderer = 0; +} } // namespace Parallaction diff --git a/engines/parallaction/inventory.h b/engines/parallaction/inventory.h index f041627810..a9424d9186 100644 --- a/engines/parallaction/inventory.h +++ b/engines/parallaction/inventory.h @@ -105,6 +105,7 @@ public: virtual ~InventoryRenderer(); void bindInventory(Inventory *inv) { _inv = inv; } + Inventory *getBoundInventory() const { return _inv; } void showInventory(); void hideInventory(); diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index e144224bd6..f7b4e226c4 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -93,8 +93,6 @@ Parallaction::~Parallaction() { delete _balloonMan; _balloonMan = 0; - destroyInventory(); - delete _localFlagNames; delete _gfx; delete _soundMan; @@ -124,8 +122,6 @@ Common::Error Parallaction::init() { memset(_locationNames, 0, NUM_LOCATIONS * 32); - initInventory(); // needs to be pushed into subclass - // this needs _disk to be already setup _input = new Input(this); diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index fd2d05427e..a4f11d3675 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -296,7 +296,6 @@ public: Table *_localFlagNames; CommandExec *_cmdExec; ProgramExec *_programExec; - Inventory *_inventory; BalloonManager *_balloonMan; DialogueManager *_dialogueMan; InventoryRenderer *_inventoryRenderer; @@ -366,11 +365,10 @@ public: bool isItemInInventory(int32 v); const InventoryItem* getInventoryItem(int16 pos); int16 getInventoryItemIndex(int16 pos); - void initInventory(); - void destroyInventory(); void cleanInventory(bool keepVerbs = true); void openInventory(); void closeInventory(); + Inventory *getActiveInventory(); virtual void parseLocation(const char* name) = 0; virtual void changeLocation() = 0; @@ -406,7 +404,6 @@ public: virtual void cleanupGame(); virtual void updateWalkers(); virtual void scheduleWalk(int16 x, int16 y, bool fromUser); - virtual DialogueManager *createDialogueManager(ZonePtr z); void switchBackground(const char* background, const char* mask); @@ -415,11 +412,14 @@ private: bool _inTestResult; LocationParser_ns *_locationParser; ProgramParser_ns *_programParser; + Inventory *_inventory; private: void initFonts(); void freeFonts(); void initResources(); + void initInventory(); + void destroyInventory(); void startGui(); void startCreditSequence(); void startEndPartSequence(); @@ -536,12 +536,15 @@ private: LocationParser_br *_locationParser; ProgramParser_br *_programParser; SoundMan_br *_soundManI; + Inventory *_inventory[3]; int32 _counters[32]; Table *_countersNames; private: void initResources(); + void initInventory(); + void destroyInventory(); void initFonts(); void freeFonts(); void freeLocation(bool removeAll); diff --git a/engines/parallaction/parallaction_br.cpp b/engines/parallaction/parallaction_br.cpp index 7d641b530f..78d5bcd116 100644 --- a/engines/parallaction/parallaction_br.cpp +++ b/engines/parallaction/parallaction_br.cpp @@ -96,6 +96,8 @@ Common::Error Parallaction_br::init() { _saveLoad = new SaveLoad_br(this, _saveFileMan); + initInventory(); + Parallaction::init(); return Common::kNoError; @@ -105,6 +107,8 @@ Parallaction_br::~Parallaction_br() { freeFonts(); freeCharacter(); + destroyInventory(); + delete _objects; delete _locationParser; @@ -406,6 +410,9 @@ void Parallaction_br::changeCharacter(const char *name) { _char.setName(name); _char._ani->gfxobj = _gfx->loadCharacterAnim(name); _char._talk = _disk->loadTalk(name); + + // TODO: select the inventory according to character + _inventoryRenderer->bindInventory(_inventory[0]); } _char._ani->_flags |= kFlagsActive; @@ -515,4 +522,5 @@ void Parallaction_br::restoreOrSaveZoneFlags(ZonePtr z, bool restore) { } } + } // namespace Parallaction diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index 430894cb19..60644f7eba 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -202,6 +202,8 @@ Common::Error Parallaction_ns::init() { _saveLoad = new SaveLoad_ns(this, _saveFileMan); + initInventory(); + Parallaction::init(); return Common::kNoError; @@ -211,6 +213,8 @@ Parallaction_ns::~Parallaction_ns() { freeFonts(); freeCharacter(); + destroyInventory(); + delete _locationParser; delete _programParser; freeLocation(true); -- cgit v1.2.3