The Battle for Wesnoth  1.19.0-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 <vector>
26 #include <map>
27 
28 //basic game configuration information is here.
29 namespace game_config
30 {
31  extern int base_income;
32  extern int village_income;
33  extern int village_support;
34  extern int poison_amount;
35  extern int rest_heal_amount;
36  extern int recall_cost;
37  extern int kill_experience;
38  extern int combat_experience;
39  extern unsigned int tile_size;
40  extern unsigned lobby_network_timer;
41  extern unsigned lobby_refresh;
42  extern const std::string default_title_string;
43  extern std::string default_terrain;
44 
45  extern std::vector<unsigned int> zoom_levels;
46 
47  inline int kill_xp(int level)
48  {
49  return level ? kill_experience * level : kill_experience / 2;
50  }
51 
52  inline int combat_xp(int level)
53  {
54  return combat_experience * level;
55  }
56 
57  /** Default percentage gold carried over to the next scenario. */
58  extern const int gold_carryover_percentage;
59 
62 
63  extern bool allow_insecure;
64 
65  extern const bool& debug;
66  void set_debug(bool new_debug);
67 
68  struct server_info
69  {
70  std::string name;
71  std::string address; /**< may include ':' followed by port number */
72  };
73 
74  extern std::vector<server_info> server_list;
75 
76  extern std::string title_music,
78 
79  extern std::vector<std::string> default_defeat_music;
80  extern std::vector<std::string> default_victory_music;
81 
82  namespace colors {
83  extern std::string ally_orb_color;
84  extern std::string enemy_orb_color;
85  extern std::string moved_orb_color;
86  extern std::string partial_orb_color;
87  extern std::string unmoved_orb_color;
88  extern std::string default_color_list;
89  } // colors
90 
91  extern bool show_ally_orb;
92  extern bool show_disengaged_orb;
93  extern bool show_enemy_orb;
94  extern bool show_moved_orb;
95  extern bool show_partial_orb;
96  extern bool show_status_on_ally_orb;
97  extern bool show_unmoved_orb;
98 
99  namespace images {
100  extern std::string game_title,
102  game_logo,
107  // orbs and hp/xp bar
108  orb,
110  energy,
111  // top bar icons
112  battery_icon,
113  time_icon,
114  // flags
115  flag,
116  flag_icon,
117  // hex overlay
118  terrain_mask,
119  grid_top,
120  grid_bottom,
121  mouseover,
122  selected,
123  editor_brush,
124  unreachable,
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;
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 
152  extern std::vector<std::string> foot_speed_prefix;
153  extern std::string foot_teleport_enter, foot_teleport_exit;
154 
155  /**
156  * Colors defined by WML [color_range] tags. In addition to team colors such as "red" and
157  * "blue", this also contains the colors used on the minimap for "cave", "fungus" etc.
158  */
159  extern std::map<std::string, color_range, std::less<>> team_rgb_range;
160  extern std::map<std::string, t_string, std::less<>> team_rgb_name;
161  extern std::map<std::string, std::vector<color_t>, std::less<>> team_rgb_colors;
162 
163  extern std::vector<std::string> default_colors;
164 
165  /**
166  * The maximum number of hexes on a map and items in an array and also used
167  * as maximum in wml loops.
168  * WARNING : This should not be set to less than the max map area
169  */
170  extern const std::size_t max_loop;
171 
172  namespace sounds {
173  extern std::string turn_bell, timer_bell, public_message,
178  extern const std::string button_press, checkbox_release, slider_adjust,
180  namespace status {
181  extern std::string poisoned, slowed, petrified;
182  }
183  }
184 
185  void load_config(const config &cfg);
186 
187  void add_color_info(const game_config_view& v);
188  void reset_color_info();
189  const std::vector<color_t>& tc_info(std::string_view name);
190  const color_range& color_info(std::string_view name);
191 
192  /**
193  * Return a color corresponding to the value val
194  * red for val=0.0 to green for val=100.0, passing by yellow.
195  * Colors are defined by [game_config] keys
196  * red_green_scale and red_green_scale_text
197  */
198  color_t red_to_green(double val, bool for_text = true);
199  color_t blue_to_white(double val, bool for_text = true);
200 
201  std::string get_default_title_string();
202 }
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:159
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 unreachable
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:60
int rest_heal_amount
Definition: game_config.cpp:44
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:70
std::string get_default_title_string()
bool ignore_replay_errors
Definition: game_config.cpp:84
std::string foot_teleport_enter
int village_income
Definition: game_config.cpp:37
bool show_status_on_ally_orb
std::vector< color_t > red_green_scale_text
int kill_xp(int level)
Definition: game_config.hpp:47
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:46
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:54
const bool & debug
Definition: game_config.cpp:91
const color_range & color_info(std::string_view name)
std::vector< std::string > default_colors
std::string shroud_prefix
Definition: game_config.cpp:54
double hp_bar_scaling
Definition: game_config.cpp:61
bool disable_autosave
Definition: game_config.cpp:88
std::vector< server_info > server_list
Definition: game_config.cpp:72
int kill_experience
Definition: game_config.cpp:40
std::string unit_rgb
unsigned int tile_size
Definition: game_config.cpp:51
bool show_ally_orb
bool allow_insecure
Definition: game_config.cpp:74
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:56
bool show_partial_orb
std::string title_music
std::string default_terrain
Definition: game_config.cpp:53
bool show_enemy_orb
unsigned lobby_network_timer
Definition: game_config.cpp:67
bool show_unmoved_orb
unsigned lobby_refresh
Definition: game_config.cpp:68
std::vector< std::string > default_victory_music
int combat_experience
Definition: game_config.cpp:41
void reset_color_info()
const std::string default_title_string
void set_debug(bool new_debug)
Definition: game_config.cpp:93
std::vector< color_t > red_green_scale
int combat_xp(int level)
Definition: game_config.hpp:52
bool exit_at_end
Definition: game_config.cpp:86
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:62
int village_support
Definition: game_config.cpp:38
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:71