2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/** @file ai_config.hpp AIConfig stores the configuration settings of every AI. */
|
|
|
|
|
|
|
|
#ifndef AI_CONFIG_HPP
|
|
|
|
#define AI_CONFIG_HPP
|
2010-02-10 16:24:05 +00:00
|
|
|
#ifdef ENABLE_AI
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
#include <map>
|
2009-01-20 16:49:10 +00:00
|
|
|
#include "ai_info.hpp"
|
2009-02-03 18:08:07 +00:00
|
|
|
#include "../core/string_compare_type.hpp"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "../company_type.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-07-31 22:16:34 +00:00
|
|
|
/**
|
|
|
|
* AI settings for one company slot.
|
|
|
|
*/
|
2009-01-12 17:11:45 +00:00
|
|
|
class AIConfig {
|
|
|
|
private:
|
2010-07-31 22:16:34 +00:00
|
|
|
/** List with name=>value pairs of all AI-specific settings */
|
2009-02-03 18:08:07 +00:00
|
|
|
typedef std::map<const char *, int, StringCompare> SettingValueList;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
AIConfig() :
|
|
|
|
name(NULL),
|
2009-01-13 00:10:58 +00:00
|
|
|
version(-1),
|
2009-01-20 16:49:10 +00:00
|
|
|
info(NULL),
|
2010-01-09 14:41:22 +00:00
|
|
|
config_list(NULL),
|
|
|
|
is_random_ai(false)
|
2009-01-12 17:11:45 +00:00
|
|
|
{}
|
2010-07-31 22:16:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new AI config that is a copy of an existing config.
|
|
|
|
* @param config The object to copy.
|
|
|
|
*/
|
2009-01-12 17:11:45 +00:00
|
|
|
AIConfig(const AIConfig *config);
|
2010-07-31 22:16:34 +00:00
|
|
|
|
|
|
|
/** Delete an AI configuration. */
|
2009-01-12 17:11:45 +00:00
|
|
|
~AIConfig();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set another AI to be loaded in this slot.
|
2009-01-13 01:46:46 +00:00
|
|
|
* @param name The name of the AI.
|
|
|
|
* @param version The version of the AI to load, or -1 of latest.
|
2010-01-29 00:03:31 +00:00
|
|
|
* @param force_exact_match If true try to find the exact same version
|
|
|
|
* as specified. If false any compatible version is ok.
|
2010-01-09 14:41:22 +00:00
|
|
|
* @param is_random Is the AI chosen randomly?
|
2009-01-12 17:11:45 +00:00
|
|
|
*/
|
2010-01-29 00:03:31 +00:00
|
|
|
void ChangeAI(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When ever the AI Scanner is reloaded, all infos become invalid. This
|
|
|
|
* function tells AIConfig about this.
|
2010-02-27 12:29:44 +00:00
|
|
|
* @return \c true if the reset was successful, \c false if the AI was no longer
|
2009-01-12 17:11:45 +00:00
|
|
|
* found.
|
|
|
|
*/
|
|
|
|
bool ResetInfo();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the AIInfo linked to this AIConfig.
|
|
|
|
*/
|
2010-01-07 00:09:27 +00:00
|
|
|
class AIInfo *GetInfo() const;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-01-20 16:49:10 +00:00
|
|
|
/**
|
|
|
|
* Get the config list for this AIConfig.
|
|
|
|
*/
|
|
|
|
const AIConfigItemList *GetConfigList();
|
|
|
|
|
2010-07-31 22:16:34 +00:00
|
|
|
/**
|
|
|
|
* Where to get the config from, either default (depends on current game
|
|
|
|
* mode) or force either newgame or normal
|
|
|
|
*/
|
2010-03-15 22:42:43 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Get the config of a company.
|
|
|
|
*/
|
2010-03-15 22:42:43 +00:00
|
|
|
static AIConfig *GetConfig(CompanyID company, AISettingSource source = AISS_DEFAULT);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-01-07 00:09:27 +00:00
|
|
|
int GetSetting(const char *name) const;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the value of a setting for this config.
|
|
|
|
*/
|
|
|
|
void SetSetting(const char *name, int value);
|
|
|
|
|
2009-01-20 16:49:10 +00:00
|
|
|
/**
|
|
|
|
* Reset all settings to their default value.
|
|
|
|
*/
|
|
|
|
void ResetSettings();
|
|
|
|
|
2009-01-13 16:53:03 +00:00
|
|
|
/**
|
|
|
|
* Randomize all settings the AI requested to be randomized.
|
|
|
|
*/
|
|
|
|
void AddRandomDeviation();
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Is this config attached to an AI?
|
|
|
|
*/
|
2010-01-07 00:09:27 +00:00
|
|
|
bool HasAI() const;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-01-09 14:41:22 +00:00
|
|
|
/**
|
|
|
|
* Is the current AI a randomly chosen AI?
|
|
|
|
*/
|
|
|
|
bool IsRandomAI() const;
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Get the name of the AI.
|
|
|
|
*/
|
2010-01-07 00:09:27 +00:00
|
|
|
const char *GetName() const;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-01-13 00:10:58 +00:00
|
|
|
/**
|
|
|
|
* Get the version of the AI.
|
|
|
|
*/
|
2010-01-07 00:09:27 +00:00
|
|
|
int GetVersion() const;
|
2009-01-13 00:10:58 +00:00
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-01-07 00:09:27 +00:00
|
|
|
void SettingsToString(char *string, size_t size) const;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
private:
|
2010-07-31 22:16:34 +00:00
|
|
|
const char *name; //!< Name of the AI
|
|
|
|
int version; //!< Version of the AI
|
|
|
|
class AIInfo *info; //!< AIInfo object for related to this AI version
|
|
|
|
SettingValueList settings; //!< List with all setting=>value pairs that are configure for this AI
|
|
|
|
AIConfigItemList *config_list; //!< List with all settings defined by this AI
|
|
|
|
bool is_random_ai; //!< True if the AI in this slot was randomly chosen.
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2010-02-10 16:24:05 +00:00
|
|
|
#endif /* ENABLE_AI */
|
2009-01-12 17:11:45 +00:00
|
|
|
#endif /* AI_CONFIG_HPP */
|