The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
map_settings.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2007 - 2025
3 by Mark de Wever <koraq@xs4all.nl>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16/**
17 * @file
18 * General settings and defaults for scenarios.
19 */
20
21#include "lexical_cast.hpp"
22#include "map_settings.hpp"
23
26#include "saved_game.hpp"
28
29namespace settings {
30
31int get_turns(const std::string& value)
32{
33 // Special case, -1 is also allowed, which means unlimited turns
34 int val = lexical_cast_default<int>(value);
35
36 if(val == -1) {
37 return turns_max;
38 }
39
40 return std::clamp<int>(lexical_cast_default<int>(value, turns_default), turns_min, turns_max);
41}
42
43int get_village_gold(const std::string& value, const game_classification* classification)
44{
45 return lexical_cast_default<int>(value, ((classification && !classification->is_normal_mp_game()) ? 1 : 2));
46}
47
48int get_village_support(const std::string& value)
49{
50 return lexical_cast_default<int>(value, 1);
51}
52
53int get_xp_modifier(const std::string& value)
54{
55 return lexical_cast_default<int>(value, 70);
56}
57
77
79{
80 return create.current_level().data()["force_lock_settings"].to_bool(!create.get_state().classification().is_normal_mp_game());
81}
82
83std::string game_name_default()
84{
85 utils::string_map i18n_symbols;
86 i18n_symbols["login"] = prefs::get().login();
87 return VGETTEXT("$login|’s game", i18n_symbols);
88}
89
91{
92 return create.get_state().mp_settings().use_map_settings ? settings::get_turns(create.current_level().data()["turns"]) : prefs::get().mp_turns();
93}
94
96{
97 return create.get_state().mp_settings().use_map_settings
98 ? settings::get_village_gold(create.current_level().data()["mp_village_gold"], &create.get_state().classification())
100}
101
103{
104 return create.get_state().mp_settings().use_map_settings
105 ? settings::get_village_support(create.current_level().data()["mp_village_support"])
107}
108
110{
111 return create.get_state().mp_settings().use_map_settings
112 ? settings::get_xp_modifier(create.current_level().data()["experience_modifier"])
114}
115
116std::chrono::seconds mp_countdown_init_time_default()
117{
119}
120
122{
124}
125
127{
129}
130
132{
134}
135
137{
138 return prefs::get().mp_countdown();
139}
140
142{
143 return force_lock_settings(create) || prefs::get().mp_use_map_settings();
144}
145
147{
148 return create.get_state().mp_settings().use_map_settings
149 ? create.current_level().data()["random_start_time"].to_bool(false)
150 : prefs::get().mp_random_start_time();
151}
152
154{
155 return create.get_state().mp_settings().use_map_settings
156 ? create.current_level().data()["mp_fog"].to_bool(create.get_state().classification().is_normal_mp_game())
157 : prefs::get().mp_fog();
158}
159
161{
162 return create.get_state().mp_settings().use_map_settings
163 ? create.current_level().data()["mp_shroud"].to_bool(false)
164 : prefs::get().mp_shroud();
165}
166
168{
169 return prefs::get().allow_observers();
170}
171
173{
174 return prefs::get().shuffle_sides();
175}
176
177random_faction_mode::type random_faction_mode_default()
178{
179 return random_faction_mode::get_enum(prefs::get().random_faction_mode()).value_or(random_faction_mode::type::independent);
180}
181} // end namespace settings
saved_game & get_state()
level & current_level() const
const config & data() const
static prefs & get()
int village_support()
std::chrono::seconds countdown_turn_bonus()
std::chrono::seconds countdown_init_time()
std::chrono::seconds countdown_action_bonus()
int village_gold()
std::string login()
std::chrono::seconds countdown_reservoir_time()
int xp_modifier()
game_classification & classification()
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
New lexcical_cast header.
General settings and defaults for scenarios.
Contains the general settings which have a default.
bool force_lock_settings(ng::create_engine &create)
random_faction_mode::type random_faction_mode_default()
bool shuffle_sides_default()
bool shroud_game_default(ng::create_engine &create)
int village_support_default(ng::create_engine &create)
std::chrono::seconds mp_countdown_action_bonus_default()
int village_gold_default(ng::create_engine &create)
const int turns_min
minimum number of turns
int get_village_support(const std::string &value)
Gets the village unit level support.
bool allow_observers_default()
int get_turns(const std::string &value)
Gets the number of turns.
std::chrono::seconds mp_countdown_reservoir_time_default()
std::chrono::seconds mp_countdown_turn_bonus_default()
int num_turns_default(ng::create_engine &create)
bool mp_countdown_default()
bool use_map_settings_default(ng::create_engine &create)
std::string game_name_default()
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
const int turns_max
maximum number of turns
const int turns_default
default number of turns
std::chrono::seconds mp_countdown_init_time_default()
bool fog_game_default(ng::create_engine &create)
bool random_start_time_default(ng::create_engine &create)
int xp_modifier_default(ng::create_engine &create)
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
void set_default_values(ng::create_engine &create)
std::map< std::string, t_string > string_map
string_enums::enum_base< random_faction_mode_defines > random_faction_mode
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
Definition sound.cpp:139
random_faction_mode::type mode
std::chrono::seconds mp_countdown_reservoir_time
std::chrono::seconds mp_countdown_action_bonus
std::chrono::seconds mp_countdown_init_time
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Definition enum_base.hpp:57