Gridarta Editor
MultiArchData.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.gameobject;
21 
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
41 public class MultiArchData<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, T extends BaseObject<G, A, R, T>> implements Iterable<T>, Serializable {
42 
46  private static final long serialVersionUID = 1L;
47 
52  private int maxX;
53 
58  private int maxY;
59 
64  private int minX;
65 
70  private int minY;
71 
76  private int multiShapeID;
77 
83  @NotNull
84  private final List<T> parts = new ArrayList<>();
85 
91  public MultiArchData(@NotNull final T head, final int multiShapeID) {
92  this.multiShapeID = multiShapeID;
93  assert head.getArchetype().getMultiX() == 0 && head.getArchetype().getMultiY() == 0;
94  parts.add(head);
95  }
96 
101  public int getMultiRefCount() {
102  return parts.size();
103  }
104 
110  public int getSizeX() {
111  return maxX - minX + 1;
112  }
113 
119  public int getSizeY() {
120  return maxY - minY + 1;
121  }
122 
128  public int getMaxX() {
129  return maxX;
130  }
131 
137  public int getMaxY() {
138  return maxY;
139  }
140 
146  public int getMinX() {
147  return minX;
148  }
149 
155  public int getMinY() {
156  return minY;
157  }
158 
163  public int getMultiShapeID() {
164  return multiShapeID;
165  }
166 
171  public void setMultiShapeID(final int multiShapeID) {
172  this.multiShapeID = multiShapeID;
173  }
174 
179  @NotNull
180  public T getHead() {
181  return parts.get(0);
182  }
183 
190  @Nullable
191  public T getNext(@NotNull final T ob) {
192  final int index = parts.indexOf(ob);
193  assert index != -1;
194  return index + 1 < parts.size() ? parts.get(index + 1) : null;
195  }
196 
201  public void addPart(@NotNull final T tail) {
202  parts.add(tail);
203 
204  final int x = tail.getArchetype().getMultiX();
205  if (x < minX) {
206  minX = x;
207  } else if (x > maxX) {
208  maxX = x;
209  }
210 
211  final int y = tail.getArchetype().getMultiY();
212  if (y < minY) {
213  minY = y;
214  } else if (y > maxY) {
215  maxY = y;
216  }
217  }
218 
219  @Override
220  public Iterator<T> iterator() {
221  return parts.iterator();
222  }
223 
224 }
int maxY
The maximum coordinate of any part; it is never negative.
int multiShapeID
The shape ID of this object.
final List< T > parts
All parts belonging to this multi-part object; the first element is the head part.
int getSizeX()
Determine the horizontal extent in squares.
int getMaxX()
Determine the maximum x-coordinate of any part.
int getSizeY()
Determine the vertical extent in squares.
static final long serialVersionUID
The serial version UID.
int getMinX()
Determine the minimum x-coordinate of any part.
int maxX
The maximum coordinate of any part; it is never negative.
int getMultiShapeID()
Return the shape ID of this object.
Base package of all Gridarta classes.
int minX
The minimum coordinate of any part; it is never positive.
Reflects a game object (object on a map).
Definition: GameObject.java:36
MultiArchData(@NotNull final T head, final int multiShapeID)
Create a new instance.
T getNext(@NotNull final T ob)
Return the part following a given part.
T getHead()
Return the head part of this multi-part object.
void addPart(@NotNull final T tail)
Add a part to this multi-part object.
int getMaxY()
Determine the maximum y-coordinate of any part.
int minY
The minimum coordinate of any part; it is never positive.
int getMultiRefCount()
Returns the number of parts this multi-part object contains.
int getMinY()
Determine the minimum y-coordinate of any part.
void setMultiShapeID(final int multiShapeID)
Set the shape ID of this object.
Class related to GameObject to store multi-part information.