Permalink
Browse files

MUTATIONOFJB: Implement data model for inventory.

  • Loading branch information...
LubomirR authored and sev- committed Mar 8, 2018
1 parent 5d29112 commit bdb6582bb2523f6216f92bbc79a602b33137d023
@@ -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 @@ class ConditionalCommand : public Command {
};

}

#endif
@@ -20,6 +20,9 @@
*
*/

#ifndef MUTATIONOFJB_DEBUG_H
#define MUTATIONOFJB_DEBUG_H

#include "gui/debugger.h"

namespace MutationOfJB {
@@ -38,3 +41,5 @@ class Console : public GUI::Debugger {

}

#endif

@@ -20,6 +20,9 @@
*
*/

#ifndef MUTATIONOFJB_ENCRYPTEDFILE_H
#define MUTATIONOFJB_ENCRYPTEDFILE_H

#include "common/file.h"

namespace MutationOfJB {
@@ -30,3 +33,5 @@ class EncryptedFile : public Common::File {
};

}

#endif
@@ -170,6 +170,7 @@ Static *Scene::getStatic(uint8 staticId) {
return &_statics[staticId - 1];
}


GameData::GameData() : _currentScene(0) {}

Scene *GameData::getScene(uint8 sceneId)
@@ -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 @@ struct GameData
bool loadFromStream(Common::ReadStream &stream);

uint8 _currentScene;
Inventory _inventory;
private:
Scene _scenes[45];

};

}

#endif
@@ -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]);
}
}

}
@@ -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
@@ -12,6 +12,7 @@ MODULE_OBJS := \
detection.o \
encryptedfile.o \
game.o \
inventory.o \
mutationofjb.o \
room.o \
script.o \
@@ -69,7 +69,7 @@ bool ScriptParseContext::readLine(Common::String &line) {
}
return true;
}
} while(_stream.eos());
} while(!_stream.eos());

return false;
}
@@ -20,6 +20,11 @@
*
*/

#ifndef MUTATIONOFJB_UTIL_H
#define MUTATIONOFJB_UTIL_H

namespace MutationOfJB {
void reportFileMissingError(const char *fileName);
}

#endif

0 comments on commit bdb6582

Please sign in to comment.