2007-06-22 12:36:04 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-02-11 12:54:56 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-02-11 12:54:56 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lure/room.h"
|
|
|
|
#include "lure/luredefs.h"
|
|
|
|
#include "lure/res.h"
|
|
|
|
#include "lure/screen.h"
|
2007-07-26 10:11:31 +00:00
|
|
|
#include "lure/game.h"
|
2007-12-02 08:32:21 +00:00
|
|
|
#include "lure/lure.h"
|
2006-02-11 12:54:56 +00:00
|
|
|
#include "lure/events.h"
|
|
|
|
#include "lure/strings.h"
|
|
|
|
#include "lure/scripts.h"
|
2007-11-12 10:09:33 +00:00
|
|
|
#include "lure/sound.h"
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
namespace Lure {
|
|
|
|
|
|
|
|
static Room *int_room;
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
RoomLayer::RoomLayer(uint16 screenId, bool backgroundLayer):
|
2006-02-11 12:54:56 +00:00
|
|
|
Surface(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT) {
|
2008-01-02 03:36:19 +00:00
|
|
|
Disk &disk = Disk::getReference();
|
2006-02-11 12:54:56 +00:00
|
|
|
byte *screenData = data().data();
|
2006-03-09 13:54:36 +00:00
|
|
|
int cellY;
|
2007-11-14 11:46:55 +00:00
|
|
|
int cellIndex = 0;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2007-10-20 22:35:23 +00:00
|
|
|
// Reset all the cells to unused
|
2007-11-14 11:46:55 +00:00
|
|
|
Common::set_to((uint8 *) _cells, (uint8 *) _cells + GRID_SIZE, 0xff);
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2008-01-02 03:36:19 +00:00
|
|
|
// Load up the screen data
|
|
|
|
MemoryBlock *rawData = disk.getEntry(screenId);
|
|
|
|
loadScreen(rawData);
|
|
|
|
|
|
|
|
uint16 v = READ_BE_UINT16(rawData->data());
|
|
|
|
bool is5Bit = (v & 0xfffe) == 0x140;
|
|
|
|
delete rawData;
|
|
|
|
|
|
|
|
_paletteId = (screenId & 0xffe0) - 1;
|
|
|
|
if (is5Bit) {
|
|
|
|
uint16 roomNumber = Room::getReference().roomNumber();
|
|
|
|
|
|
|
|
if (roomNumber == 6)
|
|
|
|
_paletteId = 0x45ff;
|
|
|
|
else if (roomNumber == 49)
|
|
|
|
_paletteId = 0xf1ff;
|
|
|
|
else {
|
|
|
|
_paletteId = 0x40ff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
// Loop through each cell of the screen
|
2006-03-09 13:54:36 +00:00
|
|
|
for (cellY = 0; cellY < NUM_VERT_RECTS; ++cellY) {
|
2006-02-11 12:54:56 +00:00
|
|
|
for (int cellX = 0; cellX < NUM_HORIZ_RECTS; ++cellX) {
|
|
|
|
bool hasPixels = false;
|
|
|
|
|
|
|
|
if (backgroundLayer) {
|
|
|
|
hasPixels = true;
|
|
|
|
} else {
|
|
|
|
// Check the cell
|
|
|
|
for (int yP = 0; yP < RECT_SIZE; ++yP) {
|
|
|
|
if (hasPixels) break;
|
2008-01-27 19:47:41 +00:00
|
|
|
byte *linePos = screenData + (cellY * RECT_SIZE + yP + MENUBAR_Y_SIZE)
|
2006-02-11 12:54:56 +00:00
|
|
|
* FULL_SCREEN_WIDTH + (cellX * RECT_SIZE);
|
|
|
|
|
|
|
|
for (int xP = 0; xP < RECT_SIZE; ++xP) {
|
|
|
|
hasPixels = *linePos++ != 0;
|
|
|
|
if (hasPixels) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
_cells[cellY + NUM_EDGE_RECTS][cellX + NUM_EDGE_RECTS] =
|
2007-11-14 11:46:55 +00:00
|
|
|
hasPixels ? cellIndex++ : 0xff;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
Room::Room(): _screen(Screen::getReference()) {
|
|
|
|
int_room = this;
|
|
|
|
|
|
|
|
_roomData = NULL;
|
2006-02-19 04:13:08 +00:00
|
|
|
_talkDialog = NULL;
|
2006-03-13 11:52:16 +00:00
|
|
|
_hotspotId = 0;
|
2006-02-11 12:54:56 +00:00
|
|
|
_hotspotName[0] = '\0';
|
2006-07-08 08:29:01 +00:00
|
|
|
_statusLine[0] = '\0';
|
2006-02-11 12:54:56 +00:00
|
|
|
for (int ctr = 0; ctr < MAX_NUM_LAYERS; ++ctr) _layers[ctr] = NULL;
|
|
|
|
_numLayers = 0;
|
|
|
|
_showInfo = false;
|
2006-02-19 04:13:08 +00:00
|
|
|
_isExit = false;
|
2007-11-17 00:19:45 +00:00
|
|
|
_roomNumber = 0;
|
2006-04-11 10:50:18 +00:00
|
|
|
_destRoomNumber = 0;
|
2006-05-23 12:36:57 +00:00
|
|
|
_cursorState = CS_NONE;
|
|
|
|
|
2006-04-29 11:19:55 +00:00
|
|
|
//****DEBUG****
|
|
|
|
memset(tempLayer, 0, DECODED_PATHS_WIDTH * DECODED_PATHS_HEIGHT * 2);
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Room::~Room() {
|
|
|
|
for (int layerNum = 0; layerNum < _numLayers; ++layerNum)
|
|
|
|
if (_layers[layerNum])
|
|
|
|
delete _layers[layerNum];
|
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
if (_talkDialog) delete _talkDialog;
|
2006-02-11 12:54:56 +00:00
|
|
|
int_room = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Room &Room::getReference() {
|
|
|
|
return *int_room;
|
|
|
|
}
|
|
|
|
|
|
|
|
// leaveRoom
|
|
|
|
// Handles leaving the current room
|
|
|
|
|
|
|
|
void Room::leaveRoom() {
|
|
|
|
Resources &r = Resources::getReference();
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
// Scan through the hotspot list and remove any uneeded entries
|
2006-07-08 08:29:01 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
HotspotList &list = r.activeHotspots();
|
|
|
|
HotspotList::iterator i = list.begin();
|
|
|
|
while (i != list.end()) {
|
2008-04-06 12:00:37 +00:00
|
|
|
Hotspot *h = (i.operator*()).get();
|
2006-02-11 12:54:56 +00:00
|
|
|
if (!h->persistant()) {
|
|
|
|
i = list.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::loadRoomHotspots() {
|
|
|
|
Resources &r = Resources::getReference();
|
|
|
|
HotspotDataList &list = r.hotspotData();
|
|
|
|
|
|
|
|
HotspotDataList::iterator i;
|
|
|
|
for (i = list.begin(); i != list.end(); ++i) {
|
2008-04-06 12:00:37 +00:00
|
|
|
HotspotData *rec = (*i).get();
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
if ((rec->hotspotId < 0x7530) && (rec->roomNumber == _roomNumber) &&
|
2006-02-11 12:54:56 +00:00
|
|
|
(rec->layer != 0))
|
|
|
|
r.activateHotspot(rec->hotspotId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::checkRoomHotspots() {
|
2006-07-08 08:29:01 +00:00
|
|
|
uint16 rangeStart[4] = {0x408, 0x3e8, 0x7530, 0x2710};
|
|
|
|
uint16 rangeEnd[4] = {0x270f, 0x407, 0xffff, 0x752f};
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
Mouse &m = Mouse::getReference();
|
2006-02-19 04:13:08 +00:00
|
|
|
Resources &res = Resources::getReference();
|
|
|
|
HotspotDataList &list = res.hotspotData();
|
2006-02-11 12:54:56 +00:00
|
|
|
HotspotData *entry = NULL;
|
|
|
|
int16 currentX = m.x();
|
|
|
|
int16 currentY = m.y();
|
|
|
|
HotspotDataList::iterator i;
|
|
|
|
|
2007-12-16 09:36:07 +00:00
|
|
|
_destRoomNumber = 0;
|
|
|
|
|
2006-07-08 08:29:01 +00:00
|
|
|
// Loop for each range of hotspot Ids
|
|
|
|
for (int ctr = 0; ctr < 4; ++ctr) {
|
|
|
|
for (i = list.begin(); i != list.end(); ++i) {
|
2008-04-06 12:00:37 +00:00
|
|
|
entry = (*i).get();
|
2006-07-08 08:29:01 +00:00
|
|
|
if ((entry->hotspotId < rangeStart[ctr]) || (entry->hotspotId > rangeEnd[ctr]))
|
|
|
|
// Hotspot outside range, so skip it
|
|
|
|
continue;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2006-07-08 08:29:01 +00:00
|
|
|
bool skipFlag = (entry->roomNumber != _roomNumber);
|
|
|
|
if (!skipFlag) {
|
2008-01-27 19:47:41 +00:00
|
|
|
skipFlag = (((entry->flags & HOTSPOTFLAG_FOUND) == 0) &&
|
2006-07-30 12:12:18 +00:00
|
|
|
((entry->flags & HOTSPOTFLAG_SKIP) != 0)) ||
|
2007-06-22 12:36:04 +00:00
|
|
|
((entry->flags & HOTSPOTFLAG_MENU_EXCLUSION) != 0);
|
2006-07-08 08:29:01 +00:00
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2006-07-08 08:29:01 +00:00
|
|
|
if ((!skipFlag) && (entry->hotspotId < 0x409))
|
|
|
|
// For character hotspots, validate they're in clipping range
|
|
|
|
skipFlag = !res.checkHotspotExtent(entry);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-07-08 08:29:01 +00:00
|
|
|
if (!skipFlag && (entry->hotspotId >= 0x2710) && (entry->hotspotId <= 0x27ff)) {
|
|
|
|
RoomExitJoinData *rec = res.getExitJoin(entry->hotspotId);
|
|
|
|
if ((rec) && (!rec->blocked))
|
2008-01-27 19:47:41 +00:00
|
|
|
// Hotspot is over a room exit, and it's not blocked, so don't
|
2006-07-08 08:29:01 +00:00
|
|
|
// register it as an active hotspot
|
|
|
|
skipFlag = true;
|
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2006-07-08 08:29:01 +00:00
|
|
|
if (!skipFlag) {
|
|
|
|
// Check for a hotspot override
|
|
|
|
HotspotOverrideData *hsEntry = res.getHotspotOverride(entry->hotspotId);
|
|
|
|
|
|
|
|
if (hsEntry) {
|
|
|
|
// Check whether cursor is in override hotspot area
|
|
|
|
if ((currentX >= hsEntry->xs) && (currentX <= hsEntry->xe) &&
|
|
|
|
(currentY >= hsEntry->ys) && (currentY <= hsEntry->ye))
|
|
|
|
// Found to be in hotspot entry
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// Check whether cursor is in default hospot area
|
|
|
|
if ((currentX >= entry->startX) && (currentY >= entry->startY) &&
|
2008-01-27 19:47:41 +00:00
|
|
|
(currentX < entry->startX + entry->widthCopy) &&
|
|
|
|
(currentY < entry->startY + entry->height))
|
2006-07-08 08:29:01 +00:00
|
|
|
// Found hotspot entry
|
|
|
|
break;
|
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-08 08:29:01 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
if (i != list.end())
|
2006-07-08 08:29:01 +00:00
|
|
|
break;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == list.end()) {
|
|
|
|
_hotspotId = 0;
|
|
|
|
_hotspotNameId = 0;
|
|
|
|
_hotspot = NULL;
|
|
|
|
} else {
|
|
|
|
_hotspotNameId = entry->nameId;
|
|
|
|
_hotspot = entry;
|
|
|
|
_hotspotId = entry->hotspotId;
|
2006-02-19 04:13:08 +00:00
|
|
|
_isExit = false;
|
2006-09-03 05:03:50 +00:00
|
|
|
entry->flags |= HOTSPOTFLAG_FOUND;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-22 12:36:04 +00:00
|
|
|
CursorType Room::checkRoomExits() {
|
2006-02-11 12:54:56 +00:00
|
|
|
Mouse &m = Mouse::getReference();
|
2006-02-19 04:13:08 +00:00
|
|
|
Resources &res = Resources::getReference();
|
2006-04-29 11:19:55 +00:00
|
|
|
_destRoomNumber = 0;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
RoomExitHotspotList &exits = _roomData->exitHotspots;
|
2006-03-28 09:42:54 +00:00
|
|
|
if (exits.empty()) return CURSOR_ARROW;
|
2006-02-11 12:54:56 +00:00
|
|
|
RoomExitJoinData *join;
|
|
|
|
bool skipFlag;
|
|
|
|
|
|
|
|
RoomExitHotspotList::iterator i;
|
|
|
|
for (i = exits.begin(); i != exits.end(); ++i) {
|
2008-04-06 12:00:37 +00:00
|
|
|
RoomExitHotspotData *rec = (*i).get();
|
2006-02-11 12:54:56 +00:00
|
|
|
skipFlag = false;
|
|
|
|
|
|
|
|
if (rec->hotspotId != 0) {
|
2006-02-19 04:13:08 +00:00
|
|
|
join = res.getExitJoin(rec->hotspotId);
|
2006-02-11 12:54:56 +00:00
|
|
|
if ((join) && (join->blocked != 0))
|
|
|
|
skipFlag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!skipFlag && (m.x() >= rec->xs) && (m.x() <= rec->xe) &&
|
|
|
|
(m.y() >= rec->ys) && (m.y() <= rec->ye)) {
|
|
|
|
// Cursor is within exit area
|
2007-06-22 12:36:04 +00:00
|
|
|
CursorType cursorNum = (CursorType)rec->cursorNum;
|
2006-04-11 10:50:18 +00:00
|
|
|
_destRoomNumber = rec->destRoomNumber;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
// If it's a hotspotted exit, change arrow to the + arrow
|
2006-02-19 04:13:08 +00:00
|
|
|
if (rec->hotspotId != 0) {
|
|
|
|
_hotspotId = rec->hotspotId;
|
|
|
|
_hotspot = res.getHotspot(_hotspotId);
|
|
|
|
_hotspotNameId = _hotspot->nameId;
|
|
|
|
_isExit = true;
|
2007-06-22 12:36:04 +00:00
|
|
|
cursorNum = (CursorType)((int)cursorNum + 7);
|
2006-02-19 04:13:08 +00:00
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
return cursorNum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No room exits found
|
|
|
|
return CURSOR_ARROW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::addAnimation(Hotspot &h) {
|
|
|
|
Surface &s = _screen.screen();
|
|
|
|
char buffer[10];
|
|
|
|
h.copyTo(&s);
|
|
|
|
|
|
|
|
if (_showInfo) {
|
|
|
|
int16 x = h.x();
|
|
|
|
int16 y = h.y();
|
2008-01-27 19:47:41 +00:00
|
|
|
if ((x >= 0) && (x < FULL_SCREEN_WIDTH) && (y >= 0) && (y < FULL_SCREEN_HEIGHT))
|
2006-07-08 08:29:01 +00:00
|
|
|
sprintf(buffer, "%xh", h.hotspotId());
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::addLayers(Hotspot &h) {
|
2007-10-20 22:35:23 +00:00
|
|
|
int16 hsX = h.x() + (NUM_EDGE_RECTS * RECT_SIZE);
|
|
|
|
int16 hsY = h.y() + (NUM_EDGE_RECTS * RECT_SIZE) - MENUBAR_Y_SIZE;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
int16 xStart = hsX / RECT_SIZE;
|
|
|
|
int16 xEnd = (hsX + h.width()) / RECT_SIZE;
|
|
|
|
int16 numX = xEnd - xStart + 1;
|
|
|
|
int16 yStart = hsY / RECT_SIZE;
|
2006-02-21 09:25:39 +00:00
|
|
|
int16 yEnd = (hsY + h.heightCopy() - 1) / RECT_SIZE;
|
2006-02-11 12:54:56 +00:00
|
|
|
int16 numY = yEnd - yStart + 1;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-06-22 12:36:04 +00:00
|
|
|
if ((xStart < 0) || (yEnd < 0))
|
|
|
|
return;
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
for (int16 xCtr = 0; xCtr < numX; ++xCtr, ++xStart) {
|
2007-10-20 22:35:23 +00:00
|
|
|
int16 xs = xStart - NUM_EDGE_RECTS;
|
2006-02-11 12:54:56 +00:00
|
|
|
if (xs < 0) continue;
|
|
|
|
|
|
|
|
// Check foreground layers for an occupied one
|
2006-02-21 09:25:39 +00:00
|
|
|
|
2007-10-20 22:35:23 +00:00
|
|
|
int layerNum = 1;
|
|
|
|
while ((layerNum < 4) && (_layers[layerNum] != NULL) &&
|
2007-11-14 11:46:55 +00:00
|
|
|
(_layers[layerNum]->getCell(xStart, yEnd) == 0xff))
|
2007-10-20 22:35:23 +00:00
|
|
|
++layerNum;
|
|
|
|
if ((layerNum == 4) || (_layers[layerNum] == NULL)) continue;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2007-10-20 22:35:23 +00:00
|
|
|
int16 ye = yEnd - NUM_EDGE_RECTS;
|
2006-02-11 12:54:56 +00:00
|
|
|
for (int16 yCtr = 0; yCtr < numY; ++yCtr, --ye) {
|
|
|
|
if (ye < 0) break;
|
|
|
|
addCell(xs, ye, layerNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::addCell(int16 xp, int16 yp, int layerNum) {
|
|
|
|
Surface &s = _screen.screen();
|
|
|
|
|
2007-10-20 22:35:23 +00:00
|
|
|
while ((layerNum < 4) && (_layers[layerNum] != NULL) &&
|
2007-11-14 11:46:55 +00:00
|
|
|
(_layers[layerNum]->getCell(xp + NUM_EDGE_RECTS, yp + NUM_EDGE_RECTS) >= 0xfe))
|
2007-10-20 22:35:23 +00:00
|
|
|
++layerNum;
|
|
|
|
if ((layerNum == 4) || (_layers[layerNum] == NULL)) return;
|
2006-02-21 09:25:39 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
RoomLayer *layer = _layers[layerNum];
|
|
|
|
|
2007-10-20 22:35:23 +00:00
|
|
|
int index = ((yp * RECT_SIZE + MENUBAR_Y_SIZE) * FULL_SCREEN_WIDTH) + (xp * RECT_SIZE);
|
2006-02-11 12:54:56 +00:00
|
|
|
byte *srcPos = layer->data().data() + index;
|
|
|
|
byte *destPos = s.data().data() + index;
|
|
|
|
|
|
|
|
for (int yCtr = 0; yCtr < RECT_SIZE; ++yCtr) {
|
|
|
|
for (int xCtr = 0; xCtr < RECT_SIZE; ++xCtr, ++destPos) {
|
|
|
|
byte pixel = *srcPos++;
|
|
|
|
if (pixel) *destPos = pixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to start of next cell line
|
|
|
|
srcPos += FULL_SCREEN_WIDTH - RECT_SIZE;
|
|
|
|
destPos += FULL_SCREEN_WIDTH - RECT_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-20 22:35:23 +00:00
|
|
|
void Room::blockMerge() {
|
|
|
|
for (int layerNum1 = 0; layerNum1 < 3; ++layerNum1) {
|
|
|
|
if (_layers[layerNum1] == NULL) break;
|
|
|
|
|
|
|
|
for (int layerNum2 = layerNum1 + 1; layerNum2 < 4; ++layerNum2) {
|
|
|
|
if (_layers[layerNum2] == NULL) break;
|
|
|
|
|
|
|
|
for (int yp = 0; yp < NUM_VERT_RECTS; ++yp) {
|
|
|
|
for (int xp = 0; xp < NUM_HORIZ_RECTS; ++xp) {
|
|
|
|
if (_layers[layerNum1]->isOccupied(xp + NUM_EDGE_RECTS, yp + NUM_EDGE_RECTS) &&
|
|
|
|
_layers[layerNum2]->isOccupied(xp + NUM_EDGE_RECTS, yp + NUM_EDGE_RECTS)) {
|
|
|
|
// Copy the rect from the later layer onto the earlier layer
|
|
|
|
int offset = (yp * RECT_SIZE + MENUBAR_Y_SIZE) * FULL_SCREEN_WIDTH + (xp * RECT_SIZE);
|
|
|
|
byte *src = _layers[layerNum2]->data().data() + offset;
|
|
|
|
byte *dest = _layers[layerNum1]->data().data() + offset;
|
|
|
|
|
|
|
|
for (int y = 0; y < RECT_SIZE; ++y) {
|
|
|
|
for (int x = 0; x < RECT_SIZE; ++x, ++src, ++dest) {
|
|
|
|
if (*src != 0) *dest = *src;
|
|
|
|
}
|
|
|
|
src += FULL_SCREEN_WIDTH - RECT_SIZE;
|
|
|
|
dest += FULL_SCREEN_WIDTH - RECT_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-20 22:35:23 +00:00
|
|
|
}
|
|
|
|
|
2007-11-14 11:46:55 +00:00
|
|
|
void Room::layersPostProcess() {
|
|
|
|
for (int layerNum = 1; layerNum < 4; ++layerNum) {
|
|
|
|
if (_layers[layerNum] == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Layer optimisation
|
|
|
|
for (int xp = NUM_EDGE_RECTS; xp < NUM_HORIZ_RECTS + NUM_EDGE_RECTS; ++xp) {
|
|
|
|
bool priorFlag = false, nextFlag = false;
|
|
|
|
|
|
|
|
for (int yp = NUM_EDGE_RECTS; yp < NUM_VERT_RECTS + NUM_EDGE_RECTS; ++yp) {
|
|
|
|
if (_layers[layerNum]->getCell(xp, yp) == 0xff) {
|
|
|
|
priorFlag = false;
|
|
|
|
nextFlag = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priorFlag && (_layers[layerNum]->getCell(xp - 1, yp) == 0xff))
|
|
|
|
_layers[layerNum]->setCell(xp - 1, yp, 0xfe);
|
|
|
|
if (nextFlag && (_layers[layerNum]->getCell(xp + 1, yp) == 0xff))
|
|
|
|
_layers[layerNum]->setCell(xp + 1, yp, 0xfe);
|
|
|
|
|
|
|
|
priorFlag = _layers[layerNum]->getCell(xp - 1, yp) != 0xff;
|
|
|
|
nextFlag = _layers[layerNum]->getCell(xp + 1, yp) != 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layer extension of final row to off-screen edge rows below
|
|
|
|
|
|
|
|
for (int xp = NUM_EDGE_RECTS + NUM_HORIZ_RECTS - 1; xp >= NUM_EDGE_RECTS; --xp) {
|
|
|
|
if (_layers[layerNum]->getCell(xp, NUM_EDGE_RECTS + NUM_VERT_RECTS - 1) != 0xff) {
|
|
|
|
for (int yp = NUM_VERT_RECTS + NUM_EDGE_RECTS; yp < FULL_VERT_RECTS; ++yp)
|
|
|
|
_layers[layerNum]->setCell(xp, yp, 0xfe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
void Room::update() {
|
|
|
|
Surface &s = _screen.screen();
|
2006-02-19 04:13:08 +00:00
|
|
|
Resources &res = Resources::getReference();
|
|
|
|
HotspotList &hotspots = res.activeHotspots();
|
2008-01-05 10:36:36 +00:00
|
|
|
byte white = LureEngine::getReference().isEGA() ? EGA_DIALOG_WHITE_COLOUR : VGA_DIALOG_WHITE_COLOUR;
|
2006-02-11 12:54:56 +00:00
|
|
|
HotspotList::iterator i;
|
|
|
|
|
2007-10-20 22:35:23 +00:00
|
|
|
// Copy the background to the temporary screen surface
|
2006-02-11 12:54:56 +00:00
|
|
|
_layers[0]->copyTo(&s);
|
|
|
|
|
|
|
|
// Handle first layer (layer 3)
|
|
|
|
for (i = hotspots.begin(); i != hotspots.end(); ++i) {
|
|
|
|
Hotspot &h = *i.operator*();
|
2006-05-23 12:36:57 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
if ((h.roomNumber() == _roomNumber) && h.isActiveAnimation() && (h.layer() == 3)) {
|
|
|
|
addAnimation(h);
|
|
|
|
addLayers(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle second layer (layer 1) - do in order of Y axis
|
|
|
|
List<Hotspot *> tempList;
|
|
|
|
List<Hotspot *>::iterator iTemp;
|
|
|
|
for (i = hotspots.begin(); i != hotspots.end(); ++i) {
|
2008-04-06 12:00:37 +00:00
|
|
|
Hotspot *h = (i.operator*()).get();
|
2008-01-27 19:47:41 +00:00
|
|
|
if ((h->layer() != 1) || (h->roomNumber() != _roomNumber) ||
|
2007-01-31 02:26:16 +00:00
|
|
|
h->skipFlag() || !h->isActiveAnimation())
|
2006-02-11 12:54:56 +00:00
|
|
|
continue;
|
2006-02-21 09:25:39 +00:00
|
|
|
int16 endY = h->y() + h->heightCopy();
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
for (iTemp = tempList.begin(); iTemp != tempList.end(); ++iTemp) {
|
|
|
|
Hotspot *hTemp = iTemp.operator*();
|
2006-02-21 09:25:39 +00:00
|
|
|
int16 tempY = hTemp->y() + hTemp->heightCopy();
|
2008-01-27 19:47:41 +00:00
|
|
|
if (endY < tempY) break;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
tempList.insert(iTemp, h);
|
|
|
|
}
|
|
|
|
for (iTemp = tempList.begin(); iTemp != tempList.end(); ++iTemp) {
|
|
|
|
Hotspot &h = *iTemp.operator*();
|
|
|
|
addAnimation(h);
|
|
|
|
addLayers(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle third layer (layer 2)
|
|
|
|
for (i = hotspots.begin(); i != hotspots.end(); ++i) {
|
|
|
|
Hotspot &h = *i.operator*();
|
2006-05-23 12:36:57 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
if ((h.roomNumber() == _roomNumber) && h.isActiveAnimation() && (h.layer() == 2)) {
|
|
|
|
addAnimation(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
// Show any active talk dialog
|
2006-02-19 04:13:08 +00:00
|
|
|
if (_talkDialog) {
|
2006-07-08 08:29:01 +00:00
|
|
|
// Make sure the character is still active and in the viewing room
|
|
|
|
Hotspot *talkCharacter = res.getActiveHotspot(res.getTalkingCharacter());
|
2008-01-27 19:47:41 +00:00
|
|
|
if ((talkCharacter != NULL) && (talkCharacter->roomNumber() == _roomNumber))
|
2007-10-24 10:09:06 +00:00
|
|
|
_talkDialog->copyTo(&s, _talkDialogX, _talkDialogY);
|
2006-02-19 04:13:08 +00:00
|
|
|
}
|
|
|
|
|
2006-07-08 08:29:01 +00:00
|
|
|
// Handle showing the status line
|
|
|
|
if (!*_statusLine) {
|
|
|
|
// No current status action being display
|
2008-01-27 19:47:41 +00:00
|
|
|
if (_hotspotId != 0)
|
2008-01-05 10:36:36 +00:00
|
|
|
s.writeString(0, 0, _hotspotName, false);
|
2006-07-08 08:29:01 +00:00
|
|
|
} else {
|
2006-08-30 11:48:43 +00:00
|
|
|
// Word wrap (if necessary) the status line and dispaly it
|
|
|
|
char *statusLineCopy = strdup(_statusLine);
|
|
|
|
char **lines;
|
|
|
|
uint8 numLines;
|
|
|
|
int16 yPos = 0;
|
|
|
|
s.wordWrap(statusLineCopy, s.width(), lines, numLines);
|
|
|
|
for (int lineNum = 0; lineNum < numLines; ++lineNum) {
|
2008-01-05 10:36:36 +00:00
|
|
|
s.writeString(0, yPos, lines[lineNum], false, white);
|
2006-08-30 11:48:43 +00:00
|
|
|
yPos += FONT_HEIGHT;
|
|
|
|
}
|
|
|
|
Memory::dealloc(lines);
|
|
|
|
Memory::dealloc(statusLineCopy);
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 12:36:04 +00:00
|
|
|
// Debug - if the bottle object is on layer 0FEh, then display it's surface
|
|
|
|
Hotspot *displayHotspot = res.getActiveHotspot(BOTTLE_HOTSPOT_ID);
|
2008-01-27 19:47:41 +00:00
|
|
|
if ((displayHotspot != NULL) && (displayHotspot->layer() == 0xfe))
|
2007-06-22 12:36:04 +00:00
|
|
|
displayHotspot->frames().copyTo(&s);
|
|
|
|
|
2006-04-11 10:50:18 +00:00
|
|
|
// If show information is turned on, show extra debugging information
|
2006-02-11 12:54:56 +00:00
|
|
|
if (_showInfo) {
|
|
|
|
char buffer[64];
|
2006-04-11 10:50:18 +00:00
|
|
|
|
|
|
|
// Temporary display of pathfinding data
|
|
|
|
for (int yctr = 0; yctr < ROOM_PATHS_HEIGHT; ++yctr) {
|
|
|
|
for (int xctr = 0; xctr < ROOM_PATHS_WIDTH; ++xctr) {
|
2007-01-31 02:26:16 +00:00
|
|
|
/*
|
2008-01-27 19:47:41 +00:00
|
|
|
if (_roomData->paths.isOccupied(xctr, yctr))
|
2006-07-08 08:29:01 +00:00
|
|
|
s.fillRect(Rect(xctr * 8, yctr * 8 + 8, xctr * 8 + 7, yctr * 8 + 15), 255);
|
2007-01-31 02:26:16 +00:00
|
|
|
*/
|
2006-04-11 10:50:18 +00:00
|
|
|
uint16 v = tempLayer[(yctr + 1) * DECODED_PATHS_WIDTH + xctr + 1];
|
|
|
|
if ((v != 0) && (v < 100)) {
|
|
|
|
sprintf(buffer, "%d", v % 10);
|
2006-07-08 08:29:01 +00:00
|
|
|
s.writeString(xctr * 8, yctr * 8 + 8, buffer, true);
|
2006-04-29 11:19:55 +00:00
|
|
|
// } else if (v == 0xffff) {
|
|
|
|
} else if (_roomData->paths.isOccupied(xctr, yctr)) {
|
2006-04-11 10:50:18 +00:00
|
|
|
s.fillRect(Rect(xctr * 8, yctr * 8 + 8, xctr * 8 + 7, yctr * 8 + 15), 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-08 08:29:01 +00:00
|
|
|
|
|
|
|
Mouse &m = Mouse::getReference();
|
2007-10-20 22:35:23 +00:00
|
|
|
sprintf(buffer, "Room %d Pos (%d,%d) @ (%d,%d)", _roomNumber, m.x(), m.y(),
|
|
|
|
m.x() / RECT_SIZE, (m.y() - MENUBAR_Y_SIZE) / RECT_SIZE);
|
2008-01-05 10:36:36 +00:00
|
|
|
s.writeString(FULL_SCREEN_WIDTH / 2, 0, buffer, false, white);
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::setRoomNumber(uint16 newRoomNumber, bool showOverlay) {
|
2007-08-25 06:08:02 +00:00
|
|
|
Resources &res = Resources::getReference();
|
2007-07-26 10:11:31 +00:00
|
|
|
Game &game = Game::getReference();
|
|
|
|
Mouse &mouse = Mouse::getReference();
|
2008-01-02 03:36:19 +00:00
|
|
|
bool isEGA = LureEngine::getReference().isEGA();
|
2007-07-26 10:11:31 +00:00
|
|
|
|
|
|
|
mouse.pushCursorNum(CURSOR_DISK);
|
|
|
|
|
2007-08-25 06:08:02 +00:00
|
|
|
_roomData = res.getRoom(newRoomNumber);
|
2006-02-11 12:54:56 +00:00
|
|
|
if (!_roomData)
|
|
|
|
error("Tried to change to non-existant room: %d", newRoomNumber);
|
2007-11-17 06:53:13 +00:00
|
|
|
|
|
|
|
bool fadeFlag = (newRoomNumber != _roomNumber) && (_roomNumber != 0);
|
|
|
|
bool leaveFlag = _roomNumber != 999;
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
_roomNumber = _roomData->roomNumber;
|
|
|
|
_descId = _roomData->descId;
|
2006-07-08 08:29:01 +00:00
|
|
|
|
2007-11-17 06:53:13 +00:00
|
|
|
if (fadeFlag) {
|
2008-01-05 12:09:24 +00:00
|
|
|
if (isEGA)
|
|
|
|
_screen.setPaletteEmpty();
|
|
|
|
else
|
|
|
|
// Fade out all the colours except the high index 0FFh, which is used to show the
|
|
|
|
// disk cursor as a room changes
|
|
|
|
_screen.paletteFadeOut(GAME_COLOURS - 1);
|
2007-11-12 10:09:33 +00:00
|
|
|
|
2007-11-17 11:03:18 +00:00
|
|
|
// Deallocate graphical layers from the room
|
|
|
|
for (int layerNum = 0; layerNum < _numLayers; ++layerNum) {
|
|
|
|
if (_layers[layerNum]) {
|
|
|
|
delete _layers[layerNum];
|
|
|
|
_layers[layerNum] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-17 06:53:13 +00:00
|
|
|
if (leaveFlag) {
|
|
|
|
leaveRoom();
|
|
|
|
Sound.removeSounds();
|
|
|
|
}
|
2007-07-26 10:11:31 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
_screen.empty();
|
2007-09-23 22:12:37 +00:00
|
|
|
_screen.setPaletteEmpty(RES_PALETTE_ENTRIES);
|
2006-02-11 12:54:56 +00:00
|
|
|
|
|
|
|
_numLayers = _roomData->numLayers;
|
|
|
|
if (showOverlay) ++_numLayers;
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
for (uint8 layerNum = 0; layerNum < _numLayers; ++layerNum)
|
2006-02-11 12:54:56 +00:00
|
|
|
_layers[layerNum] = new RoomLayer(_roomData->layers[layerNum],
|
|
|
|
layerNum == 0);
|
2007-10-20 22:35:23 +00:00
|
|
|
|
|
|
|
blockMerge();
|
2007-11-14 11:46:55 +00:00
|
|
|
layersPostProcess();
|
2007-10-20 22:35:23 +00:00
|
|
|
|
2007-08-25 06:08:02 +00:00
|
|
|
// Generate the palette for the room that will be faded in
|
2008-01-02 03:36:19 +00:00
|
|
|
Palette *p;
|
|
|
|
if (isEGA) {
|
|
|
|
p = new Palette(_layers[0]->paletteId());
|
|
|
|
} else {
|
|
|
|
p = new Palette(GAME_PALETTE_RESOURCE_ID);
|
|
|
|
Palette tempPalette(_layers[0]->paletteId());
|
|
|
|
p->copyFrom(&tempPalette);
|
|
|
|
res.insertPaletteSubset(*p);
|
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2007-02-17 03:42:43 +00:00
|
|
|
// Set the new room number
|
2007-08-25 06:08:02 +00:00
|
|
|
res.fieldList().setField(ROOM_NUMBER, newRoomNumber);
|
2007-02-17 03:42:43 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
if (_roomData->sequenceOffset != 0xffff)
|
|
|
|
Script::execute(_roomData->sequenceOffset);
|
2006-07-08 08:29:01 +00:00
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
loadRoomHotspots();
|
2007-07-26 10:11:31 +00:00
|
|
|
|
2007-12-22 11:34:10 +00:00
|
|
|
if (leaveFlag) {
|
2008-01-27 19:47:41 +00:00
|
|
|
// A previous room has been left - check if there are any seconds worth
|
2007-12-22 11:34:10 +00:00
|
|
|
// of animations that need to be done in 'fast forward'
|
|
|
|
if ((_roomData->exitTime != 0xffff) && (_roomData->exitTime != 0)) {
|
|
|
|
// If time has passed, animation ticks needed before room is displayed
|
|
|
|
int numSeconds = (g_system->getMillis() - _roomData->exitTime) / 1000;
|
|
|
|
if (numSeconds > 300) numSeconds = 300;
|
|
|
|
|
|
|
|
game.preloadFlag() = true;
|
|
|
|
while (numSeconds-- > 0)
|
|
|
|
game.tick();
|
|
|
|
game.preloadFlag() = false;
|
|
|
|
}
|
2007-07-26 10:11:31 +00:00
|
|
|
}
|
|
|
|
|
2007-08-25 06:08:02 +00:00
|
|
|
game.tick();
|
2006-02-11 12:54:56 +00:00
|
|
|
update();
|
2007-07-26 10:11:31 +00:00
|
|
|
_screen.update();
|
2007-10-28 04:27:18 +00:00
|
|
|
|
2008-01-05 12:09:24 +00:00
|
|
|
if (fadeFlag && !isEGA)
|
2008-01-02 03:36:19 +00:00
|
|
|
_screen.paletteFadeIn(p);
|
2007-10-28 04:27:18 +00:00
|
|
|
else
|
2008-01-02 03:36:19 +00:00
|
|
|
_screen.setPalette(p);
|
2007-07-26 10:11:31 +00:00
|
|
|
|
|
|
|
mouse.popCursor();
|
2008-01-02 03:36:19 +00:00
|
|
|
delete p;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
// checkCursor
|
|
|
|
// Called repeatedly to check if any changes to the cursor are required
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
void Room::checkCursor() {
|
|
|
|
Mouse &mouse = Mouse::getReference();
|
|
|
|
Resources &res = Resources::getReference();
|
2006-02-11 12:54:56 +00:00
|
|
|
uint16 oldHotspotId = _hotspotId;
|
2007-06-22 12:36:04 +00:00
|
|
|
CursorType currentCursor = mouse.getCursorNum();
|
|
|
|
CursorType newCursor = currentCursor;
|
2006-04-29 11:19:55 +00:00
|
|
|
CurrentAction playerAction = res.getActiveHotspot(PLAYER_ID)->currentActions().action();
|
2006-07-08 08:29:01 +00:00
|
|
|
uint16 oldRoomNumber = res.fieldList().getField(OLD_ROOM_NUMBER);
|
2006-02-19 04:13:08 +00:00
|
|
|
|
2006-04-29 11:19:55 +00:00
|
|
|
if ((currentCursor >= CURSOR_TIME_START) && (currentCursor <= CURSOR_TIME_END) &&
|
|
|
|
((playerAction == START_WALKING) || (playerAction == PROCESSING_PATH))) {
|
|
|
|
// Animate the clock when processing the player path
|
2007-06-22 12:36:04 +00:00
|
|
|
newCursor = (CursorType)((int)newCursor + 1);
|
2006-02-19 04:13:08 +00:00
|
|
|
if (newCursor == CURSOR_CROSS) newCursor = CURSOR_TIME_START;
|
2006-07-08 08:29:01 +00:00
|
|
|
} else if (checkInTalkDialog() && (oldRoomNumber == 0)) {
|
2006-02-19 04:13:08 +00:00
|
|
|
newCursor = CURSOR_TALK;
|
|
|
|
} else if (res.getTalkData()) {
|
|
|
|
newCursor = CURSOR_ARROW;
|
2006-05-29 08:12:07 +00:00
|
|
|
} else if (_cursorState == CS_BUMPED) {
|
2006-04-29 11:19:55 +00:00
|
|
|
newCursor = CURSOR_CAMERA;
|
|
|
|
} else if (_cursorState == CS_TALKING) {
|
|
|
|
newCursor = CURSOR_ARROW;
|
2006-02-19 04:13:08 +00:00
|
|
|
} else if (mouse.y() < MENUBAR_Y_SIZE) {
|
|
|
|
// If viewing a room remotely, then don't change to the menu cursor
|
|
|
|
if (oldRoomNumber != 0) return;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
newCursor = CURSOR_MENUBAR;
|
2006-04-29 11:19:55 +00:00
|
|
|
} else if (_cursorState != CS_NONE) {
|
|
|
|
// Currently in a special mode
|
2006-05-29 08:12:07 +00:00
|
|
|
checkRoomHotspots();
|
2006-04-29 11:19:55 +00:00
|
|
|
newCursor = CURSOR_CAMERA;
|
2006-02-19 04:13:08 +00:00
|
|
|
} else {
|
|
|
|
// Check for a highlighted hotspot
|
|
|
|
checkRoomHotspots();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
if (_hotspotId != 0) {
|
|
|
|
newCursor = CURSOR_CROSS;
|
|
|
|
} else {
|
|
|
|
newCursor = checkRoomExits();
|
|
|
|
}
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
if (oldHotspotId != _hotspotId)
|
2006-08-07 13:21:15 +00:00
|
|
|
StringData::getReference().getString(_hotspotNameId, _hotspotName);
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
if (mouse.getCursorNum() != newCursor)
|
2006-02-19 04:13:08 +00:00
|
|
|
mouse.setCursorNum(newCursor);
|
|
|
|
}
|
|
|
|
|
2006-08-07 13:21:15 +00:00
|
|
|
void Room::setTalkDialog(uint16 srcCharacterId, uint16 destCharacterId, uint16 usedId, uint16 stringId) {
|
2007-10-24 10:09:06 +00:00
|
|
|
Resources &res = Resources::getReference();
|
2006-08-07 13:21:15 +00:00
|
|
|
debugC(ERROR_DETAILED, kLureDebugAnimations, "Room::setTalkDialog - char=%xh string=%d",
|
|
|
|
srcCharacterId, stringId);
|
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
if (_talkDialog) {
|
|
|
|
delete _talkDialog;
|
|
|
|
_talkDialog = NULL;
|
|
|
|
}
|
2007-11-10 22:47:11 +00:00
|
|
|
/*
|
2007-10-24 10:09:06 +00:00
|
|
|
if (res.getTalkingCharacter() != 0) {
|
|
|
|
// Signal to any talked to character that they're no longer being talked to
|
|
|
|
HotspotData *talkingChar = res.getHotspot(res.getTalkingCharacter());
|
|
|
|
if ((talkingChar->talkDestCharacterId != 0) &&
|
|
|
|
(talkingChar->talkDestCharacterId != NOONE_ID)) {
|
|
|
|
HotspotData *destChar = res.getHotspot(talkingChar->talkDestCharacterId);
|
|
|
|
destChar->talkerId = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-11-10 22:47:11 +00:00
|
|
|
*/
|
2006-08-07 13:21:15 +00:00
|
|
|
res.setTalkingCharacter(srcCharacterId);
|
2006-02-19 04:13:08 +00:00
|
|
|
|
2006-08-07 13:21:15 +00:00
|
|
|
if (srcCharacterId == 0)
|
2006-02-19 04:13:08 +00:00
|
|
|
return;
|
|
|
|
|
2006-08-07 13:21:15 +00:00
|
|
|
HotspotData *character = res.getHotspot(srcCharacterId);
|
2006-02-19 04:13:08 +00:00
|
|
|
if (character->roomNumber != _roomNumber)
|
|
|
|
return;
|
|
|
|
|
2006-08-07 13:21:15 +00:00
|
|
|
_talkDialog = new TalkDialog(srcCharacterId, destCharacterId, usedId, stringId);
|
2006-02-19 04:13:08 +00:00
|
|
|
_talkDialogX = character->startX + (character->width / 2) - (TALK_DIALOG_WIDTH / 2);
|
|
|
|
|
|
|
|
if (_talkDialogX < 0) _talkDialogX = 0;
|
|
|
|
if (_talkDialogX + TALK_DIALOG_WIDTH >= FULL_SCREEN_WIDTH - 10)
|
2008-01-27 19:47:41 +00:00
|
|
|
_talkDialogX = FULL_SCREEN_WIDTH - 10 - TALK_DIALOG_WIDTH;
|
2006-02-19 04:13:08 +00:00
|
|
|
|
|
|
|
_talkDialogY = TALK_DIALOG_Y;
|
2007-12-17 11:23:19 +00:00
|
|
|
debugC(ERROR_DETAILED, kLureDebugAnimations, "Room::setTalkDialog end");
|
2006-02-19 04:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks to see if a talk dialog is active, and if so if the mouse is in
|
|
|
|
// within it
|
|
|
|
|
|
|
|
bool Room::checkInTalkDialog() {
|
|
|
|
// Make sure there is a talk dialog active
|
|
|
|
if (!_talkDialog) return false;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-10-24 10:09:06 +00:00
|
|
|
// Don't allow dialog close if it's still in progress
|
|
|
|
if (_talkDialog->isBuilding()) return false;
|
2006-02-19 04:13:08 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
// Only allow the dialog to be closable if it's the player talking, or
|
2007-10-25 10:40:26 +00:00
|
|
|
// someone talking to the player
|
|
|
|
Resources &res = Resources::getReference();
|
|
|
|
uint16 talkerId = res.getTalkingCharacter();
|
|
|
|
if ((talkerId == NOONE_ID) || (talkerId == 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (talkerId != PLAYER_ID) {
|
|
|
|
HotspotData *charHotspot = res.getHotspot(talkerId);
|
|
|
|
assert(charHotspot);
|
|
|
|
if (charHotspot->talkDestCharacterId != PLAYER_ID)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-02-19 04:13:08 +00:00
|
|
|
// Check boundaries
|
|
|
|
Mouse &mouse = Mouse::getReference();
|
|
|
|
return ((mouse.x() >= _talkDialogX) && (mouse.y() >= _talkDialogY) &&
|
|
|
|
(mouse.x() < _talkDialogX + _talkDialog->surface().width()) &&
|
|
|
|
(mouse.y() < _talkDialogY + _talkDialog->surface().height()));
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 12:48:56 +00:00
|
|
|
void Room::saveToStream(Common::WriteStream *stream) {
|
2008-01-27 19:47:41 +00:00
|
|
|
if (_talkDialog == NULL)
|
2007-12-02 04:49:33 +00:00
|
|
|
stream->writeUint16LE(0);
|
2008-01-27 19:47:41 +00:00
|
|
|
else
|
2007-12-02 04:49:33 +00:00
|
|
|
_talkDialog->saveToStream(stream);
|
|
|
|
|
2006-10-02 12:48:56 +00:00
|
|
|
stream->writeUint16LE(_roomNumber);
|
|
|
|
stream->writeUint16LE(_destRoomNumber);
|
|
|
|
stream->writeByte(_showInfo);
|
|
|
|
stream->writeUint16LE(_cursorState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::loadFromStream(Common::ReadStream *stream) {
|
2007-12-02 08:32:21 +00:00
|
|
|
uint8 saveVersion = LureEngine::getReference().saveVersion();
|
|
|
|
|
|
|
|
if (_talkDialog) {
|
2007-12-02 04:49:33 +00:00
|
|
|
delete _talkDialog;
|
2007-12-02 08:32:21 +00:00
|
|
|
_talkDialog = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saveVersion >= 26)
|
|
|
|
_talkDialog = TalkDialog::loadFromStream(stream);
|
2007-12-02 04:49:33 +00:00
|
|
|
|
2007-12-29 04:25:26 +00:00
|
|
|
// Clear any active hotspot
|
|
|
|
_hotspotId = 0;
|
|
|
|
_hotspotName[0] = '\0';
|
|
|
|
_statusLine[0] = '\0';
|
|
|
|
|
2007-11-09 08:22:09 +00:00
|
|
|
uint16 roomNum = stream->readUint16LE();
|
|
|
|
_roomNumber = 999; // Dummy room number so current room is faded out
|
|
|
|
setRoomNumber(roomNum, false);
|
2006-10-02 12:48:56 +00:00
|
|
|
|
|
|
|
_destRoomNumber = stream->readUint16LE();
|
|
|
|
_showInfo = stream->readByte() != 0;
|
|
|
|
_cursorState = (CursorState) stream->readUint16LE();
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
void Room::reset() {
|
|
|
|
_roomNumber = 999;
|
2007-12-29 04:25:26 +00:00
|
|
|
setTalkDialog(0, 0, 0, 0);
|
|
|
|
|
|
|
|
_hotspotId = 0;
|
|
|
|
_hotspotName[0] = '\0';
|
|
|
|
_statusLine[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
} // end of namespace Lure
|