2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:20:17 +00:00
|
|
|
* Copyright (C) 2004-2005 The ScummVM project
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Object map / Object click-area module
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Polygon Hit Test code ( HitTestPoly() ) adapted from code (C) Eric Haines
|
|
|
|
// appearing in Graphics Gems IV, "Point in Polygon Strategies."
|
|
|
|
// p. 24-46, code: p. 34-45
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/gfx.h"
|
2004-08-10 18:31:33 +00:00
|
|
|
#include "saga/console.h"
|
2004-08-03 00:06:18 +00:00
|
|
|
#include "saga/font.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/objectmap.h"
|
2004-12-15 00:24:12 +00:00
|
|
|
#include "saga/stream.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2004-12-24 20:44:39 +00:00
|
|
|
HitZone::HitZone(MemoryReadStreamEndian *readStream) {
|
|
|
|
int i, j;
|
|
|
|
HitZone::ClickArea *clickArea;
|
|
|
|
Point *point;
|
|
|
|
|
|
|
|
_flags = readStream->readByte();
|
|
|
|
_clickAreasCount = readStream->readByte();
|
2005-01-15 20:12:49 +00:00
|
|
|
_rightButtonVerb = readStream->readByte();
|
2004-12-24 20:44:39 +00:00
|
|
|
readStream->readByte(); // pad
|
|
|
|
_nameNumber = readStream->readUint16();
|
|
|
|
_scriptNumber = readStream->readUint16();
|
|
|
|
|
2005-01-02 14:52:11 +00:00
|
|
|
_clickAreas = (HitZone::ClickArea *)malloc(_clickAreasCount * sizeof(*_clickAreas));
|
2004-12-24 20:44:39 +00:00
|
|
|
|
|
|
|
if (_clickAreas == NULL) {
|
|
|
|
error("HitZone::HitZone Memory allocation failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < _clickAreasCount; i++) {
|
|
|
|
clickArea = &_clickAreas[i];
|
|
|
|
clickArea->pointsCount = readStream->readUint16();
|
|
|
|
|
|
|
|
assert(clickArea->pointsCount);
|
|
|
|
|
2005-01-02 14:52:11 +00:00
|
|
|
clickArea->points = (Point *)malloc(clickArea->pointsCount * sizeof(*(clickArea->points)));
|
2004-12-24 20:44:39 +00:00
|
|
|
if (clickArea->points == NULL) {
|
|
|
|
error("HitZone::HitZone Memory allocation failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < clickArea->pointsCount; j++) {
|
|
|
|
point = &clickArea->points[j];
|
|
|
|
point->x = readStream->readSint16();
|
|
|
|
point->y = readStream->readSint16();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HitZone::~HitZone() {
|
|
|
|
for (int i = 0; i < _clickAreasCount; i++) {
|
|
|
|
free(_clickAreas[i].points);
|
|
|
|
}
|
|
|
|
free(_clickAreas);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HitZone::hitTest(const Point &testPoint) {
|
|
|
|
int i, pointsCount;
|
|
|
|
HitZone::ClickArea *clickArea;
|
|
|
|
Point *points;
|
|
|
|
|
|
|
|
if (_flags & kHitZoneEnabled) {
|
|
|
|
for (i = 0; i < _clickAreasCount; i++) {
|
|
|
|
clickArea = &_clickAreas[i];
|
|
|
|
pointsCount = clickArea->pointsCount;
|
|
|
|
points = clickArea->points;
|
|
|
|
|
|
|
|
if (pointsCount == 2) {
|
|
|
|
// Hit-test a box region
|
|
|
|
if ((testPoint.x >= points[0].x) &&
|
|
|
|
(testPoint.x <= points[1].x) &&
|
|
|
|
(testPoint.y >= points[0].y) &&
|
|
|
|
(testPoint.y <= points[1].y)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pointsCount > 2) {
|
|
|
|
// Hit-test a polygon
|
|
|
|
if (hitTestPoly(points, pointsCount, testPoint)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HitZone::draw(SURFACE *ds, int color) {
|
|
|
|
int i, pointsCount;
|
|
|
|
HitZone::ClickArea *clickArea;
|
|
|
|
Point *points;
|
|
|
|
for (i = 0; i < _clickAreasCount; i++) {
|
|
|
|
clickArea = &_clickAreas[i];
|
|
|
|
pointsCount = clickArea->pointsCount;
|
|
|
|
points = clickArea->points;
|
|
|
|
if (pointsCount == 2) {
|
|
|
|
// 2 points represent a box
|
|
|
|
drawFrame(ds, &points[0], &points[1], color);
|
|
|
|
} else {
|
|
|
|
if (pointsCount > 2) {
|
|
|
|
// Otherwise draw a polyline
|
|
|
|
drawPolyLine(ds, points, pointsCount, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Initializes the object map module, creates module allocation context
|
2004-10-07 23:02:19 +00:00
|
|
|
ObjectMap::ObjectMap(SagaEngine *vm) : _vm(vm) {
|
|
|
|
_objectsLoaded = false;
|
|
|
|
_namesLoaded = false;
|
2004-10-07 23:26:41 +00:00
|
|
|
_nNames = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Shuts down the object map module, destroys module allocation context
|
2004-08-02 15:44:18 +00:00
|
|
|
ObjectMap::~ObjectMap() {
|
|
|
|
freeMem();
|
|
|
|
freeNames();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Loads an object map resource ( objects ( clickareas ( points ) ) )
|
2004-08-02 15:44:18 +00:00
|
|
|
int ObjectMap::load(const byte *om_res, size_t om_res_len) {
|
2004-10-27 21:32:28 +00:00
|
|
|
OBJECTMAP_ENTRY *object_map;
|
|
|
|
CLICKAREA *clickarea;
|
2004-10-04 23:09:38 +00:00
|
|
|
Point *point;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
int i, k, m;
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
MemoryReadStreamEndian readS(om_res, om_res_len, IS_BIG_ENDIAN);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if (_objectsLoaded) {
|
2004-08-02 15:44:18 +00:00
|
|
|
freeMem();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Obtain object count N and allocate space for N objects
|
2004-12-15 00:24:12 +00:00
|
|
|
_nObjects = readS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-02 14:52:11 +00:00
|
|
|
_objectMaps = (OBJECTMAP_ENTRY *)malloc(_nObjects * sizeof(*_objectMaps));
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if (_objectMaps == NULL) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("Error: Memory allocation failed");
|
2004-10-27 21:32:28 +00:00
|
|
|
return MEM;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Load all N objects
|
2004-10-07 23:02:19 +00:00
|
|
|
for (i = 0; i < _nObjects; i++) {
|
|
|
|
object_map = &_objectMaps[i];
|
2004-10-05 02:16:26 +00:00
|
|
|
object_map->flags = readS.readByte();
|
2004-10-07 23:02:19 +00:00
|
|
|
object_map->nClickareas = readS.readByte();
|
2004-10-05 02:16:26 +00:00
|
|
|
object_map->defaultVerb = readS.readByte();
|
|
|
|
readS.readByte();
|
2004-12-15 00:24:12 +00:00
|
|
|
object_map->objectNum = readS.readUint16();
|
|
|
|
object_map->scriptNum = readS.readUint16();
|
2005-01-02 14:52:11 +00:00
|
|
|
object_map->clickareas = (CLICKAREA *)malloc(object_map->nClickareas * sizeof(*(object_map->clickareas)));
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
if (object_map->clickareas == NULL) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("Error: Memory allocation failed");
|
2004-10-27 21:32:28 +00:00
|
|
|
return MEM;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Load all clickareas for this object
|
2004-10-07 23:02:19 +00:00
|
|
|
for (k = 0; k < object_map->nClickareas; k++) {
|
2004-04-12 21:40:49 +00:00
|
|
|
clickarea = &object_map->clickareas[k];
|
2004-08-01 23:24:22 +00:00
|
|
|
clickarea->n_points = readS.readUint16LE();
|
2004-04-12 21:40:49 +00:00
|
|
|
assert(clickarea->n_points != 0);
|
|
|
|
|
2005-01-02 14:52:11 +00:00
|
|
|
clickarea->points = (Point *)malloc(clickarea->n_points * sizeof(*(clickarea->points)));
|
2004-04-12 21:40:49 +00:00
|
|
|
if (clickarea->points == NULL) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("Error: Memory allocation failed");
|
2004-10-27 21:32:28 +00:00
|
|
|
return MEM;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Load all points for this clickarea
|
2004-04-12 21:40:49 +00:00
|
|
|
for (m = 0; m < clickarea->n_points; m++) {
|
|
|
|
point = &clickarea->points[m];
|
2004-12-15 00:24:12 +00:00
|
|
|
point->x = readS.readSint16();
|
|
|
|
point->y = readS.readSint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-08-02 15:44:18 +00:00
|
|
|
debug(2, "ObjectMap::load(): Read %d points for clickarea %d in object %d.",
|
2004-10-07 23:02:19 +00:00
|
|
|
clickarea->n_points, k, object_map->objectNum);
|
2004-05-01 13:04:31 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
_objectsLoaded = true;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Frees all storage allocated for the current object map data
|
2004-08-02 15:44:18 +00:00
|
|
|
int ObjectMap::freeMem() {
|
2004-10-27 21:32:28 +00:00
|
|
|
OBJECTMAP_ENTRY *object_map;
|
|
|
|
CLICKAREA *clickarea;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
int i, k;
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if (!_objectsLoaded) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
for (i = 0; i < _nObjects; i++) {
|
|
|
|
object_map = &_objectMaps[i];
|
|
|
|
for (k = 0; k < object_map->nClickareas; k++) {
|
2004-04-12 21:40:49 +00:00
|
|
|
clickarea = &object_map->clickareas[k];
|
|
|
|
free(clickarea->points);
|
|
|
|
}
|
|
|
|
free(object_map->clickareas);
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if (_nObjects) {
|
|
|
|
free(_objectMaps);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
_objectsLoaded = false;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Loads an object name list resource
|
2004-08-02 15:44:18 +00:00
|
|
|
int ObjectMap::loadNames(const unsigned char *onl_res, size_t onl_res_len) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int table_len;
|
|
|
|
int n_names;
|
|
|
|
size_t name_offset;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
MemoryReadStreamEndian readS(onl_res, onl_res_len, IS_BIG_ENDIAN);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if (_namesLoaded) {
|
2004-08-02 15:44:18 +00:00
|
|
|
freeNames();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-15 00:24:12 +00:00
|
|
|
table_len = readS.readUint16();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
n_names = table_len / 2 - 2;
|
2004-10-07 23:02:19 +00:00
|
|
|
_nNames = n_names;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 15:44:18 +00:00
|
|
|
debug(2, "ObjectMap::loadNames: Loading %d object names.", n_names);
|
2005-01-02 14:52:11 +00:00
|
|
|
_names = (const char **)malloc(n_names * sizeof(*_names));
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 15:44:18 +00:00
|
|
|
if (_names == NULL) {
|
2004-05-05 13:05:45 +00:00
|
|
|
warning("Error: Memory allocation failed");
|
2004-10-27 21:32:28 +00:00
|
|
|
return MEM;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_names; i++) {
|
2004-12-15 00:24:12 +00:00
|
|
|
name_offset = readS.readUint16();
|
2004-08-02 15:44:18 +00:00
|
|
|
_names[i] = (const char *)(onl_res + name_offset);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 15:44:18 +00:00
|
|
|
debug(3, "Loaded object name string: %s", _names[i]);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
_namesLoaded = true;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Frees all storage allocated for the current object name list data
|
2004-08-02 15:44:18 +00:00
|
|
|
int ObjectMap::freeNames() {
|
2004-10-07 23:02:19 +00:00
|
|
|
if (!_namesLoaded) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if (_nNames) {
|
2004-08-02 15:44:18 +00:00
|
|
|
free(_names);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
_namesLoaded = false;
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// If 'object' is a valid object number in the currently loaded object
|
|
|
|
// name list resource, the funciton sets '*name' to the descriptive string
|
2004-10-27 21:32:28 +00:00
|
|
|
// corresponding to 'object' and returns SUCCESS. Otherwise it returns
|
|
|
|
// FAILURE.
|
2004-10-05 02:16:26 +00:00
|
|
|
const char *ObjectMap::getName(int object) {
|
2004-10-07 23:02:19 +00:00
|
|
|
assert(_namesLoaded);
|
|
|
|
assert((object > 0) && (object <= _nNames));
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-05 02:16:26 +00:00
|
|
|
return _names[object - 1];
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-05 02:16:26 +00:00
|
|
|
const uint16 ObjectMap::getFlags(int object) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
assert(_namesLoaded);
|
|
|
|
assert((object > 0) && (object <= _nNames));
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
for (i = 0; i < _nObjects; i++) {
|
|
|
|
if (_objectMaps[i].objectNum == object) {
|
|
|
|
return _objectMaps[i].flags;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-05 02:16:26 +00:00
|
|
|
return 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-24 20:44:39 +00:00
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// If 'object' is a valid object number in the currently loaded object
|
|
|
|
// name list resource, the funciton sets '*ep_num' to the entrypoint number
|
2004-10-27 21:32:28 +00:00
|
|
|
// corresponding to 'object' and returns SUCCESS. Otherwise, it returns
|
|
|
|
// FAILURE.
|
2004-10-05 02:16:26 +00:00
|
|
|
const int ObjectMap::getEPNum(int object) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
assert(_namesLoaded);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if ((object < 0) || (object > (_nObjects + 1)))
|
2004-10-05 02:16:26 +00:00
|
|
|
return -1;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
for (i = 0; i < _nObjects; i++)
|
|
|
|
if (_objectMaps[i].objectNum == object)
|
|
|
|
return _objectMaps[i].scriptNum;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-05 02:16:26 +00:00
|
|
|
return -1;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-01 11:48:53 +00:00
|
|
|
// Uses Gfx::drawLine to display all clickareas for each object in the
|
2004-05-01 13:04:31 +00:00
|
|
|
// currently loaded object map resource.
|
2004-10-27 21:32:28 +00:00
|
|
|
int ObjectMap::draw(SURFACE *ds, const Point& imousePt, int color, int color2) {
|
|
|
|
OBJECTMAP_ENTRY *object_map;
|
|
|
|
CLICKAREA *clickarea;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
char txt_buf[32];
|
|
|
|
|
|
|
|
int draw_color = color;
|
|
|
|
int draw_txt = 0;
|
|
|
|
|
2004-10-07 23:26:41 +00:00
|
|
|
bool hitObject = false;
|
2004-10-07 23:02:19 +00:00
|
|
|
int objectNum = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
int i, k;
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
if (!_objectsLoaded) {
|
2004-10-27 21:32:28 +00:00
|
|
|
return FAILURE;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:26:41 +00:00
|
|
|
if ((objectNum = hitTest(imousePt)) != -1) {
|
|
|
|
hitObject = true;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
for (i = 0; i < _nObjects; i++) {
|
2004-04-12 21:40:49 +00:00
|
|
|
draw_color = color;
|
2004-10-07 23:26:41 +00:00
|
|
|
if (hitObject && (objectNum == _objectMaps[i].objectNum)) {
|
2005-01-02 14:52:11 +00:00
|
|
|
snprintf(txt_buf, sizeof(txt_buf), "obj %d: v %d, f %X",
|
2004-10-07 23:02:19 +00:00
|
|
|
_objectMaps[i].objectNum,
|
|
|
|
_objectMaps[i].defaultVerb,
|
|
|
|
_objectMaps[i].flags);
|
2004-04-12 21:40:49 +00:00
|
|
|
draw_txt = 1;
|
|
|
|
draw_color = color2;
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
object_map = &_objectMaps[i];
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
for (k = 0; k < object_map->nClickareas; k++) {
|
2004-04-12 21:40:49 +00:00
|
|
|
clickarea = &object_map->clickareas[k];
|
|
|
|
if (clickarea->n_points == 2) {
|
2004-05-01 13:04:31 +00:00
|
|
|
// 2 points represent a box
|
2004-10-30 22:34:08 +00:00
|
|
|
drawFrame(ds, &clickarea->points[0], &clickarea->points[1], draw_color);
|
2004-04-12 21:40:49 +00:00
|
|
|
} else if (clickarea->n_points > 2) {
|
2004-05-01 13:04:31 +00:00
|
|
|
// Otherwise draw a polyline
|
2004-10-30 22:34:08 +00:00
|
|
|
drawPolyLine(ds, clickarea->points, clickarea->n_points, draw_color);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-05-01 13:04:31 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
if (draw_txt) {
|
2004-08-03 00:06:18 +00:00
|
|
|
_vm->_font->draw(SMALL_FONT_ID, ds, txt_buf, 0, 2, 2,
|
2004-10-07 23:02:19 +00:00
|
|
|
_vm->_gfx->getWhite(), _vm->_gfx->getBlack(), FONT_OUTLINE);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
return SUCCESS;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-08 19:58:49 +00:00
|
|
|
int ObjectMap::hitTest(const Point& imousePt) {
|
2004-10-04 23:09:38 +00:00
|
|
|
Point imouse;
|
2004-10-27 21:32:28 +00:00
|
|
|
OBJECTMAP_ENTRY *object_map;
|
|
|
|
CLICKAREA *clickarea;
|
2004-10-04 23:09:38 +00:00
|
|
|
Point *points;
|
2004-04-12 21:40:49 +00:00
|
|
|
int n_points;
|
|
|
|
|
|
|
|
int i, k;
|
|
|
|
|
2004-10-07 23:26:41 +00:00
|
|
|
imouse.x = imousePt.x;
|
|
|
|
imouse.y = imousePt.y;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Loop through all scene objects
|
2004-10-07 23:02:19 +00:00
|
|
|
for (i = 0; i < _nObjects; i++) {
|
|
|
|
object_map = &_objectMaps[i];
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:04:31 +00:00
|
|
|
// Hit-test all clickareas for this object
|
2004-10-07 23:02:19 +00:00
|
|
|
for (k = 0; k < object_map->nClickareas; k++) {
|
2004-04-12 21:40:49 +00:00
|
|
|
clickarea = &object_map->clickareas[k];
|
|
|
|
n_points = clickarea->n_points;
|
|
|
|
points = clickarea->points;
|
|
|
|
|
|
|
|
if (n_points == 2) {
|
2004-05-01 13:04:31 +00:00
|
|
|
// Hit-test a box region
|
|
|
|
if ((imouse.x > points[0].x) && (imouse.x <= points[1].x) &&
|
|
|
|
(imouse.y > points[0].y) &&
|
|
|
|
(imouse.y <= points[1].y)) {
|
2004-10-07 23:26:41 +00:00
|
|
|
return object_map->objectNum;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
} else if (n_points > 2) {
|
2004-05-01 13:04:31 +00:00
|
|
|
// Hit-test a polygon
|
2004-10-30 22:34:08 +00:00
|
|
|
if (hitTestPoly(points, n_points, imouse)) {
|
2004-10-07 23:26:41 +00:00
|
|
|
return object_map->objectNum;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-01 13:04:31 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:26:41 +00:00
|
|
|
return -1;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-24 20:44:39 +00:00
|
|
|
void ObjectMap::cmdInfo(void) {
|
2004-04-12 21:40:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-12-03 19:15:44 +00:00
|
|
|
_vm->_console->DebugPrintf("%d objects loaded.\n", _nObjects);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-07 23:02:19 +00:00
|
|
|
for (i = 0; i < _nObjects; i++) {
|
2004-12-03 19:15:44 +00:00
|
|
|
_vm->_console->DebugPrintf("%s:\n", _names[i]);
|
|
|
|
_vm->_console->DebugPrintf("%d. verb: %d, flags: %X, name_i: %d, scr_n: %d, ca_ct: %d\n", i,
|
2004-10-07 23:02:19 +00:00
|
|
|
_objectMaps[i].defaultVerb,
|
|
|
|
_objectMaps[i].flags,
|
|
|
|
_objectMaps[i].objectNum,
|
|
|
|
_objectMaps[i].scriptNum,
|
|
|
|
_objectMaps[i].nClickareas);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|