-
Notifications
You must be signed in to change notification settings - Fork 6
/
HexTile.cpp
164 lines (142 loc) · 3.61 KB
/
HexTile.cpp
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
/*
* Copyright 2009-2012 Scott McCreary
* Copyright 2013 Luke (noryb009)
* Copyright 2014 Puck Meerburg
* Based on BeVexed by DarkWyrm Copyright 2007-2009
*
* Distributed under terms of the MIT License.
*
*/
/*
example layout, 4 rows, 4 columns = 16 hexagon tiles
col0 col1 col2 col3
______ ______
/\ /\ /\ /\
/tl\ t/tr\ /tl\ t/tr\
row0 /____\/____\ ____ /____\/____\______
\ /\ /\ /\ /\ /\ /\
\bl/ b\br/tl\ t/tr\bl/ b\br/tl\ t/tr\
\/____\/____\/____\/____\/____\/____\
/\ /\ /\ /\ /\ /\ /
/tl\ t/tr\bl/ b\br/tl\ t/tr\bl/ b\br/
row1 /____\/____\/____\/____\/____\/____\/
\ /\ /\ /\ /\ /\ /\
\bl/ b\br/tl\ t/tr\bl/ b\br/tl\ t/tr\
\/____\/____\/____\/____\/____\/____\
\ /\ / \ /\ /
\bl/ b\br/ \bl/ b\br/
\/____\/ \/____\/
*/
#include "HexTile.h"
#include "HexGrid.h"
#include <OS.h>
#include <stdlib.h>
#include <stdio.h>
#include "HexTileView.h"
BArchivable *
HexTile::Instantiate(BMessage *from)
{
if(validate_instantiation(from, "HexTile"))
return new HexTile(from);
return NULL;
}
HexTile::HexTile(BMessage *from)
:
topleft(-1),
top(-1),
topright(-1),
bottomleft(-1),
bottom(-1),
bottomright(-1),
id(0),
toplefttile(NULL),
toptile(NULL),
toprighttile(NULL),
bottomlefttile(NULL),
bottomtile(NULL),
bottomrighttile(NULL)
{
SetValues(
from->GetInt8("HexTile::topleft", -1),
from->GetInt8("HexTile::top", -1),
from->GetInt8("HexTile::topright", -1),
from->GetInt8("HexTile::bottomleft", -1),
from->GetInt8("HexTile::bottom", -1),
from->GetInt8("HexTile::bottomright", -1));
id = from->GetUInt16("HexTile::id", 0);
gridid = from->GetUInt16("HexTile::gridid", 0);
}
status_t
HexTile::Archive(BMessage *into, bool deep)
{
status_t error;
error = BArchivable::Archive(into, deep);
if(error != B_OK)
return error;
into->AddInt8("HexTile::topleft", topleft);
into->AddInt8("HexTile::top", top);
into->AddInt8("HexTile::topright", topright);
into->AddInt8("HexTile::bottomleft", bottomleft);
into->AddInt8("HexTile::bottom", bottom);
into->AddInt8("HexTile::bottomright", bottomright);
into->AddUInt16("HexTile::id", id);
into->AddUInt16("HexTile::gridid", gridid);
return B_OK;
}
HexTile::HexTile(void)
: topleft(-1),
top(-1),
topright(-1),
bottomleft(-1),
bottom(-1),
bottomright(-1),
id(0),
gridid(0),
toplefttile(NULL),
toptile(NULL),
toprighttile(NULL),
bottomlefttile(NULL),
bottomtile(NULL),
bottomrighttile(NULL)
{
}
HexTile::HexTile(const uint8 &tl, const uint8 &t, const uint8 &tr,
const uint8 &bl, const uint8 &b, const uint8 &br)
{
SetValues(tl, t, tr, bl, b, br);
id = 0;
}
HexTile::HexTile(const HexTile &t)
: topleft(t.topleft),
top(t.top),
topright(t.topright),
bottomleft(t.bottomleft),
bottom(t.bottom),
bottomright(t.bottomright),
id(t.id),
gridid(t.id),
toplefttile(NULL),
toptile(NULL),
toprighttile(NULL),
bottomlefttile(NULL),
bottomtile(NULL),
bottomrighttile(NULL)
{
}
HexTile &HexTile::operator=(const HexTile &t)
{
SetValues(t.topleft,t.top,t.topright,t.bottomleft,t.bottom,t.bottomright);
id = t.id;
gridid = t.gridid;
return *this;
}
void HexTile::SetValues(const uint8 &tl, const uint8 &t, const uint8 &tr,
const uint8 &bl, const uint8 &b, const uint8 &br)
{
topleft = tl;
top = t;
topright = tr;
bottomleft = bl;
bottom = b;
bottomright = br;
}