aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2002-07-15 21:50:51 +0000
committerMax Horn2002-07-15 21:50:51 +0000
commit438bb248e0356f76c9cb800d050ae419ab5625ab (patch)
treeb8f257c7feda362258be5261ddcc9f9c67831393
parent9e5c400c6ebc0a1bc05a2a1de1979282acf51cbb (diff)
downloadscummvm-rg350-438bb248e0356f76c9cb800d050ae419ab5625ab.tar.gz
scummvm-rg350-438bb248e0356f76c9cb800d050ae419ab5625ab.tar.bz2
scummvm-rg350-438bb248e0356f76c9cb800d050ae419ab5625ab.zip
simplified the path finding code for 'old' games (this included getting rid of some global vars etc.)
svn-id: r4557
-rw-r--r--actor.cpp350
-rw-r--r--boxes.cpp220
-rw-r--r--scumm.h11
3 files changed, 250 insertions, 331 deletions
diff --git a/actor.cpp b/actor.cpp
index d323db6f82..b3d66a8a06 100644
--- a/actor.cpp
+++ b/actor.cpp
@@ -791,152 +791,6 @@ void Scumm::playActorSounds()
}
-void Actor::startWalkAnim(int cmd, int angle)
-{
- if (angle == -1)
- angle = facing;
-
-/*FIXME: (yazoo): the walk script are buggy in dig causing
- * troubles while walking. It's disabled until I can
- * find a proper fix
- * note: walk scripts aren't required to make the game
- * work as usual */
-
-/* int16 args[16];
-
- if (walk_script != 0) {
- args[2] = angle;
- args[0] = number;
- args[1] = cmd;
- _vm->runScript(walk_script, 1, 0, args);
- } else*/ {
- switch (cmd) {
- case 1: /* start walk */
- setActorDirection(angle);
- startAnimActor(walkFrame);
- break;
- case 2: /* change dir only */
- setActorDirection(angle);
- break;
- case 3: /* stop walk */
- turnToDirection(angle);
- startAnimActor(standFrame);
- break;
- }
- }
-}
-
-void Actor::walkActor()
-{
- int j;
-
- if (!moving)
- return;
-
- if (!(moving & MF_NEW_LEG)) {
- if (moving & MF_IN_LEG && actorWalkStep())
- return;
-
- if (moving & MF_LAST_LEG) {
- moving = 0;
- setActorBox(walkdata.destbox);
- startWalkAnim(3, walkdata.destdir);
- return;
- }
-
- if (moving & MF_TURN) {
- j = updateActorDirection();
- if (facing != j)
- setActorDirection(j);
- else
- moving = 0;
- return;
- }
-
- setActorBox(walkdata.curbox);
- moving &= MF_IN_LEG;
- }
-#if OLD
- moving &= ~MF_NEW_LEG;
-
- if (!walkbox) {
- walkbox = walkdata.destbox;
- walkdata.curbox = walkdata.destbox;
- moving |= MF_LAST_LEG;
- calcMovementFactor(walkdata.destx, walkdata.desty);
- return;
- }
-
- if (ignoreBoxes || walkbox == walkdata.destbox) {
- walkdata.curbox = walkbox;
- moving |= MF_LAST_LEG;
- calcMovementFactor(walkdata.destx, walkdata.desty);
- return;
- }
- j = getPathToDestBox(walkbox, walkdata.destbox);
- if (j == -1) {
- error("walkActor: no path found between %d and %d", walkbox, walkdata.destbox);
- }
-
- walkdata.curbox = j;
-
- if (_vm->findPathTowards(this, walkbox, j, walkdata.destbox)) {
- moving |= MF_LAST_LEG;
- calcMovementFactor(walkdata.destx, walkdata.desty);
- return;
- }
- calcMovementFactor(_foundPathX, _foundPathY);
-#endif
-#if 1
- do {
- moving &= ~MF_NEW_LEG;
- if ((!walkbox && (!(_vm->_features & GF_SMALL_HEADER)))) {
- setActorBox(walkdata.destbox);
- walkdata.curbox = walkdata.destbox;
- break;
- }
- if (walkbox == walkdata.destbox)
- break;
- j = _vm->getPathToDestBox(walkbox, walkdata.destbox);
- if (j == -1 || j > 0xF0) {
- walkdata.destbox = walkbox;
- moving |= MF_LAST_LEG;
- return;
- }
- walkdata.curbox = j;
- if (_vm->_features & GF_OLD256) {
- _vm->findPathTowardsOld(this, walkbox, j, walkdata.destbox);
- if (_vm->gateLoc[2].x == 32000 && _vm->gateLoc[3].x == 32000) {
- moving |= MF_LAST_LEG;
- calcMovementFactor(walkdata.destx, walkdata.desty);
- return;
- }
-
- if (_vm->gateLoc[2].x != 32000) {
- if (calcMovementFactor(_vm->gateLoc[2].x, _vm->gateLoc[2].y)) {
- walkdata.destx = _vm->gateLoc[3].x;
- walkdata.desty = _vm->gateLoc[3].y;
- return;
- }
- }
-
- if (calcMovementFactor(_vm->gateLoc[3].x, _vm->gateLoc[3].y))
- return;
-
- } else {
- if (_vm->findPathTowards(this, walkbox, j, walkdata.destbox))
- break;
- if (calcMovementFactor(_vm->_foundPathX, _vm->_foundPathY))
- return;
- }
-
- setActorBox(walkdata.curbox);
- } while (1);
- moving |= MF_LAST_LEG;
- calcMovementFactor(walkdata.destx, walkdata.desty);
-#endif
-}
-
#define DRAW_ORDER(x) ((x)->y - ((x)->layer << 11))
void Scumm::processActors()
@@ -1255,71 +1109,104 @@ void Actor::startWalkActor(int destX, int destY, int dir)
walkdata.curbox = walkbox;
}
-byte *Actor::getActorName()
+void Actor::startWalkAnim(int cmd, int angle)
{
- byte *ptr = _vm->getResourceAddress(rtActorName, number);
- if (ptr == NULL)
- return (byte *)" ";
- return ptr;
-}
+ if (angle == -1)
+ angle = facing;
-void Actor::remapActor(int r_fact, int g_fact, int b_fact, int threshold)
-{
- byte *akos, *rgbs, *akpl;
- int akpl_size, i;
- int r, g, b;
- byte akpl_color;
+/*FIXME: (yazoo): the walk script are buggy in dig causing
+ * troubles while walking. It's disabled until I can
+ * find a proper fix
+ * note: walk scripts aren't required to make the game
+ * work as usual */
- if (!isInCurrentRoom()) {
- warning("Remap actor %d not in current room", number);
- return;
- }
+/* int16 args[16];
- if (costume < 1 || costume >= _vm->_numCostumes - 1) {
- warning("Remap actor %d invalid costume", number, costume);
- return;
+ if (walk_script != 0) {
+ args[2] = angle;
+ args[0] = number;
+ args[1] = cmd;
+ _vm->runScript(walk_script, 1, 0, args);
+ } else*/ {
+ switch (cmd) {
+ case 1: /* start walk */
+ setActorDirection(angle);
+ startAnimActor(walkFrame);
+ break;
+ case 2: /* change dir only */
+ setActorDirection(angle);
+ break;
+ case 3: /* stop walk */
+ turnToDirection(angle);
+ startAnimActor(standFrame);
+ break;
+ }
}
+}
- akos = _vm->getResourceAddress(rtCostume, costume);
- akpl = findResource(MKID('AKPL'), akos);
+void Actor::walkActor()
+{
+ int j;
- //get num palette entries
- akpl_size = RES_SIZE(akpl) - 8;
+ if (!moving)
+ return;
- //skip resource header
- akpl = RES_DATA(akpl);
+ if (!(moving & MF_NEW_LEG)) {
+ if (moving & MF_IN_LEG && actorWalkStep())
+ return;
- rgbs = findResource(MKID('RGBS'), akos);
+ if (moving & MF_LAST_LEG) {
+ moving = 0;
+ setActorBox(walkdata.destbox);
+ startWalkAnim(3, walkdata.destdir);
+ return;
+ }
- if (!rgbs) {
- warning("Can't remap actor %d costume %d doesn't contain an RGB block", number, costume);
- return;
+ if (moving & MF_TURN) {
+ j = updateActorDirection();
+ if (facing != j)
+ setActorDirection(j);
+ else
+ moving = 0;
+ return;
+ }
+
+ setActorBox(walkdata.curbox);
+ moving &= MF_IN_LEG;
}
- // skip resource header
- rgbs = RES_DATA(rgbs);
- for (i = 0; i < akpl_size; i++) {
- r = *rgbs++;
- g = *rgbs++;
- b = *rgbs++;
+ do {
+ moving &= ~MF_NEW_LEG;
+ if ((!walkbox && (!(_vm->_features & GF_SMALL_HEADER)))) {
+ setActorBox(walkdata.destbox);
+ walkdata.curbox = walkdata.destbox;
+ break;
+ }
+ if (walkbox == walkdata.destbox)
+ break;
+ j = _vm->getPathToDestBox(walkbox, walkdata.destbox);
+ if (j == -1 || j > 0xF0) {
+ walkdata.destbox = walkbox;
+ moving |= MF_LAST_LEG;
+ return;
+ }
+ walkdata.curbox = j;
- akpl_color = *akpl++;
+ if (_vm->findPathTowards(this, walkbox, j, walkdata.destbox))
+ break;
+ if (calcMovementFactor(_vm->_foundPathX, _vm->_foundPathY))
+ return;
- // allow remap of generic palette entry?
- if (!shadow_mode || akpl_color >= 16) {
- if (r_fact != 256)
- r = (r * r_fact) >> 8;
- if (g_fact != 256)
- g = (g * g_fact) >> 8;
- if (b_fact != 256)
- b = (b * b_fact) >> 8;
- palette[i] = _vm->remapPaletteColor(r, g, b, threshold);
- }
- }
+ setActorBox(walkdata.curbox);
+ } while (1);
+
+ moving |= MF_LAST_LEG;
+ calcMovementFactor(walkdata.destx, walkdata.desty);
}
void Actor::walkActorOld()
{
+ ScummPoint gateLoc[5]; // Gate locations
int new_dir, next_box;
if (!moving)
@@ -1352,22 +1239,22 @@ void Actor::walkActorOld()
walkdata.curbox = next_box;
- _vm->findPathTowardsOld(this, walkbox, next_box, walkdata.destbox);
- if (_vm->gateLoc[2].x == 32000 && _vm->gateLoc[3].x == 32000) {
+ _vm->findPathTowardsOld(this, walkbox, next_box, walkdata.destbox, gateLoc);
+ if (gateLoc[2].x == 32000 && gateLoc[3].x == 32000) {
moving |= MF_LAST_LEG;
calcMovementFactor(walkdata.destx, walkdata.desty);
return;
}
- if (_vm->gateLoc[2].x != 32000) {
- if (calcMovementFactor(_vm->gateLoc[2].x, _vm->gateLoc[2].y)) {
- walkdata.point3x = _vm->gateLoc[3].x;
- walkdata.point3y = _vm->gateLoc[3].y;
+ if (gateLoc[2].x != 32000) {
+ if (calcMovementFactor(gateLoc[2].x, gateLoc[2].y)) {
+ walkdata.point3x = gateLoc[3].x;
+ walkdata.point3y = gateLoc[3].y;
return;
}
}
- if (calcMovementFactor(_vm->gateLoc[3].x, _vm->gateLoc[3].y))
+ if (calcMovementFactor(gateLoc[3].x, gateLoc[3].y))
return;
walkbox = walkdata.destbox;
@@ -1412,6 +1299,69 @@ void Actor::walkActorOld()
goto restart;
}
+byte *Actor::getActorName()
+{
+ byte *ptr = _vm->getResourceAddress(rtActorName, number);
+ if (ptr == NULL)
+ return (byte *)" ";
+ return ptr;
+}
+
+void Actor::remapActor(int r_fact, int g_fact, int b_fact, int threshold)
+{
+ byte *akos, *rgbs, *akpl;
+ int akpl_size, i;
+ int r, g, b;
+ byte akpl_color;
+
+ if (!isInCurrentRoom()) {
+ warning("Remap actor %d not in current room", number);
+ return;
+ }
+
+ if (costume < 1 || costume >= _vm->_numCostumes - 1) {
+ warning("Remap actor %d invalid costume", number, costume);
+ return;
+ }
+
+ akos = _vm->getResourceAddress(rtCostume, costume);
+ akpl = findResource(MKID('AKPL'), akos);
+
+ //get num palette entries
+ akpl_size = RES_SIZE(akpl) - 8;
+
+ //skip resource header
+ akpl = RES_DATA(akpl);
+
+ rgbs = findResource(MKID('RGBS'), akos);
+
+ if (!rgbs) {
+ warning("Can't remap actor %d costume %d doesn't contain an RGB block", number, costume);
+ return;
+ }
+ // skip resource header
+ rgbs = RES_DATA(rgbs);
+
+ for (i = 0; i < akpl_size; i++) {
+ r = *rgbs++;
+ g = *rgbs++;
+ b = *rgbs++;
+
+ akpl_color = *akpl++;
+
+ // allow remap of generic palette entry?
+ if (!shadow_mode || akpl_color >= 16) {
+ if (r_fact != 256)
+ r = (r * r_fact) >> 8;
+ if (g_fact != 256)
+ g = (g * g_fact) >> 8;
+ if (b_fact != 256)
+ b = (b * b_fact) >> 8;
+ palette[i] = _vm->remapPaletteColor(r, g, b, threshold);
+ }
+ }
+}
+
void Scumm::resetActorBgs()
{
Actor *a;
diff --git a/boxes.cpp b/boxes.cpp
index d37f1995ac..1287e32b4c 100644
--- a/boxes.cpp
+++ b/boxes.cpp
@@ -118,11 +118,8 @@ bool Scumm::checkXYInBoxBounds(int b, int x, int y)
if (y > box.ul.y && y > box.ur.y && y > box.ll.y && y > box.lr.y)
return 0;
- if (box.ul.x == box.ur.x &&
- box.ul.y == box.ur.y &&
- box.ll.x == box.lr.x &&
- box.ll.y == box.lr.y ||
- box.ul.x == box.lr.x && box.ul.y == box.lr.y && box.ur.x == box.ll.x && box.ur.y == box.ll.y) {
+ if (box.ul.x == box.ur.x && box.ul.y == box.ur.y && box.ll.x == box.lr.x && box.ll.y == box.lr.y ||
+ box.ul.x == box.lr.x && box.ul.y == box.lr.y && box.ur.x == box.ll.x && box.ur.y == box.ll.y) {
ScummPoint pt;
pt = closestPtOnLine(box.ul.x, box.ul.y, box.ll.x, box.ll.y, x, y);
@@ -852,12 +849,13 @@ PathVertex *Scumm::addPathVertex()
return (PathVertex *)addToBoxVertexHeap(sizeof(PathVertex));
}
-int Scumm::findPathTowardsOld(Actor *a, byte trap1, byte trap2, byte final_trap)
+int Scumm::findPathTowardsOld(Actor *actor, byte trap1, byte trap2, byte final_trap, ScummPoint gateLoc[5])
{
- GetGates(trap1, trap2);
ScummPoint pt;
- // FIXME - is parameter "a" ignored on purpose?!?
- Actor *actor = getFirstActor();
+ ScummPoint gateA[2];
+ ScummPoint gateB[2];
+
+ getGates(trap1, trap2, gateA, gateB);
gateLoc[1].x = actor->x;
gateLoc[1].y = actor->y;
@@ -870,22 +868,22 @@ int Scumm::findPathTowardsOld(Actor *a, byte trap1, byte trap2, byte final_trap)
gateLoc[4].y = actor->walkdata.desty;
if (getMaskFromBox(trap1) == getMaskFromBox(trap2) || 1) {
- if (compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate1ax, gate1ay) !=
- compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate1bx, gate1by) &&
- compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate2ax, gate2ay) !=
- compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate2bx, gate2by)) {
+ if (compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateA[0].x, gateA[0].y) !=
+ compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateB[0].x, gateB[0].y) &&
+ compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateA[1].x, gateA[1].y) !=
+ compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateB[1].x, gateB[1].y)) {
return 0; /* same zplane and between both gates? */
}
}
}
- pt = closestPtOnLine(gate2ax, gate2ay, gate2bx, gate2by, gateLoc[1].x, gateLoc[1].y);
+ pt = closestPtOnLine(gateA[1].x, gateA[1].y, gateB[1].x, gateB[1].y, gateLoc[1].x, gateLoc[1].y);
gateLoc[3].x = pt.x;
gateLoc[3].y = pt.y;
- if (compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[3].x, gateLoc[3].y, gate1ax, gate1ay) ==
- compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[3].x, gateLoc[3].y, gate1bx, gate1by)) {
- closestPtOnLine(gate1ax, gate1ay, gate1bx, gate1by, gateLoc[1].x, gateLoc[1].y);
+ if (compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[3].x, gateLoc[3].y, gateA[0].x, gateA[0].y) ==
+ compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[3].x, gateLoc[3].y, gateB[0].x, gateB[0].y)) {
+ closestPtOnLine(gateA[0].x, gateA[0].y, gateB[0].x, gateB[0].y, gateLoc[1].x, gateLoc[1].y);
gateLoc[2].x = pt.x; /* if point 2 between gates, ignore! */
gateLoc[2].y = pt.y;
}
@@ -893,138 +891,114 @@ int Scumm::findPathTowardsOld(Actor *a, byte trap1, byte trap2, byte final_trap)
return 0;
}
-void Scumm::GetGates(int trap1, int trap2)
+void Scumm::getGates(int trap1, int trap2, ScummPoint gateA[2], ScummPoint gateB[2])
{
- int i;
- int Closest1 = 0, Closest2 = 0, Closest3 = 0;
+ int i, j;
int Dist[8];
- int Dist1, Dist2, Dist3;
- int Box1, Box2, Box3;
+ int MinDist[3];
+ int Closest[3];
+ int Box[3];
BoxCoords box;
- int polyx[8];
- int polyy[8];
- AdjustBoxResult pt;
+ ScummPoint Clo[8];
+ ScummPoint poly[8];
+ AdjustBoxResult abr;
+ int line1, line2;
+ // For all corner coordinates of the first box, compute the point cloest
+ // to them on the second box (and also compute the distance of these points).
getBoxCoordinates(trap1, &box);
- polyx[0] = box.ul.x;
- polyy[0] = box.ul.y;
- polyx[1] = box.ur.x;
- polyy[1] = box.ur.y;
- polyx[2] = box.ll.x;
- polyy[2] = box.ll.y;
- polyx[3] = box.lr.x;
- polyy[3] = box.lr.y;
+ poly[0] = box.ul;
+ poly[1] = box.ur;
+ poly[2] = box.ll;
+ poly[3] = box.lr;
for (i = 0; i < 4; i++) {
- pt = getClosestPtOnBox(trap2, polyx[i], polyy[i]);
- Dist[i] = pt.dist;
- CloX[i] = pt.x;
- CloY[i] = pt.y;
+ abr = getClosestPtOnBox(trap2, poly[i].x, poly[i].y);
+ Dist[i] = abr.dist;
+ Clo[i].x = abr.x;
+ Clo[i].y = abr.y;
}
+ // Now do the same but with the roles of the first and second box swapped.
getBoxCoordinates(trap2, &box);
- polyx[4] = box.ul.x;
- polyy[4] = box.ul.y;
- polyx[5] = box.ur.x;
- polyy[5] = box.ur.y;
- polyx[6] = box.ll.x;
- polyy[6] = box.ll.y;
- polyx[7] = box.lr.x;
- polyy[7] = box.lr.y;
+ poly[4] = box.ul;
+ poly[5] = box.ur;
+ poly[6] = box.ll;
+ poly[7] = box.lr;
for (i = 4; i < 8; i++) {
- pt = getClosestPtOnBox(trap1, polyx[i], polyy[i]);
- Dist[i] = pt.dist;
- CloX[i] = pt.x;
- CloY[i] = pt.y;
- }
-
-
- Dist1 = 0xFFFF;
- for (i = 0; i < 8; i++) {
- if (Dist[i] < Dist1) {
- Dist1 = Dist[i];
- Closest1 = i;
- }
+ abr = getClosestPtOnBox(trap1, poly[i].x, poly[i].y);
+ Dist[i] = abr.dist;
+ Clo[i].x = abr.x;
+ Clo[i].y = abr.y;
}
- Dist[Closest1] = 0xFFFF;
- Dist2 = 0xFFFF;
- for (i = 0; i < 8; i++) {
- if (Dist[i] < Dist2) {
- Dist2 = Dist[i];
- Closest2 = i;
- }
- }
- Dist[Closest2] = 0xFFFF;
-
- Dist3 = 0xFFFF;
- for (i = 0; i < 8; i++) {
- if (Dist[i] < Dist3) {
- Dist3 = Dist[i];
- Closest3 = i;
+ // Find the three closest "close" points between the two boxes.
+ for (j = 0; j < 3; j++) {
+ MinDist[j] = 0xFFFF;
+ for (i = 0; i < 8; i++) {
+ if (Dist[i] < MinDist[j]) {
+ MinDist[j] = Dist[i];
+ Closest[j] = i;
+ }
}
+ Dist[Closest[j]] = 0xFFFF;
+ MinDist[j] = (int)sqrt((double)MinDist[j]);
+ Box[j] = (Closest[j] > 3); // Is the poin on the first or on the second box?
}
- Box1 = (Closest1 > 3);
- Box2 = (Closest2 > 3);
- Box3 = (Closest3 > 3);
-
- Dist1 = (int)sqrt((double)Dist1);
- Dist2 = (int)sqrt((double)Dist2);
- Dist3 = (int)sqrt((double)Dist3);
-
- if (Box1 == Box2 && abs(Dist1 - Dist2) < 4) {
- SetGate(Closest1, Closest2, polyx, polyy);
-
- } else if (Box1 == Box2 && Dist1 == Dist2) { /* parallel */
- SetGate(Closest1, Closest2, polyx, polyy);
- } else if (Box1 == Box3 && Dist1 == Dist3) { /* parallel */
- SetGate(Closest1, Closest3, polyx, polyy);
- } else if (Box2 == Box3 && Dist2 == Dist3) { /* parallel */
- SetGate(Closest2, Closest3, polyx, polyy);
-
- } else if (Box1 == Box3 && abs(Dist1 - Dist3) < 4) {
- SetGate(Closest1, Closest3, polyx, polyy);
- } else if (abs(Dist1 - Dist3) < 4) { /* if 1 close to 3 then use 2-3 */
- SetGate(Closest2, Closest3, polyx, polyy);
- } else if (abs(Dist1 - Dist2) < 4) {
- SetGate(Closest1, Closest2, polyx, polyy);
+ // Finally, compute the "gate". That's a pair of two points that are
+ // in the same box (actually, on the border of that box), which both have
+ // "minimal" distance to the other box in a certain sense.
+
+ if (Box[0] == Box[1] && abs(MinDist[0] - MinDist[1]) < 4) {
+ line1 = Closest[0];
+ line2 = Closest[1];
+
+ } else if (Box[0] == Box[1] && MinDist[0] == MinDist[1]) { /* parallel */
+ line1 = Closest[0];
+ line2 = Closest[1];
+ } else if (Box[0] == Box[2] && MinDist[0] == MinDist[2]) { /* parallel */
+ line1 = Closest[0];
+ line2 = Closest[2];
+ } else if (Box[1] == Box[2] && MinDist[1] == MinDist[2]) { /* parallel */
+ line1 = Closest[1];
+ line2 = Closest[2];
+
+ } else if (Box[0] == Box[2] && abs(MinDist[0] - MinDist[2]) < 4) {
+ line1 = Closest[0];
+ line2 = Closest[2];
+ } else if (abs(MinDist[0] - MinDist[2]) < 4) { /* if 1 close to 3 then use 2-3 */
+ line1 = Closest[1];
+ line2 = Closest[2];
+ } else if (abs(MinDist[0] - MinDist[1]) < 4) {
+ line1 = Closest[0];
+ line2 = Closest[1];
} else {
- SetGate(Closest1, Closest1, polyx, polyy);
+ line1 = Closest[0];
+ line2 = Closest[0];
}
-}
-
-bool Scumm::compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3)
-{
- return (Y2 - Y1) * (X3 - X1) <= (Y3 - Y1) * (X2 - X1);
-}
-
-void Scumm::SetGate(int line1, int line2, int polyx[8], int polyy[8])
-{
+ // Set the gate
if (line1 < 4) { /* from box 1 to box 2 */
- gate1ax = polyx[line1];
- gate1ay = polyy[line1];
- gate2ax = CloX[line1];
- gate2ay = CloY[line1];
+ gateA[0] = poly[line1];
+ gateA[1] = Clo[line1];
} else {
- gate2ax = polyx[line1];
- gate2ay = polyy[line1];
- gate1ax = CloX[line1];
- gate1ay = CloY[line1];
+ gateA[1] = poly[line1];
+ gateA[0] = Clo[line1];
}
if (line2 < 4) { /* from box */
- gate1bx = polyx[line2];
- gate1by = polyy[line2];
- gate2bx = CloX[line2];
- gate2by = CloY[line2];
+ gateB[0] = poly[line2];
+ gateB[1] = Clo[line2];
} else {
- gate2bx = polyx[line2];
- gate2by = polyy[line2];
- gate1bx = CloX[line2];
- gate1by = CloY[line2];
+ gateB[1] = poly[line2];
+ gateB[0] = Clo[line2];
}
}
+
+bool Scumm::compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3)
+{
+ return (Y2 - Y1) * (X3 - X1) <= (Y3 - Y1) * (X2 - X1);
+}
diff --git a/scumm.h b/scumm.h
index 9746f81fc5..8b3c53c534 100644
--- a/scumm.h
+++ b/scumm.h
@@ -1163,23 +1163,18 @@ public:
-
/* Walkbox / Navigation class */
int _maxBoxVertexHeap, _boxPathVertexHeapIndex, _boxMatrixItem;
byte *_boxMatrixPtr4, *_boxMatrixPtr1, *_boxMatrixPtr3;
- ScummPoint gateLoc[5]; /* Gate locations */
- int gate1ax, gate1ay, gate1bx, gate1by, gate2ax, gate2ay, gate2bx, gate2by;
uint16 _extraBoxFlags[65];
int16 _foundPathX, _foundPathY;
- int CloX[8], CloY[8];
PathVertex *unkMatrixProc1(PathVertex *vtx, PathNode *node);
PathNode *unkMatrixProc2(PathVertex *vtx, int i);
bool areBoxesNeighbours(int i, int j);
void addToBoxMatrix(byte b);
bool compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3);
- void SetGate(int line1, int line2, int polyx[8], int polyy[8]);
void *addToBoxVertexHeap(int size);
PathVertex *addPathVertex();
bool checkXYInBoxBounds(int box, int x, int y);
@@ -1194,8 +1189,8 @@ public:
byte *getBoxMatrixBaseAddr();
int getPathToDestBox(byte from, byte to);
int findPathTowards(Actor *a, byte box, byte box2, byte box3);
- int findPathTowardsOld(Actor *a, byte box, byte box2, byte box3);
- void GetGates(int trap1, int trap2);
+ int findPathTowardsOld(Actor *a, byte box, byte box2, byte box3, ScummPoint gateLoc[5]);
+ void getGates(int trap1, int trap2, ScummPoint gateA[2], ScummPoint gateB[2]);
bool inBoxQuickReject(int box, int x, int y, int threshold);
AdjustBoxResult getClosestPtOnBox(int box, int x, int y);
int getSpecialBox(int param1, int param2);
@@ -1254,7 +1249,7 @@ public:
uint32 fileReadDword(void *handle) { return fileReadDwordLE(handle); }
#elif defined(SCUMM_BIG_ENDIAN)
uint32 fileReadDword() { return fileReadDwordBE(); }
- uint32 fileReadDword(void *handle) {return fileReadDwordBE(handle);}
+ uint32 fileReadDword(void *handle) { return fileReadDwordBE(handle); }
#endif
uint fileReadWordLE();
uint fileReadWordBE();