2016-10-03 11:24:13 +02:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-09-15 20:26:46 +02:00
|
|
|
#include "bladerunner/items.h"
|
|
|
|
|
2018-02-13 23:08:37 +01:00
|
|
|
#include "bladerunner/game_constants.h"
|
2016-10-02 00:20:56 +02:00
|
|
|
#include "bladerunner/scene.h"
|
|
|
|
#include "bladerunner/scene_objects.h"
|
2017-03-28 17:50:04 +02:00
|
|
|
#include "bladerunner/zbuffer.h"
|
2016-10-02 00:20:56 +02:00
|
|
|
|
2015-09-15 20:26:46 +02:00
|
|
|
namespace BladeRunner {
|
|
|
|
|
|
|
|
Items::Items(BladeRunnerEngine *vm) {
|
|
|
|
_vm = vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
Items::~Items() {
|
2016-10-12 23:00:33 +02:00
|
|
|
for (int i = _items.size() - 1; i >= 0; i--) {
|
2016-10-02 00:20:56 +02:00
|
|
|
delete _items.remove_at(i);
|
|
|
|
}
|
2015-09-15 20:26:46 +02:00
|
|
|
}
|
|
|
|
|
2018-01-14 12:12:06 +01:00
|
|
|
void Items::getXYZ(int itemId, float *x, float *y, float *z) const {
|
2015-09-15 20:26:46 +02:00
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
assert(itemIndex != -1);
|
|
|
|
|
2016-10-02 00:20:56 +02:00
|
|
|
_items[itemIndex]->getXYZ(x, y, z);
|
|
|
|
}
|
|
|
|
|
2018-03-24 10:46:45 +01:00
|
|
|
void Items::setXYZ(int itemId, Vector3 position) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
assert(itemIndex != -1);
|
|
|
|
|
|
|
|
_items[itemIndex]->setXYZ(position);
|
|
|
|
}
|
|
|
|
|
2018-01-14 12:12:06 +01:00
|
|
|
void Items::getWidthHeight(int itemId, int *width, int *height) const {
|
2016-10-04 02:21:08 +02:00
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
assert(itemIndex != -1);
|
|
|
|
|
|
|
|
_items[itemIndex]->getWidthHeight(width, height);
|
|
|
|
}
|
|
|
|
|
2016-10-02 00:20:56 +02:00
|
|
|
void Items::tick() {
|
|
|
|
int setId = _vm->_scene->getSetId();
|
2016-10-12 23:00:33 +02:00
|
|
|
for (int i = 0; i < (int)_items.size(); i++) {
|
|
|
|
if (_items[i]->_setId != setId) {
|
2016-10-02 00:20:56 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-02-18 22:18:41 +01:00
|
|
|
bool notPoliceMazeTarget = setId == kSetPS10_PS11_PS12_PS13 && !_items[i]->isTarget();
|
2017-03-28 17:50:04 +02:00
|
|
|
Common::Rect screenRect;
|
2018-02-18 22:18:41 +01:00
|
|
|
if (_items[i]->tick(&screenRect, notPoliceMazeTarget)) {
|
2017-03-28 17:50:04 +02:00
|
|
|
_vm->_zbuffer->mark(screenRect);
|
|
|
|
}
|
2016-10-02 00:20:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 22:55:04 +01:00
|
|
|
bool Items::addToWorld(int itemId, int animationId, int setId, Vector3 position, int facing, int height, int width, bool isTargetFlag, bool isVisible, bool isPoliceMazeEnemy, bool addToSetFlag) {
|
2016-10-02 00:20:56 +02:00
|
|
|
if (_items.size() >= 100) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-02 02:47:12 +02:00
|
|
|
int itemIndex = findItem(itemId);
|
2016-10-12 23:00:33 +02:00
|
|
|
if (itemIndex == -1) {
|
2016-10-02 02:47:12 +02:00
|
|
|
itemIndex = _items.size();
|
2018-02-25 19:31:52 +01:00
|
|
|
_items.push_back(new Item(_vm));
|
2016-10-02 00:20:56 +02:00
|
|
|
}
|
|
|
|
|
2018-02-25 19:31:52 +01:00
|
|
|
Item *item = _items[itemIndex];
|
2018-02-18 22:55:04 +01:00
|
|
|
item->setup(itemId, setId, animationId, position, facing, height, width, isTargetFlag, isVisible, isPoliceMazeEnemy);
|
2016-10-02 00:20:56 +02:00
|
|
|
|
2018-02-18 22:44:28 +01:00
|
|
|
if (addToSetFlag && setId == _vm->_scene->getSetId()) {
|
2018-02-18 22:55:04 +01:00
|
|
|
return _vm->_sceneObjects->addItem(itemId + kSceneObjectOffsetItems, &item->_boundingBox, &item->_screenRectangle, isTargetFlag, isVisible);
|
2016-10-02 00:20:56 +02:00
|
|
|
}
|
|
|
|
return true;
|
2015-09-15 20:26:46 +02:00
|
|
|
}
|
|
|
|
|
2016-10-12 23:00:33 +02:00
|
|
|
bool Items::addToSet(int setId) {
|
2018-02-25 19:31:52 +01:00
|
|
|
int itemCount = _items.size();
|
2018-01-14 12:12:06 +01:00
|
|
|
if (itemCount == 0) {
|
2016-10-12 23:00:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-01-14 12:12:06 +01:00
|
|
|
for (int i = 0; i < itemCount; i++) {
|
2018-02-25 19:31:52 +01:00
|
|
|
Item *item = _items[i];
|
2016-10-12 23:00:33 +02:00
|
|
|
if (item->_setId == setId) {
|
2018-02-18 22:18:41 +01:00
|
|
|
_vm->_sceneObjects->addItem(item->_itemId + kSceneObjectOffsetItems, &item->_boundingBox, &item->_screenRectangle, item->isTarget(), item->_isVisible);
|
2016-10-12 23:00:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-02 02:47:12 +02:00
|
|
|
bool Items::remove(int itemId) {
|
|
|
|
if (_items.size() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int itemIndex = findItem(itemId);
|
2016-10-12 23:00:33 +02:00
|
|
|
if (itemIndex == -1) {
|
2016-10-02 02:47:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_items[itemIndex]->_setId == _vm->_scene->getSetId()) {
|
2018-01-14 12:12:06 +01:00
|
|
|
_vm->_sceneObjects->remove(itemId + kSceneObjectOffsetItems);
|
2016-10-02 02:47:12 +02:00
|
|
|
}
|
2018-02-25 19:31:52 +01:00
|
|
|
|
|
|
|
delete _items.remove_at(itemIndex);
|
|
|
|
|
2016-10-02 02:47:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-23 22:14:03 +01:00
|
|
|
void Items::setIsTarget(int itemId, bool isTarget) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_items[itemIndex]->setIsTarget(isTarget);
|
|
|
|
_vm->_sceneObjects->setIsTarget(itemId + kSceneObjectOffsetItems, isTarget);
|
|
|
|
}
|
|
|
|
|
2018-02-18 22:18:41 +01:00
|
|
|
bool Items::isTarget(int itemId) const {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return _items[itemIndex]->isTarget();
|
|
|
|
}
|
|
|
|
|
2018-03-23 23:35:49 +01:00
|
|
|
bool Items::isVisible(int itemId) const {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return _items[itemIndex]->isVisible();
|
|
|
|
}
|
|
|
|
|
2018-03-23 22:02:49 +01:00
|
|
|
bool Items::isPoliceMazeEnemy(int itemId) const {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return _items[itemIndex]->isTarget();
|
|
|
|
}
|
|
|
|
|
2018-03-24 10:46:45 +01:00
|
|
|
void Items::setPoliceMazeEnemy(int itemId, bool val) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_items[itemIndex]->setPoliceMazeEnemy(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Items::setIsObstacle(int itemId, bool val) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_items[itemIndex]->setVisible(val);
|
|
|
|
_vm->_sceneObjects->setIsClickable(itemId + kSceneObjectOffsetItems, val);
|
|
|
|
}
|
|
|
|
|
2018-03-23 23:35:49 +01:00
|
|
|
BoundingBox *Items::getBoundingBox(int itemId) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return _items[itemIndex]->getBoundingBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect *Items::getScreenRectangle(int itemId) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return _items[itemIndex]->getScreenRectangle();
|
|
|
|
}
|
|
|
|
|
2018-03-24 10:46:45 +01:00
|
|
|
int Items::getFacing(int itemId) const {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return _items[itemIndex]->getFacing();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Items::setFacing(int itemId, int facing) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_items[itemIndex]->setFacing(facing);
|
|
|
|
}
|
|
|
|
|
2018-03-23 22:02:49 +01:00
|
|
|
void Items::spinInWorld(int itemId) {
|
|
|
|
int itemIndex = findItem(itemId);
|
|
|
|
if (itemIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_items[itemIndex]->spinInWorld();
|
|
|
|
}
|
|
|
|
|
2018-02-18 22:18:41 +01:00
|
|
|
int Items::findTargetUnderMouse(int mouseX, int mouseY) const {
|
|
|
|
int setId = _vm->_scene->getSetId();
|
|
|
|
for (int i = 0 ; i < (int)_items.size(); ++i) {
|
|
|
|
if (_items[i]->_setId == setId && _items[i]->isTarget() && _items[i]->isUnderMouse(mouseX, mouseY)) {
|
|
|
|
return _items[i]->_itemId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-14 12:12:06 +01:00
|
|
|
int Items::findItem(int itemId) const {
|
2016-09-10 18:16:17 +02:00
|
|
|
for (int i = 0; i < (int)_items.size(); i++) {
|
2018-02-18 22:18:41 +01:00
|
|
|
if (_items[i]->_itemId == itemId) {
|
2015-09-15 20:26:46 +02:00
|
|
|
return i;
|
2018-02-18 22:18:41 +01:00
|
|
|
}
|
2015-09-15 20:26:46 +02:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-10 18:16:17 +02:00
|
|
|
|
|
|
|
} // End of namespace BladeRunner
|