The Battle for Wesnoth  1.15.1+dev
game_classification.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "game_classification.hpp"
16 
17 #include "config.hpp"
18 #include "log.hpp"
20 #include "game_version.hpp"
21 
22 static lg::log_domain log_engine("engine");
23 #define ERR_NG LOG_STREAM(err, log_engine)
24 #define WRN_NG LOG_STREAM(warn, log_engine)
25 #define LOG_NG LOG_STREAM(info, log_engine)
26 #define DBG_NG LOG_STREAM(debug, log_engine)
27 
28 /// The default difficulty setting for campaigns.
29 const std::string DEFAULT_DIFFICULTY("NORMAL");
30 
32  : label(cfg["label"])
33  , version(cfg["version"])
34  , campaign_type(
35  cfg["campaign_type"].to_enum<game_classification::CAMPAIGN_TYPE>(game_classification::CAMPAIGN_TYPE::SCENARIO))
36  , campaign_define(cfg["campaign_define"])
37  , campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"]))
38  , scenario_define(cfg["scenario_define"])
39  , era_define(cfg["era_define"])
40  , mod_defines(utils::split(cfg["mod_defines"]))
41  , campaign(cfg["campaign"])
42  , campaign_name(cfg["campaign_name"])
43  , abbrev(cfg["abbrev"])
44  , end_credits(cfg["end_credits"].to_bool(true))
45  , end_text(cfg["end_text"])
46  , end_text_duration(cfg["end_text_duration"])
47  , difficulty(cfg["difficulty"].empty() ? DEFAULT_DIFFICULTY : cfg["difficulty"].str())
48  , random_mode(cfg["random_mode"])
49  , oos_debug(cfg["oos_debug"].to_bool(false))
50 {
51 }
52 
54 {
55  config cfg;
56  cfg["label"] = label;
57  cfg["version"] = game_config::wesnoth_version.str();
58  cfg["campaign_type"] = campaign_type.to_string();
59  cfg["campaign_define"] = campaign_define;
60  cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines);
61  cfg["scenario_define"] = scenario_define;
62  cfg["era_define"] = era_define;
63  cfg["mod_defines"] = utils::join(mod_defines);
64  cfg["campaign"] = campaign;
65  cfg["campaign_name"] = campaign_name;
66  cfg["abbrev"] = abbrev;
67  cfg["end_credits"] = end_credits;
68  cfg["end_text"] = end_text;
69  cfg["end_text_duration"] = std::to_string(end_text_duration);
70  cfg["difficulty"] = difficulty;
71  cfg["random_mode"] = random_mode;
72  cfg["oos_debug"] = oos_debug;
73 
74  return cfg;
75 }
76 
78 {
79  if(this->campaign_type == CAMPAIGN_TYPE::MULTIPLAYER) {
80  return this->campaign.empty() ? "multiplayer" : "scenario";
81  }
82 
83  return this->campaign_type.to_string();
84 }
85 
87 {
88  return this->campaign_type == CAMPAIGN_TYPE::MULTIPLAYER && this->campaign.empty();
89 }
unsigned int end_text_duration
for how long the end-of-campaign text is shown
bool end_credits
whether to show the standard credits at the end
std::string label
Name of the game (e.g.
Interfaces for manipulating version numbers of engine, add-ons, etc.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::string campaign_name
The name of the campaign being played.
const std::string DEFAULT_DIFFICULTY("NORMAL")
The default difficulty setting for campaigns.
Definitions for the interface to Wesnoth Markup Language (WML).
std::vector< std::string > split(const std::string &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
static lg::log_domain log_engine("engine")
std::string campaign_define
If there is a define the campaign uses to customize data.
std::string end_text
end-of-campaign text
std::string campaign
The id of the campaign being played.
std::string era_define
If there is a define the era uses to customize data.
std::string abbrev
the campaign abbreviation
std::vector< std::string > campaign_xtra_defines
more customization of data
std::string scenario_define
If there is a define the scenario uses to customize data.
std::vector< std::string > mod_defines
If there are defines the modifications use to customize data.
game_classification()=default
const version_info wesnoth_version(VERSION)
std::string difficulty
The difficulty level the game is being played on.
Standard logging facilities (interface).
std::string str() const
Serializes the version number into string form.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
std::string get_tagname() const