2005-04-05 18:08:02 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 Ivan Dubrov
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
2005-04-05 18:08:02 +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
|
2005-04-09 19:19:54 +00:00
|
|
|
* 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-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/gob.h"
|
|
|
|
#include "gob/map.h"
|
|
|
|
#include "gob/video.h"
|
|
|
|
#include "gob/util.h"
|
|
|
|
#include "gob/dataio.h"
|
|
|
|
#include "gob/inter.h"
|
|
|
|
#include "gob/goblin.h"
|
|
|
|
#include "gob/sound.h"
|
2005-04-09 19:32:29 +00:00
|
|
|
#include "gob/scenery.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
Map::Map(GobEngine *vm) : _vm(vm) {
|
|
|
|
for (int i = 0; i < kMapHeight; i++)
|
|
|
|
for (int j = 0; j < kMapWidth; j++) {
|
2006-01-04 01:23:20 +00:00
|
|
|
_passMap[i][j] = 0;
|
|
|
|
_itemsMap[i][j] = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < 40; i++) {
|
2006-01-04 01:23:20 +00:00
|
|
|
_wayPoints[i].x = 0;
|
|
|
|
_wayPoints[i].y = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < 40; i++) {
|
2006-01-04 01:23:20 +00:00
|
|
|
_itemPoses[i].x = 0;
|
|
|
|
_itemPoses[i].y = 0;
|
|
|
|
_itemPoses[i].orient = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
}
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
_nearestWayPoint = 0;
|
|
|
|
_nearestDest = 0;
|
|
|
|
_curGoblinX = 0;
|
|
|
|
_curGoblinY = 0;
|
|
|
|
_destX = 0;
|
|
|
|
_destY = 0;
|
|
|
|
_loadFromAvo = 0;
|
|
|
|
_sourceFile[0] = 0;
|
|
|
|
_avoDataPtr = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Map::placeItem(int16 x, int16 y, int16 id) {
|
2006-01-04 01:23:20 +00:00
|
|
|
if ((_itemsMap[y][x] & 0xff00) != 0)
|
|
|
|
_itemsMap[y][x] = (_itemsMap[y][x] & 0xff00) | id;
|
This should fix a crash which could happen when placing several objects too
close to each other on the ground. (Happened to me on the first level after
destroying the voodoo doll, where I'd drop the banana, the soap and the
false nose close to each other on the ground after using them.)
Reasoning behind the change:
From what I understand, map_itemsMap[] contains information for each "cell"
of the map about which objects are there. Each cell can contain two objects
which are stored in the upper and lower byte of a 16-bit word.
When dropping an object, it is written into map_itemsMap[], but not just to
the indicated cell but also to a few of the surrounding ones. Presumably to
make it easier to pick it up afterwards.
When writing an object to a cell, we check if one of the bytes is already
occupied. If it is, write to the other byte. Otherwise, write to that byte.
(If both bytes are occupied, one will be overwritten.)
The old code assumed that if one byte was free at position (x,y) the same
byte would automatically be the free one in the surrounding cells. This
could cause bad values in the array, since the item was added to an
existing value, rather than replacing it.
This new code makes the check for each cell that is modified. (It also gets
rid of some code duplication.)
svn-id: r17851
2005-04-28 10:34:48 +00:00
|
|
|
else
|
2006-01-04 01:23:20 +00:00
|
|
|
_itemsMap[y][x] = (_itemsMap[y][x] & 0x00ff) | (id << 8);
|
This should fix a crash which could happen when placing several objects too
close to each other on the ground. (Happened to me on the first level after
destroying the voodoo doll, where I'd drop the banana, the soap and the
false nose close to each other on the ground after using them.)
Reasoning behind the change:
From what I understand, map_itemsMap[] contains information for each "cell"
of the map about which objects are there. Each cell can contain two objects
which are stored in the upper and lower byte of a 16-bit word.
When dropping an object, it is written into map_itemsMap[], but not just to
the indicated cell but also to a few of the surrounding ones. Presumably to
make it easier to pick it up afterwards.
When writing an object to a cell, we check if one of the bytes is already
occupied. If it is, write to the other byte. Otherwise, write to that byte.
(If both bytes are occupied, one will be overwritten.)
The old code assumed that if one byte was free at position (x,y) the same
byte would automatically be the free one in the surrounding cells. This
could cause bad values in the array, since the item was added to an
existing value, rather than replacing it.
This new code makes the check for each cell that is modified. (It also gets
rid of some code duplication.)
svn-id: r17851
2005-04-28 10:34:48 +00:00
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
enum {
|
|
|
|
kLeft = (1 << 0),
|
|
|
|
kUp = (1 << 1),
|
|
|
|
kRight = (1 << 2),
|
|
|
|
kDown = (1 << 3)
|
|
|
|
};
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
|
2005-07-10 13:37:03 +00:00
|
|
|
int16 dir = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (x0 == x1 && y0 == y1)
|
|
|
|
return 0;
|
|
|
|
|
2005-12-30 18:39:01 +00:00
|
|
|
if (!(x1 >= 0 && x1 < kMapWidth && y1 >= 0 && y1 < kMapHeight))
|
2005-04-05 15:07:40 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (y1 > y0)
|
2005-07-10 13:37:03 +00:00
|
|
|
dir |= kDown;
|
2005-04-05 15:07:40 +00:00
|
|
|
else if (y1 < y0)
|
2005-07-10 13:37:03 +00:00
|
|
|
dir |= kUp;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (x1 > x0)
|
2005-07-10 13:37:03 +00:00
|
|
|
dir |= kRight;
|
2005-04-05 15:07:40 +00:00
|
|
|
else if (x1 < x0)
|
2005-07-10 13:37:03 +00:00
|
|
|
dir |= kLeft;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (_passMap[y0][x0] == 3 && (dir & kUp)) {
|
|
|
|
if (_passMap[y0 - 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirN;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (_passMap[y0][x0] == 3 && (dir & kDown)) {
|
|
|
|
if (_passMap[y0 + 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirS;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (_passMap[y0][x0] == 6 && (dir & kUp)) {
|
|
|
|
if (_passMap[y0 - 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirN;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (_passMap[y0][x0] == 6 && (dir & kDown)) {
|
|
|
|
if (_passMap[y0 + 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirS;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == kLeft) {
|
2006-01-04 01:23:20 +00:00
|
|
|
if (x0 - 1 >= 0 && _passMap[y0][x0 - 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirW;
|
2005-04-05 15:07:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == kRight) {
|
2006-01-04 01:23:20 +00:00
|
|
|
if (x0 + 1 < kMapWidth && _passMap[y0][x0 + 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirE;
|
2005-04-05 15:07:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == kUp) {
|
2006-01-04 01:23:20 +00:00
|
|
|
if (y0 - 1 >= 0 && _passMap[y0 - 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirN;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (y0 - 1 >= 0 && x0 - 1 >= 0
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 - 1][x0 - 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirNW;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2005-12-30 18:39:01 +00:00
|
|
|
if (y0 - 1 >= 0 && x0 + 1 < kMapWidth
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 - 1][x0 + 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirNE;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == kDown) {
|
2006-01-04 01:23:20 +00:00
|
|
|
if (y0 + 1 < kMapHeight && _passMap[y0 + 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirS;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2005-12-30 18:39:01 +00:00
|
|
|
if (y0 + 1 < kMapHeight && x0 - 1 >= 0
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 + 1][x0 - 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirSW;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2005-12-30 18:39:01 +00:00
|
|
|
if (y0 + 1 < kMapHeight && x0 + 1 < kMapWidth
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 + 1][x0 + 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirSE;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == (kRight | kUp)) {
|
2005-12-30 18:39:01 +00:00
|
|
|
if (y0 - 1 >= 0 && x0 + 1 < kMapWidth
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 - 1][x0 + 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirNE;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (y0 - 1 >= 0 && _passMap[y0 - 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirN;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (x0 + 1 < kMapWidth && _passMap[y0][x0 + 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirE;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == (kRight | kDown)) {
|
2005-12-30 18:39:01 +00:00
|
|
|
if (x0 + 1 < kMapWidth && y0 + 1 < kMapHeight
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 + 1][x0 + 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirSE;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (y0 + 1 < kMapHeight && _passMap[y0 + 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirS;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (x0 + 1 < kMapWidth && _passMap[y0][x0 + 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirE;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == (kLeft | kUp)) {
|
2005-04-05 15:07:40 +00:00
|
|
|
if (x0 - 1 >= 0 && y0 - 1 >= 0
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 - 1][x0 - 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirNW;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (y0 - 1 >= 0 && _passMap[y0 - 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirN;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (x0 - 1 >= 0 && _passMap[y0][x0 - 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirW;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (dir == (kLeft | kDown)) {
|
2005-12-30 18:39:01 +00:00
|
|
|
if (x0 - 1 >= 0 && y0 + 1 < kMapHeight
|
2006-01-04 01:23:20 +00:00
|
|
|
&& _passMap[y0 + 1][x0 - 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirSW;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (y0 + 1 < kMapHeight && _passMap[y0 + 1][x0] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirS;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (x0 - 1 >= 0 && _passMap[y0][x0 - 1] != 0)
|
2005-07-10 13:37:03 +00:00
|
|
|
return kDirW;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
int16 Map::findNearestWayPoint(int16 x, int16 y) {
|
|
|
|
int16 lnearestWayPoint = -1;
|
2005-04-05 15:07:40 +00:00
|
|
|
int16 length;
|
|
|
|
int16 i;
|
|
|
|
int16 tmp;
|
|
|
|
|
|
|
|
length = 30000;
|
|
|
|
|
|
|
|
for (i = 0; i < 40; i++) {
|
2006-01-04 01:23:20 +00:00
|
|
|
if (_wayPoints[i].x < 0 ||
|
|
|
|
_wayPoints[i].x >= kMapWidth ||
|
|
|
|
_wayPoints[i].y < 0 || _wayPoints[i].y >= kMapHeight)
|
2005-07-10 13:37:03 +00:00
|
|
|
return -1;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
tmp = ABS(x - _wayPoints[i].x) + ABS(y - _wayPoints[i].y);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (tmp <= length) {
|
2006-01-03 23:14:39 +00:00
|
|
|
lnearestWayPoint = i;
|
2005-04-05 15:07:40 +00:00
|
|
|
length = tmp;
|
|
|
|
}
|
|
|
|
}
|
2005-07-10 13:37:03 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
return lnearestWayPoint;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Map::findNearestToGob(void) {
|
2006-01-04 01:23:20 +00:00
|
|
|
int16 wayPoint = findNearestWayPoint(_curGoblinX, _curGoblinY);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (wayPoint != -1)
|
2006-01-04 01:23:20 +00:00
|
|
|
_nearestWayPoint = wayPoint;
|
2005-07-10 13:37:03 +00:00
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Map::findNearestToDest(void) {
|
2006-01-04 01:23:20 +00:00
|
|
|
int16 wayPoint = findNearestWayPoint(_destX, _destY);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
if (wayPoint != -1)
|
2006-01-04 01:23:20 +00:00
|
|
|
_nearestDest = wayPoint;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
int16 Map::checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) {
|
2005-04-05 15:07:40 +00:00
|
|
|
uint16 dir;
|
|
|
|
|
|
|
|
while (1) {
|
2006-01-03 23:14:39 +00:00
|
|
|
dir = getDirection(x0, y0, x1, y1);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (x0 == x1 && y0 == y1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (dir == 0)
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
switch (dir) {
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirNW:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0--;
|
|
|
|
y0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirN:
|
2005-04-05 15:07:40 +00:00
|
|
|
y0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirNE:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0++;
|
|
|
|
y0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirW:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirE:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0++;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirSW:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0--;
|
|
|
|
y0++;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirS:
|
2005-04-05 15:07:40 +00:00
|
|
|
y0++;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirSE:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0++;
|
|
|
|
y0++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
int16 Map::checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) {
|
2005-04-05 15:07:40 +00:00
|
|
|
uint16 dir;
|
|
|
|
int16 curX;
|
|
|
|
int16 curY;
|
|
|
|
int16 nextLink;
|
|
|
|
|
|
|
|
curX = x0;
|
|
|
|
curY = y0;
|
|
|
|
dir = 0;
|
|
|
|
|
|
|
|
nextLink = 1;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (x0 == curX && y0 == curY)
|
|
|
|
nextLink = 1;
|
|
|
|
|
|
|
|
if (nextLink != 0) {
|
2006-01-03 23:14:39 +00:00
|
|
|
if (checkDirectPath(x0, y0, x1, y1) == 1)
|
2005-04-05 15:07:40 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
nextLink = 0;
|
|
|
|
if (i0 > i1) {
|
2006-01-04 01:23:20 +00:00
|
|
|
curX = _wayPoints[i0].x;
|
|
|
|
curY = _wayPoints[i0].y;
|
2005-04-05 15:07:40 +00:00
|
|
|
i0--;
|
|
|
|
} else if (i0 < i1) {
|
2006-01-04 01:23:20 +00:00
|
|
|
curX = _wayPoints[i0].x;
|
|
|
|
curY = _wayPoints[i0].y;
|
2005-04-05 15:07:40 +00:00
|
|
|
i0++;
|
|
|
|
} else if (i0 == i1) {
|
2006-01-04 01:23:20 +00:00
|
|
|
curX = _wayPoints[i0].x;
|
|
|
|
curY = _wayPoints[i0].y;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-04 01:23:20 +00:00
|
|
|
if (i0 == i1 && _wayPoints[i0].x == x0
|
|
|
|
&& _wayPoints[i0].y == y0) {
|
2006-01-03 23:14:39 +00:00
|
|
|
if (checkDirectPath(x0, y0, x1, y1) == 1)
|
2005-04-05 15:07:40 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2006-01-03 23:14:39 +00:00
|
|
|
dir = getDirection(x0, y0, curX, curY);
|
2005-04-05 15:07:40 +00:00
|
|
|
switch (dir) {
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirNW:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0--;
|
|
|
|
y0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirN:
|
2005-04-05 15:07:40 +00:00
|
|
|
y0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirNE:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0++;
|
|
|
|
y0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirW:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0--;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirE:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0++;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirSW:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0--;
|
|
|
|
y0++;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirS:
|
2005-04-05 15:07:40 +00:00
|
|
|
y0++;
|
|
|
|
break;
|
|
|
|
|
2005-07-10 13:37:03 +00:00
|
|
|
case kDirSE:
|
2005-04-05 15:07:40 +00:00
|
|
|
x0++;
|
|
|
|
y0++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Map::optimizePoints(void) {
|
2005-04-05 15:07:40 +00:00
|
|
|
int16 i;
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (_nearestWayPoint < _nearestDest) {
|
|
|
|
for (i = _nearestWayPoint; i <= _nearestDest; i++) {
|
|
|
|
if (checkDirectPath(_curGoblinX, _curGoblinY,
|
|
|
|
_wayPoints[i].x, _wayPoints[i].y) == 1)
|
|
|
|
_nearestWayPoint = i;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
2006-01-04 01:23:20 +00:00
|
|
|
} else if (_nearestWayPoint > _nearestDest) {
|
|
|
|
for (i = _nearestWayPoint; i >= _nearestDest; i--) {
|
|
|
|
if (checkDirectPath(_curGoblinX, _curGoblinY,
|
|
|
|
_wayPoints[i].x, _wayPoints[i].y) == 1)
|
|
|
|
_nearestWayPoint = i;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Map::loadDataFromAvo(char *dest, int16 size) {
|
2006-01-04 01:23:20 +00:00
|
|
|
memcpy(dest, _avoDataPtr, size);
|
|
|
|
_avoDataPtr += size;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
uint16 Map::loadFromAvo_LE_UINT16() {
|
2006-01-04 01:23:20 +00:00
|
|
|
uint16 tmp = READ_LE_UINT16(_avoDataPtr);
|
|
|
|
_avoDataPtr += 2;
|
2005-04-11 20:38:17 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Map::loadItemToObject(void) {
|
2005-04-05 15:07:40 +00:00
|
|
|
int16 flag;
|
|
|
|
int16 count;
|
|
|
|
int16 i;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
flag = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
if (flag == 0)
|
|
|
|
return;
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 1456;
|
2006-01-03 23:14:39 +00:00
|
|
|
count = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 20;
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_itemToObject[i] = loadFromAvo_LE_UINT16();
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 5;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Map::loadMapObjects(char *avjFile) {
|
2005-04-05 15:07:40 +00:00
|
|
|
int16 i;
|
|
|
|
char avoName[128];
|
|
|
|
int16 handle;
|
|
|
|
char item;
|
|
|
|
int16 soundCount;
|
|
|
|
int16 tmp;
|
|
|
|
char *savedPtr;
|
|
|
|
char *savedPtr2;
|
|
|
|
char *savedPtr3;
|
|
|
|
int16 state;
|
|
|
|
int16 col;
|
|
|
|
int32 flag;
|
2006-01-03 23:14:39 +00:00
|
|
|
Goblin::Gob_State *pState;
|
2005-04-05 15:07:40 +00:00
|
|
|
char buf[128];
|
|
|
|
char sndNames[20][14];
|
|
|
|
char *dataBuf;
|
|
|
|
int16 x;
|
|
|
|
int16 y;
|
|
|
|
int16 count2;
|
|
|
|
int16 count3;
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
strcpy(avoName, _sourceFile);
|
2005-04-05 15:07:40 +00:00
|
|
|
strcat(avoName, ".avo");
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
handle = _vm->_dataio->openData(avoName);
|
2005-04-05 15:07:40 +00:00
|
|
|
if (handle >= 0) {
|
2006-01-04 01:23:20 +00:00
|
|
|
_loadFromAvo = 1;
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->closeData(handle);
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr = _vm->_dataio->getData(avoName);
|
|
|
|
dataBuf = _avoDataPtr;
|
|
|
|
loadDataFromAvo((char *)_passMap, kMapHeight * kMapWidth);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2005-12-30 18:39:01 +00:00
|
|
|
for (y = 0; y < kMapHeight; y++) {
|
|
|
|
for (x = 0; x < kMapWidth; x++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
loadDataFromAvo(&item, 1);
|
2006-01-04 01:23:20 +00:00
|
|
|
_itemsMap[y][x] = item;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 40; i++) {
|
2006-01-04 01:23:20 +00:00
|
|
|
_wayPoints[i].x = loadFromAvo_LE_UINT16();
|
|
|
|
_wayPoints[i].y = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
2006-01-04 01:23:20 +00:00
|
|
|
loadDataFromAvo((char *)_itemPoses, szMap_ItemPos * 20);
|
2005-04-05 15:07:40 +00:00
|
|
|
} else {
|
2006-01-04 01:23:20 +00:00
|
|
|
_loadFromAvo = 0;
|
|
|
|
_avoDataPtr = _vm->_dataio->getData(avjFile);
|
|
|
|
dataBuf = _avoDataPtr;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 32;
|
|
|
|
_avoDataPtr += 76;
|
|
|
|
_avoDataPtr += 4;
|
|
|
|
_avoDataPtr += 20;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
tmp = loadFromAvo_LE_UINT16();
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += tmp * 14;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
soundCount = loadFromAvo_LE_UINT16();
|
2006-01-04 01:23:20 +00:00
|
|
|
savedPtr = _avoDataPtr;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 14 * soundCount;
|
|
|
|
_avoDataPtr += 4;
|
|
|
|
_avoDataPtr += 24;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
count2 = loadFromAvo_LE_UINT16();
|
|
|
|
count3 = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
savedPtr2 = _avoDataPtr;
|
|
|
|
_avoDataPtr += count2 * 8;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
savedPtr3 = _avoDataPtr;
|
|
|
|
_avoDataPtr += count3 * 8;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_gobsCount = loadFromAvo_LE_UINT16();
|
|
|
|
for (i = 0; i < _vm->_goblin->_gobsCount; i++) {
|
|
|
|
_vm->_goblin->_goblins[i] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object));
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->xPos = READ_LE_UINT16(savedPtr2);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr2 += 2;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->yPos = READ_LE_UINT16(savedPtr2);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr2 += 2;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->order = READ_LE_UINT16(savedPtr2);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr2 += 2;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->state = READ_LE_UINT16(savedPtr2);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr2 += 2;
|
|
|
|
|
|
|
|
if (i == 3)
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 70);
|
2005-04-05 15:07:40 +00:00
|
|
|
else
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
// FIXME: All is wrong further. We should unwind calls to loadDataFromAvo()
|
2006-01-07 22:28:54 +00:00
|
|
|
loadDataFromAvo((char *)_vm->_goblin->_goblins[i]->stateMach, 40 * szGob_StateLine);
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 160;
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->multObjIndex = *_avoDataPtr;
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 2;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->realStateMach = _vm->_goblin->_goblins[i]->stateMach;
|
2005-04-05 15:07:40 +00:00
|
|
|
for (state = 0; state < 40; state++) {
|
|
|
|
for (col = 0; col < 6; col++) {
|
2006-01-07 22:28:54 +00:00
|
|
|
if (_vm->_goblin->_goblins[i]->stateMach[state][col] == 0)
|
2005-04-05 15:07:40 +00:00
|
|
|
continue;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->stateMach[state][col] = tmpState;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->animation = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->layer = loadFromAvo_LE_UINT16();
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 8;
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->unk0 = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->unk1 = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 2;
|
|
|
|
if (READ_LE_UINT32(_avoDataPtr) != 0) {
|
|
|
|
_avoDataPtr += 4;
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->sndItem = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
} else {
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 6;
|
2005-04-11 20:38:17 +00:00
|
|
|
tmpState->sndItem = -1;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->freq = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->repCount = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->sndFrame = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[0]->stateMach[39][0] = pState;
|
2005-04-05 15:07:40 +00:00
|
|
|
pState->animation = 0;
|
|
|
|
pState->layer = 98;
|
|
|
|
pState->unk0 = 0;
|
|
|
|
pState->unk1 = 0;
|
|
|
|
pState->sndItem = -1;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State));
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[1]->stateMach[39][0] = pState;
|
2005-04-05 15:07:40 +00:00
|
|
|
pState->animation = 0;
|
|
|
|
pState->layer = 99;
|
|
|
|
pState->unk0 = 0;
|
|
|
|
pState->unk1 = 0;
|
|
|
|
pState->sndItem = -1;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State));
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[2]->stateMach[39][0] = pState;
|
2005-04-05 15:07:40 +00:00
|
|
|
pState->animation = 0;
|
|
|
|
pState->layer = 100;
|
|
|
|
pState->unk0 = 0;
|
|
|
|
pState->unk1 = 0;
|
|
|
|
pState->sndItem = -1;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[2]->stateMach[10][0]->sndFrame = 13;
|
|
|
|
_vm->_goblin->_goblins[2]->stateMach[11][0]->sndFrame = 13;
|
|
|
|
_vm->_goblin->_goblins[2]->stateMach[28][0]->sndFrame = 13;
|
|
|
|
_vm->_goblin->_goblins[2]->stateMach[29][0]->sndFrame = 13;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[1]->stateMach[10][0]->sndFrame = 13;
|
|
|
|
_vm->_goblin->_goblins[1]->stateMach[11][0]->sndFrame = 13;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
for (state = 40; state < 70; state++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[3]->stateMach[state][0] = pState;
|
|
|
|
_vm->_goblin->_goblins[3]->stateMach[state][1] = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
pState->animation = 9;
|
|
|
|
pState->layer = state - 40;
|
|
|
|
pState->sndItem = -1;
|
2005-05-01 10:15:30 +00:00
|
|
|
pState->sndFrame = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objCount = loadFromAvo_LE_UINT16();
|
|
|
|
for (i = 0; i < _vm->_goblin->_objCount; i++) {
|
|
|
|
_vm->_goblin->_objects[i] =
|
2006-01-03 23:14:39 +00:00
|
|
|
(Goblin::Gob_Object *) malloc(sizeof(Goblin::Gob_Object));
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->xPos = READ_LE_UINT16(savedPtr3);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr3 += 2;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->yPos = READ_LE_UINT16(savedPtr3);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr3 += 2;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->order = READ_LE_UINT16(savedPtr3);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr3 += 2;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->state = READ_LE_UINT16(savedPtr3);
|
2005-04-05 15:07:40 +00:00
|
|
|
savedPtr3 += 2;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
loadDataFromAvo((char *)_vm->_goblin->_objects[i]->stateMach, 40 * szGob_StateLine);
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 160;
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->multObjIndex = *_avoDataPtr;
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 2;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->realStateMach = _vm->_goblin->_objects[i]->stateMach;
|
2005-04-05 15:07:40 +00:00
|
|
|
for (state = 0; state < 40; state++) {
|
|
|
|
for (col = 0; col < 6; col++) {
|
2006-01-07 22:28:54 +00:00
|
|
|
if (_vm->_goblin->_objects[i]->stateMach[state][col] == 0)
|
2005-04-05 15:07:40 +00:00
|
|
|
continue;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[i]->stateMach[state][col] = tmpState;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->animation = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->layer = loadFromAvo_LE_UINT16();
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 8;
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->unk0 = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->unk1 = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 2;
|
|
|
|
if (READ_LE_UINT32(_avoDataPtr) != 0) {
|
|
|
|
_avoDataPtr += 4;
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->sndItem = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
} else {
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 6;
|
2005-04-11 20:38:17 +00:00
|
|
|
tmpState->sndItem = -1;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
2006-01-03 23:14:39 +00:00
|
|
|
tmpState->freq = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->repCount = loadFromAvo_LE_UINT16();
|
|
|
|
tmpState->sndFrame = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[10] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object));
|
|
|
|
memset(_vm->_goblin->_objects[10], 0, sizeof(Goblin::Gob_Object));
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[10]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40);
|
|
|
|
memset(_vm->_goblin->_objects[10]->stateMach, 0, szGob_StateLine * 40);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State));
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[10]->stateMach[0][0] = pState;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
memset(pState, 0, sizeof(Goblin::Gob_State));
|
2005-04-05 15:07:40 +00:00
|
|
|
pState->animation = 9;
|
|
|
|
pState->layer = 27;
|
|
|
|
pState->unk0 = 0;
|
|
|
|
pState->unk1 = 0;
|
|
|
|
pState->sndItem = -1;
|
2005-05-01 10:15:30 +00:00
|
|
|
pState->sndFrame = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->placeObject(_vm->_goblin->_objects[10], 1);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_objects[10]->realStateMach = _vm->_goblin->_objects[10]->stateMach;
|
|
|
|
_vm->_goblin->_objects[10]->type = 1;
|
|
|
|
_vm->_goblin->_objects[10]->unk14 = 1;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
state = loadFromAvo_LE_UINT16();
|
2005-04-05 15:07:40 +00:00
|
|
|
for (i = 0; i < state; i++) {
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 30;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
loadDataFromAvo((char *)&flag, 4);
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 56;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (flag != 0)
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 30;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
loadDataFromAvo((char *)&tmp, 2);
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr += 48;
|
2006-01-03 23:14:39 +00:00
|
|
|
loadItemToObject();
|
2006-01-04 01:23:20 +00:00
|
|
|
_avoDataPtr = savedPtr;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < soundCount; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
loadDataFromAvo(buf, 14);
|
2005-04-05 15:07:40 +00:00
|
|
|
strcat(buf, ".SND");
|
|
|
|
strcpy(sndNames[i], buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(dataBuf);
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_soundData[14] = _vm->_snd->loadSoundData("diamant1.snd");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < soundCount; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
handle = _vm->_dataio->openData(sndNames[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
if (handle < 0)
|
|
|
|
continue;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_dataio->closeData(handle);
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_soundData[i] = _vm->_snd->loadSoundData(sndNames[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Map::loadMapsInitGobs(void) {
|
2005-04-05 15:07:40 +00:00
|
|
|
int16 layer;
|
|
|
|
int16 i;
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
if (_loadFromAvo == 0)
|
2006-01-03 23:14:39 +00:00
|
|
|
error("load: Loading .pas/.pos files is not supported!");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->nextLayer(_vm->_goblin->_goblins[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
|
|
|
layer =
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->stateMach[_vm->_goblin->_goblins[i]->state][0]->layer;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_scenery->updateAnim(layer, 0, _vm->_goblin->_goblins[i]->animation, 0,
|
|
|
|
_vm->_goblin->_goblins[i]->xPos, _vm->_goblin->_goblins[i]->yPos, 0);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->yPos = (_vm->_goblin->_gobPositions[i].y + 1) * 6 -
|
2006-01-09 16:10:22 +00:00
|
|
|
(_vm->_scenery->_toRedrawBottom - _vm->_scenery->_animTop);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[i]->xPos = _vm->_goblin->_gobPositions[i].x * 12 -
|
2006-01-09 16:10:22 +00:00
|
|
|
(_vm->_scenery->_toRedrawLeft - _vm->_scenery->_animLeft);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-09 16:10:22 +00:00
|
|
|
_vm->_goblin->_goblins[i]->order = _vm->_scenery->_toRedrawBottom / 24 + 3;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_currentGoblin = 0;
|
|
|
|
_vm->_goblin->_pressedMapX = _vm->_goblin->_gobPositions[0].x;
|
|
|
|
_vm->_goblin->_pressedMapY = _vm->_goblin->_gobPositions[0].y;
|
|
|
|
_vm->_goblin->_pathExistence = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_goblin->_goblins[0]->doAnim = 0;
|
|
|
|
_vm->_goblin->_goblins[1]->doAnim = 1;
|
|
|
|
_vm->_goblin->_goblins[2]->doAnim = 1;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Gob
|