2010-10-21 17:09:57 +00: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.
|
2014-02-18 01:34:21 +00:00
|
|
|
*
|
2010-10-21 17:09:57 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:21 +00:00
|
|
|
*
|
2010-10-21 17:09:57 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on original Hugo Trilogy source code
|
|
|
|
*
|
|
|
|
* Copyright (c) 1989-1995 David P. Gray
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/debug.h"
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
#include "hugo/hugo.h"
|
2011-01-23 00:05:52 +00:00
|
|
|
#include "hugo/game.h"
|
2010-10-21 17:09:57 +00:00
|
|
|
#include "hugo/object.h"
|
|
|
|
#include "hugo/display.h"
|
|
|
|
#include "hugo/file.h"
|
|
|
|
#include "hugo/route.h"
|
|
|
|
#include "hugo/util.h"
|
|
|
|
#include "hugo/parser.h"
|
2010-11-01 00:27:11 +00:00
|
|
|
#include "hugo/schedule.h"
|
2011-01-25 00:32:48 +00:00
|
|
|
#include "hugo/text.h"
|
2011-02-08 20:52:26 +00:00
|
|
|
#include "hugo/inventory.h"
|
2011-02-14 07:31:01 +00:00
|
|
|
#include "hugo/mouse.h"
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
namespace Hugo {
|
|
|
|
|
2013-11-01 13:15:19 +00:00
|
|
|
ObjectHandler::ObjectHandler(HugoEngine *vm) : _vm(vm) {
|
|
|
|
_uses = nullptr;
|
|
|
|
_objects = nullptr;
|
2010-11-22 22:49:24 +00:00
|
|
|
_numObj = 0;
|
2010-12-06 23:15:25 +00:00
|
|
|
_objCount = 0;
|
2011-02-15 09:15:21 +00:00
|
|
|
_usesSize = 0;
|
2012-06-13 18:58:01 +00:00
|
|
|
memset(_objBound, '\0', sizeof(Overlay));
|
|
|
|
memset(_boundary, '\0', sizeof(Overlay));
|
|
|
|
memset(_overlay, '\0', sizeof(Overlay));
|
|
|
|
memset(_ovlBase, '\0', sizeof(Overlay));
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectHandler::~ObjectHandler() {
|
|
|
|
}
|
|
|
|
|
2011-02-18 21:43:38 +00:00
|
|
|
byte ObjectHandler::getBoundaryOverlay(uint16 index) const {
|
|
|
|
return _boundary[index];
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 21:43:38 +00:00
|
|
|
byte ObjectHandler::getObjectBoundary(uint16 index) const {
|
|
|
|
return _objBound[index];
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 21:43:38 +00:00
|
|
|
byte ObjectHandler::getBaseBoundary(uint16 index) const {
|
|
|
|
return _ovlBase[index];
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 21:43:38 +00:00
|
|
|
byte ObjectHandler::getFirstOverlay(uint16 index) const {
|
|
|
|
return _overlay[index];
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectHandler::isCarried(int objIndex) const {
|
2012-06-13 09:28:25 +00:00
|
|
|
return _objects[objIndex]._carriedFl;
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectHandler::setCarry(int objIndex, bool val) {
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[objIndex]._carriedFl = val;
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectHandler::setVelocity(int objIndex, int8 vx, int8 vy) {
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[objIndex]._vx = vx;
|
|
|
|
_objects[objIndex]._vy = vy;
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
void ObjectHandler::setPath(int objIndex, Path pathType, int16 vxPath, int16 vyPath) {
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[objIndex]._pathType = pathType;
|
|
|
|
_objects[objIndex]._vxPath = vxPath;
|
|
|
|
_objects[objIndex]._vyPath = vyPath;
|
2011-02-18 21:24:32 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Save sequence number and image number in given object
|
|
|
|
*/
|
2012-06-13 18:58:01 +00:00
|
|
|
void ObjectHandler::saveSeq(Object *obj) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(1, kDebugObject, "saveSeq");
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
bool found = false;
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int i = 0; !found && (i < obj->_seqNumb); i++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Seq *q = obj->_seqList[i]._seqPtr;
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int j = 0; !found && (j < obj->_seqList[i]._imageNbr); j++) {
|
|
|
|
if (obj->_currImagePtr == q) {
|
2010-10-21 17:09:57 +00:00
|
|
|
found = true;
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_curSeqNum = i;
|
|
|
|
obj->_curImageNum = j;
|
2010-10-21 17:09:57 +00:00
|
|
|
} else {
|
2012-06-13 09:28:25 +00:00
|
|
|
q = q->_nextSeqPtr;
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2012-06-13 18:58:01 +00:00
|
|
|
* Set up cur_seqPtr from stored sequence and image number in object
|
2011-02-11 20:27:48 +00:00
|
|
|
*/
|
2012-06-13 18:58:01 +00:00
|
|
|
void ObjectHandler::restoreSeq(Object *obj) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(1, kDebugObject, "restoreSeq");
|
2010-10-21 17:09:57 +00:00
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
Seq *q = obj->_seqList[obj->_curSeqNum]._seqPtr;
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int j = 0; j < obj->_curImageNum; j++)
|
|
|
|
q = q->_nextSeqPtr;
|
|
|
|
obj->_currImagePtr = q;
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* If status.objid = -1, pick up objid, else use status.objid on objid,
|
|
|
|
* if objid can't be picked up, use it directly
|
|
|
|
*/
|
2010-10-21 17:09:57 +00:00
|
|
|
void ObjectHandler::useObject(int16 objId) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(1, kDebugObject, "useObject(%d)", objId);
|
2010-10-21 17:09:57 +00:00
|
|
|
|
2011-02-08 20:52:26 +00:00
|
|
|
int16 inventObjId = _vm->_inventory->getInventoryObjId();
|
2014-02-09 10:37:30 +00:00
|
|
|
Object *obj = &_objects[objId]; // Ptr to object
|
2011-02-08 20:52:26 +00:00
|
|
|
if (inventObjId == -1) {
|
2014-02-09 10:37:30 +00:00
|
|
|
const char *verb; // Background verb to use directly
|
2010-10-21 17:09:57 +00:00
|
|
|
// Get or use objid directly
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((obj->_genericCmd & TAKE) || obj->_objValue) // Get collectible item
|
|
|
|
sprintf(_vm->_line, "%s %s", _vm->_text->getVerb(_vm->_take, 0), _vm->_text->getNoun(obj->_nounIndex, 0));
|
2014-02-09 10:37:30 +00:00
|
|
|
else if (obj->_cmdIndex != 0) // Use non-collectible item if able
|
2012-06-13 09:28:25 +00:00
|
|
|
sprintf(_vm->_line, "%s %s", _vm->_text->getVerb(_vm->_parser->getCmdDefaultVerbIdx(obj->_cmdIndex), 0), _vm->_text->getNoun(obj->_nounIndex, 0));
|
2021-11-13 21:40:28 +00:00
|
|
|
else if ((verb = _vm->_parser->useBG(_vm->_text->getNoun(obj->_nounIndex, 0))) != nullptr)
|
2012-06-13 09:28:25 +00:00
|
|
|
sprintf(_vm->_line, "%s %s", verb, _vm->_text->getNoun(obj->_nounIndex, 0));
|
2010-10-21 17:09:57 +00:00
|
|
|
else
|
2014-02-09 10:37:30 +00:00
|
|
|
return; // Can't use object directly
|
2010-10-21 17:09:57 +00:00
|
|
|
} else {
|
|
|
|
// Use status.objid on objid
|
|
|
|
// Default to first cmd verb
|
2012-06-13 09:28:25 +00:00
|
|
|
sprintf(_vm->_line, "%s %s %s", _vm->_text->getVerb(_vm->_parser->getCmdDefaultVerbIdx(_objects[inventObjId]._cmdIndex), 0),
|
|
|
|
_vm->_text->getNoun(_objects[inventObjId]._nounIndex, 0),
|
|
|
|
_vm->_text->getNoun(obj->_nounIndex, 0));
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
// Check valid use of objects and override verb if necessary
|
2012-06-13 18:58:01 +00:00
|
|
|
for (Uses *use = _uses; use->_objId != _numObj; use++) {
|
2012-06-13 09:28:25 +00:00
|
|
|
if (inventObjId == use->_objId) {
|
2010-10-21 17:09:57 +00:00
|
|
|
// Look for secondary object, if found use matching verb
|
|
|
|
bool foundFl = false;
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
for (Target *target = use->_targets; target->_nounIndex != 0; target++)
|
2012-06-13 09:28:25 +00:00
|
|
|
if (target->_nounIndex == obj->_nounIndex) {
|
2010-10-21 17:09:57 +00:00
|
|
|
foundFl = true;
|
2012-06-13 09:28:25 +00:00
|
|
|
sprintf(_vm->_line, "%s %s %s", _vm->_text->getVerb(target->_verbIndex, 0),
|
|
|
|
_vm->_text->getNoun(_objects[inventObjId]._nounIndex, 0),
|
|
|
|
_vm->_text->getNoun(obj->_nounIndex, 0));
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No valid use of objects found, print failure string
|
|
|
|
if (!foundFl) {
|
|
|
|
// Deselect dragged icon if inventory not active
|
2011-02-08 20:52:26 +00:00
|
|
|
if (_vm->_inventory->getInventoryState() != kInventoryActive)
|
2011-01-08 16:56:52 +00:00
|
|
|
_vm->_screen->resetInventoryObjId();
|
2012-06-13 09:28:25 +00:00
|
|
|
Utils::notifyBox(_vm->_text->getTextData(use->_dataIndex));
|
2010-10-21 17:09:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-08 20:52:26 +00:00
|
|
|
if (_vm->_inventory->getInventoryState() == kInventoryActive) // If inventory active, remove it
|
|
|
|
_vm->_inventory->setInventoryState(kInventoryUp);
|
2011-01-08 16:56:52 +00:00
|
|
|
|
|
|
|
_vm->_screen->resetInventoryObjId();
|
|
|
|
|
2010-12-30 21:07:38 +00:00
|
|
|
_vm->_parser->lineHandler(); // and process command
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Return object index of the topmost object under the cursor, or -1 if none
|
|
|
|
* Objects are filtered if not "useful"
|
|
|
|
*/
|
2010-10-21 17:09:57 +00:00
|
|
|
int16 ObjectHandler::findObject(uint16 x, uint16 y) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(3, kDebugObject, "findObject(%d, %d)", x, y);
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
int16 objIndex = -1; // Index of found object
|
|
|
|
uint16 y2Max = 0; // Greatest y2
|
2012-06-13 18:58:01 +00:00
|
|
|
Object *obj = _objects;
|
2010-10-21 17:09:57 +00:00
|
|
|
// Check objects on screen
|
2010-11-11 23:04:04 +00:00
|
|
|
for (int i = 0; i < _numObj; i++, obj++) {
|
2010-10-21 17:09:57 +00:00
|
|
|
// Object must be in current screen and "useful"
|
2012-06-13 19:18:37 +00:00
|
|
|
if (obj->_screenIndex == *_vm->_screenPtr && (obj->_genericCmd || obj->_objValue || obj->_cmdIndex)) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Seq *curImage = obj->_currImagePtr;
|
2010-10-21 17:09:57 +00:00
|
|
|
// Object must have a visible image...
|
2021-11-13 21:40:28 +00:00
|
|
|
if (curImage != nullptr && obj->_cycling != kCycleInvisible) {
|
2010-10-21 17:09:57 +00:00
|
|
|
// If cursor inside object
|
2012-06-13 09:28:25 +00:00
|
|
|
if (x >= (uint16)obj->_x && x <= obj->_x + curImage->_x2 && y >= (uint16)obj->_y && y <= obj->_y + curImage->_y2) {
|
2010-10-21 17:09:57 +00:00
|
|
|
// If object is closest so far
|
2012-06-13 09:28:25 +00:00
|
|
|
if (obj->_y + curImage->_y2 > y2Max) {
|
|
|
|
y2Max = obj->_y + curImage->_y2;
|
2010-10-21 17:09:57 +00:00
|
|
|
objIndex = i; // Found an object!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// ...or a dummy object that has a hotspot rectangle
|
2021-11-13 21:40:28 +00:00
|
|
|
if (curImage == nullptr && obj->_vxPath != 0 && !obj->_carriedFl) {
|
2010-10-21 17:09:57 +00:00
|
|
|
// If cursor inside special rectangle
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((int16)x >= obj->_oldx && (int16)x < obj->_oldx + obj->_vxPath && (int16)y >= obj->_oldy && (int16)y < obj->_oldy + obj->_vyPath) {
|
2010-10-21 17:09:57 +00:00
|
|
|
// If object is closest so far
|
2012-06-13 09:28:25 +00:00
|
|
|
if (obj->_oldy + obj->_vyPath - 1 > (int16)y2Max) {
|
|
|
|
y2Max = obj->_oldy + obj->_vyPath - 1;
|
2010-10-21 17:09:57 +00:00
|
|
|
objIndex = i; // Found an object!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return objIndex;
|
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Issue "Look at <object>" command
|
|
|
|
* Note special case of swapped hero image
|
|
|
|
*/
|
2012-06-13 18:58:01 +00:00
|
|
|
void ObjectHandler::lookObject(Object *obj) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(1, kDebugObject, "lookObject");
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
if (obj == _vm->_hero)
|
|
|
|
// Hero swapped - look at other
|
|
|
|
obj = &_objects[_vm->_heroImage];
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
_vm->_parser->command("%s %s", _vm->_text->getVerb(_vm->_look, 0), _vm->_text->getNoun(obj->_nounIndex, 0));
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-15 18:30:15 +00:00
|
|
|
* Free all object images, uses and ObjArr (before exiting)
|
2011-02-11 20:27:48 +00:00
|
|
|
*/
|
2010-10-21 17:09:57 +00:00
|
|
|
void ObjectHandler::freeObjects() {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(1, kDebugObject, "freeObjects");
|
2010-10-21 17:09:57 +00:00
|
|
|
|
2013-11-01 13:15:19 +00:00
|
|
|
if (_vm->_hero != nullptr && _vm->_hero->_seqList[0]._seqPtr != nullptr) {
|
2011-02-15 18:30:15 +00:00
|
|
|
// Free all sequence lists and image data
|
|
|
|
for (int16 i = 0; i < _numObj; i++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Object *obj = &_objects[i];
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int16 j = 0; j < obj->_seqNumb; j++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Seq *seq = obj->_seqList[j]._seqPtr;
|
|
|
|
Seq *next;
|
2013-11-01 13:15:19 +00:00
|
|
|
if (seq == nullptr) // Failure during database load
|
2011-02-15 18:30:15 +00:00
|
|
|
break;
|
2013-11-01 13:15:19 +00:00
|
|
|
if (seq->_imagePtr != nullptr) {
|
2012-06-13 09:28:25 +00:00
|
|
|
free(seq->_imagePtr);
|
2013-11-01 13:15:19 +00:00
|
|
|
seq->_imagePtr = nullptr;
|
2010-12-05 22:02:04 +00:00
|
|
|
}
|
2012-06-13 09:28:25 +00:00
|
|
|
seq = seq->_nextSeqPtr;
|
|
|
|
while (seq != obj->_seqList[j]._seqPtr) {
|
2013-11-01 13:15:19 +00:00
|
|
|
if (seq->_imagePtr != nullptr) {
|
2012-06-13 09:28:25 +00:00
|
|
|
free(seq->_imagePtr);
|
2013-11-01 13:15:19 +00:00
|
|
|
seq->_imagePtr = nullptr;
|
2011-02-15 18:30:15 +00:00
|
|
|
}
|
2012-06-13 09:28:25 +00:00
|
|
|
next = seq->_nextSeqPtr;
|
2011-02-15 18:30:15 +00:00
|
|
|
free(seq);
|
|
|
|
seq = next;
|
|
|
|
}
|
2010-12-06 01:56:42 +00:00
|
|
|
free(seq);
|
2013-11-01 13:15:19 +00:00
|
|
|
seq = nullptr;
|
2010-12-06 01:56:42 +00:00
|
|
|
}
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-01 13:15:19 +00:00
|
|
|
if (_uses != nullptr) {
|
2011-02-15 18:30:15 +00:00
|
|
|
for (int16 i = 0; i < _usesSize; i++)
|
2012-06-13 09:28:25 +00:00
|
|
|
free(_uses[i]._targets);
|
2011-02-15 09:15:21 +00:00
|
|
|
free(_uses);
|
2013-11-01 13:15:19 +00:00
|
|
|
_uses = nullptr;
|
2011-02-15 09:15:21 +00:00
|
|
|
}
|
2011-02-15 18:30:15 +00:00
|
|
|
|
2011-09-08 05:55:40 +00:00
|
|
|
for (int16 i = 0; i < _objCount; i++) {
|
2012-06-13 09:28:25 +00:00
|
|
|
free(_objects[i]._stateDataIndex);
|
2013-11-01 13:15:19 +00:00
|
|
|
_objects[i]._stateDataIndex = nullptr;
|
2011-02-15 18:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(_objects);
|
2013-11-01 13:15:19 +00:00
|
|
|
_objects = nullptr;
|
2011-02-15 09:15:21 +00:00
|
|
|
}
|
2011-02-15 18:30:15 +00:00
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Compare function for the quicksort. The sort is to order the objects in
|
|
|
|
* increasing vertical position, using y+y2 as the baseline
|
|
|
|
* Returns -1 if ay2 < by2 else 1 if ay2 > by2 else 0
|
|
|
|
*/
|
2010-10-21 17:09:57 +00:00
|
|
|
int ObjectHandler::y2comp(const void *a, const void *b) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(6, kDebugObject, "y2comp");
|
2010-10-21 17:09:57 +00:00
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
const Object *p1 = &HugoEngine::get()._object->_objects[*(const byte *)a];
|
|
|
|
const Object *p2 = &HugoEngine::get()._object->_objects[*(const byte *)b];
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
if (p1 == p2)
|
|
|
|
// Why does qsort try the same indexes?
|
|
|
|
return 0;
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if (p1->_priority == kPriorityBackground)
|
2010-10-21 17:09:57 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if (p2->_priority == kPriorityBackground)
|
2010-10-21 17:09:57 +00:00
|
|
|
return 1;
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if (p1->_priority == kPriorityForeground)
|
2010-10-21 17:09:57 +00:00
|
|
|
return 1;
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if (p2->_priority == kPriorityForeground)
|
2010-10-21 17:09:57 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
int ay2 = p1->_y + p1->_currImagePtr->_y2;
|
|
|
|
int by2 = p2->_y + p2->_currImagePtr->_y2;
|
2010-10-21 17:09:57 +00:00
|
|
|
|
|
|
|
return ay2 - by2;
|
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Return TRUE if object being carried by hero
|
|
|
|
*/
|
2010-10-21 17:09:57 +00:00
|
|
|
bool ObjectHandler::isCarrying(uint16 wordIndex) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(1, kDebugObject, "isCarrying(%d)", wordIndex);
|
2010-10-21 17:09:57 +00:00
|
|
|
|
2010-11-11 23:04:04 +00:00
|
|
|
for (int i = 0; i < _numObj; i++) {
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((wordIndex == _objects[i]._nounIndex) && _objects[i]._carriedFl)
|
2010-10-21 17:09:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Describe any takeable objects visible in this screen
|
|
|
|
*/
|
2010-10-21 17:09:57 +00:00
|
|
|
void ObjectHandler::showTakeables() {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(1, kDebugObject, "showTakeables");
|
2010-10-21 17:09:57 +00:00
|
|
|
|
2010-11-11 23:04:04 +00:00
|
|
|
for (int j = 0; j < _numObj; j++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Object *obj = &_objects[j];
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((obj->_cycling != kCycleInvisible) &&
|
2012-06-13 19:18:37 +00:00
|
|
|
(obj->_screenIndex == *_vm->_screenPtr) &&
|
2012-06-13 09:28:25 +00:00
|
|
|
(((TAKE & obj->_genericCmd) == TAKE) || obj->_objValue)) {
|
|
|
|
Utils::notifyBox(Common::String::format("You can also see:\n%s.", _vm->_text->getNoun(obj->_nounIndex, LOOK_NAME)));
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Find a clear space around supplied object that hero can walk to
|
|
|
|
*/
|
2012-06-13 18:58:01 +00:00
|
|
|
bool ObjectHandler::findObjectSpace(Object *obj, int16 *destx, int16 *desty) {
|
2013-10-31 07:13:16 +00:00
|
|
|
debugC(1, kDebugObject, "findObjectSpace(...)");
|
2010-10-22 20:45:00 +00:00
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
Seq *curImage = obj->_currImagePtr;
|
2012-06-13 09:28:25 +00:00
|
|
|
int16 y = obj->_y + curImage->_y2 - 1;
|
2010-10-22 20:45:00 +00:00
|
|
|
|
|
|
|
bool foundFl = true;
|
|
|
|
// Try left rear corner
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int16 x = *destx = obj->_x + curImage->_x1; x < *destx + kHeroMaxWidth; x++) {
|
2011-01-23 22:51:12 +00:00
|
|
|
if (checkBoundary(x, y))
|
2010-10-22 20:45:00 +00:00
|
|
|
foundFl = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundFl) { // Try right rear corner
|
|
|
|
foundFl = true;
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int16 x = *destx = obj->_x + curImage->_x2 - kHeroMaxWidth + 1; x <= obj->_x + (int16)curImage->_x2; x++) {
|
2011-01-23 22:51:12 +00:00
|
|
|
if (checkBoundary(x, y))
|
2010-10-22 20:45:00 +00:00
|
|
|
foundFl = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundFl) { // Try left front corner
|
|
|
|
foundFl = true;
|
|
|
|
y += 2;
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int16 x = *destx = obj->_x + curImage->_x1; x < *destx + kHeroMaxWidth; x++) {
|
2011-01-23 22:51:12 +00:00
|
|
|
if (checkBoundary(x, y))
|
2010-10-22 20:45:00 +00:00
|
|
|
foundFl = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundFl) { // Try right rear corner
|
|
|
|
foundFl = true;
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int16 x = *destx = obj->_x + curImage->_x2 - kHeroMaxWidth + 1; x <= obj->_x + (int16)curImage->_x2; x++) {
|
2011-01-23 22:51:12 +00:00
|
|
|
if (checkBoundary(x, y))
|
2010-10-22 20:45:00 +00:00
|
|
|
foundFl = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*desty = y;
|
|
|
|
return foundFl;
|
|
|
|
}
|
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
void ObjectHandler::readUse(Common::ReadStream &in, Uses &curUse) {
|
2012-06-13 09:28:25 +00:00
|
|
|
curUse._objId = in.readSint16BE();
|
|
|
|
curUse._dataIndex = in.readUint16BE();
|
2011-02-18 07:11:55 +00:00
|
|
|
uint16 numSubElem = in.readUint16BE();
|
2012-06-13 18:58:01 +00:00
|
|
|
curUse._targets = (Target *)malloc(sizeof(Target) * numSubElem);
|
2011-02-18 07:11:55 +00:00
|
|
|
for (int j = 0; j < numSubElem; j++) {
|
2012-06-13 09:28:25 +00:00
|
|
|
curUse._targets[j]._nounIndex = in.readUint16BE();
|
|
|
|
curUse._targets[j]._verbIndex = in.readUint16BE();
|
2011-02-18 07:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-15 09:15:21 +00:00
|
|
|
/**
|
|
|
|
* Load _uses from Hugo.dat
|
|
|
|
*/
|
|
|
|
void ObjectHandler::loadObjectUses(Common::ReadStream &in) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Uses tmpUse;
|
2013-11-01 13:15:19 +00:00
|
|
|
tmpUse._targets = nullptr;
|
2011-03-01 07:37:26 +00:00
|
|
|
|
2011-02-15 09:15:21 +00:00
|
|
|
//Read _uses
|
|
|
|
for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
|
|
|
|
uint16 numElem = in.readUint16BE();
|
|
|
|
if (varnt == _vm->_gameVariant) {
|
|
|
|
_usesSize = numElem;
|
2012-06-13 18:58:01 +00:00
|
|
|
_uses = (Uses *)malloc(sizeof(Uses) * numElem);
|
2011-02-15 09:15:21 +00:00
|
|
|
}
|
2011-02-18 07:11:55 +00:00
|
|
|
|
2011-03-01 07:37:26 +00:00
|
|
|
for (int i = 0; i < numElem; i++) {
|
2011-06-19 22:59:48 +00:00
|
|
|
if (varnt == _vm->_gameVariant)
|
2011-03-01 07:37:26 +00:00
|
|
|
readUse(in, _uses[i]);
|
|
|
|
else {
|
|
|
|
readUse(in, tmpUse);
|
2012-06-13 09:28:25 +00:00
|
|
|
free(tmpUse._targets);
|
2013-11-01 13:15:19 +00:00
|
|
|
tmpUse._targets = nullptr;
|
2011-03-01 07:37:26 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-15 09:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
void ObjectHandler::readObject(Common::ReadStream &in, Object &curObject) {
|
2012-06-13 09:28:25 +00:00
|
|
|
curObject._nounIndex = in.readUint16BE();
|
|
|
|
curObject._dataIndex = in.readUint16BE();
|
2011-02-18 07:11:55 +00:00
|
|
|
uint16 numSubElem = in.readUint16BE();
|
|
|
|
|
|
|
|
if (numSubElem == 0)
|
2013-11-01 13:15:19 +00:00
|
|
|
curObject._stateDataIndex = nullptr;
|
2011-02-18 07:11:55 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
curObject._stateDataIndex = (uint16 *)malloc(sizeof(uint16) * numSubElem);
|
2011-02-18 07:11:55 +00:00
|
|
|
for (int j = 0; j < numSubElem; j++)
|
2012-06-13 09:28:25 +00:00
|
|
|
curObject._stateDataIndex[j] = in.readUint16BE();
|
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
curObject._pathType = (Path) in.readSint16BE();
|
2012-06-13 09:28:25 +00:00
|
|
|
curObject._vxPath = in.readSint16BE();
|
|
|
|
curObject._vyPath = in.readSint16BE();
|
|
|
|
curObject._actIndex = in.readUint16BE();
|
|
|
|
curObject._seqNumb = in.readByte();
|
2013-11-01 13:15:19 +00:00
|
|
|
curObject._currImagePtr = nullptr;
|
2012-06-13 09:28:25 +00:00
|
|
|
|
|
|
|
if (curObject._seqNumb == 0) {
|
|
|
|
curObject._seqList[0]._imageNbr = 0;
|
2013-11-01 13:15:19 +00:00
|
|
|
curObject._seqList[0]._seqPtr = nullptr;
|
2011-02-18 07:11:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
for (int j = 0; j < curObject._seqNumb; j++) {
|
|
|
|
curObject._seqList[j]._imageNbr = in.readUint16BE();
|
2013-11-01 13:15:19 +00:00
|
|
|
curObject._seqList[j]._seqPtr = nullptr;
|
2011-02-18 07:11:55 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
curObject._cycling = (Cycle)in.readByte();
|
2012-06-13 09:28:25 +00:00
|
|
|
curObject._cycleNumb = in.readByte();
|
|
|
|
curObject._frameInterval = in.readByte();
|
|
|
|
curObject._frameTimer = in.readByte();
|
|
|
|
curObject._radius = in.readByte();
|
|
|
|
curObject._screenIndex = in.readByte();
|
|
|
|
curObject._x = in.readSint16BE();
|
|
|
|
curObject._y = in.readSint16BE();
|
|
|
|
curObject._oldx = in.readSint16BE();
|
|
|
|
curObject._oldy = in.readSint16BE();
|
|
|
|
curObject._vx = in.readByte();
|
|
|
|
curObject._vy = in.readByte();
|
|
|
|
curObject._objValue = in.readByte();
|
|
|
|
curObject._genericCmd = in.readSint16BE();
|
|
|
|
curObject._cmdIndex = in.readUint16BE();
|
|
|
|
curObject._carriedFl = (in.readByte() != 0);
|
|
|
|
curObject._state = in.readByte();
|
|
|
|
curObject._verbOnlyFl = (in.readByte() != 0);
|
|
|
|
curObject._priority = in.readByte();
|
|
|
|
curObject._viewx = in.readSint16BE();
|
|
|
|
curObject._viewy = in.readSint16BE();
|
|
|
|
curObject._direction = in.readSint16BE();
|
|
|
|
curObject._curSeqNum = in.readByte();
|
|
|
|
curObject._curImageNum = in.readByte();
|
|
|
|
curObject._oldvx = in.readByte();
|
|
|
|
curObject._oldvy = in.readByte();
|
2011-02-18 07:11:55 +00:00
|
|
|
}
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Load ObjectArr from Hugo.dat
|
|
|
|
*/
|
2011-02-12 16:20:57 +00:00
|
|
|
void ObjectHandler::loadObjectArr(Common::ReadStream &in) {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(6, kDebugObject, "loadObject(&in)");
|
2012-06-13 18:58:01 +00:00
|
|
|
Object tmpObject;
|
2013-11-01 13:15:19 +00:00
|
|
|
tmpObject._stateDataIndex = nullptr;
|
2010-10-25 14:03:01 +00:00
|
|
|
|
2010-10-21 17:09:57 +00:00
|
|
|
for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
|
|
|
|
uint16 numElem = in.readUint16BE();
|
2011-03-01 07:37:26 +00:00
|
|
|
|
2010-10-21 17:09:57 +00:00
|
|
|
if (varnt == _vm->_gameVariant) {
|
2010-10-30 16:04:43 +00:00
|
|
|
_objCount = numElem;
|
2012-06-13 18:58:01 +00:00
|
|
|
_objects = (Object *)malloc(sizeof(Object) * numElem);
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
2011-02-18 07:11:55 +00:00
|
|
|
|
2011-03-01 07:37:26 +00:00
|
|
|
for (int i = 0; i < numElem; i++) {
|
|
|
|
if (varnt == _vm->_gameVariant)
|
|
|
|
readObject(in, _objects[i]);
|
|
|
|
else {
|
|
|
|
// Skip over uneeded objects.
|
|
|
|
readObject(in, tmpObject);
|
2012-06-13 09:28:25 +00:00
|
|
|
free(tmpObject._stateDataIndex);
|
2013-11-01 13:15:19 +00:00
|
|
|
tmpObject._stateDataIndex = nullptr;
|
2011-03-01 07:37:26 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-21 17:09:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-11 23:04:04 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Set the screenindex property of the carried objets to the given screen
|
|
|
|
* number
|
|
|
|
*/
|
2010-11-11 23:04:04 +00:00
|
|
|
void ObjectHandler::setCarriedScreen(int screenNum) {
|
2011-01-23 00:05:52 +00:00
|
|
|
for (int i = kHeroIndex + 1; i < _numObj; i++) {// Any others
|
2010-11-11 23:04:04 +00:00
|
|
|
if (isCarried(i)) // being carried
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[i]._screenIndex = screenNum;
|
2010-11-11 23:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Load _numObj from Hugo.dat
|
|
|
|
*/
|
2011-02-12 16:20:57 +00:00
|
|
|
void ObjectHandler::loadNumObj(Common::ReadStream &in) {
|
2010-11-11 23:04:04 +00:00
|
|
|
for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
|
2014-02-09 10:37:30 +00:00
|
|
|
int numElem = in.readUint16BE();
|
2010-11-11 23:04:04 +00:00
|
|
|
if (varnt == _vm->_gameVariant)
|
|
|
|
_numObj = numElem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Restore all sequences
|
|
|
|
*/
|
2010-11-11 23:04:04 +00:00
|
|
|
void ObjectHandler::restoreAllSeq() {
|
|
|
|
// Restore ptrs to currently loaded objects
|
|
|
|
for (int i = 0; i < _numObj; i++)
|
|
|
|
restoreSeq(&_objects[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Save objects
|
|
|
|
*/
|
2010-11-11 23:04:04 +00:00
|
|
|
void ObjectHandler::saveObjects(Common::WriteStream *out) {
|
|
|
|
for (int i = 0; i < _numObj; i++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
// Save where curr_seqPtr is pointing to
|
2010-11-11 23:04:04 +00:00
|
|
|
saveSeq(&_objects[i]);
|
2010-11-22 22:49:24 +00:00
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
out->writeByte(_objects[i]._pathType);
|
|
|
|
out->writeSint16BE(_objects[i]._vxPath);
|
|
|
|
out->writeSint16BE(_objects[i]._vyPath);
|
|
|
|
out->writeByte(_objects[i]._cycling);
|
|
|
|
out->writeByte(_objects[i]._cycleNumb);
|
|
|
|
out->writeByte(_objects[i]._frameTimer);
|
|
|
|
out->writeByte(_objects[i]._screenIndex);
|
|
|
|
out->writeSint16BE(_objects[i]._x);
|
|
|
|
out->writeSint16BE(_objects[i]._y);
|
|
|
|
out->writeSint16BE(_objects[i]._oldx);
|
|
|
|
out->writeSint16BE(_objects[i]._oldy);
|
|
|
|
out->writeSByte(_objects[i]._vx);
|
|
|
|
out->writeSByte(_objects[i]._vy);
|
|
|
|
out->writeByte(_objects[i]._objValue);
|
|
|
|
out->writeByte((_objects[i]._carriedFl) ? 1 : 0);
|
|
|
|
out->writeByte(_objects[i]._state);
|
|
|
|
out->writeByte(_objects[i]._priority);
|
|
|
|
out->writeSint16BE(_objects[i]._viewx);
|
|
|
|
out->writeSint16BE(_objects[i]._viewy);
|
|
|
|
out->writeSint16BE(_objects[i]._direction);
|
|
|
|
out->writeByte(_objects[i]._curSeqNum);
|
|
|
|
out->writeByte(_objects[i]._curImageNum);
|
|
|
|
out->writeSByte(_objects[i]._oldvx);
|
|
|
|
out->writeSByte(_objects[i]._oldvy);
|
2010-11-11 23:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Restore objects
|
|
|
|
*/
|
2010-11-11 23:04:04 +00:00
|
|
|
void ObjectHandler::restoreObjects(Common::SeekableReadStream *in) {
|
|
|
|
for (int i = 0; i < _numObj; i++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
_objects[i]._pathType = (Path) in->readByte();
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[i]._vxPath = in->readSint16BE();
|
|
|
|
_objects[i]._vyPath = in->readSint16BE();
|
2012-06-13 18:58:01 +00:00
|
|
|
_objects[i]._cycling = (Cycle) in->readByte();
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[i]._cycleNumb = in->readByte();
|
|
|
|
_objects[i]._frameTimer = in->readByte();
|
|
|
|
_objects[i]._screenIndex = in->readByte();
|
|
|
|
_objects[i]._x = in->readSint16BE();
|
|
|
|
_objects[i]._y = in->readSint16BE();
|
|
|
|
_objects[i]._oldx = in->readSint16BE();
|
|
|
|
_objects[i]._oldy = in->readSint16BE();
|
|
|
|
_objects[i]._vx = in->readSByte();
|
|
|
|
_objects[i]._vy = in->readSByte();
|
|
|
|
_objects[i]._objValue = in->readByte();
|
|
|
|
_objects[i]._carriedFl = (in->readByte() == 1);
|
|
|
|
_objects[i]._state = in->readByte();
|
|
|
|
_objects[i]._priority = in->readByte();
|
|
|
|
_objects[i]._viewx = in->readSint16BE();
|
|
|
|
_objects[i]._viewy = in->readSint16BE();
|
|
|
|
_objects[i]._direction = in->readSint16BE();
|
|
|
|
_objects[i]._curSeqNum = in->readByte();
|
|
|
|
_objects[i]._curImageNum = in->readByte();
|
|
|
|
_objects[i]._oldvx = in->readSByte();
|
|
|
|
_objects[i]._oldvy = in->readSByte();
|
2010-11-11 23:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Compute max object score
|
|
|
|
*/
|
2010-11-11 23:04:04 +00:00
|
|
|
int ObjectHandler::calcMaxScore() {
|
|
|
|
int score = 0;
|
|
|
|
for (int i = 0; i < _numObj; i++)
|
2012-06-13 09:28:25 +00:00
|
|
|
score += _objects[i]._objValue;
|
2011-01-23 22:51:12 +00:00
|
|
|
return score;
|
2010-11-11 23:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Read Object images
|
|
|
|
*/
|
2010-11-11 23:04:04 +00:00
|
|
|
void ObjectHandler::readObjectImages() {
|
|
|
|
debugC(1, kDebugObject, "readObjectImages");
|
|
|
|
|
|
|
|
for (int i = 0; i < _numObj; i++)
|
|
|
|
_vm->_file->readImage(i, &_objects[i]);
|
|
|
|
}
|
|
|
|
|
2011-01-23 22:51:12 +00:00
|
|
|
bool ObjectHandler::checkBoundary(int16 x, int16 y) {
|
|
|
|
// Check if Boundary bit set
|
2011-02-11 07:12:29 +00:00
|
|
|
return (_boundary[y * kCompLineSize + x / 8] & (0x80 >> x % 8)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Return maximum allowed movement (from zero to vx) such that object does
|
|
|
|
* not cross a boundary (either background or another object)
|
|
|
|
*/
|
2011-02-11 07:12:29 +00:00
|
|
|
int ObjectHandler::deltaX(const int x1, const int x2, const int vx, int y) const {
|
|
|
|
// Explanation of algorithm: The boundaries are drawn as contiguous
|
|
|
|
// lines 1 pixel wide. Since DX,DY are not necessarily 1, we must
|
|
|
|
// detect boundary crossing. If vx positive, examine each pixel from
|
|
|
|
// x1 old to x2 new, else x2 old to x1 new, both at the y2 line.
|
|
|
|
// If vx zero, no need to check. If vy non-zero then examine each
|
|
|
|
// pixel on the line segment x1 to x2 from y old to y new.
|
|
|
|
// Fix from Hugo I v1.5:
|
|
|
|
// Note the diff is munged in the return statement to cater for a special
|
|
|
|
// cases arising from differences in image widths from one sequence to
|
|
|
|
// another. The problem occurs reversing direction at a wall where the
|
|
|
|
// new image intersects before the object can move away. This is cured
|
|
|
|
// by comparing the intersection with half the object width pos. If the
|
|
|
|
// intersection is in the other half wrt the intended direction, use the
|
|
|
|
// desired vx, else use the computed delta. i.e. believe the desired vx
|
|
|
|
|
|
|
|
debugC(3, kDebugEngine, "deltaX(%d, %d, %d, %d)", x1, x2, vx, y);
|
|
|
|
|
|
|
|
if (vx == 0)
|
|
|
|
return 0; // Object stationary
|
|
|
|
|
|
|
|
y *= kCompLineSize; // Offset into boundary file
|
|
|
|
if (vx > 0) {
|
|
|
|
// Moving to right
|
|
|
|
for (int i = x1 >> 3; i <= (x2 + vx) >> 3; i++) {// Search by byte
|
|
|
|
int b = Utils::firstBit((byte)(_boundary[y + i] | _objBound[y + i]));
|
|
|
|
if (b < 8) { // b is index or 8
|
|
|
|
// Compute x of boundary and test if intersection
|
|
|
|
b += i << 3;
|
|
|
|
if ((b >= x1) && (b <= x2 + vx))
|
|
|
|
return (b < x1 + ((x2 - x1) >> 1)) ? vx : b - x2 - 1; // return dx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Moving to left
|
|
|
|
for (int i = x2 >> 3; i >= (x1 + vx) >> 3; i--) {// Search by byte
|
|
|
|
int b = Utils::lastBit((byte)(_boundary[y + i] | _objBound[y + i]));
|
|
|
|
if (b < 8) { // b is index or 8
|
|
|
|
// Compute x of boundary and test if intersection
|
|
|
|
b += i << 3;
|
|
|
|
if ((b >= x1 + vx) && (b <= x2))
|
|
|
|
return (b > x1 + ((x2 - x1) >> 1)) ? vx : b - x1 + 1; // return dx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Similar to Delta_x, but for movement in y direction. Special case of
|
|
|
|
* bytes at end of line segment; must only count boundary bits falling on
|
|
|
|
* line segment.
|
|
|
|
*/
|
2011-02-11 07:12:29 +00:00
|
|
|
int ObjectHandler::deltaY(const int x1, const int x2, const int vy, const int y) const {
|
|
|
|
debugC(3, kDebugEngine, "deltaY(%d, %d, %d, %d)", x1, x2, vy, y);
|
|
|
|
|
|
|
|
if (vy == 0)
|
|
|
|
return 0; // Object stationary
|
|
|
|
|
|
|
|
int inc = (vy > 0) ? 1 : -1;
|
|
|
|
for (int j = y + inc; j != (y + vy + inc); j += inc) { //Search by byte
|
|
|
|
for (int i = x1 >> 3; i <= x2 >> 3; i++) {
|
|
|
|
int b = _boundary[j * kCompLineSize + i] | _objBound[j * kCompLineSize + i];
|
|
|
|
if (b != 0) { // Any bit set
|
|
|
|
// Make sure boundary bits fall on line segment
|
|
|
|
if (i == (x2 >> 3)) // Adjust right end
|
|
|
|
b &= 0xff << ((i << 3) + 7 - x2);
|
|
|
|
else if (i == (x1 >> 3)) // Adjust left end
|
|
|
|
b &= 0xff >> (x1 - (i << 3));
|
|
|
|
if (b)
|
|
|
|
return j - y - inc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Store a horizontal line segment in the object boundary file
|
|
|
|
*/
|
2011-02-11 07:12:29 +00:00
|
|
|
void ObjectHandler::storeBoundary(const int x1, const int x2, const int y) {
|
|
|
|
debugC(5, kDebugEngine, "storeBoundary(%d, %d, %d)", x1, x2, y);
|
|
|
|
|
|
|
|
for (int i = x1 >> 3; i <= x2 >> 3; i++) { // For each byte in line
|
|
|
|
byte *b = &_objBound[y * kCompLineSize + i];// get boundary byte
|
|
|
|
if (i == x2 >> 3) // Adjust right end
|
|
|
|
*b |= 0xff << ((i << 3) + 7 - x2);
|
|
|
|
else if (i == x1 >> 3) // Adjust left end
|
|
|
|
*b |= 0xff >> (x1 - (i << 3));
|
|
|
|
else
|
|
|
|
*b = 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Clear a horizontal line segment in the object boundary file
|
|
|
|
*/
|
2011-02-11 07:12:29 +00:00
|
|
|
void ObjectHandler::clearBoundary(const int x1, const int x2, const int y) {
|
|
|
|
debugC(5, kDebugEngine, "clearBoundary(%d, %d, %d)", x1, x2, y);
|
|
|
|
|
|
|
|
for (int i = x1 >> 3; i <= x2 >> 3; i++) { // For each byte in line
|
|
|
|
byte *b = &_objBound[y * kCompLineSize + i];// get boundary byte
|
|
|
|
if (i == x2 >> 3) // Adjust right end
|
|
|
|
*b &= ~(0xff << ((i << 3) + 7 - x2));
|
|
|
|
else if (i == x1 >> 3) // Adjust left end
|
|
|
|
*b &= ~(0xff >> (x1 - (i << 3)));
|
|
|
|
else
|
|
|
|
*b = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Clear a horizontal line segment in the screen boundary file
|
|
|
|
* Used to fix some data issues
|
|
|
|
*/
|
2011-02-11 07:12:29 +00:00
|
|
|
void ObjectHandler::clearScreenBoundary(const int x1, const int x2, const int y) {
|
|
|
|
debugC(5, kDebugEngine, "clearScreenBoundary(%d, %d, %d)", x1, x2, y);
|
|
|
|
|
|
|
|
for (int i = x1 >> 3; i <= x2 >> 3; i++) { // For each byte in line
|
|
|
|
byte *b = &_boundary[y * kCompLineSize + i];// get boundary byte
|
|
|
|
if (i == x2 >> 3) // Adjust right end
|
|
|
|
*b &= ~(0xff << ((i << 3) + 7 - x2));
|
|
|
|
else if (i == x1 >> 3) // Adjust left end
|
|
|
|
*b &= ~(0xff >> (x1 - (i << 3)));
|
|
|
|
else
|
|
|
|
*b = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* An object has collided with a boundary. See if any actions are required
|
|
|
|
*/
|
2012-06-13 18:58:01 +00:00
|
|
|
void ObjectHandler::boundaryCollision(Object *obj) {
|
2011-02-11 07:12:29 +00:00
|
|
|
debugC(1, kDebugEngine, "boundaryCollision");
|
|
|
|
|
|
|
|
if (obj == _vm->_hero) {
|
|
|
|
// Hotspots only relevant to HERO
|
|
|
|
int x;
|
2012-06-13 09:28:25 +00:00
|
|
|
if (obj->_vx > 0)
|
|
|
|
x = obj->_x + obj->_currImagePtr->_x2;
|
2011-02-11 07:12:29 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
x = obj->_x + obj->_currImagePtr->_x1;
|
|
|
|
int y = obj->_y + obj->_currImagePtr->_y2;
|
2011-02-11 07:12:29 +00:00
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
int16 index = _vm->_mouse->findExit(x, y, obj->_screenIndex);
|
2011-02-14 07:31:01 +00:00
|
|
|
if (index >= 0)
|
|
|
|
_vm->_scheduler->insertActionList(_vm->_mouse->getHotspotActIndex(index));
|
|
|
|
|
2011-02-11 07:12:29 +00:00
|
|
|
} else {
|
|
|
|
// Check whether an object collided with HERO
|
2012-06-13 09:28:25 +00:00
|
|
|
int dx = _vm->_hero->_x + _vm->_hero->_currImagePtr->_x1 - obj->_x - obj->_currImagePtr->_x1;
|
|
|
|
int dy = _vm->_hero->_y + _vm->_hero->_currImagePtr->_y2 - obj->_y - obj->_currImagePtr->_y2;
|
2011-02-11 07:12:29 +00:00
|
|
|
// If object's radius is infinity, use a closer value
|
2012-06-13 09:28:25 +00:00
|
|
|
int8 radius = obj->_radius;
|
2011-02-11 07:12:29 +00:00
|
|
|
if (radius < 0)
|
|
|
|
radius = kStepDx * 2;
|
|
|
|
if ((abs(dx) <= radius) && (abs(dy) <= radius))
|
2012-06-13 09:28:25 +00:00
|
|
|
_vm->_scheduler->insertActionList(obj->_actIndex);
|
2011-02-11 07:12:29 +00:00
|
|
|
}
|
2011-01-23 22:51:12 +00:00
|
|
|
}
|
|
|
|
|
2010-10-21 17:09:57 +00:00
|
|
|
} // End of namespace Hugo
|