2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2001-2004 The ScummVM project
|
2001-10-09 14:30:12 +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
|
|
|
|
* 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.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2003-10-03 18:33:57 +00:00
|
|
|
#include "scumm/scumm.h"
|
|
|
|
#include "scumm/actor.h"
|
|
|
|
#include "scumm/akos.h"
|
|
|
|
#include "scumm/boxes.h"
|
|
|
|
#include "scumm/charset.h"
|
|
|
|
#include "scumm/costume.h"
|
|
|
|
#include "scumm/resource.h"
|
|
|
|
#include "scumm/saveload.h"
|
|
|
|
#include "scumm/sound.h"
|
|
|
|
#include "scumm/usage_bits.h"
|
|
|
|
|
|
|
|
namespace Scumm {
|
2002-05-14 23:35:28 +00:00
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
byte Actor::kInvalidBox = 0;
|
2003-10-02 22:42:03 +00:00
|
|
|
ScummEngine *Actor::_vm = 0;
|
2003-05-18 19:44:22 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void Actor::initActorClass(ScummEngine *scumm) {
|
2003-05-20 20:42:28 +00:00
|
|
|
_vm = scumm;
|
|
|
|
if (_vm->_features & GF_SMALL_HEADER) {
|
|
|
|
kInvalidBox = 255;
|
|
|
|
}
|
|
|
|
}
|
2003-05-18 19:44:22 +00:00
|
|
|
|
2003-07-27 23:45:43 +00:00
|
|
|
Actor::Actor() {
|
|
|
|
assert(_vm != 0);
|
2004-02-16 02:55:23 +00:00
|
|
|
offs_x = offs_y = 0;
|
2003-07-27 23:45:43 +00:00
|
|
|
top = bottom = 0;
|
|
|
|
number = 0;
|
|
|
|
needRedraw = needBgReset = costumeNeedsInit = visible = false;
|
|
|
|
flip = false;
|
|
|
|
speedx = 8;
|
|
|
|
speedy = 2;
|
|
|
|
frame = 0;
|
|
|
|
walkbox = 0;
|
|
|
|
animProgress = 0;
|
2004-01-12 14:09:39 +00:00
|
|
|
skipLimb = false;
|
2004-08-29 11:27:16 +00:00
|
|
|
drawToBackBuf = false;
|
2003-07-27 23:45:43 +00:00
|
|
|
memset(animVariable, 0, sizeof(animVariable));
|
|
|
|
memset(palette, 0, sizeof(palette));
|
|
|
|
memset(sound, 0, sizeof(sound));
|
|
|
|
memset(&cost, 0, sizeof(CostumeData));
|
|
|
|
memset(&walkdata, 0, sizeof(ActorWalkData));
|
2003-09-11 22:26:44 +00:00
|
|
|
walkdata.point3.x = 32000;
|
2003-07-27 23:45:43 +00:00
|
|
|
|
|
|
|
walkScript = 0;
|
|
|
|
|
|
|
|
initActor(1);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::initActor(int mode) {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (mode == 1) {
|
2002-05-14 19:11:20 +00:00
|
|
|
costume = 0;
|
|
|
|
room = 0;
|
2003-09-14 18:16:45 +00:00
|
|
|
_pos.x = 0;
|
|
|
|
_pos.y = 0;
|
2002-05-14 19:11:20 +00:00
|
|
|
facing = 180;
|
2004-09-09 02:21:48 +00:00
|
|
|
condMask = 1;
|
2004-09-11 12:22:06 +00:00
|
|
|
talkUnk = 0;
|
2004-02-21 11:37:52 +00:00
|
|
|
if (_vm->_version >= 7)
|
2004-02-21 11:41:46 +00:00
|
|
|
visible = false;
|
2004-09-21 05:59:26 +00:00
|
|
|
skipLimb = false;
|
2002-04-11 17:19:16 +00:00
|
|
|
} else if (mode == 2) {
|
2003-07-27 23:30:28 +00:00
|
|
|
facing = 180;
|
2004-09-09 02:21:48 +00:00
|
|
|
condMask = 1;
|
2004-09-21 05:59:26 +00:00
|
|
|
skipLimb = false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-05-14 19:11:20 +00:00
|
|
|
elevation = 0;
|
|
|
|
width = 24;
|
|
|
|
talkColor = 15;
|
2003-05-14 09:49:44 +00:00
|
|
|
talkPosX = 0;
|
|
|
|
talkPosY = -80;
|
2004-07-28 11:56:14 +00:00
|
|
|
boxscale = scaley = scalex = 0xFF;
|
2002-05-14 19:11:20 +00:00
|
|
|
charset = 0;
|
2003-03-07 02:43:21 +00:00
|
|
|
memset(sound, 0, sizeof(sound));
|
2003-07-24 17:44:00 +00:00
|
|
|
targetFacing = facing;
|
2002-05-14 19:11:20 +00:00
|
|
|
|
2004-07-10 23:32:31 +00:00
|
|
|
stopActorMoving();
|
2002-05-14 19:11:20 +00:00
|
|
|
|
|
|
|
shadow_mode = 0;
|
|
|
|
layer = 0;
|
|
|
|
|
|
|
|
setActorWalkSpeed(8, 2);
|
2002-12-06 08:14:22 +00:00
|
|
|
animSpeed = 0;
|
2004-02-21 11:37:52 +00:00
|
|
|
if (_vm->_version >= 6)
|
|
|
|
animProgress = 0;
|
2002-05-14 19:11:20 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
ignoreBoxes = false;
|
2004-02-18 04:21:19 +00:00
|
|
|
forceClip = (_vm->_version >= 7) ? 100 : 0;
|
2002-12-23 14:16:43 +00:00
|
|
|
ignoreTurns = false;
|
2004-07-04 03:12:02 +00:00
|
|
|
|
|
|
|
if (_vm->_features & GF_HUMONGOUS)
|
|
|
|
flip = 0;
|
2004-02-09 08:05:23 +00:00
|
|
|
|
2003-07-24 23:33:43 +00:00
|
|
|
talkFrequency = 256;
|
2003-09-03 17:00:33 +00:00
|
|
|
talkPan = 64;
|
2004-02-09 08:05:23 +00:00
|
|
|
talkVolume = 127;
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version <= 2) {
|
2003-05-20 20:42:28 +00:00
|
|
|
initFrame = 2;
|
|
|
|
walkFrame = 0;
|
|
|
|
standFrame = 1;
|
2003-05-22 09:58:33 +00:00
|
|
|
talkStartFrame = 5;
|
|
|
|
talkStopFrame = 4;
|
2003-05-20 20:42:28 +00:00
|
|
|
} else {
|
|
|
|
initFrame = 1;
|
|
|
|
walkFrame = 2;
|
|
|
|
standFrame = 3;
|
2003-05-22 09:58:33 +00:00
|
|
|
talkStartFrame = 4;
|
|
|
|
talkStopFrame = 5;
|
2003-05-20 20:42:28 +00:00
|
|
|
}
|
2002-05-14 19:11:20 +00:00
|
|
|
|
2004-08-29 11:27:16 +00:00
|
|
|
talking = false;
|
2003-05-31 14:27:47 +00:00
|
|
|
walkScript = 0;
|
|
|
|
talkScript = 0;
|
2002-05-14 19:11:20 +00:00
|
|
|
|
2004-09-04 10:29:06 +00:00
|
|
|
clipOverride = _vm->_actorClipOverride;
|
|
|
|
|
2004-09-18 00:36:17 +00:00
|
|
|
auxBlock.visible = false;
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
_vm->_classData[number] = (_vm->_version >= 7) ? _vm->_classData[0] : 0;
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::stopActorMoving() {
|
2004-07-11 10:47:25 +00:00
|
|
|
if (walkScript)
|
2003-09-11 22:00:36 +00:00
|
|
|
_vm->stopScript(walkScript);
|
2002-05-14 19:11:20 +00:00
|
|
|
moving = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::setActorWalkSpeed(uint newSpeedX, uint newSpeedY) {
|
2002-05-14 19:11:20 +00:00
|
|
|
if (newSpeedX == speedx && newSpeedY == speedy)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
speedx = newSpeedX;
|
|
|
|
speedy = newSpeedY;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
if (moving) {
|
2003-09-11 22:26:44 +00:00
|
|
|
calcMovementFactor(walkdata.next);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::getAngleFromPos(int x, int y) const {
|
2003-03-02 15:51:56 +00:00
|
|
|
if (_gameId == GID_DIG || _gameId == GID_CMI) {
|
2002-07-08 01:04:29 +00:00
|
|
|
double temp = atan2((double)x, (double)-y);
|
2002-07-22 18:11:48 +00:00
|
|
|
return normalizeAngle((int)(temp * 180 / 3.1415926535));
|
2001-11-26 19:57:57 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (abs(y) * 2 < abs(x)) {
|
|
|
|
if (x > 0)
|
2002-04-11 14:13:53 +00:00
|
|
|
return 90;
|
|
|
|
return 270;
|
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
if (y > 0)
|
2002-04-11 14:13:53 +00:00
|
|
|
return 180;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 17:43:02 +00:00
|
|
|
int Actor::calcMovementFactor(Common::Point next) {
|
2004-08-22 08:53:53 +00:00
|
|
|
Common::Point actorPos(_pos);
|
|
|
|
int diffX, diffY;
|
|
|
|
int32 deltaXFactor, deltaYFactor;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-08-22 08:53:53 +00:00
|
|
|
if (actorPos == next)
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
|
2004-08-22 08:53:53 +00:00
|
|
|
diffX = next.x - actorPos.x;
|
|
|
|
diffY = next.y - actorPos.y;
|
2004-08-21 22:33:23 +00:00
|
|
|
deltaYFactor = speedy << 16;
|
2004-08-22 08:53:53 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
if (diffY < 0)
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaYFactor = -deltaYFactor;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaXFactor = deltaYFactor * diffX;
|
2001-10-09 14:30:12 +00:00
|
|
|
if (diffY != 0) {
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaXFactor /= diffY;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaYFactor = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2004-08-22 08:53:53 +00:00
|
|
|
if ((uint) abs((int)(deltaXFactor >> 16)) > speedx) {
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaXFactor = speedx << 16;
|
2001-10-09 14:30:12 +00:00
|
|
|
if (diffX < 0)
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaXFactor = -deltaXFactor;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaYFactor = deltaXFactor * diffY;
|
2001-10-09 14:30:12 +00:00
|
|
|
if (diffX != 0) {
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaYFactor /= diffX;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2003-05-05 12:09:22 +00:00
|
|
|
deltaXFactor = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-22 08:53:53 +00:00
|
|
|
walkdata.cur = actorPos;
|
2003-09-11 22:26:44 +00:00
|
|
|
walkdata.next = next;
|
2003-05-05 12:09:22 +00:00
|
|
|
walkdata.deltaXFactor = deltaXFactor;
|
|
|
|
walkdata.deltaYFactor = deltaYFactor;
|
2002-05-14 19:11:20 +00:00
|
|
|
walkdata.xfrac = 0;
|
|
|
|
walkdata.yfrac = 0;
|
2002-03-06 09:40:21 +00:00
|
|
|
|
2003-07-24 17:44:00 +00:00
|
|
|
targetFacing = _vm->getAngleFromPos(deltaXFactor, deltaYFactor);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
return actorWalkStep();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Actor::remapDirection(int dir, bool is_walking) {
|
2001-11-26 19:57:57 +00:00
|
|
|
int specdir;
|
|
|
|
byte flags;
|
2002-05-11 14:55:03 +00:00
|
|
|
bool flipX;
|
|
|
|
bool flipY;
|
2002-07-07 19:31:51 +00:00
|
|
|
|
2003-05-03 16:20:18 +00:00
|
|
|
// FIXME - It seems that at least in The Dig the original code does
|
|
|
|
// check ignoreBoxes here. However, it breaks some animations in Loom,
|
|
|
|
// causing Bobbin to face towards the camera instead of away from it
|
|
|
|
// in some places: After the tree has been destroyed by lightning, and
|
|
|
|
// when entering the dark tunnels beyond the dragon's lair at the very
|
|
|
|
// least. Possibly other places as well.
|
|
|
|
//
|
|
|
|
// The Dig also checks if the actor is in the current room, but that's
|
|
|
|
// not necessary here because we never call the function unless the
|
|
|
|
// actor is in the current room anyway.
|
2003-03-08 13:29:41 +00:00
|
|
|
|
2003-08-08 11:32:40 +00:00
|
|
|
if (!ignoreBoxes || (_vm->_gameId == GID_LOOM || _vm->_gameId == GID_LOOM256)) {
|
2002-05-23 21:22:08 +00:00
|
|
|
specdir = _vm->_extraBoxFlags[walkbox];
|
2001-11-26 19:57:57 +00:00
|
|
|
if (specdir) {
|
|
|
|
if (specdir & 0x8000) {
|
|
|
|
dir = specdir & 0x3FFF;
|
|
|
|
} else {
|
2003-03-08 13:29:41 +00:00
|
|
|
specdir = specdir & 0x3FFF;
|
|
|
|
if (specdir - 90 < dir && dir < specdir + 90)
|
|
|
|
dir = specdir;
|
|
|
|
else
|
|
|
|
dir = specdir + 180;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-23 21:22:08 +00:00
|
|
|
flags = _vm->getBoxFlags(walkbox);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-05 12:09:22 +00:00
|
|
|
flipX = (walkdata.deltaXFactor > 0);
|
|
|
|
flipY = (walkdata.deltaYFactor > 0);
|
2001-12-29 12:45:54 +00:00
|
|
|
|
2003-11-07 02:11:41 +00:00
|
|
|
// FIXME - this special cases for the class might be necessary
|
2003-05-03 16:20:18 +00:00
|
|
|
// for other games besides Loom!
|
2002-08-15 22:54:32 +00:00
|
|
|
|
2002-05-11 14:55:03 +00:00
|
|
|
// Check for X-Flip
|
2003-05-20 20:42:28 +00:00
|
|
|
if ((flags & kBoxXFlip) || isInClass(kObjectClassXFlip)) {
|
2001-11-26 19:57:57 +00:00
|
|
|
dir = 360 - dir;
|
2002-05-11 14:55:03 +00:00
|
|
|
flipX = !flipX;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2002-05-11 14:55:03 +00:00
|
|
|
// Check for Y-Flip
|
2003-05-20 20:42:28 +00:00
|
|
|
if ((flags & kBoxYFlip) || isInClass(kObjectClassYFlip)) {
|
2001-11-26 19:57:57 +00:00
|
|
|
dir = 180 - dir;
|
2002-05-11 14:55:03 +00:00
|
|
|
flipY = !flipY;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
switch (flags & 7) {
|
2001-11-26 19:57:57 +00:00
|
|
|
case 1:
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version >= 7) {
|
2003-03-08 13:29:41 +00:00
|
|
|
if (dir < 180)
|
|
|
|
return 90;
|
|
|
|
else
|
|
|
|
return 270;
|
|
|
|
} else {
|
|
|
|
if (is_walking) // Actor is walking
|
|
|
|
return flipX ? 90 : 270;
|
|
|
|
else // Actor is standing/turning
|
|
|
|
return (dir == 90) ? 90 : 270;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
case 2:
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version >= 7) {
|
2003-03-08 13:29:41 +00:00
|
|
|
if (dir > 90 && dir < 270)
|
|
|
|
return 180;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
if (is_walking) // Actor is walking
|
|
|
|
return flipY ? 180 : 0;
|
|
|
|
else // Actor is standing/turning
|
|
|
|
return (dir == 0) ? 0 : 180;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
case 3:
|
|
|
|
return 270;
|
|
|
|
case 4:
|
|
|
|
return 90;
|
|
|
|
case 5:
|
|
|
|
return 0;
|
|
|
|
case 6:
|
|
|
|
return 180;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-08 04:11:02 +00:00
|
|
|
// OR 1024 in to signal direction interpolation should be done
|
2003-05-08 10:48:29 +00:00
|
|
|
return normalizeAngle(dir) | 1024;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Actor::updateActorDirection(bool is_walking) {
|
2003-03-08 04:11:02 +00:00
|
|
|
int from;
|
2001-12-27 17:51:58 +00:00
|
|
|
int dirType;
|
2002-05-10 21:35:53 +00:00
|
|
|
int dir;
|
|
|
|
bool shouldInterpolate;
|
2002-07-07 19:31:51 +00:00
|
|
|
|
2004-01-07 06:08:54 +00:00
|
|
|
if ((_vm->_version == 6) && ignoreTurns)
|
2004-01-05 06:53:03 +00:00
|
|
|
return facing;
|
|
|
|
|
2004-01-15 02:59:51 +00:00
|
|
|
dirType = (_vm->_version >= 7) ? _vm->akos_hasManyDirections(costume) : false;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2002-07-22 18:11:48 +00:00
|
|
|
from = toSimpleDir(dirType, facing);
|
2003-07-24 17:44:00 +00:00
|
|
|
dir = remapDirection(targetFacing, is_walking);
|
2003-03-08 04:11:02 +00:00
|
|
|
|
2004-01-15 02:59:51 +00:00
|
|
|
if (_vm->_version >= 7)
|
2002-12-15 21:54:47 +00:00
|
|
|
// Direction interpolation interfers with walk scripts in Dig; they perform
|
|
|
|
// (much better) interpolation themselves.
|
|
|
|
shouldInterpolate = false;
|
|
|
|
else
|
|
|
|
shouldInterpolate = (dir & 1024) ? true : false;
|
2003-03-08 04:11:02 +00:00
|
|
|
dir &= 1023;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2002-05-10 21:35:53 +00:00
|
|
|
if (shouldInterpolate) {
|
2003-03-08 04:11:02 +00:00
|
|
|
int to = toSimpleDir(dirType, dir);
|
|
|
|
int num = dirType ? 8 : 4;
|
|
|
|
|
2002-05-10 21:35:53 +00:00
|
|
|
// Turn left or right, depending on which is shorter.
|
2003-03-08 04:11:02 +00:00
|
|
|
int diff = to - from;
|
2002-05-10 21:35:53 +00:00
|
|
|
if (abs(diff) > (num >> 1))
|
|
|
|
diff = -diff;
|
2002-07-07 19:31:51 +00:00
|
|
|
|
2002-08-18 13:55:30 +00:00
|
|
|
if (diff > 0) {
|
|
|
|
to = from + 1;
|
|
|
|
} else if (diff < 0){
|
|
|
|
to = from - 1;
|
2002-05-10 21:35:53 +00:00
|
|
|
}
|
2002-07-07 19:31:51 +00:00
|
|
|
|
2003-03-08 04:11:02 +00:00
|
|
|
dir = fromSimpleDir(dirType, (to + num) % num);
|
|
|
|
}
|
2002-05-11 14:55:03 +00:00
|
|
|
|
|
|
|
return dir;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::setBox(int box) {
|
2002-05-14 19:11:20 +00:00
|
|
|
walkbox = box;
|
|
|
|
setupActorScale();
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int Actor::actorWalkStep() {
|
2001-11-26 19:57:57 +00:00
|
|
|
int tmpX, tmpY;
|
2003-10-02 17:43:02 +00:00
|
|
|
Common::Point actorPos;
|
2001-11-26 19:57:57 +00:00
|
|
|
int distX, distY;
|
2003-07-24 17:44:00 +00:00
|
|
|
int nextFacing;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
needRedraw = true;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-07-24 17:44:00 +00:00
|
|
|
nextFacing = updateActorDirection(true);
|
|
|
|
if (!(moving & MF_IN_LEG) || facing != nextFacing) {
|
|
|
|
if (walkFrame != frame || facing != nextFacing) {
|
|
|
|
startWalkAnim(1, nextFacing);
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2002-05-14 19:11:20 +00:00
|
|
|
moving |= MF_IN_LEG;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
actorPos = _pos;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
if (walkbox != walkdata.curbox && _vm->checkXYInBoxBounds(walkdata.curbox, actorPos.x, actorPos.y)) {
|
2002-07-18 15:45:10 +00:00
|
|
|
setBox(walkdata.curbox);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 22:26:44 +00:00
|
|
|
distX = abs(walkdata.next.x - walkdata.cur.x);
|
|
|
|
distY = abs(walkdata.next.y - walkdata.cur.y);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
if (abs(actorPos.x - walkdata.cur.x) >= distX && abs(actorPos.y - walkdata.cur.y) >= distY) {
|
2002-05-14 19:11:20 +00:00
|
|
|
moving &= ~MF_IN_LEG;
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
tmpX = (actorPos.x << 16) + walkdata.xfrac + (walkdata.deltaXFactor >> 8) * scalex;
|
2002-05-14 19:11:20 +00:00
|
|
|
walkdata.xfrac = (uint16)tmpX;
|
2003-09-14 18:16:45 +00:00
|
|
|
actorPos.x = (tmpX >> 16);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
tmpY = (actorPos.y << 16) + walkdata.yfrac + (walkdata.deltaYFactor >> 8) * scaley;
|
2002-05-14 19:11:20 +00:00
|
|
|
walkdata.yfrac = (uint16)tmpY;
|
2003-09-14 18:16:45 +00:00
|
|
|
actorPos.y = (tmpY >> 16);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
if (abs(actorPos.x - walkdata.cur.x) > distX) {
|
|
|
|
actorPos.x = walkdata.next.x;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
if (abs(actorPos.y - walkdata.cur.y) > distY) {
|
|
|
|
actorPos.y = walkdata.next.y;
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
_pos = actorPos;
|
2001-10-09 14:30:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::setupActorScale() {
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-07-22 20:53:01 +00:00
|
|
|
if (_vm->_features & GF_NO_SCALING) {
|
2002-05-14 19:11:20 +00:00
|
|
|
scalex = 0xFF;
|
|
|
|
scaley = 0xFF;
|
2002-02-15 13:11:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
if (ignoreBoxes)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-11-01 01:17:15 +00:00
|
|
|
// For some boxes, we ignore the scaling and use whatever values the
|
|
|
|
// scripts set. This is used e.g. in the Mystery Vortex in Sam&Max.
|
|
|
|
// Older games used the flag 0x20 differently, though.
|
2004-08-17 13:09:20 +00:00
|
|
|
if (_vm->_gameId == GID_SAMNMAX && (_vm->getBoxFlags(walkbox) & kBoxIgnoreScale))
|
2003-11-01 01:17:15 +00:00
|
|
|
return;
|
|
|
|
|
2004-07-28 11:56:14 +00:00
|
|
|
boxscale = _vm->getBoxScale(walkbox);
|
|
|
|
|
2003-11-01 01:17:15 +00:00
|
|
|
uint16 scale = _vm->getScale(walkbox, _pos.x, _pos.y);
|
2003-09-13 23:50:29 +00:00
|
|
|
assert(scale <= 0xFF);
|
2003-09-09 17:29:22 +00:00
|
|
|
|
2003-09-13 23:50:29 +00:00
|
|
|
scalex = scaley = (byte)scale;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::startAnimActor(int f) {
|
2004-07-04 03:12:02 +00:00
|
|
|
if (_vm->_version >= 7 && !((_vm->_gameId == GID_FT) && (_vm->_features & GF_DEMO) && (_vm->_features & GF_PC))) {
|
2002-10-23 00:22:55 +00:00
|
|
|
switch (f) {
|
2002-04-11 17:19:16 +00:00
|
|
|
case 1001:
|
2002-10-23 00:22:55 +00:00
|
|
|
f = initFrame;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case 1002:
|
2002-10-23 00:22:55 +00:00
|
|
|
f = walkFrame;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case 1003:
|
2002-10-23 00:22:55 +00:00
|
|
|
f = standFrame;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case 1004:
|
2003-05-22 09:58:33 +00:00
|
|
|
f = talkStartFrame;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
|
|
|
case 1005:
|
2003-05-22 09:58:33 +00:00
|
|
|
f = talkStopFrame;
|
2002-04-11 17:19:16 +00:00
|
|
|
break;
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
2004-01-15 02:59:51 +00:00
|
|
|
|
|
|
|
if (costume != 0) {
|
|
|
|
animProgress = 0;
|
|
|
|
needRedraw = true;
|
|
|
|
if (f == initFrame)
|
|
|
|
cost.reset();
|
|
|
|
_vm->akos_decodeData(this, f, (uint) - 1);
|
2004-07-18 04:24:03 +00:00
|
|
|
frame = f;
|
2004-01-15 02:59:51 +00:00
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
} else {
|
2002-10-23 00:22:55 +00:00
|
|
|
switch (f) {
|
2002-05-14 19:11:20 +00:00
|
|
|
case 0x38:
|
2002-10-23 00:22:55 +00:00
|
|
|
f = initFrame;
|
2002-05-14 19:11:20 +00:00
|
|
|
break;
|
|
|
|
case 0x39:
|
2002-10-23 00:22:55 +00:00
|
|
|
f = walkFrame;
|
2002-05-14 19:11:20 +00:00
|
|
|
break;
|
|
|
|
case 0x3A:
|
2002-10-23 00:22:55 +00:00
|
|
|
f = standFrame;
|
2002-05-14 19:11:20 +00:00
|
|
|
break;
|
|
|
|
case 0x3B:
|
2003-05-22 09:58:33 +00:00
|
|
|
f = talkStartFrame;
|
2002-05-14 19:11:20 +00:00
|
|
|
break;
|
|
|
|
case 0x3C:
|
2003-05-22 09:58:33 +00:00
|
|
|
f = talkStopFrame;
|
2002-05-14 19:11:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-12-28 12:51:18 +00:00
|
|
|
|
2002-12-15 21:54:47 +00:00
|
|
|
assert(f != 0x3E);
|
2002-11-10 12:59:36 +00:00
|
|
|
|
2003-01-06 13:41:29 +00:00
|
|
|
if (isInCurrentRoom() && costume != 0) {
|
2002-05-14 19:11:20 +00:00
|
|
|
animProgress = 0;
|
2003-06-01 18:20:38 +00:00
|
|
|
cost.animCounter = 0;
|
2002-05-14 19:11:20 +00:00
|
|
|
needRedraw = true;
|
2003-12-15 16:04:31 +00:00
|
|
|
// V1 - V2 games don't seem to need a cost.reset() at this point.
|
2003-12-15 16:05:40 +00:00
|
|
|
// Causes Zak to lose his body in several scenes, see bug #771508
|
2004-09-19 03:26:47 +00:00
|
|
|
if (_vm->_version >= 3 && f == initFrame) {
|
2002-05-23 00:37:00 +00:00
|
|
|
cost.reset();
|
2004-09-19 03:26:47 +00:00
|
|
|
auxBlock.visible = false;
|
|
|
|
}
|
2004-09-19 02:00:33 +00:00
|
|
|
if (_vm->_features & GF_NEW_COSTUMES)
|
2004-01-15 02:59:51 +00:00
|
|
|
_vm->akos_decodeData(this, f, (uint) - 1);
|
|
|
|
else
|
|
|
|
_vm->cost_decodeData(this, f, (uint) - 1);
|
2004-07-18 04:24:03 +00:00
|
|
|
frame = f;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::animateActor(int anim) {
|
2002-06-04 23:32:53 +00:00
|
|
|
int cmd, dir;
|
|
|
|
|
2004-07-04 03:12:02 +00:00
|
|
|
if (_vm->_version >= 7 && !((_vm->_gameId == GID_FT) && (_vm->_features & GF_DEMO) && (_vm->_features & GF_PC))) {
|
2002-06-04 23:32:53 +00:00
|
|
|
|
|
|
|
if (anim == 0xFF)
|
|
|
|
anim = 2000;
|
|
|
|
|
|
|
|
cmd = anim / 1000;
|
|
|
|
dir = anim % 1000;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2002-12-15 21:54:47 +00:00
|
|
|
cmd = anim / 4;
|
|
|
|
dir = oldDirToNewDir(anim % 4);
|
2002-06-04 23:32:53 +00:00
|
|
|
|
|
|
|
// Convert into old cmd code
|
|
|
|
cmd = 0x3F - cmd + 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
2002-12-15 21:54:47 +00:00
|
|
|
case 2: // stop walking
|
2004-07-11 10:47:25 +00:00
|
|
|
startAnimActor(standFrame);
|
2002-06-04 23:32:53 +00:00
|
|
|
stopActorMoving();
|
|
|
|
break;
|
2002-12-15 21:54:47 +00:00
|
|
|
case 3: // change direction immediatly
|
2002-06-04 23:32:53 +00:00
|
|
|
moving &= ~MF_TURN;
|
2002-07-18 15:45:10 +00:00
|
|
|
setDirection(dir);
|
2002-06-04 23:32:53 +00:00
|
|
|
break;
|
2002-12-15 21:54:47 +00:00
|
|
|
case 4: // turn to new direction
|
2002-06-04 23:32:53 +00:00
|
|
|
turnToDirection(dir);
|
|
|
|
break;
|
|
|
|
default:
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version <= 2)
|
2003-05-22 10:40:49 +00:00
|
|
|
startAnimActor(anim / 4);
|
|
|
|
else
|
|
|
|
startAnimActor(anim);
|
2002-06-04 23:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::setDirection(int direction) {
|
2002-05-14 19:11:20 +00:00
|
|
|
uint aMask;
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
uint16 vald;
|
|
|
|
|
2003-07-24 17:44:00 +00:00
|
|
|
// Do nothing if actor is already facing in the given direction
|
2002-05-14 19:11:20 +00:00
|
|
|
if (facing == direction)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-07-24 17:44:00 +00:00
|
|
|
// Normalize the angle
|
2002-07-22 18:11:48 +00:00
|
|
|
facing = normalizeAngle(direction);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-07-24 17:44:00 +00:00
|
|
|
// If there is no costume set for this actor, we are finished
|
2002-05-14 19:11:20 +00:00
|
|
|
if (costume == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2003-07-24 17:44:00 +00:00
|
|
|
// Update the costume for the new direction (and mark the actor for redraw)
|
2002-05-14 19:11:20 +00:00
|
|
|
aMask = 0x8000;
|
|
|
|
for (i = 0; i < 16; i++, aMask >>= 1) {
|
|
|
|
vald = cost.frame[i];
|
2002-04-11 17:19:16 +00:00
|
|
|
if (vald == 0xFFFF)
|
2001-11-26 19:57:57 +00:00
|
|
|
continue;
|
2003-02-17 21:40:13 +00:00
|
|
|
if (_vm->_features & GF_NEW_COSTUMES)
|
2002-05-23 21:22:08 +00:00
|
|
|
_vm->akos_decodeData(this, vald, aMask);
|
2002-04-11 17:19:16 +00:00
|
|
|
else
|
2002-05-23 21:22:08 +00:00
|
|
|
_vm->cost_decodeData(this, vald, aMask);
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
needRedraw = true;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::putActor(int dstX, int dstY, byte newRoom) {
|
2004-03-15 03:33:08 +00:00
|
|
|
if (visible && _vm->_currentRoom != newRoom && _vm->getTalkingActor() == number) {
|
2004-03-15 03:24:29 +00:00
|
|
|
_vm->stopTalk();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-06-06 10:01:26 +00:00
|
|
|
// HACK: The green transparency of the tank in the Hall of Oddities is
|
|
|
|
// is positioned one pixel too far to the left. This appears to be a
|
|
|
|
// bug in the original game as well.
|
|
|
|
|
|
|
|
if (_vm->_gameId == GID_SAMNMAX && newRoom == 16 && number == 5 && dstX == 235 && dstY == 236)
|
|
|
|
dstX++;
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
_pos.x = dstX;
|
|
|
|
_pos.y = dstY;
|
2002-07-18 15:45:10 +00:00
|
|
|
room = newRoom;
|
|
|
|
needRedraw = true;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-08 15:48:50 +00:00
|
|
|
if (_vm->VAR(_vm->VAR_EGO) == number) {
|
2002-07-18 15:45:10 +00:00
|
|
|
_vm->_egoPositioned = true;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-07-18 15:45:10 +00:00
|
|
|
if (visible) {
|
|
|
|
if (isInCurrentRoom()) {
|
|
|
|
if (moving) {
|
2004-07-10 23:32:31 +00:00
|
|
|
stopActorMoving();
|
2002-07-18 15:45:10 +00:00
|
|
|
startAnimActor(standFrame);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-07-18 15:45:10 +00:00
|
|
|
adjustActorPos();
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2004-09-19 02:00:33 +00:00
|
|
|
if (_vm->_heversion >= 71)
|
|
|
|
_vm->queueAuxBlock(this);
|
2002-07-18 15:45:10 +00:00
|
|
|
hideActor();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-07-18 15:45:10 +00:00
|
|
|
if (isInCurrentRoom())
|
|
|
|
showActor();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-26 02:26:13 +00:00
|
|
|
int Actor::getActorXYPos(int &xPos, int &yPos) const {
|
2002-07-16 18:51:27 +00:00
|
|
|
if (!isInCurrentRoom())
|
2002-04-11 20:10:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
xPos = _pos.x;
|
|
|
|
yPos = _pos.y;
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-20 19:35:40 +00:00
|
|
|
AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
|
2003-05-18 19:44:22 +00:00
|
|
|
const uint thresholdTable[] = { 30, 80, 0 };
|
2003-07-02 13:47:03 +00:00
|
|
|
AdjustBoxResult abr;
|
|
|
|
int16 tmpX, tmpY;
|
|
|
|
int tmpDist, bestDist, threshold, numBoxes;
|
2003-05-18 19:44:22 +00:00
|
|
|
byte flags, bestBox;
|
2003-07-02 13:47:03 +00:00
|
|
|
int box;
|
2003-05-18 19:44:22 +00:00
|
|
|
const int firstValidBox = (_vm->_features & GF_SMALL_HEADER) ? 0 : 1;
|
2002-03-11 08:34:12 +00:00
|
|
|
|
2002-05-14 23:35:28 +00:00
|
|
|
abr.x = dstX;
|
|
|
|
abr.y = dstY;
|
2003-07-02 13:47:03 +00:00
|
|
|
abr.box = kInvalidBox;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
if (ignoreBoxes)
|
|
|
|
return abr;
|
2002-02-12 18:20:37 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
for (int tIdx = 0; tIdx < ARRAYSIZE(thresholdTable); tIdx++) {
|
|
|
|
threshold = thresholdTable[tIdx];
|
2002-03-26 05:23:06 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
numBoxes = _vm->getNumBoxes() - 1;
|
|
|
|
if (numBoxes < firstValidBox)
|
|
|
|
return abr;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-07-12 17:53:22 +00:00
|
|
|
bestDist = 0xFFFF;
|
|
|
|
if (_vm->_version <= 2)
|
|
|
|
bestDist *= 8*2; // Adjust for the fact that we multiply x by 8 and y by 2
|
2003-05-20 20:42:28 +00:00
|
|
|
bestBox = kInvalidBox;
|
2002-08-15 16:46:29 +00:00
|
|
|
|
2003-05-20 23:05:34 +00:00
|
|
|
// We iterate (backwards) over all boxes, searching the one closest
|
2003-05-18 19:44:22 +00:00
|
|
|
// to the desired coordinates.
|
|
|
|
for (box = numBoxes; box >= firstValidBox; box--) {
|
|
|
|
flags = _vm->getBoxFlags(box);
|
2002-08-15 16:46:29 +00:00
|
|
|
|
2003-05-20 23:05:34 +00:00
|
|
|
// Skip over invisible boxes
|
2003-05-22 00:51:42 +00:00
|
|
|
if (flags & kBoxInvisible && !(flags & kBoxPlayerOnly && !isPlayer()))
|
2003-05-18 19:44:22 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// For increased performance, we perform a quick test if
|
|
|
|
// the coordinates can even be within a distance of 'threshold'
|
|
|
|
// pixels of the box.
|
2003-07-02 13:47:03 +00:00
|
|
|
if (threshold > 0 && _vm->inBoxQuickReject(box, dstX, dstY, threshold))
|
2003-05-18 19:44:22 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check if the point is contained in the box. If it is,
|
|
|
|
// we don't have to search anymore.
|
|
|
|
if (_vm->checkXYInBoxBounds(box, dstX, dstY)) {
|
|
|
|
abr.x = dstX;
|
|
|
|
abr.y = dstY;
|
2003-07-02 13:47:03 +00:00
|
|
|
abr.box = box;
|
2003-05-18 19:44:22 +00:00
|
|
|
return abr;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
// Find the point in the box which is closest to our point.
|
2003-07-02 13:47:03 +00:00
|
|
|
tmpDist = _vm->getClosestPtOnBox(box, dstX, dstY, tmpX, tmpY);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
// Check if the box is closer than the previous boxes.
|
2003-07-02 13:47:03 +00:00
|
|
|
if (tmpDist < bestDist) {
|
|
|
|
abr.x = tmpX;
|
|
|
|
abr.y = tmpY;
|
2003-05-18 19:44:22 +00:00
|
|
|
|
2003-07-02 13:47:03 +00:00
|
|
|
if (tmpDist == 0) {
|
|
|
|
abr.box = box;
|
2002-07-27 20:11:02 +00:00
|
|
|
return abr;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-07-02 13:47:03 +00:00
|
|
|
bestDist = tmpDist;
|
2003-05-18 19:44:22 +00:00
|
|
|
bestBox = box;
|
2002-07-27 20:11:02 +00:00
|
|
|
}
|
2003-05-18 19:44:22 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
// If the closest ('best') box we found is within the threshold, or if
|
|
|
|
// we are on the last run (i.e. threshold == 0), return that box.
|
|
|
|
if (threshold == 0 || threshold * threshold >= bestDist) {
|
2003-07-02 13:47:03 +00:00
|
|
|
abr.box = bestBox;
|
2003-05-18 19:44:22 +00:00
|
|
|
return abr;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-15 18:11:30 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
return abr;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::adjustActorPos() {
|
2001-10-09 14:30:12 +00:00
|
|
|
AdjustBoxResult abr;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
abr = adjustXYToBeInBox(_pos.x, _pos.y);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
_pos.x = abr.x;
|
|
|
|
_pos.y = abr.y;
|
2003-07-02 13:47:03 +00:00
|
|
|
walkdata.destbox = abr.box;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-07-02 13:47:03 +00:00
|
|
|
setBox(abr.box);
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-09-11 22:26:44 +00:00
|
|
|
walkdata.dest.x = -1;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2004-07-10 23:32:31 +00:00
|
|
|
stopActorMoving();
|
2003-06-01 18:20:38 +00:00
|
|
|
cost.soundCounter = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
if (walkbox != kInvalidBox) {
|
2003-05-18 19:44:22 +00:00
|
|
|
byte flags = _vm->getBoxFlags(walkbox);
|
|
|
|
if (flags & 7) {
|
|
|
|
turnToDirection(facing);
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-20 17:11:13 +00:00
|
|
|
void Actor::faceToObject(int obj) {
|
2003-01-01 18:22:41 +00:00
|
|
|
int x2, y2, dir;
|
|
|
|
|
|
|
|
if (!isInCurrentRoom())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_vm->getObjectOrActorXY(obj, x2, y2) == -1)
|
|
|
|
return;
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
dir = (x2 > _pos.x) ? 90 : 270;
|
2003-01-01 18:22:41 +00:00
|
|
|
turnToDirection(dir);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::turnToDirection(int newdir) {
|
2004-01-07 06:08:54 +00:00
|
|
|
if (newdir == -1 || ignoreTurns)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
moving &= ~MF_TURN;
|
|
|
|
|
|
|
|
if (newdir != facing) {
|
2003-07-01 12:08:22 +00:00
|
|
|
if (_vm->_version <= 3)
|
|
|
|
moving = MF_TURN;
|
|
|
|
else
|
|
|
|
moving |= MF_TURN;
|
2003-07-24 17:44:00 +00:00
|
|
|
targetFacing = newdir;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::hideActor() {
|
2002-05-14 19:11:20 +00:00
|
|
|
if (!visible)
|
2001-11-26 19:57:57 +00:00
|
|
|
return;
|
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
if (moving) {
|
2004-07-10 23:32:31 +00:00
|
|
|
stopActorMoving();
|
2002-05-14 19:11:20 +00:00
|
|
|
startAnimActor(standFrame);
|
2001-11-26 19:57:57 +00:00
|
|
|
}
|
2002-05-14 19:11:20 +00:00
|
|
|
visible = false;
|
2003-06-01 18:20:38 +00:00
|
|
|
cost.soundCounter = 0;
|
2002-05-14 19:11:20 +00:00
|
|
|
needRedraw = false;
|
|
|
|
needBgReset = true;
|
2004-09-19 02:00:33 +00:00
|
|
|
auxBlock.visible = false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::showActor() {
|
2002-05-23 21:22:08 +00:00
|
|
|
if (_vm->_currentRoom == 0 || visible)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
|
2002-11-18 00:35:21 +00:00
|
|
|
adjustActorPos();
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-23 21:22:08 +00:00
|
|
|
_vm->ensureResourceLoaded(rtCostume, costume);
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
if (costumeNeedsInit) {
|
|
|
|
startAnimActor(initFrame);
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version <= 2) {
|
2003-05-17 18:07:07 +00:00
|
|
|
startAnimActor(standFrame);
|
2003-05-22 09:58:33 +00:00
|
|
|
startAnimActor(talkStopFrame);
|
2003-05-22 09:52:21 +00:00
|
|
|
}
|
2002-05-14 19:11:20 +00:00
|
|
|
costumeNeedsInit = false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-09-12 00:42:36 +00:00
|
|
|
|
|
|
|
// FIXME: Evil hack to work around bug #770717
|
|
|
|
if (!moving && _vm->_version <= 2)
|
|
|
|
startAnimActor(standFrame);
|
|
|
|
|
2004-07-10 23:32:31 +00:00
|
|
|
stopActorMoving();
|
2002-05-14 19:11:20 +00:00
|
|
|
visible = true;
|
|
|
|
needRedraw = true;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2004-01-16 10:51:48 +00:00
|
|
|
// V1 Maniac doesn't have a ScummVar for VAR_TALK_ACTOR, and just uses
|
2004-01-16 10:45:56 +00:00
|
|
|
// an internal variable. Emulate this to prevent overwriting script vars...
|
2004-03-15 03:33:08 +00:00
|
|
|
int ScummEngine::getTalkingActor() {
|
2004-01-16 10:51:48 +00:00
|
|
|
if (_gameId == GID_MANIAC && _version == 1)
|
2004-01-16 10:45:56 +00:00
|
|
|
return _V1_talkingActor;
|
|
|
|
else
|
|
|
|
return VAR(VAR_TALK_ACTOR);
|
2004-03-16 23:51:41 +00:00
|
|
|
}
|
2004-01-16 10:45:56 +00:00
|
|
|
|
2004-03-15 03:33:08 +00:00
|
|
|
void ScummEngine::setTalkingActor(int value) {
|
2004-01-16 10:51:48 +00:00
|
|
|
if (_gameId == GID_MANIAC && _version == 1)
|
2004-01-16 10:45:56 +00:00
|
|
|
_V1_talkingActor = value;
|
|
|
|
else
|
|
|
|
VAR(VAR_TALK_ACTOR) = value;
|
2004-03-16 23:51:41 +00:00
|
|
|
}
|
2004-01-16 10:45:56 +00:00
|
|
|
|
2004-07-05 06:25:01 +00:00
|
|
|
void ScummEngine::putActors() {
|
|
|
|
Actor *a;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < _numActors; i++) {
|
|
|
|
a = &_actors[i];
|
|
|
|
if (a && a->isInCurrentRoom())
|
|
|
|
a->putActor(a->_pos.x, a->_pos.y, a->room);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-26 15:14:10 +00:00
|
|
|
static const int v1MMActorTalkColor[25] = {
|
|
|
|
1, 7, 2, 14, 8, 1, 3, 7, 7, 12, 1, 13, 1, 4, 5, 5, 4, 3, 1, 5, 1, 1, 1, 7, 7
|
|
|
|
};
|
|
|
|
|
|
|
|
void ScummEngine::setupV1ActorTalkColor() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < _numActors; i++)
|
|
|
|
_actors[i].talkColor = v1MMActorTalkColor[i];
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::showActors() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
for (i = 1; i < _numActors; i++) {
|
2003-05-23 12:48:50 +00:00
|
|
|
if (_actors[i].isInCurrentRoom())
|
|
|
|
_actors[i].showActor();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::walkActors() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-02-22 16:06:09 +00:00
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
for (i = 1; i < _numActors; i++) {
|
2003-05-23 12:48:50 +00:00
|
|
|
if (_actors[i].isInCurrentRoom())
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version <= 3)
|
2003-05-23 12:48:50 +00:00
|
|
|
_actors[i].walkActorOld();
|
2002-04-11 17:19:16 +00:00
|
|
|
else
|
2003-05-23 12:48:50 +00:00
|
|
|
_actors[i].walkActor();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-23 19:51:50 +00:00
|
|
|
/* Used in Scumm v5 only. Play sounds associated with actors */
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::playActorSounds() {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
for (i = 1; i < _numActors; i++) {
|
2003-06-01 18:20:38 +00:00
|
|
|
if (_actors[i].cost.soundCounter && _actors[i].isInCurrentRoom() && _actors[i].sound) {
|
2001-10-09 14:30:12 +00:00
|
|
|
_currentScript = 0xFF;
|
2003-05-23 12:48:50 +00:00
|
|
|
_sound->addSoundToQueue(_actors[i].sound[0]);
|
2003-05-13 23:42:41 +00:00
|
|
|
for (i = 1; i < _numActors; i++) {
|
2003-06-01 18:20:38 +00:00
|
|
|
_actors[i].cost.soundCounter = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
Actor *ScummEngine::derefActor(int id, const char *errmsg) const {
|
2003-08-12 16:43:43 +00:00
|
|
|
if (id == 0)
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_ACTORS, "derefActor(0, \"%s\") in script %d, opcode 0x%x",
|
|
|
|
errmsg, vm.slot[_curExecScript].number, _opcode);
|
|
|
|
|
2003-08-12 16:43:43 +00:00
|
|
|
if (id < 0 || id >= _numActors || _actors[id].number != id) {
|
2003-07-19 18:18:01 +00:00
|
|
|
if (errmsg)
|
|
|
|
error("Invalid actor %d in %s", id, errmsg);
|
|
|
|
else
|
|
|
|
error("Invalid actor %d", id);
|
|
|
|
}
|
|
|
|
return &_actors[id];
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
Actor *ScummEngine::derefActorSafe(int id, const char *errmsg) const {
|
2003-08-12 16:43:43 +00:00
|
|
|
if (id == 0)
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_ACTORS, "derefActorSafe(0, \"%s\") in script %d, opcode 0x%x",
|
|
|
|
errmsg, vm.slot[_curExecScript].number, _opcode);
|
|
|
|
|
2003-08-12 16:43:43 +00:00
|
|
|
if (id < 0 || id >= _numActors || _actors[id].number != id) {
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_ACTORS, "Invalid actor %d in %s (script %d, opcode 0x%x)",
|
2003-07-19 18:18:01 +00:00
|
|
|
id, errmsg, vm.slot[_curExecScript].number, _opcode);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &_actors[id];
|
|
|
|
}
|
|
|
|
|
2003-07-02 11:32:32 +00:00
|
|
|
static int compareDrawOrder(const void* a, const void* b)
|
2003-06-05 03:19:07 +00:00
|
|
|
{
|
2003-06-05 09:54:57 +00:00
|
|
|
const Actor* actor1 = *(const Actor *const*)a;
|
|
|
|
const Actor* actor2 = *(const Actor *const*)b;
|
2003-07-02 11:32:32 +00:00
|
|
|
int diff;
|
|
|
|
|
|
|
|
// The actor in the higher layer is ordered lower
|
|
|
|
diff = actor1->layer - actor2->layer;
|
|
|
|
if (diff < 0)
|
|
|
|
return +1;
|
|
|
|
if (diff > 0)
|
|
|
|
return -1;
|
2003-06-21 15:10:30 +00:00
|
|
|
|
2003-07-02 11:32:32 +00:00
|
|
|
// The actor with higher y value is ordered higher
|
2003-09-14 18:16:45 +00:00
|
|
|
diff = actor1->_pos.y - actor2->_pos.y;
|
2003-07-02 11:32:32 +00:00
|
|
|
if (diff < 0)
|
|
|
|
return -1;
|
|
|
|
if (diff > 0)
|
|
|
|
return +1;
|
|
|
|
|
2004-07-18 23:41:49 +00:00
|
|
|
// FIXME: This hack works around bug #775097. It's probably wrong, though :-/
|
|
|
|
// Would be interesting if somebody could check the disassembly (see also the
|
|
|
|
// comment on the above mentioned tracker item).
|
|
|
|
if (g_scumm->_gameId == GID_TENTACLE) {
|
|
|
|
diff = actor1->forceClip - actor2->forceClip;
|
|
|
|
if (diff < 0)
|
|
|
|
return -1;
|
|
|
|
if (diff > 0)
|
|
|
|
return +1;
|
|
|
|
}
|
|
|
|
|
2003-07-02 11:32:32 +00:00
|
|
|
// The qsort() function is not guaranteed to be stable (i.e. it may
|
|
|
|
// re-order "equal" elements in an array it sorts). Hence we use the
|
2003-06-21 15:10:30 +00:00
|
|
|
// actor number as tie-breaker. This is needed for the Sam & Max intro,
|
|
|
|
// and possibly other cases as well. See bug #758167.
|
|
|
|
|
2003-07-02 11:32:32 +00:00
|
|
|
return actor1->number - actor2->number;
|
2003-06-05 03:19:07 +00:00
|
|
|
}
|
2002-06-07 16:54:11 +00:00
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::processActors() {
|
2004-08-28 14:05:33 +00:00
|
|
|
if (_skipProcessActors)
|
|
|
|
return;
|
|
|
|
|
2002-06-07 16:54:11 +00:00
|
|
|
int numactors = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2003-06-05 15:31:34 +00:00
|
|
|
// TODO : put this actors as a member array. It never has to grow or shrink
|
|
|
|
// since _numActors is constant within a game.
|
2003-06-05 03:19:07 +00:00
|
|
|
Actor** actors = new Actor * [_numActors];
|
2002-12-25 00:31:39 +00:00
|
|
|
|
2002-06-01 21:45:15 +00:00
|
|
|
// Make a list of all actors in this room
|
2003-06-05 03:19:07 +00:00
|
|
|
for (int i = 1; i < _numActors; i++) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_version == 8 && _actors[i].layer < 0)
|
2003-02-27 10:17:29 +00:00
|
|
|
continue;
|
2004-01-05 16:19:14 +00:00
|
|
|
if (_actors[i].isInCurrentRoom() && _actors[i].costume)
|
2003-05-23 12:48:50 +00:00
|
|
|
actors[numactors++] = &_actors[i];
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-12-25 00:31:39 +00:00
|
|
|
if (!numactors) {
|
|
|
|
delete [] actors;
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2002-12-25 00:31:39 +00:00
|
|
|
}
|
2002-07-07 19:31:51 +00:00
|
|
|
|
2002-06-01 21:45:15 +00:00
|
|
|
// Sort actors by position before we draw them (to ensure that actors in
|
2002-06-04 23:32:53 +00:00
|
|
|
// front are drawn after those "behind" them).
|
2003-07-02 11:32:32 +00:00
|
|
|
qsort(actors, numactors, sizeof (Actor*), compareDrawOrder);
|
2003-06-05 03:19:07 +00:00
|
|
|
|
|
|
|
Actor** end = actors + numactors;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-06-07 16:54:11 +00:00
|
|
|
// Finally draw the now sorted actors
|
2003-06-05 03:19:07 +00:00
|
|
|
for (Actor** ac = actors; ac != end; ++ac) {
|
|
|
|
Actor* a = *ac;
|
2004-01-05 16:19:14 +00:00
|
|
|
CHECK_HEAP
|
|
|
|
a->drawActorCostume();
|
|
|
|
CHECK_HEAP
|
|
|
|
a->animateCostume();
|
2002-06-07 16:54:11 +00:00
|
|
|
}
|
2002-12-25 00:31:39 +00:00
|
|
|
|
|
|
|
delete [] actors;
|
2004-08-28 03:18:52 +00:00
|
|
|
|
|
|
|
if (_features & GF_NEW_COSTUMES)
|
|
|
|
akos_processQueue();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-02-27 10:17:29 +00:00
|
|
|
// Used in Scumm v8, to allow the verb coin to be drawn over the inventory
|
|
|
|
// chest. I'm assuming that draw order won't matter here.
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::processUpperActors() {
|
2003-02-27 10:17:29 +00:00
|
|
|
int i;
|
|
|
|
|
2003-05-13 23:42:41 +00:00
|
|
|
for (i = 1; i < _numActors; i++) {
|
2003-05-23 12:48:50 +00:00
|
|
|
if (_actors[i].isInCurrentRoom() && _actors[i].costume && _actors[i].layer < 0) {
|
2003-05-18 19:44:22 +00:00
|
|
|
CHECK_HEAP
|
2003-05-23 12:48:50 +00:00
|
|
|
_actors[i].drawActorCostume();
|
2003-05-18 19:44:22 +00:00
|
|
|
CHECK_HEAP
|
2003-05-23 12:48:50 +00:00
|
|
|
_actors[i].animateCostume();
|
2003-02-27 10:17:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-03 19:54:58 +00:00
|
|
|
void Actor::drawActorCostume(bool hitTestMode) {
|
|
|
|
if (!hitTestMode) {
|
|
|
|
if (!needRedraw)
|
|
|
|
return;
|
|
|
|
|
|
|
|
needRedraw = false;
|
|
|
|
}
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2002-07-15 22:56:24 +00:00
|
|
|
setupActorScale();
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2003-06-14 13:38:22 +00:00
|
|
|
BaseCostumeRenderer* bcr = _vm->_costumeRenderer;
|
2003-05-20 12:25:47 +00:00
|
|
|
|
2004-01-05 16:19:14 +00:00
|
|
|
bcr->_actorID = number;
|
2003-05-20 12:25:47 +00:00
|
|
|
|
2004-02-16 02:55:23 +00:00
|
|
|
bcr->_actorX = _pos.x + offs_x - _vm->virtscr[0].xstart;
|
|
|
|
bcr->_actorY = _pos.y + offs_y - elevation;
|
2003-07-12 17:53:22 +00:00
|
|
|
|
2003-08-25 20:57:36 +00:00
|
|
|
if (_vm->_version <= 2) {
|
|
|
|
// HACK: We have to adjust the x position by one strip (8 pixels) in
|
|
|
|
// V2 games. However, it is not quite clear to me why. And to fully
|
|
|
|
// match the original, it seems we have to offset by 2 strips if the
|
|
|
|
// actor is facing left (270 degree).
|
|
|
|
// V1 games are once again slightly different, here we only have
|
|
|
|
// to adjust the 270 degree case...
|
2003-07-12 17:53:22 +00:00
|
|
|
if (facing == 270)
|
|
|
|
bcr->_actorX += 16;
|
2003-08-25 20:57:36 +00:00
|
|
|
else if (_vm->_version == 2)
|
2003-07-12 17:53:22 +00:00
|
|
|
bcr->_actorX += 8;
|
2003-07-02 14:23:45 +00:00
|
|
|
}
|
2003-07-12 17:53:22 +00:00
|
|
|
|
2004-09-04 00:18:55 +00:00
|
|
|
bcr->_clipOverride = clipOverride;
|
|
|
|
|
2004-07-28 11:56:14 +00:00
|
|
|
if (_vm->_version == 4 && boxscale & 0x8000) {
|
|
|
|
bcr->_scaleX = bcr->_scaleY = _vm->getScale(walkbox, _pos.x, _pos.y);
|
|
|
|
} else {
|
|
|
|
bcr->_scaleX = scalex;
|
|
|
|
bcr->_scaleY = scaley;
|
|
|
|
}
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2003-05-20 12:25:47 +00:00
|
|
|
bcr->_shadow_mode = shadow_mode;
|
|
|
|
if (_vm->_features & GF_SMALL_HEADER)
|
|
|
|
bcr->_shadow_table = NULL;
|
2004-06-27 15:41:01 +00:00
|
|
|
else if (_vm->_heversion == 70)
|
2004-07-11 09:15:14 +00:00
|
|
|
bcr->_shadow_table = _vm->_HEV7ActorPalette;
|
2003-05-20 12:25:47 +00:00
|
|
|
else
|
|
|
|
bcr->_shadow_table = _vm->_shadowPalette;
|
|
|
|
|
|
|
|
bcr->setCostume(costume);
|
|
|
|
bcr->setPalette(palette);
|
|
|
|
bcr->setFacing(this);
|
|
|
|
|
2004-01-15 02:59:51 +00:00
|
|
|
if (_vm->_version >= 7) {
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2004-01-11 08:39:39 +00:00
|
|
|
bcr->_zbuf = forceClip;
|
2004-01-11 08:59:51 +00:00
|
|
|
if (bcr->_zbuf == 100) {
|
2003-05-29 17:14:47 +00:00
|
|
|
bcr->_zbuf = _vm->getMaskFromBox(walkbox);
|
2003-08-25 20:05:02 +00:00
|
|
|
if (bcr->_zbuf > _vm->gdi._numZBuffer-1)
|
|
|
|
bcr->_zbuf = _vm->gdi._numZBuffer-1;
|
2003-05-18 19:44:22 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-01-11 08:39:39 +00:00
|
|
|
} else {
|
|
|
|
if (forceClip)
|
|
|
|
bcr->_zbuf = forceClip;
|
|
|
|
else if (isInClass(kObjectClassNeverClip))
|
|
|
|
bcr->_zbuf = 0;
|
|
|
|
else {
|
2003-05-29 17:14:47 +00:00
|
|
|
bcr->_zbuf = _vm->getMaskFromBox(walkbox);
|
2003-08-25 20:05:02 +00:00
|
|
|
if (bcr->_zbuf > _vm->gdi._numZBuffer-1)
|
|
|
|
bcr->_zbuf = _vm->gdi._numZBuffer-1;
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-05-28 21:43:34 +00:00
|
|
|
}
|
2003-01-05 23:53:16 +00:00
|
|
|
|
2004-09-03 19:54:58 +00:00
|
|
|
bcr->_draw_top = 0x7fffffff;
|
|
|
|
bcr->_draw_bottom = 0;
|
2004-09-03 15:39:14 +00:00
|
|
|
|
2004-01-12 14:09:39 +00:00
|
|
|
bcr->_skipLimb = (skipLimb != 0);
|
2004-08-10 23:54:15 +00:00
|
|
|
|
2004-09-11 12:22:06 +00:00
|
|
|
if (_vm->_heversion >= 80 && talkUnk == 0) {
|
|
|
|
condMask &= 0xFFFFFC00;
|
2004-09-12 02:05:12 +00:00
|
|
|
condMask |= 1;
|
|
|
|
if (_vm->getTalkingActor() == number) {
|
2004-09-11 12:22:06 +00:00
|
|
|
// Checks if talk sound is active?
|
|
|
|
// Otherwise just do rand animation
|
|
|
|
int rnd = _vm->_rnd.getRandomNumberRng(1, 10);
|
2004-09-12 02:05:12 +00:00
|
|
|
setTalkCondition(rnd);
|
2004-09-11 12:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-11 12:55:50 +00:00
|
|
|
talkUnk = 0;
|
2004-09-11 12:22:06 +00:00
|
|
|
|
2003-05-28 21:43:34 +00:00
|
|
|
// If the actor is partially hidden, redraw it next frame.
|
2003-05-31 16:09:09 +00:00
|
|
|
// Only done for pre-AKOS, though.
|
2004-09-08 21:14:12 +00:00
|
|
|
if (bcr->drawCostume(_vm->virtscr[0], this, drawToBackBuf) & 1) {
|
2004-02-06 14:16:14 +00:00
|
|
|
needRedraw = (_vm->_version <= 6);
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
2003-05-20 12:25:47 +00:00
|
|
|
|
2004-09-03 19:54:58 +00:00
|
|
|
if (!hitTestMode) {
|
|
|
|
// Record the vertical extent of the drawn actor
|
|
|
|
top = bcr->_draw_top;
|
|
|
|
bottom = bcr->_draw_bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Actor::actorHitTest(int x, int y) {
|
|
|
|
AkosRenderer *ar = (AkosRenderer *)_vm->_costumeRenderer;
|
|
|
|
|
|
|
|
ar->_actorHitX = x;
|
|
|
|
ar->_actorHitY = y;
|
|
|
|
ar->_actorHitMode = true;
|
|
|
|
ar->_actorHitResult = false;
|
|
|
|
|
|
|
|
drawActorCostume(true);
|
|
|
|
|
|
|
|
ar->_actorHitMode = false;
|
|
|
|
|
|
|
|
return ar->_actorHitResult;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::animateCostume() {
|
2002-05-23 00:37:00 +00:00
|
|
|
if (costume == 0)
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-05-23 00:37:00 +00:00
|
|
|
animProgress++;
|
|
|
|
if (animProgress >= animSpeed) {
|
|
|
|
animProgress = 0;
|
2001-11-26 19:57:57 +00:00
|
|
|
|
2003-02-17 21:40:13 +00:00
|
|
|
if (_vm->_features & GF_NEW_COSTUMES) {
|
2002-05-23 21:22:08 +00:00
|
|
|
byte *akos = _vm->getResourceAddress(rtCostume, costume);
|
2002-03-05 23:05:55 +00:00
|
|
|
assert(akos);
|
2002-05-23 21:22:08 +00:00
|
|
|
if (_vm->akos_increaseAnims(akos, this)) {
|
2002-05-23 00:37:00 +00:00
|
|
|
needRedraw = true;
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-07-15 22:56:24 +00:00
|
|
|
LoadedCostume lc(_vm);
|
|
|
|
lc.loadCostume(costume);
|
|
|
|
if (lc.increaseAnims(this)) {
|
2002-05-23 00:37:00 +00:00
|
|
|
needRedraw = true;
|
2002-03-05 23:05:55 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::animateLimb(int limb, int f) {
|
2003-01-06 16:04:01 +00:00
|
|
|
// This methods is very similiar to animateCostume().
|
|
|
|
// However, instead of animating *all* the limbs, it only animates
|
|
|
|
// the specified limb to be at the frame specified by "f".
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
animProgress++;
|
|
|
|
if (animProgress >= animSpeed) {
|
|
|
|
animProgress = 0;
|
|
|
|
|
|
|
|
if (costume == 0)
|
|
|
|
return;
|
|
|
|
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *aksq, *akfo;
|
2003-01-06 16:04:01 +00:00
|
|
|
uint size;
|
|
|
|
byte *akos = _vm->getResourceAddress(rtCostume, costume);
|
|
|
|
assert(akos);
|
|
|
|
|
|
|
|
aksq = _vm->findResourceData(MKID('AKSQ'), akos);
|
|
|
|
akfo = _vm->findResourceData(MKID('AKFO'), akos);
|
|
|
|
|
2003-11-16 20:52:57 +00:00
|
|
|
size = _vm->getResourceDataSize(akfo) / 2;
|
2003-01-06 16:04:01 +00:00
|
|
|
|
|
|
|
while (f--) {
|
|
|
|
if (cost.active[limb] != 0)
|
2003-05-28 20:01:47 +00:00
|
|
|
_vm->akos_increaseAnim(this, limb, aksq, (const uint16 *)akfo, size);
|
2003-01-06 16:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// needRedraw = true;
|
|
|
|
// needBgReset = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::setActorRedrawFlags() {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i, j;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-06-07 16:54:11 +00:00
|
|
|
if (_fullRedraw) {
|
2003-05-13 23:42:41 +00:00
|
|
|
for (j = 1; j < _numActors; j++) {
|
2003-05-30 00:55:21 +00:00
|
|
|
_actors[j].needRedraw = true;
|
2002-06-07 16:54:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-10-24 06:28:54 +00:00
|
|
|
for (i = 0; i < gdi._numStrips; i++) {
|
2003-01-14 10:06:56 +00:00
|
|
|
int strip = _screenStartStrip + i;
|
|
|
|
if (testGfxAnyUsageBits(strip)) {
|
2003-05-13 23:42:41 +00:00
|
|
|
for (j = 1; j < _numActors; j++) {
|
2003-01-14 10:06:56 +00:00
|
|
|
if (testGfxUsageBit(strip, j) && testGfxOtherUsageBits(strip, j)) {
|
2003-05-30 00:55:21 +00:00
|
|
|
_actors[j].needRedraw = true;
|
2002-06-07 16:54:11 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::resetActorBgs() {
|
2003-09-08 21:03:31 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < gdi._numStrips; i++) {
|
|
|
|
int strip = _screenStartStrip + i;
|
|
|
|
clearGfxUsageBit(strip, USAGE_BIT_DIRTY);
|
|
|
|
clearGfxUsageBit(strip, USAGE_BIT_RESTORED);
|
|
|
|
for (j = 1; j < _numActors; j++) {
|
|
|
|
if (testGfxUsageBit(strip, j) &&
|
2004-09-03 15:39:14 +00:00
|
|
|
((_actors[j].top != 0x7fffffff && _actors[j].needRedraw) || _actors[j].needBgReset)) {
|
2003-09-08 21:03:31 +00:00
|
|
|
clearGfxUsageBit(strip, j);
|
|
|
|
if ((_actors[j].bottom - _actors[j].top) >= 0)
|
|
|
|
gdi.resetBackground(_actors[j].top, _actors[j].bottom, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i < _numActors; i++) {
|
|
|
|
_actors[i].needBgReset = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
int ScummEngine::getActorFromPos(int x, int y) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2003-11-16 20:52:57 +00:00
|
|
|
if (!testGfxAnyUsageBits(x / 8))
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
2003-05-13 23:42:41 +00:00
|
|
|
for (i = 1; i < _numActors; i++) {
|
2003-11-16 20:52:57 +00:00
|
|
|
if (testGfxUsageBit(x / 8, i) && !getClass(i, kObjectClassUntouchable)
|
2003-05-23 12:48:50 +00:00
|
|
|
&& y >= _actors[i].top && y <= _actors[i].bottom) {
|
2003-07-12 22:41:58 +00:00
|
|
|
if (_version > 2 || i != VAR(VAR_EGO))
|
|
|
|
return i;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-03-15 03:09:48 +00:00
|
|
|
void ScummEngine::actorTalk(const byte *msg) {
|
2001-10-09 14:30:12 +00:00
|
|
|
Actor *a;
|
|
|
|
|
2004-04-02 21:42:42 +00:00
|
|
|
_lastStringTag[0] = 0;
|
2004-03-15 03:22:36 +00:00
|
|
|
addMessageToStack(msg, _charsetBuffer, sizeof(_charsetBuffer));
|
2004-03-19 23:19:57 +00:00
|
|
|
|
2004-04-02 21:42:42 +00:00
|
|
|
// Play associated speech, if any
|
|
|
|
playSpeech((byte *)_lastStringTag);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-01-08 15:07:44 +00:00
|
|
|
// FIXME: Workaround for bugs #770039 and #770049
|
|
|
|
if (_gameId == GID_LOOM || _gameId == GID_LOOM256) {
|
2004-01-08 14:41:14 +00:00
|
|
|
if (!*_charsetBuffer)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (_actorToPrintStrFor == 0xFF) {
|
2004-07-16 03:39:23 +00:00
|
|
|
if ((_version <= 7 && !_keepText) || (_version == 8 && VAR(VAR_HAVE_MSG))) {
|
2001-10-09 14:30:12 +00:00
|
|
|
stopTalk();
|
2004-07-16 03:39:23 +00:00
|
|
|
}
|
2004-03-15 03:33:08 +00:00
|
|
|
setTalkingActor(0xFF);
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2003-05-13 23:03:18 +00:00
|
|
|
int oldact;
|
2003-07-15 19:09:11 +00:00
|
|
|
|
|
|
|
// FIXME: Workaround for bug #770724
|
|
|
|
if (_gameId == GID_LOOM && _roomResource == 23 &&
|
|
|
|
vm.slot[_currentScript].number == 232 && _actorToPrintStrFor == 0) {
|
|
|
|
_actorToPrintStrFor = 2; // Could be anything from 2 to 5. Maybe compare to original?
|
|
|
|
}
|
|
|
|
|
2003-05-23 12:48:50 +00:00
|
|
|
a = derefActor(_actorToPrintStrFor, "actorTalk");
|
2004-02-06 14:16:14 +00:00
|
|
|
if (!a->isInCurrentRoom() && (_version <= 6)) {
|
2001-10-09 14:30:12 +00:00
|
|
|
oldact = 0xFF;
|
|
|
|
} else {
|
2004-07-16 03:39:23 +00:00
|
|
|
if ((_version <= 7 && !_keepText) || (_version == 8 && VAR(VAR_HAVE_MSG)))
|
2001-10-09 14:30:12 +00:00
|
|
|
stopTalk();
|
2004-03-15 03:33:08 +00:00
|
|
|
setTalkingActor(a->number);
|
2004-08-29 11:27:16 +00:00
|
|
|
a->talking = true;
|
2004-08-05 20:14:43 +00:00
|
|
|
if (!_string[0].no_talk_anim) {
|
2004-07-15 12:26:10 +00:00
|
|
|
a->runActorTalkScript(a->talkStartFrame);
|
2001-11-05 19:21:49 +00:00
|
|
|
_useTalkAnims = true;
|
|
|
|
}
|
2004-03-15 03:33:08 +00:00
|
|
|
oldact = getTalkingActor();
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-05-13 23:03:18 +00:00
|
|
|
if (oldact >= 0x80)
|
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-07-26 13:53:24 +00:00
|
|
|
if (getTalkingActor() > 0x7F) {
|
2002-09-22 01:17:53 +00:00
|
|
|
_charsetColor = (byte)_string[0].color;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2004-03-15 03:33:08 +00:00
|
|
|
a = derefActor(getTalkingActor(), "actorTalk(2)");
|
2001-10-09 14:30:12 +00:00
|
|
|
_charsetColor = a->talkColor;
|
|
|
|
}
|
2002-12-26 00:21:19 +00:00
|
|
|
_charsetBufPos = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
_talkDelay = 0;
|
|
|
|
_haveMsg = 0xFF;
|
2004-07-16 03:39:23 +00:00
|
|
|
if (_version <= 7)
|
|
|
|
VAR(VAR_HAVE_MSG) = 0xFF;
|
2003-05-14 13:30:52 +00:00
|
|
|
if (VAR_CHARCOUNT != 0xFF)
|
|
|
|
VAR(VAR_CHARCOUNT) = 0;
|
2001-10-09 14:30:12 +00:00
|
|
|
CHARSET_1();
|
|
|
|
}
|
|
|
|
|
2004-07-15 12:26:10 +00:00
|
|
|
void Actor::runActorTalkScript(int f) {
|
2004-07-16 03:39:23 +00:00
|
|
|
if (_vm->_version == 8 && _vm->VAR(_vm->VAR_HAVE_MSG) == 2)
|
|
|
|
return;
|
|
|
|
|
2004-07-15 12:26:10 +00:00
|
|
|
if (talkScript) {
|
|
|
|
int script = talkScript;
|
|
|
|
int args[16];
|
|
|
|
memset(args, 0, sizeof(args));
|
|
|
|
args[1] = f;
|
|
|
|
args[0] = number;
|
|
|
|
|
|
|
|
_vm->runScript(script, 1, 0, args);
|
2004-07-16 03:39:23 +00:00
|
|
|
} else {
|
|
|
|
if (frame != f)
|
|
|
|
startAnimActor(f);
|
|
|
|
}
|
2004-07-15 12:26:10 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
void ScummEngine::stopTalk() {
|
2003-05-13 23:03:18 +00:00
|
|
|
int act;
|
|
|
|
|
|
|
|
_sound->stopTalkSound();
|
|
|
|
|
|
|
|
_haveMsg = 0;
|
|
|
|
_talkDelay = 0;
|
|
|
|
|
2004-03-15 03:33:08 +00:00
|
|
|
act = getTalkingActor();
|
2003-05-13 23:03:18 +00:00
|
|
|
if (act && act < 0x80) {
|
2003-05-23 12:48:50 +00:00
|
|
|
Actor *a = derefActor(act, "stopTalk");
|
2004-08-15 01:22:04 +00:00
|
|
|
if (a->isInCurrentRoom() || _version >= 7) {
|
2004-08-05 20:14:43 +00:00
|
|
|
if ((_version >= 7 && !_string[0].no_talk_anim) || (_version <= 6 && _useTalkAnims)) {
|
2004-07-16 03:39:23 +00:00
|
|
|
a->runActorTalkScript(a->talkStopFrame);
|
|
|
|
_useTalkAnims = false;
|
|
|
|
}
|
2003-05-13 23:03:18 +00:00
|
|
|
}
|
2004-07-16 03:39:23 +00:00
|
|
|
if (_version <= 7 && !(_features & GF_HUMONGOUS))
|
2004-03-15 03:33:08 +00:00
|
|
|
setTalkingActor(0xFF);
|
2004-08-29 11:27:16 +00:00
|
|
|
a->talking = false;
|
2003-05-13 23:03:18 +00:00
|
|
|
}
|
2004-07-16 03:39:23 +00:00
|
|
|
if (_version == 8 || _features & GF_HUMONGOUS)
|
2004-03-15 03:33:08 +00:00
|
|
|
setTalkingActor(0);
|
2004-07-16 03:39:23 +00:00
|
|
|
if (_version == 8)
|
|
|
|
VAR(VAR_HAVE_MSG) = 0;
|
2003-05-13 23:03:18 +00:00
|
|
|
_keepText = false;
|
2004-01-08 21:21:40 +00:00
|
|
|
_charset->restoreCharsetBg();
|
2003-05-13 23:03:18 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::setActorCostume(int c) {
|
2001-10-09 14:30:12 +00:00
|
|
|
int i;
|
|
|
|
|
2004-01-12 14:09:39 +00:00
|
|
|
if ((_vm->_features & GF_HUMONGOUS) && (c == -1 || c == -2)) {
|
|
|
|
skipLimb = (c == -1);
|
|
|
|
needRedraw = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-03 03:06:15 +00:00
|
|
|
// Based on disassembly. It seems that high byte is not used at all, though
|
|
|
|
// it is attached to all horizontally flipped object, like left eye.
|
|
|
|
if (_vm->_heversion == 60)
|
|
|
|
c &= 0xff;
|
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
costumeNeedsInit = true;
|
2003-07-25 18:07:42 +00:00
|
|
|
|
2004-01-03 06:38:34 +00:00
|
|
|
if (_vm->_features & GF_NEW_COSTUMES) {
|
2004-01-14 03:07:29 +00:00
|
|
|
cost.reset();
|
2004-09-19 03:26:47 +00:00
|
|
|
auxBlock.visible = false;
|
2003-07-25 18:07:42 +00:00
|
|
|
memset(animVariable, 0, sizeof(animVariable));
|
2004-01-14 03:07:29 +00:00
|
|
|
costume = c;
|
2003-07-25 18:07:42 +00:00
|
|
|
|
2004-09-19 02:00:33 +00:00
|
|
|
if (_vm->_heversion >= 71)
|
|
|
|
_vm->queueAuxBlock(this);
|
2004-09-18 00:36:17 +00:00
|
|
|
|
2003-07-25 18:07:42 +00:00
|
|
|
if (visible) {
|
|
|
|
if (costume) {
|
|
|
|
_vm->ensureResourceLoaded(rtCostume, costume);
|
|
|
|
}
|
2004-01-26 10:51:57 +00:00
|
|
|
startAnimActor(initFrame);
|
2003-07-25 18:07:42 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2003-07-25 18:07:42 +00:00
|
|
|
if (visible) {
|
|
|
|
hideActor();
|
|
|
|
cost.reset();
|
|
|
|
costume = c;
|
|
|
|
showActor();
|
|
|
|
} else {
|
|
|
|
costume = c;
|
|
|
|
cost.reset();
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-07-25 18:07:42 +00:00
|
|
|
|
2003-08-23 15:16:07 +00:00
|
|
|
// V1 zak uses palette[] as a dynamic costume color array.
|
2003-08-20 12:04:25 +00:00
|
|
|
if (_vm->_version == 1)
|
|
|
|
return;
|
|
|
|
|
2003-02-17 21:40:13 +00:00
|
|
|
if (_vm->_features & GF_NEW_COSTUMES) {
|
2002-11-10 17:17:11 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
palette[i] = 0xFF;
|
2003-04-16 07:11:04 +00:00
|
|
|
} else if (_vm->_features & GF_OLD_BUNDLE) {
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
palette[i] = i;
|
2002-11-10 17:17:11 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
palette[i] = 0xFF;
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::startWalkActor(int destX, int destY, int dir) {
|
2001-10-09 14:30:12 +00:00
|
|
|
AdjustBoxResult abr;
|
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version <= 3) {
|
2003-05-18 23:14:21 +00:00
|
|
|
abr.x = destX;
|
|
|
|
abr.y = destY;
|
|
|
|
} else {
|
2003-05-20 19:35:40 +00:00
|
|
|
abr = adjustXYToBeInBox(destX, destY);
|
2003-05-18 23:14:21 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-05-20 14:41:47 +00:00
|
|
|
if (!isInCurrentRoom()) {
|
2003-09-14 18:16:45 +00:00
|
|
|
_pos.x = abr.x;
|
|
|
|
_pos.y = abr.y;
|
2004-01-22 03:22:01 +00:00
|
|
|
if (!(_vm->_version == 6 && ignoreTurns) && dir != -1)
|
2002-07-18 15:45:10 +00:00
|
|
|
setDirection(dir);
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-18 19:44:22 +00:00
|
|
|
if (ignoreBoxes) {
|
2003-07-02 13:47:03 +00:00
|
|
|
abr.box = kInvalidBox;
|
2003-05-20 20:42:28 +00:00
|
|
|
walkbox = kInvalidBox;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2002-05-23 21:22:08 +00:00
|
|
|
if (_vm->checkXYInBoxBounds(walkdata.destbox, abr.x, abr.y)) {
|
2003-07-02 13:47:03 +00:00
|
|
|
abr.box = walkdata.destbox;
|
2001-10-09 14:30:12 +00:00
|
|
|
} else {
|
2003-05-20 19:35:40 +00:00
|
|
|
abr = adjustXYToBeInBox(abr.x, abr.y);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2003-09-11 22:26:44 +00:00
|
|
|
if (moving && walkdata.destdir == dir && walkdata.dest.x == abr.x && walkdata.dest.y == abr.y)
|
2002-04-11 17:19:16 +00:00
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
if (_pos.x == abr.x && _pos.y == abr.y) {
|
2002-05-14 19:11:20 +00:00
|
|
|
turnToDirection(dir);
|
2001-10-09 14:30:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-09-11 22:26:44 +00:00
|
|
|
walkdata.dest.x = abr.x;
|
|
|
|
walkdata.dest.y = abr.y;
|
2003-07-02 13:47:03 +00:00
|
|
|
walkdata.destbox = abr.box;
|
2002-05-14 19:11:20 +00:00
|
|
|
walkdata.destdir = dir;
|
|
|
|
moving = (moving & MF_IN_LEG) | MF_NEW_LEG;
|
2003-09-11 22:26:44 +00:00
|
|
|
walkdata.point3.x = 32000;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
walkdata.curbox = walkbox;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::startWalkAnim(int cmd, int angle) {
|
2002-07-15 21:50:51 +00:00
|
|
|
if (angle == -1)
|
|
|
|
angle = facing;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2004-07-18 09:53:58 +00:00
|
|
|
/* Note: walk scripts aren't required to make the Dig
|
2002-12-15 21:54:47 +00:00
|
|
|
* work as usual
|
|
|
|
*/
|
2004-07-18 09:53:58 +00:00
|
|
|
if (walkScript) {
|
2002-12-28 00:45:44 +00:00
|
|
|
int args[16];
|
2004-01-15 06:36:58 +00:00
|
|
|
memset(args, 0, sizeof(args));
|
2002-07-15 21:50:51 +00:00
|
|
|
args[0] = number;
|
|
|
|
args[1] = cmd;
|
2002-12-15 21:54:47 +00:00
|
|
|
args[2] = angle;
|
2003-05-31 14:27:47 +00:00
|
|
|
_vm->runScript(walkScript, 1, 0, args);
|
2004-07-18 09:53:58 +00:00
|
|
|
} else {
|
2002-07-15 21:50:51 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case 1: /* start walk */
|
2002-07-18 15:45:10 +00:00
|
|
|
setDirection(angle);
|
2002-07-15 21:50:51 +00:00
|
|
|
startAnimActor(walkFrame);
|
|
|
|
break;
|
|
|
|
case 2: /* change dir only */
|
2002-07-18 15:45:10 +00:00
|
|
|
setDirection(angle);
|
2002-07-15 21:50:51 +00:00
|
|
|
break;
|
|
|
|
case 3: /* stop walk */
|
|
|
|
turnToDirection(angle);
|
|
|
|
startAnimActor(standFrame);
|
|
|
|
break;
|
|
|
|
}
|
2001-12-11 13:34:15 +00:00
|
|
|
}
|
2002-07-15 21:50:51 +00:00
|
|
|
}
|
2001-12-11 13:34:15 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::walkActor() {
|
2003-09-11 22:00:36 +00:00
|
|
|
int new_dir, next_box;
|
2003-10-02 17:43:02 +00:00
|
|
|
Common::Point foundPath;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version >= 7) {
|
2003-03-08 13:29:41 +00:00
|
|
|
// FIXME - this is kind of a hack right now but it fixes the
|
|
|
|
// walk scripts in The Dig.
|
|
|
|
if (moving & MF_FROZEN) {
|
|
|
|
if (moving & MF_TURN) {
|
|
|
|
new_dir = updateActorDirection(false);
|
|
|
|
if (facing != new_dir)
|
|
|
|
setDirection(new_dir);
|
|
|
|
else
|
2003-03-08 14:12:58 +00:00
|
|
|
moving &= ~MF_TURN;
|
2003-03-08 13:29:41 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-12-11 13:34:15 +00:00
|
|
|
|
2003-05-20 19:35:40 +00:00
|
|
|
if (!moving)
|
2003-03-08 14:12:58 +00:00
|
|
|
return;
|
|
|
|
|
2002-07-15 21:50:51 +00:00
|
|
|
if (!(moving & MF_NEW_LEG)) {
|
|
|
|
if (moving & MF_IN_LEG && actorWalkStep())
|
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-07-15 21:50:51 +00:00
|
|
|
if (moving & MF_LAST_LEG) {
|
|
|
|
moving = 0;
|
2002-07-18 15:45:10 +00:00
|
|
|
setBox(walkdata.destbox);
|
2002-07-15 21:50:51 +00:00
|
|
|
startWalkAnim(3, walkdata.destdir);
|
|
|
|
return;
|
|
|
|
}
|
2001-12-11 13:34:15 +00:00
|
|
|
|
2002-07-15 21:50:51 +00:00
|
|
|
if (moving & MF_TURN) {
|
2003-03-08 04:11:02 +00:00
|
|
|
new_dir = updateActorDirection(false);
|
|
|
|
if (facing != new_dir)
|
|
|
|
setDirection(new_dir);
|
2002-07-15 21:50:51 +00:00
|
|
|
else
|
|
|
|
moving = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-18 15:45:10 +00:00
|
|
|
setBox(walkdata.curbox);
|
2002-07-15 21:50:51 +00:00
|
|
|
moving &= MF_IN_LEG;
|
2001-12-11 13:34:15 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
moving &= ~MF_NEW_LEG;
|
2002-07-15 21:50:51 +00:00
|
|
|
do {
|
2003-05-20 19:35:40 +00:00
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
if (walkbox == kInvalidBox) {
|
2002-07-18 15:45:10 +00:00
|
|
|
setBox(walkdata.destbox);
|
2002-07-15 21:50:51 +00:00
|
|
|
walkdata.curbox = walkdata.destbox;
|
|
|
|
break;
|
|
|
|
}
|
2003-05-05 12:09:22 +00:00
|
|
|
|
2002-07-15 21:50:51 +00:00
|
|
|
if (walkbox == walkdata.destbox)
|
|
|
|
break;
|
2003-05-05 12:09:22 +00:00
|
|
|
|
2003-09-11 22:00:36 +00:00
|
|
|
next_box = _vm->getPathToDestBox(walkbox, walkdata.destbox);
|
|
|
|
if (next_box < 0) {
|
2002-07-15 21:50:51 +00:00
|
|
|
walkdata.destbox = walkbox;
|
|
|
|
moving |= MF_LAST_LEG;
|
|
|
|
return;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-09-11 22:00:36 +00:00
|
|
|
walkdata.curbox = next_box;
|
2003-05-20 17:50:43 +00:00
|
|
|
|
2003-09-11 22:36:21 +00:00
|
|
|
if (findPathTowards(walkbox, next_box, walkdata.destbox, foundPath))
|
2002-07-15 21:50:51 +00:00
|
|
|
break;
|
2003-05-05 12:09:22 +00:00
|
|
|
|
2003-09-11 22:26:44 +00:00
|
|
|
if (calcMovementFactor(foundPath))
|
2002-07-15 21:50:51 +00:00
|
|
|
return;
|
2001-12-11 13:34:15 +00:00
|
|
|
|
2002-07-18 15:45:10 +00:00
|
|
|
setBox(walkdata.curbox);
|
2002-07-15 21:50:51 +00:00
|
|
|
} while (1);
|
|
|
|
|
|
|
|
moving |= MF_LAST_LEG;
|
2003-09-11 22:26:44 +00:00
|
|
|
calcMovementFactor(walkdata.dest);
|
2001-12-11 13:34:15 +00:00
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
/*
|
|
|
|
void Actor::walkActorV12() {
|
2003-10-02 17:43:02 +00:00
|
|
|
Common::Point foundPath, tmp;
|
2003-09-14 18:16:45 +00:00
|
|
|
int new_dir, next_box;
|
|
|
|
|
|
|
|
if (moving & MF_TURN) {
|
|
|
|
new_dir = updateActorDirection(false);
|
|
|
|
if (facing != new_dir)
|
|
|
|
setDirection(new_dir);
|
|
|
|
else
|
|
|
|
moving = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!moving)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (moving & MF_IN_LEG) {
|
|
|
|
actorWalkStep();
|
|
|
|
} else {
|
|
|
|
if (moving & MF_LAST_LEG) {
|
|
|
|
moving = 0;
|
|
|
|
startWalkAnim(3, walkdata.destdir);
|
|
|
|
} else {
|
|
|
|
setBox(walkdata.curbox);
|
|
|
|
if (walkbox == walkdata.destbox) {
|
|
|
|
foundPath = walkdata.dest;
|
|
|
|
moving |= MF_LAST_LEG;
|
|
|
|
} else {
|
|
|
|
next_box = _vm->getPathToDestBox(walkbox, walkdata.destbox);
|
|
|
|
if (next_box < 0) {
|
|
|
|
moving |= MF_LAST_LEG;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't walk through locked boxes
|
|
|
|
int flags = _vm->getBoxFlags(next_box);
|
|
|
|
if (flags & kBoxLocked && !(flags & kBoxPlayerOnly && !isPlayer())) {
|
|
|
|
moving |= MF_LAST_LEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
walkdata.curbox = next_box;
|
|
|
|
|
|
|
|
_vm->getClosestPtOnBox(walkdata.curbox, x, y, tmp.x, tmp.y);
|
|
|
|
_vm->getClosestPtOnBox(walkbox, tmp.x, tmp.y, foundPath.x, foundPath.y);
|
|
|
|
}
|
|
|
|
calcMovementFactor(foundPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::walkActorOld() {
|
2003-10-02 17:43:02 +00:00
|
|
|
Common::Point p2, p3; // Gate locations
|
2004-01-16 09:05:57 +00:00
|
|
|
int new_dir, next_box, loopCtr = 0;
|
2002-03-18 22:48:57 +00:00
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
if (!moving)
|
2002-03-18 22:48:57 +00:00
|
|
|
return;
|
2003-09-11 23:31:46 +00:00
|
|
|
|
2003-05-20 17:50:43 +00:00
|
|
|
if (!(moving & MF_NEW_LEG)) {
|
|
|
|
if (moving & MF_IN_LEG && actorWalkStep())
|
|
|
|
return;
|
2003-09-11 23:31:46 +00:00
|
|
|
|
2003-05-20 17:50:43 +00:00
|
|
|
if (moving & MF_LAST_LEG) {
|
|
|
|
moving = 0;
|
|
|
|
startWalkAnim(3, walkdata.destdir);
|
|
|
|
return;
|
|
|
|
}
|
2003-09-11 23:31:46 +00:00
|
|
|
|
2003-05-20 17:50:43 +00:00
|
|
|
if (moving & MF_TURN) {
|
|
|
|
new_dir = updateActorDirection(false);
|
|
|
|
if (facing != new_dir)
|
|
|
|
setDirection(new_dir);
|
|
|
|
else
|
|
|
|
moving = 0;
|
|
|
|
return;
|
|
|
|
}
|
2003-09-11 23:31:46 +00:00
|
|
|
|
2003-09-11 22:26:44 +00:00
|
|
|
if (walkdata.point3.x != 32000) {
|
|
|
|
if (calcMovementFactor(walkdata.point3)) {
|
|
|
|
walkdata.point3.x = 32000;
|
2003-05-20 17:50:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-09-11 22:26:44 +00:00
|
|
|
walkdata.point3.x = 32000;
|
2003-05-20 17:50:43 +00:00
|
|
|
}
|
2003-09-11 23:31:46 +00:00
|
|
|
|
2003-09-11 22:00:36 +00:00
|
|
|
setBox(walkdata.curbox);
|
2003-05-20 17:50:43 +00:00
|
|
|
moving &= MF_IN_LEG;
|
|
|
|
}
|
|
|
|
|
2003-09-14 18:16:45 +00:00
|
|
|
moving &= ~MF_NEW_LEG;
|
2003-05-20 17:50:43 +00:00
|
|
|
do {
|
2004-01-16 09:05:57 +00:00
|
|
|
loopCtr++;
|
2002-03-18 22:48:57 +00:00
|
|
|
|
2003-05-20 20:42:28 +00:00
|
|
|
if (walkbox == kInvalidBox) {
|
2003-09-11 22:00:36 +00:00
|
|
|
setBox(walkdata.destbox);
|
2002-05-14 19:11:20 +00:00
|
|
|
walkdata.curbox = walkdata.destbox;
|
2003-05-20 17:50:43 +00:00
|
|
|
break;
|
2002-03-18 22:48:57 +00:00
|
|
|
}
|
|
|
|
|
2003-05-20 17:50:43 +00:00
|
|
|
if (walkbox == walkdata.destbox)
|
|
|
|
break;
|
2002-03-18 22:48:57 +00:00
|
|
|
|
2002-05-23 21:22:08 +00:00
|
|
|
next_box = _vm->getPathToDestBox(walkbox, walkdata.destbox);
|
2003-05-18 19:44:22 +00:00
|
|
|
if (next_box < 0) {
|
2002-05-14 19:11:20 +00:00
|
|
|
moving |= MF_LAST_LEG;
|
2002-03-18 22:48:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-09-14 18:16:45 +00:00
|
|
|
|
2003-07-21 21:59:07 +00:00
|
|
|
// Can't walk through locked boxes
|
2003-05-20 19:35:40 +00:00
|
|
|
int flags = _vm->getBoxFlags(next_box);
|
2003-05-22 00:51:42 +00:00
|
|
|
if (flags & kBoxLocked && !(flags & kBoxPlayerOnly && !isPlayer())) {
|
2003-09-14 13:36:49 +00:00
|
|
|
moving |= MF_LAST_LEG;
|
2003-09-14 18:16:45 +00:00
|
|
|
// FIXME: Work in progress
|
|
|
|
// walkdata.destdir = facing;
|
2003-09-14 13:36:49 +00:00
|
|
|
return;
|
2003-05-20 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
2002-05-14 19:11:20 +00:00
|
|
|
walkdata.curbox = next_box;
|
2003-09-14 13:36:49 +00:00
|
|
|
|
2003-09-11 22:00:36 +00:00
|
|
|
if (_vm->_version <= 2) {
|
2003-09-14 18:16:45 +00:00
|
|
|
_vm->getClosestPtOnBox(walkdata.curbox, _pos.x, _pos.y, p2.x, p2.y);
|
2003-09-11 22:00:36 +00:00
|
|
|
_vm->getClosestPtOnBox(walkbox, p2.x, p2.y, p3.x, p3.y);
|
2003-09-14 18:16:45 +00:00
|
|
|
// FIXME: Work in progress
|
|
|
|
// calcMovementFactor(p3);
|
|
|
|
// return;
|
2003-09-11 22:00:36 +00:00
|
|
|
} else {
|
2003-09-11 23:31:46 +00:00
|
|
|
findPathTowardsOld(walkbox, next_box, walkdata.destbox, p2, p3);
|
|
|
|
if (p2.x == 32000 && p3.x == 32000) {
|
|
|
|
break;
|
|
|
|
}
|
2003-09-14 18:16:45 +00:00
|
|
|
|
2003-09-11 23:31:46 +00:00
|
|
|
if (p2.x != 32000) {
|
|
|
|
if (calcMovementFactor(p2)) {
|
|
|
|
walkdata.point3 = p3;
|
|
|
|
return;
|
|
|
|
}
|
2002-03-18 22:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-11 22:26:44 +00:00
|
|
|
if (calcMovementFactor(p3))
|
2002-03-18 22:48:57 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-09-27 22:12:01 +00:00
|
|
|
// FIXME: Fingolfin changed the destbox to curbox, matching walkActor.
|
|
|
|
// Motivation for this was comparision with some MI EGA disasm...
|
2003-09-28 16:08:23 +00:00
|
|
|
// However, that caused a regression in Indy3 (bug #809547).
|
2003-12-06 16:12:14 +00:00
|
|
|
// On the other hand, curbox is needed to fix bug #830106... <sigh>
|
|
|
|
if (_vm->_version >= 3)
|
|
|
|
setBox(walkdata.destbox);
|
|
|
|
else
|
|
|
|
setBox(walkdata.curbox);
|
2004-01-16 09:05:57 +00:00
|
|
|
|
|
|
|
// FIXME: Ender added this recursion counter as a hack around
|
|
|
|
// a infinite loop in Maniac V1 - see bug #862245
|
|
|
|
if (loopCtr > 10000) {
|
|
|
|
moving |= MF_LAST_LEG;
|
|
|
|
return;
|
|
|
|
}
|
2003-06-07 00:49:36 +00:00
|
|
|
} while (1);
|
2002-03-18 22:48:57 +00:00
|
|
|
|
2003-05-20 17:50:43 +00:00
|
|
|
moving |= MF_LAST_LEG;
|
2003-09-11 22:26:44 +00:00
|
|
|
calcMovementFactor(walkdata.dest);
|
2002-03-18 22:48:57 +00:00
|
|
|
}
|
2002-06-04 23:32:53 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *Actor::getActorName() {
|
2002-07-15 21:50:51 +00:00
|
|
|
byte *ptr = _vm->getResourceAddress(rtActorName, number);
|
2003-05-21 18:09:49 +00:00
|
|
|
if (ptr == NULL) {
|
2003-07-13 16:22:17 +00:00
|
|
|
warning("Failed to find name of actor %d", number);
|
2003-05-21 18:09:49 +00:00
|
|
|
}
|
2002-07-15 21:50:51 +00:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2004-01-16 01:52:49 +00:00
|
|
|
void Actor::remapActorPaletteColor(int color, int new_color) {
|
|
|
|
const byte *akos, *akpl;
|
|
|
|
int akpl_size, i;
|
|
|
|
byte akpl_color;
|
|
|
|
|
|
|
|
akos = _vm->getResourceAddress(rtCostume, costume);
|
|
|
|
if (!akos) {
|
|
|
|
warning("Can't remap actor %d, costume %d not found", number, costume);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-23 01:36:57 +00:00
|
|
|
akpl = _vm->findResource(MKID('AKPL'), akos);
|
2004-01-16 01:52:49 +00:00
|
|
|
if (!akpl) {
|
|
|
|
warning("Can't remap actor %d, costume %d doesn't contain an AKPL block", number, costume);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//get num palette entries
|
|
|
|
akpl_size = RES_SIZE(akpl) - 8;
|
|
|
|
|
|
|
|
//skip resource header
|
|
|
|
akpl = RES_DATA(akpl);
|
|
|
|
|
|
|
|
for (i = 0; i < akpl_size; i++) {
|
|
|
|
akpl_color = *akpl++;
|
|
|
|
if (akpl_color == color) {
|
|
|
|
palette[i] = new_color;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::remapActorPalette(int r_fact, int g_fact, int b_fact, int threshold) {
|
2003-05-28 20:01:47 +00:00
|
|
|
const byte *akos, *rgbs, *akpl;
|
2002-07-15 21:50:51 +00:00
|
|
|
int akpl_size, i;
|
|
|
|
int r, g, b;
|
|
|
|
byte akpl_color;
|
|
|
|
|
2004-07-04 03:25:24 +00:00
|
|
|
if (!isInCurrentRoom()) {
|
|
|
|
debugC(DEBUG_ACTORS, "Remap actor %d not in current room", number);
|
|
|
|
return;
|
|
|
|
} else if (costume < 1 || costume >= _vm->_numCostumes - 1) {
|
|
|
|
debugC(DEBUG_ACTORS, "Remap actor %d invalid costume %d", number, costume);
|
2002-07-15 21:50:51 +00:00
|
|
|
return;
|
2004-07-04 03:25:24 +00:00
|
|
|
}
|
2002-07-15 21:50:51 +00:00
|
|
|
|
|
|
|
akos = _vm->getResourceAddress(rtCostume, costume);
|
2002-10-02 09:14:59 +00:00
|
|
|
if (!akos) {
|
|
|
|
warning("Can't remap actor %d, costume %d not found", number, costume);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-23 01:36:57 +00:00
|
|
|
akpl = _vm->findResource(MKID('AKPL'), akos);
|
2002-10-02 09:14:59 +00:00
|
|
|
if (!akpl) {
|
|
|
|
warning("Can't remap actor %d, costume %d doesn't contain an AKPL block", number, costume);
|
|
|
|
return;
|
|
|
|
}
|
2002-07-15 21:50:51 +00:00
|
|
|
|
|
|
|
//get num palette entries
|
|
|
|
akpl_size = RES_SIZE(akpl) - 8;
|
|
|
|
|
|
|
|
//skip resource header
|
|
|
|
akpl = RES_DATA(akpl);
|
|
|
|
|
2004-06-23 01:36:57 +00:00
|
|
|
rgbs = _vm->findResource(MKID('RGBS'), akos);
|
2002-07-15 21:50:51 +00:00
|
|
|
|
|
|
|
if (!rgbs) {
|
2004-07-04 03:25:24 +00:00
|
|
|
debugC(DEBUG_ACTORS, "Can't remap actor %d costume %d doesn't contain an RGB block", number, costume);
|
2002-07-15 21:50:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// skip resource header
|
|
|
|
rgbs = RES_DATA(rgbs);
|
|
|
|
|
|
|
|
for (i = 0; i < akpl_size; i++) {
|
|
|
|
r = *rgbs++;
|
|
|
|
g = *rgbs++;
|
|
|
|
b = *rgbs++;
|
|
|
|
|
|
|
|
akpl_color = *akpl++;
|
|
|
|
|
|
|
|
// allow remap of generic palette entry?
|
|
|
|
if (!shadow_mode || akpl_color >= 16) {
|
|
|
|
if (r_fact != 256)
|
|
|
|
r = (r * r_fact) >> 8;
|
|
|
|
if (g_fact != 256)
|
|
|
|
g = (g * g_fact) >> 8;
|
|
|
|
if (b_fact != 256)
|
|
|
|
b = (b * b_fact) >> 8;
|
|
|
|
palette[i] = _vm->remapPaletteColor(r, g, b, threshold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Actor::classChanged(int cls, bool value) {
|
2003-05-20 20:42:28 +00:00
|
|
|
if (cls == kObjectClassAlwaysClip)
|
2002-07-26 16:50:41 +00:00
|
|
|
forceClip = value;
|
2003-05-20 20:42:28 +00:00
|
|
|
if (cls == kObjectClassIgnoreBoxes)
|
2002-07-26 16:13:04 +00:00
|
|
|
ignoreBoxes = value;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
bool Actor::isInClass(int cls) {
|
2002-07-15 22:56:24 +00:00
|
|
|
return _vm->getClass(number, cls);
|
|
|
|
}
|
2003-05-22 00:51:42 +00:00
|
|
|
|
|
|
|
bool Actor::isPlayer() {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_vm->_version <= 2)
|
2003-05-22 00:51:42 +00:00
|
|
|
return _vm->VAR(42) <= number && number <= _vm->VAR(43);
|
|
|
|
else
|
|
|
|
return isInClass(kObjectClassPlayer);
|
|
|
|
}
|
|
|
|
|
2004-09-08 21:14:12 +00:00
|
|
|
void Actor::setUserCondition(int slot, int set) {
|
|
|
|
debug(1, "Actor::setUserCondition(%d, %d)", slot, set);
|
|
|
|
assert(slot >= 1 && slot <= 0x20);
|
|
|
|
if (set == 0) {
|
|
|
|
condMask &= ~(1 << (slot + 0xF));
|
|
|
|
} else {
|
|
|
|
condMask |= 1 << (slot + 0xF);
|
|
|
|
}
|
|
|
|
if (condMask & 0x3FF) {
|
|
|
|
condMask &= ~1;
|
|
|
|
} else {
|
|
|
|
condMask |= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Actor::isUserConditionSet(int slot) {
|
|
|
|
assert(slot >= 1 && slot <= 0x20);
|
2004-09-18 11:34:55 +00:00
|
|
|
return (condMask & (1 << (slot + 0xF))) != 0;
|
2004-09-08 21:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::setTalkCondition(int slot) {
|
|
|
|
debug(1, "Actor::setTalkCondition(%d)", slot);
|
|
|
|
assert(slot >= 1 && slot <= 0x10);
|
|
|
|
condMask = (condMask & ~0x3FF) | 1;
|
|
|
|
if (slot != 1) {
|
|
|
|
condMask |= 1 << (slot - 1);
|
|
|
|
if (condMask & 0x3FF) {
|
|
|
|
condMask &= ~1;
|
|
|
|
} else {
|
|
|
|
condMask |= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Actor::isTalkConditionSet(int slot) {
|
|
|
|
assert(slot >= 1 && slot <= 0x10);
|
2004-09-18 11:34:55 +00:00
|
|
|
return (condMask & (1 << (slot - 1))) != 0;
|
2004-09-08 21:14:12 +00:00
|
|
|
}
|
|
|
|
|
2004-09-18 00:36:17 +00:00
|
|
|
void ScummEngine::preProcessAuxQueue() {
|
|
|
|
if (!_skipProcessActors) {
|
|
|
|
for (int i = 0; i < _auxBlocksNum; ++i) {
|
|
|
|
AuxBlock *ab = &_auxBlocks[i];
|
|
|
|
assert(ab->r.top <= ab->r.bottom);
|
|
|
|
if (ab->visible) {
|
|
|
|
gdi.copyVirtScreenBuffers(ab->r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_auxBlocksNum = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine::postProcessAuxQueue() {
|
|
|
|
if (!_skipProcessActors) {
|
|
|
|
for (int i = 0; i < _auxEntriesNum; ++i) {
|
|
|
|
AuxEntry *ae = &_auxEntries[i];
|
|
|
|
if (ae->actorNum != -1) {
|
|
|
|
Actor *a = derefActor(ae->actorNum, "postProcessAuxQueue");
|
|
|
|
const uint8 *cost = getResourceAddress(rtCostume, a->costume);
|
|
|
|
|
|
|
|
int dy = a->offs_y + a->_pos.y - a->getElevation();
|
|
|
|
int dx = a->offs_x + a->_pos.x;
|
|
|
|
|
|
|
|
const uint8 *akax = findResource(MKID('AKAX'), cost);
|
|
|
|
if (!akax) {
|
|
|
|
error("No AKAX block for actor %d", ae->actorNum);
|
|
|
|
}
|
|
|
|
const uint8 *auxd = findPalInPals(akax, ae->subIndex) - _resourceHeaderSize;
|
|
|
|
if (!auxd) {
|
|
|
|
error("No AUXD block for actor %d", ae->actorNum);
|
|
|
|
}
|
|
|
|
const uint8 *axfd = findResourceData(MKID('AXFD'), auxd);
|
|
|
|
if (!axfd) {
|
|
|
|
error("No AXFD block for actor %d", ae->actorNum);
|
|
|
|
} else {
|
|
|
|
uint16 comp = READ_LE_UINT16(axfd);
|
2004-09-19 08:58:51 +00:00
|
|
|
if (comp != 0) {
|
2004-09-20 18:27:13 +00:00
|
|
|
int x = (int16)READ_LE_UINT16(axfd + 2) + dx;
|
|
|
|
int y = (int16)READ_LE_UINT16(axfd + 4) + dy;
|
|
|
|
int w = (int16)READ_LE_UINT16(axfd + 6);
|
|
|
|
int h = (int16)READ_LE_UINT16(axfd + 8);
|
2004-09-18 00:36:17 +00:00
|
|
|
VirtScreen *pvs = &virtscr[kMainVirtScreen];
|
2004-09-20 18:27:13 +00:00
|
|
|
uint8 *dst1 = pvs->getPixels(0, pvs->topline);
|
|
|
|
uint8 *dst2 = pvs->getBackPixels(0, pvs->topline);
|
2004-09-18 00:36:17 +00:00
|
|
|
switch (comp) {
|
|
|
|
case 1:
|
2004-09-20 18:27:13 +00:00
|
|
|
gdi.copyAuxImage(dst1, dst2, axfd + 10, pvs->w, pvs->h, x, y, w, h, NULL);
|
2004-09-18 00:36:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warning("unimplemented compression type %d", comp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const uint8 *axur = findResourceData(MKID('AXUR'), auxd);
|
|
|
|
if (axur) {
|
|
|
|
uint16 n = READ_LE_UINT16(axur); axur += 2;
|
|
|
|
while (n--) {
|
2004-09-20 18:27:13 +00:00
|
|
|
int x1 = (int16)READ_LE_UINT16(axur + 0) + dx;
|
|
|
|
int y1 = (int16)READ_LE_UINT16(axur + 2) + dy;
|
|
|
|
int x2 = (int16)READ_LE_UINT16(axur + 4) + dx;
|
|
|
|
int y2 = (int16)READ_LE_UINT16(axur + 6) + dy;
|
|
|
|
markRectAsDirty(kMainVirtScreen, x1, x2, y1, y2);
|
2004-09-18 00:36:17 +00:00
|
|
|
axur += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const uint8 *axer = findResourceData(MKID('AXER'), auxd);
|
|
|
|
if (axer) {
|
|
|
|
a->auxBlock.visible = true;
|
|
|
|
a->auxBlock.r.left = (int16)READ_LE_UINT16(axer + 0) + dx;
|
|
|
|
a->auxBlock.r.top = (int16)READ_LE_UINT16(axer + 2) + dy;
|
|
|
|
a->auxBlock.r.right = (int16)READ_LE_UINT16(axer + 4) + dx;
|
|
|
|
a->auxBlock.r.bottom = (int16)READ_LE_UINT16(axer + 6) + dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_auxEntriesNum = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine::queueAuxBlock(Actor *a) {
|
2004-09-19 02:00:33 +00:00
|
|
|
if (!a->auxBlock.visible)
|
|
|
|
return;
|
|
|
|
|
2004-09-18 00:36:17 +00:00
|
|
|
assert(_auxBlocksNum < ARRAYSIZE(_auxBlocks));
|
|
|
|
_auxBlocks[_auxBlocksNum] = a->auxBlock;
|
|
|
|
++_auxBlocksNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummEngine::queueAuxEntry(int actorNum, int subIndex) {
|
|
|
|
assert(_auxEntriesNum < ARRAYSIZE(_auxEntries));
|
|
|
|
AuxEntry *ae = &_auxEntries[_auxEntriesNum];
|
|
|
|
ae->actorNum = actorNum;
|
|
|
|
ae->subIndex = subIndex;
|
|
|
|
++_auxEntriesNum;
|
|
|
|
}
|
|
|
|
|
2003-05-22 00:51:42 +00:00
|
|
|
|
2003-05-26 02:26:13 +00:00
|
|
|
const SaveLoadEntry *Actor::getSaveLoadEntries() {
|
|
|
|
static const SaveLoadEntry actorEntries[] = {
|
2003-09-14 18:16:45 +00:00
|
|
|
MKLINE(Actor, _pos.x, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, _pos.y, sleInt16, VER(8)),
|
2004-07-11 11:59:18 +00:00
|
|
|
MKLINE(Actor, offs_x, sleInt16, VER(32)),
|
|
|
|
MKLINE(Actor, offs_y, sleInt16, VER(32)),
|
2003-08-29 04:05:23 +00:00
|
|
|
MKLINE(Actor, top, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, bottom, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, elevation, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, width, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, facing, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, costume, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, room, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, talkColor, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, talkFrequency, sleInt16, VER(16)),
|
2003-11-29 13:58:17 +00:00
|
|
|
MKLINE(Actor, talkPan, sleInt16, VER(24)),
|
2004-02-17 00:40:52 +00:00
|
|
|
MKLINE(Actor, talkVolume, sleInt16, VER(29)),
|
2004-07-28 11:56:14 +00:00
|
|
|
MKLINE(Actor, boxscale, sleUint16, VER(34)),
|
2003-08-29 04:05:23 +00:00
|
|
|
MKLINE(Actor, scalex, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, scaley, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, charset, sleByte, VER(8)),
|
2004-09-05 09:36:51 +00:00
|
|
|
|
|
|
|
// Actor sound grew from 8 to 32 bytes
|
2004-09-05 16:18:07 +00:00
|
|
|
MKARRAY_OLD(Actor, sound[0], sleByte, 8, VER(8), VER(36)),
|
2004-09-05 09:36:51 +00:00
|
|
|
MKARRAY(Actor, sound[0], sleByte, 32, VER(37)),
|
|
|
|
|
2003-08-29 04:05:23 +00:00
|
|
|
MKARRAY(Actor, animVariable[0], sleUint16, 8, VER(8)),
|
|
|
|
MKLINE(Actor, targetFacing, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, moving, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, ignoreBoxes, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, forceClip, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, initFrame, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, walkFrame, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, standFrame, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, talkStartFrame, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, talkStopFrame, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, speedx, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, speedy, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, cost.animCounter, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, cost.soundCounter, sleByte, VER(8)),
|
2004-08-29 11:27:16 +00:00
|
|
|
MKLINE(Actor, drawToBackBuf, sleByte, VER(32)),
|
2004-07-11 09:15:14 +00:00
|
|
|
MKLINE(Actor, flip, sleByte, VER(32)),
|
|
|
|
MKLINE(Actor, skipLimb, sleByte, VER(32)),
|
|
|
|
|
2003-05-26 02:26:13 +00:00
|
|
|
// Actor palette grew from 64 to 256 bytes
|
2003-08-29 04:05:23 +00:00
|
|
|
MKARRAY_OLD(Actor, palette[0], sleByte, 64, VER(8), VER(9)),
|
|
|
|
MKARRAY(Actor, palette[0], sleByte, 256, VER(10)),
|
2003-05-26 02:26:13 +00:00
|
|
|
|
2003-08-29 04:05:23 +00:00
|
|
|
MK_OBSOLETE(Actor, mask, sleByte, VER(8), VER(9)),
|
|
|
|
MKLINE(Actor, shadow_mode, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, visible, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, frame, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, animSpeed, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, animProgress, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, walkbox, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, needRedraw, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, needBgReset, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, costumeNeedsInit, sleByte, VER(8)),
|
2004-09-10 01:03:01 +00:00
|
|
|
MKLINE(Actor, condMask, sleUint32, VER(38)),
|
|
|
|
|
2003-08-29 04:05:23 +00:00
|
|
|
MKLINE(Actor, talkPosY, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, talkPosX, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, ignoreTurns, sleByte, VER(8)),
|
2003-05-26 02:26:13 +00:00
|
|
|
|
2003-08-29 04:05:23 +00:00
|
|
|
MKLINE(Actor, layer, sleByte, VER(8)),
|
2003-05-26 02:26:13 +00:00
|
|
|
|
2003-08-29 04:05:23 +00:00
|
|
|
MKLINE(Actor, talkScript, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, walkScript, sleUint16, VER(8)),
|
2004-09-10 01:03:01 +00:00
|
|
|
|
2003-09-11 22:26:44 +00:00
|
|
|
MKLINE(Actor, walkdata.dest.x, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.dest.y, sleInt16, VER(8)),
|
2003-08-29 04:05:23 +00:00
|
|
|
MKLINE(Actor, walkdata.destbox, sleByte, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.destdir, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.curbox, sleByte, VER(8)),
|
2003-09-11 22:26:44 +00:00
|
|
|
MKLINE(Actor, walkdata.cur.x, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.cur.y, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.next.x, sleInt16, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.next.y, sleInt16, VER(8)),
|
2003-08-29 04:05:23 +00:00
|
|
|
MKLINE(Actor, walkdata.deltaXFactor, sleInt32, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.deltaYFactor, sleInt32, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.xfrac, sleUint16, VER(8)),
|
|
|
|
MKLINE(Actor, walkdata.yfrac, sleUint16, VER(8)),
|
2003-05-26 02:26:13 +00:00
|
|
|
|
2003-08-29 04:05:23 +00:00
|
|
|
MKARRAY(Actor, cost.active[0], sleByte, 16, VER(8)),
|
|
|
|
MKLINE(Actor, cost.stopped, sleUint16, VER(8)),
|
|
|
|
MKARRAY(Actor, cost.curpos[0], sleUint16, 16, VER(8)),
|
|
|
|
MKARRAY(Actor, cost.start[0], sleUint16, 16, VER(8)),
|
|
|
|
MKARRAY(Actor, cost.end[0], sleUint16, 16, VER(8)),
|
|
|
|
MKARRAY(Actor, cost.frame[0], sleUint16, 16, VER(8)),
|
2003-05-26 02:26:13 +00:00
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
|
|
|
|
return actorEntries;
|
|
|
|
}
|
2003-10-03 18:33:57 +00:00
|
|
|
|
|
|
|
} // End of namespace Scumm
|