hero is hit by something other than a monster (though it could be a missile thrown or shot by a monster) */
| 72 | /* hero is hit by something other than a monster (though it could be a |
| 73 | missile thrown or shot by a monster) */ |
| 74 | int |
| 75 | thitu( |
| 76 | int tlev, /* pseudo-level used when deciding whether to hit hero's AC */ |
| 77 | int dam, |
| 78 | struct obj **objp, |
| 79 | const char *name) /* if null, then format `*objp' */ |
| 80 | { |
| 81 | struct obj *obj = objp ? *objp : 0; |
| 82 | const char *onm, *knm; |
| 83 | boolean is_acid, named = (name != 0); |
| 84 | int kprefix = KILLED_BY_AN, dieroll; |
| 85 | char onmbuf[BUFSZ], knmbuf[BUFSZ]; |
| 86 | |
| 87 | if (!name) { |
| 88 | if (!obj) |
| 89 | panic("thitu: name & obj both null?"); |
| 90 | name = strcpy(onmbuf, |
| 91 | (obj->quan > 1L) ? doname(obj) : mshot_xname(obj)); |
| 92 | knm = strcpy(knmbuf, killer_xname(obj)); |
| 93 | kprefix = KILLED_BY; /* killer_name supplies "an" if warranted */ |
| 94 | } else { |
| 95 | knm = name; |
| 96 | /* [perhaps ought to check for plural here too] */ |
| 97 | if (!strncmpi(name, "the ", 4) || !strncmpi(name, "an ", 3) |
| 98 | || !strncmpi(name, "a ", 2)) |
| 99 | kprefix = KILLED_BY; |
| 100 | } |
| 101 | onm = (obj && obj_is_pname(obj)) ? the(name) |
| 102 | : (obj && obj->quan > 1L) ? name |
| 103 | : an(name); |
| 104 | is_acid = (obj && obj->otyp == ACID_VENOM); |
| 105 | |
| 106 | if (u.uac + tlev <= (dieroll = rnd(20))) { |
| 107 | ++gm.mesg_given; |
| 108 | if (Blind || !flags.verbose) { |
| 109 | pline("It misses."); |
| 110 | } else if (u.uac + tlev <= dieroll - 2) { |
| 111 | if (onm != onmbuf) |
| 112 | Strcpy(onmbuf, onm); /* [modifiable buffer for upstart()] */ |
| 113 | pline("%s %s you.", upstart(onmbuf), vtense(onmbuf, "miss")); |
| 114 | } else |
| 115 | You("are almost hit by %s.", onm); |
| 116 | return 0; |
| 117 | } else { |
| 118 | if (Blind || !flags.verbose) |
| 119 | You("are hit%s", exclam(dam)); |
| 120 | else |
| 121 | You("are hit by %s%s", onm, exclam(dam)); |
| 122 | |
| 123 | if (is_acid && Acid_resistance) { |
| 124 | pline("It doesn't seem to hurt you."); |
| 125 | monstseesu(M_SEEN_ACID); |
| 126 | } else if (obj && stone_missile(obj) |
| 127 | && passes_rocks(gy.youmonst.data)) { |
| 128 | /* use 'named' as an approximation for "hitting from above"; |
| 129 | we avoid "passes through you" for horizontal flight path |
| 130 | because missile stops and that wording would suggest that |
| 131 | it should keep going */ |
no test coverage detected