-
Notifications
You must be signed in to change notification settings - Fork 0
/
HGBCellPack.java
226 lines (195 loc) · 6.26 KB
/
HGBCellPack.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package hgb;
import java.util.Arrays;
//This class is created and stored in HGBShared.cellAry with index as the key.
//This class stores data about hexagon cells.
// Each Cell has it's data stored in its personal instance of HGBCellPack.
// HGBShared.cellAry stores each instance of HGBCellPack
// HGBCellPack is access through cellAry via an index
// (Note that cellAry contains null members)
public class HGBCellPack
{
protected HGBCellPack()
{
bondAry = new int[HGBShared.SIDES];
hgbShared = null;
}
protected HGBCellPack(int index, HGBShared hgbShared)
{
this.index = index;
this.hgbShared = hgbShared;
origin = new float[2]; // the origin of the cell is not stored
offset = new float[2]; // rather, the origin is calculated via offset
bondAry = new int[HGBShared.SIDES];
// This -1 fill IS NEEDED and DEPENDED upon elsewhere.
Arrays.fill(bondAry, 0, HGBShared.SIDES, -1);
}
private HGBShared hgbShared = null;
// ------------------------------------------------------------------------------
// The cells index. An index into HGBShared.cellAry
private int index = -1;
protected int getIndex()
{
return index;
}
// protected void setIndex(int index) { this.index = index; }
// ------------------------------------------------------------------------------
// An array of hexagon indices of the adjacent hexagon on
// the current hexagons side by the index into the array.
protected int[] bondAry = null;
protected int[] getBondAry()
{
return bondAry;
}
// Public access protects the pointer into bondAry by
// coping into a new array.
public int[] getBondings()
{
//int[] rtnAry = new int[bondAry.length];
int[] rtnAry = Arrays.copyOf(bondAry, bondAry.length);
return rtnAry;
}
/**
* Returns the cell index of the cell the side is bound with
* NoteOnAndroidStudio that if bound to an edge, -1 will be returned.
* @param side
* @return returns a bound cell index or -1 on error
*/
public int getBondToSide(int side)
{
if ((side >= 0) && (side < bondAry.length)) return bondAry[side];
return -1;
}
// ------------------------------------------------------------------------------
// This class does not store the origin of each cell. Rather it holds
// an offset from the hive origin to its initial origin, and uses that
// to compute the the current origin as related to the hive origin,
// with each call to getOrigin(). The offset from the initial origin
// is computed from the hive origin in HGBGenerateHive.calculateRoseOrigins()
// and originRosePetals(). Throughout any game, the offset from each cell
// to the hive origin remains constant. Thus, as the hive is translated,
// only the hive origin is updated. The offset is corrected when the hive
// is regenerated due a new game, the number of cells in the hive changed,
// or to size of cells being changed. Each of which will call
// HGBGenerateHive.generateHive_Main()
private float[] origin;
private float[] hiveOrigin;
private float[] offset;
public float[] getOrigin()
{
hiveOrigin = hgbShared.getHiveOrigin();
origin[0] = hiveOrigin[0] - offset[0];
origin[1] = hiveOrigin[1] - offset[1];
return origin;
}
protected void setOffsetFromHiveOrigin(float[] offset)
{
this.offset[0] = offset[0];
this.offset[1] = offset[1];
}
// ------------------------------------------------------------------------------
// CodeProject note: I think the following is debug stuff
// at any rate the code is not used. So commented out.
// The vertices used as the origin of vectors used to locate adjacent roses.
// Only roses contain an allocated vectorOriginVertex array. (see
// Progressions.vectorOriginVertex())
// protected int[] vectorOriginVertex = null;
// The rose the vector vertex points to
// Only roses contain an allocated vectorVertices array. (see
// Progressions.vectorVertices())
// protected int[] vectorToRose = null;
// protected String ToString()
// {
// String str = "Index [" + index + "]\n";
// // ------------------------------------------------
// if (bondAry != null)
// {
// str += "bondAry [";
// str += bondAry[0] + ", ";
// str += bondAry[1] + ", ";
// str += bondAry[2] + ", ";
// str += bondAry[3] + ", ";
// str += bondAry[4] + ", ";
// str += bondAry[5] + "]\n";
// }
// else
// {
// str += "boundAry [null]\n";
// }
// // ------------------------------------------------
// if (origin != null)
// {
// str += "orgin [";
// str += this.getOrigin()[0] + ", ";
// str += this.getOrigin()[1] + "]\n";
// }
// else
// {
// str += "origin [null]\n";
// }
// // ------------------------------------------------
// if (offset != null)
// {
// str += "offSet [";
// str += this.offset[0] + ", ";
// str += this.offset[1] + "]\n";
// }
// else
// {
// str += "offset [null]\n";
// }
// // ------------------------------------------------
// // -- the follow TWO conditions are identical
// // except for the variable -- could be a function
// // if (vectorOriginVertex != null)
// // {
// // str += writeArray("vectorOriginVertex", vectorOriginVertex);
// // }
// // ------------------------------------------------
// // if (vectorToRose != null)
// // {
// // str += writeArray("vectorToRose", vectorToRose);
// // }
// // ------------------------------------------------
// return str;
// }
// // private String writeArray(String str, int[] ary)
// // {
// // str += " [";
// // for (int inx = 0; inx < ary.length; inx++)
// // {
// // if (ary.length == 2)
// // {
// // switch (inx)
// // {
// // case 0:
// // str += ary[inx] + ", ";
// // break;
// //
// // case 1:
// // str += ary[inx];
// // break;
// // }
// // }
// // else if (ary.length == 3)
// // {
// // switch (inx)
// // {
// // case 0:
// // case 1:
// // str += ary[inx] + ", ";
// // break;
// //
// // case 2:
// // str += ary[inx];
// // break;
// // }
// // }
// // else
// // {
// // str += ary[inx] + ", ";
// // }
// // }
// // str += "]\n";
// // return str;
// // }
}