ai/configuration.hpp

Go to the documentation of this file.
00001 /* $Id: configuration.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Yurii Chernyi <terraninfo@terraninfo.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  * Managing the AIs configuration - headers
00018  * @file
00019  * */
00020 
00021 #ifndef AI_CONFIGURATION_HPP_INCLUDED
00022 #define AI_CONFIGURATION_HPP_INCLUDED
00023 
00024 #include "../config.hpp"
00025 #include "game_info.hpp"
00026 
00027 namespace ai {
00028 
00029 /**
00030  * AI parameters. class to deal with AI parameters. It is an implementation detail.
00031  * We need implementation which will allow easy access to all the parameters
00032  * which match any of the pre-defined set of filters
00033  * such as 'select from ai_parameters where time_of_day=first watch'
00034  * or 'select from ai_parameters where active(current_game_state)=true'
00035  * it should be noted that there may be several variables with a same name but
00036  * different filters. the proposed rules, in general, are:
00037  * 1) scenario_parameter_in_SIDE_section > scenario_parameter_in_AI_section > default_value
00038  * then, if (1) is equal:
00039  * 2) use scenario-creator supplied priority ( 'not set' = 0)
00040  * then, if (2) is equal:
00041  * 3) more restricted parameter > less restricted parameter
00042  * then, if (3) is equal:
00043  * use any and loudly complain.
00044  */
00045 
00046 struct description {
00047 public:
00048     description()
00049         : text()
00050         , id()
00051         , cfg()
00052     {
00053     }
00054 
00055     std::string text;
00056     std::string id;
00057     config cfg;
00058 };
00059 
00060 class configuration {
00061 public:
00062 
00063     /**
00064      * Init the parameters of ai configuration parser
00065      * @param game_config_ game config
00066      */
00067     static void init(const config &game_config);
00068     static void add_era_ai_from_config(const config &game_config);
00069 
00070 
00071     /**
00072      * get default AI parameters
00073      * @return default AI parameters
00074      */
00075     static const config& get_default_ai_parameters();
00076 
00077 
00078     /**
00079      * Return the config for a specified ai
00080      */
00081     static const config& get_ai_config_for(const std::string &id);
00082 
00083 
00084     /**
00085      * Returns a list of available AIs.
00086      * @return the list of available AIs.
00087      */
00088     static std::vector<description*> get_available_ais();
00089 
00090 
00091     /**
00092      * get side config from file
00093      * @param file the file name to open. follows usual WML convention.
00094      * @param[out] cfg the config to be written from file.
00095      * @return was all ok?
00096      * @retval true success
00097      * @retval false failure
00098      */
00099     static bool get_side_config_from_file( const std::string& file, config& cfg );
00100 
00101 
00102 
00103     /**
00104      * change a bunch of old aspect configs into a new-style [ai] snippet
00105      * @param[in] ai_parameters - old [ai] snippets
00106      * @param[out cfg - new-style [ai] snippet
00107      */
00108     static void upgrade_aspect_configs_from_1_07_02_to_1_07_03(side_number side, const config::const_child_itors &ai_parameters, config &parsed_cfg);
00109 
00110 
00111     /**
00112      * @param[in] cfg the config to be read
00113      * @param[out] parsed_cfg parsed config
00114      * @return was all ok?
00115      * @retval true success
00116      * @retval false failure
00117      */
00118     static bool parse_side_config(side_number side, const config& cfg, config &parsed_cfg);
00119 
00120 
00121 private:
00122     /**
00123      * Upgrade aspect config from version 1.7.2 to version 1.7.3
00124      * @param[in] cfg the config to be read
00125      * @param[out] parsed_cfg parsed config
00126      * @param[in] id id of the aspect to work on
00127      * @param aspect_was_attribute aspect was an attribute, not a [child]
00128      * @return was all ok?
00129      * @retval true success
00130      * @retval false failure
00131      */
00132     static bool upgrade_aspect_config_from_1_07_02_to_1_07_03(side_number side, const config& cfg, config& parsed_cfg, const std::string &id, bool aspect_was_attribute = true);
00133 
00134 
00135     /**
00136      * Upgrade protect goal config from version 1.7.2 to version 1.7.3
00137      * @param side side number
00138      * @param[in] protect_cfg the config to be read
00139      * @param[out] parsed_cfg parsed config, to which a new goal is to be added
00140      * @param[in] add_filter should [filter] be added to criteria or not
00141      */
00142     static void upgrade_protect_goal_config_from_1_07_02_to_1_07_03(side_number side, const config &protect_cfg, config &parsed_cfg, bool add_filter);
00143 
00144     /**
00145      * Upgrade side config from version 1.7.2 to version 1.7.3
00146      * @param[in] cfg the config to be read
00147      * @param[out] parsed_cfg parsed config
00148      * @return was all ok?
00149      * @retval true success, cfg is guaranteed to be valid
00150      * @retval false failure
00151      */
00152     static bool upgrade_side_config_from_1_07_02_to_1_07_03(side_number side, config &cfg);
00153 
00154     typedef std::map<std::string, description> description_map;
00155     static description_map ai_configurations_;
00156     static description_map era_ai_configurations_;
00157     static config default_config_;
00158 
00159 };
00160 
00161 } //end of namespace ai
00162 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:29 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs