mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-08 00:36:25 +00:00
Game Classification: added convenience type check functions
Shortens a bunch of code
This commit is contained in:
parent
158cb4ed7c
commit
4b12410086
@ -84,24 +84,19 @@ config game_classification::to_config() const
|
||||
|
||||
std::string game_classification::get_tagname() const
|
||||
{
|
||||
if(this->campaign_type == CAMPAIGN_TYPE::MULTIPLAYER) {
|
||||
return this->campaign.empty() ? "multiplayer" : "scenario";
|
||||
if(is_multiplayer()) {
|
||||
return campaign.empty() ? "multiplayer" : "scenario";
|
||||
}
|
||||
|
||||
if(this->campaign_type == CAMPAIGN_TYPE::TUTORIAL) {
|
||||
if(is_tutorial()) {
|
||||
return "scenario";
|
||||
}
|
||||
|
||||
return this->campaign_type.to_string();
|
||||
return campaign_type.to_string();
|
||||
}
|
||||
|
||||
bool game_classification::is_normal_mp_game() const
|
||||
namespace
|
||||
{
|
||||
return this->campaign_type == CAMPAIGN_TYPE::MULTIPLAYER && this->campaign.empty();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// helper objects for saved_game::expand_mp_events()
|
||||
struct modevents_entry
|
||||
{
|
||||
|
@ -31,11 +31,6 @@ public:
|
||||
game_classification() = default;
|
||||
explicit game_classification(const config& cfg);
|
||||
|
||||
config to_config() const;
|
||||
std::string get_tagname() const;
|
||||
bool is_normal_mp_game() const;
|
||||
std::set<std::string> active_addons(const std::string& scenario_id) const;
|
||||
|
||||
std::string label; /**< Name of the game (e.g. name of save file). */
|
||||
std::string version; /**< Version game was created with. */
|
||||
MAKE_ENUM (CAMPAIGN_TYPE, /**< Type of the game - campaign, multiplayer etc. */
|
||||
@ -64,4 +59,33 @@ public:
|
||||
std::string difficulty = DEFAULT_DIFFICULTY; /**< The difficulty level the game is being played on. */
|
||||
std::string random_mode = "";
|
||||
bool oos_debug = false;
|
||||
|
||||
config to_config() const;
|
||||
std::string get_tagname() const;
|
||||
std::set<std::string> active_addons(const std::string& scenario_id) const;
|
||||
|
||||
bool is_normal_mp_game() const
|
||||
{
|
||||
return is_multiplayer() && campaign.empty();
|
||||
}
|
||||
|
||||
bool is_scenario() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::SCENARIO;
|
||||
}
|
||||
|
||||
bool is_multiplayer() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
}
|
||||
|
||||
bool is_test() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::TEST;
|
||||
}
|
||||
|
||||
bool is_tutorial() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::TUTORIAL;
|
||||
}
|
||||
};
|
||||
|
@ -668,9 +668,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::CAMPAIGN_TYPE::MULTIPLAYER);
|
||||
classification.is_multiplayer());
|
||||
game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest &&
|
||||
classification.campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
|
||||
classification.is_multiplayer());
|
||||
|
||||
//
|
||||
// NOTE: these deques aren't used here, but the objects within are utilized as RAII helpers.
|
||||
|
@ -904,7 +904,7 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine, const
|
||||
update_controller_options();
|
||||
|
||||
// Tweak the controllers.
|
||||
if(parent_.state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::SCENARIO && cfg_["controller"].blank()) {
|
||||
if(parent_.state_.classification().is_scenario() && cfg_["controller"].blank()) {
|
||||
cfg_["controller"] = "ai";
|
||||
}
|
||||
|
||||
|
@ -258,11 +258,10 @@ create_engine::create_engine(saved_game& state)
|
||||
state_.clear();
|
||||
state_.classification().campaign_type = type;
|
||||
|
||||
game_config_manager::get()->load_game_config_for_create(type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER);
|
||||
game_config_manager::get()->load_game_config_for_create(state_.classification().is_multiplayer());
|
||||
|
||||
// Initialize dependency_manager_ after refreshing game config.
|
||||
dependency_manager_.reset(new depcheck::manager(
|
||||
game_config_, type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER));
|
||||
dependency_manager_.reset(new depcheck::manager(game_config_, state_.classification().is_multiplayer()));
|
||||
|
||||
// TODO: the editor dir is already configurable, is the preferences value
|
||||
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/maps", &user_map_names_,
|
||||
@ -279,7 +278,7 @@ create_engine::create_engine(saved_game& state)
|
||||
|
||||
state_.mp_settings().saved_game = mp_game_settings::SAVED_GAME_MODE::NONE;
|
||||
|
||||
for(const std::string& str : preferences::modifications(state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)) {
|
||||
for(const std::string& str : preferences::modifications(state_.classification().is_multiplayer())) {
|
||||
if(game_config_.find_child("modification", "id", str)) {
|
||||
state_.classification().active_mods.push_back(str);
|
||||
}
|
||||
@ -531,7 +530,7 @@ void create_engine::set_current_level(const std::size_t index)
|
||||
generator_.reset(nullptr);
|
||||
}
|
||||
|
||||
if(state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
|
||||
if(state_.classification().is_multiplayer()) {
|
||||
dependency_manager_->try_scenario(current_level().id());
|
||||
}
|
||||
}
|
||||
@ -733,7 +732,7 @@ void create_engine::init_all_levels()
|
||||
}
|
||||
|
||||
const std::string& type = data["type"];
|
||||
bool mp = state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
const bool mp = state_.classification().is_multiplayer();
|
||||
|
||||
if(type == "mp" || (type == "hybrid" && mp)) {
|
||||
type_map_[level::TYPE::CAMPAIGN].games.emplace_back(new campaign(data));
|
||||
@ -770,7 +769,7 @@ void create_engine::init_extras(const MP_EXTRA extra_type)
|
||||
for(const config& extra : game_config_.child_range(extra_name))
|
||||
{
|
||||
ng::depcheck::component_availability type = extra["type"].to_enum(default_availabilty);
|
||||
bool mp = state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
const bool mp = state_.classification().is_multiplayer();
|
||||
|
||||
if((type != ng::depcheck::component_availability::MP || mp) && (type != ng::depcheck::component_availability::SP || !mp) )
|
||||
{
|
||||
|
@ -93,9 +93,7 @@ void campaign_controller::show_carryover_message(
|
||||
}
|
||||
}
|
||||
|
||||
if(persistent_teams > 0 && ((has_next_scenario && end_level.proceed_to_next_level)||
|
||||
state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::TEST))
|
||||
{
|
||||
if(persistent_teams > 0 && ((has_next_scenario && end_level.proceed_to_next_level) || state_.classification().is_test())) {
|
||||
const gamemap& map = playcontroller.get_map_const();
|
||||
const tod_manager& tod = playcontroller.get_tod_manager_const();
|
||||
|
||||
@ -256,8 +254,6 @@ LEVEL_RESULT campaign_controller::play_game()
|
||||
|
||||
state_.expand_scenario();
|
||||
|
||||
game_classification::CAMPAIGN_TYPE game_type = state_.classification().campaign_type;
|
||||
|
||||
while(state_.valid()) {
|
||||
LEVEL_RESULT res = LEVEL_RESULT::VICTORY;
|
||||
end_level_data end_level;
|
||||
@ -276,7 +272,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
||||
state_.expand_mp_options();
|
||||
|
||||
#if !defined(ALWAYS_USE_MP_CONTROLLER)
|
||||
if(game_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER || is_replay_) {
|
||||
if(!state_.classification().is_multiplayer() || is_replay_) {
|
||||
res = playsingle_scenario(end_level);
|
||||
if(is_replay_) {
|
||||
return res;
|
||||
@ -376,7 +372,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
||||
|
||||
ng::connect_engine connect_engine(state_, false, mp_info_);
|
||||
|
||||
if(!connect_engine.can_start_game() || (game_config::debug && game_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)) {
|
||||
if(!connect_engine.can_start_game() || (game_config::debug && state_.classification().is_multiplayer())) {
|
||||
// Opens staging dialog to allow users to make an adjustments for scenario.
|
||||
if(!mp::goto_mp_connect(connect_engine, mp_info_ ? &mp_info_->connection : nullptr)) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
@ -414,7 +410,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
||||
return LEVEL_RESULT::QUIT;
|
||||
}
|
||||
|
||||
if(game_type == game_classification::CAMPAIGN_TYPE::SCENARIO) {
|
||||
if(state_.classification().is_scenario()) {
|
||||
if(preferences::delete_saves()) {
|
||||
savegame::clean_saves(state_.classification().label);
|
||||
}
|
||||
|
@ -727,7 +727,7 @@ bool game_launcher::load_game()
|
||||
statistics::clear_current_scenario();
|
||||
}
|
||||
|
||||
if(state_.classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
|
||||
if(state_.classification().is_multiplayer()) {
|
||||
state_.unify_controllers();
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ void game_stats::pre_show(window& window)
|
||||
}
|
||||
|
||||
if(resources::controller) {
|
||||
if(resources::controller->get_classification().campaign_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
|
||||
if(resources::controller->get_classification().is_multiplayer()) {
|
||||
leader_name = team.side_name();
|
||||
}
|
||||
}
|
||||
|
@ -4282,7 +4282,7 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
|
||||
}
|
||||
luaL_setfuncs(L, callbacks, 0);
|
||||
|
||||
if(play_controller_.get_classification().campaign_type == game_classification::CAMPAIGN_TYPE::TEST) {
|
||||
if(play_controller_.get_classification().is_test()) {
|
||||
static luaL_Reg const test_callbacks[] {
|
||||
{ "fire_wml_menu_item", &dispatch<&game_lua_kernel::intf_fire_wml_menu_item > },
|
||||
{ nullptr, nullptr }
|
||||
|
Loading…
x
Reference in New Issue
Block a user