return 2 if used-up portion paid * 1 if paid successfully * 0 if not enough money * -1 if skip this object * -2 if no money/credit left */
| 2217 | * -2 if no money/credit left |
| 2218 | */ |
| 2219 | staticfn int |
| 2220 | dopayobj( |
| 2221 | struct monst *shkp, |
| 2222 | struct bill_x *bp, |
| 2223 | struct obj *obj, |
| 2224 | int which, /* 0 => used-up item, 1 => other (unpaid or lost) */ |
| 2225 | boolean itemize, |
| 2226 | boolean unseen) |
| 2227 | { |
| 2228 | long ltmp, quan, save_quan; |
| 2229 | int buy; |
| 2230 | boolean consumed = (which == 0); |
| 2231 | |
| 2232 | if (!obj->unpaid && !bp->useup |
| 2233 | && !(Has_contents(obj) && unpaid_cost(obj, COST_CONTENTS))) { |
| 2234 | impossible("Paid object on bill??"); |
| 2235 | return PAY_BUY; |
| 2236 | } |
| 2237 | if (itemize && insufficient_funds(shkp, obj, 0L)) { |
| 2238 | return PAY_BROKE; |
| 2239 | } |
| 2240 | /* we may need to temporarily adjust the object, if part of the |
| 2241 | original quantity has been used up but part remains unpaid; [note: |
| 2242 | this predates 'ibill[]' and feels redundant but still works] */ |
| 2243 | save_quan = obj->quan; |
| 2244 | if (consumed) { |
| 2245 | /* either completely used up (simple), or split needed */ |
| 2246 | quan = bp->bquan; |
| 2247 | if (quan > obj->quan) /* difference is amount used up */ |
| 2248 | quan -= obj->quan; |
| 2249 | } else { |
| 2250 | /* dealing with ordinary unpaid item */ |
| 2251 | quan = obj->quan; |
| 2252 | } |
| 2253 | ltmp = bp->price * quan; |
| 2254 | |
| 2255 | obj->quan = quan; /* to be used by doname() */ |
| 2256 | iflags.suppress_price++; /* affects containers */ |
| 2257 | buy = PAY_BUY; /* flag; if changed then return early */ |
| 2258 | |
| 2259 | if (itemize) { |
| 2260 | char qbuf[BUFSZ], qsfx[BUFSZ]; |
| 2261 | |
| 2262 | /* |
| 2263 | * TODO: |
| 2264 | * This should also accept 'a' and 'q' to end itemized paying: |
| 2265 | * 'a' to buy the rest without asking, 'q' to just stop. |
| 2266 | */ |
| 2267 | |
| 2268 | Sprintf(qsfx, " for %ld %s. Pay?", ltmp, currency(ltmp)); |
| 2269 | (void) safe_qbuf(qbuf, (char *) 0, qsfx, obj, |
| 2270 | (quan == 1L) ? Doname2 : doname, ansimpleoname, |
| 2271 | (quan == 1L) ? "that" : "those"); |
| 2272 | if (y_n(qbuf) == 'n') { |
| 2273 | buy = PAY_SKIP; /* don't want to buy */ |
| 2274 | } |
| 2275 | } /* itemize */ |
| 2276 |
no test coverage detected