]> granicus.if.org Git - nethack/commitdiff
Add getpos_coord option
authorPasi Kallinen <paxed@alt.org>
Mon, 11 Jan 2016 19:07:33 +0000 (21:07 +0200)
committerPasi Kallinen <paxed@alt.org>
Mon, 11 Jan 2016 19:10:51 +0000 (21:10 +0200)
Allows showing the coordinate when picking a position on the
map with '/' and autodescribe is on.

This is another blind player request

doc/Guidebook.mn
doc/Guidebook.tex
include/flag.h
src/do_name.c
src/options.c

index 2d73781f5f856f3b4e626f5324355ac5eb5b24fa..44dc33b2953d361e2f94a7633077164a93be986e 100644 (file)
@@ -2125,6 +2125,11 @@ The default is to randomly pick an appropriate gender.
 If you prefix a `!' or ``no'' to the value, you can 
 exclude that gender from being picked randomly.
 Cannot be set with the `O' command.  Persistent.
+.lp getpos_coord
+When using the `/' command to look around on the map with
+``autodescribe'' on, display coordinates after the description.
+The value specified should be the first letter of one of the following:
+absolute, cartesian, or none.  Default is none.
 .lp "help    "
 If more information is available for an object looked at
 with the `/' command, ask if you want to see it (default on). Turning help
index 53716a2a906af439a0b13e431854af2dc23a3cc7..88a9d8eb6c5899ea2fac0e72ebad982592fc0b5a 100644 (file)
@@ -2559,6 +2559,12 @@ If you prefix `{\tt !}' or ``{\tt no}'' to the value, you can
 exclude that gender from being picked randomly. 
 Cannot be set with the `{\tt O}' command.  Persistent.
 %.lp
+\item[\ib{getpos\verb+_+coord}]
+When using the `{\tt /}' command to look around on the map with
+``{\tt autodescribe}'' on, display coordinates after the description.
+The value specified should be the first letter of one of the following:
+absolute, cartesian, or none.  Default is none.
+%.lp
 \item[\ib{help}]
 If more information is available for an object looked at
 with the `{\tt /}' command, ask if you want to see it (default on).
index 79da89f925e5a546ec93f52797af06eb0ab98c93..298825660a1ec3f38988baeb4b5a38a33c073356 100644 (file)
@@ -167,6 +167,11 @@ struct sysflag {
  *
  */
 
+/* values for iflags.getpos_coords */
+#define GPCOORDS_NONE      'n'
+#define GPCOORDS_ABSOLUTE  'a'
+#define GPCOORDS_CARTESIAN 'c'
+
 struct instance_flags {
     /* stuff that really isn't option or platform related. They are
      * set and cleared during the game to control the internal
@@ -185,6 +190,7 @@ struct instance_flags {
     boolean mon_polycontrol; /* debug: control monster polymorphs */
     /* stuff that is related to options and/or user or platform preferences */
     unsigned msg_history; /* hint: # of top lines to save */
+    int getpos_coords;    /* show coordinates when getting cursor position */
     int menu_headings;    /* ATR for menu headings */
     int *opt_booldup;     /* for duplication of boolean opts in config file */
     int *opt_compdup; /* for duplication of compound opts in config file */
index 80d2093fd6069c32ac03c3999c3a13baa46f219c..3c86589c28321d10e7fab5b1e2ac3c6a5ac68b19 100644 (file)
@@ -149,6 +149,34 @@ boolean do_mons;
     } /* pass */
 }
 
+char *
+dxdy_to_dist_descr(dx,dy)
+int dx,dy;
+{
+    static char buf[QBUFSZ];
+    int d;
+    if (!dx && !dy)
+        Sprintf(buf, "here");
+    else if ((d = xytod(dx,dy)) != -1)
+        Sprintf(buf, "%s", directionname(d));
+    else {
+        char tmp[QBUFSZ];
+        buf[0] = '\0';
+        if (dy) {
+            Sprintf(tmp, "%i%c", abs(dy), (dy > 0) ? 's' : 'n');
+            Strcat(buf, tmp);
+        }
+        if (dy && dx)
+            Strcat(buf, ",");
+        if (dx) {
+            Sprintf(tmp, "%i%c", abs(dx), (dx > 0) ? 'e' : 'w');
+            Strcat(buf, tmp);
+        }
+    }
+    return buf;
+}
+
+
 int
 getpos(ccp, force, goal)
 coord *ccp;
@@ -192,12 +220,27 @@ const char *goal;
             coord cc;
             int sym = 0;
             char tmpbuf[BUFSZ];
+            char outbuf[BUFSZ];
             const char *firstmatch = NULL;
