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

Function throw_obj

src/dothrow.c:86–293  ·  view source on GitHub ↗

Throw the selected object, asking for direction */

Source from the content-addressed store, hash-verified

84
85/* Throw the selected object, asking for direction */
86staticfn int
87throw_obj(struct obj *obj, int shotlimit)
88{
89 struct obj *otmp, *oldslot;
90 int multishot;
91 schar skill;
92 long wep_mask;
93 boolean twoweap, weakmultishot;
94 int res = ECMD_TIME;
95 struct obj_split save_osplit = svc.context.objsplit;
96
97 /* ask "in what direction?" */
98 if (!getdir((char *) 0)) {
99 /* No direction specified, so cancel the throw */
100 res = ECMD_CANCEL; /* no time passes */
101 goto unsplit_stack;
102 }
103
104 /*
105 * Throwing gold is usually for getting rid of it when
106 * a leprechaun approaches, or for bribing an oncoming
107 * angry monster. So throw the whole object.
108 *
109 * If the gold is in quiver, throw one coin at a time,
110 * possibly using a sling.
111 */
112 if (obj->oclass == COIN_CLASS && obj != uquiver) {
113 /* throw_gold will unsplit the stack itself if necessary and may have
114 freed the object, so don't route through unsplit_stack here */
115 return throw_gold(obj); /* check */
116 }
117
118 if (!canletgo(obj, "throw")) {
119 res = ECMD_OK;
120 goto unsplit_stack;
121 }
122 if (is_art(obj, ART_MJOLLNIR) && obj != uwep) {
123 pline("%s must be wielded before it can be thrown.", The(xname(obj)));
124 res = ECMD_OK;
125 goto unsplit_stack;
126 }
127 if ((is_art(obj, ART_MJOLLNIR) && ACURR(A_STR) < STR19(25))
128 || (obj->otyp == BOULDER && !throws_rocks(gy.youmonst.data))) {
129 pline("It's too heavy.");
130 res = ECMD_TIME;
131 goto unsplit_stack;
132 }
133 if (!u.dx && !u.dy && !u.dz) {
134 You("cannot throw an object at yourself.");
135 res = ECMD_OK;
136 goto unsplit_stack;
137 }
138 u_wipe_engr(2);
139 if (!uarmg && obj->otyp == CORPSE && touch_petrifies(&mons[obj->corpsenm])
140 && !Stone_resistance) {
141 You("throw %s with your bare %s.",
142 corpse_xname(obj, (const char *) 0, CXN_PFX_THE),
143 /* throwing with one hand, but pluralize since the

Callers 2

dothrowFunction · 0.85
dofireFunction · 0.85

Calls 15

getdirFunction · 0.85
throw_goldFunction · 0.85
canletgoFunction · 0.85
is_artFunction · 0.85
TheFunction · 0.85
xnameFunction · 0.85
YouFunction · 0.85
u_wipe_engrFunction · 0.85
corpse_xnameFunction · 0.85
makepluralFunction · 0.85
body_partFunction · 0.85
killer_xnameFunction · 0.85

Tested by

no test coverage detected