MCPcopy Index your code
hub / github.com/NetHack/NetHack / findtravelpath

Function findtravelpath

src/hack.c:1265–1523  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1263 * this travel session. It will be cleared once the travel stops.
1264 */
1265staticfn boolean
1266findtravelpath(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

Callers 2

is_valid_travelptFunction · 0.85
domove_coreFunction · 0.85

Calls 15

selection_newFunction · 0.85
crawl_destinationFunction · 0.85
end_runningFunction · 0.85
test_moveFunction · 0.85
nomulFunction · 0.85
isokFunction · 0.85
can_oozeFunction · 0.85
closed_doorFunction · 0.85
sobj_atFunction · 0.85
could_move_onto_boulderFunction · 0.85
selection_getpointFunction · 0.85
YouFunction · 0.85

Tested by

no test coverage detected