2006-05-11 19:43:30 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 Ivan Dubrov
|
|
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
2006-06-13 19:15:08 +00:00
|
|
|
#include "common/stream.h"
|
2006-05-11 19:43:30 +00:00
|
|
|
|
|
|
|
#include "gob/gob.h"
|
|
|
|
#include "gob/map.h"
|
2007-03-20 14:51:57 +00:00
|
|
|
#include "gob/global.h"
|
2006-05-11 19:43:30 +00:00
|
|
|
#include "gob/goblin.h"
|
|
|
|
#include "gob/inter.h"
|
|
|
|
#include "gob/game.h"
|
|
|
|
#include "gob/parse.h"
|
|
|
|
#include "gob/mult.h"
|
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
|
|
|
Map_v2::Map_v2(GobEngine *vm) : Map_v1(vm) {
|
|
|
|
}
|
|
|
|
|
2006-06-10 14:37:48 +00:00
|
|
|
Map_v2::~Map_v2() {
|
|
|
|
_passMap = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-17 09:56:09 +00:00
|
|
|
void Map_v2::init(void) {
|
|
|
|
}
|
|
|
|
|
2007-04-02 11:05:09 +00:00
|
|
|
void Map_v2::loadMapObjects(const char *avjFile) {
|
2006-05-29 18:24:52 +00:00
|
|
|
uint8 wayPointsCount;
|
2006-05-11 19:43:30 +00:00
|
|
|
int16 var;
|
|
|
|
int16 id;
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 mapWidth, mapHeight;
|
2006-05-11 19:43:30 +00:00
|
|
|
int16 tmp;
|
2007-04-02 11:05:09 +00:00
|
|
|
byte *variables;
|
|
|
|
byte *extData;
|
2007-03-20 14:51:57 +00:00
|
|
|
uint32 tmpPos;
|
|
|
|
uint32 passPos;
|
2006-05-11 19:43:30 +00:00
|
|
|
|
|
|
|
var = _vm->_parse->parseVarIndex();
|
|
|
|
variables = _vm->_global->_inter_variables + var;
|
|
|
|
|
|
|
|
id = _vm->_inter->load16();
|
|
|
|
|
|
|
|
if (id == -1) {
|
2006-05-29 18:24:52 +00:00
|
|
|
_passMap = (int8 *)(_vm->_global->_inter_variables + var);
|
2006-05-11 19:43:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
extData = _vm->_game->loadExtData(id, 0, 0);
|
2007-04-02 11:05:09 +00:00
|
|
|
Common::MemoryReadStream mapData(extData, 4294967295U);
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2006-06-13 19:15:08 +00:00
|
|
|
if (mapData.readByte() == 3) {
|
|
|
|
_screenWidth = 640;
|
|
|
|
_passWidth = 65;
|
2006-05-11 19:43:30 +00:00
|
|
|
} else {
|
2006-06-13 19:15:08 +00:00
|
|
|
_screenWidth = 320;
|
|
|
|
_passWidth = 40;
|
2006-05-11 19:43:30 +00:00
|
|
|
}
|
2006-06-13 19:15:08 +00:00
|
|
|
_wayPointsCount = mapData.readByte();
|
|
|
|
_tilesWidth = mapData.readSint16LE();
|
|
|
|
_tilesHeight = mapData.readSint16LE();
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2006-06-13 19:15:08 +00:00
|
|
|
_bigTiles = !(_tilesHeight & 0xFF00);
|
|
|
|
_tilesHeight &= 0xFF;
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2006-06-13 19:15:08 +00:00
|
|
|
_mapWidth = _screenWidth / _tilesWidth;
|
|
|
|
_mapHeight = 200 / _tilesHeight;
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
passPos = mapData.pos();
|
|
|
|
mapData.skip(_mapWidth * _mapHeight);
|
2006-05-29 18:24:52 +00:00
|
|
|
|
|
|
|
if (*extData == 1)
|
|
|
|
wayPointsCount = _wayPointsCount = 40;
|
|
|
|
else
|
|
|
|
wayPointsCount = _wayPointsCount == 0 ? 1 : _wayPointsCount;
|
|
|
|
|
2007-02-17 09:56:09 +00:00
|
|
|
if (_wayPoints)
|
|
|
|
delete[] _wayPoints;
|
|
|
|
|
2006-05-29 18:24:52 +00:00
|
|
|
_wayPoints = new Point[wayPointsCount];
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < _wayPointsCount; i++) {
|
2006-06-13 19:15:08 +00:00
|
|
|
_wayPoints[i].x = mapData.readSByte();
|
|
|
|
_wayPoints[i].y = mapData.readSByte();
|
2007-03-20 14:51:57 +00:00
|
|
|
_wayPoints[i].notWalkable = mapData.readSByte();
|
2006-05-11 19:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// In the original asm, this writes byte-wise into the variables-array
|
2007-03-20 14:51:57 +00:00
|
|
|
tmpPos = mapData.pos();
|
|
|
|
mapData.seek(passPos);
|
2006-05-11 19:43:30 +00:00
|
|
|
if (variables != _vm->_global->_inter_variables) {
|
2006-11-27 14:19:30 +00:00
|
|
|
byte *sizes;
|
|
|
|
|
2006-05-29 18:24:52 +00:00
|
|
|
_passMap = (int8 *) variables;
|
2006-06-13 19:15:08 +00:00
|
|
|
mapHeight = 200 / _tilesHeight;
|
|
|
|
mapWidth = _screenWidth / _tilesWidth;
|
2006-11-27 14:19:30 +00:00
|
|
|
sizes = _vm->_global->_inter_variablesSizes +
|
2007-04-02 11:05:09 +00:00
|
|
|
(((byte *) _passMap) - _vm->_global->_inter_variables);
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < mapHeight; i++) {
|
|
|
|
for (int j = 0; j < mapWidth; j++)
|
2006-06-13 19:15:08 +00:00
|
|
|
setPass(j, i, mapData.readSByte());
|
2006-11-27 14:19:30 +00:00
|
|
|
memset(sizes + i * _passWidth, 0, mapWidth);
|
|
|
|
}
|
2006-05-11 19:43:30 +00:00
|
|
|
}
|
2007-03-20 14:51:57 +00:00
|
|
|
mapData.seek(tmpPos);
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2006-06-13 19:15:08 +00:00
|
|
|
tmp = mapData.readSint16LE();
|
2007-03-20 14:51:57 +00:00
|
|
|
mapData.skip(tmp * 14);
|
2006-06-13 19:15:08 +00:00
|
|
|
tmp = mapData.readSint16LE();
|
2007-03-20 14:51:57 +00:00
|
|
|
mapData.skip(tmp * 14 + 28);
|
2006-06-13 19:15:08 +00:00
|
|
|
tmp = mapData.readSint16LE();
|
2007-03-20 14:51:57 +00:00
|
|
|
mapData.skip(tmp * 14);
|
2006-05-11 19:43:30 +00:00
|
|
|
|
|
|
|
_vm->_goblin->_gobsCount = tmp;
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < _vm->_goblin->_gobsCount; i++)
|
|
|
|
loadGoblinStates(mapData, i);
|
2006-05-11 19:43:30 +00:00
|
|
|
|
|
|
|
_vm->_goblin->_soundSlotsCount = _vm->_inter->load16();
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < _vm->_goblin->_soundSlotsCount; i++)
|
2006-05-11 19:43:30 +00:00
|
|
|
_vm->_goblin->_soundSlots[i] = _vm->_inter->loadSound(1);
|
2007-02-17 09:56:09 +00:00
|
|
|
|
|
|
|
delete[] extData;
|
2006-05-11 19:43:30 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
void Map_v2::loadGoblinStates(Common::SeekableReadStream &data, int index) {
|
|
|
|
Mult::Mult_GobState *statesPtr;
|
|
|
|
Mult::Mult_GobState *gobState;
|
|
|
|
int8 indices[102];
|
|
|
|
uint8 statesCount;
|
|
|
|
uint8 dataCount;
|
|
|
|
int16 state;
|
|
|
|
uint32 tmpPos;
|
|
|
|
|
|
|
|
memset(indices, -1, 101);
|
|
|
|
_vm->_mult->_objects[index].goblinStates = new Mult::Mult_GobState*[101];
|
|
|
|
memset(_vm->_mult->_objects[index].goblinStates, 0,
|
|
|
|
101 * sizeof(Mult::Mult_GobState *));
|
|
|
|
|
|
|
|
data.read(indices, 100);
|
|
|
|
tmpPos = data.pos();
|
|
|
|
statesCount = 0;
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
if (indices[i] != -1) {
|
|
|
|
statesCount++;
|
|
|
|
data.skip(4);
|
|
|
|
dataCount = data.readByte();
|
|
|
|
statesCount += dataCount;
|
|
|
|
data.skip(dataCount * 9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data.seek(tmpPos);
|
|
|
|
|
|
|
|
statesPtr = new Mult::Mult_GobState[statesCount];
|
|
|
|
_vm->_mult->_objects[index].goblinStates[0] = statesPtr;
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
state = indices[i];
|
|
|
|
if (state != -1) {
|
|
|
|
_vm->_mult->_objects[index].goblinStates[state] = statesPtr++;
|
|
|
|
gobState = _vm->_mult->_objects[index].goblinStates[state];
|
|
|
|
|
|
|
|
gobState[0].animation = data.readSint16LE();
|
|
|
|
gobState[0].layer = data.readSint16LE();
|
|
|
|
dataCount = data.readByte();
|
|
|
|
gobState[0].dataCount = dataCount;
|
|
|
|
for (uint8 j = 1; j <= dataCount; j++) {
|
|
|
|
data.skip(1);
|
|
|
|
gobState[j].sndItem = data.readSByte();
|
|
|
|
data.skip(1);
|
|
|
|
gobState[j].sndFrame = data.readByte();
|
|
|
|
data.skip(1);
|
|
|
|
gobState[j].freq = data.readSint16LE();
|
|
|
|
gobState[j].repCount = data.readSByte();
|
|
|
|
gobState[j].speaker = data.readByte();
|
|
|
|
statesPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-07 18:49:20 +00:00
|
|
|
void Map_v2::findNearestToGob(Mult::Mult_Object *obj) {
|
2006-05-29 18:24:52 +00:00
|
|
|
int16 wayPoint = findNearestWayPoint(obj->goblinX, obj->goblinY);
|
|
|
|
|
|
|
|
if (wayPoint != -1)
|
|
|
|
obj->nearestWayPoint = wayPoint;
|
|
|
|
}
|
|
|
|
|
2006-06-07 18:49:20 +00:00
|
|
|
void Map_v2::findNearestToDest(Mult::Mult_Object *obj) {
|
2006-05-29 18:24:52 +00:00
|
|
|
int16 wayPoint = findNearestWayPoint(obj->destX, obj->destY);
|
|
|
|
|
|
|
|
if (wayPoint != -1)
|
|
|
|
obj->nearestDest = wayPoint;
|
|
|
|
}
|
|
|
|
|
2006-06-07 18:49:20 +00:00
|
|
|
void Map_v2::optimizePoints(Mult::Mult_Object *obj, int16 x, int16 y) {
|
2006-05-29 18:24:52 +00:00
|
|
|
if (obj->nearestWayPoint < obj->nearestDest) {
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = obj->nearestWayPoint; i <= obj->nearestDest; i++) {
|
2006-06-07 18:49:20 +00:00
|
|
|
if (checkDirectPath(obj, x, y, _wayPoints[i].x, _wayPoints[i].y) == 1)
|
2006-05-29 18:24:52 +00:00
|
|
|
obj->nearestWayPoint = i;
|
|
|
|
}
|
|
|
|
} else {
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = obj->nearestWayPoint;
|
|
|
|
i >= obj->nearestDest && (_wayPoints[i].notWalkable != 1); i--) {
|
2006-06-07 18:49:20 +00:00
|
|
|
if (checkDirectPath(obj, x, y, _wayPoints[i].x, _wayPoints[i].y) == 1)
|
2006-05-29 18:24:52 +00:00
|
|
|
obj->nearestWayPoint = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-11 19:43:30 +00:00
|
|
|
} // End of namespace Gob
|