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

Function hornoplenty

src/mkobj.c:2846–2936  ·  view source on GitHub ↗

create an object from a horn of plenty; mirrors bagotricks(makemon.c) */

Source from the content-addressed store, hash-verified

2844
2845/* create an object from a horn of plenty; mirrors bagotricks(makemon.c) */
2846int
2847hornoplenty(
2848 struct obj *horn,
2849 boolean tipping, /* caller emptying entire contents; affects shop mesgs */
2850 struct obj *targetbox) /* if non-Null, container to tip into */
2851{
2852 int objcount = 0;
2853
2854 if (!horn || horn->otyp != HORN_OF_PLENTY) {
2855 impossible("bad horn o' plenty");
2856 } else if (horn->spe < 1) {
2857 pline1(nothing_happens);
2858 if (!horn->cknown) {
2859 horn->cknown = 1;
2860 update_inventory();
2861 }
2862 } else {
2863 struct obj *obj;
2864 const char *what;
2865
2866 consume_obj_charge(horn, !tipping);
2867 if (!rn2(13)) {
2868 obj = mkobj(POTION_CLASS, FALSE);
2869 if (objects[obj->otyp].oc_magic) {
2870 do {
2871 obj->otyp = rnd_class(POT_BOOZE, POT_WATER);
2872 } while (obj->otyp == POT_SICKNESS);
2873 /* oil uses obj->age field differently from other potions */
2874 if (obj->otyp == POT_OIL)
2875 fixup_oil(obj, (struct obj *) NULL);
2876 }
2877 what = (obj->quan > 1L) ? "Some potions" : "A potion";
2878 } else {
2879 obj = mkobj(FOOD_CLASS, FALSE);
2880 if (obj->otyp == FOOD_RATION && !rn2(7))
2881 obj->otyp = LUMP_OF_ROYAL_JELLY;
2882 what = "Some food";
2883 }
2884 ++objcount;
2885 pline("%s %s out.", what, vtense(what, "spill"));
2886 obj->blessed = horn->blessed;
2887 obj->cursed = horn->cursed;
2888 obj->owt = weight(obj);
2889 /* using a shop's horn of plenty entails a usage fee and also
2890 confers ownership of the created item to the shopkeeper */
2891 if (horn->unpaid)
2892 addtobill(obj, FALSE, FALSE, tipping);
2893 /* if it ended up on bill, we don't want "(unpaid, N zorkmids)"
2894 being included in its formatted name during next message */
2895 iflags.suppress_price++;
2896 if (!tipping) {
2897 obj = hold_another_object(obj,
2898 u.uswallow
2899 ? "Oops! %s out of your reach!"
2900 : (Is_airlevel(&u.uz)
2901 || Is_waterlevel(&u.uz)
2902 || levl[u.ux][u.uy].typ < IRONBARS
2903 || levl[u.ux][u.uy].typ >= ICE)

Callers 2

tipcontainer_checksFunction · 0.85
doapplyFunction · 0.85

Calls 15

update_inventoryFunction · 0.85
consume_obj_chargeFunction · 0.85
rn2Function · 0.85
mkobjFunction · 0.85
rnd_classFunction · 0.85
fixup_oilFunction · 0.85
vtenseFunction · 0.85
weightFunction · 0.85
addtobillFunction · 0.85
hold_another_objectFunction · 0.85
TheFunction · 0.85
aobjnamFunction · 0.85

Tested by

no test coverage detected