Gridarta Editor
BlockedMatrix.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 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;
28 import net.sf.gridarta.utils.Size2D;
29 import org.jetbrains.annotations.NotNull;
30 
35 public class BlockedMatrix<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
36 
42  private final boolean @NotNull [] @NotNull [] blocked;
43 
48  public BlockedMatrix(@NotNull final MapModel<G, A, R> mapModel) {
49  final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
50  final int width = mapSize.getWidth();
51  final int height = mapSize.getHeight();
52  blocked = new boolean[width][height];
53  final Point pos = new Point();
54  for (pos.y = 0; pos.y < height; pos.y++) {
55  for (pos.x = 0; pos.x < width; pos.x++) {
56  for (final BaseObject<G, A, R, ?> gameObject : mapModel.getMapSquare(pos)) {
57  if (gameObject.getAttributeInt(BaseObject.NO_PASS) != 0) {
58  blocked[pos.x][pos.y] = true;
59  break;
60  }
61  }
62  }
63  }
64  }
65 
72  public boolean isBlocked(final int x, final int y) {
73  try {
74  return blocked[x][y];
75  } catch (final IndexOutOfBoundsException ignored) {
76  return true;
77  }
78  }
79 
80 }
net.sf.gridarta.utils.Size2D.getWidth
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta
Base package of all Gridarta classes.
net.sf
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.validation.checks.BlockedMatrix.BlockedMatrix
BlockedMatrix(@NotNull final MapModel< G, A, R > mapModel)
Creates a new instance.
Definition: BlockedMatrix.java:48
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.utils.Size2D.getHeight
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
net.sf.gridarta.model.validation.checks.BlockedMatrix
Determines whether a map square is blocked.
Definition: BlockedMatrix.java:35
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.baseobject.BaseObject.NO_PASS
String NO_PASS
The name of the "no_pass" attribute.
Definition: BaseObject.java:102
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model
net.sf.gridarta.model.validation.checks.BlockedMatrix.isBlocked
boolean isBlocked(final int x, final int y)
Returns whether a given location is blocked.
Definition: BlockedMatrix.java:72
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.validation.checks.BlockedMatrix.blocked
final boolean[][] blocked
The blocked grid of the currently processed map:
Definition: BlockedMatrix.java:42
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20