2007-05-30 21:56:52 +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.
|
2005-10-03 20:21:18 +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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-10-03 20:21:18 +00:00
|
|
|
*
|
2006-02-09 12:19:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-10-03 20:21:18 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-03-29 15:59:37 +00:00
|
|
|
#include "common/endian.h"
|
2005-10-03 20:21:18 +00:00
|
|
|
#include "common/stream.h"
|
|
|
|
#include "common/util.h"
|
|
|
|
#include "common/system.h"
|
2009-07-25 12:59:46 +00:00
|
|
|
#include "common/EventRecorder.h"
|
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
#include "kyra/screen.h"
|
2008-05-11 22:32:37 +00:00
|
|
|
#include "kyra/kyra_lok.h"
|
2005-10-03 20:21:18 +00:00
|
|
|
#include "kyra/sprites.h"
|
|
|
|
#include "kyra/resource.h"
|
2008-05-11 22:32:37 +00:00
|
|
|
#include "kyra/animator_lok.h"
|
2005-10-03 20:21:18 +00:00
|
|
|
|
|
|
|
namespace Kyra {
|
|
|
|
|
2008-05-11 22:32:37 +00:00
|
|
|
Sprites::Sprites(KyraEngine_LoK *vm, OSystem *system) {
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm = vm;
|
|
|
|
_res = vm->resource();
|
|
|
|
_screen = vm->screen();
|
2005-10-03 20:21:18 +00:00
|
|
|
_system = system;
|
|
|
|
_dat = 0;
|
|
|
|
memset(_anims, 0, sizeof(_anims));
|
2005-11-18 23:55:31 +00:00
|
|
|
memset(_sceneShapes, 0, sizeof(_sceneShapes));
|
2005-10-29 18:37:40 +00:00
|
|
|
_spriteDefStart = 0;
|
2005-11-18 23:55:31 +00:00
|
|
|
memset(_drawLayerTable, 0, sizeof(_drawLayerTable));
|
2005-12-22 01:49:59 +00:00
|
|
|
_sceneAnimatorBeaconFlag = 0;
|
2009-07-25 12:59:46 +00:00
|
|
|
g_eventRec.registerRandomSource(_rnd, "kyraSprites");
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sprites::~Sprites() {
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] _dat;
|
2005-10-29 18:37:40 +00:00
|
|
|
freeSceneShapes();
|
2005-10-03 20:21:18 +00:00
|
|
|
for (int i = 0; i < MAX_NUM_ANIMS; i++) {
|
2005-11-10 14:08:50 +00:00
|
|
|
if (_anims[i].background)
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] _anims[i].background;
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
void Sprites::setupSceneAnims() {
|
|
|
|
uint8 *data;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
for (int i = 0; i < MAX_NUM_ANIMS; i++) {
|
2009-10-31 18:32:17 +00:00
|
|
|
delete[] _anims[i].background;
|
|
|
|
_anims[i].background = 0;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
if (_anims[i].script != 0) {
|
2005-10-03 20:21:18 +00:00
|
|
|
data = _anims[i].script;
|
|
|
|
|
|
|
|
assert( READ_LE_UINT16(data) == 0xFF86 );
|
2005-11-10 14:08:50 +00:00
|
|
|
data += 4;
|
|
|
|
|
2006-02-11 00:17:20 +00:00
|
|
|
_anims[i].disable = READ_LE_UINT16(data) != 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
data += 4;
|
|
|
|
_anims[i].unk2 = READ_LE_UINT16(data);
|
|
|
|
data += 4;
|
|
|
|
|
2007-04-01 13:10:50 +00:00
|
|
|
if ((_vm->_northExitHeight & 0xFF) > READ_LE_UINT16(data))
|
|
|
|
_anims[i].drawY = _vm->_northExitHeight & 0xFF;
|
2005-11-10 14:08:50 +00:00
|
|
|
else
|
|
|
|
_anims[i].drawY = READ_LE_UINT16(data);
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
//sceneUnk2[i] = READ_LE_UINT16(data);
|
|
|
|
data += 4;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
_anims[i].x = READ_LE_UINT16(data);
|
|
|
|
data += 4;
|
|
|
|
_anims[i].y = READ_LE_UINT16(data);
|
|
|
|
data += 4;
|
2006-03-16 16:35:46 +00:00
|
|
|
_anims[i].width = *(data);
|
2005-11-10 14:08:50 +00:00
|
|
|
data += 4;
|
|
|
|
_anims[i].height = *(data);
|
|
|
|
data += 4;
|
|
|
|
_anims[i].sprite = READ_LE_UINT16(data);
|
|
|
|
data += 4;
|
2006-01-01 10:49:27 +00:00
|
|
|
_anims[i].flipX = READ_LE_UINT16(data) != 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
data += 4;
|
|
|
|
_anims[i].width2 = *(data);
|
|
|
|
data += 4;
|
|
|
|
_anims[i].height2 = *(data);
|
|
|
|
data += 4;
|
2006-01-01 10:49:27 +00:00
|
|
|
_anims[i].unk1 = READ_LE_UINT16(data) != 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
data += 4;
|
2006-01-01 10:49:27 +00:00
|
|
|
_anims[i].play = READ_LE_UINT16(data) != 0;
|
2005-10-03 20:21:18 +00:00
|
|
|
data += 2;
|
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
_anims[i].script = data;
|
2007-02-01 14:57:48 +00:00
|
|
|
_anims[i].curPos = data;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2006-03-17 14:19:18 +00:00
|
|
|
int bkgdWidth = _anims[i].width;
|
2005-11-10 14:08:50 +00:00
|
|
|
int bkgdHeight = _anims[i].height;
|
2005-10-18 20:38:30 +00:00
|
|
|
|
2006-03-17 14:19:18 +00:00
|
|
|
if (_anims[i].width2 > 0)
|
|
|
|
bkgdWidth += (_anims[i].width2 >> 3) + 1;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2006-03-17 14:19:18 +00:00
|
|
|
if (_anims[i].height2 > 0)
|
2005-11-10 14:08:50 +00:00
|
|
|
bkgdHeight += _anims[i].height2;
|
2005-10-18 20:38:30 +00:00
|
|
|
|
2006-09-16 13:40:28 +00:00
|
|
|
_anims[i].background = new uint8[_screen->getRectSize(bkgdWidth + 1, bkgdHeight)];
|
2005-11-10 14:08:50 +00:00
|
|
|
assert(_anims[i].background);
|
2006-09-16 13:40:28 +00:00
|
|
|
memset(_anims[i].background, 0, _screen->getRectSize(bkgdWidth + 1, bkgdHeight));
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprites::updateSceneAnims() {
|
|
|
|
uint32 currTime = _system->getMillis();
|
2007-02-01 14:57:48 +00:00
|
|
|
bool update;
|
2005-11-10 14:08:50 +00:00
|
|
|
uint8 *data;
|
2006-01-28 05:09:39 +00:00
|
|
|
uint16 rndNr;
|
|
|
|
uint16 anim;
|
|
|
|
uint16 sound;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
for (int i = 0; i < MAX_NUM_ANIMS; i++) {
|
2008-05-08 21:23:14 +00:00
|
|
|
if (_anims[i].script == 0 || !_anims[i].play || (_anims[i].nextRun != 0 && _anims[i].nextRun > currTime))
|
2005-11-10 14:08:50 +00:00
|
|
|
continue;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2007-02-01 14:57:48 +00:00
|
|
|
data = _anims[i].curPos;
|
|
|
|
update = true;
|
|
|
|
debugC(6, kDebugLevelSprites, "anim: %d 0x%.04X", i, READ_LE_UINT16(data));
|
|
|
|
assert((data - _anims[i].script) < _anims[i].length);
|
|
|
|
switch (READ_LE_UINT16(data)) {
|
|
|
|
case 0xFF88:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set sprite image.");
|
|
|
|
debugC(6, kDebugLevelSprites, "Sprite index %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].sprite = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
//debugC(6, kDebugLevelSprites, "Unused %i", READ_LE_UINT16(data));
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "X %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].x = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "Y %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].y = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
_anims[i].flipX = false;
|
2007-02-01 15:30:50 +00:00
|
|
|
_anims[i].lastRefresh = _system->getMillis();
|
2007-02-01 14:57:48 +00:00
|
|
|
refreshSceneAnimObject(i, _anims[i].sprite, _anims[i].x, _anims[i].y, _anims[i].flipX, _anims[i].unk1 != 0);
|
|
|
|
break;
|
|
|
|
case 0xFF8D:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set sprite image, flipped.");
|
|
|
|
debugC(6, kDebugLevelSprites, "Sprite index %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].sprite = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "X %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].x = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "Y %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].y = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
_anims[i].flipX = true;
|
2007-02-01 15:30:50 +00:00
|
|
|
_anims[i].lastRefresh = _system->getMillis();
|
2007-02-01 14:57:48 +00:00
|
|
|
refreshSceneAnimObject(i, _anims[i].sprite, _anims[i].x, _anims[i].y, _anims[i].flipX, _anims[i].unk1 != 0);
|
|
|
|
break;
|
|
|
|
case 0xFF8A:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set time to wait");
|
|
|
|
debugC(6, kDebugLevelSprites, "Time %i", READ_LE_UINT16(data));
|
2007-04-01 13:10:50 +00:00
|
|
|
_anims[i].nextRun = _system->getMillis() + READ_LE_UINT16(data) * _vm->tickLength();
|
2007-02-01 15:30:50 +00:00
|
|
|
_anims[i].nextRun -= _system->getMillis() - _anims[i].lastRefresh;
|
2007-02-01 14:57:48 +00:00
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFFB3:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set time to wait to random value");
|
|
|
|
rndNr = READ_LE_UINT16(data) + _rnd.getRandomNumber( READ_LE_UINT16(data) + 2);
|
|
|
|
debugC(6, kDebugLevelSprites, "Minimum time %i", READ_LE_UINT16(data));
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "Maximum time %i", READ_LE_UINT16(data));
|
|
|
|
data += 2;
|
2007-04-01 13:10:50 +00:00
|
|
|
_anims[i].nextRun = _system->getMillis() + rndNr * _vm->tickLength();
|
2007-02-01 15:30:50 +00:00
|
|
|
_anims[i].nextRun -= _system->getMillis() - _anims[i].lastRefresh;
|
2007-02-01 14:57:48 +00:00
|
|
|
break;
|
|
|
|
case 0xFF8C:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Wait until wait time has elapsed");
|
|
|
|
update = (_anims[i].nextRun < currTime);
|
|
|
|
//assert( _anims[i].nextRun > _system->getMillis());
|
|
|
|
break;
|
|
|
|
case 0xFF99:
|
|
|
|
data += 2;
|
|
|
|
debugC(1, kDebugLevelSprites, "func: Set value of unknown animation property to 1");
|
|
|
|
_anims[i].unk1 = 1;
|
|
|
|
break;
|
|
|
|
case 0xFF9A:
|
|
|
|
data += 2;
|
|
|
|
debugC(1, kDebugLevelSprites, "func: Set value of unknown animation property to 0");
|
|
|
|
_anims[i].unk1 = 0;
|
2007-09-19 08:40:12 +00:00
|
|
|
break;
|
2007-02-01 14:57:48 +00:00
|
|
|
case 0xFF97:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set default X coordinate of sprite");
|
|
|
|
debugC(6, kDebugLevelSprites, "X %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].x = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFF98:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set default Y coordinate of sprite");
|
|
|
|
debugC(6, kDebugLevelSprites, "Y %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].y = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFF8B:
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Jump to start of script section");
|
|
|
|
_anims[i].curPos = _anims[i].script;
|
|
|
|
_anims[i].nextRun = _system->getMillis();
|
|
|
|
update = false;
|
|
|
|
break;
|
|
|
|
case 0xFF8E:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Begin for () loop");
|
|
|
|
debugC(6, kDebugLevelSprites, "Iterations: %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].loopsLeft = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
_anims[i].loopStart = data;
|
|
|
|
break;
|
|
|
|
case 0xFF8F:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: End for () loop");
|
|
|
|
if (_anims[i].loopsLeft > 0) {
|
|
|
|
_anims[i].loopsLeft--;
|
|
|
|
data = _anims[i].loopStart;
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
2007-02-01 14:57:48 +00:00
|
|
|
break;
|
|
|
|
case 0xFF90:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set sprite image using default X and Y");
|
|
|
|
debugC(6, kDebugLevelSprites, "Sprite index %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].sprite = READ_LE_UINT16(data);
|
|
|
|
_anims[i].flipX = false;
|
|
|
|
data += 2;
|
2007-02-01 15:30:50 +00:00
|
|
|
_anims[i].lastRefresh = _system->getMillis();
|
2007-02-01 14:57:48 +00:00
|
|
|
refreshSceneAnimObject(i, _anims[i].sprite, _anims[i].x, _anims[i].y, _anims[i].flipX, _anims[i].unk1 != 0);
|
|
|
|
break;
|
|
|
|
case 0xFF91:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set sprite image using default X and Y, flipped.");
|
|
|
|
debugC(6, kDebugLevelSprites, "Sprite index %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].sprite = READ_LE_UINT16(data);
|
|
|
|
_anims[i].flipX = true;
|
|
|
|
data += 2;
|
2007-02-01 15:30:50 +00:00
|
|
|
_anims[i].lastRefresh = _system->getMillis();
|
2007-02-01 14:57:48 +00:00
|
|
|
refreshSceneAnimObject(i, _anims[i].sprite, _anims[i].x, _anims[i].y, _anims[i].flipX, _anims[i].unk1 != 0);
|
|
|
|
break;
|
|
|
|
case 0xFF92:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Increase value of default X-coordinate");
|
|
|
|
debugC(6, kDebugLevelSprites, "Increment %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].x += READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFF93:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Increase value of default Y-coordinate");
|
|
|
|
debugC(6, kDebugLevelSprites, "Increment %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].y += READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFF94:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Decrease value of default X-coordinate");
|
|
|
|
debugC(6, kDebugLevelSprites, "Decrement %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].x -= READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFF95:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Decrease value of default Y-coordinate");
|
|
|
|
debugC(6, kDebugLevelSprites, "Decrement %i", READ_LE_UINT16(data));
|
|
|
|
_anims[i].y -= READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFF96:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Stop animation");
|
|
|
|
debugC(6, kDebugLevelSprites, "Animation index %i", READ_LE_UINT16(data));
|
|
|
|
anim = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
_anims[anim].play = false;
|
|
|
|
_anims[anim].sprite = -1;
|
|
|
|
break;
|
|
|
|
/* case 0xFF97:
|
|
|
|
data += 2;
|
|
|
|
debugC(1, kDebugLevelSprites, "func: Set value of animation property 34h to 0");
|
|
|
|
break;*/
|
|
|
|
case 0xFFAD:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set Brandon's X coordinate");
|
|
|
|
debugC(6, kDebugLevelSprites, "X %i", READ_LE_UINT16(data));
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->currentCharacter()->x1 = READ_LE_UINT16(data);
|
2007-02-01 14:57:48 +00:00
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFFAE:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set Brandon's Y coordinate");
|
|
|
|
debugC(6, kDebugLevelSprites, "Y %i", READ_LE_UINT16(data));
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->currentCharacter()->y1 = READ_LE_UINT16(data);
|
2007-02-01 14:57:48 +00:00
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFFAF:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Set Brandon's sprite");
|
|
|
|
debugC(6, kDebugLevelSprites, "Sprite %i", READ_LE_UINT16(data));
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->currentCharacter()->currentAnimFrame = READ_LE_UINT16(data);
|
2007-02-01 14:57:48 +00:00
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFFAA:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Reset Brandon's sprite");
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->animator()->actors()->sceneAnimPtr = 0;
|
|
|
|
_vm->animator()->actors()->bkgdChangeFlag = 1;
|
|
|
|
_vm->animator()->actors()->refreshFlag = 1;
|
|
|
|
_vm->animator()->restoreAllObjectBackgrounds();
|
|
|
|
_vm->animator()->flagAllObjectsForRefresh();
|
|
|
|
_vm->animator()->updateAllObjectShapes();
|
2007-02-01 14:57:48 +00:00
|
|
|
break;
|
|
|
|
case 0xFFAB:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Update Brandon's sprite");
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->animator()->animRefreshNPC(0);
|
|
|
|
_vm->animator()->flagAllObjectsForRefresh();
|
|
|
|
_vm->animator()->updateAllObjectShapes();
|
2007-02-01 14:57:48 +00:00
|
|
|
break;
|
|
|
|
case 0xFFB0:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Play sound");
|
|
|
|
debugC(6, kDebugLevelSprites, "Sound index %i", READ_LE_UINT16(data));
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->snd_playSoundEffect(READ_LE_UINT16(data));
|
2007-02-01 14:57:48 +00:00
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFFB1:
|
|
|
|
data += 2;
|
|
|
|
_sceneAnimatorBeaconFlag = 1;
|
|
|
|
break;
|
|
|
|
case 0xFFB2:
|
|
|
|
data += 2;
|
|
|
|
_sceneAnimatorBeaconFlag = 0;
|
|
|
|
break;
|
|
|
|
case 0xFFB4:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Play (at random) a certain sound at a certain percentage of time");
|
|
|
|
debugC(6, kDebugLevelSprites, "Sound index %i", READ_LE_UINT16(data));
|
|
|
|
sound = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "Percentage %i", READ_LE_UINT16(data));
|
|
|
|
rndNr = _rnd.getRandomNumber(100);
|
|
|
|
if (rndNr <= READ_LE_UINT16(data))
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->snd_playSoundEffect(sound);
|
2007-02-01 14:57:48 +00:00
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFFA7:
|
|
|
|
data += 2;
|
|
|
|
debugC(6, kDebugLevelSprites, "func: Play animation");
|
|
|
|
debugC(6, kDebugLevelSprites, "Animation index %i", READ_LE_UINT16(data));
|
|
|
|
_anims[READ_LE_UINT16(data)].play = 1;
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warning("Unsupported anim command %X in script %i", READ_LE_UINT16(data), i);
|
|
|
|
data += 2;
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
|
|
|
|
2007-02-01 14:57:48 +00:00
|
|
|
if (update)
|
|
|
|
_anims[i].curPos = data;
|
2005-10-03 20:21:18 +00:00
|
|
|
if (READ_LE_UINT16(data) == 0xFF87)
|
|
|
|
_anims[i].play = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-18 12:08:13 +00:00
|
|
|
void Sprites::loadDat(const char *filename, SceneExits &exits) {
|
2005-10-03 20:21:18 +00:00
|
|
|
uint32 fileSize;
|
|
|
|
|
|
|
|
delete[] _dat;
|
2005-11-10 14:08:50 +00:00
|
|
|
_spriteDefStart = 0;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2008-04-19 14:31:10 +00:00
|
|
|
_res->exists(filename, true);
|
2005-10-03 20:21:18 +00:00
|
|
|
_dat = _res->fileData(filename, &fileSize);
|
|
|
|
|
2009-10-31 18:32:17 +00:00
|
|
|
for (uint i = 0; i < MAX_NUM_ANIMS; ++i)
|
|
|
|
delete[] _anims[i].background;
|
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
memset(_anims, 0, sizeof(_anims));
|
2005-10-03 20:21:18 +00:00
|
|
|
uint8 nextAnim = 0;
|
|
|
|
|
|
|
|
assert(fileSize > 0x6D);
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
memcpy(_drawLayerTable, (_dat + 0x0D), 8);
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->_northExitHeight = READ_LE_UINT16(_dat + 0x15);
|
|
|
|
if (_vm->_northExitHeight & 1)
|
|
|
|
_vm->_northExitHeight += 1;
|
2007-01-31 23:48:12 +00:00
|
|
|
|
2006-01-28 05:09:39 +00:00
|
|
|
// XXX
|
2007-04-01 13:10:50 +00:00
|
|
|
_vm->_paletteChanged = 1;
|
2007-03-23 16:24:28 +00:00
|
|
|
|
2007-04-01 13:10:50 +00:00
|
|
|
if (_vm->gameFlags().platform == Common::kPlatformAmiga) {
|
|
|
|
if (_vm->queryGameFlag(0xA0))
|
2009-06-22 02:36:16 +00:00
|
|
|
_screen->copyPalette(3, 4);
|
2007-03-23 16:24:28 +00:00
|
|
|
else
|
2009-06-22 02:36:16 +00:00
|
|
|
_screen->copyPalette(3, 0);
|
2007-03-23 16:24:28 +00:00
|
|
|
} else {
|
2007-04-01 13:10:50 +00:00
|
|
|
if (_vm->queryGameFlag(0xA0))
|
2009-06-22 02:36:16 +00:00
|
|
|
_screen->copyPalette(1, 3);
|
2007-03-23 16:24:28 +00:00
|
|
|
else
|
2009-06-22 02:36:16 +00:00
|
|
|
_screen->copyPalette(1, 0);
|
2007-03-23 16:24:28 +00:00
|
|
|
|
2009-06-22 02:37:41 +00:00
|
|
|
_screen->getPalette(1).copy(_dat + 0x17, 0, 20, 228);
|
2007-03-12 20:43:56 +00:00
|
|
|
}
|
2005-10-03 20:21:18 +00:00
|
|
|
uint8 *data = _dat + 0x6B;
|
|
|
|
|
|
|
|
uint16 length = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
|
|
|
|
if (length > 2) {
|
|
|
|
assert( length < fileSize);
|
|
|
|
uint8 *animstart;
|
|
|
|
uint8 *start = data;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (((uint16)(data - _dat) >= fileSize) || (data - start) >= length)
|
2007-09-19 08:40:12 +00:00
|
|
|
break;
|
2005-10-03 20:21:18 +00:00
|
|
|
|
|
|
|
if (READ_LE_UINT16(data) == 0xFF83) {
|
2006-02-14 23:31:25 +00:00
|
|
|
//debugC(1, kDebugLevelSprites, "Body section end.");
|
2005-10-03 20:21:18 +00:00
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (READ_LE_UINT16(data)) {
|
|
|
|
case 0xFF81:
|
|
|
|
data += 2;
|
2006-02-14 23:31:25 +00:00
|
|
|
//debugC(1, kDebugLevelSprites, "Body section start");
|
2005-10-03 20:21:18 +00:00
|
|
|
break;
|
|
|
|
case 0xFF82:
|
|
|
|
data += 2;
|
2006-02-14 23:31:25 +00:00
|
|
|
//debugC(1, kDebugLevelSprites, "Unknown 0xFF82 section");
|
2005-10-03 20:21:18 +00:00
|
|
|
break;
|
|
|
|
case 0xFF84:
|
|
|
|
data += 2;
|
2005-10-29 18:37:40 +00:00
|
|
|
_spriteDefStart = data;
|
2007-04-15 16:41:20 +00:00
|
|
|
while (READ_LE_UINT16(data) != 0xFF85)
|
2005-10-03 20:21:18 +00:00
|
|
|
data += 2;
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
case 0xFF86:
|
|
|
|
assert(nextAnim < MAX_NUM_ANIMS);
|
|
|
|
_anims[nextAnim].script = data;
|
2007-02-01 14:57:48 +00:00
|
|
|
_anims[nextAnim].curPos = data;
|
2005-10-03 20:21:18 +00:00
|
|
|
_anims[nextAnim].sprite = -1;
|
|
|
|
_anims[nextAnim].play = true;
|
|
|
|
animstart = data;
|
|
|
|
data += 2;
|
|
|
|
while (READ_LE_UINT16(data) != 0xFF87) {
|
|
|
|
assert((uint16)(data - _dat) < fileSize);
|
|
|
|
data += 2;
|
|
|
|
}
|
|
|
|
_anims[nextAnim].length = data - animstart;
|
2006-04-04 22:04:51 +00:00
|
|
|
//debugC(1, kDebugLevelSprites, "Found an anim script of length %i", _anims[nextAnim].length);
|
2005-10-03 20:21:18 +00:00
|
|
|
nextAnim++;
|
|
|
|
data += 2;
|
|
|
|
break;
|
|
|
|
default:
|
2007-03-07 20:31:19 +00:00
|
|
|
warning("Unknown code in DAT file '%s' offset %d: %x", filename, int(data - _dat), READ_LE_UINT16(data));
|
2005-10-03 20:21:18 +00:00
|
|
|
data += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(fileSize - (data - _dat) == 0xC);
|
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
exits.northXPos = READ_LE_UINT16(data) & 0xFFFC; data += 2;
|
|
|
|
exits.northYPos = *data++ & 0xFFFE;
|
|
|
|
exits.eastXPos = READ_LE_UINT16(data) & 0xFFFC; data += 2;
|
|
|
|
exits.eastYPos = *data++ & 0xFFFE;
|
|
|
|
exits.southXPos = READ_LE_UINT16(data) & 0xFFFC; data += 2;
|
|
|
|
exits.southYPos = *data++ & 0xFFFE;
|
|
|
|
exits.westXPos = READ_LE_UINT16(data) & 0xFFFC; data += 2;
|
|
|
|
exits.westYPos = *data++ & 0xFFFE;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sprites::freeSceneShapes() {
|
2005-11-10 14:08:50 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(_sceneShapes); i++ ) {
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] _sceneShapes[i];
|
2005-11-10 14:08:50 +00:00
|
|
|
_sceneShapes[i] = 0;
|
|
|
|
}
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sprites::loadSceneShapes() {
|
|
|
|
uint8 *data = _spriteDefStart;
|
|
|
|
int spriteNum, x, y, width, height;
|
|
|
|
|
|
|
|
freeSceneShapes();
|
|
|
|
memset( _sceneShapes, 0, sizeof(_sceneShapes));
|
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
if (_spriteDefStart == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int bakPage = _screen->_curPage;
|
|
|
|
_screen->_curPage = 3;
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
while (READ_LE_UINT16(data) != 0xFF85) {
|
|
|
|
spriteNum = READ_LE_UINT16(data);
|
|
|
|
assert(spriteNum < ARRAYSIZE(_sceneShapes));
|
|
|
|
data += 2;
|
|
|
|
x = READ_LE_UINT16(data) * 8;
|
|
|
|
data += 2;
|
|
|
|
y = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
|
|
|
width = READ_LE_UINT16(data) * 8;
|
|
|
|
data += 2;
|
|
|
|
height = READ_LE_UINT16(data);
|
|
|
|
data += 2;
|
2005-11-10 14:08:50 +00:00
|
|
|
_sceneShapes[spriteNum] = _screen->encodeShape(x, y, width, height, 2);
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->_curPage = bakPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprites::refreshSceneAnimObject(uint8 animNum, uint8 shapeNum, uint16 x, uint16 y, bool flipX, bool unkFlag) {
|
2008-05-11 22:32:37 +00:00
|
|
|
Animator_LoK::AnimObject &anim = _vm->animator()->sprites()[animNum];
|
2006-01-02 22:58:59 +00:00
|
|
|
anim.refreshFlag = 1;
|
|
|
|
anim.bkgdChangeFlag = 1;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (unkFlag)
|
2006-01-02 22:58:59 +00:00
|
|
|
anim.flags |= 0x0200;
|
2005-11-10 14:08:50 +00:00
|
|
|
else
|
2006-01-02 22:58:59 +00:00
|
|
|
anim.flags &= 0xFD00;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (flipX)
|
2006-01-02 22:58:59 +00:00
|
|
|
anim.flags |= 1;
|
2005-11-10 14:08:50 +00:00
|
|
|
else
|
2006-01-02 22:58:59 +00:00
|
|
|
anim.flags &= 0xFE;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
anim.sceneAnimPtr = _sceneShapes[shapeNum];
|
|
|
|
anim.animFrameNumber = -1;
|
|
|
|
anim.x1 = x;
|
|
|
|
anim.y1 = y;
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
int Sprites::getDrawLayer(int y) {
|
|
|
|
uint8 returnValue = 0;
|
|
|
|
for (int i = 0; i < ARRAYSIZE(_drawLayerTable); ++i) {
|
|
|
|
uint8 temp = _drawLayerTable[i];
|
|
|
|
if (temp) {
|
2007-04-15 16:41:20 +00:00
|
|
|
if (temp <= y)
|
2005-11-18 23:55:31 +00:00
|
|
|
returnValue = i;
|
|
|
|
}
|
|
|
|
}
|
2007-04-15 16:41:20 +00:00
|
|
|
|
|
|
|
if (returnValue <= 0)
|
2005-11-18 23:55:31 +00:00
|
|
|
returnValue = 1;
|
2007-04-15 16:41:20 +00:00
|
|
|
else if (returnValue >= 7)
|
2005-11-18 23:55:31 +00:00
|
|
|
returnValue = 6;
|
2007-04-15 16:41:20 +00:00
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
return returnValue;
|
|
|
|
}
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Kyra
|
2007-04-15 16:41:20 +00:00
|
|
|
|