+            int dx,dy;
 
             cc.x = cx;
             cc.y = cy;
             if (do_screen_description(cc, TRUE, sym, tmpbuf, &firstmatch)) {
-                pline1(firstmatch);
+                outbuf[0] = '\0';
+                switch (iflags.getpos_coords) {
+                default:
+                    break;
+                case GPCOORDS_CARTESIAN:
+                    dx = cc.x - u.ux;
+                    dy = cc.y - u.uy;
+                    Sprintf(outbuf, " (%s)", dxdy_to_dist_descr(dx,dy));
+                    break;
+                case GPCOORDS_ABSOLUTE:
+                    Sprintf(outbuf, " (%d,%d)", cc.x,cc.y);
+                    break;
+                }
+                pline("%s%s", firstmatch, outbuf);
                 curs(WIN_MAP, cx, cy);
                 flush_screen(0);
             }
index 8c47c6ae4753b873fad8c081283df86b2554aa4e..6ba023a3c69985a8e42be9c88b76012e372edc4d 100644 (file)
@@ -294,6 +294,7 @@ static struct Comp_Opt {
       DISP_IN_GAME }, /*WC*/
     { "fruit", "the name of a fruit you enjoy eating", PL_FSIZ, SET_IN_GAME },
     { "gender", "your starting gender (male or female)", 8, DISP_IN_GAME },
+    { "getpos_coord", "show coordinates when getting cursor position", 1, SET_IN_GAME },
     { "horsename", "the name of your (first) horse (e.g., horsename:Silver)",
       PL_PSIZ, DISP_IN_GAME },
     { "map_mode", "map display mode under Windows", 20, DISP_IN_GAME }, /*WC*/
@@ -685,6 +686,7 @@ initoptions_init()
     iflags.prevmsg_window = 's';
 #endif
     iflags.menu_headings = ATR_INVERSE;
+    iflags.getpos_coords = GPCOORDS_NONE;
 
     /* hero's role, race, &c haven't been chosen yet */
     flags.initrole = flags.initrace = flags.initgend = flags.initalign =
@@ -2332,6 +2334,24 @@ boolean tinitial, tfrom_file;
         return;
     }
 
+    fullname = "getpos_coord";
+    if (match_optname(opts, fullname, 6, TRUE)) {
+        if (duplicate)
+            complain_about_duplicate(opts, 1);
+        if (negated) {
+            iflags.getpos_coords = GPCOORDS_NONE;
+            return;
+        } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
+            if (tolower(*op) == GPCOORDS_NONE
+                || tolower(*op) == GPCOORDS_CARTESIAN
+                || tolower(*op) == GPCOORDS_ABSOLUTE) {
+                iflags.getpos_coords = tolower(*op);
+            } else
+                badoption(opts);
+        }
+        return;
+    }
+
     fullname = "warnings";
     if (match_optname(opts, fullname, 5, TRUE)) {
         if (duplicate)
@@ -4008,6 +4028,27 @@ boolean setinitial, setfromfile;
             free((genericptr_t) mode_pick);
         }
         destroy_nhwindow(tmpwin);
+    } else if (!strcmp("getpos_coord", optname)) {
+        menu_item *window_pick = (menu_item *) 0;
+
+        tmpwin = create_nhwindow(NHW_MENU);
+        start_menu(tmpwin);
+        any = zeroany;
+        any.a_char = GPCOORDS_ABSOLUTE;
+        add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_ABSOLUTE,
+                 0, ATR_NONE, "absolute", MENU_UNSELECTED);
+        any.a_char = GPCOORDS_CARTESIAN;
+        add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_CARTESIAN,
+                 0, ATR_NONE, "cartesian", MENU_UNSELECTED);
+        any.a_char = GPCOORDS_NONE;
+        add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_NONE,
+                 0, ATR_NONE, "none", MENU_UNSELECTED);
+        end_menu(tmpwin, "Select coordinate display when picking a position:");
+        if (select_menu(tmpwin, PICK_ONE, &window_pick) > 0) {
+            iflags.getpos_coords = window_pick->item.a_char;
+            free((genericptr_t) window_pick);
+        }
+        destroy_nhwindow(tmpwin);
     } else if (!strcmp("msg_window", optname)) {
 #ifdef TTY_GRAPHICS
         /* by Christian W. Cooper */
@@ -4755,6 +4796,11 @@ char *buf;
         Sprintf(buf, "%s", rolestring(flags.initrole, roles, name.m));
     } else if (!strcmp(optname, "runmode")) {
         Sprintf(buf, "%s", runmodes[flags.runmode]);
+    } else if (!strcmp(optname, "getpos_coord")) {
+        Sprintf(buf, "%s",
+                (iflags.getpos_coords == GPCOORDS_ABSOLUTE) ? "absolute"
+                : (iflags.getpos_coords == GPCOORDS_CARTESIAN) ? "cartesian"
+                : "none");
     } else if (!strcmp(optname, "scores")) {
         Sprintf(buf, "%d top/%d around%s", flags.end_top, flags.end_around,
                 flags.end_own ? "/own" : "");