MCPcopy Create free account
hub / github.com/NetHack/NetHack / dotravel

Function dotravel

src/cmd.c:5298–5344  ·  view source on GitHub ↗

'_' command, #travel, via keyboard rather than mouse click */

Source from the content-addressed store, hash-verified

5296
5297/* '_' command, #travel, via keyboard rather than mouse click */
5298staticfn int
5299dotravel(void)
5300{
5301 coord cc;
5302
5303 /*
5304 * Traveling used to be a no-op if user toggled 'travel' option
5305 * Off. However, travel was initially implemented as a mouse-only
5306 * command and the original purpose of the option was to be able
5307 * to prevent clicks on the map from initiating travel.
5308 *
5309 * Travel via '_' came later. Since it requires a destination--
5310 * which offers the user a chance to cancel if it was accidental--
5311 * there's no reason for the option to disable travel-by-keys.
5312 */
5313
5314 cc.x = iflags.travelcc.x;
5315 cc.y = iflags.travelcc.y;
5316 if (cc.x == 0 && cc.y == 0) {
5317 /* No cached destination, start attempt from current position */
5318 cc.x = u.ux;
5319 cc.y = u.uy;
5320 }
5321 iflags.getloc_travelmode = TRUE;
5322 if (iflags.menu_requested) {
5323 int gfilt = iflags.getloc_filter;
5324
5325 iflags.getloc_filter = GFILTER_VIEW;
5326 if (!getpos_menu(&cc, GLOC_INTERESTING)) {
5327 iflags.getloc_filter = gfilt;
5328 iflags.getloc_travelmode = FALSE;
5329 return ECMD_OK;
5330 }
5331 iflags.getloc_filter = gfilt;
5332 } else {
5333 pline("Where do you want to travel to?");
5334 if (getpos(&cc, TRUE, "the desired destination") < 0) {
5335 /* user pressed ESC */
5336 iflags.getloc_travelmode = FALSE;
5337 return ECMD_CANCEL;
5338 }
5339 }
5340 iflags.travelcc.x = u.tx = cc.x;
5341 iflags.travelcc.y = u.ty = cc.y;
5342
5343 return dotravel_target();
5344}
5345
5346/* #retravel, travel to iflags.travelcc, which must be set */
5347staticfn int

Callers

nothing calls this directly

Calls 4

getpos_menuFunction · 0.85
getposFunction · 0.85
dotravel_targetFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected