20 package net.sf.gridarta.model.floodfill;
22 import java.awt.Point;
23 import java.util.List;
32 import org.jetbrains.annotations.NotNull;
64 private static final byte
BORDER = (byte) 1;
68 private static final byte
BLOCKED = (byte) 3;
77 public void floodFill(@NotNull
final MapModel<G, A, R> mapModel, @NotNull
final Point start, @NotNull
final List<? extends
BaseObject<G, A, R, ?>> archList, @NotNull
final InsertionModeSet<G, A, R> insertionModeSet) {
81 area[start.x][start.y] =
BORDER;
82 mapModel.beginTransaction(
"Flood Fill");
86 final Point p =
new Point();
87 for (p.x = 0; p.x < mapSize.
getWidth(); p.x++) {
88 for (p.y = 0; p.y < mapSize.
getHeight(); p.y++) {
89 if (area[p.x][p.y] == BORDER) {
91 if (mapArchObject.
isPointValid(p) && mapModel.getMapSquare(p).isEmpty()) {
94 mapModel.insertBaseObject(gameObject, p,
false,
false, insertionModeSet.getTopmostInsertionMode());
97 if (area[p.x - 1][p.y] == NOT_LOOKED_AT) {
98 area[p.x - 1][p.y] =
BORDER;
101 }
catch (
final ArrayIndexOutOfBoundsException ignored) {
106 if (area[p.x + 1][p.y] == NOT_LOOKED_AT) {
107 area[p.x + 1][p.y] =
BORDER;
110 }
catch (
final ArrayIndexOutOfBoundsException ignored) {
115 if (area[p.x][p.y - 1] == NOT_LOOKED_AT) {
116 area[p.x][p.y - 1] =
BORDER;
119 }
catch (
final ArrayIndexOutOfBoundsException ignored) {
124 if (area[p.x][p.y + 1] == NOT_LOOKED_AT) {
125 area[p.x][p.y + 1] =
BORDER;
128 }
catch (
final ArrayIndexOutOfBoundsException ignored) {
139 mapModel.endTransaction();
static final byte NOT_LOOKED_AT
Constants for lookArea.
boolean isPointValid(@Nullable Point pos)
Checks whether the given coordinate is within map bounds.
A MapModel reflects the data of a map.
static final byte BLOCKED
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Size2D getMapSize()
Returns the map size.
GameObjects are the objects based on Archetypes found on maps.
int getWidth()
Returns the width of the area.
static final Random RND
Global random number generator.
static final byte WAS_EMPTY
Implements flood-filling.
int getHeight()
Returns the height of the area.
Interface for MapArchObjects.
void floodFill(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Point start, @NotNull final List<? extends BaseObject< G, A, R, ?>> archList, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
Flood-fill the map.
The class Size2D represents a 2d rectangular area.