2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 21:21:05 +01: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_info.hpp AIInfo keeps track of all information of an AI, like Author, Description, ... */
|
|
|
|
|
2010-12-22 11:46:41 +00:00
|
|
|
#ifndef AI_INFO_HPP
|
|
|
|
#define AI_INFO_HPP
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-02-10 16:24:05 +00:00
|
|
|
#ifdef ENABLE_AI
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
#include <list>
|
2009-02-06 00:25:37 +00:00
|
|
|
#include "../core/smallmap_type.hpp"
|
2009-03-15 22:41:57 +00:00
|
|
|
#include "../script/script_info.hpp"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-07-31 23:16:34 +01:00
|
|
|
/** Bitmask of flags for AI settings. */
|
2009-01-12 17:11:45 +00:00
|
|
|
enum AIConfigFlags {
|
2010-08-01 20:36:56 +01:00
|
|
|
AICONFIG_NONE = 0x0, ///< No flags set.
|
|
|
|
AICONFIG_RANDOM = 0x1, ///< When randomizing the AI, pick any value between min_value and max_value when on custom difficulty setting.
|
|
|
|
AICONFIG_BOOLEAN = 0x2, ///< This value is a boolean (either 0 (false) or 1 (true) ).
|
|
|
|
AICONFIG_INGAME = 0x4, ///< This setting can be changed while the AI is running.
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2010-08-01 20:36:56 +01:00
|
|
|
typedef SmallMap<int, char *> LabelMapping; ///< Map-type used to map the setting numbers to labels.
|
2009-02-06 00:25:37 +00:00
|
|
|
|
2010-07-31 23:16:34 +01:00
|
|
|
/** Info about a single AI setting. */
|
2009-01-12 17:11:45 +00:00
|
|
|
struct AIConfigItem {
|
2010-08-01 20:36:56 +01:00
|
|
|
const char *name; ///< The name of the configuration setting.
|
|
|
|
const char *description; ///< The description of the configuration setting.
|
|
|
|
int min_value; ///< The minimal value this configuration setting can have.
|
|
|
|
int max_value; ///< The maximal value this configuration setting can have.
|
|
|
|
int custom_value; ///< The default value on custom difficulty setting.
|
|
|
|
int easy_value; ///< The default value on easy difficulty setting.
|
|
|
|
int medium_value; ///< The default value on medium difficulty setting.
|
|
|
|
int hard_value; ///< The default value on hard difficulty setting.
|
|
|
|
int random_deviation; ///< The maximum random deviation from the default value.
|
|
|
|
int step_size; ///< The step size in the gui.
|
|
|
|
AIConfigFlags flags; ///< Flags for the configuration setting.
|
|
|
|
LabelMapping *labels; ///< Text labels for the integer values.
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2009-01-20 16:49:10 +00:00
|
|
|
extern AIConfigItem _start_date_config;
|
|
|
|
|
2010-08-01 20:36:56 +01:00
|
|
|
typedef std::list<AIConfigItem> AIConfigItemList; ///< List of AIConfig items.
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-07-31 23:16:34 +01:00
|
|
|
/** Base class that holds some basic information about AIs and AI libraries. */
|
2009-03-15 22:41:57 +00:00
|
|
|
class AIFileInfo : public ScriptFileInfo {
|
2009-01-12 17:11:45 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Process the creation of a FileInfo object.
|
|
|
|
*/
|
2009-03-15 22:41:57 +00:00
|
|
|
static SQInteger Constructor(HSQUIRRELVM vm, AIFileInfo *info);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
protected:
|
2010-08-01 20:36:56 +01:00
|
|
|
class AIScanner *base; ///< AIScanner object that was used to scan this AI (library) info.
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2010-07-31 23:16:34 +01:00
|
|
|
/** All static information from an AI like name, version, etc. */
|
2009-01-12 17:11:45 +00:00
|
|
|
class AIInfo : public AIFileInfo {
|
|
|
|
public:
|
2011-05-01 10:24:19 +01:00
|
|
|
/**
|
|
|
|
* Get the class name, so the script code can create the right code.
|
|
|
|
* @return The class name.
|
|
|
|
*/
|
2009-01-12 17:11:45 +00:00
|
|
|
static const char *GetClassName() { return "AIInfo"; }
|
|
|
|
|
2009-12-06 20:22:21 +00:00
|
|
|
AIInfo();
|
2009-01-12 17:11:45 +00:00
|
|
|
~AIInfo();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an AI, using this AIInfo as start-template.
|
|
|
|
*/
|
|
|
|
static SQInteger Constructor(HSQUIRRELVM vm);
|
2010-07-31 23:16:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dummy-AI.
|
|
|
|
*/
|
2009-01-12 17:11:45 +00:00
|
|
|
static SQInteger DummyConstructor(HSQUIRRELVM vm);
|
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
/**
|
|
|
|
* Get the settings of the AI.
|
|
|
|
*/
|
|
|
|
bool GetSettings();
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Get the config list for this AI.
|
|
|
|
*/
|
2009-02-13 02:11:54 +00:00
|
|
|
const AIConfigItemList *GetConfigList() const;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-01-13 13:09:49 +00:00
|
|
|
/**
|
|
|
|
* Get the description of a certain ai config option.
|
|
|
|
*/
|
2009-02-13 02:11:54 +00:00
|
|
|
const AIConfigItem *GetConfigItem(const char *name) const;
|
2009-01-13 13:09:49 +00:00
|
|
|
|
2009-02-13 01:44:56 +00:00
|
|
|
/**
|
|
|
|
* Check if we can start this AI.
|
|
|
|
*/
|
2009-02-13 02:11:54 +00:00
|
|
|
bool CanLoadFromVersion(int version) const;
|
2009-02-13 01:44:56 +00:00
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Set a setting.
|
|
|
|
*/
|
|
|
|
SQInteger AddSetting(HSQUIRRELVM vm);
|
|
|
|
|
2009-02-06 00:25:37 +00:00
|
|
|
/**
|
|
|
|
* Add labels for a setting.
|
|
|
|
*/
|
|
|
|
SQInteger AddLabels(HSQUIRRELVM vm);
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Get the default value for a setting.
|
|
|
|
*/
|
2009-02-13 02:11:54 +00:00
|
|
|
int GetSettingDefaultValue(const char *name) const;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-04-21 20:13:32 +01:00
|
|
|
/**
|
|
|
|
* Use this AI as a random AI.
|
|
|
|
*/
|
|
|
|
bool UseAsRandomAI() const { return this->use_as_random; }
|
|
|
|
|
2009-08-18 19:51:42 +01:00
|
|
|
/**
|
|
|
|
* Get the API version this AI is written for.
|
|
|
|
*/
|
|
|
|
const char *GetAPIVersion() const { return this->api_version; }
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
private:
|
2010-08-01 20:36:56 +01:00
|
|
|
AIConfigItemList config_list; ///< List of settings from this AI.
|
|
|
|
int min_loadable_version; ///< The AI can load savegame data if the version is equal or greater than this.
|
|
|
|
bool use_as_random; ///< Should this AI be used when the user wants a "random AI"?
|
|
|
|
const char *api_version; ///< API version used by this AI.
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2010-07-31 23:16:34 +01:00
|
|
|
/** All static information from an AI library like name, version, etc. */
|
2009-01-12 17:11:45 +00:00
|
|
|
class AILibrary : public AIFileInfo {
|
|
|
|
public:
|
2009-01-15 15:56:10 +00:00
|
|
|
AILibrary() : AIFileInfo(), category(NULL) {};
|
2009-01-15 18:15:12 +00:00
|
|
|
~AILibrary();
|
2009-01-15 15:56:10 +00:00
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/**
|
|
|
|
* Create an AI, using this AIInfo as start-template.
|
|
|
|
*/
|
|
|
|
static SQInteger Constructor(HSQUIRRELVM vm);
|
|
|
|
|
2010-07-31 23:16:34 +01:00
|
|
|
/**
|
|
|
|
* Import a library in the current AI. This function can be used by AIs
|
|
|
|
* by calling import.
|
|
|
|
* @param vm The squirrel vm of the calling AI.
|
|
|
|
*/
|
2009-01-12 17:11:45 +00:00
|
|
|
static SQInteger Import(HSQUIRRELVM vm);
|
2009-01-15 15:56:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the category this library is in.
|
|
|
|
*/
|
2009-02-13 02:11:54 +00:00
|
|
|
const char *GetCategory() const { return this->category; }
|
2009-01-15 15:56:10 +00:00
|
|
|
|
|
|
|
private:
|
2010-08-01 20:36:56 +01:00
|
|
|
const char *category; ///< The category this library is in.
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2010-02-10 16:24:05 +00:00
|
|
|
#endif /* ENABLE_AI */
|
2010-12-22 11:46:41 +00:00
|
|
|
#endif /* AI_INFO_HPP */
|