update shk's bill and augmented bill after an item has been purchased */
| 2168 | |
| 2169 | /* update shk's bill and augmented bill after an item has been purchased */ |
| 2170 | staticfn void |
| 2171 | update_bill( |
| 2172 | int indx, /* index into ibill[]; -1 for unpaid contained item */ |
| 2173 | int ibillct, |
| 2174 | Bill *ibill, |
| 2175 | struct eshk *eshkp, |
| 2176 | struct bill_x *bp, |
| 2177 | struct obj *paiditem) |
| 2178 | { |
| 2179 | int j, newebillct; |
| 2180 | |
| 2181 | /* remove from eshkp->bill_p[] unless this was the used up portion |
| 2182 | of partly used item (since removal would take out both; note: |
| 2183 | can't buy PartlyIntact until PartlyUsedUp has been paid for) */ |
| 2184 | if (indx >= 0 && ibill[indx].usedup == PartlyUsedUp) { |
| 2185 | /* 'paiditem' points to the partly intact portion still in invent or |
| 2186 | inside a container (ibill[indx].obj points to the container) */ |
| 2187 | bp->bquan = paiditem->quan; |
| 2188 | for (j = 0; j < ibillct; ++j) |
| 2189 | if (ibill[j].obj == paiditem && ibill[j].usedup == PartlyIntact) { |
| 2190 | ibill[j].usedup = FullyIntact; |
| 2191 | break; |
| 2192 | } |
| 2193 | } else { |
| 2194 | /* if we get here, something was bought and needs to be removed |
| 2195 | from shop bill; if it was used up, remove it from the billobjs |
| 2196 | list and delete it; update shop's bill by moving last bill_p[] |
| 2197 | entry into vacated slot; also update ibill[] indices for that */ |
| 2198 | paiditem->unpaid = 0; /* clear before maybe deallocating */ |
| 2199 | if (paiditem->where == OBJ_ONBILL) { |
| 2200 | obj_extract_self(paiditem); |
| 2201 | dealloc_obj(paiditem); |
| 2202 | } |
| 2203 | newebillct = eshkp->billct - 1; |
| 2204 | *bp = eshkp->bill_p[newebillct]; |
| 2205 | for (j = 0; j < ibillct; ++j) |
| 2206 | if (ibill[j].bidx == newebillct) |
| 2207 | ibill[j].bidx = (int) (bp - eshkp->bill_p); |
| 2208 | eshkp->billct = newebillct; /* eshkp->billct - 1 */ |
| 2209 | } |
| 2210 | return; |
| 2211 | } |
| 2212 | |
| 2213 | /* return 2 if used-up portion paid |
| 2214 | * 1 if paid successfully |
no test coverage detected