eliminate using namespace

This commit is contained in:
Martin Michelsen
2026-05-25 16:38:31 -07:00
parent 4503d09c77
commit e9c2ac34a3
98 changed files with 6022 additions and 6531 deletions
+51 -52
View File
@@ -1,7 +1,5 @@
#include "QuestMetadata.hh"
using namespace std;
phosg::JSON QuestMetadata::FloorAssignment::json() const {
return phosg::JSON::dict({
{"Floor", this->floor},
@@ -21,51 +19,51 @@ std::string QuestMetadata::FloorAssignment::str() const {
void QuestMetadata::apply_json_overrides(const phosg::JSON& json) {
try {
this->description_flag = json.at("DescriptionFlag").as_int();
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->available_expression = make_shared<IntegralExpression>(json.get_string("AvailableIf"));
} catch (const out_of_range&) {
this->available_expression = std::make_shared<IntegralExpression>(json.get_string("AvailableIf"));
} catch (const std::out_of_range&) {
}
try {
this->enabled_expression = make_shared<IntegralExpression>(json.get_string("EnabledIf"));
} catch (const out_of_range&) {
this->enabled_expression = std::make_shared<IntegralExpression>(json.get_string("EnabledIf"));
} catch (const std::out_of_range&) {
}
try {
this->allow_start_from_chat_command = json.get_bool("AllowStartFromChatCommand");
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->joinable = json.get_bool("Joinable");
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->lock_status_register = json.get_int("LockStatusRegister");
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->enemy_exp_overrides = QuestMetadata::parse_enemy_exp_overrides(json.at("EnemyEXPOverrides"));
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->common_item_set_name = json.at("CommonItemSetName").as_string();
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->rare_item_set_name = json.at("RareItemSetName").as_string();
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->allowed_drop_modes = json.at("AllowedDropModes").as_int();
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->default_drop_mode = phosg::enum_for_name<ServerDropMode>(json.at("DefaultDropMode").as_string());
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
try {
this->enable_schtserv_commands = json.at("EnableSchtservCommands").as_bool();
} catch (const out_of_range&) {
} catch (const std::out_of_range&) {
}
}
@@ -82,51 +80,51 @@ void QuestMetadata::assign_default_floors() {
void QuestMetadata::assert_compatible(const QuestMetadata& other) const {
if (this->quest_number != other.quest_number) {
throw logic_error(std::format(
throw std::logic_error(std::format(
"incorrect versioned quest number (existing: {:08X}, new: {:08X})", this->quest_number, other.quest_number));
}
if (this->category_id != other.category_id) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version is in a different category (existing: {:08X}, new: {:08X})",
this->category_id, other.category_id));
}
if (this->episode != other.episode) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version is in a different episode (existing: {}, new: {})",
name_for_episode(this->episode), name_for_episode(other.episode)));
}
if (this->allow_start_from_chat_command != other.allow_start_from_chat_command) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has a different allow_start_from_chat_command state (existing: {}, new: {})",
this->allow_start_from_chat_command ? "true" : "false",
other.allow_start_from_chat_command ? "true" : "false"));
}
if (this->joinable != other.joinable) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has a different joinability state (existing: {}, new: {})",
this->joinable ? "true" : "false", other.joinable ? "true" : "false"));
}
bool this_has_player_limit = (this->max_players != 0) && (this->max_players != 4);
bool other_has_player_limit = (other.max_players != 0) && (other.max_players != 4);
if ((this_has_player_limit || other_has_player_limit) && (this->max_players != other.max_players)) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has a different maximum player count (existing: {}, new: {})",
this->max_players, other.max_players));
}
if (this->lock_status_register != other.lock_status_register) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has a different lock status register (existing: {:04X}, new: {:04X})",
this->lock_status_register, other.lock_status_register));
}
if (this->enemy_exp_overrides != other.enemy_exp_overrides) {
throw runtime_error("quest version has different enemy EXP overrides");
throw std::runtime_error("quest version has different enemy EXP overrides");
}
if (this->solo_unlock_flags != other.solo_unlock_flags) {
throw runtime_error(std::format("quest version has a different set of solo unlock flags"));
throw std::runtime_error(std::format("quest version has a different set of solo unlock flags"));
}
if (!this->create_item_mask_entries.empty() && !other.create_item_mask_entries.empty() &&
this->create_item_mask_entries != other.create_item_mask_entries) {
string this_str, other_str;
std::string this_str, other_str;
for (const auto& item : this->create_item_mask_entries) {
if (!this_str.empty()) {
this_str += ", ";
@@ -139,32 +137,32 @@ void QuestMetadata::assert_compatible(const QuestMetadata& other) const {
}
other_str += item.str();
}
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has a different set of create item masks (existing: {}, new: {})", this_str, other_str));
}
if (!this->battle_rules != !other.battle_rules) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has a different battle rules presence state (existing: {}, new: {})",
this->battle_rules ? "present" : "absent", other.battle_rules ? "present" : "absent"));
}
if (this->battle_rules && (*this->battle_rules != *other.battle_rules)) {
string existing_str = this->battle_rules->json().serialize();
string new_str = other.battle_rules->json().serialize();
throw runtime_error(std::format(
std::string existing_str = this->battle_rules->json().serialize();
std::string new_str = other.battle_rules->json().serialize();
throw std::runtime_error(std::format(
"quest version has different battle rules (existing: {}, new: {})", existing_str, new_str));
}
if (this->challenge_template_index != other.challenge_template_index) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has different challenge template index (existing: {}, new: {})",
this->challenge_template_index, other.challenge_template_index));
}
if (this->challenge_exp_multiplier != other.challenge_exp_multiplier) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has different challenge EXP multiplier (existing: {}, new: {})",
this->challenge_exp_multiplier, other.challenge_exp_multiplier));
}
if (this->challenge_difficulty != other.challenge_difficulty) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has different challenge difficulty (existing: {}, new: {})",
name_for_difficulty(this->challenge_difficulty), name_for_difficulty(other.challenge_difficulty)));
}
@@ -172,58 +170,59 @@ void QuestMetadata::assert_compatible(const QuestMetadata& other) const {
const auto& this_fa = this->floor_assignments[z];
const auto& other_fa = other.floor_assignments[z];
if (this_fa.area != other_fa.area) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has different area on floor 0x{:02X} (existing: {}, new: {})",
z, this_fa.str(), other_fa.str()));
}
}
if (this->description_flag != other.description_flag) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has different description flag (existing: {:02X}, new: {:02X})",
this->description_flag, other.description_flag));
}
if (!this->available_expression != !other.available_expression) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has available expression but root quest does not, or vice versa (existing: {}, new: {})",
this->available_expression ? "present" : "absent", other.available_expression ? "present" : "absent"));
}
if (this->available_expression && *this->available_expression != *other.available_expression) {
string existing_str = this->available_expression->str();
string new_str = other.available_expression->str();
throw runtime_error(std::format(
std::string existing_str = this->available_expression->str();
std::string new_str = other.available_expression->str();
throw std::runtime_error(std::format(
"quest version has a different available expression (existing: {}, new: {})", existing_str, new_str));
}
if (!this->enabled_expression != !other.enabled_expression) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has enabled expression but root quest does not, or vice versa (existing: {}, new: {})",
this->enabled_expression ? "present" : "absent", other.enabled_expression ? "present" : "absent"));
}
if (this->enabled_expression && *this->enabled_expression != *other.enabled_expression) {
string existing_str = this->enabled_expression->str();
string new_str = other.enabled_expression->str();
throw runtime_error(std::format(
std::string existing_str = this->enabled_expression->str();
std::string new_str = other.enabled_expression->str();
throw std::runtime_error(std::format(
"quest version has a different enabled expression (existing: {}, new: {})", existing_str, new_str));
}
if (this->common_item_set_name != other.common_item_set_name) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has different common table name (existing: {}, new: {})",
this->common_item_set_name, other.common_item_set_name));
}
if (this->rare_item_set_name != other.rare_item_set_name) {
throw runtime_error(std::format(
throw std::runtime_error(std::format(
"quest version has different rare table name (existing: {}, new: {})",
this->rare_item_set_name, other.rare_item_set_name));
}
if (this->allowed_drop_modes != other.allowed_drop_modes) {
throw runtime_error(format("quest version has different allowed drop modes (existing: {:02X}, new: {:02X})",
throw std::runtime_error(std::format(
"quest version has different allowed drop modes (existing: {:02X}, new: {:02X})",
this->allowed_drop_modes, other.allowed_drop_modes));
}
if (this->default_drop_mode != other.default_drop_mode) {
throw runtime_error(format("quest version has different default drop mode (existing: {}, new: {})",
throw std::runtime_error(std::format("quest version has different default drop mode (existing: {}, new: {})",
phosg::name_for_enum(this->default_drop_mode), phosg::name_for_enum(other.default_drop_mode)));
}
if (this->enable_schtserv_commands != other.enable_schtserv_commands) {
throw runtime_error(format(
throw std::runtime_error(std::format(
"quest version has different value for enable_schtserv_commands (existing: {}, new: {})",
this->enable_schtserv_commands ? "true" : "false", other.enable_schtserv_commands ? "true" : "false"));
}
@@ -354,7 +353,7 @@ std::unordered_map<uint32_t, uint32_t> QuestMetadata::parse_enemy_exp_overrides(
// Key is like "Difficulty:Floor:EnemyType" or "Difficulty:EnemyType"
auto key_tokens = phosg::split(key, ':');
static const unordered_map<string, Difficulty> difficulty_keys(
static const std::unordered_map<std::string, Difficulty> difficulty_keys(
{{"Normal", Difficulty::NORMAL}, {"Hard", Difficulty::HARD}, {"VeryHard", Difficulty::VERY_HARD}, {"Ultimate", Difficulty::ULTIMATE}});
Difficulty difficulty = Difficulty::NORMAL;
@@ -366,7 +365,7 @@ std::unordered_map<uint32_t, uint32_t> QuestMetadata::parse_enemy_exp_overrides(
floor = stoul(key_tokens[1], nullptr, 0);
enemy_type = phosg::enum_for_name<EnemyType>(key_tokens[2]);
} else {
throw runtime_error("malformatted key: " + key);
throw std::runtime_error("malformatted key: " + key);
}
difficulty = difficulty_keys.at(key_tokens[0]);
if (floor == 0xFF) {
@@ -379,7 +378,7 @@ std::unordered_map<uint32_t, uint32_t> QuestMetadata::parse_enemy_exp_overrides(
}
return ret;
} catch (const exception& e) {
} catch (const std::exception& e) {
throw std::runtime_error(std::format("invalid enemy EXP overrides: ", e.what()));
}
}