# ai_config.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_config.hpp 19430 2010-03-15 22:52:39Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef AI_CONFIG_HPP
    00013 #define AI_CONFIG_HPP
    00014 #ifdef ENABLE_AI
    00015
    00016 #include <map>
    00017 #include "ai_info.hpp"
    00018 #include "../core/string_compare_type.hpp"
    00019 #include "../company_type.h"
    00020
    00021 class AIConfig {
    00022 private:
    00023   typedef std::map<const char *, int, StringCompare> SettingValueList;
    00024
    00025 public:
    00026   AIConfig() :
    00027     name(NULL),
    00028     version(-1),
    00029     info(NULL),
    00030     config_list(NULL),
    00031     is_random_ai(false)
    00032   {}
    00033   AIConfig(const AIConfig *config);
    00034   ~AIConfig();
    00035
    00044   void ChangeAI(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
    00045
    00052   bool ResetInfo();
    00053
    00057   class AIInfo *GetInfo() const;
    00058
    00062   const AIConfigItemList *GetConfigList();
    00063
    00064   /* Where to get the config from, either default (depends on current game
    00065    * mode) or force either newgame or normal */
    00066   enum AISettingSource {
    00067     AISS_DEFAULT,
    00068     AISS_FORCE_NEWGAME,
    00069     AISS_FORCE_GAME,
    00070   };
    00071
    00075   static AIConfig *GetConfig(CompanyID company, AISettingSource source = AISS_DEFAULT);
    00076
    00084   int GetSetting(const char *name) const;
    00085
    00089   void SetSetting(const char *name, int value);
    00090
    00094   void ResetSettings();
    00095
    00099   void AddRandomDeviation();
    00100
    00104   bool HasAI() const;
    00105
    00109   bool IsRandomAI() const;
    00110
    00114   const char *GetName() const;
    00115
    00119   int GetVersion() const;
    00120
    00125   void StringToSettings(const char *value);
    00126
    00131   void SettingsToString(char *string, size_t size) const;
    00132
    00133 private:
    00134   const char *name;
    00135   int version;
    00136   class AIInfo *info;
    00137   SettingValueList settings;
    00138   AIConfigItemList *config_list;
    00139   bool is_random_ai;
    00140 };
    00141
    00142 #endif /* ENABLE_AI */
    00143 #endif /* AI_CONFIG_HPP */