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

Function sellobj

src/shk.c:3926–4194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3924}
3925
3926void
3927sellobj(
3928 struct obj *obj,
3929 coordxy x, coordxy y)
3930{
3931 struct monst *shkp;
3932 struct eshk *eshkp;
3933 long ltmp = 0L, cltmp = 0L, gltmp = 0L, offer, shkmoney;
3934 boolean saleitem, cgold = FALSE, container = Has_contents(obj);
3935 boolean isgold = (obj->oclass == COIN_CLASS);
3936 boolean only_partially_your_contents = FALSE;
3937
3938 if (!*u.ushops) /* do cheapest exclusion test first */
3939 return;
3940 shkp = shop_keeper(*in_rooms(x, y, SHOPBASE));
3941 if (!shkp || !inhishop(shkp))
3942 return;
3943 if (!costly_spot(x, y))
3944 return;
3945
3946 if (obj->unpaid && !container && !isgold) {
3947 sub_one_frombill(obj, shkp);
3948 return;
3949 }
3950 if (container) {
3951 /* find the price of content before subfrombill */
3952 cltmp = contained_cost(obj, shkp, cltmp, TRUE, FALSE);
3953 /* find the value of contained gold */
3954 gltmp += contained_gold(obj, TRUE);
3955 cgold = (gltmp > 0L);
3956 }
3957
3958 saleitem = saleable(shkp, obj);
3959 if (!isgold && !obj->unpaid && saleitem)
3960 ltmp = set_cost(obj, shkp);
3961
3962 offer = ltmp + cltmp;
3963
3964 /* you dropped something of your own - probably want to sell it */
3965 rouse_shk(shkp, TRUE); /* wake up sleeping or paralyzed shk */
3966 eshkp = ESHK(shkp);
3967
3968 if (ANGRY(shkp)) { /* they become shop-objects, no pay */
3969 if (!Deaf && !muteshk(shkp)) {
3970 SetVoice(shkp, 0, 80, 0);
3971 verbalize("Thank you, scum!");
3972 } else {
3973 pline("%s smirks with satisfaction.", Shknam(shkp));
3974 }
3975 subfrombill(obj, shkp);
3976 return;
3977 }
3978
3979 /* get one case out of the way: nothing to sell, and no gold */
3980 if (!(isgold || cgold)
3981 && ((offer + gltmp) == 0L || gs.sell_how == SELL_DONTSELL)) {
3982 boolean unpaid = is_unpaid(obj);
3983

Callers 5

dropzFunction · 0.85
check_shop_objFunction · 0.85
throw_goldFunction · 0.85
in_containerFunction · 0.85
cnv_trap_objFunction · 0.85

Calls 15

shop_keeperFunction · 0.85
in_roomsFunction · 0.85
inhishopFunction · 0.85
costly_spotFunction · 0.85
sub_one_frombillFunction · 0.85
contained_costFunction · 0.85
contained_goldFunction · 0.85
saleableFunction · 0.85
set_costFunction · 0.85
rouse_shkFunction · 0.85
verbalizeFunction · 0.85
ShknamFunction · 0.85

Tested by

no test coverage detected