The Battle for Wesnoth  1.15.12+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 
25 namespace settings {
26 
27 int get_turns(const std::string& value)
28 {
29  // Special case, -1 is also allowed, which means unlimited turns
30  int val = lexical_cast_default<int>(value);
31 
32  if(val == -1) {
33  return turns_max;
34  }
35 
36  return std::clamp<int>(lexical_cast_default<int>(value, turns_default), turns_min, turns_max);
37 }
38 
39 int get_village_gold(const std::string& value, const game_classification* classification)
40 {
41  return std::clamp<int>(lexical_cast_default<int>(value, ((classification && !classification->is_normal_mp_game()) ? 1 : 2)), 1, 5);
42 }
43 
44 int get_village_support(const std::string& value)
45 {
46  return std::clamp<int>(lexical_cast_default<int>(value, 1), 0, 4);
47 }
48 
49 int get_xp_modifier(const std::string& value)
50 {
51  return std::clamp<int>(lexical_cast_default<int>(value, 70), 30, 200);
52 }
53 
54 } // 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.