The Battle for Wesnoth  1.19.7+dev
game_config.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
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 #pragma once
17 
18 class config;
19 class color_range;
20 
21 #include "color.hpp"
22 #include "tstring.hpp"
23 #include "game_config_view.hpp"
24 
25 #include <chrono>
26 #include <vector>
27 #include <map>
28 
29 //basic game configuration information is here.
30 namespace game_config
31 {
32  extern int base_income;
33  extern int village_income;
34  extern int village_support;
35  extern int poison_amount;
36  extern int rest_heal_amount;
37  extern int recall_cost;
38  extern int kill_experience;
39  extern int combat_experience;
40  extern unsigned int tile_size;
41  extern std::chrono::milliseconds lobby_network_timer;
42  extern std::chrono::milliseconds lobby_refresh;
43  extern const std::string default_title_string;
44  extern std::string default_terrain;
45 
46  extern std::vector<unsigned int> zoom_levels;
47 
48  inline int kill_xp(int level)
49  {
50  return level ? kill_experience * level : kill_experience / 2;
51  }
52 
53  inline int combat_xp(int level)
54  {
55  return combat_experience * level;
56  }
57 
58  /** Default percentage gold carried over to the next scenario. */
59  extern const int gold_carryover_percentage;
60 
63 
64  extern bool allow_insecure;
65 
66  extern const bool& debug;
67  void set_debug(bool new_debug);
68 
69  struct server_info
70  {
71  std::string name;
72  std::string address; /**< may include ':' followed by port number */
73  };
74 
75  extern std::vector<server_info> server_list;
76 
77  extern std::string title_music,
79 
80  extern std::vector<std::string> default_defeat_music;
81  extern std::vector<std::string> default_victory_music;
82 
83  namespace colors {
84  extern std::string ally_orb_color;
85  extern std::string enemy_orb_color;
86  extern std::string moved_orb_color;
87  extern std::string partial_orb_color;
88  extern std::string unmoved_orb_color;
89  extern std::string default_color_list;
90  } // colors
91 
92  extern bool show_ally_orb;
93  extern bool show_disengaged_orb;
94  extern bool show_enemy_orb;
95  extern bool show_moved_orb;
96  extern bool show_partial_orb;
97  extern bool show_status_on_ally_orb;
98  extern bool show_unmoved_orb;
99 
100  namespace images {
101  extern std::string game_title,
103  game_logo,
108  // orbs and hp/xp bar
109  orb,
111  energy,
112  // top bar icons
113  battery_icon,
114  time_icon,
115  // flags
116  flag,
117  flag_icon,
118  // hex overlay
119  terrain_mask,
120  grid_top,
121  grid_bottom,
122  mouseover,
123  selected,
124  editor_brush,
125  linger,
126  // GUI elements
127  observer,
128  tod_bright,
129  tod_dark,
132  checked_menu,
134  wml_menu,
135  level,
136  ellipsis,
137  missing,
138  blank,
139  // notifications icon
140  app_icon;
141  } //images
142 
143 
144  extern std::string shroud_prefix, fog_prefix, reach_map_prefix;
145 
146  extern double hp_bar_scaling, xp_bar_scaling;
147 
148  extern std::string flag_rgb, unit_rgb;
149  extern std::vector<color_t> red_green_scale;
150  extern std::vector<color_t> red_green_scale_text;
151  extern std::vector<color_t> blue_white_scale;
152  extern std::vector<color_t> blue_white_scale_text;
153 
154  extern std::vector<std::string> foot_speed_prefix;
155  extern std::string foot_teleport_enter, foot_teleport_exit;
156 
157  /**
158  * Colors defined by WML [color_range] tags. In addition to team colors such as "red" and
159  * "blue", this also contains the colors used on the minimap for "cave", "fungus" etc.
160  */
161  extern std::map<std::string, color_range, std::less<>> team_rgb_range;
162  extern std::map<std::string, t_string, std::less<>> team_rgb_name;
163  extern std::map<std::string, std::vector<color_t>, std::less<>> team_rgb_colors;
164 
165  extern std::vector<std::string> default_colors;
166 
167  /**
168  * The maximum number of hexes on a map and items in an array and also used
169  * as maximum in wml loops.
170  * WARNING : This should not be set to less than the max map area
171  */
172  extern const std::size_t max_loop;
173 
174  namespace sounds {
175  extern std::string turn_bell, timer_bell, public_message,
180  extern const std::string button_press, checkbox_release, slider_adjust,
182  namespace status {
183  extern std::string poisoned, slowed, petrified;
184  }
185  }
186 
187  void load_config(const config &cfg);
188 
189  void add_color_info(const game_config_view& v);
190  void reset_color_info();
191  const std::vector<color_t>& tc_info(std::string_view name);
192  const color_range& color_info(std::string_view name);
193 
194  /**
195  * Return a color corresponding to the value val
196  * red for val=0.0 to green for val=100.0, passing by yellow.
197  * Colors are defined by [game_config] keys
198  * red_green_scale and red_green_scale_text
199  */
200  color_t red_to_green(double val, bool for_text = true);
201  color_t blue_to_white(double val, bool for_text = true);
202 
203  std::string get_default_title_string();
204 }
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
Definition: color_range.hpp:49
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
A class grating read only view to a vector of config objects, viewed as one config with all children ...
std::string partial_orb_color
std::string moved_orb_color
std::string unmoved_orb_color
std::string ally_orb_color
std::string enemy_orb_color
std::string default_color_list
std::string selected_menu
std::string terrain_mask
std::string victory_laurel_hardest
std::string victory_laurel
std::string orb_two_color
std::string tod_bright
std::string time_icon
std::string selected
std::string app_icon
std::string deselected_menu
std::string observer
std::string ellipsis
std::string unchecked_menu
std::string game_title_background
std::string grid_top
std::string grid_bottom
std::string game_title
std::string game_logo
std::string game_logo_background
std::string wml_menu
std::string flag_icon
std::string editor_brush
std::string checked_menu
std::string mouseover
std::string battery_icon
std::string victory_laurel_easy
std::string tod_dark
std::string public_message
std::string private_message
const std::string menu_expand
std::string player_leaves
std::string server_message
std::string game_user_arrive
std::string turn_bell
const std::string menu_contract
std::string game_user_leave
const std::string checkbox_release
std::string timer_bell
std::string friend_message
const std::string menu_select
std::string ready_for_start
std::string game_has_begun
const std::string button_press
std::string game_created
std::string player_joins
const std::string slider_adjust
Game configuration data as global variables.
Definition: build_info.cpp:61
int rest_heal_amount
Definition: game_config.cpp:48
std::vector< std::string > default_defeat_music
std::map< std::string, color_range, std::less<> > team_rgb_range
Colors defined by WML [color_range] tags.
std::string flag_rgb
color_t blue_to_white(double val, bool for_text)
std::map< std::string, t_string, std::less<> > team_rgb_name
const std::size_t max_loop
The maximum number of hexes on a map and items in an array and also used as maximum in wml loops.
Definition: game_config.cpp:74
std::string get_default_title_string()
bool ignore_replay_errors
Definition: game_config.cpp:88
std::string foot_teleport_enter
int village_income
Definition: game_config.cpp:41
bool show_status_on_ally_orb
std::vector< color_t > red_green_scale_text
int kill_xp(int level)
Definition: game_config.hpp:48
bool show_moved_orb
std::vector< std::string > foot_speed_prefix
const int gold_carryover_percentage
Default percentage gold carried over to the next scenario.
Definition: game_config.cpp:50
std::string foot_teleport_exit
std::string lobby_music
const std::vector< color_t > & tc_info(std::string_view name)
std::string fog_prefix
Definition: game_config.cpp:58
const bool & debug
Definition: game_config.cpp:94
const color_range & color_info(std::string_view name)
std::vector< std::string > default_colors
std::vector< color_t > blue_white_scale
std::string shroud_prefix
Definition: game_config.cpp:58
double hp_bar_scaling
Definition: game_config.cpp:65
bool disable_autosave
Definition: game_config.cpp:91
std::vector< server_info > server_list
Definition: game_config.cpp:76
int kill_experience
Definition: game_config.cpp:44
std::string unit_rgb
unsigned int tile_size
Definition: game_config.cpp:55
bool show_ally_orb
bool allow_insecure
Definition: game_config.cpp:78
static void add_color_info(const game_config_view &v, bool build_defaults)
bool show_disengaged_orb
std::vector< unsigned int > zoom_levels
Definition: game_config.cpp:60
bool show_partial_orb
std::chrono::milliseconds lobby_refresh
Definition: game_config.cpp:72
std::string title_music
std::chrono::milliseconds lobby_network_timer
Definition: game_config.cpp:71
std::string default_terrain
Definition: game_config.cpp:57
bool show_enemy_orb
bool show_unmoved_orb
std::string reach_map_prefix
Definition: game_config.cpp:58
std::vector< std::string > default_victory_music
int combat_experience
Definition: game_config.cpp:45
void reset_color_info()
const std::string default_title_string
void set_debug(bool new_debug)
Definition: game_config.cpp:96
std::vector< color_t > red_green_scale
int combat_xp(int level)
Definition: game_config.hpp:53
bool exit_at_end
Definition: game_config.cpp:90
std::vector< color_t > blue_white_scale_text
void load_config(const config &v)
color_t red_to_green(double val, bool for_text)
Return a color corresponding to the value val red for val=0.0 to green for val=100....
std::map< std::string, std::vector< color_t >, std::less<> > team_rgb_colors
double xp_bar_scaling
Definition: game_config.cpp:66
int village_support
Definition: game_config.cpp:42
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
std::string address
may include ':' followed by port number
Definition: game_config.hpp:72