The Battle for Wesnoth  1.19.7+dev
map_settings.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2024
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 
25 
26 namespace settings {
27 
28 int get_turns(const std::string& value)
29 {
30  // Special case, -1 is also allowed, which means unlimited turns
31  int val = lexical_cast_default<int>(value);
32 
33  if(val == -1) {
34  return turns_max;
35  }
36 
37  return std::clamp<int>(lexical_cast_default<int>(value, turns_default), turns_min, turns_max);
38 }
39 
40 int get_village_gold(const std::string& value, const game_classification* classification)
41 {
42  return lexical_cast_default<int>(value, ((classification && !classification->is_normal_mp_game()) ? 1 : 2));
43 }
44 
45 int get_village_support(const std::string& value)
46 {
47  return lexical_cast_default<int>(value, 1);
48 }
49 
50 int get_xp_modifier(const std::string& value)
51 {
52  return lexical_cast_default<int>(value, 70);
53 }
54 
55 } // end namespace settings
New lexcical_cast header.
General settings and defaults for scenarios.
game_classification * classification
Definition: resources.cpp:34
Contains the general settings which have a default.
const int turns_min
minimum number of turns
int get_village_support(const std::string &value)
Gets the village unit level support.
int get_turns(const std::string &value)
Gets the number of turns.
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
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.