the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include "Pos.h"
4
5
6
7Pos::Pos()
8{
9 x = y = z = 0;
10}
11
12Pos::Pos(int x, int y, int z)
13{
14 this->x = x;
15 this->y = y;
16 this->z = z;
17}
18
19Pos::Pos(Pos *position)
20{
21 x = position->x;
22 y = position->y;
23 z = position->z;
24}
25
26//@Override
27//public boolean equals(Object other)
28bool Pos::equals(void *other)
29{
30 // TODO 4J Stu I cannot do a dynamic_cast from a void pointer
31 // If I cast it to a Pos then do a dynamic_cast will it still return NULL if it wasn't originally a Pos?
32 if (!( dynamic_cast<Pos *>( (Pos *)other ) != NULL ))
33 {
34 return false;
35 }
36
37 Pos *p = (Pos *) other;
38 return x == p->x && y == p->y && z == p->z;
39}
40
41//@Override
42int Pos::hashCode()
43{
44 return x + (z << 8) + (y << 16);
45}
46
47int Pos::compareTo(Pos *pos)
48{
49 if (y == pos->y)
50 {
51 if (z == pos->z)
52 {
53 return x - pos->x;
54 }
55 return z - pos->z;
56 }
57 return y - pos->y;
58}
59
60Pos *Pos::offset(int x, int y, int z)
61{
62 return new Pos(this->x + x, this->y + y, this->z + z);
63}
64
65void Pos::set(int x, int y, int z)
66{
67 this->x = x;
68 this->y = y;
69 this->z = z;
70}
71
72void Pos::set(Pos *pos)
73{
74 x = pos->x;
75 y = pos->y;
76 z = pos->z;
77}
78
79Pos *Pos::above()
80{
81 return new Pos(x, y + 1, z);
82}
83
84Pos *Pos::above(int steps)
85{
86 return new Pos(x, y + steps, z);
87}
88
89Pos *Pos::below()
90{
91 return new Pos(x, y - 1, z);
92}
93
94Pos *Pos::below(int steps)
95{
96 return new Pos(x, y - steps, z);
97}
98
99Pos *Pos::north()
100{
101 return new Pos(x, y, z - 1);
102}
103
104Pos *Pos::north(int steps)
105{
106 return new Pos(x, y, z - steps);
107}
108
109Pos *Pos::south()
110{
111 return new Pos(x, y, z + 1);
112}
113
114Pos *Pos::south(int steps)
115{
116 return new Pos(x, y, z + steps);
117}
118
119Pos *Pos::west()
120{
121 return new Pos(x - 1, y, z);
122}
123
124Pos *Pos::west(int steps)
125{
126 return new Pos(x - 1, y, z);
127}
128
129Pos *Pos::east()
130{
131 return new Pos(x + 1, y, z);
132}
133
134Pos *Pos::east(int steps)
135{
136 return new Pos(x + steps, y, z);
137}
138
139void Pos::move(int x, int y, int z)
140{
141 this->x += x;
142 this->y += y;
143 this->z += z;
144}
145
146void Pos::move(Pos pos)
147{
148 x += pos.x;
149 y += pos.y;
150 z += pos.z;
151}
152
153void Pos::moveX(int steps)
154{
155 x += steps;
156}
157
158void Pos::moveY(int steps)
159{
160 y += steps;
161}
162
163void Pos::moveZ(int steps)
164{
165 z += steps;
166}
167
168void Pos::moveUp(int steps)
169{
170 y += steps;
171}
172
173void Pos::moveUp()
174{
175 y++;
176}
177
178void Pos::moveDown(int steps)
179{
180 y -= steps;
181}
182
183void Pos::moveDown()
184{
185 y--;
186}
187
188void Pos::moveEast(int steps)
189{
190 x += steps;
191}
192
193void Pos::moveEast()
194{
195 x++;
196}
197
198void Pos::moveWest(int steps)
199{
200 x -= steps;
201}
202
203void Pos::moveWest()
204{
205 x--;
206}
207
208void Pos::moveNorth(int steps)
209{
210 z -= steps;
211}
212
213void Pos::moveNorth()
214{
215 z--;
216}
217
218void Pos::moveSouth(int steps)
219{
220 z += steps;
221}
222
223void Pos::moveSouth()
224{
225 z++;
226}
227
228double Pos::dist(int x, int y, int z)
229{
230 double dx = this->x - x;
231 double dy = this->y - y;
232 double dz = this->z - z;
233
234 return sqrt( dx * dx + dy * dy + dz * dz);
235}
236
237double Pos::dist(Pos *pos)
238{
239 return dist(pos->x, pos->y, pos->z);
240}
241
242float Pos::distSqr(int x, int y, int z)
243{
244 float dx = this->x - x;
245 float dy = this->y - y;
246 float dz = this->z - z;
247 return dx * dx + dy * dy + dz * dz;
248}
249
250float Pos::distSqr(Pos *pos)
251{
252 return distSqr(pos->x, pos->y, pos->z);
253}