called when attempting to #loot while confused */
| 2347 | |
| 2348 | /* called when attempting to #loot while confused */ |
| 2349 | staticfn boolean |
| 2350 | reverse_loot(void) |
| 2351 | { |
| 2352 | struct obj *goldob = 0, *coffers, *otmp, boxdummy; |
| 2353 | struct monst *mon; |
| 2354 | long contribution; |
| 2355 | int n, x = u.ux, y = u.uy; |
| 2356 | |
| 2357 | if (!rn2(3)) { |
| 2358 | /* n objects: 1/(n+1) chance per object, 1/(n+1) to fall off end */ |
| 2359 | for (n = inv_cnt(TRUE), otmp = gi.invent; otmp; |
| 2360 | --n, otmp = otmp->nobj) |
| 2361 | if (!rn2(n + 1)) { |
| 2362 | prinv("You find old loot:", otmp, 0L); |
| 2363 | return TRUE; |
| 2364 | } |
| 2365 | return FALSE; |
| 2366 | } |
| 2367 | |
| 2368 | /* find a money object to mess with */ |
| 2369 | for (goldob = gi.invent; goldob; goldob = goldob->nobj) |
| 2370 | if (goldob->oclass == COIN_CLASS) { |
| 2371 | contribution = ((long) rnd(5) * goldob->quan + 4L) / 5L; |
| 2372 | if (contribution < goldob->quan) |
| 2373 | goldob = splitobj(goldob, contribution); |
| 2374 | break; |
| 2375 | } |
| 2376 | if (!goldob) |
| 2377 | return FALSE; |
| 2378 | |
| 2379 | /* gold might be quivered; dropping would un-wear it, but freeinv() |
| 2380 | expects caller to do that; do so now */ |
| 2381 | remove_worn_item(goldob, FALSE); |
| 2382 | |
| 2383 | if (!IS_THRONE(levl[x][y].typ)) { |
| 2384 | dropx(goldob); |
| 2385 | /* the dropped gold might have fallen to lower level */ |
| 2386 | if (g_at(x, y)) |
| 2387 | pline("Ok, now there is loot here."); |
| 2388 | } else { |
| 2389 | /* find original coffers chest if present, otherwise use nearest */ |
| 2390 | otmp = 0; |
| 2391 | for (coffers = fobj; coffers; coffers = coffers->nobj) |
| 2392 | if (coffers->otyp == CHEST) { |
| 2393 | if (coffers->spe == 2) |
| 2394 | break; /* a throne room chest */ |
| 2395 | if (!otmp || (distu(coffers->ox, coffers->oy) |
| 2396 | < distu(otmp->ox, otmp->oy))) |
| 2397 | otmp = coffers; /* remember closest ordinary chest */ |
| 2398 | } |
| 2399 | if (!coffers) |
| 2400 | coffers = otmp; |
| 2401 | |
| 2402 | if (coffers) { |
| 2403 | SetVoice((struct monst *) 0, 0, 80, 0); |
| 2404 | verbalize("Thank you for your contribution to reduce the debt."); |
| 2405 | freeinv(goldob); |
| 2406 | (void) add_to_container(coffers, goldob); |
no test coverage detected