1
2 /* Battle Tanks Game
3 * Copyright (C) 2006-2009 Battle Tanks team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 /*
21 * Additional rights can be granted beyond the GNU General Public License
22 * on the terms provided in the Exception. If you modify this file,
23 * you may extend this exception to your version of the file,
24 * but you are not obligated to do so. If you do not wish to provide this
25 * exception without modification, you must delete this exception statement
26 * from your version and license this file solely under the GPL without exception.
27 */
28 #include "zbox.h"
29 #include "math/unary.h"
30 #include <assert.h>
31
ZBox(const v3<int> & position,const v2<int> & size)32 ZBox::ZBox(const v3<int> &position, const v2<int> &size) : position(position), size(size) {}
33
operator <(const ZBox & other) const34 const bool ZBox::operator<(const ZBox &other) const {
35 if (position != other.position)
36 return position < other.position;
37 if (size != other.size)
38 return size < other.size;
39 return false;
40 }
41
in(const v3<int> & p,const bool ignore_z) const42 const bool ZBox::in(const v3<int> &p, const bool ignore_z) const {
43 if (!ignore_z && getBox(position.z) != getBox(p.z))
44 return false;
45 return (
46 p.x >= position.x && p.y >= position.y &&
47 p.x < position.x + size.x && p.y < position.y + size.y
48 );
49 }
50
sameBox(const int z1,const int z2)51 const bool ZBox::sameBox(const int z1, const int z2) {
52 return getBox(z1) == getBox(z2);
53 }
54
getBox(const int z)55 const int ZBox::getBox(const int z) {
56 return ((z < 0?z + 1:z) / 1000 + math::sign(z) ) / 2;
57 }
58
getBoxBase(const int z)59 const int ZBox::getBoxBase(const int z) {
60 return getBox(z) * 2000;
61 }
62