The Battle for Wesnoth  1.17.23+dev
game_config.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2023
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 #include <cstdint>
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 unsigned lobby_network_timer;
42  extern unsigned 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  unreachable,
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;
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 
153  extern std::vector<std::string> foot_speed_prefix;
154  extern std::string foot_teleport_enter, foot_teleport_exit;
155 
156  /**
157  * Colors defined by WML [color_range] tags. In addition to team colors such as "red" and
158  * "blue", this also contains the colors used on the minimap for "cave", "fungus" etc.
159  */
160  extern std::map<std::string, color_range> team_rgb_range;
161  extern std::map<std::string, t_string> team_rgb_name;
162  extern std::map<std::string, std::vector<color_t>> team_rgb_colors;
163 
164  extern std::vector<std::string> default_colors;
165 
166  /**
167  * The maximum number of hexes on a map and items in an array and also used
168  * as maximum in wml loops.
169  * WARNING : This should not be set to less than the max map area
170  */
171  extern const std::size_t max_loop;
172 
173  namespace sounds {
174  extern std::string turn_bell, timer_bell, public_message,
179  extern const std::string button_press, checkbox_release, slider_adjust,
181  namespace status {
182  extern std::string poisoned, slowed, petrified;
183  }
184  }
185 
186  void load_config(const config &cfg);
187 
188  void add_color_info(const game_config_view& v);
189  void reset_color_info();
190  const std::vector<color_t>& tc_info(const std::string& name);
191  const color_range& color_info(const std::string& name);
192 
193  /**
194  * Return a color corresponding to the value val
195  * red for val=0.0 to green for val=100.0, passing by yellow.
196  * Colors are defined by [game_config] keys
197  * red_green_scale and red_green_scale_text
198  */
199  color_t red_to_green(double val, bool for_text = true);
200  color_t blue_to_white(double val, bool for_text = true);
201 
202  std::string get_default_title_string();
203 }
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
Definition: color_range.hpp:50
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
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:63
int rest_heal_amount
Definition: game_config.cpp:44
std::vector< std::string > default_defeat_music
std::map< std::string, color_range > team_rgb_range
Colors defined by WML [color_range] tags.
std::string flag_rgb
color_t blue_to_white(double val, bool for_text)
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: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:46
std::string foot_teleport_exit
std::string lobby_music
std::string fog_prefix
Definition: game_config.cpp:54
const std::vector< color_t > & tc_info(const std::string &name)
const bool & debug
Definition: game_config.cpp:91
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)
std::map< std::string, t_string > team_rgb_name
bool show_disengaged_orb
std::vector< unsigned int > zoom_levels
Definition: game_config.cpp:56
bool show_partial_orb
const color_range & color_info(const std::string &name)
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
std::map< std::string, std::vector< color_t > > team_rgb_colors
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:53
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....
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:72