The Battle for Wesnoth  1.19.8+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  extern bool addon_server_info;
66 
67  extern const bool& debug;
68  void set_debug(bool new_debug);
69 
70  struct server_info
71  {
72  std::string name;
73  std::string address; /**< may include ':' followed by port number */
74  };
75 
76  extern std::vector<server_info> server_list;
77 
78  extern std::string title_music,
80 
81  extern std::vector<std::string> default_defeat_music;
82  extern std::vector<std::string> default_victory_music;
83 
84  namespace colors {
85  extern std::string ally_orb_color;
86  extern std::string enemy_orb_color;
87  extern std::string moved_orb_color;
88  extern std::string partial_orb_color;
89  extern std::string unmoved_orb_color;
90  extern std::string default_color_list;
91  } // colors
92 
93  extern bool show_ally_orb;
94  extern bool show_disengaged_orb;
95  extern bool show_enemy_orb;
96  extern bool show_moved_orb;
97  extern bool show_partial_orb;
98  extern bool show_status_on_ally_orb;
99  extern bool show_unmoved_orb;
100 
101  namespace images {
102  extern std::string game_title,
104  game_logo,
109  // orbs and hp/xp bar
110  orb,
112  energy,
113  // top bar icons
114  battery_icon,
115  time_icon,
116  // flags
117  flag,
118  flag_icon,
119  // hex overlay
120  terrain_mask,
121  grid_top,
122  grid_bottom,
123  mouseover,
124  selected,
125  editor_brush,
126  linger,
127  // GUI elements
128  observer,
129  tod_bright,
130  tod_dark,
133  checked_menu,
135  wml_menu,
136  level,
137  ellipsis,
138  missing,
139  blank,
140  // notifications icon
141  app_icon;
142  } //images
143 
144 
145  extern std::string shroud_prefix, fog_prefix, reach_map_prefix;
146 
147  extern double hp_bar_scaling, xp_bar_scaling;
148 
149  extern std::string flag_rgb, unit_rgb;
150  extern std::vector<color_t> red_green_scale;
151  extern std::vector<color_t> red_green_scale_text;
152  extern std::vector<color_t> blue_white_scale;
153  extern std::vector<color_t> blue_white_scale_text;
154 
155  extern std::vector<std::string> foot_speed_prefix;
156  extern std::string foot_teleport_enter, foot_teleport_exit;
157 
158  /**
159  * Colors defined by WML [color_range] tags. In addition to team colors such as "red" and
160  * "blue", this also contains the colors used on the minimap for "cave", "fungus" etc.
161  */
162  extern std::map<std::string, color_range, std::less<>> team_rgb_range;
163  extern std::map<std::string, t_string, std::less<>> team_rgb_name;
164  extern std::map<std::string, std::vector<color_t>, std::less<>> team_rgb_colors;
165 
166  extern std::vector<std::string> default_colors;
167 
168  /**
169  * The maximum number of hexes on a map and items in an array and also used
170  * as maximum in wml loops.
171  * WARNING : This should not be set to less than the max map area
172  */
173  extern const std::size_t max_loop;
174 
175  namespace sounds {
176  extern std::string turn_bell, timer_bell, public_message,
181  extern const std::string button_press, checkbox_release, slider_adjust,
183  namespace status {
184  extern std::string poisoned, slowed, petrified;
185  }
186  }
187 
188  void load_config(const config &cfg);
189 
190  void add_color_info(const game_config_view& v);
191  void reset_color_info();
192  const std::vector<color_t>& tc_info(std::string_view name);
193  const color_range& color_info(std::string_view name);
194 
195  /**
196  * Return a color corresponding to the value val
197  * red for val=0.0 to green for val=100.0, passing by yellow.
198  * Colors are defined by [game_config] keys
199  * red_green_scale and red_green_scale_text
200  */
201  color_t red_to_green(double val, bool for_text = true);
202  color_t blue_to_white(double val, bool for_text = true);
203 
204  std::string get_default_title_string();
205 }
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:158
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:89
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
bool addon_server_info
Definition: game_config.cpp:79
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:95
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:92
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:97
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:91
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:73