Commit d0531fdd authored by Chen Bill's avatar Chen Bill Committed by GitHub

Refactor card data handling for clarity and efficiency (#763)

parent 4bbece76
...@@ -456,9 +456,9 @@ uint32_t card::get_another_code() { ...@@ -456,9 +456,9 @@ uint32_t card::get_another_code() {
return 0; return 0;
} }
inline bool check_setcode(uint16_t setcode, uint32_t value) { inline bool check_setcode(uint16_t setcode, uint32_t value) {
uint32_t settype = value & 0x0fffU; const uint32_t settype = value & 0x0fffU;
uint32_t setsubtype = value & 0xf000U; const uint32_t setsubtype = value & 0xf000U;
return (setcode & 0x0fffU) == settype && (setcode & 0xf000U & setsubtype) == setsubtype; return (setcode & 0x0fffU) == settype && (setcode & setsubtype) == setsubtype;
} }
int32_t card::is_set_card(uint32_t set_code) { int32_t card::is_set_card(uint32_t set_code) {
uint32_t code1 = get_code(); uint32_t code1 = get_code();
......
#ifndef CARD_DATA_H_ #ifndef CARD_DATA_H_
#define CARD_DATA_H_ #define CARD_DATA_H_
#include <cstring>
#include <unordered_map> #include <unordered_map>
#include "common.h" #include "common.h"
...@@ -38,26 +39,14 @@ struct card_data { ...@@ -38,26 +39,14 @@ struct card_data {
uint32_t link_marker{}; uint32_t link_marker{};
void clear() { void clear() {
code = 0; std::memset(this, 0, sizeof(card_data));
alias = 0;
for (auto& x : setcode)
x = 0;
type = 0;
level = 0;
attribute = 0;
race = 0;
attack = 0;
defense = 0;
lscale = 0;
rscale = 0;
link_marker = 0;
} }
bool is_setcode(uint32_t value) const { bool is_setcode(uint32_t value) const {
uint16_t settype = value & 0x0fff; const uint16_t settype = value & 0x0fff;
uint16_t setsubtype = value & 0xf000; const uint16_t setsubtype = value & 0xf000;
for (auto& x : setcode) { for (auto& x : setcode) {
if ((x & 0x0fff) == settype && (x & 0xf000 & setsubtype) == setsubtype) if ((x & 0x0fff) == settype && (x & setsubtype) == setsubtype)
return true; return true;
if (!x) if (!x)
return false; return false;
...@@ -80,8 +69,8 @@ struct card_data { ...@@ -80,8 +69,8 @@ struct card_data {
} }
value >>= 16; value >>= 16;
} }
for (int i = ctr; i < SIZE_SETCODE; ++i) if (ctr < SIZE_SETCODE)
setcode[i] = 0; std::memset(setcode + ctr, 0, (SIZE_SETCODE - ctr) * sizeof(uint16_t));
} }
uint32_t get_original_code() const { uint32_t get_original_code() const {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment