create an object from a horn of plenty; mirrors bagotricks(makemon.c) */
| 2844 | |
| 2845 | /* create an object from a horn of plenty; mirrors bagotricks(makemon.c) */ |
| 2846 | int |
| 2847 | hornoplenty( |
| 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) |
no test coverage detected