scummvm/engines/dragons/inventory.cpp

211 lines
5.3 KiB
C++
Raw Normal View History

/* 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 "actor.h"
#include "dragons.h"
#include "dragonrms.h"
#include "dragonini.h"
2019-05-02 22:12:04 +10:00
#include "background.h"
#include "inventory.h"
2019-05-02 22:12:04 +10:00
#include "bag.h"
namespace Dragons {
static const Common::Point positionTable[4] = {
{2,0},
{0xce,0},
{2,0x9e},
{0xce,0x9e}
};
Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
2019-03-05 21:39:44 +11:00
_type = 0;
_sequenceId = 0;
_screenPositionIndex = 0;
_old_showing_value = 0;
2019-05-02 22:12:04 +10:00
_bag = NULL;
}
2019-05-02 22:12:04 +10:00
void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag) {
_actor = actorManager->loadActor(1, 1); //Load inventory
_actor->x_pos = 2;
_actor->y_pos = 0;
_actor->priorityLayer = 6;
_actor->flags = 0;
_actor->field_e = 0x100;
_actor->updateSequence(0);
_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
Dragons::ACTOR_FLAG_200);
_sequenceId = 0;
2019-03-05 21:39:44 +11:00
_type = 0;
_old_showing_value = 0;
2019-05-02 22:12:04 +10:00
_bag = bag;
}
void Inventory::loadScene(uint32 sceneId) {
2019-03-05 21:39:44 +11:00
if (!_type) {
_sequenceId = _vm->isFlagSet(Dragons::ENGINE_FLAG_400000) ? 1 : 0;
}
_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(sceneId);
if (_sequenceId == 0 && _vm->getVar(7) == 1) {
_actor->updateSequence(5);
} else {
_actor->updateSequence(_sequenceId);
}
_actor->x_pos = positionTable[_screenPositionIndex].x;
if ((_sequenceId == 0 || _sequenceId == 2) && (_screenPositionIndex == 1 || _screenPositionIndex == 3)) {
_actor->x_pos += 0x32;
}
_actor->y_pos = positionTable[_screenPositionIndex].y;
}
2019-03-05 21:39:44 +11:00
void Inventory::updateVisibility() {
_actor->priorityLayer = _vm->isFlagSet(Dragons::ENGINE_FLAG_10) ? (int16)6 : (int16)0;
}
2019-03-07 21:24:10 +11:00
Common::Point Inventory::getPosition() {
return positionTable[_screenPositionIndex];
}
void Inventory::setActorFlag400() {
_actor->setFlag(ACTOR_FLAG_400);
}
void Inventory::setPriority(uint16 priority) {
_actor->priorityLayer = priority;
}
void Inventory::setActorSequenceId(int32 sequenceId) {
if (isActorSet()) {
_actor->_sequenceID = sequenceId;
}
}
2019-05-02 22:12:04 +10:00
void Inventory::openInventory() {
//TODO 0x80030e8c
_sequenceId = 4;
if (!_vm->isFlagSet(ENGINE_FLAG_400000)) {
_sequenceId = 2;
}
_actor->updateSequence(_sequenceId);
_screenPositionIndex = 1;
_actor->x_pos = positionTable[_screenPositionIndex].x;
if ((_sequenceId == 0) || (_sequenceId == 2)) {
_actor->x_pos = positionTable[_screenPositionIndex].x + 0x32;
}
_actor->y_pos = positionTable[_screenPositionIndex].y;
animateBagIn();
//TODO 0x800310e0 update cursor position.
for(int i = 0; i < 0x29; i++) {
Actor *item = _vm->_actorManager->getActor(i + 0x17);
item->x_pos = 0x28; //TODO
item->y_pos = 0x28;
if (_vm->unkArray_uint16[i]) {
item->field_e = 0x100;
item->priorityLayer = 0;
item->updateSequence(_vm->getINI(_vm->unkArray_uint16[i] - 1)->field_8 * 2 + 10);
item->setFlag(ACTOR_FLAG_200); //80 + 40
item->setFlag(ACTOR_FLAG_100);
item->setFlag(ACTOR_FLAG_80);
item->setFlag(ACTOR_FLAG_40);
item->priorityLayer = 6;
}
}
}
2019-05-02 22:12:04 +10:00
void Inventory::animateBagIn() {
_vm->clearFlags(ENGINE_FLAG_8);
_vm->setFlags(ENGINE_FLAG_80);
Common::Point pos = _bag->getPosition();
pos.y = -228;
int16 accel = 8;
while (pos.y < 0) {
pos.y += accel;
_bag->updatePosition(pos);
_vm->waitForFrames(1);
accel += 2;
}
_vm->playSound(0x8001);
// TODO wait here
pos.y = 0;
_bag->updatePosition(pos);
_vm->setFlags(ENGINE_FLAG_8);
_vm->setFlags(ENGINE_FLAG_10);
}
void Inventory::animateBagOut() {
_vm->playSound(0x8000);
Common::Point pos = _bag->getPosition();
if (pos.y != 0xc8) {
for (;pos.y != 0xc8; pos.y += 0x19) {
_bag->updatePosition(pos);
_vm->waitForFrames(1);
}
}
_vm->clearFlags(ENGINE_FLAG_80);
}
void Inventory::closeInventory() {
_vm->_actorManager->clearActorFlags(0x17);
_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(_vm->getCurrentSceneId());
if (!_vm->isFlagSet(ENGINE_FLAG_400000)) {
_sequenceId = 0;
}
else {
if (_old_showing_value == 2) {
_sequenceId = 3;
}
else {
_sequenceId = 1;
}
}
_actor->updateSequence(_sequenceId);
_actor->x_pos = positionTable[_screenPositionIndex].x;
if (((_sequenceId == 0) || (_sequenceId == 2)) && ((_screenPositionIndex == 1 || (_screenPositionIndex == 3)))) {
_actor->x_pos += 0x32;
}
_actor->y_pos = positionTable[_screenPositionIndex].y;
animateBagOut();
}
void Inventory::draw() {
if(_bag) {
_bag->draw();
}
}
} // End of namespace Dragons