Gridarta Editor
ArchetypeTypeChecks.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.util.Collection;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.Set;
54 import org.apache.log4j.Category;
55 import org.apache.log4j.Logger;
56 import org.jetbrains.annotations.NotNull;
57 import org.jetbrains.annotations.Nullable;
58 
63 public class ArchetypeTypeChecks {
64 
68  private static final Category LOG = Logger.getLogger(ArchetypeTypeChecks.class);
69 
73  private ArchetypeTypeChecks() {
74  }
75 
83  public static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> void addChecks(@NotNull final ArchetypeTypeSet archetypeTypeSet, @Nullable final AttributeRangeChecker<G, A, R> attributeRangeChecker, @NotNull final EnvironmentChecker<G, A, R> environmentChecker) {
84  if (attributeRangeChecker == null) {
85  return;
86  }
87 
88  final Set<Integer> allowsAllInvTypes = new HashSet<>();
89  for (final ArchetypeType archetypeType : archetypeTypeSet) {
90  if (archetypeType.isAllowsAllInv()) {
91  allowsAllInvTypes.add(archetypeType.getTypeNo());
92  }
93  }
94  for (final ArchetypeType archetypeType : archetypeTypeSet) {
95  addChecks(archetypeTypeSet, attributeRangeChecker, archetypeType);
96  if (!archetypeType.isMap()) {
97  environmentChecker.addNoMap(archetypeType);
98  }
99  final int[] types = archetypeType.getInv();
100  if (types != null) {
101  final Collection<Integer> tmp = new HashSet<>(allowsAllInvTypes);
102  for (final int type : types) {
103  tmp.add(type);
104  }
105  final int[] tmp2 = new int[tmp.size()];
106  final Iterator<Integer> it = tmp.iterator();
107  for (int i = 0; i < tmp2.length; i++) {
108  tmp2[i] = it.next();
109  }
110  assert !it.hasNext();
111  environmentChecker.addInv(archetypeType, tmp2);
112  }
113  }
114  }
115 
123  private static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> void addChecks(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final AttributeRangeChecker<G, A, R> attributeRangeChecker, @NotNull final ArchetypeType archetypeType) {
124  if (archetypeType.hasTypeAttributes()) {
125  return; // XXX: make such attributes work
126  }
127 
128  final ArchetypeAttributeVisitor archetypeAttributeVisitor = new ArchetypeAttributeVisitor() {
129 
130  @Override
131  public void visit(@NotNull final ArchetypeAttributeAnimationName archetypeAttribute) {
132  // XXX: missing
133  }
134 
135  @Override
136  public void visit(@NotNull final ArchetypeAttributeBitmask archetypeAttribute) {
137  final AttributeBitmask bitmask = archetypeTypeSet.getBitmask(archetypeAttribute.getBitmaskName());
138  if (bitmask != null) {
139  try {
140  attributeRangeChecker.add(archetypeType.getTypeNo(), archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName(), 0, bitmask.getMaxValue());
141  } catch (final InvalidCheckException ex) {
142  LOG.warn(ex.getMessage() + " in type " + archetypeType.getTypeNo() + ".");
143  }
144  }
145  }
146 
147  @Override
148  public void visit(@NotNull final ArchetypeAttributeBool archetypeAttribute) {
149  try {
150  attributeRangeChecker.add(archetypeType.getTypeNo(), archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName(), 0, 1);
151  } catch (final InvalidCheckException ex) {
152  LOG.warn(ex.getMessage() + " in type " + archetypeType.getTypeNo() + ".");
153  }
154  }
155 
156  @Override
157  public void visit(@NotNull final ArchetypeAttributeBoolSpec archetypeAttribute) {
158  // XXX: missing
159  }
160 
161  @Override
162  public void visit(@NotNull final ArchetypeAttributeFaceName archetypeAttribute) {
163  // XXX: missing
164  }
165 
166  @Override
167  public void visit(@NotNull final ArchetypeAttributeFixed archetypeAttribute) {
168  // XXX: missing
169  }
170 
171  @Override
172  public void visit(@NotNull final ArchetypeAttributeFloat archetypeAttribute) {
173  // XXX: missing
174  }
175 
176  @Override
177  public void visit(@NotNull final ArchetypeAttributeInt archetypeAttribute) {
178  try {
179  attributeRangeChecker.add(archetypeType.getTypeNo(), archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName(), archetypeAttribute.getMinCheckValue(), archetypeAttribute.getMaxCheckValue());
180  } catch (final InvalidCheckException ex) {
181  LOG.warn(ex.getMessage() + " in type " + archetypeType.getTypeNo() + ".");
182  }
183  }
184 
185  @Override
186  public void visit(@NotNull final ArchetypeAttributeInvSpell archetypeAttribute) {
187  // XXX: missing
188  }
189 
190  @Override
191  public void visit(@NotNull final ArchetypeAttributeList archetypeAttribute) {
192  // XXX: missing
193  }
194 
195  @Override
196  public void visit(@NotNull final ArchetypeAttributeList2 archetypeAttribute) {
197  // XXX: missing
198  }
199 
200  @Override
201  public void visit(@NotNull final ArchetypeAttributeLong archetypeAttribute) {
202  // XXX: missing
203  }
204 
205  @Override
206  public void visit(@NotNull final ArchetypeAttributeMapPath archetypeAttribute) {
207  // XXX: missing
208  }
209 
210  @Override
211  public void visit(@NotNull final ArchetypeAttributeScriptFile archetypeAttribute) {
212  // XXX: missing
213  }
214 
215  @Override
216  public void visit(@NotNull final ArchetypeAttributeSpell archetypeAttribute) {
217  // XXX: missing
218  }
219 
220  @Override
221  public void visit(@NotNull final ArchetypeAttributeString archetypeAttribute) {
222  // XXX: missing
223  }
224 
225  @Override
226  public void visit(@NotNull final ArchetypeAttributeText archetypeAttribute) {
227  // XXX: missing
228  }
229 
230  @Override
231  public void visit(@NotNull final ArchetypeAttributeTreasure archetypeAttribute) {
232  // XXX: missing
233  }
234 
235  @Override
236  public void visit(@NotNull final ArchetypeAttributeZSpell archetypeAttribute) {
237  // XXX: missing
238  }
239 
240  };
241 
242  for (final ArchetypeAttributeSection archetypeAttributeSection : archetypeType) {
243  for (final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) {
244  archetypeAttribute.visit(archetypeAttributeVisitor);
245  }
246  }
247  }
248 
249 }
A validator that checks for suspicious attribute values.
An ArchetypeAttribute for selecting long integer values.
Manages ArchetypeType instances, list, and bitmask definitions.
This Class contains the data of one archetype attribute.
An ArchetypeAttribute for selecting an optional spell encoded as an integer attribute.
Contains the data of one Gridarta Object-Type.
An ArchetypeAttribute displaying a fixed string.
An ArchetypeAttribute for selecting boolean values having specific "true" and "false" values...
An ArchetypeAttribute for selecting map path names.
An ArchetypeAttribute for selecting string values.
An Exception indicating that an attribute check is invalid.
int getMaxValue()
Returns the maximum allowed bitmask value.
A GameObjectValidator that checks for valid environment.
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.
This class manages bitmask values which appear in Gridarta archetype attributes.
An ArchetypeAttribute for selecting bitmask values.
An ArchetypeAttribute for selecting spells encoded as in integer attribute.
An ArchetypeAttribute for selecting integer values.
An ArchetypeAttribute for selecting a value from two lists.
ArchetypeTypeChecks()
Private constructor to prevent instantiation.
An ArchetypeAttribute for selecting boolean values.
static final Category LOG
The logger for printing log messages.
An ArchetypeAttribute for selecting a value from a list.
An ArchetypeAttribute for selecting floating point values.
An ArchetypeAttribute for selecting text fields.
An ArchetypeAttribute for selecting a spell encoded as an inventory game object.
Defines types of GameObjects with corresponding attributes.