Merge pull request #6570 from wesnoth/misc-cleanups

Misc cleanups
This commit is contained in:
Charles Dang 2022-03-22 11:26:54 -04:00 committed by GitHub
commit e95afdab9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 137 additions and 133 deletions

View File

@ -1000,6 +1000,49 @@ static void execute_or_check(action_result& action, bool execute)
}
}
const std::map<int, std::string> actions::error_names_ {
{action_result::AI_ACTION_SUCCESS, "action_result::AI_ACTION_SUCCESS"},
{action_result::AI_ACTION_STARTED, "action_result::AI_ACTION_STARTED"},
{action_result::AI_ACTION_FAILURE, "action_result::AI_ACTION_FAILURE"},
{attack_result::E_EMPTY_ATTACKER, "attack_result::E_EMPTY_ATTACKER"},
{attack_result::E_EMPTY_DEFENDER, "attack_result::E_EMPTY_DEFENDER"},
{attack_result::E_INCAPACITATED_ATTACKER, "attack_result::E_INCAPACITATED_ATTACKER"},
{attack_result::E_INCAPACITATED_DEFENDER, "attack_result::E_INCAPACITATED_DEFENDER"},
{attack_result::E_NOT_OWN_ATTACKER, "attack_result::E_NOT_OWN_ATTACKER"},
{attack_result::E_NOT_ENEMY_DEFENDER, "attack_result::E_NOT_ENEMY_DEFENDER"},
{attack_result::E_NO_ATTACKS_LEFT, "attack_result::E_NO_ATTACKS_LEFT"},
{attack_result::E_WRONG_ATTACKER_WEAPON, "attack_result::E_WRONG_ATTACKER_WEAPON"},
{attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON, "attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON"},
{attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACENT," attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACENT"},
{move_result::E_EMPTY_MOVE, "move_result::E_EMPTY_MOVE"},
{move_result::E_NO_UNIT, "move_result::E_NO_UNIT"},
{move_result::E_NOT_OWN_UNIT, "move_result::E_NOT_OWN_UNIT"},
{move_result::E_INCAPACITATED_UNIT, "move_result::E_INCAPACITATED_UNIT"},
{move_result::E_AMBUSHED, "move_result::E_AMBUSHED"},
{move_result::E_FAILED_TELEPORT, "move_result::E_FAILED_TELEPORT"},
{move_result::E_NO_ROUTE, "move_result::E_NO_ROUTE"},
{move_result::E_OFF_MAP, "move_result::E_OFF_MAP"},
{recall_result::E_NOT_AVAILABLE_FOR_RECALLING, "recall_result::E_NOT_AVAILABLE_FOR_RECALLING"},
{recall_result::E_NO_GOLD, "recall_result::E_NO_GOLD"},
{recall_result::E_NO_LEADER," recall_result::E_NO_LEADER"},
{recall_result::E_LEADER_NOT_ON_KEEP, "recall_result::E_LEADER_NOT_ON_KEEP"},
{recall_result::E_BAD_RECALL_LOCATION, "recall_result::E_BAD_RECALL_LOCATION"},
{recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING, "recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING"},
{recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE, "recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE"},
{recruit_result::E_NO_GOLD, "recruit_result::E_NO_GOLD"},
{recruit_result::E_NO_LEADER, "recruit_result::E_NO_LEADER"},
{recruit_result::E_LEADER_NOT_ON_KEEP, "recruit_result::E_LEADER_NOT_ON_KEEP"},
{recruit_result::E_BAD_RECRUIT_LOCATION, "recruit_result::E_BAD_RECRUIT_LOCATION"},
{stopunit_result::E_NO_UNIT, "stopunit_result::E_NO_UNIT"},
{stopunit_result::E_NOT_OWN_UNIT, "stopunit_result::E_NOT_OWN_UNIT"},
{stopunit_result::E_INCAPACITATED_UNIT, "stopunit_result::E_INCAPACITATED_UNIT"},
};
attack_result_ptr actions::execute_attack_action(side_number side,
bool execute,
const map_location& attacker_loc,
@ -1007,7 +1050,7 @@ attack_result_ptr actions::execute_attack_action(side_number side,
int attacker_weapon,
double aggression)
{
attack_result_ptr action(new attack_result(side, attacker_loc, defender_loc, attacker_weapon, aggression));
auto action = std::make_shared<attack_result>(side, attacker_loc, defender_loc, attacker_weapon, aggression);
execute_or_check(*action, execute);
return action;
}
@ -1019,7 +1062,7 @@ move_result_ptr actions::execute_move_action( side_number side,
bool remove_movement,
bool unreach_is_ok)
{
move_result_ptr action(new move_result(side, from, to, remove_movement, unreach_is_ok));
auto action = std::make_shared<move_result>(side, from, to, remove_movement, unreach_is_ok);
execute_or_check(*action, execute);
return action;
}
@ -1030,7 +1073,7 @@ recall_result_ptr actions::execute_recall_action( side_number side,
const map_location& where,
const map_location& from)
{
recall_result_ptr action(new recall_result(side, unit_id, where, from));
auto action = std::make_shared<recall_result>(side, unit_id, where, from);
execute_or_check(*action, execute);
return action;
}
@ -1041,7 +1084,7 @@ recruit_result_ptr actions::execute_recruit_action( side_number side,
const map_location& where,
const map_location& from)
{
recruit_result_ptr action(new recruit_result(side, unit_name, where, from));
auto action = std::make_shared<recruit_result>(side, unit_name, where, from);
execute_or_check(*action, execute);
return action;
}
@ -1052,7 +1095,7 @@ stopunit_result_ptr actions::execute_stopunit_action( side_number side,
bool remove_movement,
bool remove_attacks)
{
stopunit_result_ptr action(new stopunit_result(side, unit_location, remove_movement, remove_attacks));
auto action = std::make_shared<stopunit_result>(side, unit_location, remove_movement, remove_attacks);
execute_or_check(*action, execute);
return action;
}
@ -1062,56 +1105,14 @@ synced_command_result_ptr actions::execute_synced_command_action( side_number si
const std::string& lua_code,
const map_location& location)
{
synced_command_result_ptr action(new synced_command_result(side, lua_code, location));
auto action = std::make_shared<synced_command_result>(side, lua_code, location);
execute_or_check(*action, execute);
return action;
}
const std::string& actions::get_error_name(int error_code)
{
if (error_names_.empty()){
error_names_.emplace(action_result::AI_ACTION_SUCCESS, "action_result::AI_ACTION_SUCCESS");
error_names_.emplace(action_result::AI_ACTION_STARTED, "action_result::AI_ACTION_STARTED");
error_names_.emplace(action_result::AI_ACTION_FAILURE, "action_result::AI_ACTION_FAILURE");
error_names_.emplace(attack_result::E_EMPTY_ATTACKER, "attack_result::E_EMPTY_ATTACKER");
error_names_.emplace(attack_result::E_EMPTY_DEFENDER, "attack_result::E_EMPTY_DEFENDER");
error_names_.emplace(attack_result::E_INCAPACITATED_ATTACKER, "attack_result::E_INCAPACITATED_ATTACKER");
error_names_.emplace(attack_result::E_INCAPACITATED_DEFENDER, "attack_result::E_INCAPACITATED_DEFENDER");
error_names_.emplace(attack_result::E_NOT_OWN_ATTACKER, "attack_result::E_NOT_OWN_ATTACKER");
error_names_.emplace(attack_result::E_NOT_ENEMY_DEFENDER, "attack_result::E_NOT_ENEMY_DEFENDER");
error_names_.emplace(attack_result::E_NO_ATTACKS_LEFT, "attack_result::E_NO_ATTACKS_LEFT");
error_names_.emplace(attack_result::E_WRONG_ATTACKER_WEAPON, "attack_result::E_WRONG_ATTACKER_WEAPON");
error_names_.emplace(attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON, "attack_result::E_UNABLE_TO_CHOOSE_ATTACKER_WEAPON");
error_names_.emplace(attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACENT," attack_result::E_ATTACKER_AND_DEFENDER_NOT_ADJACENT");
error_names_.emplace(move_result::E_EMPTY_MOVE, "move_result::E_EMPTY_MOVE");
error_names_.emplace(move_result::E_NO_UNIT, "move_result::E_NO_UNIT");
error_names_.emplace(move_result::E_NOT_OWN_UNIT, "move_result::E_NOT_OWN_UNIT");
error_names_.emplace(move_result::E_INCAPACITATED_UNIT, "move_result::E_INCAPACITATED_UNIT");
error_names_.emplace(move_result::E_AMBUSHED, "move_result::E_AMBUSHED");
error_names_.emplace(move_result::E_FAILED_TELEPORT, "move_result::E_FAILED_TELEPORT");
error_names_.emplace(move_result::E_NO_ROUTE, "move_result::E_NO_ROUTE");
error_names_.emplace(move_result::E_OFF_MAP, "move_result::E_OFF_MAP");
error_names_.emplace(recall_result::E_NOT_AVAILABLE_FOR_RECALLING, "recall_result::E_NOT_AVAILABLE_FOR_RECALLING");
error_names_.emplace(recall_result::E_NO_GOLD, "recall_result::E_NO_GOLD");
error_names_.emplace(recall_result::E_NO_LEADER," recall_result::E_NO_LEADER");
error_names_.emplace(recall_result::E_LEADER_NOT_ON_KEEP, "recall_result::E_LEADER_NOT_ON_KEEP");
error_names_.emplace(recall_result::E_BAD_RECALL_LOCATION, "recall_result::E_BAD_RECALL_LOCATION");
error_names_.emplace(recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING, "recruit_result::E_NOT_AVAILABLE_FOR_RECRUITING");
error_names_.emplace(recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE, "recruit_result::E_UNKNOWN_OR_DUMMY_UNIT_TYPE");
error_names_.emplace(recruit_result::E_NO_GOLD, "recruit_result::E_NO_GOLD");
error_names_.emplace(recruit_result::E_NO_LEADER, "recruit_result::E_NO_LEADER");
error_names_.emplace(recruit_result::E_LEADER_NOT_ON_KEEP, "recruit_result::E_LEADER_NOT_ON_KEEP");
error_names_.emplace(recruit_result::E_BAD_RECRUIT_LOCATION, "recruit_result::E_BAD_RECRUIT_LOCATION");
error_names_.emplace(stopunit_result::E_NO_UNIT, "stopunit_result::E_NO_UNIT");
error_names_.emplace(stopunit_result::E_NOT_OWN_UNIT, "stopunit_result::E_NOT_OWN_UNIT");
error_names_.emplace(stopunit_result::E_INCAPACITATED_UNIT, "stopunit_result::E_INCAPACITATED_UNIT");
}
std::map<int,std::string>::iterator i = error_names_.find(error_code);
auto i = error_names_.find(error_code);
if (i==error_names_.end()){
ERR_AI_ACTIONS << "error name not available for error #"<<error_code << std::endl;
i = error_names_.find(-1);
@ -1120,8 +1121,6 @@ const std::string& actions::get_error_name(int error_code)
return i->second;
}
std::map<int,std::string> actions::error_names_;
void sim_gamestate_changed(action_result *result, bool gamestate_changed){
if(gamestate_changed){
result->set_gamestate_changed();

View File

@ -425,7 +425,7 @@ const static std::string& get_error_name(int error_code);
private:
static std::map<int,std::string> error_names_;
static const std::map<int, std::string> error_names_;
};

View File

@ -877,6 +877,30 @@ void display::layout_buttons()
}
}
namespace
{
gui::button::TYPE string_to_button_type(const std::string& type)
{
if(type == "checkbox") {
return gui::button::TYPE_CHECK;
} else if(type == "image") {
return gui::button::TYPE_IMAGE;
} else if(type == "radiobox") {
return gui::button::TYPE_RADIO;
} else if(type == "turbo") {
return gui::button::TYPE_TURBO;
} else {
return gui::button::TYPE_PRESS;
}
}
const std::string& get_direction(std::size_t n)
{
static const std::array<std::string, 6> dirs{"-n", "-ne", "-se", "-s", "-sw", "-nw"};
return dirs[n >= dirs.size() ? 0 : n];
}
} // namespace
void display::create_buttons()
{
std::vector<std::shared_ptr<gui::button>> menu_work;
@ -949,23 +973,6 @@ void display::render_buttons()
}
}
gui::button::TYPE display::string_to_button_type(const std::string& type)
{
gui::button::TYPE res = gui::button::TYPE_PRESS;
if (type == "checkbox") { res = gui::button::TYPE_CHECK; }
else if (type == "image") { res = gui::button::TYPE_IMAGE; }
else if (type == "radiobox") { res = gui::button::TYPE_RADIO; }
else if (type == "turbo") { res = gui::button::TYPE_TURBO; }
return res;
}
static const std::string& get_direction(std::size_t n)
{
static const std::array<std::string, 6> dirs {{ "-n", "-ne", "-se", "-s", "-sw", "-nw" }};
return dirs[n >= dirs.size() ? 0 : n];
}
std::vector<surface> display::get_fog_shroud_images(const map_location& loc, image::TYPE image_type)
{
std::vector<std::string> names;
@ -1222,18 +1229,6 @@ void display::drawing_buffer_add(const drawing_layer layer,
drawing_buffer_.emplace_back(layer, loc, x, y, surf, clip);
}
// FIXME: temporary method. Group splitting should be made
// public into the definition of drawing_layer
//
// The drawing is done per layer_group, the range per group is [low, high).
const std::array<display::drawing_layer, 4> display::drawing_buffer_key::layer_groups {{
LAYER_TERRAIN_BG,
LAYER_UNIT_FIRST,
LAYER_UNIT_MOVE_DEFAULT,
// Make sure the movement doesn't show above fog and reachmap.
LAYER_REACHMAP
}};
enum {
// you may adjust the following when needed:

View File

@ -397,7 +397,6 @@ public:
std::shared_ptr<gui::button> find_action_button(const std::string& id);
std::shared_ptr<gui::button> find_menu_button(const std::string& id);
static gui::button::TYPE string_to_button_type(const std::string& type);
void create_buttons();
void layout_buttons();
@ -926,7 +925,17 @@ protected:
private:
unsigned int key_;
static const std::array<drawing_layer, 4> layer_groups;
// FIXME: temporary method. Group splitting should be made
// public into the definition of drawing_layer
//
// The drawing is done per layer_group, the range per group is [low, high).
static inline const std::array layer_groups {
LAYER_TERRAIN_BG,
LAYER_UNIT_FIRST,
LAYER_UNIT_MOVE_DEFAULT,
// Make sure the movement doesn't show above fog and reachmap.
LAYER_REACHMAP
};
public:
drawing_buffer_key(const map_location &loc, drawing_layer layer);

View File

@ -82,9 +82,13 @@ struct enum_base : public T
}
};
#define ENUM_AND_ARRAY(...) \
static constexpr std::size_t count = std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value; \
enum class type { __VA_ARGS__ }; \
static constexpr std::array<const char*, count> values{ __VA_ARGS__ };
#define ENUM_AND_ARRAY(...) \
enum class type { __VA_ARGS__ }; \
\
/** Provide a variable template for an array of matching size. */ \
template<typename T> \
using sized_array = std::array<T, std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value>; \
\
static constexpr sized_array<const char*> values{__VA_ARGS__};
} // namespace string_enums

