* Find a path from the destination (u.tx,u.ty) back to (u.ux,u.uy). * A shortest path is returned. If guess is TRUE, consider various * inaccessible locations as valid intermediate path points. * Returns TRUE if a path was found. * gt.travelmap keeps track of map locations we've moved through * this travel session. It will be cleared once the travel stops. */
| 1263 | * this travel session. It will be cleared once the travel stops. |
| 1264 | */ |
| 1265 | staticfn boolean |
| 1266 | findtravelpath(int mode) |
| 1267 | { |
| 1268 | if (!gt.travelmap) |
| 1269 | gt.travelmap = selection_new(); |
| 1270 | /* if travel to adjacent, reachable location, use normal movement rules */ |
| 1271 | if ((mode == TRAVP_TRAVEL || mode == TRAVP_VALID) && svc.context.travel1 |
| 1272 | /* was '&& distmin(u.ux, u.uy, u.tx, u.ty) == 1' */ |
| 1273 | && next2u(u.tx, u.ty) /* one step away */ |
| 1274 | /* handle restricted diagonals */ |
| 1275 | && crawl_destination(u.tx, u.ty)) { |
| 1276 | end_running(FALSE); |
| 1277 | if (test_move(u.ux, u.uy, u.tx - u.ux, u.ty - u.uy, TEST_MOVE)) { |
| 1278 | if (mode == TRAVP_TRAVEL) { |
| 1279 | u.dx = u.tx - u.ux; |
| 1280 | u.dy = u.ty - u.uy; |
| 1281 | nomul(0); |
| 1282 | iflags.travelcc.x = iflags.travelcc.y = 0; |
| 1283 | } |
| 1284 | return TRUE; |
| 1285 | } |
| 1286 | if (mode == TRAVP_TRAVEL) |
| 1287 | svc.context.run = 8; |
| 1288 | } |
| 1289 | if (u.tx != u.ux || u.ty != u.uy) { |
| 1290 | coordxy travel[COLNO][ROWNO]; |
| 1291 | coordxy travelstepx[2][COLNO * ROWNO]; |
| 1292 | coordxy travelstepy[2][COLNO * ROWNO]; |
| 1293 | coordxy tx, ty, ux, uy; |
| 1294 | int n = 1; /* max offset in travelsteps */ |
| 1295 | int set = 0; /* two sets current and previous */ |
| 1296 | int radius = 1; /* search radius */ |
| 1297 | int i; |
| 1298 | |
| 1299 | /* If guessing, first find an "obvious" goal location. The obvious |
| 1300 | * goal is the position the player knows of, or might figure out |
| 1301 | * (couldsee) that is closest to the target on a straight path. |
| 1302 | */ |
| 1303 | if (mode == TRAVP_GUESS || mode == TRAVP_VALID) { |
| 1304 | tx = u.ux; |
| 1305 | ty = u.uy; |
| 1306 | ux = u.tx; |
| 1307 | uy = u.ty; |
| 1308 | } else { |
| 1309 | tx = u.tx; |
| 1310 | ty = u.ty; |
| 1311 | ux = u.ux; |
| 1312 | uy = u.uy; |
| 1313 | } |
| 1314 | |
| 1315 | noguess: |
| 1316 | (void) memset((genericptr_t) travel, 0, sizeof travel); |
| 1317 | travelstepx[0][0] = tx; |
| 1318 | travelstepy[0][0] = ty; |
| 1319 | |
| 1320 | while (n != 0) { |
| 1321 | int nn = 0; |
| 1322 |
no test coverage detected