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 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) {
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();