eliminate using namespace
This commit is contained in:
+30
-32
@@ -6,11 +6,9 @@
|
||||
#include "ItemParameterTable.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_DC_NTE({10});
|
||||
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V1_V2({10, 10, 1, 10, 10, 10, 10, 10, 10, 1});
|
||||
const vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V3_V4(
|
||||
const std::vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_DC_NTE({10});
|
||||
const std::vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V1_V2({10, 10, 1, 10, 10, 10, 10, 10, 10, 1});
|
||||
const std::vector<uint8_t> ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V3_V4(
|
||||
{10, 10, 1, 10, 10, 10, 10, 10, 10, 1, 1, 1, 1, 1, 1, 1, 99, 1});
|
||||
|
||||
const ItemData::StackLimits ItemData::StackLimits::DEFAULT_STACK_LIMITS_DC_NTE(
|
||||
@@ -21,7 +19,7 @@ const ItemData::StackLimits ItemData::StackLimits::DEFAULT_STACK_LIMITS_V3_V4(
|
||||
Version::GC_V3, ItemData::StackLimits::DEFAULT_TOOL_LIMITS_V3_V4, 999999);
|
||||
|
||||
ItemData::StackLimits::StackLimits(
|
||||
Version version, const vector<uint8_t>& max_tool_stack_sizes_by_data1_1, uint32_t max_meseta_stack_size)
|
||||
Version version, const std::vector<uint8_t>& max_tool_stack_sizes_by_data1_1, uint32_t max_meseta_stack_size)
|
||||
: version(version),
|
||||
max_tool_stack_sizes_by_data1_1(max_tool_stack_sizes_by_data1_1),
|
||||
max_meseta_stack_size(max_meseta_stack_size) {}
|
||||
@@ -40,7 +38,7 @@ uint8_t ItemData::StackLimits::get(uint8_t data1_0, uint8_t data1_1) const {
|
||||
}
|
||||
if (data1_0 == 3) {
|
||||
const auto& vec = this->max_tool_stack_sizes_by_data1_1;
|
||||
return vec.at(min<size_t>(data1_1, vec.size() - 1));
|
||||
return vec.at(std::min<size_t>(data1_1, vec.size() - 1));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -181,7 +179,7 @@ bool ItemData::is_wrapped(const StackLimits& limits) const {
|
||||
case 4:
|
||||
return false;
|
||||
default:
|
||||
throw runtime_error("invalid item data");
|
||||
throw std::runtime_error("invalid item data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +204,7 @@ void ItemData::wrap(const StackLimits& limits, uint8_t present_color) {
|
||||
case 4:
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid item data");
|
||||
throw std::runtime_error("invalid item data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +225,7 @@ void ItemData::unwrap(const StackLimits& limits) {
|
||||
case 4:
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid item data");
|
||||
throw std::runtime_error("invalid item data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +307,7 @@ uint16_t ItemData::compute_mag_strength_flags() const {
|
||||
ret |= 0x020;
|
||||
}
|
||||
|
||||
uint16_t highest = max<uint16_t>(dex, max<uint16_t>(pow, mind));
|
||||
uint16_t highest = std::max<uint16_t>(dex, std::max<uint16_t>(pow, mind));
|
||||
if ((pow == highest) + (dex == highest) + (mind == highest) > 1) {
|
||||
ret |= 0x100;
|
||||
}
|
||||
@@ -343,10 +341,10 @@ uint8_t ItemData::mag_photon_blast_for_slot(uint8_t slot) const {
|
||||
left_pb_num--;
|
||||
}
|
||||
}
|
||||
throw logic_error("failed to find unused photon blast number");
|
||||
throw std::logic_error("failed to find unused photon blast number");
|
||||
|
||||
} else {
|
||||
throw logic_error("invalid slot index");
|
||||
throw std::logic_error("invalid slot index");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,7 +385,7 @@ void ItemData::add_mag_photon_blast(uint8_t pb_num) {
|
||||
pb_num--;
|
||||
}
|
||||
if (pb_num >= 4) {
|
||||
throw runtime_error("left photon blast number is too high");
|
||||
throw std::runtime_error("left photon blast number is too high");
|
||||
}
|
||||
pb_nums |= (pb_num << 6);
|
||||
flags |= 4;
|
||||
@@ -471,11 +469,11 @@ void ItemData::decode_for_version(Version from_version) {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw runtime_error("invalid item class");
|
||||
throw std::runtime_error("invalid item class");
|
||||
}
|
||||
}
|
||||
|
||||
void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParameterTable> item_parameter_table) {
|
||||
void ItemData::encode_for_version(Version to_version, std::shared_ptr<const ItemParameterTable> item_parameter_table) {
|
||||
bool should_encode_v2_data = item_parameter_table &&
|
||||
(is_v1(to_version) || is_v2(to_version)) &&
|
||||
(to_version != Version::GC_NTE) &&
|
||||
@@ -501,7 +499,7 @@ void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParam
|
||||
break;
|
||||
|
||||
case 0x01: {
|
||||
static const array<uint8_t, 4> armor_limits = {0x00, 0x29, 0x27, 0x44};
|
||||
static const std::array<uint8_t, 4> armor_limits = {0x00, 0x29, 0x27, 0x44};
|
||||
if (should_encode_v2_data && (this->data1[2] >= armor_limits[this->data1[1]])) {
|
||||
this->data1[3] = this->data1[2];
|
||||
this->data1[2] = 0x00;
|
||||
@@ -554,7 +552,7 @@ void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParam
|
||||
break;
|
||||
|
||||
default:
|
||||
throw runtime_error("invalid item class");
|
||||
throw std::runtime_error("invalid item class");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,7 +656,7 @@ bool ItemData::has_bonuses() const {
|
||||
case 3:
|
||||
return (this->get_unit_bonus() > 0);
|
||||
default:
|
||||
throw runtime_error("invalid item");
|
||||
throw std::runtime_error("invalid item");
|
||||
}
|
||||
case 2:
|
||||
if (this->data1[1] < 0x23) {
|
||||
@@ -670,7 +668,7 @@ bool ItemData::has_bonuses() const {
|
||||
case 4:
|
||||
return false;
|
||||
default:
|
||||
throw runtime_error("invalid item");
|
||||
throw std::runtime_error("invalid item");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -703,7 +701,7 @@ EquipSlot ItemData::default_equip_slot() const {
|
||||
case 0x02:
|
||||
return EquipSlot::MAG;
|
||||
}
|
||||
throw runtime_error("item cannot be equipped");
|
||||
throw std::runtime_error("item cannot be equipped");
|
||||
}
|
||||
|
||||
bool ItemData::can_be_equipped_in_slot(EquipSlot slot) const {
|
||||
@@ -722,7 +720,7 @@ bool ItemData::can_be_equipped_in_slot(EquipSlot slot) const {
|
||||
case EquipSlot::WEAPON:
|
||||
return (this->data1[0] == 0x00);
|
||||
default:
|
||||
throw runtime_error("invalid equip slot");
|
||||
throw std::runtime_error("invalid equip slot");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -748,23 +746,23 @@ bool ItemData::compare_for_sort(const ItemData& a, const ItemData& b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemData ItemData::from_data(const string& data) {
|
||||
ItemData ItemData::from_data(const std::string& data) {
|
||||
if (data.size() < 2) {
|
||||
throw runtime_error("data is too short");
|
||||
throw std::runtime_error("data is too short");
|
||||
}
|
||||
if (data.size() > 0x10) {
|
||||
throw runtime_error("data is too long");
|
||||
throw std::runtime_error("data is too long");
|
||||
}
|
||||
|
||||
ItemData ret;
|
||||
for (size_t z = 0; z < min<size_t>(data.size(), 12); z++) {
|
||||
for (size_t z = 0; z < std::min<size_t>(data.size(), 12); z++) {
|
||||
ret.data1[z] = data[z];
|
||||
}
|
||||
for (size_t z = 12; z < min<size_t>(data.size(), 16); z++) {
|
||||
for (size_t z = 12; z < std::min<size_t>(data.size(), 16); z++) {
|
||||
ret.data2[z - 12] = data[z];
|
||||
}
|
||||
if (ret.data1[0] > 4) {
|
||||
throw runtime_error("invalid item class");
|
||||
throw std::runtime_error("invalid item class");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -772,7 +770,7 @@ ItemData ItemData::from_data(const string& data) {
|
||||
ItemData ItemData::from_primary_identifier(const StackLimits& limits, uint32_t primary_identifier) {
|
||||
ItemData ret;
|
||||
if (primary_identifier > 0x04000000) {
|
||||
throw runtime_error("invalid item class");
|
||||
throw std::runtime_error("invalid item class");
|
||||
}
|
||||
ret.data1[0] = (primary_identifier >> 24) & 0xFF;
|
||||
ret.data1[1] = (primary_identifier >> 16) & 0xFF;
|
||||
@@ -786,16 +784,16 @@ ItemData ItemData::from_primary_identifier(const StackLimits& limits, uint32_t p
|
||||
return ret;
|
||||
}
|
||||
|
||||
string ItemData::hex() const {
|
||||
std::string ItemData::hex() const {
|
||||
return std::format("{:08X} {:08X} {:08X} ({:08X}) {:08X}",
|
||||
this->data1db[0], this->data1db[1], this->data1db[2], this->id, this->data2db);
|
||||
}
|
||||
|
||||
string ItemData::short_hex() const {
|
||||
std::string ItemData::short_hex() const {
|
||||
auto ret = std::format("{:08X}{:08X}{:08X}{:08X}",
|
||||
this->data1db[0], this->data1db[1], this->data1db[2], this->data2db);
|
||||
size_t offset = ret.find_last_not_of('0');
|
||||
if (offset != string::npos) {
|
||||
if (offset != std::string::npos) {
|
||||
offset += (offset & 1) ? 1 : 2;
|
||||
offset = std::max<size_t>(offset, 6);
|
||||
if (offset < ret.size()) {
|
||||
|
||||
Reference in New Issue
Block a user