MCPcopy Create free account
hub / github.com/NetHack/NetHack / pay_for_damage

Function pay_for_damage

src/shk.c:5173–5346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5171}
5172
5173void
5174pay_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;

Callers 9

still_chewingFunction · 0.85
digFunction · 0.85
digactualholeFunction · 0.85
zap_digFunction · 0.85
bhitFunction · 0.85
dobuzzFunction · 0.85
kick_doorFunction · 0.85
do_break_wandFunction · 0.85
explodeFunction · 0.85

Calls 15

in_roomsFunction · 0.85
shop_keeperFunction · 0.85
inhishopFunction · 0.85
rn2Function · 0.85
hot_pursuitFunction · 0.85
getcadFunction · 0.85
um_distFunction · 0.85
ShknamFunction · 0.85
mnextoFunction · 0.85
You_hearFunction · 0.85
verbalizeFunction · 0.85
wait_synchFunction · 0.85

Tested by

no test coverage detected