static int describe_object(int x, int y, int votyp, char *buf) { int num_objs = 0; struct obj *otmp; if (votyp == -1) return -1; otmp = vobj_at(x,y); if (!otmp || otmp->otyp != votyp) { if (votyp != STRANGE_OBJECT) { otmp = mksobj(level, votyp, FALSE, FALSE); if (otmp->oclass == COIN_CLASS) otmp->quan = 1L; /* to force pluralization off */ else if (otmp->otyp == SLIME_MOLD) otmp->spe = current_fruit; /* give the fruit a type */ strcpy(buf, distant_name(otmp, xname)); dealloc_obj(otmp); otmp = vobj_at(x,y); /* make sure we don't point to the temp obj any more */ } } else strcpy(buf, distant_name(otmp, xname)); if (level->locations[x][y].typ == STONE || level->locations[x][y].typ == SCORR) strcat(buf, " embedded in stone"); else if (IS_WALL(level->locations[x][y].typ) || level->locations[x][y].typ == SDOOR) strcat(buf, " embedded in a wall"); else if (closed_door(level, x,y)) strcat(buf, " embedded in a door"); else if (is_pool(level, x,y)) strcat(buf, " in water"); else if (is_lava(level, x,y)) strcat(buf, " in molten lava"); /* [can this ever happen?] */ if (!cansee(x, y)) return -1; /* don't disclose the number of objects for location out of LOS */ if (!otmp) /* There is no object here. Since the player sees one it must be a mimic */ return 1; if (otmp->otyp != votyp) /* Hero sees something other than the actual top object. Probably a mimic */ num_objs++; for ( ; otmp; otmp = otmp->nexthere) num_objs++; return num_objs; }
/* quick: use cursor && don't search for "more info" */ static int do_look(boolean quick, const struct nh_cmd_arg *arg) { const char *out_str; const char *firstmatch; int i, ans = 0, objplur = 0, is_in; coord cc; /* screen pos of unknown glyph */ boolean save_verbose; /* saved value of flags.verbose */ boolean from_screen; /* question from the screen */ struct nh_desc_buf descbuf; struct obj *otmp; if (arg->argtype & CMD_ARG_OBJ) { from_screen = FALSE; } else if (quick || (arg->argtype & CMD_ARG_POS)) { from_screen = TRUE; /* yes, we want to use the cursor */ } else { i = ynq("Specify unknown object by cursor?"); if (i == 'q') return 0; from_screen = (i == 'y'); } if (from_screen) { cc.x = u.ux; cc.y = u.uy; } else { if (arg->argtype & CMD_ARG_OBJ) { static const char allowall[] = { ALL_CLASSES, 0 }; out_str = simple_typename(getargobj(arg, allowall, "explain")->otyp); } else { out_str = getarglin(arg, "Specify what? (type the word)"); if (out_str[0] == '\0' || out_str[0] == '\033') return 0; } /* the ability to specify symbols is gone: it is simply impossible to know how the window port is displaying things (tiles?) and even if charaters are used it may not be possible to type them (utf8) */ checkfile(out_str, NULL, !(arg->argtype & CMD_ARG_OBJ), TRUE); return 0; } /* Save the verbose flag, we change it later. */ save_verbose = flags.verbose; flags.verbose = flags.verbose && !quick; /* * we're identifying from the screen. */ do { /* Reset some variables. */ firstmatch = NULL; objplur = 0; if (flags.verbose) pline("Please move the cursor to %s.", what_is_an_unknown_object); else pline("Pick an object."); ans = getargpos(arg, &cc, FALSE, what_is_an_unknown_object); if (ans == NHCR_CLIENT_CANCEL || cc.x < 0) { flags.verbose = save_verbose; if (flags.verbose) pline(quick ? "Never mind." : "Done."); return 0; /* done */ } flags.verbose = FALSE; /* only print long question once */ nh_describe_pos(cc.x, cc.y, &descbuf, &is_in); otmp = vobj_at(cc.x, cc.y); if (otmp && is_plural(otmp)) objplur = 1; out_str = ""; if (append_str(&out_str, descbuf.effectdesc, 0, 0)) if (!firstmatch) firstmatch = descbuf.effectdesc; if (append_str(&out_str, descbuf.invisdesc, 0, 0)) if (!firstmatch) firstmatch = descbuf.invisdesc; /* We already have a/an added by describe_mon; don't add it again, because that'll fail in cases like "Dudley's ghost" */ if (append_str(&out_str, descbuf.mondesc, 1, 0)) if (!firstmatch) firstmatch = descbuf.mondesc; if (append_str(&out_str, descbuf.objdesc, objplur, 0)) if (!firstmatch) firstmatch = descbuf.objdesc; if (append_str(&out_str, descbuf.trapdesc, 0, 0)) if (!firstmatch) firstmatch = descbuf.trapdesc; if (!descbuf.feature_described && append_str(&out_str, descbuf.bgdesc, 0, is_in)) if (!firstmatch) firstmatch = descbuf.bgdesc; /* Finally, print out our explanation. */ if (firstmatch) { pline("%s.", msgupcasefirst(out_str)); /* check the data file for information about this thing */ if (firstmatch && ans != NHCR_CONTINUE && (ans == NHCR_MOREINFO || ans == NHCR_MOREINFO_CONTINUE || !quick)) { checkfile(firstmatch, NULL, FALSE, ans == NHCR_MOREINFO || ans == NHCR_MOREINFO_CONTINUE); } } else { pline("I've never heard of such things."); } } while (ans == NHCR_CONTINUE || ans == NHCR_MOREINFO_CONTINUE); flags.verbose = save_verbose; if (!quick && flags.verbose) pline("Done."); return 0; }
static int describe_object(int x, int y, int votyp, char *buf, int known_embed, boolean *feature_described) { int num_objs = 0; struct obj *otmp; int typ; *feature_described = FALSE; if (votyp == -1) return -1; otmp = vobj_at(x, y); if (!otmp || otmp->otyp != votyp) { /* We have a mimic. */ if (votyp == STRANGE_OBJECT) { strcpy(buf, "strange object"); } else { otmp = mktemp_sobj(level, votyp); otmp->corpsenm = PM_TENGU; /* (basic object only, no random features) */ if (otmp->oclass == COIN_CLASS) otmp->quan = 1L; /* to force pluralization off */ else if (otmp->otyp == SLIME_MOLD) otmp->spe = gamestate.fruits.current;/* give the fruit a type */ strcpy(buf, distant_name(otmp, xname)); dealloc_obj(otmp); otmp = vobj_at(x, y); /* make sure we don't point to the temp obj any more */ } } else strcpy(buf, distant_name(otmp, xname)); typ = level->locations[x][y].typ; if (known_embed && IS_TREE(typ)) strcat(buf, " stuck"); else if (known_embed && (IS_ROCK(typ) || closed_door(level, x, y))) strcat(buf, " embedded"); else if (IS_TREE(typ)) { strcat(buf, " stuck in a tree"); *feature_described = TRUE; } else if (typ == STONE || typ == SCORR) { strcat(buf, " embedded in stone"); *feature_described = TRUE; } else if (IS_WALL(typ) || typ == SDOOR) { strcat(buf, " embedded in a wall"); *feature_described = TRUE; } else if (closed_door(level, x, y)) { strcat(buf, " embedded in a door"); *feature_described = TRUE; } else if (is_pool(level, x, y)) { strcat(buf, " in water"); *feature_described = TRUE; } else if (is_lava(level, x, y)) { strcat(buf, " in molten lava"); /* [can this ever happen?] */ *feature_described = TRUE; } if (!cansee(x, y)) return -1; /* don't disclose the number of objects for location out of LOS */ if (!otmp) /* There is no object here. Since the player sees one it must be a mimic */ return 1; if (otmp->otyp != votyp) /* Hero sees something other than the actual top object. Probably a mimic */ num_objs++; for (; otmp; otmp = otmp->nexthere) num_objs++; return num_objs; }
/* quick: use cursor && don't search for "more info" */ static int do_look(boolean quick) { char out_str[BUFSZ]; char firstmatch[BUFSZ]; int i, ans = 0, objplur = 0; int found; /* count of matching syms found */ coord cc; /* screen pos of unknown glyph */ boolean save_verbose; /* saved value of flags.verbose */ boolean from_screen; /* question from the screen */ struct nh_desc_buf descbuf; struct obj *otmp; if (quick) { from_screen = TRUE; /* yes, we want to use the cursor */ } else { i = ynq("Specify unknown object by cursor?"); if (i == 'q') return 0; from_screen = (i == 'y'); } if (from_screen) { cc.x = u.ux; cc.y = u.uy; } else { getlin("Specify what? (type the word)", out_str); if (out_str[0] == '\0' || out_str[0] == '\033') return 0; /* the ability to specify symbols is gone: it is simply impossible to * know how the window port is displaying things (tiles?) and even if * charaters are used it may not be possible to type them (utf8) */ checkfile(out_str, NULL, TRUE, TRUE); return 0; } /* Save the verbose flag, we change it later. */ save_verbose = flags.verbose; flags.verbose = flags.verbose && !quick; /* * we're identifying from the screen. */ do { /* Reset some variables. */ found = 0; out_str[0] = '\0'; objplur = 0; if (flags.verbose) pline("Please move the cursor to %s.", what_is_an_unknown_object); else pline("Pick an object."); ans = getpos(&cc, FALSE, what_is_an_unknown_object); if (ans < 0 || cc.x < 0) { flags.verbose = save_verbose; return 0; /* done */ } flags.verbose = FALSE; /* only print long question once */ nh_describe_pos(cc.x, cc.y, &descbuf); otmp = vobj_at(cc.x, cc.y); if (otmp && is_plural(otmp)) objplur = 1; out_str[0] = '\0'; if (append_str(out_str, descbuf.effectdesc, 0)) if (++found == 1) strcpy (firstmatch, descbuf.effectdesc); if (append_str(out_str, descbuf.invisdesc, 0)) if (++found == 1) strcpy (firstmatch, descbuf.invisdesc); if (append_str(out_str, descbuf.mondesc, 0)) if (++found == 1) strcpy (firstmatch, descbuf.mondesc); if (append_str(out_str, descbuf.objdesc, objplur)) if (++found == 1) strcpy (firstmatch, descbuf.objdesc); if (append_str(out_str, descbuf.trapdesc, 0)) if (++found == 1) strcpy (firstmatch, descbuf.trapdesc); if (append_str(out_str, descbuf.bgdesc, 0)) if (!found) { found++; /* only increment found if nothing else was seen, so that checkfile can be called below */ strcpy (firstmatch, descbuf.bgdesc); } /* Finally, print out our explanation. */ if (found) { out_str[0] = highc(out_str[0]); pline("%s.", out_str); /* check the data file for information about this thing */ if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE && (ans == LOOK_VERBOSE || !quick)) { checkfile(firstmatch, NULL, FALSE, ans == LOOK_VERBOSE); } } else { pline("I've never heard of such things."); } } while (!quick && ans != LOOK_ONCE); flags.verbose = save_verbose; return 0; }