2010-10-25 12:07:07 +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.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-25 12:07:07 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/random.h"
|
|
|
|
|
|
|
|
#include "hugo/hugo.h"
|
2011-01-23 00:05:52 +00:00
|
|
|
#include "hugo/game.h"
|
2010-10-25 12:07:07 +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"
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
namespace Hugo {
|
|
|
|
|
|
|
|
ObjectHandler_v3d::ObjectHandler_v3d(HugoEngine *vm) : ObjectHandler_v2d(vm) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectHandler_v3d::~ObjectHandler_v3d() {
|
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Update all object positions. Process object 'local' events
|
|
|
|
* including boundary events and collisions
|
|
|
|
*/
|
2010-10-25 12:07:07 +00:00
|
|
|
void ObjectHandler_v3d::moveObjects() {
|
2010-10-25 14:03:01 +00:00
|
|
|
debugC(4, kDebugObject, "moveObjects");
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
// Added to DOS version in order to handle mouse properly
|
2011-02-08 20:52:26 +00:00
|
|
|
// Do special route processing
|
|
|
|
_vm->_route->processRoute();
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
// Perform any adjustments to velocity based on special path types
|
|
|
|
// and store all (visible) object baselines into the boundary file.
|
|
|
|
// Don't store foreground or background objects
|
2010-11-11 23:04:04 +00:00
|
|
|
for (int i = 0; i < _numObj; i++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Object *obj = &_objects[i]; // Get pointer to object
|
|
|
|
Seq *currImage = obj->_currImagePtr; // Get ptr to current image
|
2012-06-13 19:18:37 +00:00
|
|
|
if (obj->_screenIndex == *_vm->_screenPtr) {
|
2012-06-13 09:28:25 +00:00
|
|
|
switch (obj->_pathType) {
|
2011-01-23 00:05:52 +00:00
|
|
|
case kPathChase:
|
|
|
|
case kPathChase2: {
|
2012-06-13 09:28:25 +00:00
|
|
|
int8 radius = obj->_radius; // Default to object's radius
|
2010-10-25 12:07:07 +00:00
|
|
|
if (radius < 0) // If radius infinity, use closer value
|
2011-01-23 00:05:52 +00:00
|
|
|
radius = kStepDx;
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
// Allowable motion wrt boundary
|
2012-06-13 09:28:25 +00:00
|
|
|
int dx = _vm->_hero->_x + _vm->_hero->_currImagePtr->_x1 - obj->_x - currImage->_x1;
|
|
|
|
int dy = _vm->_hero->_y + _vm->_hero->_currImagePtr->_y2 - obj->_y - currImage->_y2 - 1;
|
2010-10-25 12:07:07 +00:00
|
|
|
if (abs(dx) <= radius)
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_vx = 0;
|
2010-10-25 12:07:07 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_vx = (dx > 0) ? MIN(dx, obj->_vxPath) : MAX(dx, -obj->_vxPath);
|
2010-10-25 12:07:07 +00:00
|
|
|
if (abs(dy) <= radius)
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_vy = 0;
|
2010-10-25 12:07:07 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_vy = (dy > 0) ? MIN(dy, obj->_vyPath) : MAX(dy, -obj->_vyPath);
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
// Set first image in sequence (if multi-seq object)
|
2012-06-13 09:28:25 +00:00
|
|
|
switch (obj->_seqNumb) {
|
2010-10-25 12:07:07 +00:00
|
|
|
case 4:
|
2012-06-13 09:28:25 +00:00
|
|
|
if (!obj->_vx) { // Got 4 directions
|
|
|
|
if (obj->_vx != obj->_oldvx) { // vx just stopped
|
2010-10-25 12:07:07 +00:00
|
|
|
if (dy >= 0)
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_DOWN]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_UP]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
2012-06-13 09:28:25 +00:00
|
|
|
} else if (obj->_vx != obj->_oldvx) {
|
2010-10-25 12:07:07 +00:00
|
|
|
if (dx > 0)
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_RIGHT]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_LEFT]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 2:
|
2012-06-13 09:28:25 +00:00
|
|
|
if (obj->_vx != obj->_oldvx) { // vx just stopped
|
2010-10-25 12:07:07 +00:00
|
|
|
if (dx > 0) // Left & right only
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_RIGHT]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_LEFT]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if (obj->_vx || obj->_vy) {
|
|
|
|
obj->_cycling = kCycleForward;
|
2010-10-25 12:07:07 +00:00
|
|
|
} else {
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_cycling = kCycleNotCycling;
|
2011-02-11 07:12:29 +00:00
|
|
|
boundaryCollision(obj); // Must have got hero!
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_oldvx = obj->_vx;
|
|
|
|
obj->_oldvy = obj->_vy;
|
|
|
|
currImage = obj->_currImagePtr; // Get (new) ptr to current image
|
2010-10-25 12:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-01-23 00:05:52 +00:00
|
|
|
case kPathWander2:
|
|
|
|
case kPathWander:
|
2010-12-12 07:40:00 +00:00
|
|
|
if (!_vm->_rnd->getRandomNumber(3 * _vm->_normalTPS)) { // Kick on random interval
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_vx = _vm->_rnd->getRandomNumber(obj->_vxPath << 1) - obj->_vxPath;
|
|
|
|
obj->_vy = _vm->_rnd->getRandomNumber(obj->_vyPath << 1) - obj->_vyPath;
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
// Set first image in sequence (if multi-seq object)
|
2012-06-13 09:28:25 +00:00
|
|
|
if (obj->_seqNumb > 1) {
|
|
|
|
if (!obj->_vx && (obj->_seqNumb >= 4)) {
|
|
|
|
if (obj->_vx != obj->_oldvx) { // vx just stopped
|
|
|
|
if (obj->_vy > 0)
|
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_DOWN]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_UP]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
2012-06-13 09:28:25 +00:00
|
|
|
} else if (obj->_vx != obj->_oldvx) {
|
|
|
|
if (obj->_vx > 0)
|
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_RIGHT]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
else
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_currImagePtr = obj->_seqList[SEQ_LEFT]._seqPtr;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_oldvx = obj->_vx;
|
|
|
|
obj->_oldvy = obj->_vy;
|
|
|
|
currImage = obj->_currImagePtr; // Get (new) ptr to current image
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
2012-06-13 09:28:25 +00:00
|
|
|
if (obj->_vx || obj->_vy)
|
|
|
|
obj->_cycling = kCycleForward;
|
2011-01-18 09:16:52 +00:00
|
|
|
|
2010-10-25 12:07:07 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
; // Really, nothing
|
|
|
|
}
|
|
|
|
// Store boundaries
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((obj->_cycling > kCycleAlmostInvisible) && (obj->_priority == kPriorityFloating))
|
|
|
|
storeBoundary(obj->_x + currImage->_x1, obj->_x + currImage->_x2, obj->_y + currImage->_y2);
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move objects, allowing for boundaries
|
2010-11-11 23:04:04 +00:00
|
|
|
for (int i = 0; i < _numObj; i++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Object *obj = &_objects[i]; // Get pointer to object
|
2012-06-13 19:18:37 +00:00
|
|
|
if ((obj->_screenIndex == *_vm->_screenPtr) && (obj->_vx || obj->_vy)) {
|
2010-10-25 12:07:07 +00:00
|
|
|
// Only process if it's moving
|
|
|
|
|
|
|
|
// Do object movement. Delta_x,y return allowed movement in x,y
|
|
|
|
// to move as close to a boundary as possible without crossing it.
|
2012-06-13 18:58:01 +00:00
|
|
|
Seq *currImage = obj->_currImagePtr; // Get ptr to current image
|
2010-10-25 12:07:07 +00:00
|
|
|
// object coordinates
|
2012-06-13 09:28:25 +00:00
|
|
|
int x1 = obj->_x + currImage->_x1; // Left edge of object
|
|
|
|
int x2 = obj->_x + currImage->_x2; // Right edge
|
|
|
|
int y1 = obj->_y + currImage->_y1; // Top edge
|
|
|
|
int y2 = obj->_y + currImage->_y2; // Bottom edge
|
2010-10-25 12:07:07 +00:00
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((obj->_cycling > kCycleAlmostInvisible) && (obj->_priority == kPriorityFloating))
|
2011-02-11 07:12:29 +00:00
|
|
|
clearBoundary(x1, x2, y2); // Clear our own boundary
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
// Allowable motion wrt boundary
|
2012-06-13 09:28:25 +00:00
|
|
|
int dx = deltaX(x1, x2, obj->_vx, y2);
|
|
|
|
if (dx != obj->_vx) {
|
2010-10-25 12:07:07 +00:00
|
|
|
// An object boundary collision!
|
2011-02-11 07:12:29 +00:00
|
|
|
boundaryCollision(obj);
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_vx = 0;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
int dy = deltaY(x1, x2, obj->_vy, y2);
|
|
|
|
if (dy != obj->_vy) {
|
2010-10-25 12:07:07 +00:00
|
|
|
// An object boundary collision!
|
2011-02-11 07:12:29 +00:00
|
|
|
boundaryCollision(obj);
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_vy = 0;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((obj->_cycling > kCycleAlmostInvisible) && (obj->_priority == kPriorityFloating))
|
2011-02-11 07:12:29 +00:00
|
|
|
storeBoundary(x1, x2, y2); // Re-store our own boundary
|
2010-10-25 12:07:07 +00:00
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_x += dx; // Update object position
|
|
|
|
obj->_y += dy;
|
2010-10-25 12:07:07 +00:00
|
|
|
|
|
|
|
// Don't let object go outside screen
|
2011-01-23 00:05:52 +00:00
|
|
|
if (x1 < kEdge)
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_x = kEdge2;
|
2011-01-23 00:05:52 +00:00
|
|
|
if (x2 > (kXPix - kEdge))
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_x = kXPix - kEdge2 - (x2 - x1);
|
2011-01-23 00:05:52 +00:00
|
|
|
if (y1 < kEdge)
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_y = kEdge2;
|
2011-01-23 00:05:52 +00:00
|
|
|
if (y2 > (kYPix - kEdge))
|
2012-06-13 09:28:25 +00:00
|
|
|
obj->_y = kYPix - kEdge2 - (y2 - y1);
|
2011-01-23 00:05:52 +00:00
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
if ((obj->_vx == 0) && (obj->_vy == 0) && (obj->_pathType != kPathWander2) && (obj->_pathType != kPathChase2))
|
|
|
|
obj->_cycling = kCycleNotCycling;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear all object baselines from the boundary file.
|
2010-11-11 23:04:04 +00:00
|
|
|
for (int i = 0; i < _numObj; i++) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Object *obj = &_objects[i]; // Get pointer to object
|
|
|
|
Seq *currImage = obj->_currImagePtr; // Get ptr to current image
|
2012-06-13 19:18:37 +00:00
|
|
|
if ((obj->_screenIndex == *_vm->_screenPtr) && (obj->_cycling > kCycleAlmostInvisible) && (obj->_priority == kPriorityFloating))
|
2012-06-13 09:28:25 +00:00
|
|
|
clearBoundary(obj->_oldx + currImage->_x1, obj->_oldx + currImage->_x2, obj->_oldy + currImage->_y2);
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If maze mode is enabled, do special maze processing
|
2012-06-13 09:28:25 +00:00
|
|
|
if (_vm->_maze._enabledFl) {
|
2012-06-13 18:58:01 +00:00
|
|
|
Seq *currImage = _vm->_hero->_currImagePtr;// Get ptr to current image
|
2010-11-01 15:29:06 +00:00
|
|
|
// hero coordinates
|
2012-06-13 09:28:25 +00:00
|
|
|
int x1 = _vm->_hero->_x + currImage->_x1; // Left edge of object
|
|
|
|
int x2 = _vm->_hero->_x + currImage->_x2; // Right edge
|
|
|
|
int y1 = _vm->_hero->_y + currImage->_y1; // Top edge
|
|
|
|
int y2 = _vm->_hero->_y + currImage->_y2; // Bottom edge
|
2010-11-01 15:29:06 +00:00
|
|
|
|
|
|
|
_vm->_scheduler->processMaze(x1, x2, y1, y2);
|
|
|
|
}
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 20:20:21 +00:00
|
|
|
/**
|
2011-02-11 20:27:48 +00:00
|
|
|
* Swap all the images of one object with another. Set hero_image (we make
|
|
|
|
* the assumption for now that the first obj is always the HERO) to the object
|
|
|
|
* number of the swapped image
|
|
|
|
*/
|
2011-01-18 21:32:18 +00:00
|
|
|
void ObjectHandler_v3d::swapImages(int objIndex1, int objIndex2) {
|
|
|
|
debugC(1, kDebugObject, "swapImages(%d, %d)", objIndex1, objIndex2);
|
2010-10-25 12:07:07 +00:00
|
|
|
|
2011-01-18 21:32:18 +00:00
|
|
|
saveSeq(&_objects[objIndex1]);
|
2010-10-25 12:07:07 +00:00
|
|
|
|
2012-06-13 18:58:01 +00:00
|
|
|
SeqList tmpSeqList[kMaxSeqNumb];
|
|
|
|
int seqListSize = sizeof(SeqList) * kMaxSeqNumb;
|
2010-10-25 12:07:07 +00:00
|
|
|
|
2012-06-13 09:28:25 +00:00
|
|
|
memmove(tmpSeqList, _objects[objIndex1]._seqList, seqListSize);
|
|
|
|
memmove(_objects[objIndex1]._seqList, _objects[objIndex2]._seqList, seqListSize);
|
|
|
|
memmove(_objects[objIndex2]._seqList, tmpSeqList, seqListSize);
|
2011-01-18 21:32:18 +00:00
|
|
|
restoreSeq(&_objects[objIndex1]);
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[objIndex2]._currImagePtr = _objects[objIndex2]._seqList[0]._seqPtr;
|
2011-01-23 00:05:52 +00:00
|
|
|
_vm->_heroImage = (_vm->_heroImage == kHeroIndex) ? objIndex2 : kHeroIndex;
|
2011-01-18 09:16:52 +00:00
|
|
|
|
|
|
|
// Make sure baseline stays constant
|
2012-06-13 09:28:25 +00:00
|
|
|
_objects[objIndex1]._y += _objects[objIndex2]._currImagePtr->_y2 - _objects[objIndex1]._currImagePtr->_y2;
|
2010-10-25 12:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Hugo
|