aboutsummaryrefslogtreecommitdiff
path: root/engines/hdb
diff options
context:
space:
mode:
authorEugene Sandulenko2019-07-23 11:05:15 +0200
committerEugene Sandulenko2019-09-03 17:17:26 +0200
commit20a270a5aebc10e5945020b8db6b76e91deb3240 (patch)
tree86976a73432ec21b3cf61ffda9ef0ae39d7bf7c1 /engines/hdb
parent4b65e396c801e1a08c89de79ebfeaf2f20ada0a0 (diff)
downloadscummvm-rg350-20a270a5aebc10e5945020b8db6b76e91deb3240.tar.gz
scummvm-rg350-20a270a5aebc10e5945020b8db6b76e91deb3240.tar.bz2
scummvm-rg350-20a270a5aebc10e5945020b8db6b76e91deb3240.zip
HDB: Fix waypoints calculation code
Now player does not go back and forth
Diffstat (limited to 'engines/hdb')
-rw-r--r--engines/hdb/ai-waypoint.cpp148
1 files changed, 16 insertions, 132 deletions
diff --git a/engines/hdb/ai-waypoint.cpp b/engines/hdb/ai-waypoint.cpp
index 34704d2e08..312c2cf90e 100644
--- a/engines/hdb/ai-waypoint.cpp
+++ b/engines/hdb/ai-waypoint.cpp
@@ -25,16 +25,20 @@
namespace HDB {
void AI::addWaypoint(int px, int py, int x, int y, int level) {
+ // at the max yet?
if (_numWaypoints >= kMaxWaypoints || (playerOnIce() && _player->goalX))
return;
- // Check for duplicates
+ // first, let's see if this is a duplicate waypoint
int i;
for (i = 0; i < _numWaypoints; i++)
if (_waypoints[i].x == x && _waypoints[i].y == y)
return;
- // Check if path is clear
+ // check to make sure the path is clear...
+ // if it's not, don't add to waypoint list!
+ // The destination x,y might be modified, so
+ // we'll pass in the address to them...
int nx = x;
int ny = y;
if (!_numWaypoints) {
@@ -60,71 +64,13 @@ void AI::addWaypoint(int px, int py, int x, int y, int level) {
lvl1 = lvl2 = level;
if (traceStraightPath(px, py, &tx, &ty, &lvl1)) {
- if (tx != nx || ty != py) {
- tx = px;
- ty = ny;
- tx2 = nx;
- ty2 = ny;
-
- lvl1 = lvl2 = level;
-
- if (traceStraightPath(px, py, &tx, &ty, &lvl1)) {
- if (tx != px || ty != ny)
- return;
-
- traceStraightPath(tx, ty, &nx, &ny, &lvl2);
-
- if (tx2 != nx || ty2 != ny)
- return;
-
- _waypoints[_numWaypoints].x = tx;
- _waypoints[_numWaypoints].y = ty;
- _waypoints[_numWaypoints].level = lvl1;
- _numWaypoints++;
- _waypoints[_numWaypoints].x = nx;
- _waypoints[_numWaypoints].y = ny;
- _waypoints[_numWaypoints].level = lvl2;
- _numWaypoints++;
- g_hdb->_sound->playSound(SND_MENU_SLIDER);
-
- if (onEvenTile(_player->x, _player->y))
- setEntityGoal(_player, tx, ty);
- }
- }
+ if (tx != nx || ty != py)
+ goto newpath;
traceStraightPath(tx, ty, &tx2, &ty2, &lvl2);
- if (tx2 != nx || ty2 != ny) {
- tx = px;
- ty = ny;
- tx2 = nx;
- ty2 = ny;
-
- lvl1 = lvl2 = level;
-
- if (traceStraightPath(px, py, &tx, &ty, &lvl1)) {
- if (tx != px || ty != ny)
- return;
-
- traceStraightPath(tx, ty, &nx, &ny, &lvl2);
-
- if (tx2 != nx || ty2 != ny)
- return;
-
- _waypoints[_numWaypoints].x = tx;
- _waypoints[_numWaypoints].y = ty;
- _waypoints[_numWaypoints].level = lvl1;
- _numWaypoints++;
- _waypoints[_numWaypoints].x = nx;
- _waypoints[_numWaypoints].y = ny;
- _waypoints[_numWaypoints].level = lvl2;
- _numWaypoints++;
- g_hdb->_sound->playSound(SND_MENU_SLIDER);
-
- if (onEvenTile(_player->x, _player->y))
- setEntityGoal(_player, tx, ty);
- }
- }
+ if (tx2 != nx || ty2 != ny)
+ goto newpath;
_waypoints[_numWaypoints].x = tx;
_waypoints[_numWaypoints].y = ty;
@@ -139,6 +85,7 @@ void AI::addWaypoint(int px, int py, int x, int y, int level) {
if (onEvenTile(_player->x, _player->y))
setEntityGoal(_player, tx, ty);
} else {
+newpath:
tx = px;
ty = ny;
tx2 = nx;
@@ -199,77 +146,13 @@ void AI::addWaypoint(int px, int py, int x, int y, int level) {
lvl1 = lvl2 = level;
if (traceStraightPath(px, py, &tx, &ty, &lvl1)) {
- if (tx != nx || ty != py) {
- tx = px;
- ty = ny;
- tx2 = nx;
- ty2 = ny;
-
- lvl1 = lvl2 = level;
-
- if (traceStraightPath(px, py, &tx, &ty, &lvl1)) {
- if (tx != px || ty != ny)
- return;
-
- traceStraightPath(tx, ty, &nx, &ny, &lvl2);
-
- if (tx2 != nx || ty2 != ny)
- return;
-
- if (_numWaypoints < kMaxWaypoints) {
- _waypoints[_numWaypoints].x = tx;
- _waypoints[_numWaypoints].y = ty;
- _waypoints[_numWaypoints].level = lvl1;
- _numWaypoints++;
- g_hdb->_sound->playSound(SND_MENU_SLIDER);
- }
-
- if (_numWaypoints < kMaxWaypoints) {
- _waypoints[_numWaypoints].x = nx;
- _waypoints[_numWaypoints].y = ny;
- _waypoints[_numWaypoints].level = lvl2;
- _numWaypoints++;
- g_hdb->_sound->playSound(SND_MENU_SLIDER);
- }
- }
- }
+ if (tx != nx || ty != py)
+ goto newpath2;
traceStraightPath(tx, ty, &tx2, &ty2, &lvl2);
- if (tx2 != nx || ty2 != ny) {
- tx = px;
- ty = ny;
- tx2 = nx;
- ty2 = ny;
-
- lvl1 = lvl2 = level;
-
- if (traceStraightPath(px, py, &tx, &ty, &lvl1)) {
- if (tx != px || ty != ny)
- return;
-
- traceStraightPath(tx, ty, &nx, &ny, &lvl2);
-
- if (tx2 != nx || ty2 != ny)
- return;
-
- if (_numWaypoints < kMaxWaypoints) {
- _waypoints[_numWaypoints].x = tx;
- _waypoints[_numWaypoints].y = ty;
- _waypoints[_numWaypoints].level = lvl1;
- _numWaypoints++;
- g_hdb->_sound->playSound(SND_MENU_SLIDER);
- }
-
- if (_numWaypoints < kMaxWaypoints) {
- _waypoints[_numWaypoints].x = nx;
- _waypoints[_numWaypoints].y = ny;
- _waypoints[_numWaypoints].level = lvl2;
- _numWaypoints++;
- g_hdb->_sound->playSound(SND_MENU_SLIDER);
- }
- }
- }
+ if (tx2 != nx || ty2 != ny)
+ goto newpath2;
if (_numWaypoints < kMaxWaypoints) {
_waypoints[_numWaypoints].x = tx;
@@ -287,6 +170,7 @@ void AI::addWaypoint(int px, int py, int x, int y, int level) {
g_hdb->_sound->playSound(SND_MENU_SLIDER);
}
} else {
+newpath2:
tx = px;
ty = ny;
tx2 = nx;