18
18
* along with this program; if not, write to the Free Software
19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/engines/gob/map.cpp $
22
* $Id: map.cpp 53795 2010-10-25 03:47:53Z drmccoy $
76
85
delete[] _wayPoints;
88
uint8 Map::getVersion() const {
92
int16 Map::getMapWidth() const {
96
int16 Map::getMapHeight() const {
100
int16 Map::getScreenWidth() const {
104
int16 Map::getScreenHeight() const {
105
return _screenHeight;
108
int16 Map::getTilesWidth() const {
112
int16 Map::getTilesHeight() const {
116
bool Map::hasBigTiles() const {
120
int8 Map::getPass(int x, int y, int width) const {
124
if ((x < 0) || (y < 0) || (x >= _mapWidth) || (y >= _mapHeight))
129
return _passMap[y * width + x];
132
void Map::setPass(int x, int y, int8 pass, int width) {
136
if ((x < 0) || (y < 0) || (x >= _mapWidth) || (y >= _mapHeight))
141
_passMap[y * width + x] = pass;
144
const WayPoint &Map::getWayPoint(int n) const {
146
assert(n < _wayPointCount);
148
return _wayPoints[n];
151
int16 Map::getItem(int x, int y) const {
154
x = CLIP<int>(x, 0, _mapWidth - 1);
155
y = CLIP<int>(y, 0, _mapHeight - 1);
157
return _itemsMap[y][x];
160
void Map::setItem(int x, int y, int16 item) {
163
x = CLIP<int>(x, 0, _mapWidth - 1);
164
y = CLIP<int>(y, 0, _mapHeight - 1);
166
_itemsMap[y][x] = item;
79
169
void Map::placeItem(int16 x, int16 y, int16 id) {
80
170
if ((getItem(x, y) & 0xFF00) != 0)
81
171
setItem(x, y, (getItem(x, y) & 0xFF00) | id);
83
173
setItem(x, y, (getItem(x, y) & 0x00FF) | (id << 8));
93
Map::Direction Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
176
Direction Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
94
177
if ((x0 == x1) && (y0 == y1))
95
178
// Already at the destination
99
182
// Destination out of range
185
RelativeDirection relDir = kRelDirNone;
104
187
// Find the direct direction we want to move
189
relDir = kRelDirDown;
107
190
else if (y1 < y0)
194
relDir = (RelativeDirection)(relDir | kRelDirRight);
112
195
else if (x1 < x0)
196
relDir = (RelativeDirection)(relDir | kRelDirLeft);
116
199
// Are we on ladders and can continue the ladder in the wanted direction?
117
if ((getPass(x0, y0) == 3) && (dir & kUp ) && (getPass(x0, y0 - 1) != 0))
200
if ((getPass(x0, y0) == 3) && (relDir & kRelDirUp ) && (getPass(x0, y0 - 1) != 0))
120
if ((getPass(x0, y0) == 3) && (dir & kDown) && (getPass(x0, y0 + 1) != 0))
203
if ((getPass(x0, y0) == 3) && (relDir & kRelDirDown) && (getPass(x0, y0 + 1) != 0))
123
if ((getPass(x0, y0) == 6) && (dir & kUp ) && (getPass(x0, y0 - 1) != 0))
206
if ((getPass(x0, y0) == 6) && (relDir & kRelDirUp ) && (getPass(x0, y0 - 1) != 0))
126
if ((getPass(x0, y0) == 6) && (dir & kDown) && (getPass(x0, y0 + 1) != 0))
209
if ((getPass(x0, y0) == 6) && (relDir & kRelDirDown) && (getPass(x0, y0 + 1) != 0))
130
213
// Want to go left
214
if (relDir == kRelDirLeft) {
132
215
if (getPass(x0 - 1, y0) != 0)
188
271
// Want to go up and right
189
if (dir == (kRight | kUp)) {
272
if (relDir == kRelDirRightUp) {
190
273
if (getPass(x0 + 1, y0 - 1) != 0)
191
274
// Can go north-east
206
289
// Want to go down and right
207
if (dir == (kRight | kDown)) {
290
if (relDir == kRelDirRightDown) {
208
291
if (getPass(x0 + 1, y0 + 1) != 0)
209
292
// Can go south-east
224
307
// Want to go up and left
225
if (dir == (kLeft | kUp)) {
308
if (relDir == kRelDirLeftUp) {
226
309
if (getPass(x0 - 1, y0 - 1) != 0)
227
310
// Can go north-west
242
325
// Want to go left and down
243
if (dir == (kLeft | kDown)) {
326
if (relDir == kRelDirLeftDown) {
244
327
if (getPass(x0 - 1, y0 + 1) != 0)
245
328
// Can go south-west
271
for (int i = 0; i < _wayPointsCount; i++) {
354
for (int i = 0; i < _wayPointCount; i++) {
272
355
if ((_wayPoints[i].x < 0) || (_wayPoints[i].x >= _mapWidth) ||
273
356
(_wayPoints[i].y < 0) || (_wayPoints[i].y >= _mapHeight))
402
485
// Check for a blocking waypoint
404
487
if (obj->nearestWayPoint < obj->nearestDest)
405
if ((obj->nearestWayPoint + 1) < _wayPointsCount)
488
if ((obj->nearestWayPoint + 1) < _wayPointCount)
406
489
if (_wayPoints[obj->nearestWayPoint + 1].notWalkable == 1)