rewrite MAKE_ENUM macro

Instead of creating an enum, the MAKE_ENUM macro now creates a struct
which holds an enum and provides functions for enum <-> string
conversion.

This has multiple advantages:
1) We don't need MAKE_ENUM_STREAM_OPS anymore.
2) The generated struct is much easier to use in templates
3) We don't allow implicit to int conversions anymore.
4) The enum values are now declared inside the structs scope.
This commit is contained in:
gfgtdf 2015-06-03 17:57:57 +02:00
parent 759ab3d4cb
commit da1c8bf60e
58 changed files with 484 additions and 505 deletions

View file

@ -1062,6 +1062,7 @@ set(libwesnoth-game_STAT_SRC
language.cpp
loadscreen.cpp
lobby_preferences.cpp
make_enum.cpp
map_label.cpp
marked-up_text.cpp
minimap.cpp

View file

@ -108,6 +108,7 @@ libwesnoth_sources = Split("""
key.cpp
language.cpp
loadscreen.cpp
make_enum.cpp
map_label.cpp
marked-up_text.cpp
minimap.cpp

View file

@ -1630,17 +1630,17 @@ int combat_modifier(const unit_map & units, const gamemap & map, const map_locat
int generic_combat_modifier(int lawful_bonus, unit_type::ALIGNMENT alignment,
bool is_fearless) {
int bonus;
switch(alignment) {
case unit_type::LAWFUL:
switch(alignment.v) {
case unit_type::ALIGNMENT::LAWFUL:
bonus = lawful_bonus;
break;
case unit_type::NEUTRAL:
case unit_type::ALIGNMENT::NEUTRAL:
bonus = 0;
break;
case unit_type::CHAOTIC:
case unit_type::ALIGNMENT::CHAOTIC:
bonus = -lawful_bonus;
break;
case unit_type::LIMINAL:
case unit_type::ALIGNMENT::LIMINAL:
bonus = -abs(lawful_bonus);
break;
default:

View file

@ -1165,11 +1165,11 @@ double readonly_context_impl::power_projection(const map_location& loc, const mo
// Considering the unit location would be too slow, we only apply the bonus granted by the global ToD
const int lawful_bonus = resources::tod_manager->get_time_of_day(attack_turn).lawful_bonus;
int tod_modifier = 0;
if(un.alignment() == unit_type::LAWFUL) {
if(un.alignment() == unit_type::ALIGNMENT::LAWFUL) {
tod_modifier = lawful_bonus;
} else if(un.alignment() == unit_type::CHAOTIC) {
} else if(un.alignment() == unit_type::ALIGNMENT::CHAOTIC) {
tod_modifier = -lawful_bonus;
} else if(un.alignment() == unit_type::LIMINAL) {
} else if(un.alignment() == unit_type::ALIGNMENT::LIMINAL) {
tod_modifier = -(abs(lawful_bonus));
}

View file

@ -838,8 +838,8 @@ void save_preview_pane::draw_contents()
try {
game_classification::CAMPAIGN_TYPE ct = lexical_cast<game_classification::CAMPAIGN_TYPE> (campaign_type);
switch (ct) {
case game_classification::SCENARIO:
switch (ct.v) {
case game_classification::CAMPAIGN_TYPE::SCENARIO:
{
const std::string campaign_id = summary["campaign"];
const config *campaign = NULL;
@ -862,13 +862,13 @@ void save_preview_pane::draw_contents()
}
break;
}
case game_classification::MULTIPLAYER:
case game_classification::CAMPAIGN_TYPE::MULTIPLAYER:
str << _("Multiplayer");
break;
case game_classification::TUTORIAL:
case game_classification::CAMPAIGN_TYPE::TUTORIAL:
str << _("Tutorial");
break;
case game_classification::TEST:
case game_classification::CAMPAIGN_TYPE::TEST:
str << _("Test scenario");
break;
}

View file

@ -460,7 +460,7 @@ config map_context::to_config()
side["side"] = side_num;
side["hidden"] = t->hidden();
side["controller"] = team::CONTROLLER_to_string (t->controller());
side["controller"] = team::CONTROLLER::enum_to_string (t->controller());
side["no_leader"] = t->no_leader();
side["team_name"] = t->team_name();

View file

@ -104,16 +104,16 @@ void game_board::check_victory(bool & continue_level, bool & found_player, bool
DBG_EE << "Found a unit: " << i.id() << " on side " << i.side() << std::endl;
const team& tm = teams()[i.side()-1];
DBG_EE << "That team's defeat condition is: " << lexical_cast<std::string> (tm.defeat_condition()) << std::endl;
if (i.can_recruit() && tm.defeat_condition() == team::NO_LEADER) {
if (i.can_recruit() && tm.defeat_condition() == team::DEFEAT_CONDITION::NO_LEADER) {
not_defeated.insert(i.side());
} else if (tm.defeat_condition() == team::NO_UNITS) {
} else if (tm.defeat_condition() == team::DEFEAT_CONDITION::NO_UNITS) {
not_defeated.insert(i.side());
}
}
BOOST_FOREACH(team& tm, teams_)
{
if(tm.defeat_condition() == team::NEVER)
if(tm.defeat_condition() == team::DEFEAT_CONDITION::NEVER)
{
not_defeated.insert(tm.side());
}
@ -220,20 +220,20 @@ void game_board::side_change_controller(int side_num, team::CONTROLLER ctrl, con
bool game_board::team_is_defeated(const team& t) const
{
switch(t.defeat_condition())
switch(t.defeat_condition().v)
{
case team::ALWAYS:
case team::DEFEAT_CONDITION::ALWAYS:
return true;
case team::NO_LEADER:
case team::DEFEAT_CONDITION::NO_LEADER:
return !units_.find_leader(t.side()).valid();
case team::NO_UNITS:
case team::DEFEAT_CONDITION::NO_UNITS:
BOOST_FOREACH(const unit& u, units_)
{
if(u.side() == t.side())
return false;
}
return true;
case team::NEVER:
case team::DEFEAT_CONDITION::NEVER:
default:
return false;
}

View file

@ -117,7 +117,7 @@ class game_board : public display_context {
// Manipulator from playturn
void side_drop_to (int side_num, team::CONTROLLER ctrl, team::PROXY_CONTROLLER proxy = team::PROXY_HUMAN);
void side_drop_to (int side_num, team::CONTROLLER ctrl, team::PROXY_CONTROLLER proxy = team::PROXY_CONTROLLER::PROXY_HUMAN);
void side_change_controller (int side_num, team::CONTROLLER ctrl, const std::string pname = "");
// Manipulator from actionwml

View file

@ -14,6 +14,7 @@
#include "global.hpp"
#include "game_classification.hpp"
#include "game_config.hpp"
#include "util.hpp"
#include "serialization/string_utils.hpp"
#include "log.hpp"
@ -51,7 +52,7 @@ game_classification::game_classification(const config& cfg):
savegame_config(),
label(cfg["label"]),
version(cfg["version"]),
campaign_type(lexical_cast_default<game_classification::CAMPAIGN_TYPE> (cfg["campaign_type"].str(), game_classification::SCENARIO)),
campaign_type(lexical_cast_default<game_classification::CAMPAIGN_TYPE> (cfg["campaign_type"].str(), game_classification::CAMPAIGN_TYPE::SCENARIO)),
campaign_define(cfg["campaign_define"]),
campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
scenario_define(cfg["scenario_define"]),

View file

@ -57,6 +57,5 @@ public:
std::string random_mode;
bool oos_debug;
};
MAKE_ENUM_STREAM_OPS2(game_classification, CAMPAIGN_TYPE)
#endif

View file

@ -245,8 +245,8 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
// become [multiplayer] tags and campaign's id should be added to them
// to allow to recognize which scenarios belongs to a loaded campaign.
if (classification != NULL) {
if ((classification->campaign_type == game_classification::MULTIPLAYER ||
classification->campaign_type == game_classification::SCENARIO) &&
if ((classification->campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER ||
classification->campaign_type == game_classification::CAMPAIGN_TYPE::SCENARIO) &&
!classification->campaign_define.empty()) {
const config& campaign = game_config().find_child("campaign",
@ -267,7 +267,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
cfg["require_scenario"] = require_campaign;
// make force_lock_settings default to true for [scenario]
cfg["force_lock_settings"] = cfg["force_lock_settings"].to_bool(true);
game_config_.add_child(lexical_cast<std::string>(game_classification::MULTIPLAYER), cfg);
game_config_.add_child(lexical_cast<std::string>(game_classification::CAMPAIGN_TYPE::MULTIPLAYER), cfg);
}
}
}
@ -502,9 +502,9 @@ void game_config_manager::load_game_config_for_game(
game_config::scoped_preproc_define era(classification.era_define,
!classification.era_define.empty());
game_config::scoped_preproc_define multiplayer("MULTIPLAYER",
classification.campaign_type == game_classification::MULTIPLAYER);
classification.campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest &&
classification.campaign_type == game_classification::MULTIPLAYER);
classification.campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
typedef boost::shared_ptr<game_config::scoped_preproc_define> define;
std::deque<define> extra_defines;

View file

@ -32,12 +32,11 @@
#include <boost/optional.hpp>
MAKE_ENUM(LEVEL_RESULT,
(VICTORY, "victory")
(DEFEAT, "defeat")
(QUIT, "quit")
(OBSERVER_END, "observer_end")
(VICTORY, "victory")
(DEFEAT, "defeat")
(QUIT, "quit")
(OBSERVER_END, "observer_end")
)
MAKE_ENUM_STREAM_OPS1(LEVEL_RESULT)
/**
* Exception used to escape form the ai or ui code to playsingle_controller::play_side.

View file

@ -60,7 +60,7 @@ void configure_engine::set_default_values() {
bool configure_engine::force_lock_settings() const {
return state_.get_starting_pos()["force_lock_settings"].to_bool(
state_.classification().campaign_type != game_classification::MULTIPLAYER);
state_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
}
std::string configure_engine::game_name() const { return parameters_.name; }
@ -169,7 +169,7 @@ bool configure_engine::random_start_time_default() const {
}
bool configure_engine::fog_game_default() const {
return use_map_settings() && !side_cfg_.empty() ?
side_cfg_["fog"].to_bool(state_.classification().campaign_type != game_classification::SCENARIO) :
side_cfg_["fog"].to_bool(state_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::SCENARIO) :
preferences::fog();
}
bool configure_engine::shroud_game_default() const {
@ -179,13 +179,13 @@ bool configure_engine::shroud_game_default() const {
}
bool configure_engine::allow_observers_default() const {
return preferences::allow_observers() &&
state_.classification().campaign_type != game_classification::SCENARIO;
state_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::SCENARIO;
}
bool configure_engine::shuffle_sides_default() const {
return preferences::shuffle_sides();
}
mp_game_settings::RANDOM_FACTION_MODE configure_engine::random_faction_mode_default() const {
return mp_game_settings::string_to_RANDOM_FACTION_MODE_default(preferences::random_faction_mode(), mp_game_settings::DEFAULT);
return mp_game_settings::RANDOM_FACTION_MODE::string_to_enum(preferences::random_faction_mode(), mp_game_settings::RANDOM_FACTION_MODE::DEFAULT);
}
const config& configure_engine::options_default() const {

View file

@ -388,14 +388,14 @@ void connect_engine::start_game(LOAD_USERS load_users)
std::vector<std::string> avoid_faction_ids;
// If we aren't resolving random factions independently at random, calculate which factions should not appear for this side.
if (params_.random_faction_mode != mp_game_settings::DEFAULT) {
if (params_.random_faction_mode != mp_game_settings::RANDOM_FACTION_MODE::DEFAULT) {
BOOST_FOREACH(side_engine_ptr side2, side_engines_) {
if (!side2->flg().is_random_faction()) {
switch(params_.random_faction_mode) {
case mp_game_settings::NO_MIRROR:
switch(params_.random_faction_mode.v) {
case mp_game_settings::RANDOM_FACTION_MODE::NO_MIRROR:
avoid_faction_ids.push_back(side2->flg().current_faction()["id"].str());
break;
case mp_game_settings::NO_ALLY_MIRROR:
case mp_game_settings::RANDOM_FACTION_MODE::NO_ALLY_MIRROR:
if (side2->team() == side->team()) {// TODO: When the connect engines are fixed to allow multiple teams, this should be changed to "if side1 and side2 are allied, i.e. their list of teams has nonempty intersection"
avoid_faction_ids.push_back(side2->flg().current_faction()["id"].str());
}
@ -878,7 +878,7 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine,
// Tweak the controllers.
if (cfg_["controller"] == "network_ai" ||
(parent_.state_.classification().campaign_type == game_classification::SCENARIO && cfg_["controller"].blank()))
(parent_.state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::SCENARIO && cfg_["controller"].blank()))
{
cfg_["controller"] = "ai";
}

View file

@ -421,7 +421,7 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
state_.mp_settings().show_configure = configure;
state_.mp_settings().show_connect = connect;
if (!(type == game_classification::SCENARIO &&
if (!(type == game_classification::CAMPAIGN_TYPE::SCENARIO &&
game_config_manager::get()->old_defines_map().count("TITLE_SCREEN") != 0))
{
game_config_manager::get()->
@ -449,8 +449,8 @@ create_engine::create_engine(game_display& disp, saved_game& state) :
state_.mp_settings().active_mods.push_back(str);
}
if (current_level_type_ != level::CAMPAIGN &&
current_level_type_ != level::SP_CAMPAIGN) {
if (current_level_type_ != level::TYPE::CAMPAIGN &&
current_level_type_ != level::TYPE::SP_CAMPAIGN) {
dependency_manager_.try_modifications(state_.mp_settings().active_mods, true);
}
@ -745,23 +745,23 @@ std::vector<std::string> create_engine::extras_menu_item_names(
level& create_engine::current_level() const
{
switch (current_level_type_) {
case level::SCENARIO: {
switch (current_level_type_.v) {
case level::TYPE::SCENARIO: {
return *scenarios_[current_level_index_];
}
case level::USER_SCENARIO: {
case level::TYPE::USER_SCENARIO: {
return *user_scenarios_[current_level_index_];
}
case level::USER_MAP: {
case level::TYPE::USER_MAP: {
return *user_maps_[current_level_index_];
}
case level::RANDOM_MAP: {
case level::TYPE::RANDOM_MAP: {
return *random_maps_[current_level_index_];
}
case level::CAMPAIGN: {
case level::TYPE::CAMPAIGN: {
return *campaigns_[current_level_index_];
}
case level::SP_CAMPAIGN:
case level::TYPE::SP_CAMPAIGN:
default: {
return *sp_campaigns_[current_level_index_];
}
@ -789,27 +789,27 @@ level::TYPE create_engine::current_level_type() const
void create_engine::set_current_level(const size_t index)
{
switch (current_level_type()) {
case level::CAMPAIGN:
switch (current_level_type().v) {
case level::TYPE::CAMPAIGN:
current_level_index_ = campaigns_filtered_[index];
break;
case level::SP_CAMPAIGN:
case level::TYPE::SP_CAMPAIGN:
current_level_index_ = sp_campaigns_filtered_[index];
break;
case level::SCENARIO:
case level::TYPE::SCENARIO:
current_level_index_ = scenarios_filtered_[index];
break;
case level::RANDOM_MAP:
case level::TYPE::RANDOM_MAP:
current_level_index_ = random_maps_filtered_[index];
break;
case level::USER_MAP:
case level::TYPE::USER_MAP:
current_level_index_ = user_maps_filtered_[index];
break;
case level::USER_SCENARIO:
case level::TYPE::USER_SCENARIO:
current_level_index_ = user_scenarios_filtered_[index];
}
if (current_level_type_ == level::RANDOM_MAP) {
if (current_level_type_ == level::TYPE::RANDOM_MAP) {
random_map* current_random_map =
dynamic_cast<random_map*>(&current_level());
@ -820,8 +820,8 @@ void create_engine::set_current_level(const size_t index)
generator_.reset(NULL);
}
if (current_level_type_ != level::CAMPAIGN &&
current_level_type_ != level::SP_CAMPAIGN) {
if (current_level_type_ != level::TYPE::CAMPAIGN &&
current_level_type_ != level::TYPE::SP_CAMPAIGN) {
dependency_manager_.try_scenario(current_level().id());
}
@ -851,7 +851,7 @@ size_t create_engine::current_mod_index() const
bool create_engine::toggle_current_mod(bool force)
{
force |= (current_level_type_ == ng::level::CAMPAIGN || current_level_type_ == ng::level::SP_CAMPAIGN);
force |= (current_level_type_ == ng::level::TYPE::CAMPAIGN || current_level_type_ == ng::level::TYPE::SP_CAMPAIGN);
bool is_active = dependency_manager_.is_modification_active(current_mod_index_);
dependency_manager_.try_modification_by_index(current_mod_index_, !is_active, force);
@ -942,30 +942,30 @@ level::TYPE create_engine::find_level_type_by_id(const std::string& id) const
{
BOOST_FOREACH(user_map_ptr user_map, user_maps_) {
if (user_map->id() == id) {
return level::USER_MAP;
return level::TYPE::USER_MAP;
}
}
BOOST_FOREACH(random_map_ptr random_map, random_maps_) {
if (random_map->id() == id) {
return level::RANDOM_MAP;
return level::TYPE::RANDOM_MAP;
}
}
BOOST_FOREACH(scenario_ptr scenario, scenarios_) {
if (scenario->id() == id) {
return level::SCENARIO;
return level::TYPE::SCENARIO;
}
}
BOOST_FOREACH(scenario_ptr scenario, user_scenarios_) {
if (scenario->id() == id) {
return level::USER_SCENARIO;
return level::TYPE::USER_SCENARIO;
}
}
BOOST_FOREACH(campaign_ptr campaign, campaigns_) {
if (campaign->id() == id) {
return level::CAMPAIGN;
return level::TYPE::CAMPAIGN;
}
}
return level::SP_CAMPAIGN;
return level::TYPE::SP_CAMPAIGN;
}
const depcheck::manager& create_engine::dependency_manager() const
@ -1072,7 +1072,7 @@ void create_engine::init_all_levels()
// Stand-alone scenarios.
BOOST_FOREACH(const config &data,
game_config_manager::get()->game_config().child_range(
lexical_cast<std::string> (game_classification::MULTIPLAYER)))
lexical_cast<std::string> (game_classification::CAMPAIGN_TYPE::MULTIPLAYER)))
{
if (!data["allow_new_game"].to_bool(true))
continue;
@ -1093,7 +1093,7 @@ void create_engine::init_all_levels()
game_config_manager::get()->game_config().child_range("campaign"))
{
const std::string& type = data["type"];
bool mp = state_.classification().campaign_type == game_classification::MULTIPLAYER;
bool mp = state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
if (type == "mp" || (type == "hybrid" && mp)) {
campaign_ptr new_campaign(new campaign(data));
@ -1121,7 +1121,7 @@ void create_engine::init_extras(const MP_EXTRA extra_type)
game_config_manager::get()->game_config().child_range(extra_name)) {
const std::string& type = extra["type"];
bool mp = state_.classification().campaign_type == game_classification::MULTIPLAYER;
bool mp = state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
if((type != "mp" || mp) && (type != "sp" || !mp) )
{
@ -1199,33 +1199,33 @@ std::vector<create_engine::level_ptr>
create_engine::get_levels_by_type_unfiltered(level::TYPE type) const
{
std::vector<level_ptr> levels;
switch (type) {
case level::SCENARIO:
switch (type.v) {
case level::TYPE::SCENARIO:
BOOST_FOREACH(level_ptr level, scenarios_) {
levels.push_back(level);
}
break;
case level::USER_MAP:
case level::TYPE::USER_MAP:
BOOST_FOREACH(level_ptr level, user_maps_) {
levels.push_back(level);
}
break;
case level::USER_SCENARIO:
case level::TYPE::USER_SCENARIO:
BOOST_FOREACH(level_ptr level, user_scenarios_) {
levels.push_back(level);
}
break;
case level::RANDOM_MAP:
case level::TYPE::RANDOM_MAP:
BOOST_FOREACH(level_ptr level, random_maps_) {
levels.push_back(level);
}
break;
case level::CAMPAIGN:
case level::TYPE::CAMPAIGN:
BOOST_FOREACH(level_ptr level, campaigns_) {
levels.push_back(level);
}
break;
case level::SP_CAMPAIGN:
case level::TYPE::SP_CAMPAIGN:
BOOST_FOREACH(level_ptr level, sp_campaigns_) {
levels.push_back(level);
}
@ -1238,33 +1238,33 @@ std::vector<create_engine::level_ptr>
std::vector<create_engine::level_ptr> create_engine::get_levels_by_type(level::TYPE type) const
{
std::vector<level_ptr> levels;
switch (type) {
case level::SCENARIO:
switch (type.v) {
case level::TYPE::SCENARIO:
BOOST_FOREACH(size_t level, scenarios_filtered_) {
levels.push_back(scenarios_[level]);
}
break;
case level::USER_MAP:
case level::TYPE::USER_MAP:
BOOST_FOREACH(size_t level, user_maps_filtered_) {
levels.push_back(user_maps_[level]);
}
break;
case level::USER_SCENARIO:
case level::TYPE::USER_SCENARIO:
BOOST_FOREACH(size_t level, user_scenarios_filtered_) {
levels.push_back(user_scenarios_[level]);
}
break;
case level::RANDOM_MAP:
case level::TYPE::RANDOM_MAP:
BOOST_FOREACH(size_t level, random_maps_filtered_) {
levels.push_back(random_maps_[level]);
}
break;
case level::CAMPAIGN:
case level::TYPE::CAMPAIGN:
BOOST_FOREACH(size_t level, campaigns_filtered_) {
levels.push_back(campaigns_[level]);
}
break;
case level::SP_CAMPAIGN:
case level::TYPE::SP_CAMPAIGN:
BOOST_FOREACH(size_t level, sp_campaigns_filtered_) {
levels.push_back(sp_campaigns_[level]);
}

View file

@ -34,13 +34,13 @@ public:
level(const config& data);
virtual ~level() {}
MAKE_ENUM( TYPE,
(SCENARIO, "scenario")
(USER_MAP, "user_map")
(USER_SCENARIO, "user_scenario")
(RANDOM_MAP, "random_map")
(CAMPAIGN, "campaign")
(SP_CAMPAIGN, "sp_campaign")
MAKE_ENUM(TYPE,
(SCENARIO, "scenario")
(USER_MAP, "user_map")
(USER_SCENARIO, "user_scenario")
(RANDOM_MAP, "random_map")
(CAMPAIGN, "campaign")
(SP_CAMPAIGN, "sp_campaign")
)
virtual bool can_launch_game() const = 0;
@ -66,7 +66,6 @@ private:
level(const level&);
void operator=(const level&);
};
MAKE_ENUM_STREAM_OPS2( level, TYPE )
class scenario : public level
{

View file

@ -823,7 +823,7 @@ void start_local_game_commandline(game_display& disp, const config& game_config,
}
game_classification classification;
classification.campaign_type = game_classification::MULTIPLAYER;
classification.campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
classification.scenario_define = level_preload["define"].str();
classification.era_define = era_cfg_preload["define"].str();
game_config_manager::get()->load_game_config_for_game(classification);

View file

@ -178,7 +178,7 @@ configure::configure(game_display& disp, const config &cfg, chat& c, config& gam
observers_game_.set_check(engine_.allow_observers_default());
observers_game_.set_help_string(_("Allow users who are not playing to watch the game"));
observers_game_.enable(state_.classification().campaign_type != game_classification::SCENARIO);
observers_game_.enable(state_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::SCENARIO);
oos_debug_.set_check(false);
oos_debug_.set_help_string(_("More checks for OOS errors but also more network traffic"));
@ -190,12 +190,12 @@ configure::configure(game_display& disp, const config &cfg, chat& c, config& gam
random_faction_mode_label_.set_help_string(_("Allow for mirror matchups when random factions are chosen"));
std::vector<std::string> translated_modes;
for(size_t i = 0; i < mp_game_settings::RANDOM_FACTION_MODE_COUNT; ++i) {
std::string mode_str = mp_game_settings::RANDOM_FACTION_MODE_to_string(static_cast<mp_game_settings::RANDOM_FACTION_MODE> (i));
for(size_t i = 0; i < mp_game_settings::RANDOM_FACTION_MODE::count; ++i) {
std::string mode_str = mp_game_settings::RANDOM_FACTION_MODE::enum_to_string(mp_game_settings::RANDOM_FACTION_MODE::from_int(i));
translated_modes.push_back(translation::gettext(mode_str.c_str()));
}
random_faction_mode_.set_items(translated_modes);
random_faction_mode_.set_selected(engine_.random_faction_mode());
random_faction_mode_.set_selected(engine_.random_faction_mode().cast<int>());
random_faction_mode_.set_help_string(_("Independent: Random factions assigned independently\nNo Mirror: No two players will get the same faction\nNo Ally Mirror: No two allied players will get the same faction"));
#if 0
@ -244,7 +244,7 @@ configure::~configure()
// Save values for next game
DBG_MP << "storing parameter values in preferences" << std::endl;
preferences::set_shuffle_sides(engine_.shuffle_sides());
preferences::set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE_to_string(engine_.random_faction_mode()));
preferences::set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE::enum_to_string(engine_.random_faction_mode()));
preferences::set_use_map_settings(engine_.use_map_settings());
preferences::set_countdown(engine_.mp_countdown());
preferences::set_countdown_init_time(engine_.mp_countdown_init_time());
@ -308,7 +308,7 @@ const mp_game_settings& configure::get_parameters()
engine_.set_allow_observers(observers_game_.checked());
engine_.set_oos_debug(oos_debug_.checked());
engine_.set_shuffle_sides(shuffle_sides_.checked());
engine_.set_random_faction_mode(static_cast<mp_game_settings::RANDOM_FACTION_MODE>(random_faction_mode_.selected()));
engine_.set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE::from_int(random_faction_mode_.selected()));
engine_.set_options(options_manager_.get_values());

View file

@ -68,7 +68,7 @@ static config get_selected_helper(const ng::create_engine * eng_ptr)
("icon", eng.current_level().icon())
("description", eng.current_level().description())
("allow_era_choice", eng.current_level().allow_era_choice())
("type", ng::level::TYPE_to_string(eng.current_level_type()));
("type", ng::level::TYPE::enum_to_string(eng.current_level_type()));
}
static config find_helper(const ng::create_engine * eng_ptr, const config & cfg)
@ -78,7 +78,7 @@ static config find_helper(const ng::create_engine * eng_ptr, const config & cfg)
std::string str = cfg["id"].str();
return config_of("index", eng.find_level_by_id(str))
("type", ng::level::TYPE_to_string(eng.find_level_type_by_id(str)));
("type", ng::level::TYPE::enum_to_string(eng.find_level_type_by_id(str)));
}
create::create(game_display& disp, const config& cfg, saved_game& state,
@ -126,14 +126,14 @@ create::create(game_display& disp, const config& cfg, saved_game& state,
typedef std::pair<ng::level::TYPE, std::string> level_type_info;
std::vector<level_type_info> all_level_types;
all_level_types.push_back(std::make_pair(ng::level::SCENARIO, _("Scenarios")));
all_level_types.push_back(std::make_pair(ng::level::CAMPAIGN, _("Campaigns")));
all_level_types.push_back(std::make_pair(ng::level::USER_MAP, _("User Maps")));
all_level_types.push_back(std::make_pair(ng::level::USER_SCENARIO, _("User Scenarios")));
all_level_types.push_back(std::make_pair(ng::level::RANDOM_MAP, _("Random Maps")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::SCENARIO, _("Scenarios")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::CAMPAIGN, _("Campaigns")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::USER_MAP, _("User Maps")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::USER_SCENARIO, _("User Scenarios")));
all_level_types.push_back(std::make_pair(ng::level::TYPE::RANDOM_MAP, _("Random Maps")));
if (game_config::debug) {
all_level_types.push_back(std::make_pair(ng::level::SP_CAMPAIGN,
all_level_types.push_back(std::make_pair(ng::level::TYPE::SP_CAMPAIGN,
"SP Campaigns"));
}
@ -159,7 +159,7 @@ create::create(game_display& disp, const config& cfg, saved_game& state,
// Set level selection according to the preferences, if possible.
size_t type_index = 0;
BOOST_FOREACH(ng::level::TYPE type, available_level_types_) {
if (preferences::level_type() == type) {
if (preferences::level_type() == type.cast<int>()) {
break;
}
type_index++;
@ -227,7 +227,7 @@ create::create(game_display& disp, const config& cfg, saved_game& state,
void create::select_level_type_helper(const std::string & str)
{
for (size_t idx = 0; idx < available_level_types_.size(); idx++) {
if (ng::level::TYPE_to_string(available_level_types_[idx]) == str) {
if (ng::level::TYPE::enum_to_string(available_level_types_[idx]) == str) {
level_type_combo_.set_selected(idx);
init_level_type_changed(0);
process_event_impl(process_event_data(false, false, false));
@ -249,7 +249,7 @@ create::~create()
DBG_MP << "storing parameter values in preferences" << std::endl;
preferences::set_era(engine_.current_extra(ng::create_engine::ERA).id);
preferences::set_level(engine_.current_level().id());
preferences::set_level_type(engine_.current_level_type());
preferences::set_level_type(engine_.current_level_type().cast<int>());
preferences::set_modifications(engine_.active_mods());
} catch (...) {}
}
@ -291,8 +291,8 @@ void create::process_event_impl(const process_event_data & data)
engine_.prepare_for_era_and_mods();
if (engine_.current_level_type() == ng::level::CAMPAIGN ||
engine_.current_level_type() == ng::level::SP_CAMPAIGN) {
if (engine_.current_level_type() == ng::level::TYPE::CAMPAIGN ||
engine_.current_level_type() == ng::level::TYPE::SP_CAMPAIGN) {
std::string difficulty = engine_.select_campaign_difficulty();
if (difficulty == "CANCEL") {
@ -301,7 +301,7 @@ void create::process_event_impl(const process_event_data & data)
engine_.prepare_for_campaign(difficulty);
}
else if (engine_.current_level_type() == ng::level::SCENARIO)
else if (engine_.current_level_type() == ng::level::TYPE::SCENARIO)
{
engine_.prepare_for_scenario();
}
@ -427,11 +427,11 @@ void create::process_event_impl(const process_event_data & data)
set_description(engine_.current_level().description());
switch (engine_.current_level_type()) {
case ng::level::SCENARIO:
case ng::level::USER_MAP:
case ng::level::USER_SCENARIO:
case ng::level::RANDOM_MAP: {
switch (engine_.current_level_type().v) {
case ng::level::TYPE::SCENARIO:
case ng::level::TYPE::USER_MAP:
case ng::level::TYPE::USER_SCENARIO:
case ng::level::TYPE::RANDOM_MAP: {
ng::scenario* current_scenario =
dynamic_cast<ng::scenario*>(&engine_.current_level());
@ -443,8 +443,8 @@ void create::process_event_impl(const process_event_data & data)
break;
}
case ng::level::CAMPAIGN:
case ng::level::SP_CAMPAIGN: {
case ng::level::TYPE::CAMPAIGN:
case ng::level::TYPE::SP_CAMPAIGN: {
ng::campaign* current_campaign =
dynamic_cast<ng::campaign*>(&engine_.current_level());
@ -525,8 +525,8 @@ void create::synchronize_selections()
process_event();
}
if (engine_.current_level_type() != ng::level::CAMPAIGN &&
engine_.current_level_type() != ng::level::SP_CAMPAIGN) {
if (engine_.current_level_type() != ng::level::TYPE::CAMPAIGN &&
engine_.current_level_type() != ng::level::TYPE::SP_CAMPAIGN) {
if (engine_.current_level().id() !=
engine_.dependency_manager().get_scenario()) {

View file

@ -217,7 +217,7 @@ wait::~wait()
try {
if (get_result() == QUIT) {
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
game_config_manager::get()->
load_game_config_for_game(state_.classification());
@ -251,7 +251,7 @@ void wait::join_game(bool observe)
if (first_scenario_) {
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
const config* campaign = &game_config_manager::get()->
game_config().find_child("campaign", "id",
@ -259,7 +259,7 @@ void wait::join_game(bool observe)
const config* scenario = &game_config_manager::get()->
game_config().find_child("multiplayer", "id",
level_.child(lexical_cast<std::string>(game_classification::MULTIPLAYER))["id"]);
level_.child(lexical_cast<std::string>(game_classification::CAMPAIGN_TYPE::MULTIPLAYER))["id"]);
const config* era = &game_config_manager::get()->
game_config().find_child("era", "id", level_.child("era")["id"]);

View file

@ -74,7 +74,7 @@ static void show_carryover_message(saved_game& gamestate, playsingle_controller&
if (obs) {
title = _("Scenario Report");
} else if (res == VICTORY) {
} else if (res == LEVEL_RESULT::VICTORY) {
title = _("Victory");
report << "<b>" << _("You have emerged victorious!") << "</b>\n\n";
} else {
@ -93,7 +93,7 @@ static void show_carryover_message(saved_game& gamestate, playsingle_controller&
}
if (persistent_teams > 0 && ((has_next_scenario && end_level.proceed_to_next_level)||
gamestate.classification().campaign_type == game_classification::TEST))
gamestate.classification().campaign_type == game_classification::CAMPAIGN_TYPE::TEST))
{
gamemap map = playcontroller.get_map_const();
tod_manager tod = playcontroller.get_tod_manager_const();
@ -145,25 +145,25 @@ LEVEL_RESULT play_replay(display& disp, saved_game& gamestate, const config& gam
} catch(game::load_game_failed& e) {
ERR_NG << std::string(_("The game could not be loaded: ")) + " (game::load_game_failed) " + e.message << std::endl;
if (is_unit_test) {
return DEFEAT;
return LEVEL_RESULT::DEFEAT;
} else {
gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
}
} catch(quit_game_exception&) {
LOG_NG << "The replay was aborted\n";
return QUIT;
return LEVEL_RESULT::QUIT;
} catch(game::game_error& e) {
ERR_NG << std::string(_("Error while playing the game: ")) + " (game::game_error) " + e.message << std::endl;
if (is_unit_test) {
return DEFEAT;
return LEVEL_RESULT::DEFEAT;
} else {
gui2::show_error_message(disp.video(), std::string(_("Error while playing the game: ")) + e.message);
}
} catch(incorrect_map_format_error& e) {
ERR_NG << std::string(_("The game map could not be loaded: ")) + " (incorrect_map_format_error) " + e.message << std::endl;
if (is_unit_test) {
return DEFEAT;
return LEVEL_RESULT::DEFEAT;
} else {
gui2::show_error_message(disp.video(), std::string(_("The game map could not be loaded: ")) + e.message);
}
@ -171,13 +171,13 @@ LEVEL_RESULT play_replay(display& disp, saved_game& gamestate, const config& gam
ERR_NG << std::string("WML Exception: ") + e.user_message << std::endl;
ERR_NG << std::string("Dev Message: ") + e.dev_message << std::endl;
if (is_unit_test) {
return DEFEAT;
return LEVEL_RESULT::DEFEAT;
} else {
e.show(disp);
}
}
//TODO: when can this happen?
return VICTORY;
return LEVEL_RESULT::VICTORY;
}
static LEVEL_RESULT playsingle_scenario(const config& game_config,
@ -194,9 +194,9 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,
LEVEL_RESULT res = playcontroller.play_scenario(story);
if (res == QUIT)
if (res == LEVEL_RESULT::QUIT)
{
return QUIT;
return LEVEL_RESULT::QUIT;
}
end_level = playcontroller.get_end_level_data_const();
@ -227,14 +227,14 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
if (io_type == IO_CLIENT && playcontroller.is_host())
io_type = IO_SERVER;
if (res == QUIT)
if (res == LEVEL_RESULT::QUIT)
{
return QUIT;
return LEVEL_RESULT::QUIT;
}
end_level = playcontroller.get_end_level_data_const();
if(res != OBSERVER_END)
if(res != LEVEL_RESULT::OBSERVER_END)
{
//We need to call this before linger because it prints the defeated/victory message.
//(we want to see that message before entering the linger mode)
@ -261,7 +261,7 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
while(gamestate.valid())
{
LEVEL_RESULT res = VICTORY;
LEVEL_RESULT res = LEVEL_RESULT::VICTORY;
end_level_data end_level;
try {
@ -278,7 +278,7 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
config::const_child_itors story = gamestate.get_starting_pos().child_range("story");
#if !defined(ALWAYS_USE_MP_CONTROLLER)
if (game_type != game_classification::MULTIPLAYER) {
if (game_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
res = playsingle_scenario(game_config, tdata, disp, gamestate, story, skip_replay, end_level);
} else
#endif
@ -287,30 +287,30 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
}
} catch(game::load_game_failed& e) {
gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
return QUIT;
return LEVEL_RESULT::QUIT;
} catch(quit_game_exception&) {
LOG_NG << "The game was aborted\n";
return QUIT;
return LEVEL_RESULT::QUIT;
} catch(game::game_error& e) {
gui2::show_error_message(disp.video(), _("Error while playing the game: ") + e.message);
return QUIT;
return LEVEL_RESULT::QUIT;
} catch(incorrect_map_format_error& e) {
gui2::show_error_message(disp.video(), std::string(_("The game map could not be loaded: ")) + e.message);
return QUIT;
return LEVEL_RESULT::QUIT;
} catch (mapgen_exception& e) {
gui2::show_error_message(disp.video(), std::string(_("Map generator error: ") + e.message));
} catch(config::error& e) {
gui2::show_error_message(disp.video(), _("Error while reading the WML: ") + e.message);
return QUIT;
return LEVEL_RESULT::QUIT;
} catch(twml_exception& e) {
e.show(disp);
return QUIT;
return LEVEL_RESULT::QUIT;
}
if (is_unit_test) {
return res;
}
if(res == QUIT) {
if(res == LEVEL_RESULT::QUIT) {
return res;
}
// proceed_to_next_level <=> 'any human side recieved victory'
@ -335,7 +335,7 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
{
return res;
}
else if(res == OBSERVER_END)
else if(res == LEVEL_RESULT::OBSERVER_END)
{
// TODO: does it make sense to ask this question if we are currently the host?
const int dlg_res = gui2::show_message(disp.video(), _("Game Over"),
@ -350,9 +350,9 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
if (io_type == IO_CLIENT) {
// Opens mp::connect dialog to get a new gamestate.
mp::ui::result wait_res = mp::goto_mp_wait(gamestate, disp,
game_config, res == OBSERVER_END);
game_config, res == LEVEL_RESULT::OBSERVER_END);
if (wait_res == mp::ui::QUIT) {
return QUIT;
return LEVEL_RESULT::QUIT;
}
//The host should send the complete savegame now that also contains the carryvoer sides start.
@ -367,21 +367,21 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
gamestate.mp_settings().num_turns = starting_pos["turns"].to_int(-1);
gamestate.mp_settings().saved_game = false;
gamestate.mp_settings().use_map_settings
= starting_pos["force_lock_settings"].to_bool(game_type != game_classification::MULTIPLAYER);
= starting_pos["force_lock_settings"].to_bool(game_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
ng::connect_engine_ptr
connect_engine(new ng::connect_engine(gamestate,
!network_game, false));
if (starting_pos["allow_new_game"].to_bool(gamestate.mp_settings().show_connect)
|| (game_config::debug && network::nconnections() == 0 && game_type == game_classification::MULTIPLAYER)) {
|| (game_config::debug && network::nconnections() == 0 && game_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)) {
// Opens mp::connect dialog to allow users to
// make an adjustments for scenario.
// TODO: Fix this so that it works when network::nconnections() > 0 as well.
mp::ui::result connect_res = mp::goto_mp_connect(disp,
*connect_engine, game_config, gamestate.mp_settings().name);
if (connect_res == mp::ui::QUIT) {
return QUIT;
return LEVEL_RESULT::QUIT;
}
} else {
// Start the next scenario immediately.
@ -419,14 +419,14 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
symbols["scenario"] = gamestate.get_scenario_id();
message = utils::interpolate_variables_into_string(message, &symbols);
gui2::show_error_message(disp.video(), message);
return QUIT;
return LEVEL_RESULT::QUIT;
}
if (game_type == game_classification::SCENARIO){
if (game_type == game_classification::CAMPAIGN_TYPE::SCENARIO){
if (preferences::delete_saves()) {
savegame::clean_saves(gamestate.classification().label);
}
}
return VICTORY;
return LEVEL_RESULT::VICTORY;
}

View file

@ -11,6 +11,7 @@
#include "multiplayer_ui.hpp"
#include "playcampaign.hpp"
#include "resources.hpp"
#include "wml_exception.hpp"
namespace {
@ -29,10 +30,10 @@ bool enter_create_mode(game_display& disp, const config& game_config,
do {
ng::create_engine create_eng(disp, state);
create_eng.set_current_level_type(ng::level::SP_CAMPAIGN);
create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN);
std::vector<ng::create_engine::level_ptr> campaigns(
create_eng.get_levels_by_type_unfiltered(ng::level::SP_CAMPAIGN));
create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN));
if (campaigns.empty()) {
gui2::show_error_message(disp.video(),

View file

@ -547,7 +547,7 @@ bool game_launcher::play_test()
first_time = false;
state_.classification().campaign_type = game_classification::TEST;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST;
state_.classification().campaign_define = "TEST";
state_.set_carryover_sides_start(
@ -581,7 +581,7 @@ int game_launcher::unit_test()
first_time_unit = false;
state_.classification().campaign_type = game_classification::TEST;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST;
state_.classification().campaign_define = "TEST";
state_.set_carryover_sides_start(
config_of("next_scenario", test_scenario_)
@ -593,7 +593,7 @@ int game_launcher::unit_test()
try {
LEVEL_RESULT res = play_game(disp(),state_,game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types(), IO_SERVER, false, false, false, true);
if (!(res == VICTORY) || lg::broke_strict()) {
if (!(res == LEVEL_RESULT::VICTORY) || lg::broke_strict()) {
return 1;
}
} catch (game::load_game_exception &) {
@ -629,7 +629,7 @@ int game_launcher::unit_test()
try {
//LEVEL_RESULT res = play_game(disp(), state_, game_config_manager::get()->game_config(), IO_SERVER, false,false,false,true);
LEVEL_RESULT res = ::play_replay(disp(), state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types(), true);
if (!(res == VICTORY)) {
if (!(res == LEVEL_RESULT::VICTORY)) {
std::cerr << "Observed failure on replay" << std::endl;
return 4;
}
@ -666,7 +666,7 @@ bool game_launcher::play_render_image_mode()
return true;
}
state_.classification().campaign_type = game_classification::MULTIPLAYER;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
DBG_GENERAL << "Current campaign type: " << state_.classification().campaign_type << std::endl;
try {
@ -761,7 +761,7 @@ bool game_launcher::load_game()
statistics::clear_current_scenario();
}
if(state_.classification().campaign_type == game_classification::MULTIPLAYER) {
if(state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
state_.unify_controllers();
gui2::show_message(disp().video(), _("Warning") , _("This is a multiplayer scenario. Some parts of it may not work properly in single-player. It is recommended to load this scenario through the <b>Multiplayer</b> → <b>Load Game</b> dialog instead."), "", true, true);
}
@ -776,7 +776,7 @@ bool game_launcher::load_game()
void game_launcher::set_tutorial()
{
state_ = saved_game();
state_.classification().campaign_type = game_classification::TUTORIAL;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TUTORIAL;
state_.classification().campaign_define = "TUTORIAL";
state_.mp_settings().mp_era = "era_blank";
state_.mp_settings().show_connect = false;
@ -796,7 +796,7 @@ void game_launcher::mark_completed_campaigns(std::vector<config> &campaigns)
bool game_launcher::new_campaign()
{
state_ = saved_game();
state_.classification().campaign_type = game_classification::SCENARIO;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::SCENARIO;
state_.mp_settings().show_configure = false;
state_.mp_settings().show_connect = false;
@ -888,7 +888,7 @@ bool game_launcher::play_multiplayer()
int res;
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
//Print Gui only if the user hasn't specified any server
if( multiplayer_server_.empty() ){
@ -1014,7 +1014,7 @@ bool game_launcher::play_multiplayer_commandline()
// These are all the relevant lines taken literally from play_multiplayer() above
state_ = saved_game();
state_.classification().campaign_type = game_classification::MULTIPLAYER;
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
game_config_manager::get()->
load_game_config_for_game(state_.classification());
@ -1080,7 +1080,7 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload)
game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types());
// don't show The End for multiplayer scenario
// change this if MP campaigns are implemented
if(result == VICTORY && state_.classification().campaign_type != game_classification::MULTIPLAYER) {
if(result == LEVEL_RESULT::VICTORY && state_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
preferences::add_completed_campaign(state_.classification().campaign);
the_end(disp(), state_.classification().end_text, state_.classification().end_text_duration);
if(state_.classification().end_credits) {

View file

@ -72,16 +72,16 @@ void tadvanced_graphics_options::setup_scale_button(const std::string & case_id,
{
std::string pref_id = "scale_" + case_id;
tadvanced_graphics_options::SCALING_ALGORITHM algo = tadvanced_graphics_options::LEGACY_LINEAR;
tadvanced_graphics_options::SCALING_ALGORITHM algo = tadvanced_graphics_options::SCALING_ALGORITHM::LEGACY_LINEAR;
try {
algo = string_to_SCALING_ALGORITHM(preferences::get(pref_id));
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
} catch (bad_enum_cast &) {
preferences::set(pref_id, SCALING_ALGORITHM_to_string(algo));
preferences::set(pref_id, SCALING_ALGORITHM::enum_to_string(algo));
}
// algo is now synced with preference, and default value of linear if something went wrong
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM_to_string(button), false);
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM::enum_to_string(button), false);
b->set_value(algo == button);
connect_signal_mouse_left_click(*b, boost::bind(&tadvanced_graphics_options::scale_button_callback, this, pref_id, button, boost::ref(window)));
@ -89,22 +89,22 @@ void tadvanced_graphics_options::setup_scale_button(const std::string & case_id,
void tadvanced_graphics_options::scale_button_callback(std::string pref_id, SCALING_ALGORITHM me, twindow & window)
{
tadvanced_graphics_options::SCALING_ALGORITHM algo = tadvanced_graphics_options::LEGACY_LINEAR;
tadvanced_graphics_options::SCALING_ALGORITHM algo = tadvanced_graphics_options::SCALING_ALGORITHM::LEGACY_LINEAR;
try {
algo = string_to_SCALING_ALGORITHM(preferences::get(pref_id));
algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id));
} catch (bad_enum_cast &) {
preferences::set(pref_id, SCALING_ALGORITHM_to_string(algo));
preferences::set(pref_id, SCALING_ALGORITHM::enum_to_string(algo));
}
if (algo != me) {
image::flush_cache();
}
preferences::set(pref_id, SCALING_ALGORITHM_to_string(me));
preferences::set(pref_id, SCALING_ALGORITHM::enum_to_string(me));
for (size_t x = 0; x < SCALING_ALGORITHM_COUNT; ++x) {
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM_to_string(static_cast<SCALING_ALGORITHM>(x)), false);
b->set_value(x == static_cast<size_t>(me));
for (size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
ttoggle_button * b = &find_widget<ttoggle_button>(&window, pref_id + "_" + SCALING_ALGORITHM::enum_to_string(SCALING_ALGORITHM::from_int(x)), false);
b->set_value(x == me.cast<size_t>());
}
image::update_from_preferences();
@ -112,8 +112,8 @@ void tadvanced_graphics_options::scale_button_callback(std::string pref_id, SCAL
void tadvanced_graphics_options::setup_scale_case(const std::string & i, twindow & window)
{
for (size_t x = 0; x < SCALING_ALGORITHM_COUNT; ++x) {
setup_scale_button(i, static_cast<SCALING_ALGORITHM>(x), window);
for (size_t x = 0; x < SCALING_ALGORITHM::count; ++x) {
setup_scale_button(i, SCALING_ALGORITHM::from_int(x), window);
}
}

View file

@ -66,8 +66,6 @@ private:
void scale_button_callback(std::string, SCALING_ALGORITHM, twindow &);
};
MAKE_ENUM_STREAM_OPS2(tadvanced_graphics_options, SCALING_ALGORITHM)
} // end namespace gui2
#endif

View file

@ -118,7 +118,7 @@ void tcampaign_selection::pre_show(CVideo& video, twindow& window)
tmulti_page& multi_page
= find_widget<tmulti_page>(&window, "campaign_details", false);
FOREACH(const AUTO & level, engine_.get_levels_by_type_unfiltered(ng::level::SP_CAMPAIGN))
FOREACH(const AUTO & level, engine_.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN))
{
const config& campaign = level->data();

View file

@ -94,10 +94,10 @@ teditor_edit_side::teditor_edit_side(int side,
void teditor_edit_side::pre_show(CVideo& /*video*/, twindow& window)
{
register_controller_toggle(window, "human", team::HUMAN);
register_controller_toggle(window, "ai", team::AI);
register_controller_toggle(window, "null", team::EMPTY);
register_controller_toggle(window, "number", team::CONTROLLER(-1));
register_controller_toggle(window, "human", team::CONTROLLER::HUMAN);
register_controller_toggle(window, "ai", team::CONTROLLER::AI);
register_controller_toggle(window, "null", team::CONTROLLER::EMPTY);
register_controller_toggle(window, "number", team::CONTROLLER::from_int(-1));
}
void teditor_edit_side::register_controller_toggle(twindow& window,

View file

@ -282,8 +282,8 @@ void tgame_load::evaluate_summary_string(std::stringstream& str,
= lexical_cast<game_classification::CAMPAIGN_TYPE>(
campaign_type);
switch(ct) {
case game_classification::SCENARIO: {
switch(ct.v) {
case game_classification::CAMPAIGN_TYPE::SCENARIO: {
const std::string campaign_id = cfg_summary["campaign"];
const config* campaign = NULL;
if(!campaign_id.empty()) {
@ -308,13 +308,13 @@ void tgame_load::evaluate_summary_string(std::stringstream& str,
}
break;
}
case game_classification::MULTIPLAYER:
case game_classification::CAMPAIGN_TYPE::MULTIPLAYER:
str << _("Multiplayer");
break;
case game_classification::TUTORIAL:
case game_classification::CAMPAIGN_TYPE::TUTORIAL:
str << _("Tutorial");
break;
case game_classification::TEST:
case game_classification::CAMPAIGN_TYPE::TEST:
str << _("Test scenario");
break;
}

View file

@ -769,29 +769,29 @@ static surface scale_xbrz_helper(const surface & res, int w, int h)
static scaling_function select_algorithm(gui2::tadvanced_graphics_options::SCALING_ALGORITHM algo)
{
switch (algo)
switch (algo.v)
{
case gui2::tadvanced_graphics_options::LINEAR:
case gui2::tadvanced_graphics_options::SCALING_ALGORITHM::LINEAR:
{
scaling_function result = &scale_surface;
return result;
}
case gui2::tadvanced_graphics_options::NEAREST_NEIGHBOR:
case gui2::tadvanced_graphics_options::SCALING_ALGORITHM::NEAREST_NEIGHBOR:
{
scaling_function result = &scale_surface_nn;
return result;
}
case gui2::tadvanced_graphics_options::XBRZ_LIN:
case gui2::tadvanced_graphics_options::SCALING_ALGORITHM::XBRZ_LIN:
{
scaling_function result = &scale_xbrz_helper<scale_surface>;
return result;
}
case gui2::tadvanced_graphics_options::XBRZ_NN:
case gui2::tadvanced_graphics_options::SCALING_ALGORITHM::XBRZ_NN:
{
scaling_function result = &scale_xbrz_helper<scale_surface_nn>;
return result;
}
case gui2::tadvanced_graphics_options::LEGACY_LINEAR:
case gui2::tadvanced_graphics_options::SCALING_ALGORITHM::LEGACY_LINEAR:
{
scaling_function result = &scale_surface_legacy;
return result;
@ -1304,16 +1304,16 @@ std::string describe_versions()
bool update_from_preferences()
{
gui2::tadvanced_graphics_options::SCALING_ALGORITHM algo = gui2::tadvanced_graphics_options::LINEAR;
gui2::tadvanced_graphics_options::SCALING_ALGORITHM algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::LINEAR;
try {
algo = gui2::tadvanced_graphics_options::string_to_SCALING_ALGORITHM(preferences::get("scale_hex"));
algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::string_to_enum(preferences::get("scale_hex"));
} catch (bad_enum_cast &) {}
scale_to_hex_func = select_algorithm(algo);
algo = gui2::tadvanced_graphics_options::LINEAR;
algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::LINEAR;
try {
algo = gui2::tadvanced_graphics_options::string_to_SCALING_ALGORITHM(preferences::get("scale_zoom"));
algo = gui2::tadvanced_graphics_options::SCALING_ALGORITHM::string_to_enum(preferences::get("scale_zoom"));
} catch (bad_enum_cast &) {}
scale_to_zoom_func = select_algorithm(algo);

View file

@ -107,7 +107,7 @@ void status_table(display& gui, int selected)
leader_bools.push_back(false);
leader_name = "Unknown";
}
// if (gamestate_.classification().campaign_type == game_classification::MULTIPLAYER)
// if (gamestate_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)
// leader_name = teams[n].current_player();
#ifndef LOW_MEM

14
src/make_enum.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "make_enum.hpp"
#include "wml_exception.hpp"
#include "game_config.hpp"
namespace make_enum_detail
{
void debug_conversion_error(const std::string& temp, const bad_enum_cast & e)
{
if (!temp.empty() && game_config::debug) {
FAIL( e.what() );
}
}
}

View file

@ -12,8 +12,20 @@
See the COPYING file for more details.
*/
#ifndef MAKE_ENUM_HPP
#define MAKE_ENUM_HPP
#include <cassert>
#include <exception>
#include <string>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor.hpp>
#include <istream>
#include <ostream>
// Defines the MAKE_ENUM macro,
// and companion macro MAKE_ENUM_STREAM_OPS, which also enables lexical_cast
// Currently this has 1 argument and 2 argument variety.
/**
@ -26,51 +38,28 @@
#include "make_enum.hpp"
namespace foo {
MAKE_ENUM(enumname,
(val1, "name1")
(val2, "name2")
(val3, "name3")
)
MAKE_ENUM_STREAM_OPS1(enumname)
}
class bar {
public:
MAKE_ENUM(another,
(val1, "name1")
(val2, "name2")
(val3, "name3")
)
};
MAKE_ENUM_STREAM_OPS2(bar , another)
MAKE_ENUM(enumname,
(val1, "name1")
(val2, "name2")
(val3, "name3")
)
*/
/**
*
* What it does:
*
* generates an enum foo::enumname, with functions to convert to and from string
* const size_t foo::enumname_COUNT, which counts the number of possible values,
* generates a struct enumname which holds an enum and gives function to convert to and from string
* const size_t enumname::count, which counts the number of possible values,
*
*
* foo::string_to_enumname(std::string); //throws bad_enum_cast
* foo::string_to_enumname(std::string, foo::enumname default); //no throw
* foo::enumname_to_string(foo::enumname); //no throw
* enumname enumname::string_to_enum(std::string); //throws bad_enum_cast
* enumname enumname::string_to_enum(std::string, enumname default); //no throw
* std::string enumname::enum_to_string(enumname); //no throw
*
* The stream ops define
* std::ostream & operator<< (std::ostream &, foo::enumname) //no throw. asserts false if enum has an illegal value.
* std::istream & operator>> (std::istream &, foo::enumname &) //throws twml_exception including line number and arguments, IF game_config::debug is true.
* std::ostream & operator<< (std::ostream &, enumname) //no throw. asserts false if enum has an illegal value.
* std::istream & operator>> (std::istream &, enumname &) //throws twml_exception including line number and arguments, IF game_config::debug is true.
* //doesn't throw except in that case, and correctly sets istream state to failing always.
* //this is generally a recoverable exception that only shows a temporary dialog box,
* //and is caught at many places in the gui code. you may safely catch it and ignore it,
@ -97,161 +86,159 @@ MAKE_ENUM_STREAM_OPS2(bar , another)
*
**/
#ifndef MAKE_ENUM_HPP
#define MAKE_ENUM_HPP
#include "game_config.hpp"
#include "global.hpp"
#include "wml_exception.hpp"
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <cassert>
#include <cstddef>
#include <exception>
#include <iostream>
#include <string>
class bad_enum_cast : public std::exception
{
public:
bad_enum_cast(const std::string& enumname, const std::string& str)
: message("Failed to convert String \"" + str + "\" to type " + enumname)
{}
bad_enum_cast(const std::string& enumname, const std::string str)
: message("Failed to convert String \"" + str + "\" to type " + enumname)
{}
virtual ~bad_enum_cast() throw() {}
const char * what() const throw()
{
return message.c_str();
}
const char * what() const throw()
{
return message.c_str();
}
private:
const std::string message;
std::string message;
};
// Add compiler directive suppressing unused variable warning
#if defined(__GNUC__) || defined(__clang__) || defined(__MINGW32__)
#define ATTR_UNUSED __attribute__((unused))
#else
#define ATTR_UNUSED
#endif
namespace make_enum_detail
{
void debug_conversion_error(const std::string& tmp, const bad_enum_cast & e);
}
#define CAT2( A, B ) A ## B
#define CAT3( A, B, C ) A ## B ## C
//Clang apparently doesn't support __VA_ARGS__ with --C98 (???)
//Can try this again when we upgrade
/*
#define GET_COUNT(_1, _2, _3, _4, _5, COUNT, ...) COUNT
#define VA_SIZE(...) GET_COUNT(__VA_ARGS__, 5, 4, 3, 2, 1)
#define VA_SELECT(MNAME, ...) CAT2(MNAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
*/
#define EXPANDENUMVALUE( a, b ) a ,
#define EXPANDENUMTYPE( r, data, elem ) EXPANDENUMVALUE elem
#define EXPANDENUMFUNCTIONRETURN( a, b ) if ( str == b ) return a;
#define EXPANDENUMFUNCTION( r, data, elem ) EXPANDENUMFUNCTIONRETURN elem
#define EXPANDENUMFUNCTIONREVRETURN( a, b ) if ( val == a ) return b;
#define EXPANDENUMFUNCTIONREV( r, data, elem ) EXPANDENUMFUNCTIONREVRETURN elem
#define EXPANDENUMFUNCTIONCOUNTRETURN( a, b ) 1+
#define EXPANDENUMFUNCTIONCOUNT( r, data, elem ) EXPANDENUMFUNCTIONCOUNTRETURN elem
#define ADD_PAREN_1( A, B ) ((A, B)) ADD_PAREN_2
#define ADD_PAREN_2( A, B ) ((A, B)) ADD_PAREN_1
#define ADD_PAREN_1_END
#define ADD_PAREN_2_END
#define MAKEPAIRS( INPUT ) BOOST_PP_CAT(ADD_PAREN_1 INPUT,_END)
#define PP_SEQ_FOR_EACH_I_PAIR(macro, data, pairs) BOOST_PP_SEQ_FOR_EACH_I(macro, data, MAKEPAIRS(pairs))
#define MAKEENUMTYPE( NAME, CONTENT ) \
enum NAME { \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMTYPE, , MAKEPAIRS(CONTENT)) \
#define CAT2( A, B ) A ## B
#define CAT3( A, B, C ) A ## B ## C
#define EXPAND_ENUMVALUE_NORMAL(r, data, i, record) \
BOOST_PP_TUPLE_ELEM(2, 0, record) = i,
#define EXPAND_ENUMFUNC_NORMAL(r, data, i, record) \
if(data == BOOST_PP_TUPLE_ELEM(2, 1, record)) return BOOST_PP_TUPLE_ELEM(2, 0, record);
#define EXPAND_ENUMFUNCREV_NORMAL(r, data, i, record) \
if(data == BOOST_PP_TUPLE_ELEM(2, 0, record)) return BOOST_PP_TUPLE_ELEM(2, 1, record);
#define EXPAND_ENUMFUNCTIONCOUNT(r, data, i, record) \
+ 1
class enum_tag
{
};
#define MAKE_ENUM(NAME, CONTENT) \
struct NAME : public enum_tag \
{ \
enum type \
{ \
PP_SEQ_FOR_EACH_I_PAIR(EXPAND_ENUMVALUE_NORMAL, ,CONTENT) \
}; \
type v; \
NAME(type v) : v(v) {} \
/*We don't want a default contructor but we need one in order to make lexical_cast working*/ \
NAME() : v() {} \
/*operator type() const { return v; } */\
static NAME string_to_enum (const std::string& str, NAME def) \
{ \
PP_SEQ_FOR_EACH_I_PAIR(EXPAND_ENUMFUNC_NORMAL, str , CONTENT) \
return def; \
} \
static NAME string_to_enum (const std::string& str) \
{ \
PP_SEQ_FOR_EACH_I_PAIR(EXPAND_ENUMFUNC_NORMAL, str , CONTENT) \
throw bad_enum_cast( #NAME , str); \
} \
static std::string enum_to_string (NAME val) \
{ \
PP_SEQ_FOR_EACH_I_PAIR(EXPAND_ENUMFUNCREV_NORMAL, val.v , CONTENT) \
assert(false && "Corrupted enum found with identifier NAME"); \
throw "assertion ignored"; \
} \
friend std::ostream& operator<< (std::ostream & os, NAME val) \
{ \
os << enum_to_string(val); \
return os; \
} \
friend std::ostream& operator<< (std::ostream & os, NAME::type val) \
{ \
return (os << NAME(val)); \
} \
friend std::istream& operator>> (std::istream & is, NAME& val) \
{ \
std::istream::sentry s(is, true); \
if(!s) return is; \
std::string temp; \
is >> temp; \
try { \
val = string_to_enum(temp); \
} catch (const bad_enum_cast & e) {\
is.setstate(std::ios::failbit); \
make_enum_detail::debug_conversion_error(temp, e); \
} \
return is; \
} \
friend std::istream& operator>> (std::istream & os, NAME::type& val) \
{ \
return (os >> reinterpret_cast< NAME &>(val)); \
} \
friend bool operator==(NAME v1, NAME v2) \
{ \
return v1.v == v2.v; \
} \
friend bool operator==(NAME::type v1, NAME v2) \
{ \
return v1 == v2.v; \
} \
friend bool operator==(NAME v1, NAME::type v2) \
{ \
return v1.v == v2; \
} \
friend bool operator!=(NAME v1, NAME v2) \
{ \
return v1.v != v2.v; \
} \
friend bool operator!=(NAME::type v1, NAME v2) \
{ \
return v1 != v2.v; \
} \
friend bool operator!=(NAME v1, NAME::type v2) \
{ \
return v1.v != v2; \
} \
/* operator< is used for by std::map and similar */ \
friend bool operator<(NAME v1, NAME v2) \
{ \
return v1.v < v2.v; \
} \
template<typename T> \
T cast() \
{ \
return static_cast<T>(v); \
} \
static NAME from_int(int i) \
{ \
return static_cast<type>(i); \
} \
static const size_t count = 0 PP_SEQ_FOR_EACH_I_PAIR(EXPAND_ENUMFUNCTIONCOUNT, , CONTENT);\
private: \
/*prevent automatic conversion for any other built-in types such as bool, int, etc*/ \
/*template<typename T> \
operator T () const; */\
/* For some unknown reason the following version doesnt compile: */ \
/* template<typename T, typename = typename boost::enable_if<Cond>::type> \
operator T(); */\
};
#define MAKEENUMCAST( NAME, PREFIX, CONTENT, COUNT_VAR ) \
PREFIX NAME ATTR_UNUSED CAT3(string_to_, NAME, _default) (const std::string& str, NAME def) \
{ \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMFUNCTION, , MAKEPAIRS(CONTENT)) \
return def; \
} \
PREFIX NAME ATTR_UNUSED CAT2(string_to_,NAME) (const std::string& str) \
{ \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMFUNCTION, , MAKEPAIRS(CONTENT)) \
throw bad_enum_cast( #NAME , str); \
} \
PREFIX std::string ATTR_UNUSED CAT2(NAME,_to_string) (NAME val) \
{ \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMFUNCTIONREV, , MAKEPAIRS(CONTENT)) \
assert(false && "Corrupted enum found with identifier NAME"); \
throw 42; \
} \
\
PREFIX const size_t ATTR_UNUSED COUNT_VAR = \
BOOST_PP_SEQ_FOR_EACH(EXPANDENUMFUNCTIONCOUNT, , MAKEPAIRS(CONTENT)) \
0;
#define MAKE_ENUM( NAME, CONTENT ) \
MAKEENUMTYPE( NAME, CONTENT ) \
MAKEENUMCAST( NAME, static , CONTENT, CAT2(NAME,_COUNT) )
#define MAKE_ENUM_STREAM_OPS1( NAME ) \
inline std::ostream& operator<< (std::ostream & os, NAME val) \
{ \
os << CAT2(NAME,_to_string) ( val ); \
return os; \
} \
inline std::istream& operator>> (std::istream & is, NAME & val) \
{ \
std::istream::sentry s(is, true); \
if(!s) return is; \
std::string temp; \
is >> temp; \
try { \
val = CAT2(string_to_, NAME) ( temp ); \
} catch (bad_enum_cast & e) { \
is.setstate(std::ios::failbit); \
if (!temp.empty() && game_config::debug) { \
FAIL( e.what() ); \
} \
} \
return is; \
} \
#define MAKE_ENUM_STREAM_OPS2( NAMESPACE, NAME ) \
inline std::ostream& operator<< (std::ostream & os, NAMESPACE::NAME val) \
{ \
os << CAT2(NAMESPACE::NAME,_to_string) ( val ); \
return os; \
} \
inline std::istream& operator>> (std::istream & is, NAMESPACE::NAME & val) \
{ \
std::istream::sentry s(is, true); \
if(!s) return is; \
std::string temp; \
is >> temp; \
try { \
val = CAT2(NAMESPACE::string_to_,NAME) ( temp ); \
} catch (bad_enum_cast & e) {\
is.setstate(std::ios::failbit); \
if (!temp.empty() && game_config::debug) { \
FAIL( e.what() ); \
} \
} \
return is; \
} \
//Clang apparently doesn't support __VA_ARGS__ with --C98 (???)
//Can try this again when we upgrade
//#define MAKE_ENUM_STREAM_OPS VA_SELECT(MAKE_ENUM_STREAM_OPS, __VA_ARGS__)
#endif

View file

@ -269,7 +269,7 @@ void menu_handler::status_table(int selected)
leader_name = "Unknown";
}
if (pc_.get_classification().campaign_type == game_classification::MULTIPLAYER)
if (pc_.get_classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)
leader_name = teams()[n].current_player();
} else {
@ -2810,9 +2810,9 @@ void console_handler::do_controller()
return;
}
std::string report = team::CONTROLLER_to_string (menu_handler_.teams()[side_num - 1].controller());
std::string report = team::CONTROLLER::enum_to_string (menu_handler_.teams()[side_num - 1].controller());
if (!menu_handler_.teams()[side_num - 1].is_proxy_human()) {
report += " (" + team::PROXY_CONTROLLER_to_string(menu_handler_.teams()[side_num - 1].proxy_controller()) + ")";
report += " (" + team::PROXY_CONTROLLER::enum_to_string(menu_handler_.teams()[side_num - 1].proxy_controller()) + ")";
}
print(get_cmd(), report);

View file

@ -60,7 +60,7 @@ mp_game_settings::mp_game_settings() :
allow_observers(false),
shuffle_sides(false),
saved_game(false),
random_faction_mode(DEFAULT),
random_faction_mode(RANDOM_FACTION_MODE::DEFAULT),
options(),
addons()
{}
@ -95,7 +95,7 @@ mp_game_settings::mp_game_settings(const config& cfg)
, allow_observers(cfg["observer"].to_bool())
, shuffle_sides(cfg["shuffle_sides"].to_bool())
, saved_game(cfg["savegame"].to_bool())
, random_faction_mode(string_to_RANDOM_FACTION_MODE_default(cfg["random_faction_mode"].str(), DEFAULT))
, random_faction_mode(RANDOM_FACTION_MODE::string_to_enum(cfg["random_faction_mode"].str(), RANDOM_FACTION_MODE::DEFAULT))
, options(cfg.child_or_empty("options"))
, addons()
{
@ -136,7 +136,7 @@ config mp_game_settings::to_config() const
cfg["mp_random_start_time"] = random_start_time;
cfg["observer"] = allow_observers;
cfg["shuffle_sides"] = shuffle_sides;
cfg["random_faction_mode"] = RANDOM_FACTION_MODE_to_string (random_faction_mode);
cfg["random_faction_mode"] = RANDOM_FACTION_MODE::enum_to_string (random_faction_mode);
cfg["savegame"] = saved_game;
cfg.add_child("options", options);

View file

@ -91,6 +91,4 @@ struct mp_game_settings : public savegame::savegame_config
void update_addon_requirements(const config & addon_cfg);
};
MAKE_ENUM_STREAM_OPS2(mp_game_settings, RANDOM_FACTION_MODE)
#endif

View file

@ -296,7 +296,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
//store persistent teams
saved_game_.set_snapshot(config());
return VICTORY; // this is probably only a story scenario, i.e. has its endlevel in the prestart event
return LEVEL_RESULT::VICTORY; // this is probably only a story scenario, i.e. has its endlevel in the prestart event
}
if(linger_) {
LOG_NG << "resuming from loaded linger state...\n";
@ -305,7 +305,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
if(!is_observer()) {
persist_.end_transaction();
}
return VICTORY;
return LEVEL_RESULT::VICTORY;
}
pump().fire(is_victory ? "victory" : "defeat");
{ // Block for set_scontext_synced_base
@ -317,7 +317,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
}
if(is_observer()) {
gui2::show_transient_message(gui_->video(), _("Game Over"), _("The game is over."));
return OBSERVER_END;
return LEVEL_RESULT::OBSERVER_END;
}
// If we're a player, and the result is victory/defeat, then send
// a message to notify the server of the reason for the game ending.
@ -339,7 +339,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(
sound::play_music_once(end_music);
}
persist_.end_transaction();
return is_victory ? VICTORY : DEFEAT;
return is_victory ? LEVEL_RESULT::VICTORY : LEVEL_RESULT::DEFEAT;
} catch(const game::load_game_exception &) {
// Loading a new game is effectively a quit.
//
@ -360,11 +360,11 @@ LEVEL_RESULT playsingle_controller::play_scenario(
if(disconnect) {
throw network::error();
} else {
return QUIT;
return LEVEL_RESULT::QUIT;
}
}
return QUIT;
return LEVEL_RESULT::QUIT;
}
void playsingle_controller::play_turn()

View file

@ -190,7 +190,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
team::CONTROLLER new_controller = team::CONTROLLER();
try {
new_controller = team::string_to_CONTROLLER (change["controller"].str());
new_controller = team::CONTROLLER::string_to_enum(change["controller"].str());
} catch (bad_enum_cast & e) {
ERR_NW << "Bad [change_controller] message from server:\n" << e.what() << std::endl << change.debug() << std::endl;
return PROCESS_CONTINUE;
@ -237,13 +237,13 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
team::CONTROLLER ctrl = team::CONTROLLER();
try {
ctrl = team::string_to_CONTROLLER(controller);
ctrl = team::CONTROLLER::string_to_enum(controller);
} catch (bad_enum_cast & e) {
ERR_NW << "unknown controller type issued from server on side drop: " << e.what() << std::endl;
throw network::error("");
}
if (ctrl == team::AI){
if (ctrl == team::CONTROLLER::AI){
resources::gameboard->side_drop_to(side_drop, ctrl);
return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
}
@ -304,8 +304,8 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
switch(action) {
case 0:
resources::controller->on_not_observer();
resources::gameboard->side_drop_to(side_drop, team::HUMAN, team::PROXY_AI);
change_controller(side_drop, team::CONTROLLER_to_string(team::HUMAN));
resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_AI);
change_controller(side_drop, team::CONTROLLER::enum_to_string(team::CONTROLLER::HUMAN));
resources::controller->maybe_do_init_side();
@ -313,15 +313,15 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
case 1:
resources::controller->on_not_observer();
resources::gameboard->side_drop_to(side_drop, team::HUMAN, team::PROXY_HUMAN);
change_controller(side_drop, team::CONTROLLER_to_string(team::HUMAN));
resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_HUMAN);
change_controller(side_drop, team::CONTROLLER::enum_to_string(team::CONTROLLER::HUMAN));
resources::controller->maybe_do_init_side();
return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
case 2:
resources::gameboard->side_drop_to(side_drop, team::HUMAN, team::PROXY_IDLE);
change_controller(side_drop, team::CONTROLLER_to_string(team::HUMAN));
resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_IDLE);
change_controller(side_drop, team::CONTROLLER::enum_to_string(team::CONTROLLER::HUMAN));
return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
@ -335,7 +335,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
{
// Server thinks this side is ours now so in case of error transferring side we have to make local state to same as what server thinks it is.
resources::gameboard->side_drop_to(side_drop, team::HUMAN, team::PROXY_IDLE);
resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_IDLE);
}
const size_t index = static_cast<size_t>(action - first_observer_option_idx);
@ -345,8 +345,8 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
size_t i = index - observers.size();
change_side_controller(side_drop, allies[i]->current_player());
} else {
resources::gameboard->side_drop_to(side_drop, team::HUMAN, team::PROXY_AI);
change_controller(side_drop, team::CONTROLLER_to_string(team::HUMAN));
resources::gameboard->side_drop_to(side_drop, team::CONTROLLER::HUMAN, team::PROXY_CONTROLLER::PROXY_AI);
change_controller(side_drop, team::CONTROLLER::enum_to_string(team::CONTROLLER::HUMAN));
}
return restart ? PROCESS_RESTART_TURN : PROCESS_CONTINUE;
}

View file

@ -72,14 +72,14 @@ LEVEL_RESULT play_replay_level(const config& game_config, const tdata_cache & td
play_replay_level_main_loop(*rc, is_unit_test);
if(rc->is_regular_game_end())
{
// return rc->get_end_level_data_const().is_victory ? VICTORY : DEFEAT;
//The replay contained the whole scenario, returns VICTORY regardless of the original outcome.
return VICTORY;
// return rc->get_end_level_data_const().is_victory ? LEVEL_RESULT::VICTORY : LEVEL_RESULT::DEFEAT;
//The replay contained the whole scenario, returns LEVEL_RESULT::VICTORY regardless of the original outcome.
return LEVEL_RESULT::VICTORY;
}
else
{
//The replay was finished without reaching the scenario end.
return QUIT;
return LEVEL_RESULT::QUIT;
}
}
@ -115,7 +115,7 @@ replay_controller::replay_controller(const config& level,
, gameboard_start_(gamestate_.board_)
, tod_manager_start_(level)
, is_playing_(false)
, vision_(state_of_game.classification().campaign_type == game_classification::MULTIPLAYER ? CURRENT_TEAM : HUMAN_TEAM)
, vision_(state_of_game.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER ? CURRENT_TEAM : HUMAN_TEAM)
{
hotkey_handler_.reset(new hotkey_handler(*this, saved_game_)); //upgrade hotkey handler to the replay controller version

View file

@ -386,7 +386,7 @@ void extract_summary_from_config(config& cfg_save, config& cfg_summary)
{
BOOST_FOREACH(const config &side, snapshot.child_range("side"))
{
if (side["controller"] != team::CONTROLLER_to_string(team::HUMAN)) {
if (side["controller"] != team::CONTROLLER::enum_to_string(team::CONTROLLER::HUMAN)) {
continue;
}

View file

@ -183,8 +183,8 @@ void saved_game::expand_scenario()
game_config_manager::get()->load_game_config_for_game(this->classification());
const config& game_config = game_config_manager::get()->game_config();
const config& scenario = game_config.find_child(lexical_cast_default<std::string>
(classification().campaign_type == game_classification::SCENARIO ?
game_classification::MULTIPLAYER : classification().campaign_type),
(classification().campaign_type == game_classification::CAMPAIGN_TYPE::SCENARIO ?
game_classification::CAMPAIGN_TYPE::MULTIPLAYER : classification().campaign_type),
"id", carryover_["next_scenario"]);
if(scenario)
{

View file

@ -245,7 +245,7 @@ bool loadgame::load_game(
}
#if 0
gamestate_.classification().campaign_define = load_config_["campaign_define"].str();
gamestate_.classification().campaign_type = lexical_cast_default<game_classification::CAMPAIGN_TYPE> (load_config_["campaign_type"].str(), game_classification::SCENARIO);
gamestate_.classification().campaign_type = lexical_cast_default<game_classification::CAMPAIGN_TYPE> (load_config_["campaign_type"].str(), game_classification::CAMPAIGN_TYPE::SCENARIO);
gamestate_.classification().campaign_xtra_defines = utils::split(load_config_["campaign_extra_defines"]);
gamestate_.classification().version = load_config_["version"].str();
gamestate_.classification().difficulty = load_config_["difficulty"].str();
@ -339,7 +339,7 @@ bool loadgame::load_multiplayer_game()
return false;
}
if(gamestate_.classification().campaign_type != game_classification::MULTIPLAYER) {
if(gamestate_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
gui2::show_transient_error_message(gui_.video(), _("This is not a multiplayer save."));
return false;
}

View file

@ -100,6 +100,7 @@
#include "util.hpp" // for lexical_cast
#include "variable.hpp" // for vconfig, etc
#include "variable_info.hpp"
#include "wml_exception.hpp"
#include <boost/bind.hpp> // for bind_t, bind
#include <boost/foreach.hpp> // for auto_any_base, etc
@ -1448,7 +1449,7 @@ int game_lua_kernel::impl_game_config_get(lua_State *L)
const game_classification & classification = play_controller_.get_classification();
return_string_attrib("campaign_type", lexical_cast<std::string>(classification.campaign_type));
if(classification.campaign_type==game_classification::MULTIPLAYER) {
if(classification.campaign_type==game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
return_cfgref_attrib("mp_settings", mp_settings.to_config());
return_cfgref_attrib("era", game_config_manager::get()->game_config().find_child("era","id",mp_settings.mp_era));
//^ finds the era with name matching mp_era, and creates a lua reference from the config of that era.

View file

@ -70,8 +70,8 @@ static int impl_side_get(lua_State *L)
return_string_attrib("team_name", t.team_name());
return_string_attrib("name", t.name());
return_string_attrib("color", t.color());
return_cstring_attrib("controller", team::CONTROLLER_to_string(t.controller()).c_str());
return_string_attrib("defeat_condition", team::DEFEAT_CONDITION_to_string(t.defeat_condition()));
return_cstring_attrib("controller", team::CONTROLLER::enum_to_string(t.controller()).c_str());
return_string_attrib("defeat_condition", team::DEFEAT_CONDITION::enum_to_string(t.defeat_condition()));
return_bool_attrib("lost", t.lost());
if (strcmp(m, "recruit") == 0) {

View file

@ -75,9 +75,9 @@ size_t plugins_manager::size() {
plugins_manager::STATUS plugins_manager::get_status(size_t idx) {
if (idx < plugins_.size()) {
if (!plugins_[idx].thread) {
return plugins_manager::NONE;
return plugins_manager::STATUS::NONE;
} else {
return plugins_[idx].thread->is_running() ? plugins_manager::RUNNING : plugins_manager::STOPPED;
return plugins_[idx].thread->is_running() ? plugins_manager::STATUS::RUNNING : plugins_manager::STATUS::STOPPED;
}
}
throw std::runtime_error("index out of bounds");
@ -208,8 +208,9 @@ void plugins_manager::play_slice(const plugins_context & ctxt)
bool plugins_manager::any_running()
{
for (size_t i = 0; i < size(); ++i) {
if (RUNNING == get_status(i)) {
if (STATUS::RUNNING == get_status(i)) {
return true;
}
}

View file

@ -75,6 +75,4 @@ private:
boost::scoped_ptr<application_lua_kernel> kernel_;
};
MAKE_ENUM_STREAM_OPS2(plugins_manager, STATUS)
#endif

View file

@ -41,7 +41,7 @@ int get_turns(const std::string& value)
int get_village_gold(const std::string& value, game_classification::CAMPAIGN_TYPE gametype)
{
return lexical_cast_in_range<int>(value, (gametype == game_classification::SCENARIO ? 1 : 2), 1, 5);
return lexical_cast_in_range<int>(value, (gametype == game_classification::CAMPAIGN_TYPE::SCENARIO ? 1 : 2), 1, 5);
}
int get_village_support(const std::string& value)

View file

@ -58,7 +58,7 @@ namespace settings {
*
* @returns the village gold
*/
int get_village_gold(const std::string& value, game_classification::CAMPAIGN_TYPE gametype = game_classification::MULTIPLAYER);
int get_village_gold(const std::string& value, game_classification::CAMPAIGN_TYPE gametype = game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
/**
* Gets the village unit level support.

View file

@ -228,7 +228,7 @@ bool side_filter::match_internal(const team &t) const
ERR_NG << "ignoring controller= in SSF due to danger of OOS errors" << std::endl;
else
{
if(cfg_controller.str() != team::CONTROLLER_to_string (t.controller()))
if(cfg_controller.str() != team::CONTROLLER::enum_to_string (t.controller()))
return false;
}
}

View file

@ -95,8 +95,8 @@ team::team_info::team_info() :
objectives(),
objectives_changed(false),
controller(),
defeat_condition(team::NO_LEADER),
proxy_controller(team::PROXY_HUMAN),
defeat_condition(team::DEFEAT_CONDITION::NO_LEADER),
proxy_controller(team::PROXY_CONTROLLER::PROXY_HUMAN),
share_maps(false),
share_view(false),
disallow_observers(false),
@ -137,7 +137,7 @@ void team::team_info::read(const config &cfg)
allow_player = cfg["allow_player"].to_bool(true);
chose_random = cfg["chose_random"].to_bool(false);
no_leader = cfg["no_leader"].to_bool();
defeat_condition = lexical_cast_default<team::DEFEAT_CONDITION>(cfg["defeat_condition"].str(), team::NO_LEADER);
defeat_condition = lexical_cast_default<team::DEFEAT_CONDITION>(cfg["defeat_condition"].str(), team::DEFEAT_CONDITION::NO_LEADER);
lost = cfg["lost"].to_bool(false);
hidden = cfg["hidden"].to_bool();
no_turn_confirmation = cfg["suppress_end_turn_confirmation"].to_bool();
@ -195,15 +195,15 @@ void team::team_info::read(const config &cfg)
else
support_per_village = lexical_cast_default<int>(village_support, game_config::village_support);
controller = lexical_cast_default<team::CONTROLLER> (cfg["controller"].str(), team::AI);
controller = lexical_cast_default<team::CONTROLLER> (cfg["controller"].str(), team::CONTROLLER::AI);
//TODO: Why do we read disallow observers differently when controller is empty?
if (controller == EMPTY) {
if (controller == CONTROLLER::EMPTY) {
disallow_observers = cfg["disallow_observers"].to_bool(true);
}
//override persistence flag if it is explicitly defined in the config
//by default, persistence of a team is set depending on the controller
persistent = cfg["persistent"].to_bool(this->controller == HUMAN || this->controller == NETWORK);
persistent = cfg["persistent"].to_bool(this->controller == CONTROLLER::HUMAN || this->controller == CONTROLLER::NETWORK);
//========================================================
//END OF MESSY CODE
@ -241,11 +241,11 @@ void team::team_info::write(config& cfg) const
cfg["allow_player"] = allow_player;
cfg["chose_random"] = chose_random;
cfg["no_leader"] = no_leader;
cfg["defeat_condition"] = DEFEAT_CONDITION_to_string(defeat_condition);
cfg["defeat_condition"] = DEFEAT_CONDITION::enum_to_string(defeat_condition);
cfg["hidden"] = hidden;
cfg["suppress_end_turn_confirmation"] = no_turn_confirmation;
cfg["scroll_to_leader"] = scroll_to_leader;
cfg["controller"] = CONTROLLER_to_string (controller);
cfg["controller"] = CONTROLLER::enum_to_string(controller);
cfg["recruit"] = utils::join(can_recruit);
cfg["share_maps"] = share_maps;
cfg["share_view"] = share_view;
@ -472,10 +472,10 @@ void team::change_controller_by_wml(const std::string& new_controller_string)
try
{
CONTROLLER new_controller = lexical_cast<CONTROLLER> (new_controller_string);
if(new_controller == NETWORK || new_controller == NETWORK_AI) {
if(new_controller == CONTROLLER::NETWORK || new_controller == CONTROLLER::NETWORK_AI) {
throw bad_enum_cast(new_controller_string, "CONTROLLER"); //catched below
}
if(new_controller == EMPTY && resources::controller->current_side() == this->side()) {
if(new_controller == CONTROLLER::EMPTY && resources::controller->current_side() == this->side()) {
//We dont allow changing the currently active side to "null" controlled.
throw bad_enum_cast(new_controller_string, "CONTROLLER"); //catched below
}
@ -492,11 +492,11 @@ void team::change_controller_by_wml(const std::string& new_controller_string)
// In case this->is_empty() this side wasn't contorlled by any client yet, we need to assign controll to some client
// We assign controll to the currentyl active client, and asume the server does the same.
bool is_networked = this->is_empty() ? (*teams)[resources::controller->current_side() - 1].is_network() : this->is_network();
if(is_networked && new_controller == AI) {
new_controller = NETWORK_AI;
if(is_networked && new_controller == CONTROLLER::AI) {
new_controller = CONTROLLER::NETWORK_AI;
}
if(is_networked && new_controller == HUMAN) {
new_controller = NETWORK;
if(is_networked && new_controller == CONTROLLER::HUMAN) {
new_controller = CONTROLLER::NETWORK;
}
change_controller(new_controller);
}

View file

@ -50,8 +50,6 @@ namespace wb {
class team : public savegame::savegame_config
{
public:
//enum CONTROLLER { HUMAN, AI, NETWORK, NETWORK_AI, IDLE, EMPTY };
//enum DEFEAT_CONDITION {NO_LEADER, NO_UNITS, NEVER, ALWAYS};
MAKE_ENUM(CONTROLLER,
(HUMAN, "human")
@ -255,40 +253,38 @@ public:
CONTROLLER controller() const { return info_.controller; }
const std::string& color() const { return info_.color; }
void set_color(const std::string& color) { info_.color = color; }
//bool is_human() const { return info_.controller == HUMAN; }
//bool is_ai() const { return info_.controller == AI; }
bool is_empty() const { return info_.controller == EMPTY; }
bool is_empty() const { return info_.controller == CONTROLLER::EMPTY; }
bool is_local() const { return is_local_human() || is_local_ai(); }
bool is_network() const { return is_network_human() || is_network_ai(); }
bool is_local_human() const { return info_.controller == HUMAN; }
bool is_local_ai() const { return info_.controller == AI; }
bool is_network_human() const { return info_.controller == NETWORK; }
bool is_network_ai() const { return info_.controller == NETWORK_AI; }
bool is_local_human() const { return info_.controller == CONTROLLER::HUMAN; }
bool is_local_ai() const { return info_.controller == CONTROLLER::AI; }
bool is_network_human() const { return info_.controller == CONTROLLER::NETWORK; }
bool is_network_ai() const { return info_.controller == CONTROLLER::NETWORK_AI; }
void make_human() { info_.controller = HUMAN; }
void make_ai() { info_.controller = AI; }
void make_human() { info_.controller = CONTROLLER::HUMAN; }
void make_ai() { info_.controller = CONTROLLER::AI; }
void change_controller(const std::string& new_controller) {
info_.controller = lexical_cast_default<CONTROLLER> (new_controller, AI);
info_.controller = lexical_cast_default<CONTROLLER> (new_controller, CONTROLLER::AI);
}
void change_controller_by_wml(const std::string& new_controller);
void change_controller(CONTROLLER controller) { info_.controller = controller; }
PROXY_CONTROLLER proxy_controller() const { return info_.proxy_controller; }
bool is_proxy_human() const { return info_.proxy_controller == PROXY_HUMAN; }
bool is_droid() const { return info_.proxy_controller == PROXY_AI; }
bool is_idle() const { return info_.proxy_controller == PROXY_IDLE; }
bool is_proxy_human() const { return info_.proxy_controller == PROXY_CONTROLLER::PROXY_HUMAN; }
bool is_droid() const { return info_.proxy_controller == PROXY_CONTROLLER::PROXY_AI; }
bool is_idle() const { return info_.proxy_controller == PROXY_CONTROLLER::PROXY_IDLE; }
void make_droid() { info_.proxy_controller = PROXY_AI; }
void make_idle() { info_.proxy_controller = PROXY_IDLE; }
void make_proxy_human() { info_.proxy_controller = PROXY_HUMAN; }
void make_droid() { info_.proxy_controller = PROXY_CONTROLLER::PROXY_AI; }
void make_idle() { info_.proxy_controller = PROXY_CONTROLLER::PROXY_IDLE; }
void make_proxy_human() { info_.proxy_controller = PROXY_CONTROLLER::PROXY_HUMAN; }
void clear_proxy() { make_proxy_human(); }
void change_proxy(PROXY_CONTROLLER proxy) { info_.proxy_controller = proxy; }
void toggle_droid() { info_.proxy_controller = (info_.proxy_controller == PROXY_AI ) ? PROXY_HUMAN : PROXY_AI; }
void toggle_idle() { info_.proxy_controller = (info_.proxy_controller == PROXY_IDLE) ? PROXY_HUMAN : PROXY_IDLE; }
void toggle_droid() { info_.proxy_controller = (info_.proxy_controller == PROXY_CONTROLLER::PROXY_AI ) ? PROXY_CONTROLLER::PROXY_HUMAN : PROXY_CONTROLLER::PROXY_AI; }
void toggle_idle() { info_.proxy_controller = (info_.proxy_controller == PROXY_CONTROLLER::PROXY_IDLE) ? PROXY_CONTROLLER::PROXY_HUMAN : PROXY_CONTROLLER::PROXY_IDLE; }
const std::string& team_name() const { return info_.team_name; }
const t_string &user_team_name() const { return info_.user_team_name; }
@ -414,10 +410,6 @@ private:
boost::shared_ptr<wb::side_actions> planned_actions_;
};
MAKE_ENUM_STREAM_OPS2(team, CONTROLLER)
MAKE_ENUM_STREAM_OPS2(team, PROXY_CONTROLLER)
MAKE_ENUM_STREAM_OPS2(team, DEFEAT_CONDITION)
//function which will validate a side. Throws game::game_error
//if the side is invalid
void validate_side(int side); //throw game::game_error

View file

@ -268,14 +268,14 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
if(!tod_type.empty()) {
const std::vector<std::string>& vals = utils::split(tod_type);
if(tod.lawful_bonus<0) {
if(std::find(vals.begin(),vals.end(),lexical_cast<std::string>(unit_type::CHAOTIC)) == vals.end()) {
if(std::find(vals.begin(),vals.end(),lexical_cast<std::string>(unit_type::ALIGNMENT::CHAOTIC)) == vals.end()) {
return false;
}
} else if(tod.lawful_bonus>0) {
if(std::find(vals.begin(),vals.end(),lexical_cast<std::string>(unit_type::LAWFUL)) == vals.end()) {
if(std::find(vals.begin(),vals.end(),lexical_cast<std::string>(unit_type::ALIGNMENT::LAWFUL)) == vals.end()) {
return false;
}
} else if(std::find(vals.begin(),vals.end(),lexical_cast<std::string>(unit_type::NEUTRAL)) == vals.end()) {
} else if(std::find(vals.begin(),vals.end(),lexical_cast<std::string>(unit_type::ALIGNMENT::NEUTRAL)) == vals.end()) {
return false;
}
}

View file

@ -529,7 +529,7 @@ struct twrapper<gui2::tcampaign_selection>
static gui2::tcampaign_selection* create()
{
static saved_game state;
state.classification().campaign_type = game_classification::SCENARIO;
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::SCENARIO;
static ng::create_engine ng(test_utils::get_fake_display(-1, -1), state);
return new gui2::tcampaign_selection(ng);
}
@ -541,7 +541,7 @@ struct twrapper<gui2::tcampaign_settings>
static gui2::tcampaign_settings* create()
{
static saved_game state;
state.classification().campaign_type = game_classification::SCENARIO;
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::SCENARIO;
static ng::create_engine ng(test_utils::get_fake_display(-1, -1), state);
return new gui2::tcampaign_settings(ng);
}

View file

@ -26,8 +26,6 @@ namespace foo {
(con2, "name2")
(con3, "name3")
)
MAKE_ENUM_STREAM_OPS1(enumname)
}
@ -44,17 +42,14 @@ foo::enumname lexical_cast<std::string> ( std::string str ) throws bad_lexical_c
*/
class bar {
public:
public:
MAKE_ENUM(another,
(val1, "name1")
(val2, "name2")
(val3, "name3")
)
};
MAKE_ENUM_STREAM_OPS2(bar,another)
/** Tests begin **/
@ -62,11 +57,11 @@ BOOST_AUTO_TEST_SUITE ( test_make_enum )
BOOST_AUTO_TEST_CASE ( test_make_enum_namespace )
{
foo::enumname e = foo::string_to_enumname_default("name2", foo::con1); //returns con2
foo::enumname e = foo::enumname::string_to_enum("name2", foo::enumname::con1); //returns con2
BOOST_CHECK_EQUAL ( e, foo::con2 );
BOOST_CHECK_EQUAL ( e, foo::enumname::con2 );
std::string str = foo::enumname_to_string(foo::con1); //returns "name1"
std::string str = foo::enumname::enum_to_string(foo::enumname::con1); //returns "name1"
BOOST_CHECK_EQUAL ( str, "name1" );
@ -103,11 +98,11 @@ BOOST_AUTO_TEST_CASE ( test_make_enum_namespace )
BOOST_AUTO_TEST_CASE ( test_make_enum_class )
{
bar::another e = bar::string_to_another_default("name2", bar::val1); //returns val2
bar::another e = bar::another::string_to_enum("name2", bar::another::val1); //returns val2
BOOST_CHECK_EQUAL ( e, bar::val2 );
BOOST_CHECK_EQUAL ( e, bar::another::val2 );
std::string str = bar::another_to_string(bar::val1); //returns "name1"
std::string str = bar::another::enum_to_string(bar::another::val1); //returns "name1"
BOOST_CHECK_EQUAL ( str, "name1" );

View file

@ -77,7 +77,7 @@ struct mp_connect_fixture {
config_manager->init_game_config(game_config_manager::NO_FORCE_RELOAD);
state.reset(new saved_game());
state->classification().campaign_type = game_classification::MULTIPLAYER;
state->classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
config_manager->load_game_config_for_game(state->classification());
state->mp_settings().mp_era = "era_default";
@ -86,7 +86,7 @@ struct mp_connect_fixture {
state->mp_settings().saved_game = false;
state->set_scenario(config_manager->
game_config().find_child(lexical_cast<std::string>(game_classification::MULTIPLAYER), "id", state->mp_settings().name));
game_config().find_child(lexical_cast<std::string>(game_classification::CAMPAIGN_TYPE::MULTIPLAYER), "id", state->mp_settings().name));
state->mp_settings().num_turns = state->get_starting_pos()["turns"];

View file

@ -114,7 +114,7 @@ namespace test_utils {
source_.type_key(current_time_++, SDLK_RETURN);
saved_game& state = end->get_state();
state.classification().campaign_type = game_classification::TEST;
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST;
state.set_carryover_sides_start(
config_of("next_scenario", id_)
);

View file

@ -95,7 +95,6 @@ namespace conditional {
(OR, "or")
(NOT, "not")
)
MAKE_ENUM_STREAM_OPS1(TYPE)
}
/// This class lazily parses an attribute value to a vector of strings
@ -182,7 +181,7 @@ public:
const std::string& cond_name = cond.get_key();
try {
conditional::TYPE type = conditional::string_to_TYPE(cond_name); // throws bad_enum_cast if we don't get a string match with any enum
conditional::TYPE type = conditional::TYPE::string_to_enum(cond_name); // throws bad_enum_cast if we don't get a string match with any enum
const vconfig& cond_filter = cond.get_child();
@ -339,14 +338,14 @@ bool basic_unit_filter_impl::matches(const unit & u, const map_location& loc) co
// Handle [and], [or], and [not] with in-order precedence
for (size_t i = 0; i < cond_children_.size(); i++) {
switch (cond_child_types_[i]) {
case conditional::AND:
switch (cond_child_types_[i].v) {
case conditional::TYPE::AND:
matches = matches && cond_children_[i].matches(u,loc);
break;
case conditional::OR:
case conditional::TYPE::OR:
matches = matches || cond_children_[i].matches(u,loc);
break;
case conditional::NOT:
case conditional::TYPE::NOT:
matches = matches && !cond_children_[i].matches(u,loc);
}
}

View file

@ -149,7 +149,7 @@ unit_type::unit_type(const config &cfg, const std::string & parent_id) :
advances_to_(),
experience_needed_(0),
in_advancefrom_(false),
alignment_(unit_type::NEUTRAL),
alignment_(unit_type::ALIGNMENT::NEUTRAL),
movement_type_(),
possibleTraits_(),
genders_(),
@ -198,7 +198,7 @@ void unit_type::build_full(const movement_type_map &mv_types,
} else {
BOOST_FOREACH(const config &t, race_->additional_traits())
{
if (alignment_ != unit_type::NEUTRAL || t["id"] != "fearless")
if (alignment_ != unit_type::ALIGNMENT::NEUTRAL || t["id"] != "fearless")
possibleTraits_.add_child("trait", t);
}
}
@ -269,7 +269,7 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
big_profile_ = cfg_["profile"].str();
adjust_profile(small_profile_, big_profile_, image_);
alignment_ = lexical_cast_default<unit_type::ALIGNMENT>(cfg_["alignment"].str(), unit_type::NEUTRAL);
alignment_ = lexical_cast_default<unit_type::ALIGNMENT>(cfg_["alignment"].str(), unit_type::ALIGNMENT::NEUTRAL);
for (int i = 0; i < 2; ++i) {
if (gender_types_[i])
@ -846,19 +846,17 @@ bool unit_type::resistance_filter_matches(const config& cfg, bool attacker, cons
/** Implementation detail of unit_type::alignment_description */
MAKE_ENUM (ALIGNMENT_FEMALE_VARIATION,
(FEMALE_LAWFUL, N_("female^lawful"))
(LAWFUL, N_("female^lawful"))
(FEMALE_NEUTRAL, N_("female^neutral"))
(FEMALE_CHAOTIC, N_("female^chaotic"))
(FEMALE_LIMINAL, N_("female^liminal"))
(CHAOTIC, N_("female^chaotic"))
(LIMINAL, N_("female^liminal"))
)
MAKE_ENUM_STREAM_OPS1(ALIGNMENT_FEMALE_VARIATION)
std::string unit_type::alignment_description(ALIGNMENT align, unit_race::GENDER gender)
{
std::string str = std::string();
if (gender == unit_race::FEMALE) {
ALIGNMENT_FEMALE_VARIATION fem = static_cast<ALIGNMENT_FEMALE_VARIATION> (align);
ALIGNMENT_FEMALE_VARIATION fem = align.cast<ALIGNMENT_FEMALE_VARIATION::type>();
str = lexical_cast<std::string>(fem);
} else {
str = lexical_cast<std::string>(align);

View file

@ -140,7 +140,6 @@ public:
int experience_needed(bool with_acceleration=true) const;
//enum ALIGNMENT { LAWFUL, NEUTRAL, CHAOTIC, LIMINAL };
MAKE_ENUM (ALIGNMENT,
(LAWFUL, N_("lawful"))
(NEUTRAL, N_("neutral"))
@ -285,8 +284,6 @@ private:
std::vector<tportrait> portraits_;
};
MAKE_ENUM_STREAM_OPS2(unit_type, ALIGNMENT)
class unit_type_data
: private boost::noncopyable
{