Files
@ r14994:b24d36ab6c4f
Branch filter:
Location: cpp/openttd-patchpack/source/src/ai/ai_config.hpp
r14994:b24d36ab6c4f
3.8 KiB
text/x-c++hdr
(svn r19616) -Codechange: Increase transparency of 'Extract' by passing also the number of used bits.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | /* $Id$ */
/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file ai_config.hpp AIConfig stores the configuration settings of every AI. */
#ifndef AI_CONFIG_HPP
#define AI_CONFIG_HPP
#ifdef ENABLE_AI
#include <map>
#include "ai_info.hpp"
#include "../core/string_compare_type.hpp"
#include "../company_type.h"
class AIConfig {
private:
typedef std::map<const char *, int, StringCompare> SettingValueList;
public:
AIConfig() :
name(NULL),
version(-1),
info(NULL),
config_list(NULL),
is_random_ai(false)
{}
AIConfig(const AIConfig *config);
~AIConfig();
/**
* Set another AI to be loaded in this slot.
* @param name The name of the AI.
* @param version The version of the AI to load, or -1 of latest.
* @param force_exact_match If true try to find the exact same version
* as specified. If false any compatible version is ok.
* @param is_random Is the AI chosen randomly?
*/
void ChangeAI(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
/**
* When ever the AI Scanner is reloaded, all infos become invalid. This
* function tells AIConfig about this.
* @return \c true if the reset was successful, \c false if the AI was no longer
* found.
*/
bool ResetInfo();
/**
* Get the AIInfo linked to this AIConfig.
*/
class AIInfo *GetInfo() const;
/**
* Get the config list for this AIConfig.
*/
const AIConfigItemList *GetConfigList();
/* Where to get the config from, either default (depends on current game
* mode) or force either newgame or normal */
enum AISettingSource {
AISS_DEFAULT, ///< Get the AI config from the current game mode
AISS_FORCE_NEWGAME, ///< Get the newgame AI config
AISS_FORCE_GAME, ///< Get the AI config from the current game
};
/**
* Get the config of a company.
*/
static AIConfig *GetConfig(CompanyID company, AISettingSource source = AISS_DEFAULT);
/**
* Get the value of a setting for this config. It might fallback to his
* 'info' to find the default value (if not set or if not-custom difficulty
* level).
* @return The (default) value of the setting, or -1 if the setting was not
* found.
*/
int GetSetting(const char *name) const;
/**
* Set the value of a setting for this config.
*/
void SetSetting(const char *name, int value);
/**
* Reset all settings to their default value.
*/
void ResetSettings();
/**
* Randomize all settings the AI requested to be randomized.
*/
void AddRandomDeviation();
/**
* Is this config attached to an AI?
*/
bool HasAI() const;
/**
* Is the current AI a randomly chosen AI?
*/
bool IsRandomAI() const;
/**
* Get the name of the AI.
*/
const char *GetName() const;
/**
* Get the version of the AI.
*/
int GetVersion() const;
/**
* Convert a string which is stored in the config file or savegames to
* custom settings of this AI.
*/
void StringToSettings(const char *value);
/**
* Convert the custom settings to a string that can be stored in the config
* file or savegames.
*/
void SettingsToString(char *string, size_t size) const;
private:
const char *name;
int version;
class AIInfo *info;
SettingValueList settings;
AIConfigItemList *config_list;
bool is_random_ai;
};
#endif /* ENABLE_AI */
#endif /* AI_CONFIG_HPP */
|