CleverRaven/Cataclysm-DDA — pull request #8190 by BevapDin (2014-07-09 21:26:59+00:00)
Title: fix bug in distance calculation.

A wonderful old bug (e6fd9aab4c5630fb5aad7b69f562bd36193fa699):

Original code:
```
if (rl_dist(x, y, g->u.posx, g->u.posy > 3 && g->num_zombies() < 30 &&
g->mon_at(x, y) == -1 && one_in(20))) { // Spawn an extra monster
```

Slightly reformatted (no functional changes):
```
if (
rl_dist(
x,
y,
g->u.posx,
g->u.posy > 3 && g->num_zombies() < 30 && g->mon_at(x, y) == -1 && one_in(20)
)
) { // Spawn an extra monster
```

The fourth parameter of `rl_dist` is `const int`.

`g->u.posy > 3 && g->num_zombies() < 30 && g->mon_at(x, y) == -1 && one_in(20)` is actually a `bool`, but that's close enough for C++.
And because bool->int conversion results in either 1 or 0, the function is always called with y2=0 or y2=1.

It becomes: `if ( rl_dist(x, y, g->u.posx, 1) ) {` and rl_dist is very unlikely to return 0 (y is calculated as `rng(g->u.posy, z->posy() - 3)`, most likely greater than 1).
Because everything but 0 is true, the condition is actually always true.

I'm pretty sure this is not intended.