diff options
author | Ľubomír Remák | 2018-03-08 21:25:55 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | bdb6582bb2523f6216f92bbc79a602b33137d023 (patch) | |
tree | bdb3b00b0846c1c8b9963d899a1ab51d95a87e87 | |
parent | 5d29112f1c06dea3a789b36b0d109e6529f8cd61 (diff) | |
download | scummvm-rg350-bdb6582bb2523f6216f92bbc79a602b33137d023.tar.gz scummvm-rg350-bdb6582bb2523f6216f92bbc79a602b33137d023.tar.bz2 scummvm-rg350-bdb6582bb2523f6216f92bbc79a602b33137d023.zip |
MUTATIONOFJB: Implement data model for inventory.
-rw-r--r-- | engines/mutationofjb/commands/conditionalcommand.h | 5 | ||||
-rw-r--r-- | engines/mutationofjb/debug.h | 5 | ||||
-rw-r--r-- | engines/mutationofjb/encryptedfile.h | 5 | ||||
-rw-r--r-- | engines/mutationofjb/game.cpp | 1 | ||||
-rw-r--r-- | engines/mutationofjb/game.h | 7 | ||||
-rw-r--r-- | engines/mutationofjb/inventory.cpp | 92 | ||||
-rw-r--r-- | engines/mutationofjb/inventory.h | 52 | ||||
-rw-r--r-- | engines/mutationofjb/module.mk | 1 | ||||
-rw-r--r-- | engines/mutationofjb/script.cpp | 2 | ||||
-rw-r--r-- | engines/mutationofjb/util.h | 5 |
10 files changed, 174 insertions, 1 deletions
diff --git a/engines/mutationofjb/commands/conditionalcommand.h b/engines/mutationofjb/commands/conditionalcommand.h index 27a8ac1968..6f647204c6 100644 --- a/engines/mutationofjb/commands/conditionalcommand.h +++ b/engines/mutationofjb/commands/conditionalcommand.h @@ -20,6 +20,9 @@ * */ +#ifndef MUTATIONOFJB_CONDITIONALCOMMAND_H +#define MUTATIONOFJB_CONDITIONALCOMMAND_H + #include "mutationofjb/commands/command.h" #include "common/scummsys.h" @@ -43,3 +46,5 @@ protected: }; } + +#endif diff --git a/engines/mutationofjb/debug.h b/engines/mutationofjb/debug.h index 86ee8448c5..a41bacaaf3 100644 --- a/engines/mutationofjb/debug.h +++ b/engines/mutationofjb/debug.h @@ -20,6 +20,9 @@ * */ +#ifndef MUTATIONOFJB_DEBUG_H +#define MUTATIONOFJB_DEBUG_H + #include "gui/debugger.h" namespace MutationOfJB { @@ -38,3 +41,5 @@ private: } +#endif + diff --git a/engines/mutationofjb/encryptedfile.h b/engines/mutationofjb/encryptedfile.h index 69f6f6251e..2053f1feee 100644 --- a/engines/mutationofjb/encryptedfile.h +++ b/engines/mutationofjb/encryptedfile.h @@ -20,6 +20,9 @@ * */ +#ifndef MUTATIONOFJB_ENCRYPTEDFILE_H +#define MUTATIONOFJB_ENCRYPTEDFILE_H + #include "common/file.h" namespace MutationOfJB { @@ -30,3 +33,5 @@ public: }; } + +#endif diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp index 9f517d6608..15fbd033fb 100644 --- a/engines/mutationofjb/game.cpp +++ b/engines/mutationofjb/game.cpp @@ -170,6 +170,7 @@ Static *Scene::getStatic(uint8 staticId) { return &_statics[staticId - 1]; } + GameData::GameData() : _currentScene(0) {} Scene *GameData::getScene(uint8 sceneId) diff --git a/engines/mutationofjb/game.h b/engines/mutationofjb/game.h index eda178bf8f..77e336f024 100644 --- a/engines/mutationofjb/game.h +++ b/engines/mutationofjb/game.h @@ -20,7 +20,11 @@ * */ +#ifndef MUTATIONOFJB_GAME_H +#define MUTATIONOFJB_GAME_H + #include "common/scummsys.h" +#include "mutationofjb/inventory.h" namespace Common { class ReadStream; @@ -133,9 +137,12 @@ public: bool loadFromStream(Common::ReadStream &stream); uint8 _currentScene; + Inventory _inventory; private: Scene _scenes[45]; }; } + +#endif diff --git a/engines/mutationofjb/inventory.cpp b/engines/mutationofjb/inventory.cpp new file mode 100644 index 0000000000..0f91a93203 --- /dev/null +++ b/engines/mutationofjb/inventory.cpp @@ -0,0 +1,92 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "mutationofjb/inventory.h" +#include "common/algorithm.h" +#include "common/debug.h" + +namespace MutationOfJB { + +static const uint VISIBLE_ITEMS = 6; + +const Inventory::Items &Inventory::getItems() const { + return _items; +} + +void Inventory::addItem(const Common::String &item) { + _items.push_back(item); + + if (_items.size() > VISIBLE_ITEMS) { + rotateItemsRight(VISIBLE_ITEMS); + } +} + +void Inventory::removeItem(const Common::String &item) { + Items::iterator it = find(_items.begin(), _items.end(), item); + if (it == _items.end()) { + debug("Item '%s' not in inventory.", item.c_str()); + return; + } + + _items.remove_at(it - _items.begin()); +} + +void Inventory::removeAllItems() { + _items.clear(); +} + +void Inventory::rotateItemsRight(uint n) { + if (_items.size() < 2) { + return; + } + + n %= _items.size(); + + reverseItems(0, _items.size() - 1); + reverseItems(0, n - 1); + reverseItems(n, _items.size() - 1); +} + +void Inventory::rotateItemsLeft(uint n) { + if (_items.size() < 2) { + return; + } + + n %= _items.size(); + reverseItems(0, _items.size() - 1); + reverseItems(_items.size() - n, _items.size() - 1); + reverseItems(0, _items.size() - n - 1); +} + +void Inventory::reverseItems(uint from, uint to) { + assert(from <= to); + if (from == to) { + return; + } + + const uint size = to - from + 1; + for (uint i = 0; i < size / 2; ++i) { + SWAP(_items[i], _items[size - i - 1]); + } +} + +} diff --git a/engines/mutationofjb/inventory.h b/engines/mutationofjb/inventory.h new file mode 100644 index 0000000000..02cccc0a51 --- /dev/null +++ b/engines/mutationofjb/inventory.h @@ -0,0 +1,52 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef MUTATIONOFJB_INVENTORY_H +#define MUTATIONOFJB_INVENTORY_H + +#include "common/scummsys.h" +#include "common/array.h" +#include "common/str.h" + +namespace MutationOfJB { + +class Inventory { +public: + typedef Common::Array<Common::String> Items; + + const Items &getItems() const; + void addItem(const Common::String &item); + void removeItem(const Common::String &item); + void removeAllItems(); + + void rotateItemsRight(uint n); + void rotateItemsLeft(uint n); + +private: + void reverseItems(uint from, uint to); + + Items _items; +}; + +} + +#endif diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk index 2c89988916..f719ae0ced 100644 --- a/engines/mutationofjb/module.mk +++ b/engines/mutationofjb/module.mk @@ -12,6 +12,7 @@ MODULE_OBJS := \ detection.o \ encryptedfile.o \ game.o \ + inventory.o \ mutationofjb.o \ room.o \ script.o \ diff --git a/engines/mutationofjb/script.cpp b/engines/mutationofjb/script.cpp index 4490af537e..98b1727935 100644 --- a/engines/mutationofjb/script.cpp +++ b/engines/mutationofjb/script.cpp @@ -69,7 +69,7 @@ bool ScriptParseContext::readLine(Common::String &line) { } return true; } - } while(_stream.eos()); + } while(!_stream.eos()); return false; } diff --git a/engines/mutationofjb/util.h b/engines/mutationofjb/util.h index 3059d51012..7dd74953ec 100644 --- a/engines/mutationofjb/util.h +++ b/engines/mutationofjb/util.h @@ -20,6 +20,11 @@ * */ +#ifndef MUTATIONOFJB_UTIL_H +#define MUTATIONOFJB_UTIL_H + namespace MutationOfJB { void reportFileMissingError(const char *fileName); } + +#endif |