The Battle for Wesnoth  1.19.4+dev
configuration.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Yurii Chernyi <terraninfo@terraninfo.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 /**
17  * Managing the AIs configuration - headers
18  * @file
19  * */
20 
21 #pragma once
22 
23 #include "config.hpp"
24 #include "ai/game_info.hpp"
25 #include "game_config_view.hpp"
26 
27 namespace ai {
28 
29 /**
30  * AI parameters. class to deal with AI parameters. It is an implementation detail.
31  * We need implementation which will allow easy access to all the parameters
32  * which match any of the pre-defined set of filters
33  * such as 'select from ai_parameters where time_of_day=first watch'
34  * or 'select from ai_parameters where active(current_game_state)=true'
35  * it should be noted that there may be several variables with a same name but
36  * different filters. the proposed rules, in general, are:
37  * 1) scenario_parameter_in_SIDE_section > scenario_parameter_in_AI_section > default_value
38  * then, if (1) is equal:
39  * 2) use scenario-creator supplied priority ( 'not set' = 0)
40  * then, if (2) is equal:
41  * 3) more restricted parameter > less restricted parameter
42  * then, if (3) is equal:
43  * use any and loudly complain.
44  */
45 
46 struct description {
47 public:
49  : text()
50  , id()
51  , mp_rank()
52  , cfg()
53  {
54  }
55 
57  std::string id;
58  int mp_rank;
60 };
61 
63 public:
64 
65  /**
66  * Init the parameters of ai configuration parser
67  * @param game_config game config
68  */
69  static void init(const game_config_view &game_config);
70  static void add_era_ai_from_config(const config &game_config);
72 
73 
74  /**
75  * get default AI parameters
76  * @return default AI parameters
77  */
78  static const config& get_default_ai_parameters();
79 
80 
81  /**
82  * Return the config for a specified ai
83  */
84  static const config& get_ai_config_for(const std::string &id);
85 
86 
87  /**
88  * Returns a list of available AIs.
89  * @return the list of available AIs.
90  */
91  static std::vector<description*> get_available_ais();
92 
93 
94  /**
95  * get side config from file
96  * @param file the file name to open. follows usual WML convention.
97  * @param[out] cfg the config to be written from file.
98  * @return was all ok?
99  * @retval true success
100  * @retval false failure
101  */
102  static bool get_side_config_from_file( const std::string& file, config& cfg );
103 
104 
105  /**
106  * @param[in] side the side to be parsed
107  * @param[in] original_cfg the config to be read
108  * @param[out] cfg parsed config
109  * @return was all ok?
110  * @retval true success
111  * @retval false failure
112  */
113  static bool parse_side_config(side_number side, const config& original_cfg, config &cfg);
114 
115 
116  /**
117  * Expand simplified aspects, similar to the change from 1.7.2 to 1.7.3
118  * but with some additional syntax options.
119  */
120  static void expand_simplified_aspects(side_number side, config &cfg);
121 private:
122 
123  typedef std::map<std::string, description> description_map;
127  static inline config default_config_ {};
128  static inline std::string default_ai_algorithm_ {};
129 
130 };
131 
132 } //end of namespace ai
static void add_mod_ai_from_config(config::const_child_itors configs)
static description_map ai_configurations_
static config default_config_
static std::vector< description * > get_available_ais()
Returns a list of available AIs.
static description_map era_ai_configurations_
static bool get_side_config_from_file(const std::string &file, config &cfg)
get side config from file
static std::string default_ai_algorithm_
static void init(const game_config_view &game_config)
Init the parameters of ai configuration parser.
static const config & get_ai_config_for(const std::string &id)
Return the config for a specified ai.
static bool parse_side_config(side_number side, const config &original_cfg, config &cfg)
static void add_era_ai_from_config(const config &game_config)
static void expand_simplified_aspects(side_number side, config &cfg)
Expand simplified aspects, similar to the change from 1.7.2 to 1.7.3 but with some additional syntax ...
std::map< std::string, description > description_map
static const config & get_default_ai_parameters()
get default AI parameters
static description_map mod_ai_configurations_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:163
boost::iterator_range< const_child_iterator > const_child_itors
Definition: config.hpp:287
A class grating read only view to a vector of config objects, viewed as one config with all children ...
Definitions for the interface to Wesnoth Markup Language (WML).
Game information for the AI.
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
int side_number
Definition: game_info.hpp:40
Game configuration data as global variables.
Definition: build_info.cpp:61
AI parameters.
std::string id