returns nonzero if something was hit */
| 2425 | |
| 2426 | /* returns nonzero if something was hit */ |
| 2427 | int |
| 2428 | bhitpile( |
| 2429 | struct obj *obj, /* wand or fake spellbook for type of zap */ |
| 2430 | int (*fhito)(OBJ_P, OBJ_P), /* callback for each object being hit */ |
| 2431 | coordxy tx, coordxy ty, /* target location */ |
| 2432 | schar zz) /* direction for up/down zaps */ |
| 2433 | { |
| 2434 | struct obj *otmp, *next_obj; |
| 2435 | boolean hidingunder, first; |
| 2436 | int prevotyp, hitanything = 0; |
| 2437 | |
| 2438 | if (!svl.level.objects[tx][ty]) |
| 2439 | return 0; |
| 2440 | |
| 2441 | /* if hiding underneath an object and zapping up or down, the top item |
| 2442 | is either the only thing hit (up) or is skipped (down) */ |
| 2443 | hidingunder = (zz != 0 && u.uundetected && hides_under(gy.youmonst.data)); |
| 2444 | first = TRUE; |
| 2445 | |
| 2446 | if (obj->otyp == SPE_FORCE_BOLT || obj->otyp == WAN_STRIKING) { |
| 2447 | struct trap *t = t_at(tx, ty); |
| 2448 | struct obj *topofpile = svl.level.objects[tx][ty]; |
| 2449 | |
| 2450 | /* We can't settle for the default calling sequence of |
| 2451 | bhito(otmp) -> break_statue(otmp) -> activate_statue_trap(ox,oy) |
| 2452 | because that last call might end up operating on our `next_obj' |
| 2453 | (below), rather than on the current object, if it happens to |
| 2454 | encounter a statue which mustn't become animated. */ |
| 2455 | if (t && t->ttyp == STATUE_TRAP |
| 2456 | && activate_statue_trap(t, tx, ty, TRUE)) |
| 2457 | learnwand(obj); |
| 2458 | /* assume zapping up or down while hiding under the top item can |
| 2459 | still activate the trap even if it's below (when zapping up) |
| 2460 | or above (when zapping down) */ |
| 2461 | if (svl.level.objects[tx][ty] != topofpile) |
| 2462 | first = FALSE; /* top item was statue which activated */ |
| 2463 | } |
| 2464 | |
| 2465 | gp.poly_zapped = -1; |
| 2466 | for (otmp = svl.level.objects[tx][ty]; otmp; otmp = next_obj) { |
| 2467 | next_obj = otmp->nexthere; |
| 2468 | if (hidingunder) { |
| 2469 | if (first) { |
| 2470 | first = FALSE; /* reset for next item */ |
| 2471 | if (zz > 0) /* down when hiding-under skips first item */ |
| 2472 | continue; |
| 2473 | } else { |
| 2474 | /* !first */ |
| 2475 | if (zz < 0) /* up when hiding-under skips rest of pile */ |
| 2476 | continue; |
| 2477 | } |
| 2478 | } |
| 2479 | if (otmp->where != OBJ_FLOOR || otmp->ox != tx || otmp->oy != ty) |
| 2480 | continue; |
| 2481 | hitanything += (*fhito)(otmp, obj); |
| 2482 | } |
| 2483 | |
| 2484 | if (gp.poly_zapped >= 0) |
no test coverage detected