From 0753a0751ec03e5209ab5ca4737a9559acfd4076 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 14 Sep 2017 14:11:09 +0300 Subject: [PATCH] Move BoH item loss into separate function --- src/pickup.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/pickup.c b/src/pickup.c index c100d2ce3..1bba6492b 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -29,6 +29,7 @@ STATIC_DCL long FDECL(carry_count, (struct obj *, struct obj *, long, STATIC_DCL int FDECL(lift_object, (struct obj *, struct obj *, long *, BOOLEAN_P)); STATIC_DCL boolean FDECL(mbag_explodes, (struct obj *, int)); +STATIC_DCL long FDECL(boh_loss, (struct obj *container, int)); STATIC_PTR int FDECL(in_container, (struct obj *)); STATIC_PTR int FDECL(out_container, (struct obj *)); STATIC_DCL void FDECL(removed_from_icebox, (struct obj *)); @@ -2018,6 +2019,28 @@ int depthin; return FALSE; } +STATIC_OVL long +boh_loss(container, held) +struct obj *container; +int held; +{ + /* sometimes toss objects if a cursed magic bag */ + if (Is_mbag(container) && container->cursed && Has_contents(container)) { + long loss = 0L; + struct obj *curr, *otmp; + + for (curr = container->cobj; curr; curr = otmp) { + otmp = curr->nobj; + if (!rn2(13)) { + obj_extract_self(curr); + loss += mbag_item_gone(held, curr); + } + } + return loss; + } + return 0; +} + /* Returns: -1 to stop, 1 item was inserted, 0 item was not inserted. */ STATIC_PTR int in_container(obj) @@ -2374,6 +2397,7 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ stash_one, inokay, outokay, outmaybe; char c, emptymsg[BUFSZ], qbuf[QBUFSZ], pbuf[QBUFSZ], xbuf[QBUFSZ]; int used = 0; + long loss; abort_looting = FALSE; emptymsg[0] = '\0'; @@ -2414,22 +2438,10 @@ boolean more_containers; /* True iff #loot multiple and this isn't last one */ observe_quantum_cat(current_container); used = 1; } - /* sometimes toss objects if a cursed magic bag */ - cursed_mbag = (Is_mbag(current_container) && current_container->cursed - && Has_contents(current_container)); - if (cursed_mbag) { - long loss = 0L; - for (curr = current_container->cobj; curr; curr = otmp) { - otmp = curr->nobj; - if (!rn2(13)) { - obj_extract_self(curr); - loss += mbag_item_gone(held, curr); - used = 1; - } - } - if (loss) - You("owe %ld %s for lost merchandise.", loss, currency(loss)); + if ((loss = boh_loss(current_container, held)) != 0) { + used = 1; + You("owe %ld %s for lost merchandise.", loss, currency(loss)); current_container->owt = weight(current_container); } inokay = (invent != 0