2010-10-08 22:30:39 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2014-02-18 01:34:26 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2010-10-08 22:30:39 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/debug.h"
|
|
|
|
|
2010-10-08 22:45:28 +00:00
|
|
|
#include "toon/hotspot.h"
|
|
|
|
#include "toon/tools.h"
|
2010-10-08 22:30:39 +00:00
|
|
|
|
|
|
|
namespace Toon {
|
|
|
|
|
|
|
|
Hotspots::Hotspots(ToonEngine *vm) : _vm(vm) {
|
2010-11-10 06:22:18 +00:00
|
|
|
_items = NULL;
|
2010-10-08 22:30:39 +00:00
|
|
|
_numItems = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-07 21:08:46 +00:00
|
|
|
Hotspots::~Hotspots() {
|
2010-11-10 06:22:18 +00:00
|
|
|
delete[] _items;
|
2010-11-07 21:08:46 +00:00
|
|
|
}
|
2010-10-08 22:30:39 +00:00
|
|
|
|
|
|
|
void Hotspots::load(Common::ReadStream *Stream) {
|
|
|
|
delete[] _items;
|
|
|
|
|
|
|
|
_numItems = Stream->readSint16BE();
|
|
|
|
_items = new HotspotData[_numItems];
|
|
|
|
|
|
|
|
for (int32 i = 0; i < _numItems; i++) {
|
|
|
|
for (int32 a = 0; a < 256; a++)
|
2010-10-09 11:11:26 +00:00
|
|
|
_items[i].setData(a, Stream->readSint16BE());
|
2010-10-08 22:30:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hotspots::save(Common::WriteStream *Stream) {
|
|
|
|
Stream->writeSint16BE(_numItems);
|
|
|
|
|
|
|
|
for (int32 i = 0; i < _numItems; i++) {
|
|
|
|
for (int32 a = 0; a < 256; a++)
|
|
|
|
Stream->writeSint16BE(_items[i].getData(a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:21:21 +00:00
|
|
|
int32 Hotspots::FindBasedOnCorner(int16 x, int16 y) {
|
2010-10-08 22:30:39 +00:00
|
|
|
debugC(1, kDebugHotspot, "FindBasedOnCorner(%d, %d)", x, y);
|
|
|
|
|
|
|
|
for (int32 i = 0; i < _numItems; i++) {
|
|
|
|
if (x == _items[i].getX1()) {
|
|
|
|
if (y == _items[i].getY1()) {
|
|
|
|
if (_items[i].getMode() == -1)
|
|
|
|
return _items[i].getRef();
|
|
|
|
|
2010-10-12 04:19:58 +00:00
|
|
|
return i;
|
2010-10-08 22:30:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:21:21 +00:00
|
|
|
int32 Hotspots::Find(int16 x, int16 y) {
|
2010-10-08 22:30:39 +00:00
|
|
|
debugC(6, kDebugHotspot, "Find(%d, %d)", x, y);
|
|
|
|
|
|
|
|
int32 priority = -1;
|
|
|
|
int32 foundId = -1;
|
|
|
|
int32 testId = -1;
|
|
|
|
|
|
|
|
for (int i = 0; i < _numItems; i++) {
|
|
|
|
if (x >= _items[i].getX1() && x <= _items[i].getX2() && y >= _items[i].getY1() && y <= _items[i].getY2()) {
|
|
|
|
if (_items[i].getMode() == -1)
|
|
|
|
testId = _items[i].getRef();
|
|
|
|
else
|
|
|
|
testId = i;
|
|
|
|
|
|
|
|
if (_items[testId].getPriority() > priority) {
|
|
|
|
foundId = testId;
|
|
|
|
priority = _items[testId].getPriority();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundId;
|
|
|
|
}
|
|
|
|
|
2011-11-26 21:26:47 +00:00
|
|
|
bool Hotspots::LoadRif(const Common::String &rifName, const Common::String &additionalRifName) {
|
2010-10-08 22:30:39 +00:00
|
|
|
debugC(1, kDebugHotspot, "LoadRif(%s, %s)", rifName.c_str(), additionalRifName.c_str());
|
|
|
|
|
|
|
|
uint32 size = 0;
|
|
|
|
uint8 *rifData = _vm->resources()->getFileData(rifName, &size);
|
2010-10-09 11:11:26 +00:00
|
|
|
if (!rifData)
|
2010-10-08 22:30:39 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
uint32 size2 = 0;
|
|
|
|
uint8 *rifData2 = 0;
|
|
|
|
if (additionalRifName.size())
|
|
|
|
rifData2 = _vm->resources()->getFileData(additionalRifName, &size2);
|
|
|
|
|
|
|
|
// figure out the number of hotspots based on file size
|
|
|
|
int32 rifsize = READ_BE_UINT32(&rifData[4]);
|
|
|
|
int32 rifsize2 = 0;
|
|
|
|
|
|
|
|
if (size2)
|
|
|
|
rifsize2 = READ_BE_UINT32(&rifData2[4]);
|
|
|
|
|
|
|
|
_numItems = (rifsize + rifsize2) / 512;
|
|
|
|
|
2010-11-10 06:22:18 +00:00
|
|
|
delete[] _items;
|
2010-10-08 22:30:39 +00:00
|
|
|
_items = new HotspotData[_numItems];
|
|
|
|
|
|
|
|
// RIFs are compressed in RNC1
|
|
|
|
RncDecoder decoder;
|
2011-04-06 21:07:11 +00:00
|
|
|
decoder.unpackM1(rifData, size, _items);
|
2010-10-08 22:30:39 +00:00
|
|
|
if (rifsize2) {
|
|
|
|
RncDecoder decoder2;
|
2011-04-09 17:07:20 +00:00
|
|
|
decoder2.unpackM1(rifData2 , size2, _items + (rifsize >> 9));
|
2010-10-08 22:30:39 +00:00
|
|
|
for (int32 i = 0; i < (rifsize2 >> 9); i++) {
|
|
|
|
HotspotData *hot = _items + (rifsize >> 9) + i;
|
|
|
|
hot->setData(0, hot->getX1() + 1280);
|
|
|
|
hot->setData(2, hot->getX2() + 1280);
|
|
|
|
if (hot->getMode() == -1)
|
|
|
|
hot->setData(5, hot->getRef() + (rifsize >> 9));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
HotspotData *Hotspots::Get(int32 id) {
|
|
|
|
debugC(5, kDebugHotspot, "Get(%d)", id);
|
|
|
|
|
|
|
|
if (id < 0 || id >= _numItems)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return &_items[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Toon
|