split "swallowit" on throwit() into a separate function

This commit is contained in:
SHIRAKATA Kentaro
2025-03-04 21:31:17 +09:00
parent 121e12085b
commit d2af1afb52
+19 -10
View File
@@ -16,6 +16,7 @@ staticfn int gem_accept(struct monst *, struct obj *);
staticfn boolean toss_up(struct obj *, boolean) NONNULLARG1; staticfn boolean toss_up(struct obj *, boolean) NONNULLARG1;
staticfn void sho_obj_return_to_u(struct obj * obj); staticfn void sho_obj_return_to_u(struct obj * obj);
staticfn void throwit_return(boolean); staticfn void throwit_return(boolean);
staticfn void swallowit(struct obj *);
staticfn struct obj *return_throw_to_inv(struct obj *, long, boolean, staticfn struct obj *return_throw_to_inv(struct obj *, long, boolean,
struct obj *); struct obj *);
staticfn void tmiss(struct obj *, struct monst *, boolean); staticfn void tmiss(struct obj *, struct monst *, boolean);
@@ -1456,6 +1457,15 @@ throwit_return(boolean clear_thrownobj)
gt.thrownobj = (struct obj *) 0; gt.thrownobj = (struct obj *) 0;
} }
staticfn void
swallowit(struct obj *obj){
if (obj != uball) {
(void) mpickobj(u.ustuck, obj); /* clears 'gt.thrownobj' */
throwit_return(FALSE);
} else
throwit_return(TRUE);
}
/* throw an object, NB: obj may be consumed in the process */ /* throw an object, NB: obj may be consumed in the process */
void void
throwit(struct obj *obj, throwit(struct obj *obj,
@@ -1664,12 +1674,7 @@ throwit(struct obj *obj,
if (tethered_weapon) if (tethered_weapon)
tmp_at(DISP_END, 0); tmp_at(DISP_END, 0);
} else if (u.uswallow && !iflags.returning_missile) { } else if (u.uswallow && !iflags.returning_missile) {
swallowit: swallowit(obj);
if (obj != uball) {
(void) mpickobj(u.ustuck, obj); /* clears 'gt.thrownobj' */
throwit_return(FALSE);
} else
throwit_return(TRUE);
return; return;
} else { } else {
/* Mjollnir must be wielded to be thrown--caller verifies this; /* Mjollnir must be wielded to be thrown--caller verifies this;
@@ -1715,8 +1720,10 @@ throwit(struct obj *obj,
KILLED_BY); KILLED_BY);
} }
if (u.uswallow) if (u.uswallow) {
goto swallowit; swallowit(obj);
return;
}
if (!ship_object(obj, u.ux, u.uy, FALSE)) if (!ship_object(obj, u.ux, u.uy, FALSE))
dropy(obj); dropy(obj);
} }
@@ -1734,8 +1741,10 @@ throwit(struct obj *obj,
capability back anyway, quivered or not shouldn't matter */ capability back anyway, quivered or not shouldn't matter */
pline("%s to return!", Tobjnam(obj, "fail")); pline("%s to return!", Tobjnam(obj, "fail"));
if (u.uswallow) if (u.uswallow) {
goto swallowit; swallowit(obj);
return;
}
/* continue below with placing 'obj' at target location */ /* continue below with placing 'obj' at target location */
} }
} }