The Battle for Wesnoth  1.15.0+dev
map_settings.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2018 by Mark de Wever <koraq@xs4all.nl>
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 /**
16  * @file
17  * General settings and defaults for scenarios.
18  */
19 
20 #include "lexical_cast.hpp"
21 #include "map_settings.hpp"
22 
24 #include "utils/general.hpp"
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 utils::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 utils::clamp<int>(lexical_cast_default<int>(value, ((classification && !classification->is_normal_mp_game()) ? 1 : 2)), 1, 5);
43 }
44 
45 int get_village_support(const std::string& value)
46 {
47  return utils::clamp<int>(lexical_cast_default<int>(value, 1), 0, 4);
48 }
49 
50 int get_xp_modifier(const std::string& value)
51 {
52  return utils::clamp<int>(lexical_cast_default<int>(value, 70), 30, 200);
53 }
54 
55 } // end namespace settings
const int turns_max
maximum number of turns
game_classification * classification
Definition: resources.cpp:34
New lexcical_cast header.
int get_village_gold(const std::string &value, const game_classification *classification)
Gets the village gold.
const int turns_default
default number of turns
int get_village_support(const std::string &value)
Gets the village unit level support.
General settings and defaults for scenarios.
Contains the general settings which have a default.
int get_xp_modifier(const std::string &value)
Gets the xp modifier.
const int turns_min
minimum number of turns
int get_turns(const std::string &value)
Gets the number of turns.