42 #define ERR_CF LOG_STREAM(err, log_config)
45 #define WRN_MP LOG_STREAM(warn, log_mp_create_engine)
46 #define DBG_MP LOG_STREAM(debug, log_mp_create_engine)
51 if (str2.size() > str1.size()) {
55 for (
size_t i = 0;
i<str1.size() - str2.size()+1;
i++) {
57 for (
size_t j = 0; j<str2.size(); j++) {
58 if (std::tolower(str1[
i+j]) != std::tolower(str2[j])) {
76 return a->data()[
"rank"].to_int(1000) < b->data()[
"rank"].to_int(1000);
87 return data_[
"description"];
107 return data_[
"allow_era_choice"].to_bool(
true);
140 return map_.get() !=
nullptr;
168 data_[
"description"] =
_(
"Map could not be loaded: ") + e.
message;
172 data_[
"description"] =
_(
"Map could not be loaded.");
189 if (
map_.get() !=
nullptr) {
190 map_size <<
map_.get()->w();
192 map_size <<
map_.get()->h();
194 map_size <<
_(
"not available.");
197 return map_size.str();
202 if (
map_.get() !=
nullptr) {
205 const int map_positions =
map_->num_valid_starting_positions();
208 pos < map_positions; ++
pos) {
210 side[
"side"] =
pos + 1;
211 side[
"team_name"] =
"Team " + std::to_string(
pos + 1);
212 side[
"canrecruit"] =
true;
213 side[
"controller"] =
"human";
218 if (
scenario[
"allow_player"].to_bool(
true)) {
229 if (map !=
nullptr) {
245 if (
data_[
"description"].empty()) {
246 return _(
"User made map");
248 return data_[
"description"];
265 generate_whole_scenario_(data_.has_attribute(
"scenario_generation")),
266 generator_name_(generate_whole_scenario_ ? data_[
"scenario_generation"] : data_[
"map_generation"])
271 data_[
"description"] =
"Error: Random map found with missing generator information. Scenario should have a [generator] child.";
272 data_[
"error_message"] =
"missing [generator] tag";
280 data_[
"description"] =
"Error: Random map found with missing generator information. Scenario should have a [generator] child.";
281 data_[
"error_message"] =
"couldn't find 'scenario_generation' or 'map_generation' attribute";
296 return data_[
"name"];
301 return data_[
"description"];
327 allow_era_choice_(
level::allow_era_choice()),
348 return scale_surface(temp_image, image_rect.w, image_rect.h);
355 int min =
data_[
"min_players"].to_int(2);
356 int max =
data_[
"max_players"].to_int(2);
391 current_level_type_(),
392 current_level_index_(0),
393 current_era_index_(0),
394 current_mod_index_(0),
395 level_name_filter_(),
396 player_count_filter_(1),
404 user_scenario_names_(),
409 dependency_manager_(nullptr),
412 DBG_MP <<
"restoring game config\n";
430 DBG_MP <<
"initializing all levels, eras and mods\n";
439 game_classification::CAMPAIGN_TYPE::MULTIPLAYER)) {
441 game_config().find_child(
"modification",
"id", str))
459 DBG_MP <<
"initializing generated level data\n";
467 WRN_MP <<
"Tried to initialized generated level data on a level that wasn't a random map\n";
474 DBG_MP <<
"** replacing map ** \n";
484 DBG_MP <<
"** replacing scenario ** \n";
491 data[
"modify_placing"] =
"true";
495 data[
"description"] = description;
502 data[
"error_message"] = e.
what();
514 DBG_MP <<
"preparing mp_game_settings for new level\n";
527 "modification",
"id", mod_id)[
"define"].str());
533 DBG_MP <<
"preparing data for scenario by reloading game config\n";
545 DBG_MP <<
"preparing data for campaign by reloading game config\n";
547 if (difficulty !=
"") {
584 std::vector<std::string> difficulties;
588 difficulties.push_back(
d[
"define"]);
591 if(difficulties.empty()) {
596 if(difficulties.empty()) {
602 if(set_value != -1) {
603 if (set_value > static_cast<int>(difficulties.size())) {
604 std::cerr <<
"incorrect difficulty number: [" <<
605 set_value <<
"]. maximum is [" << difficulties.size() <<
"].\n";
607 }
else if (set_value < 1) {
608 std::cerr <<
"incorrect difficulty number: [" <<
609 set_value <<
"]. minimum is [1].\n";
612 return difficulties[set_value - 1];
627 DBG_MP <<
"preparing mp_game_settings for saved game\n";
641 DBG_MP <<
"prepare_for_other\n";
705 std::vector<std::string> menu_names;
716 const MP_EXTRA extra_type,
bool escape_markup)
const
718 std::vector<std::string>
names;
724 names.push_back(extra->name);
737 case level::TYPE::USER_SCENARIO: {
740 case level::TYPE::USER_MAP: {
743 case level::TYPE::RANDOM_MAP: {
746 case level::TYPE::CAMPAIGN: {
749 case level::TYPE::SP_CAMPAIGN:
759 const size_t index = (extra_type ==
ERA) ?
778 case level::TYPE::CAMPAIGN:
781 case level::TYPE::SP_CAMPAIGN:
787 case level::TYPE::RANDOM_MAP:
790 case level::TYPE::USER_MAP:
793 case level::TYPE::USER_SCENARIO:
801 assert(current_random_map);
902 if (sp_campaign->id() ==
id) {
916 if (extra->id ==
id) {
929 return level::TYPE::USER_MAP;
934 return level::TYPE::RANDOM_MAP;
944 return level::TYPE::USER_SCENARIO;
949 return level::TYPE::CAMPAIGN;
952 return level::TYPE::SP_CAMPAIGN;
972 DBG_MP <<
"getting parameter values" << std::endl;
982 if (
const config &generic_multiplayer =
984 "generic_multiplayer")) {
985 config gen_mp_data = generic_multiplayer;
988 int dep_index_offset = 0;
991 config user_map_data = gen_mp_data;
998 boost::scoped_ptr<gamemap> map;
1001 user_map_data[
"map_data"]));
1003 user_map_data[
"description"] =
_(
"Map could not be loaded: ") +
1024 i - dep_index_offset);
1029 dep_index_offset = 0;
1036 ERR_CF <<
"Caught a config error while parsing user made (editor) scenarios:\n" << e.
message << std::endl;
1042 if (new_scenario->id().empty())
continue;
1049 depinfo[
"id"] = data[
"id"];
1050 depinfo[
"name"] = data[
"name"];
1052 i - dep_index_offset++);
1059 if (!
data[
"allow_new_game"].to_bool(
true))
1062 if (!
data[
"campaign_id"].empty())
1065 if (
data.has_attribute(
"map_generation") ||
data.has_attribute(
"scenario_generation")) {
1082 if (type ==
"mp" || (type ==
"hybrid" && mp)) {
1087 if (type ==
"sp" || type.empty() || (type ==
"hybrid" && !mp)) {
1102 const std::string extra_name = (extra_type ==
ERA) ?
"era" :
"modification";
1103 ng::depcheck::component_availabilty default_availabilty = (extra_type ==
ERA) ? ng::depcheck::component_availabilty::MP : ng::depcheck::component_availabilty::HYBRID;
1106 ng::depcheck::component_availabilty
type = extra[
"type"].to_enum(default_availabilty);
1109 if((type != ng::depcheck::component_availabilty::MP || mp) && (type != ng::depcheck::component_availabilty::SP || !mp) )
1112 new_extras_metadata->id = extra[
"id"].str();
1113 new_extras_metadata->name = extra[
"name"].str();
1114 new_extras_metadata->description = extra[
"description"].str();
1116 extras.push_back(new_extras_metadata);
1181 std::vector<create_engine::level_ptr>
1184 std::vector<level_ptr>
levels;
1188 levels.push_back(
level);
1191 case level::TYPE::USER_MAP:
1193 levels.push_back(
level);
1196 case level::TYPE::USER_SCENARIO:
1198 levels.push_back(
level);
1201 case level::TYPE::RANDOM_MAP:
1203 levels.push_back(
level);
1206 case level::TYPE::CAMPAIGN:
1208 levels.push_back(
level);
1211 case level::TYPE::SP_CAMPAIGN:
1213 levels.push_back(
level);
1223 std::vector<level_ptr>
levels;
1230 case level::TYPE::USER_MAP:
1235 case level::TYPE::USER_SCENARIO:
1240 case level::TYPE::RANDOM_MAP:
1245 case level::TYPE::CAMPAIGN:
1250 case level::TYPE::SP_CAMPAIGN:
1260 const std::vector<create_engine::extras_metadata_ptr>&
1266 std::vector<create_engine::extras_metadata_ptr>&
void set_current_mod_index(const size_t index)
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
std::vector< std::string > levels_menu_item_names() const
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
child_itors child_range(const std::string &key)
unsigned int end_text_duration
for how long the end-of-campaign text is shown
surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::map< map_location, unsigned int > *reach_map)
function to create the minimap for a given map the surface returned must be freed by the user ...
char const IMG_TEXT_SEPARATOR
std::vector< extras_metadata_ptr > mods_
bool can_launch_game() const
const depcheck::manager & dependency_manager() const
const std::vector< extras_metadata_ptr > & get_const_extras_by_type(const MP_EXTRA extra_type) const
void expand_scenario()
copies the content of a [scenario] with the correct id attribute from the game config into this objec...
const char * what() const
std::vector< extras_metadata_ptr > & get_extras_by_type(const MP_EXTRA extra_type)
int player_num_filter() const
std::vector< level_ptr > get_levels_by_type(level::TYPE type) const
void set_scenario(config scenario)
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
size_t current_era_index_
std::string generator_name() const
GLuint GLuint GLsizei GLenum type
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
level & current_level() const
virtual std::string name() const
static lg::log_domain log_mp_create_engine("mp/create/engine")
bool is_campaign_completed(const std::string &campaign_id)
std::vector< std::string > user_scenario_names_
void generator_user_config(CVideo &v)
std::vector< level_ptr > get_levels_by_type_unfiltered(level::TYPE type) const
void expand_random_scenario()
takes care of generate_map=, generate_scenario=, map= attributes This should be called before expandi...
bool generate_whole_scenario_
std::vector< size_t > user_maps_filtered_
size_t current_era_index() const
bool generate_whole_scenario() const
void set_current_era_index(const size_t index, bool force=false)
const std::string unicode_multiplication_sign
std::array< uint8_t, 16 > md5(const std::string &input)
Returns the MD5 digest for the specified input.
void set_data(const config &data)
surface scale_surface(const surface &surf, int w, int h)
surface create_image_surface(const SDL_Rect &image_rect)
static lg::log_domain log_config("config")
void set_current_level(const size_t index)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
std::vector< random_map_ptr > random_maps_
const mp_game_settings & get_parameters()
void prepare_for_era_and_mods()
void prepare_for_scenario()
bool generator_assigned() const
std::vector< std::pair< const std::string *, const stats * > > levels
Stats (and name) for each scenario. The pointers are never nullptr.
bool toggle_current_mod(bool force=false)
campaign(const config &data)
bool can_launch_game() const
std::string select_campaign_difficulty(int set_value=-1)
select_campaign_difficulty
GLdouble GLdouble GLdouble b
This module controls the multiplayer lobby.
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
std::vector< size_t > scenarios_filtered_
std::vector< std::string > active_mods
static game_config_manager * get()
std::string level_name_filter_
static UNUSEDNOWARN std::string _(const char *str)
std::map< std::string, t_string > string_map
std::vector< scenario_ptr > scenarios_
void apply_level_filters()
char const HELP_STRING_SEPARATOR
const config & generator_data() const
std::string get_user_data_dir()
const extras_metadata & current_extra(const MP_EXTRA extra_type) const
std::string campaign_define
If there is a define the campaign uses to customize data.
size_t current_mod_index() const
level::TYPE current_level_type_
GLboolean GLboolean GLboolean GLboolean a
std::string dev_message
The message for developers telling which problem was triggered, this shouldn't be translated...
Encapsulates the map of the game.
size_t current_mod_index_
config & add_child(const std::string &key)
std::string end_text
end-of-campaign text
static bool less_campaigns_rank(const create_engine::level_ptr &a, const create_engine::level_ptr &b)
const config & data() const
std::vector< size_t > random_maps_filtered_
std::string campaign
the campaign being played
GLuint const GLuint * names
std::vector< std::string > & active_mods()
void apply_level_filter(const std::string &name)
void init_generated_level_data()
int find_extra_by_id(const MP_EXTRA extra_type, const std::string &id) const
std::string read_map(const std::string &name)
std::string era_define
If there is a define the era uses to customize data.
std::string selected_difficulty() const
Returns the selected difficulty define after displaying.
map_generator * create_map_generator(const std::string &name, const config &cfg)
virtual bool allow_era_choice() const
std::vector< campaign_ptr > sp_campaigns_
void load_game_config_for_create(bool is_mp)
std::vector< user_map_ptr > user_maps_
std::string abbrev
the campaign abbreviation
scenario(const config &data)
std::vector< std::string > extras_menu_item_names(const MP_EXTRA extra_type, bool escape_markup=true) const
bool allow_era_choice() const
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs=nullptr, file_name_option mode=FILE_NAME_ONLY, file_filter_option filter=NO_FILTER, file_reorder_option reorder=DONT_REORDER, file_tree_checksum *checksum=nullptr)
Populates 'files' with all the files and 'dirs' with all the directories in dir.
surface create_image_surface(const SDL_Rect &image_rect)
level::TYPE find_level_type_by_id(const std::string &id) const
std::vector< std::string > campaign_xtra_defines
more customization of data
std::string description() const
Game configuration data as global variables.
level(const config &data)
std::string encode_hash(const std::array< uint8_t, 16 > &input)
const config & game_config() const
map_generator * create_map_generator() const
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::vector< std::string > user_map_names_
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
void prepare_for_campaign(const std::string &difficulty)
boost::scoped_ptr< depcheck::manager > dependency_manager_
std::vector< size_t > sp_campaigns_filtered_
const std::string & level_name_filter() const
level::TYPE current_level_type() const
unsigned child_count(const std::string &key) const
std::vector< scenario_ptr > user_scenarios_
std::string difficulty
The difficulty level the game is being played on.
std::string description() const
GLuint const GLchar * name
std::vector< extras_metadata_ptr > eras_
std::istream * preprocess_file(std::string const &fname, preproc_map *defines)
boost::scoped_ptr< gamemap > map_
connection connect(const std::string &host, int port)
Function to attempt to connect to a remote host.
const std::vector< std::string > & modifications(bool mp)
std::vector< size_t > campaigns_filtered_
void load_game_config_for_game(const game_classification &classification)
bool has_attribute(const std::string &key) const
random_map(const config &data)
game_classification & classification()
void set_carryover_sides_start(config carryover_sides_start)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
config & find_child(const std::string &key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Standard logging facilities (interface).
virtual std::string description() const
void set_current_level_type(const level::TYPE)
virtual std::string icon() const
std::vector< size_t > user_scenarios_filtered_
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.
void prepare_for_saved_game()
virtual std::string id() const
std::string generator_name_
int find_level_by_id(const std::string &id) const
A config object defines a single node in a WML file, with access to child nodes.
Helper class, don't construct this directly.
std::string map_size() const
void prepare_for_new_level()
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
size_t current_level_index_
GLsizei const GLcharARB ** string
user_map(const config &data, const std::string &name, gamemap *map)
create_engine(CVideo &v, saved_game &state)
void reset_level_filters()
std::vector< campaign_ptr > campaigns_
boost::scoped_ptr< map_generator > generator_
void init_extras(const MP_EXTRA extra_type)