-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.cpp
235 lines (202 loc) · 3.28 KB
/
box.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
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
227
228
229
230
231
232
233
234
235
#include "box.h"
Box::Box(unsigned short newType)
{
type = newType;
state = (unsigned short)0;
stateStartTime = GetTickCount64();
return;
}
Box::~Box(void)
{
return;
}
void Box::setType(unsigned short newType)
{
type = newType;
return;
}
unsigned short Box::getType(void)
{
return type;
}
void Box::setState(unsigned short newState)
{
state = newState;
return;
}
unsigned short Box::getState(void)
{
return state;
}
void Box::setStateStartTime(void)
{
stateStartTime = GetTickCount64();
}
ULONGLONG Box::getStateStartTime(void)
{
return stateStartTime;
}
unsigned char Box::getBase(void)
{
return (unsigned char)((type >> 12) & 0xF);
}
bool Box::isPlain(void)
{
return (type & 0xFFF) == 0;
}
bool Box::isUnknown(void)
{
return type & 1;
}
/* 判定水域中的非平坦已知方块是否可拾取 */
static bool canFetch_Water(unsigned short type)
{
switch (type) {
case WATER_ICE:
return false;
case WATER_WOOD_01:
return true;
default:
break;
}
return false;
}
/* 判定方块是否可拾取 */
bool Box::canFetch(void)
{
if (isPlain() || isUnknown()) {
return false;
}
switch (getBase()) {
case 0x0:
return canFetch_Water(type);
default:
break;
}
return false;
}
/* 根据所属的生态,获取平坦的图片 */
static cv::Mat getPlainMatByBase(unsigned char base)
{
switch (base) {
case 0x0: // 水域
return getWaterPlainMat();
case 0x1: // 深水域
case 0x2: // 森林
case 0x3: // 深森林
case 0x4: // 沙漠
case 0x5: // 深沙漠
default:
return getDefaultMat();
}
}
static cv::Mat getUnknownMatByBase(unsigned int base)
{
switch (base) {
case 0x0: // 水域
return getWaterUnknownMat();
case 0x1: // 深水域
case 0x2: // 森林
case 0x3: // 深森林
case 0x4: // 沙漠
case 0x5: // 深沙漠
default:
return getDefaultMat();
}
}
static cv::Mat getWaterMat(unsigned short type)
{
switch (type) {
case WATER_ICE:
return getWaterIceMat();
case WATER_WOOD_01:
return getWaterWood01Mat();
default:
break;
}
return getDefaultMat();
}
static cv::Mat getDeepWaterMat(unsigned short type)
{
switch (type) {
default:
break;
}
return getDefaultMat();
}
static cv::Mat getForestMat(unsigned short type)
{
switch (type) {
default:
break;
}
return getDefaultMat();
}
static cv::Mat getDeepForestMat(unsigned short type)
{
switch (type) {
default:
break;
}
return getDefaultMat();
}
static cv::Mat getDesertMat(unsigned short type)
{
switch (type) {
default:
break;
}
return getDefaultMat();
}
static cv::Mat getDeepDesertMat(unsigned short type)
{
switch (type) {
default:
break;
}
return getDefaultMat();
}
cv::Mat Box::getMat(void)
{
unsigned char base = getBase();
// 平坦方块
if (isPlain()) {
return getPlainMatByBase(base);
}
// 未知方块
if (isUnknown()) {
return getUnknownMatByBase(base);
}
// 已知的非平坦方块
switch (base) {
case 0x0: // 水域
return getWaterMat(type);
case 0x1: // 深水域
return getDeepWaterMat(type);
case 0x2: // 森林
return getForestMat(type);
case 0x3: // 深森林
return getDeepForestMat(type);
case 0x4: // 沙漠
return getDesertMat(type);
case 0x5: // 深沙漠
return getDeepDesertMat(type);
default:
break;
}
return getDefaultMat();
}
/* 挖掘未知方块,使其变成已知 */
void Box::dig(void)
{
if (isUnknown()) {
type++;
}
return;
}
/* 将方块属性设置为平坦 */
void Box::setPlain(void)
{
type &= 0xF000;
return;
}