The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game_classification.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 "global.hpp"
16 #include "game_classification.hpp"
17 #include "game_config.hpp"
18 #include "config.hpp"
19 #include "util.hpp"
21 #include "log.hpp"
22 
23 static lg::log_domain log_engine("engine");
24 #define ERR_NG LOG_STREAM(err, log_engine)
25 #define WRN_NG LOG_STREAM(warn, log_engine)
26 #define LOG_NG LOG_STREAM(info, log_engine)
27 #define DBG_NG LOG_STREAM(debug, log_engine)
28 
29 /// The default difficulty setting for campaigns.
30 const std::string DEFAULT_DIFFICULTY("NORMAL");
31 
33  label(),
34  version(),
35  campaign_type(),
36  campaign_define(),
37  campaign_xtra_defines(),
38  scenario_define(),
39  era_define(),
40  mod_defines(),
41  campaign(),
42  abbrev(),
43  end_credits(true),
44  end_text(),
45  end_text_duration(),
46  difficulty(DEFAULT_DIFFICULTY),
47  random_mode(""),
48  oos_debug(false)
49  {}
50 
52  label(cfg["label"]),
53  version(cfg["version"]),
54  campaign_type(cfg["campaign_type"].to_enum<game_classification::CAMPAIGN_TYPE>(game_classification::CAMPAIGN_TYPE::SCENARIO)),
55  campaign_define(cfg["campaign_define"]),
56  campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"])),
57  scenario_define(cfg["scenario_define"]),
58  era_define(cfg["era_define"]),
59  mod_defines(utils::split(cfg["mod_defines"])),
60  campaign(cfg["campaign"]),
61  abbrev(cfg["abbrev"]),
62  end_credits(cfg["end_credits"].to_bool(true)),
63  end_text(cfg["end_text"]),
64  end_text_duration(cfg["end_text_duration"]),
65  difficulty(cfg["difficulty"].empty() ? DEFAULT_DIFFICULTY : cfg["difficulty"].str()),
66  random_mode(cfg["random_mode"]),
67  oos_debug(cfg["oos_debug"].to_bool(false))
68  {}
69 
71  label(gc.label),
72  version(gc.version),
73  campaign_type(gc.campaign_type),
74  campaign_define(gc.campaign_define),
75  campaign_xtra_defines(gc.campaign_xtra_defines),
76  scenario_define(gc.scenario_define),
77  era_define(gc.era_define),
78  mod_defines(gc.mod_defines),
79  campaign(gc.campaign),
80  abbrev(gc.abbrev),
81  end_credits(gc.end_credits),
82  end_text(gc.end_text),
83  end_text_duration(gc.end_text_duration),
84  difficulty(gc.difficulty),
85  random_mode(gc.random_mode),
86  oos_debug(gc.oos_debug)
87 {
88 }
89 
91 {
92  config cfg;
93 
94  cfg["label"] = label;
95  cfg["version"] = game_config::version;
96  cfg["campaign_type"] = campaign_type.to_string();
97  cfg["campaign_define"] = campaign_define;
98  cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines);
99  cfg["scenario_define"] = scenario_define;
100  cfg["era_define"] = era_define;
101  cfg["mod_defines"] = utils::join(mod_defines);
102  cfg["campaign"] = campaign;
103  cfg["abbrev"] = abbrev;
104  cfg["end_credits"] = end_credits;
105  cfg["end_text"] = end_text;
106  cfg["end_text_duration"] = std::to_string(end_text_duration);
107  cfg["difficulty"] = difficulty;
108  cfg["random_mode"] = random_mode;
109  cfg["oos_debug"] = oos_debug;
110  return cfg;
111 }
112 
114 {
115  if(this->campaign_type == CAMPAIGN_TYPE::MULTIPLAYER) {
116  return this->campaign.empty() ? "multiplayer" : "scenario";
117  }
118  else {
119  return this->campaign_type.to_string();
120  }
121 }
122 
124 {
125  return this->campaign_type == CAMPAIGN_TYPE::MULTIPLAYER && this->campaign.empty();
126 }
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.
std::string get_tagname() const
const std::string DEFAULT_DIFFICULTY("NORMAL")
The default difficulty setting for campaigns.
Definitions for the interface to Wesnoth Markup Language (WML).
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 campaign being played
Templates and utility-routines for strings and numbers.
std::string era_define
If there is a define the era uses to customize data.
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
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.
std::string difficulty
The difficulty level the game is being played on.
Standard logging facilities (interface).
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
const std::string version
Definition: game_config.cpp:48
GLsizei const GLcharARB ** string
Definition: glew.h:4503