SUPERNOVA2: Add inventory from supernova

This commit is contained in:
Jaromir Wysoglad 2019-05-30 08:06:34 +02:00 committed by Thierry Crozat
parent 977d67b272
commit 777040557d
2 changed files with 83 additions and 1 deletions

View File

@ -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;

View File

@ -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;