| 5171 | } |
| 5172 | |
| 5173 | void |
| 5174 | pay_for_damage(const char *dmgstr, boolean cant_mollify) |
| 5175 | { |
| 5176 | struct monst *shkp = (struct monst *) 0; |
| 5177 | char shops_affected[5]; |
| 5178 | boolean uinshp = (*u.ushops != '\0'); |
| 5179 | char qbuf[80]; |
| 5180 | coordxy x, y; |
| 5181 | boolean animal, pursue; |
| 5182 | struct damage *tmp_dam, *appear_here = 0; |
| 5183 | long cost_of_damage = 0L; |
| 5184 | unsigned int nearest_shk = (ROWNO * ROWNO) + (COLNO * COLNO), |
| 5185 | nearest_damage = nearest_shk; |
| 5186 | int picks = 0; |
| 5187 | |
| 5188 | for (tmp_dam = svl.level.damagelist; tmp_dam; tmp_dam = tmp_dam->next) { |
| 5189 | char *shp; |
| 5190 | |
| 5191 | if (tmp_dam->when != svm.moves || !tmp_dam->cost) |
| 5192 | continue; |
| 5193 | cost_of_damage += tmp_dam->cost; |
| 5194 | Strcpy(shops_affected, |
| 5195 | in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE)); |
| 5196 | for (shp = shops_affected; *shp; shp++) { |
| 5197 | struct monst *tmp_shk; |
| 5198 | unsigned int shk_distance; |
| 5199 | |
| 5200 | if (!(tmp_shk = shop_keeper(*shp))) |
| 5201 | continue; |
| 5202 | if (tmp_shk == shkp) { |
| 5203 | unsigned int damage_distance = |
| 5204 | distu(tmp_dam->place.x, tmp_dam->place.y); |
| 5205 | |
| 5206 | if (damage_distance < nearest_damage) { |
| 5207 | nearest_damage = damage_distance; |
| 5208 | appear_here = tmp_dam; |
| 5209 | } |
| 5210 | continue; |
| 5211 | } |
| 5212 | if (!inhishop(tmp_shk)) |
| 5213 | continue; |
| 5214 | shk_distance = mdistu(tmp_shk); |
| 5215 | if (shk_distance > nearest_shk) |
| 5216 | continue; |
| 5217 | if ((shk_distance == nearest_shk) && picks) { |
| 5218 | if (rn2(++picks)) |
| 5219 | continue; |
| 5220 | } else |
| 5221 | picks = 1; |
| 5222 | shkp = tmp_shk; |
| 5223 | nearest_shk = shk_distance; |
| 5224 | appear_here = tmp_dam; |
| 5225 | nearest_damage = distu(tmp_dam->place.x, tmp_dam->place.y); |
| 5226 | } |
| 5227 | } |
| 5228 | |
| 5229 | if (!cost_of_damage || !shkp) |
| 5230 | return; |
no test coverage detected