MCPcopy Create free account
hub / github.com/NetHack/NetHack / stolen_value

Function stolen_value

src/shk.c:3753–3872  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3751}
3752
3753long
3754stolen_value(
3755 struct obj *obj,
3756 coordxy x,
3757 coordxy y,
3758 boolean peaceful,
3759 boolean silent)
3760{
3761 long value = 0L, gvalue = 0L, billamt = 0L;
3762 char roomno;
3763 struct bill_x *bp;
3764 struct monst *shkp;
3765 boolean was_unpaid;
3766 long c_count = 0L, u_count = 0L;
3767
3768 if ((shkp = find_objowner(obj, x, y)) != (struct monst *) 0) {
3769 roomno = ESHK(shkp)->shoproom;
3770 } else {
3771 roomno = *in_rooms(x, y, SHOPBASE);
3772 }
3773
3774 /* gather information for message(s) prior to manipulating bill */
3775 was_unpaid = obj->unpaid ? TRUE : FALSE;
3776 if (Has_contents(obj)) {
3777 c_count = count_contents(obj, TRUE, FALSE, TRUE, FALSE);
3778 u_count = count_contents(obj, TRUE, FALSE, FALSE, FALSE);
3779 }
3780
3781 shkp = (struct monst *) 0;
3782 if (!billable(&shkp, obj, roomno, TRUE)) {
3783 /* things already on the bill yield a not-billable result, so
3784 we need to check bill before deciding that shk doesn't care */
3785 if ((bp = onbill(obj, shkp, FALSE)) != 0) {
3786 assert(shkp != NULL); /* onbill() found shkp so it's not Null */
3787 /* shk does care; take obj off bill to avoid double billing */
3788 billamt = bp->bquan * bp->price;
3789 sub_one_frombill(obj, shkp);
3790 }
3791 if (!bp && !u_count)
3792 return 0L;
3793 }
3794
3795 if (obj->oclass == COIN_CLASS) {
3796 gvalue += obj->quan;
3797 } else {
3798 if (billamt)
3799 value += billamt;
3800 else if (!obj->no_charge)
3801 value += get_pricing_units(obj) * get_cost(obj, shkp);
3802
3803 if (Has_contents(obj)) {
3804 boolean ininv =
3805 (obj->where == OBJ_INVENT || obj->where == OBJ_FREE);
3806
3807 value += stolen_container(obj, shkp, 0L, ininv);
3808 if (!ininv)
3809 gvalue += contained_gold(obj, TRUE);
3810 }

Callers 15

potionhitFunction · 0.85
rloc_to_coreFunction · 0.85
rlocoFunction · 0.85
dropzFunction · 0.85
dopushFunction · 0.85
moverock_coreFunction · 0.85
bury_objsFunction · 0.85
check_shop_objFunction · 0.85
breakobjFunction · 0.85
breakchestlockFunction · 0.85
useupfFunction · 0.85
mbag_item_goneFunction · 0.85

Calls 15

find_objownerFunction · 0.85
in_roomsFunction · 0.85
count_contentsFunction · 0.85
billableFunction · 0.85
onbillFunction · 0.85
sub_one_frombillFunction · 0.85
get_pricing_unitsFunction · 0.85
get_costFunction · 0.85
stolen_containerFunction · 0.85
contained_goldFunction · 0.85
check_creditFunction · 0.85
YouFunction · 0.85

Tested by

no test coverage detected