aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-05-30 08:06:34 +0200
committerThierry Crozat2019-07-28 15:09:14 +0100
commit777040557d7a48eb6c408ea5b66d3048434afdfb (patch)
treeb21032986f149c28463ab009981d21e76caa3941 /engines
parent977d67b27216a98be36e128432f09f0bbcc8e9f1 (diff)
downloadscummvm-rg350-777040557d7a48eb6c408ea5b66d3048434afdfb.tar.gz
scummvm-rg350-777040557d7a48eb6c408ea5b66d3048434afdfb.tar.bz2
scummvm-rg350-777040557d7a48eb6c408ea5b66d3048434afdfb.zip
SUPERNOVA2: Add inventory from supernova
Diffstat (limited to 'engines')
-rw-r--r--engines/supernova2/state.cpp56
-rw-r--r--engines/supernova2/state.h28
2 files changed, 83 insertions, 1 deletions
diff --git a/engines/supernova2/state.cpp b/engines/supernova2/state.cpp
index 71adbf0af9..2d44b2a479 100644
--- a/engines/supernova2/state.cpp
+++ b/engines/supernova2/state.cpp
@@ -42,8 +42,59 @@ namespace Supernova2 {
// kStringStatusCommandPress, kStringStatusCommandPull, kStringStatusCommandUse, kStringStatusCommandTalk, kStringStatusCommandGive
//};
+void Inventory::add(Object &obj) {
+ if (_numObjects < kMaxCarry) {
+ _inventory[_numObjects++] = &obj;
+ obj.setProperty(CARRIED);
+ }
+
+ if (getSize() > _inventoryScroll + 8) {
+ _inventoryScroll = getSize() - 8;
+ _inventoryScroll += _inventoryScroll % 2;
+ }
+}
+
+void Inventory::remove(Object &obj) {
+ for (int i = 0; i < _numObjects; ++i) {
+ if (_inventory[i] == &obj) {
+ if (_inventoryScroll >= 2 && getSize() % 2)
+ _inventoryScroll -= 2;
+
+ --_numObjects;
+ while (i < _numObjects) {
+ _inventory[i] = _inventory[i + 1];
+ ++i;
+ }
+ obj.disableProperty(CARRIED);
+ }
+ }
+}
+
+void Inventory::clear() {
+ for (int i = 0; i < _numObjects; ++i)
+ _inventory[i]->disableProperty(CARRIED);
+ _numObjects = 0;
+ _inventoryScroll = 0;
+}
+
+Object *Inventory::get(int index) const {
+ if (index < _numObjects)
+ return _inventory[index];
+
+ return _nullObject;
+}
+
+Object *Inventory::get(ObjectId id) const {
+ for (int i = 0; i < _numObjects; ++i) {
+ if (_inventory[i]->_id == id)
+ return _inventory[i];
+ }
+
+ return _nullObject;
+}
GameManager::GameManager(Supernova2Engine *vm)
- : _vm(vm)
+ : _inventory(&_nullObject, _inventoryScroll)
+ , _vm(vm)
, _mouseClickType(Common::EVENT_INVALID) {
initRooms();
changeRoom(INTRO);
@@ -54,6 +105,9 @@ GameManager::~GameManager() {
}
void GameManager::initState() {
+ _currentInputObject = &_nullObject;
+ _inputObject[0] = &_nullObject;
+ _inputObject[1] = &_nullObject;
_processInput = false;
_guiEnabled = true;
_animationEnabled = true;
diff --git a/engines/supernova2/state.h b/engines/supernova2/state.h
index 9c7ad22dde..a8e3b368f3 100644
--- a/engines/supernova2/state.h
+++ b/engines/supernova2/state.h
@@ -36,6 +36,30 @@ const int32 kMaxTimerValue = 0x7FFFFFFF;
struct GameState {
};
+class Inventory {
+public:
+ Inventory(Object *nullObject, int &inventoryScroll)
+ : _numObjects(0)
+ , _nullObject(nullObject)
+ , _inventoryScroll(inventoryScroll) {
+ for (int i = 0; i < kMaxCarry; ++i)
+ _inventory[i] = nullptr;
+ }
+
+ void add(Object &obj);
+ void remove(Object &obj);
+ void clear();
+ Object *get(int index) const;
+ Object *get(ObjectId id) const;
+ int getSize() const { return _numObjects; }
+
+private:
+ Object *_inventory[kMaxCarry];
+ Object *_nullObject;
+ int &_inventoryScroll;
+ int _numObjects;
+};
+
class GameManager {
public:
GameManager(Supernova2Engine *vm);
@@ -56,10 +80,14 @@ public:
Room *_currentRoom;
bool _newRoom;
Room *_rooms[NUMROOMS];
+ Inventory _inventory;
GameState _state;
bool _processInput;
bool _guiEnabled;
bool _animationEnabled;
+ Object _nullObject;
+ Object *_currentInputObject;
+ Object *_inputObject[2];
uint _timePaused;
bool _timerPaused;
int32 _messageDuration;