20 package net.sf.gridarta.model.validation.checks;
22 import java.awt.Point;
23 import java.util.ArrayList;
24 import java.util.Collection;
37 import org.jetbrains.annotations.NotNull;
45 public class BlockedSquareChecker<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends
AbstractValidator<G, A, R> implements
MapValidator<G, A, R> {
52 super(validatorPreferences);
57 for (
final MapSquare<G, A, R> completelyBlockedSquare : findCompletelyBlockedSquares(mapModel)) {
67 public static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> Iterable<MapSquare<G, A, R>> findCompletelyBlockedSquares(@NotNull
final MapModel<G, A, R> mapModel) {
68 final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
69 final int mapWidth = mapSize.
getWidth();
70 final int mapHeight = mapSize.
getHeight();
74 final boolean[][] blockedMatrix =
new boolean[mapWidth + 2][mapHeight + 2];
75 final Point pos =
new Point();
76 for (
int x = 0; x < mapWidth; x++) {
78 for (
int y = 0; y < mapHeight; y++) {
80 if (
isBlocked(mapModel.getMapSquare(pos))) {
81 blockedMatrix[x + 1][y + 1] =
true;
85 final Collection<MapSquare<G, A, R>> completelyBlockedSquares =
new ArrayList<>();
86 for (
int x = 0; x < mapWidth; x++) {
88 for (
int y = 0; y < mapHeight; y++) {
90 if (
and9x9(blockedMatrix, x + 1, y + 1)) {
91 completelyBlockedSquares.add(mapModel.getMapSquare(pos));
95 return completelyBlockedSquares;
109 private static boolean and9x9(@NotNull
final boolean[][] matrix,
final int x,
final int y) {
110 return matrix[x - 1][y - 1] && matrix[x - 1][y] && matrix[x - 1][y + 1] && matrix[x][y - 1] && matrix[x][y] && matrix[x][y + 1] && matrix[x + 1][y - 1] && matrix[x + 1][y] && matrix[x + 1][y + 1];
121 boolean noPass =
false;
122 boolean blocksView =
false;
130 if (noPass && blocksView) {
A ValidationError that refers to a completely blocked map square.
static boolean and9x9(@NotNull final boolean[][] matrix, final int x, final int y)
Returns the.
A MapModel reflects the data of a map.
This is the base class for validators.
static boolean isBlocked(@NotNull final Iterable<? extends GameObject<?, ?, ?>> square)
Return whether a square is blocked and impassable.
This package contains the framework for validating maps.
Interface for Map Validators.
String NO_PASS
The name of the "no_pass" attribute.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Configuration parameters for Validators.
GameObjects are the objects based on Archetypes found on maps.
int getWidth()
Returns the width of the area.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
An interface for classes that collect errors.
String BLOCKSVIEW
The name of the "blocksview" attribute.
BlockedSquareChecker(@NotNull final ValidatorPreferences validatorPreferences)
Creates a new instance.
A MapValidator to assert that a square that's blocked and no_pass is not surrounded by blocked and no...
int getHeight()
Returns the height of the area.
Interface for MapArchObjects.
void validateMap(@NotNull final MapModel< G, A, R > mapModel, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validate a map.
The class Size2D represents a 2d rectangular area.