View File

@ -87,7 +87,7 @@ namespace
#ifdef CAIRO_HAS_WIN32_FONT
bool is_valid_font_file(const std::string& file)
{
static const std::array<std::string, 3> font_exts { ".ttf", ".ttc", ".otf" };
static const std::array font_exts { ".ttf", ".ttc", ".otf" };
for(const std::string& ext : font_exts) {
if(filesystem::ends_with(file, ext)) {

View File

@ -50,13 +50,13 @@ static lg::log_domain log_network("network");
namespace
{
const std::array<std::string, 5> controller_names {{
const std::array controller_names {
side_controller::human,
side_controller::human,
side_controller::ai,
side_controller::none,
side_controller::reserved
}};
};
const std::set<std::string> children_to_swap {
"village",
@ -317,7 +317,7 @@ void connect_engine::update_level()
}
}
void connect_engine::update_and_send_diff(bool /*update_time_of_day*/)
void connect_engine::update_and_send_diff()
{
config old_level = level_;
update_level();
@ -457,7 +457,7 @@ void connect_engine::start_game()
config lock("stop_updates");
mp::send_to_server(lock);
update_and_send_diff(true);
update_and_send_diff();
save_reserved_sides_information();
@ -523,7 +523,7 @@ void connect_engine::start_game_commandline(const commandline_options& cmdline_o
side->resolve_random(rng);
} // end top-level loop
update_and_send_diff(true);
update_and_send_diff();
// Update sides with commandline parameters.
if(cmdline_opts.multiplayer_turns) {

View File

@ -60,7 +60,7 @@ public:
// Import all sides into the level.
void update_level();
// Updates the level and sends a diff to the clients.
void update_and_send_diff(bool update_time_of_day = false);
void update_and_send_diff();
bool can_start_game() const;
void start_game();

View File

@ -37,7 +37,7 @@ lua_map_generator::lua_map_generator(const config & cfg, const config* vars)
, generator_data_(cfg)
{
lk_.load_core();
const std::array<std::string, 3> required {{"id", "config_name", "create_map"}};
const std::array required {"id", "config_name", "create_map"};
for(const std::string& req : required) {
if (!cfg.has_attribute(req)) {
if(req == "create_map" && cfg.has_attribute("create_scenario")) {

View File

@ -67,7 +67,7 @@ unit_const_ptr game_stats::get_leader(const int side)
static std::string controller_name(const team& t)
{
static const std::array<t_string, side_controller::size()> names {{_("controller^Idle"), _("controller^Human"), _("controller^AI"), _("controller^Reserved")}};
static const side_controller::sized_array<t_string> names {_("controller^Idle"), _("controller^Human"), _("controller^AI"), _("controller^Reserved")};
return "<span color='#808080'><small>" + names[static_cast<int>(t.controller())] + "</small></span>";
}

View File

@ -253,12 +253,12 @@ void mp_create_game::pre_show(window& win)
//
// Set up random faction mode menu_button
//
static const std::array<t_string, random_faction_mode::size()> names {{_("Independent"), _("No Mirror"), _("No Ally Mirror")}};
static const std::array<t_string, random_faction_mode::size()> tooltips {{
static const random_faction_mode::sized_array<t_string> names {_("Independent"), _("No Mirror"), _("No Ally Mirror")};
static const random_faction_mode::sized_array<t_string> tooltips {
_("Independent: Random factions assigned independently"),
_("No Mirror: No two players will get the same faction"),
_("No Ally Mirror: No two allied players will get the same faction")
}};
};
std::vector<config> rfm_options;
for(std::size_t i = 0; i < random_faction_mode::size(); i++) {
rfm_options.emplace_back("label", names[i]);

View File

@ -106,7 +106,7 @@ static void verify(const unit_map& units, const config& cfg) {
u->write(u_cfg);
bool is_ok = true;
static const std::array<std::string, 4> fields {{"type","hitpoints","experience","side"}};
static const std::array fields {"type","hitpoints","experience","side"};
for(const std::string& field : fields) {
if (u_cfg[field] != un[field]) {
errbuf << "ERROR IN FIELD '" << field << "' for unit at "

View File

@ -4726,7 +4726,7 @@ void game_lua_kernel::set_game_display(game_display * gd) {
* elsewhere (in the C++ code).
* Any child tags not in this list will be passed to Lua's on_load event.
*/
static const std::array<std::string, 24> handled_file_tags {{
static const std::array handled_file_tags {
"color_palette",
"color_range",
"display",
@ -4751,7 +4751,7 @@ static const std::array<std::string, 24> handled_file_tags {{
"tunnel",
"undo_stack",
"variables"
}};
};
static bool is_handled_file_tag(const std::string& s)
{

View File

@ -86,9 +86,6 @@ static map_location legacy_difference(const map_location& me, const map_location
*
*/
terrain_builder::building_ruleset terrain_builder::building_rules_;
const game_config_view* terrain_builder::rules_cfg_ = nullptr;
terrain_builder::rule_image::rule_image(int layer, int x, int y, bool global_image, int cx, int cy, bool is_water)
: layer(layer)
, basex(x)
@ -730,7 +727,7 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
// If an integer is given then assign that, but if a bool is given, then assign -1 if true and 0 if false
int random_start = variant["random_start"].to_bool(true) ? variant["random_start"].to_int(-1) : 0;
images.back().variants.push_back(rule_image_variant(name, variations, tod, has_flag, random_start));
images.back().variants.emplace_back(name, variations, tod, has_flag, random_start);
}
// Adds the main (default) variant of the image at the end,
@ -740,7 +737,7 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi
int random_start = img["random_start"].to_bool(true) ? img["random_start"].to_int(-1) : 0;
images.back().variants.push_back(rule_image_variant(name, variations, random_start));
images.back().variants.emplace_back(name, variations, random_start);
}
}
@ -1093,7 +1090,7 @@ void terrain_builder::apply_rule(const terrain_builder::building_rule& rule, con
if(!constraint.no_draw) {
for(const rule_image& img : constraint.images) {
btile.images.push_back(tile::rule_image_rand(&img, rand_seed));
btile.images.emplace_back(&img, rand_seed);
}
}

View File

@ -860,8 +860,8 @@ private:
bool draw_border_;
/** Parsed terrain rules. Cached between instances */
static building_ruleset building_rules_;
static inline building_ruleset building_rules_{};
/** Config used to parse global terrain rules */
static const game_config_view* rules_cfg_;
static const inline game_config_view* rules_cfg_ = nullptr;
};

View File

@ -57,52 +57,52 @@ BOOST_AUTO_TEST_CASE( utils_split_test )
{
auto split = utils::split(test_string);
std::array<std::string, 7> expect = {"a", "bb", "ccc || d", "ee", "fff | | g", "hh", "iii"};
std::array expect = {"a", "bb", "ccc || d", "ee", "fff | | g", "hh", "iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, ',', utils::REMOVE_EMPTY | utils::STRIP_SPACES);
std::array<std::string, 7> expect = {"a", "bb", "ccc || d", "ee", "fff | | g", "hh", "iii"};
std::array expect = {"a", "bb", "ccc || d", "ee", "fff | | g", "hh", "iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, ',', utils::REMOVE_EMPTY);
std::array<std::string, 9> expect = {"a", " ", " bb", " ccc || d", " ee", " fff | | g", " ", " hh", " iii"};
std::array expect = {"a", " ", " bb", " ccc || d", " ee", " fff | | g", " ", " hh", " iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, ',', utils::STRIP_SPACES);
std::array<std::string, 10> expect = {"a", "", "bb", "ccc || d", "ee", "", "fff | | g", "", "hh", "iii"};
std::array expect = {"a", "", "bb", "ccc || d", "ee", "", "fff | | g", "", "hh", "iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, ',', 0);
std::array<std::string, 10> expect = {"a", " ", " bb", " ccc || d", " ee", "", " fff | | g", " ", " hh", " iii"};
std::array expect = {"a", " ", " bb", " ccc || d", " ee", "", " fff | | g", " ", " hh", " iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, '|');
std::array<std::string, 3> expect = {"a, , bb, ccc", "d, ee,, fff", "g, , hh, iii"};
std::array expect = {"a, , bb, ccc", "d, ee,, fff", "g, , hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, '|', utils::REMOVE_EMPTY | utils::STRIP_SPACES);
std::array<std::string, 3> expect = {"a, , bb, ccc", "d, ee,, fff", "g, , hh, iii"};
std::array expect = {"a, , bb, ccc", "d, ee,, fff", "g, , hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, '|', utils::REMOVE_EMPTY);
std::array<std::string, 4> expect = {"a, , bb, ccc ", " d, ee,, fff ", " ", " g, , hh, iii"};
std::array expect = {"a, , bb, ccc ", " d, ee,, fff ", " ", " g, , hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, '|', utils::STRIP_SPACES);
std::array<std::string, 5> expect = {"a, , bb, ccc", "", "d, ee,, fff", "", "g, , hh, iii"};
std::array expect = {"a, , bb, ccc", "", "d, ee,, fff", "", "g, , hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::split(test_string, '|', 0);
std::array<std::string, 5> expect = {"a, , bb, ccc ", "", " d, ee,, fff ", " ", " g, , hh, iii"};
std::array expect = {"a, , bb, ccc ", "", " d, ee,, fff ", " ", " g, , hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
}
@ -113,42 +113,42 @@ BOOST_AUTO_TEST_CASE( utils_quoted_split_test )
{
auto split = utils::quoted_split(test_string, ',', utils::REMOVE_EMPTY | utils::STRIP_SPACES, '`');
std::array<std::string, 7> expect = {"a", "`, bb", "ccc || d", "ee", "fff | `| g", "`, hh", "iii"};
std::array expect = {"a", "`, bb", "ccc || d", "ee", "fff | `| g", "`, hh", "iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::quoted_split(test_string, ',', utils::REMOVE_EMPTY, '`');
std::array<std::string, 7> expect = {"a", " `, bb", " ccc || d", " ee", " fff | `| g", " `, hh", " iii"};
std::array expect = {"a", " `, bb", " ccc || d", " ee", " fff | `| g", " `, hh", " iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::quoted_split(test_string, ',', utils::STRIP_SPACES, '`');
std::array<std::string, 8> expect = {"a", "`, bb", "ccc || d", "ee", "", "fff | `| g", "`, hh", "iii"};
std::array expect = {"a", "`, bb", "ccc || d", "ee", "", "fff | `| g", "`, hh", "iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::quoted_split(test_string, ',', 0, '`');
std::array<std::string, 8> expect = {"a", " `, bb", " ccc || d", " ee", "", " fff | `| g", " `, hh", " iii"};
std::array expect = {"a", " `, bb", " ccc || d", " ee", "", " fff | `| g", " `, hh", " iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::quoted_split(test_string, '|', utils::REMOVE_EMPTY | utils::STRIP_SPACES, '`');
std::array<std::string, 3> expect = {"a, `, bb, ccc", "d, ee,, fff", "`| g, `, hh, iii"};
std::array expect = {"a, `, bb, ccc", "d, ee,, fff", "`| g, `, hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::quoted_split(test_string, '|', utils::REMOVE_EMPTY, '`');
std::array<std::string, 3> expect = {"a, `, bb, ccc ", " d, ee,, fff ", " `| g, `, hh, iii"};
std::array expect = {"a, `, bb, ccc ", " d, ee,, fff ", " `| g, `, hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::quoted_split(test_string, '|', utils::STRIP_SPACES, '`');
std::array<std::string, 4> expect = {"a, `, bb, ccc", "", "d, ee,, fff", "`| g, `, hh, iii"};
std::array expect = {"a, `, bb, ccc", "", "d, ee,, fff", "`| g, `, hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
{
auto split = utils::quoted_split(test_string, '|', 0, '`');
std::array<std::string, 4> expect = {"a, `, bb, ccc ", "", " d, ee,, fff ", " `| g, `, hh, iii"};
std::array expect = {"a, `, bb, ccc ", "", " d, ee,, fff ", " `| g, `, hh, iii"};
BOOST_CHECK_EQUAL_COLLECTIONS(split.begin(), split.end(), expect.begin(), expect.end());
}
}

View File

@ -839,8 +839,8 @@ bool unit_type::resistance_filter_matches(
std::string unit_type::alignment_description(unit_alignments::type align, unit_race::GENDER gender)
{
static const std::array<t_string, unit_alignments::size()> male_names {{_("lawful"), _("neutral"), _("chaotic"), _("liminal")}};
static const std::array<t_string, unit_alignments::size()> female_names {{_("female^lawful"), _("female^neutral"), _("female^chaotic"), _("female^liminal")}};
static const unit_alignments::sized_array<t_string> male_names {_("lawful"), _("neutral"), _("chaotic"), _("liminal")};
static const unit_alignments::sized_array<t_string> female_names {_("female^lawful"), _("female^neutral"), _("female^chaotic"), _("female^liminal")};
if(gender == unit_race::FEMALE) {
return female_names[static_cast<int>(align)];
@ -926,7 +926,7 @@ void patch_movetype(movetype& mt,
// These three need to follow movetype's fallback system, where values for
// movement costs are used for vision too.
const auto fallback_children = std::array<std::string, 3>{{"movement_costs", "vision_costs", "jamming_costs"}};
const std::array fallback_children {"movement_costs", "vision_costs", "jamming_costs"};
config cumulative_values;
for(const auto& x : fallback_children) {
if(mt_cfg.has_child(x)) {
@ -943,7 +943,7 @@ void patch_movetype(movetype& mt,
}
// These don't need the fallback system
const auto child_names = std::array<std::string, 2>{{"defense", "resistance"}};
const std::array child_names {"defense", "resistance"};
for(const auto& x : child_names) {
if(mt_cfg.has_child(x)) {
const auto& subtag = mt_cfg.child(x);
@ -1143,7 +1143,7 @@ void unit_type_data::set_config(const game_config_view& cfg)
std::string alias;
int default_val;
};
const std::array<ter_defs_to_movetype, 4> terrain_info_tags{
const std::array terrain_info_tags{
ter_defs_to_movetype{{"movement_costs"}, {"movement"}, movetype::UNREACHABLE},
ter_defs_to_movetype{{"vision_costs"}, {"vision"}, movetype::UNREACHABLE},
ter_defs_to_movetype{{"jamming_costs"}, {"jamming"}, movetype::UNREACHABLE},