char *test_is_plural() { mu_assert(!is_plural("hati-ku"), "hati-ku is not plural"); mu_assert(!is_plural("test2"), "test2 is not plural"); mu_assert(is_plural("hati-hati"), "hati-hati is plural"); return NULL; }
/* * This routine changes the address of obj. Be careful not to call it * when there might be pointers around in unknown places. For now: only * when obj is in the inventory. */ int do_oname(const struct nh_cmd_arg *arg) { const char *qbuf, *buf; const char *aname; short objtyp; struct obj *obj; obj = getargobj(arg, nameable, "name"); if (!obj) return 0; qbuf = msgprintf("What do you want to name %s %s?", is_plural(obj) ? "these" : "this", safe_qbuf("", sizeof("What do you want to name these ?"), xname(obj), simple_typename(obj->otyp), is_plural(obj) ? "things" : "thing")); buf = getarglin(arg, qbuf); if (!*buf || *buf == '\033') return 0; /* strip leading and trailing spaces; unnames item if all spaces */ buf = msgmungspaces(buf); /* relax restrictions over proper capitalization for artifacts */ if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp) buf = aname; char slipbuf[strlen(buf) + 1]; if (obj->oartifact) { pline("The artifact seems to resist the attempt."); return 0; } else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) { int n = rn2((int)strlen(buf)); char c1, c2; strcpy(slipbuf, buf); c1 = lowc(buf[n]); do c2 = 'a' + rn2('z' - 'a' + 1); while (c1 == c2); slipbuf[n] = (slipbuf[n] == c1) ? c2 : highc(c2); /* keep same case */ pline("While engraving your %s slips.", body_part(HAND)); win_pause_output(P_MESSAGE); pline("You engrave: \"%s\".", slipbuf); buf = slipbuf; } oname(obj, buf); return 0; }
/* * This routine changes the address of obj. Be careful not to call it * when there might be pointers around in unknown places. For now: only * when obj is in the inventory. */ static void do_oname(struct obj *obj) { char buf[BUFSZ], qbuf[QBUFSZ]; const char *aname; short objtyp; sprintf(qbuf, "What do you want to name %s %s?", is_plural(obj) ? "these" : "this", xname(obj)); getlin(qbuf, buf); if (!*buf || *buf == '\033') return; /* strip leading and trailing spaces; unnames item if all spaces */ mungspaces(buf); /* relax restrictions over proper capitalization for artifacts */ if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp) strcpy(buf, aname); if (obj->oartifact) { pline("The artifact seems to resist the attempt."); return; } else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) { int n = rn2((int)strlen(buf)); char c1, c2; c1 = lowc(buf[n]); do c2 = 'a' + rn2('z'-'a'); while (c1 == c2); buf[n] = (buf[n] == c1) ? c2 : highc(c2); /* keep same case */ pline("While engraving your %s slips.", body_part(HAND)); win_pause_output(P_MESSAGE); pline("You engrave: \"%s\".",buf); } oname(obj, buf); }
int can_twoweapon(void) { struct obj *otmp; #define NOT_WEAPON(obj) (!is_weptool(obj) && obj->oclass != WEAPON_CLASS) if (!could_twoweap(youmonst.data)) { if (Upolyd) pline("You can't use two weapons in your current form."); else pline("%s aren't able to use two weapons at once.", makeplural((flags.female && urole.name.f) ? urole.name.f : urole.name.m)); } else if (!uwep || !uswapwep) pline("Your %s%s%s empty.", uwep ? "left " : uswapwep ? "right " : "", body_part(HAND), (!uwep && !uswapwep) ? "s are" : " is"); else if (NOT_WEAPON(uwep) || NOT_WEAPON(uswapwep)) { otmp = NOT_WEAPON(uwep) ? uwep : uswapwep; pline("%s %s.", Yname2(otmp), is_plural(otmp) ? "aren't weapons" : "isn't a weapon"); } else if (bimanual(uwep) || bimanual(uswapwep)) { otmp = bimanual(uwep) ? uwep : uswapwep; pline("%s isn't one-handed.", Yname2(otmp)); } else if (uarms) pline("You can't use two weapons while wearing a shield."); else if (uswapwep->oartifact) pline("%s %s being held second to another weapon!", Yname2(uswapwep), otense(uswapwep, "resist")); else if (!uarmg && !Stone_resistance && (uswapwep->otyp == CORPSE && touch_petrifies(&mons[uswapwep->corpsenm]))) { char kbuf[BUFSZ]; pline("You wield the %s corpse with your bare %s.", mons[uswapwep->corpsenm].mname, body_part(HAND)); sprintf(kbuf, "%s corpse", an(mons[uswapwep->corpsenm].mname)); instapetrify(kbuf); } else if (Glib || uswapwep->cursed) { if (!Glib) uswapwep->bknown = TRUE; drop_uswapwep(); } else return TRUE; return FALSE; }
/* 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; }
/* 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; }
int dowieldquiver(struct obj *newquiver) { const char *quivee_types = (uslinging() || (uswapwep && objects[uswapwep->otyp].oc_skill == P_SLING)) ? bullets : ready_objs; /* Since the quiver isn't in your hands, don't check cantwield(), */ /* will_weld(), touch_petrifies(), etc. */ multi = 0; if (newquiver && !validate_object(newquiver, quivee_types, "ready")) return 0; else if (!newquiver) /* Prompt for a new quiver */ newquiver = getobj(quivee_types, "ready"); if (!newquiver) /* Cancelled */ return 0; /* Handle no object, or object in other slot */ /* Any type is okay, since we give no intrinsics anyways */ if (newquiver == &zeroobj) { /* Explicitly nothing */ if (uquiver) { pline("You now have no ammunition readied."); setuqwep(newquiver = NULL); } else { pline("You already have no ammunition readied!"); return 0; } } else if (newquiver == uquiver) { pline("That ammunition is already readied!"); return 0; } else if (newquiver == uwep) { /* Prevent accidentally readying the main weapon */ pline("%s already being used as a weapon!", !is_plural(uwep) ? "That is" : "They are"); return 0; } else if (newquiver->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL | W_SADDLE)) { pline("You cannot ready that!"); return 0; } else { long dummy; /* Check if it's the secondary weapon */ if (newquiver == uswapwep) { setuswapwep(NULL); untwoweapon(); } /* Okay to put in quiver; print it */ dummy = newquiver->owornmask; newquiver->owornmask |= W_QUIVER; prinv(NULL, newquiver, 0L); newquiver->owornmask = dummy; } /* Finally, place it in the quiver */ setuqwep(newquiver); /* Take no time since this is a convenience slot */ return 0; }