[Scummvm-cvs-logs] SF.net SVN: scummvm:[53795] scummvm/branches/branch-1-2-0/engines/gob
drmccoy at users.sourceforge.net
drmccoy at users.sourceforge.net
Mon Oct 25 05:47:53 CEST 2010
Revision: 53795
http://scummvm.svn.sourceforge.net/scummvm/?rev=53795&view=rev
Author: drmccoy
Date: 2010-10-25 03:47:53 +0000 (Mon, 25 Oct 2010)
Log Message:
-----------
GOB: Backporting r53787 - r53794
Walking cleanup and fixes
Modified Paths:
--------------
scummvm/branches/branch-1-2-0/engines/gob/goblin.cpp
scummvm/branches/branch-1-2-0/engines/gob/goblin_v1.cpp
scummvm/branches/branch-1-2-0/engines/gob/goblin_v2.cpp
scummvm/branches/branch-1-2-0/engines/gob/map.cpp
scummvm/branches/branch-1-2-0/engines/gob/map.h
scummvm/branches/branch-1-2-0/engines/gob/map_v2.cpp
Modified: scummvm/branches/branch-1-2-0/engines/gob/goblin.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/gob/goblin.cpp 2010-10-25 03:39:58 UTC (rev 53794)
+++ scummvm/branches/branch-1-2-0/engines/gob/goblin.cpp 2010-10-25 03:47:53 UTC (rev 53795)
@@ -1780,40 +1780,69 @@
}
void Goblin::move(int16 destX, int16 destY, int16 objIndex) {
- Mult::Mult_Object *obj;
- Mult::Mult_AnimData *animData;
- int16 mouseX;
- int16 mouseY;
- int16 gobDestX;
- int16 gobDestY;
- obj = &_vm->_mult->_objects[objIndex];
- animData = obj->pAnimData;
+ Mult::Mult_Object *obj = &_vm->_mult->_objects[objIndex];
+ Mult::Mult_AnimData *animData = obj->pAnimData;
- obj->gobDestX = destX;
- obj->gobDestY = destY;
+ obj->gobDestX = destX;
+ obj->gobDestY = destY;
animData->destX = destX;
animData->destY = destY;
if (animData->isBusy != 0) {
if ((destX == -1) && (destY == -1)) {
- mouseX = _vm->_global->_inter_mouseX;
- mouseY = _vm->_global->_inter_mouseY;
+ int16 mouseX = _vm->_global->_inter_mouseX;
+ int16 mouseY = _vm->_global->_inter_mouseY;
+
if (_vm->_map->_bigTiles)
mouseY += ((_vm->_global->_inter_mouseY / _vm->_map->_tilesHeight) + 1) / 2;
- gobDestX = mouseX / _vm->_map->_tilesWidth;
- gobDestY = mouseY / _vm->_map->_tilesHeight;
+ int16 gobDestX = mouseX / _vm->_map->_tilesWidth;
+ int16 gobDestY = mouseY / _vm->_map->_tilesHeight;
if (_vm->_map->getPass(gobDestX, gobDestY) == 0)
_vm->_map->findNearestWalkable(gobDestX, gobDestY, mouseX, mouseY);
- animData->destX = obj->gobDestX =
- (gobDestX == -1) ? obj->goblinX : gobDestX;
- animData->destY = obj->gobDestY =
- (gobDestY == -1) ? obj->goblinY : gobDestY;
+ obj->gobDestX = (gobDestX == -1) ? obj->goblinX : gobDestX;
+ obj->gobDestY = (gobDestY == -1) ? obj->goblinY : gobDestY;
+
+ animData->destX = obj->gobDestX;
+ animData->destY = obj->gobDestY;
}
}
+
+ WRITE_VAR(56, 0);
+
+ byte passType = _vm->_map->getPass(obj->gobDestX, obj->gobDestY);
+
+ // Prevent continous walking on wide stairs
+ if (passType == 11) {
+ if (_vm->_map->_screenWidth == 640) {
+ obj->gobDestY++;
+ animData->destY++;
+ }
+ }
+
+ // Prevent stopping in the middle of big ladders
+ if ((passType == 19) || (passType == 20)) {
+ int ladderTop = 0;
+ while (_vm->_map->getPass(obj->gobDestX, obj->gobDestY + ladderTop) == passType)
+ ladderTop++;
+
+ int ladderBottom = 0;
+ while (_vm->_map->getPass(obj->gobDestX, obj->gobDestY + ladderBottom) == passType)
+ ladderBottom--;
+
+ int ladderDest;
+ if (ABS(ladderBottom) <= ladderTop)
+ ladderDest = obj->gobDestY + ladderBottom;
+ else
+ ladderDest = obj->gobDestY + ladderTop;
+
+ obj->gobDestY = ladderDest;
+ animData->destY = ladderDest;
+ }
+
initiateMove(obj);
}
Modified: scummvm/branches/branch-1-2-0/engines/gob/goblin_v1.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/gob/goblin_v1.cpp 2010-10-25 03:39:58 UTC (rev 53794)
+++ scummvm/branches/branch-1-2-0/engines/gob/goblin_v1.cpp 2010-10-25 03:47:53 UTC (rev 53795)
@@ -173,10 +173,10 @@
_pathExistence = 0;
}
- nextAct = _vm->_map->getDirection(_vm->_map->_curGoblinX,
+ nextAct = (int16) _vm->_map->getDirection(_vm->_map->_curGoblinX,
_vm->_map->_curGoblinY, _vm->_map->_destX, _vm->_map->_destY);
- if (nextAct == 0)
+ if (nextAct == Map::kDirNone)
_pathExistence = 0;
} else if (_pathExistence == 3) {
_vm->_map->_curGoblinX = _gobPositions[_currentGoblin].x;
@@ -229,7 +229,7 @@
}
}
}
- nextAct = _vm->_map->getDirection(_vm->_map->_curGoblinX,
+ nextAct = (int16) _vm->_map->getDirection(_vm->_map->_curGoblinX,
_vm->_map->_curGoblinY, _vm->_map->_destX, _vm->_map->_destY);
}
}
Modified: scummvm/branches/branch-1-2-0/engines/gob/goblin_v2.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/gob/goblin_v2.cpp 2010-10-25 03:39:58 UTC (rev 53794)
+++ scummvm/branches/branch-1-2-0/engines/gob/goblin_v2.cpp 2010-10-25 03:47:53 UTC (rev 53795)
@@ -39,10 +39,10 @@
Goblin_v2::Goblin_v2(GobEngine *vm) : Goblin_v1(vm) {
_gobsCount = -1;
- _rotStates[0][0] = 0; _rotStates[0][1] = 18; _rotStates[0][2] = 19; _rotStates[0][3] = 20;
- _rotStates[1][0] = 13; _rotStates[1][1] = 2; _rotStates[1][2] = 12; _rotStates[1][3] = 14;
- _rotStates[2][0] = 16; _rotStates[2][1] = 15; _rotStates[2][2] = 4; _rotStates[2][3] = 17;
- _rotStates[3][0] = 23; _rotStates[3][1] = 21; _rotStates[3][2] = 22; _rotStates[3][3] = 6;
+ _rotStates[0][0] = 0; _rotStates[0][1] = 18; _rotStates[0][2] = 19; _rotStates[0][3] = 20;
+ _rotStates[1][0] = 13; _rotStates[1][1] = 2; _rotStates[1][2] = 12; _rotStates[1][3] = 14;
+ _rotStates[2][0] = 16; _rotStates[2][1] = 15; _rotStates[2][2] = 4; _rotStates[2][3] = 17;
+ _rotStates[3][0] = 23; _rotStates[3][1] = 21; _rotStates[3][2] = 22; _rotStates[3][3] = 6;
}
void Goblin_v2::freeObjects() {
@@ -127,44 +127,39 @@
}
void Goblin_v2::movePathFind(Mult::Mult_Object *obj, Gob_Object *gobDesc, int16 nextAct) {
- Mult::Mult_AnimData *animData;
- int16 framesCount;
- int16 gobX;
- int16 gobY;
- int16 gobDestX;
- int16 gobDestY;
- int16 destX;
- int16 destY;
- int16 dir;
+ Mult::Mult_AnimData *animData = obj->pAnimData;
- dir = 0;
- animData = obj->pAnimData;
- framesCount = _vm->_scenery->getAnimLayer(animData->animation, animData->layer)->framesCount;
- animData->newCycle = framesCount;
- gobX = obj->goblinX;
- gobY = obj->goblinY;
- animData->order = gobY;
- gobDestX = obj->gobDestX;
- gobDestY = obj->gobDestY;
+ animData->newCycle = _vm->_scenery->getAnimLayer(animData->animation, animData->layer)->framesCount;
+
+ int16 gobX = obj->goblinX;
+ int16 gobY = obj->goblinY;
+ int16 destX = obj->destX;
+ int16 destY = obj->destY;
+ int16 gobDestX = obj->gobDestX;
+ int16 gobDestY = obj->gobDestY;
+
animData->destX = gobDestX;
animData->destY = gobDestY;
- destX = obj->destX;
- destY = obj->destY;
+ animData->order = gobY;
+ Map::Direction dir = Map::kDirNone;
+
if (animData->pathExistence == 1) {
+
dir = _vm->_map->getDirection(gobX, gobY, destX, destY);
- if (dir == 0)
+ if (dir == Map::kDirNone)
animData->pathExistence = 0;
- if ((gobX == destX) && (gobY == destY))
+ if ((gobX == gobDestX) && (gobY == gobDestY))
animData->pathExistence = 4;
+
} else if (animData->pathExistence == 3) {
- if ((gobX == gobDestX) && (gobY == gobDestY)) {
- animData->pathExistence = 4;
- destX = gobDestX;
- destY = gobDestY;
- } else {
+
+ if ((gobX != gobDestX) || (gobY != gobDestY)) {
+
if (_vm->_map->checkDirectPath(obj, gobX, gobY, gobDestX, gobDestY) != 1) {
+
if ((gobX == destX) && (gobY == destY)) {
+
if (obj->nearestWayPoint > obj->nearestDest) {
_vm->_map->optimizePoints(obj, gobX, gobY);
destX = _vm->_map->_wayPoints[obj->nearestWayPoint].x;
@@ -197,21 +192,30 @@
destY = gobDestY;
}
}
+
}
+
} else {
destX = gobDestX;
destY = gobDestY;
}
+
dir = _vm->_map->getDirection(gobX, gobY, destX, destY);
+
+ } else {
+ animData->pathExistence = 4;
+ destX = gobDestX;
+ destY = gobDestY;
}
+
}
- obj->goblinX = gobX;
- obj->goblinY = gobY;
- obj->gobDestX = gobDestX;
- obj->gobDestY = gobDestY;
- obj->destX = destX;
- obj->destY = destY;
+ obj->goblinX = gobX;
+ obj->goblinY = gobY;
+ obj->destX = destX;
+ obj->destY = destY;
+ obj->gobDestX = gobDestX;
+ obj->gobDestY = gobDestY;
switch (dir) {
case Map::kDirNW:
@@ -229,22 +233,23 @@
(animData->curLookDir == 2) ? 2 : rotateState(animData->curLookDir, 2);
if (_vm->_map->_screenWidth == 640) {
if (_vm->_map->getPass(obj->goblinX, obj->goblinY) == 10) {
- if (_vm->_map->getPass(obj->goblinX - 1, obj->goblinY - 2) != 10) {
- if (_vm->_map->getPass(obj->goblinX + 1, obj->goblinY - 2) == 10)
- animData->nextState = 42;
- else
- animData->nextState = 2;
- } else
+ if (_vm->_map->getPass(obj->goblinX - 1, obj->goblinY - 2) == 10)
animData->nextState = 40;
- } else if (_vm->_map->getPass(obj->goblinX, obj->goblinY) == 20)
+ else if (_vm->_map->getPass(obj->goblinX + 1, obj->goblinY - 2) == 10)
+ animData->nextState = 42;
+ else
+ animData->nextState = 2;
+ }
+
+ if (_vm->_map->getPass(obj->goblinX, obj->goblinY) == 20)
animData->nextState = 38;
- else if (_vm->_map->getPass(obj->goblinX, obj->goblinY) == 19)
+ if (_vm->_map->getPass(obj->goblinX, obj->goblinY) == 19)
animData->nextState = 26;
}
break;
case Map::kDirNE:
- animData->nextState = 3;
+ animData->nextState = 3;
if (_vm->_map->_screenWidth == 640) {
if (_vm->_map->getPass(obj->goblinX, obj->goblinY) == 10)
animData->nextState = 42;
@@ -293,7 +298,7 @@
break;
default:
- if (animData->curLookDir == 0)
+ if (animData->curLookDir == 0)
animData->nextState = 8;
else if (animData->curLookDir == 2)
animData->nextState = 29;
@@ -307,12 +312,6 @@
void Goblin_v2::moveAdvance(Mult::Mult_Object *obj, Gob_Object *gobDesc,
int16 nextAct, int16 framesCount) {
- Mult::Mult_AnimData *animData;
- int16 gobX;
- int16 gobY;
- int16 animation;
- int16 state;
- int16 layer;
if (!obj->goblinStates)
return;
@@ -320,7 +319,7 @@
movePathFind(obj, 0, 0);
playSounds(obj);
- animData = obj->pAnimData;
+ Mult::Mult_AnimData *animData = obj->pAnimData;
framesCount = _vm->_scenery->getAnimLayer(animData->animation, animData->layer)->framesCount;
@@ -395,72 +394,87 @@
}
if ((animData->newState != -1) && (animData->frame == framesCount) &&
- (animData->newState != animData->state)) {
+ (animData->newState != animData->state)) {
+
animData->nextState = animData->newState;
- animData->newState = -1;
- animData->state = animData->nextState;
+ animData->newState = -1;
+ animData->state = animData->nextState;
Scenery::AnimLayer *animLayer =
_vm->_scenery->getAnimLayer(animData->animation, animData->layer);
+
*obj->pPosX += animLayer->animDeltaX;
*obj->pPosY += animLayer->animDeltaY;
- animation = obj->goblinStates[animData->nextState][0].animation;
- layer = obj->goblinStates[animData->nextState][0].layer;
- animData->layer = layer;
+ int16 animation = obj->goblinStates[animData->nextState][0].animation;
+ int16 layer = obj->goblinStates[animData->nextState][0].layer;
+
+ animData->layer = layer;
animData->animation = animation;
- animData->frame = 0;
- } else {
- if (isMovement(animData->state)) {
- state = animData->nextState;
- if (animData->frame == ((framesCount + 1) / 2)) {
- gobX = obj->goblinX;
- gobY = obj->goblinY;
+ animData->frame = 0;
- advMovement(obj, state);
+ return;
+ }
- if (animData->state != state) {
- animation = obj->goblinStates[state][0].animation;
- layer = obj->goblinStates[state][0].layer;
- animData->layer = layer;
- animData->animation = animation;
- animData->frame = 0;
- animData->state = state;
- _vm->_scenery->updateAnim(layer, 0, animation, 0, *obj->pPosX, *obj->pPosY, 0);
- if (_vm->_map->_bigTiles)
- *obj->pPosY = ((gobY + 1) * _vm->_map->_tilesHeight) -
- (_vm->_scenery->_animBottom - _vm->_scenery->_animTop) - (gobY + 1) / 2;
- else
- *obj->pPosY = ((gobY + 1) * _vm->_map->_tilesHeight) -
- (_vm->_scenery->_animBottom - _vm->_scenery->_animTop);
- *obj->pPosX = gobX * _vm->_map->_tilesWidth;
- }
- }
- }
+ if (isMovement(animData->state)) {
+ int16 state = animData->nextState;
- if (animData->frame >= framesCount) {
- state = animData->nextState;
- animation = obj->goblinStates[state][0].animation;
- layer = obj->goblinStates[state][0].layer;
- animData->layer = layer;
- animData->animation = animation;
- animData->frame = 0;
- animData->state = state;
- gobX = obj->goblinX;
- gobY = obj->goblinY;
+ if (animData->frame == ((framesCount + 1) / 2)) {
+ int16 gobX = obj->goblinX;
+ int16 gobY = obj->goblinY + 1;
advMovement(obj, state);
- _vm->_scenery->updateAnim(layer, 0, animation, 0, *obj->pPosX, *obj->pPosY, 0);
- if (_vm->_map->_bigTiles)
- *obj->pPosY = ((gobY + 1) * _vm->_map->_tilesHeight) -
- (_vm->_scenery->_animBottom - _vm->_scenery->_animTop) - (gobY + 1) / 2;
- else
- *obj->pPosY = ((gobY + 1) * _vm->_map->_tilesHeight) -
- (_vm->_scenery->_animBottom - _vm->_scenery->_animTop);
- *obj->pPosX = gobX * _vm->_map->_tilesWidth;
+ if (animData->state != state) {
+ int16 animation = obj->goblinStates[state][0].animation;
+ int16 layer = obj->goblinStates[state][0].layer;
+
+ animData->layer = layer;
+ animData->animation = animation;
+ animData->frame = 0;
+ animData->state = state;
+
+ _vm->_scenery->updateAnim(layer, 0, animation, 0, *obj->pPosX, *obj->pPosY, 0);
+ uint32 gobPosX = gobX * _vm->_map->_tilesWidth;
+ uint32 gobPosY = (gobY * _vm->_map->_tilesHeight) -
+ (_vm->_scenery->_animBottom - _vm->_scenery->_animTop);
+
+ if (_vm->_map->_bigTiles)
+ gobPosY -= gobY / 2;
+
+ *obj->pPosX = gobPosX;
+ *obj->pPosY = gobPosY;
+ }
}
}
+
+ if (animData->frame < framesCount)
+ return;
+
+ int16 state = animData->nextState;
+ int16 animation = obj->goblinStates[state][0].animation;
+ int16 layer = obj->goblinStates[state][0].layer;
+
+ animData->layer = layer;
+ animData->animation = animation;
+ animData->frame = 0;
+ animData->state = state;
+
+ int16 gobX = obj->goblinX;
+ int16 gobY = obj->goblinY + 1;
+
+ advMovement(obj, state);
+
+ _vm->_scenery->updateAnim(layer, 0, animation, 0, *obj->pPosX, *obj->pPosY, 0);
+ uint32 gobPosX = gobX * _vm->_map->_tilesWidth;
+ uint32 gobPosY = (gobY * _vm->_map->_tilesHeight) -
+ (_vm->_scenery->_animBottom - _vm->_scenery->_animTop);
+
+ if (_vm->_map->_bigTiles)
+ gobPosY -= gobY / 2;
+
+ *obj->pPosX = gobPosX;
+ *obj->pPosY = gobPosY;
}
void Goblin_v2::handleGoblins() {
Modified: scummvm/branches/branch-1-2-0/engines/gob/map.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/gob/map.cpp 2010-10-25 03:39:58 UTC (rev 53794)
+++ scummvm/branches/branch-1-2-0/engines/gob/map.cpp 2010-10-25 03:47:53 UTC (rev 53795)
@@ -90,15 +90,18 @@
kDown = (1 << 3)
};
-int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
- int16 dir = 0;
-
+Map::Direction Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) {
if ((x0 == x1) && (y0 == y1))
- return 0;
+ // Already at the destination
+ return kDirNone;
if ((x1 < 0) || (x1 > _mapWidth) || (y1 < 0) || (y1 > _mapHeight))
- return 0;
+ // Destination out of range
+ return kDirNone;
+ int16 dir = 0;
+
+ // Find the direct direction we want to move
if (y1 > y0)
dir |= kDown;
else if (y1 < y0)
@@ -109,124 +112,153 @@
else if (x1 < x0)
dir |= kLeft;
- if ((getPass(x0, y0) == 3) && (dir & kUp)) {
- if ((getPass(x0, y0 - 1) != 0))
- return kDirN;
- }
- if ((getPass(x0, y0) == 3) && (dir & kDown)) {
- if ((getPass(x0, y0 + 1) != 0))
- return kDirS;
- }
+ // Are we on ladders and can continue the ladder in the wanted direction?
+ if ((getPass(x0, y0) == 3) && (dir & kUp ) && (getPass(x0, y0 - 1) != 0))
+ return kDirN;
- if ((getPass(x0, y0) == 6) && (dir & kUp)) {
- if ((getPass(x0, y0 - 1) != 0))
- return kDirN;
- }
+ if ((getPass(x0, y0) == 3) && (dir & kDown) && (getPass(x0, y0 + 1) != 0))
+ return kDirS;
- if ((getPass(x0, y0) == 6) && (dir & kDown)) {
- if ((getPass(x0, y0 + 1) != 0))
- return kDirS;
- }
+ if ((getPass(x0, y0) == 6) && (dir & kUp ) && (getPass(x0, y0 - 1) != 0))
+ return kDirN;
+ if ((getPass(x0, y0) == 6) && (dir & kDown) && (getPass(x0, y0 + 1) != 0))
+ return kDirS;
+
+
+ // Want to go left
if (dir == kLeft) {
- if (((x0 - 1) >= 0) && (getPass(x0 - 1, y0) != 0))
+ if (getPass(x0 - 1, y0) != 0)
+ // Can go west
return kDirW;
- return 0;
+
+ // Can't go
+ return kDirNone;
}
+ // Want to go left
if (dir == kRight) {
- if (((x0 + 1) < _mapWidth) && (getPass(x0 + 1, y0) != 0))
+ if (getPass(x0 + 1, y0) != 0)
+ // Can go east
return kDirE;
- return 0;
+
+ // Can't go
+ return kDirNone;
}
+
+ // Want to go up
if (dir == kUp) {
- if (((y0 - 1) >= 0) && (getPass(x0, y0 - 1) != 0))
+ if (getPass(x0 , y0 - 1) != 0)
+ // Can go north
return kDirN;
- if (((y0 - 1) >= 0) && ((x0 - 1) >= 0) &&
- (getPass(x0 - 1, y0 - 1) != 0))
+ if (getPass(x0 - 1, y0 - 1) != 0)
+ // Can up north-west instead
return kDirNW;
- if (((y0 - 1) >= 0) && ((x0 + 1) < _mapWidth) &&
- (getPass(x0 + 1, y0 - 1) != 0))
+ if (getPass(x0 + 1, y0 - 1) != 0)
+ // Can up north-east instead
return kDirNE;
- return 0;
+ // Can't go at all
+ return kDirNone;
}
+ // Want to go down
if (dir == kDown) {
- if (((y0 + 1) < _mapHeight) && (getPass(x0, y0 + 1) != 0))
+ if (getPass(x0 , y0 + 1) != 0)
+ // Can go south
return kDirS;
- if (((y0 + 1) < _mapHeight) && ((x0 - 1) >= 0) &&
- (getPass(x0 - 1, y0 + 1) != 0))
+ if (getPass(x0 - 1, y0 + 1) != 0)
+ // Can up south-west instead
return kDirSW;
- if (((y0 + 1) < _mapHeight) && ((x0 + 1) < _mapWidth) &&
- (getPass(x0 + 1, y0 + 1) != 0))
+ if (getPass(x0 + 1, y0 + 1) != 0)
+ // Can up south-east instead
return kDirSE;
- return 0;
+ // Can't go at all
+ return kDirNone;
}
+
+ // Want to go up and right
if (dir == (kRight | kUp)) {
- if (((y0 - 1) >= 0) && ((x0 + 1) < _mapWidth) &&
- (getPass(x0 + 1, y0 - 1) != 0))
+ if (getPass(x0 + 1, y0 - 1) != 0)
+ // Can go north-east
return kDirNE;
- if (((y0 - 1) >= 0) && (getPass(x0, y0 - 1) != 0))
+ if (getPass(x0 , y0 - 1) != 0)
+ // Can only go north
return kDirN;
- if (((x0 + 1) < _mapWidth) && (getPass(x0 + 1, y0) != 0))
+ if (getPass(x0 + 1, y0 ) != 0)
+ // Can only go east
return kDirE;
- return 0;
+ // Can't go at all
+ return kDirNone;
}
+ // Want to go down and right
if (dir == (kRight | kDown)) {
- if (((x0 + 1) < _mapWidth) && ((y0 + 1) < _mapHeight) &&
- (getPass(x0 + 1, y0 + 1) != 0))
+ if (getPass(x0 + 1, y0 + 1) != 0)
+ // Can go south-east
return kDirSE;
- if (((y0 + 1) < _mapHeight) && (getPass(x0, y0 + 1) != 0))
+ if (getPass(x0 , y0 + 1) != 0)
+ // Can only go south
return kDirS;
- if (((x0 + 1) < _mapWidth) && (getPass(x0 + 1, y0) != 0))
+ if (getPass(x0 + 1, y0 ) != 0)
+ // Can only go east
return kDirE;
- return 0;
+ // Can't go at all
+ return kDirNone;
}
+ // Want to go up and left
if (dir == (kLeft | kUp)) {
- if (((x0 - 1) >= 0) && ((y0 - 1) >= 0) &&
- (getPass(x0 - 1, y0 - 1) != 0))
+ if (getPass(x0 - 1, y0 - 1) != 0)
+ // Can go north-west
return kDirNW;
- if (((y0 - 1) >= 0) && (getPass(x0, y0 - 1) != 0))
+ if (getPass(x0 , y0 - 1) != 0)
+ // Can only go north
return kDirN;
- if (((x0 - 1) >= 0) && (getPass(x0 - 1, y0) != 0))
+ if (getPass(x0 - 1, y0 ) != 0)
+ // Can only go west
return kDirW;
- return 0;
+ // Can't go at all
+ return kDirNone;
}
+ // Want to go left and down
if (dir == (kLeft | kDown)) {
- if (((x0 - 1) >= 0) && ((y0 + 1) < _mapHeight) &&
- (getPass(x0 - 1, y0 + 1) != 0))
+ if (getPass(x0 - 1, y0 + 1) != 0)
+ // Can go south-west
return kDirSW;
- if (((y0 + 1) < _mapHeight) && (getPass(x0, y0 + 1) != 0))
+ if (getPass(x0 , y0 + 1) != 0)
+ // Can only go south
return kDirS;
- if (((x0 - 1) >= 0) && (getPass(x0 - 1, y0) != 0))
+ if (getPass(x0 - 1, y0 ) != 0)
+ // Can only go west
return kDirW;
- return 0;
+ // Can't go at all
+ return kDirNone;
}
- return -1;
+
+ warning("Map::getDirection(): Invalid direction?!?");
+ return kDirNone;
}
int16 Map::findNearestWayPoint(int16 x, int16 y) {
@@ -318,73 +350,81 @@
gobDestY -= distance;
}
-int16 Map::checkDirectPath(Mult::Mult_Object *obj,
- int16 x0, int16 y0, int16 x1, int16 y1) {
- uint16 dir;
+void Map::moveDirection(Direction dir, int16 &x, int16 &y) {
+ switch (dir) {
+ case kDirNW:
+ x--;
+ y--;
+ break;
- while (1) {
- dir = getDirection(x0, y0, x1, y1);
+ case kDirN:
+ y--;
+ break;
- if (obj) {
- if (obj->nearestWayPoint < obj->nearestDest) {
- if (_wayPoints[obj->nearestWayPoint + 1].notWalkable == 1)
- return 3;
- } else if (obj->nearestWayPoint > obj->nearestDest) {
- if (obj->nearestDest > 0)
- if (_wayPoints[obj->nearestDest - 1].notWalkable == 1)
- return 3;
- }
- }
+ case kDirNE:
+ x++;
+ y--;
+ break;
- if ((x0 == x1) && (y0 == y1))
- return 1;
+ case kDirW:
+ x--;
+ break;
- if (dir == 0)
- return 3;
+ case kDirE:
+ x++;
+ break;
- switch (dir) {
- case kDirNW:
- x0--;
- y0--;
- break;
+ case kDirSW:
+ x--;
+ y++;
+ break;
- case kDirN:
- y0--;
- break;
+ case kDirS:
+ y++;
+ break;
- case kDirNE:
- x0++;
- y0--;
- break;
+ case kDirSE:
+ x++;
+ y++;
+ break;
- case kDirW:
- x0--;
- break;
+ default:
+ break;
+ }
+}
- case kDirE:
- x0++;
- break;
+int16 Map::checkDirectPath(Mult::Mult_Object *obj, int16 x0, int16 y0, int16 x1, int16 y1) {
- case kDirSW:
- x0--;
- y0++;
- break;
+ while (1) {
+ Direction dir = getDirection(x0, y0, x1, y1);
- case kDirS:
- y0++;
- break;
+ if (obj) {
+ // Check for a blocking waypoint
- case kDirSE:
- x0++;
- y0++;
- break;
+ if (obj->nearestWayPoint < obj->nearestDest)
+ if ((obj->nearestWayPoint + 1) < _wayPointsCount)
+ if (_wayPoints[obj->nearestWayPoint + 1].notWalkable == 1)
+ return 3;
+
+ if (obj->nearestWayPoint > obj->nearestDest)
+ if (obj->nearestWayPoint > 0)
+ if (_wayPoints[obj->nearestWayPoint - 1].notWalkable == 1)
+ return 3;
}
+
+ if ((x0 == x1) && (y0 == y1))
+ // Successfully reached the destination
+ return 1;
+
+ if (dir == kDirNone)
+ // No way
+ return 3;
+
+ moveDirection(dir, x0, y0);
}
}
-int16 Map::checkLongPath(int16 x0, int16 y0,
- int16 x1, int16 y1, int16 i0, int16 i1) {
- uint16 dir = 0;
+int16 Map::checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) {
int16 curX = x0;
int16 curY = y0;
int16 nextLink = 1;
@@ -417,47 +457,13 @@
return 1;
return 0;
}
- dir = getDirection(x0, y0, curX, curY);
- switch (dir) {
- case 0:
+
+ Direction dir = getDirection(x0, y0, curX, curY);
+ if (dir == kDirNone)
+ // No way
return 0;
- case kDirNW:
- x0--;
- y0--;
- break;
-
- case kDirN:
- y0--;
- break;
-
- case kDirNE:
- x0++;
- y0--;
- break;
-
- case kDirW:
- x0--;
- break;
-
- case kDirE:
- x0++;
- break;
-
- case kDirSW:
- x0--;
- y0++;
- break;
-
- case kDirS:
- y0++;
- break;
-
- case kDirSE:
- x0++;
- y0++;
- break;
- }
+ moveDirection(dir, x0, y0);
}
}
Modified: scummvm/branches/branch-1-2-0/engines/gob/map.h
===================================================================
--- scummvm/branches/branch-1-2-0/engines/gob/map.h 2010-10-25 03:39:58 UTC (rev 53794)
+++ scummvm/branches/branch-1-2-0/engines/gob/map.h 2010-10-25 03:47:53 UTC (rev 53795)
@@ -34,15 +34,16 @@
class Map {
public:
- enum {
- kDirNW = 0x4700,
- kDirN = 0x4800,
- kDirNE = 0x4900,
- kDirW = 0x4B00,
- kDirE = 0x4D00,
- kDirSW = 0x4F00,
- kDirS = 0x5000,
- kDirSE = 0x5100
+ enum Direction {
+ kDirNone = 0x0000,
+ kDirNW = 0x4700,
+ kDirN = 0x4800,
+ kDirNE = 0x4900,
+ kDirW = 0x4B00,
+ kDirE = 0x4D00,
+ kDirSW = 0x4F00,
+ kDirS = 0x5000,
+ kDirSE = 0x5100
};
#include "common/pack-start.h" // START STRUCT PACKING
@@ -94,7 +95,8 @@
void placeItem(int16 x, int16 y, int16 id);
- int16 getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
+ Direction getDirection(int16 x0, int16 y0, int16 x1, int16 y1);
+
int16 checkDirectPath(Mult::Mult_Object *obj, int16 x0,
int16 y0, int16 x1, int16 y1);
int16 checkLongPath(int16 x0, int16 y0,
@@ -122,6 +124,10 @@
GobEngine *_vm;
int16 findNearestWayPoint(int16 x, int16 y);
+
+private:
+ // Move the x and y values according to the direction
+ void moveDirection(Direction dir, int16 &x, int16 &y);
};
class Map_v1 : public Map {
@@ -152,6 +158,9 @@
if (!_passMap)
return 0;
+ if ((x < 0) || (y < 0) || (x >= _mapWidth) || (y >= _mapHeight))
+ return 0;
+
return _passMap[y * _mapWidth + x];
}
@@ -159,6 +168,9 @@
if (!_passMap)
return;
+ if ((x < 0) || (y < 0) || (x >= _mapWidth) || (y >= _mapHeight))
+ return;
+
_passMap[y * _mapWidth + x] = pass;
}
@@ -184,6 +196,9 @@
if (!_passMap)
return 0;
+ if ((x < 0) || (y < 0) || (x >= _mapWidth) || (y >= _mapHeight))
+ return 0;
+
if (heightOff == -1)
heightOff = _passWidth;
return _passMap[y * heightOff + x];
@@ -193,6 +208,9 @@
if (!_passMap)
return;
+ if ((x < 0) || (y < 0) || (x >= _mapWidth) || (y >= _mapHeight))
+ return;
+
if (heightOff == -1)
heightOff = _passWidth;
_passMap[y * heightOff + x] = pass;
Modified: scummvm/branches/branch-1-2-0/engines/gob/map_v2.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/gob/map_v2.cpp 2010-10-25 03:39:58 UTC (rev 53794)
+++ scummvm/branches/branch-1-2-0/engines/gob/map_v2.cpp 2010-10-25 03:47:53 UTC (rev 53795)
@@ -258,17 +258,24 @@
void Map_v2::optimizePoints(Mult::Mult_Object *obj, int16 x, int16 y) {
if (obj->nearestWayPoint < obj->nearestDest) {
+
for (int i = obj->nearestWayPoint; i <= obj->nearestDest; i++) {
if (checkDirectPath(obj, x, y, _wayPoints[i].x, _wayPoints[i].y) == 1)
obj->nearestWayPoint = i;
}
+
} else {
- for (int i = obj->nearestWayPoint;
- i >= obj->nearestDest && (_wayPoints[i].notWalkable != 1); i--) {
+
+ for (int i = obj->nearestWayPoint; i >= obj->nearestDest; i++) {
+ if (_wayPoints[i].notWalkable == 1)
+ break;
+
if (checkDirectPath(obj, x, y, _wayPoints[i].x, _wayPoints[i].y) == 1)
obj->nearestWayPoint = i;
}
+
}
+
}
} // End of namespace Gob
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list