Invert the behavior of selection.gradient

selection.gradient has some pretty unintuitive behavior, in that it
selects points that are NOT close to the defined center. I've used
gradient selections several times and so far all of them have had to be
negated, because I wanted to select points close to the center with a
decreasing probability further out.

This implements that behavior, and also fixes a bug in which the x,y
coordinates of the gradient center(s) were not converted properly when
used within a des.room or des.map. Also updated the lua documentation
for gradient.

I removed the "limited" argument, as it was previously used to control
whether the rest of the map outside the max given distance would be
included in the selection; now that the area beyond maxdist is naturally
never in the selection, it doesn't have much use. (And I can't think of
a reasonable use case for the inverse: wanting to select points close to
the center, with decreasing chance towards maxdist, but then select the
entire map beyond maxdist.)

Currently this does not affect any special levels or themed rooms
because none of them use selection.gradient.
This commit is contained in:
copperwater
2023-02-10 07:38:22 -05:00
committed by Pasi Kallinen
parent 10cafddcb0
commit 9d0df0c9f0
4 changed files with 27 additions and 20 deletions

View File

@@ -4989,13 +4989,14 @@ line_dist_coord(long x1, long y1, long x2, long y2, long x3, long y3)
return dist;
}
/* guts of l_selection_gradient */
void
selection_do_gradient(
struct selectionvar *ov,
long x, long y,
long x2,long y2,
long gtyp,
long mind, long maxd, long limit)
long mind, long maxd)
{
long dx, dy, dofs;
@@ -5017,10 +5018,8 @@ selection_do_gradient(
for (dx = 0; dx < COLNO; dx++)
for (dy = 0; dy < ROWNO; dy++) {
long d0 = line_dist_coord(x, y, x2, y2, dx, dy);
if (d0 >= mind && (!limit || d0 <= maxd)) {
if (d0 - mind > rn2(dofs))
selection_setpoint(dx, dy, ov, 1);
}
if (d0 <= mind || (d0 <= maxd && d0 - mind < rn2(dofs)))
selection_setpoint(dx, dy, ov, 1);
}
break;
}
@@ -5034,10 +5033,8 @@ selection_do_gradient(
long d5 = line_dist_coord(x, y, x2, y2, dx, dy);
long d0 = min(d5, min(max(d1, d2), max(d3, d4)));
if (d0 >= mind && (!limit || d0 <= maxd)) {
if (d0 - mind > rn2(dofs))
selection_setpoint(dx, dy, ov, 1);
}
if (d0 <= mind || (d0 <= maxd && d0 - mind < rn2(dofs)))
selection_setpoint(dx, dy, ov, 1);
}
break;
} /*case*/