forked from Fluorohydride/ygopro-core
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcard_data.h
More file actions
87 lines (75 loc) · 2.07 KB
/
card_data.h
File metadata and controls
87 lines (75 loc) · 2.07 KB
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
#ifndef CARD_DATA_H_
#define CARD_DATA_H_
#include <cstring>
#include <unordered_map>
#include "common.h"
constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20;
constexpr int SIZE_SETCODE = 16;
constexpr uint32_t CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
//double name
constexpr uint32_t CARD_MARINE_DOLPHIN = 78734254;
constexpr uint32_t CARD_TWINKLE_MOSS = 13857930;
constexpr uint32_t CARD_TIMAEUS = 1784686;
constexpr uint32_t CARD_CRITIAS = 11082056;
constexpr uint32_t CARD_HERMOS = 46232525;
const std::unordered_map<uint32_t, uint32_t> second_code = {
{CARD_MARINE_DOLPHIN, 17955766u},
{CARD_TWINKLE_MOSS, 17732278u},
{CARD_TIMAEUS, 10000050u},
{CARD_CRITIAS, 10000060u},
{CARD_HERMOS, 10000070u},
};
inline bool check_setcode(uint16_t setcode, uint32_t value) {
const uint32_t settype = value & 0x0fffU;
const uint32_t setsubtype = value & 0xf000U;
return setcode && (setcode & 0x0fffU) == settype && (setcode & setsubtype) == setsubtype;
}
inline void write_setcode(uint16_t list[], uint64_t value) {
if (!list)
return;
int len = 0;
while (value) {
if (value & 0xffff) {
list[len] = value & 0xffff;
++len;
}
value >>= 16;
}
if (len < SIZE_SETCODE)
std::memset(list + len, 0, (SIZE_SETCODE - len) * sizeof(uint16_t));
}
inline bool is_alternative(uint32_t code, uint32_t alias) {
if (code == CARD_BLACK_LUSTER_SOLDIER2)
return false;
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
}
struct card_data {
uint32_t code{};
uint32_t alias{};
uint16_t setcode[SIZE_SETCODE]{};
uint32_t type{};
uint32_t level{};
uint32_t attribute{};
uint32_t race{};
int32_t attack{};
int32_t defense{};
uint32_t lscale{};
uint32_t rscale{};
uint32_t link_marker{};
void clear() {
std::memset(this, 0, sizeof(card_data));
}
bool is_setcode(uint32_t value) const {
for (auto& x : setcode) {
if (!x)
return false;
if (check_setcode(x, value))
return true;
}
return false;
}
uint32_t get_original_code() const {
return is_alternative(code, alias) ? alias : code;
}
};
#endif /* CARD_DATA_H_ */