Gridarta Editor
AbstractShopSquareChecker.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.validation.checks;
21 
22 import java.awt.Point;
31 import net.sf.gridarta.utils.Size2D;
32 import org.jetbrains.annotations.NotNull;
33 
40 public abstract class AbstractShopSquareChecker<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> {
41 
47  super(validatorPreferences);
48  }
49 
57  @NotNull
58  protected boolean[][] findMatchingSquares(@NotNull final MapModel<G, A, R> mapModel, @NotNull final GameObjectMatcher matcher) {
59  final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
60  final int mapWidth = mapSize.getWidth();
61  final int mapHeight = mapSize.getHeight();
62  final boolean[][] matchingSquares = new boolean[mapWidth][mapHeight];
63  final Point point = new Point();
64  for (point.x = 0; point.x < mapWidth; point.x++) {
65  for (point.y = 0; point.y < mapHeight; point.y++) {
66  matchingSquares[point.x][point.y] = isMatching(mapModel.getMapSquare(point), matcher);
67  }
68  }
69  return matchingSquares;
70  }
71 
79  private boolean isMatching(@NotNull final Iterable<G> mapSquare, @NotNull final GameObjectMatcher matcher) {
80  for (final GameObject<G, A, R> gameObject : mapSquare) {
81  if (matcher.isMatching(gameObject.getHead())) {
82  return true;
83  }
84  }
85  return false;
86  }
87 
88 }
A MapModel reflects the data of a map.
Definition: MapModel.java:75
This is the base class for validators.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
This package contains the framework for validating maps.
boolean isMatching(@NotNull final Iterable< G > mapSquare, @NotNull final GameObjectMatcher matcher)
Returns whether a map square contains a game object matching a given GameObjectMatcher.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
GameObjects are the objects based on Archetypes found on maps.
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
boolean [][] findMatchingSquares(@NotNull final MapModel< G, A, R > mapModel, @NotNull final GameObjectMatcher matcher)
Returns a.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
A MapValidator to detect shop squares which allow magic or prayers, or which have adjacent squares th...
AbstractShopSquareChecker(@NotNull final ValidatorPreferences validatorPreferences)
Creates a new instance.
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30