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

@@ -1090,11 +1090,23 @@ Example:
=== gradient
Create a "gradient" of selected positions.
Create a "gradient" of selected positions, radiating outward from a center point
or line.
x and y are required; x2 and y2 are not required. If they are provided and are
different from x and y, the center of the gradient will be a line; otherwise it
will be a point source at (x,y).
type is either "radial" or "square"; defaults to "radial" if not provided.
mindist is not required and is 0 by default. Points within (mindist) tiles of
the center will always be added to the selection.
maxdist is required. Points more than (maxdist) tiles from the center will never
be added to the selection.
For any given point between mindist and maxdist, there is a random chance it
will be added to the selection; this chance starts at 100% at mindist and
decreases linearly to 0% at maxdist.
Example:
local s = selection.gradient({ type = "radial", x = 3, y = 5, x2 = 10, y2 = 12, mindist = 4, maxdist = 10, limited = false });
local s = selection.gradient({ type = "radial", x = 3, y = 5, x2 = 10, y2 = 12, mindist = 4, maxdist = 10 });
=== grow