| 4194 | } |
| 4195 | |
| 4196 | int |
| 4197 | doinvbill( |
| 4198 | int mode) /* 0: deliver count 1: paged */ |
| 4199 | { |
| 4200 | struct monst *shkp; |
| 4201 | struct eshk *eshkp; |
| 4202 | struct bill_x *bp, *end_bp; |
| 4203 | struct obj *obj; |
| 4204 | long totused; |
| 4205 | char *buf_p; |
| 4206 | winid datawin; |
| 4207 | |
| 4208 | shkp = shop_keeper(*u.ushops); |
| 4209 | if (!shkp || !inhishop(shkp)) { |
| 4210 | if (mode != 0) |
| 4211 | impossible("doinvbill: no shopkeeper?"); |
| 4212 | return 0; |
| 4213 | } |
| 4214 | eshkp = ESHK(shkp); |
| 4215 | |
| 4216 | if (mode == 0) { |
| 4217 | /* count expended items, so that the `I' command can decide |
| 4218 | whether to include 'x' in its prompt string */ |
| 4219 | int cnt = !eshkp->debit ? 0 : 1; |
| 4220 | |
| 4221 | for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; |
| 4222 | bp < end_bp; bp++) |
| 4223 | if (bp->useup |
| 4224 | || ((obj = bp_to_obj(bp)) != 0 && obj->quan < bp->bquan)) |
| 4225 | cnt++; |
| 4226 | return cnt; |
| 4227 | } |
| 4228 | |
| 4229 | datawin = create_nhwindow(NHW_MENU); |
| 4230 | putstr(datawin, 0, "Unpaid articles already used up:"); |
| 4231 | putstr(datawin, 0, ""); |
| 4232 | |
| 4233 | totused = 0L; |
| 4234 | for (bp = eshkp->bill_p, end_bp = &eshkp->bill_p[eshkp->billct]; |
| 4235 | bp < end_bp; bp++) { |
| 4236 | obj = bp_to_obj(bp); |
| 4237 | if (!obj) { |
| 4238 | impossible("Bad shopkeeper administration."); |
| 4239 | goto quit; |
| 4240 | } |
| 4241 | if (bp->useup || bp->bquan > obj->quan) { |
| 4242 | long oquan, uquan, thisused; |
| 4243 | |
| 4244 | oquan = obj->quan; |
| 4245 | uquan = (bp->useup ? bp->bquan : bp->bquan - oquan); |
| 4246 | thisused = bp->price * uquan; |
| 4247 | totused += thisused; |
| 4248 | iflags.suppress_price++; /* suppress "(unpaid)" suffix */ |
| 4249 | /* Why 'x'? To match `I x', more or less. */ |
| 4250 | buf_p = xprname(obj, (char *) 0, 'x', FALSE, thisused, uquan); |
| 4251 | iflags.suppress_price--; |
| 4252 | putstr(datawin, 0, buf_p); |
| 4253 | } |
no test coverage detected