20 package net.sf.gridarta.model.floodfill;
22 import java.awt.Point;
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.List;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
61 public static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
void fill(@NotNull
final MapModel<G, A, R> mapModel, @NotNull
final Collection<
MapSquare<G, A, R>> selection, @NotNull
final InsertionMode<G, A, R> insertionMode, @NotNull
final List<? extends
BaseObject<G, A, R, ?>> gameObjects,
final int density,
final boolean noAdjacent) {
62 if (selection.isEmpty()) {
66 if (gameObjects.isEmpty()) {
70 @Nullable
final Set<String> archetypeNames;
72 archetypeNames =
new HashSet<>();
74 archetypeNames.add(baseObject.getArchetype().getArchetypeName());
77 archetypeNames = null;
80 mapModel.beginTransaction(
"Fill");
83 if (density != -1 && density != 100 && density <
RandomUtils.
RND.nextInt(100) + 1) {
87 if (archetypeNames != null) {
91 if (containsArchetype(mapModel, archetypeNames, mapSquare, w, h)) {
95 mapModel.insertBaseObject(gameObject, mapSquare.
getMapLocation(),
false,
false, insertionMode);
98 mapModel.endTransaction();
112 private static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends
Archetype<G, A, R>>
boolean containsArchetype(@NotNull
final MapModel<G, A, R> mapModel, @NotNull
final Collection<String> archetypeNames, @NotNull
final MapSquare<G, A, R> topLeftMapSquare,
final int w,
final int h) {
113 final Point pos =
new Point();
114 for (
int dy = -1; dy < h + 1; dy++) {
115 for (
int dx = -1; dx < w + 1; dx++) {
116 topLeftMapSquare.getMapLocation(pos, dx, dy);
120 }
catch (
final IndexOutOfBoundsException ignored) {
125 if (archetypeNames.contains(gameObject.getHead().getArchetype().getArchetypeName())) {
141 public static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends
Archetype<G, A, R>>
void floodFill(@NotNull
final MapModel<G, A, R> mapModel, @NotNull
final Point start, @NotNull
final List<? extends
BaseObject<G, A, R, ?>> gameObjects, @NotNull
final InsertionModeSet<G, A, R> insertionModeSet) {
142 if (gameObjects.isEmpty()) {
146 if (!mapModel.getMapArchObject().isPointValid(start) || !mapModel.getMapSquare(start).isEmpty()) {
150 mapModel.beginTransaction(
"Flood-fill");
154 mapModel.endTransaction();
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
FillUtils()
Private constructor to prevent instantiation.
int getSizeY()
Determines the vertical extent in squares.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
int getSizeX()
Determines the horizontal extent in squares.
GameObjects are the objects based on Archetypes found on maps.
static final Random RND
Global random number generator.
Point getMapLocation()
Returns the coordinate of this GameObject on its map.
R getArchetype()
Returns the Archetype this GameObject is based on.
Implements flood-filling.
Utility class implementing fill operations on map instances.
Interface for MapArchObjects.