(svn r19081) -Codechange: make it possible to disable compilation of the AI+Squirrel

This commit is contained in:
rubidium
2010-02-10 16:24:05 +00:00
parent 78ce2858fc
commit 21bd2722cd
21 changed files with 190 additions and 30 deletions

View File

@@ -12,6 +12,7 @@
#ifndef AI_HPP
#define AI_HPP
#ifdef ENABLE_AI
#include "api/ai_event_types.hpp"
#include "../date_type.h"
#include "../core/string_compare_type.hpp"
@@ -125,4 +126,26 @@ private:
static class AIScanner *ai_scanner;
};
#else /* ENABLE_AI */
#include "../company_type.h"
#define NewEvent(cid, event) nop()
#define BroadcastNewEvent(...) nop()
class AI {
public:
static void StartNew(CompanyID company, bool rerandomise_ai = true) {}
static void Stop(CompanyID company) {}
static void Initialize() {}
static void Uninitialize(bool keepConfig) {}
static void KillAll() {}
static void GameLoop() {}
static bool HasAI(const struct ContentInfo *ci, bool md5sum) { return false; }
static void Rescan() {}
static char *GetConsoleList(char *p, const char *last) { return p; }
static void nop() { }
};
#endif /* ENABLE_AI */
#endif /* AI_HPP */

View File

@@ -11,6 +11,7 @@
#ifndef AI_CONFIG_HPP
#define AI_CONFIG_HPP
#ifdef ENABLE_AI
#include <map>
#include "ai_info.hpp"
@@ -130,4 +131,5 @@ private:
bool is_random_ai;
};
#endif /* ENABLE_AI */
#endif /* AI_CONFIG_HPP */

View File

@@ -14,7 +14,17 @@
#include "../company_type.h"
#ifdef ENABLE_AI
void ShowAIDebugWindow(CompanyID show_company = INVALID_COMPANY);
void ShowAIConfigWindow();
#else
#include "table/strings.h"
static inline void ShowAIConfigWindow()
{
ShowErrorMessage(STR_ERROR_NO_AI, STR_ERROR_NO_AI_SUB, 0, 0);
}
static inline void ShowAIDebugWindow(CompanyID show_company = INVALID_COMPANY) {ShowAIConfigWindow();}
#endif /* ENABLE_AI */
#endif /* AI_GUI_HPP */

View File

@@ -12,6 +12,8 @@
#ifndef AI_INFO
#define AI_INFO
#ifdef ENABLE_AI
#include <list>
#include "../core/smallmap_type.hpp"
#include "../script/script_info.hpp"
@@ -141,4 +143,5 @@ private:
const char *category;
};
#endif /* ENABLE_AI */
#endif /* AI_INFO */

View File

@@ -1269,17 +1269,14 @@ static void CrashAirplane(Aircraft *v)
v->Next()->cargo.Truncate(0);
const Station *st = GetTargetAirportIfValid(v);
StringID newsitem;
AIEventVehicleCrashed::CrashReason crash_reason;
if (st == NULL) {
newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
crash_reason = AIEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT;
} else {
SetDParam(1, st->index);
newsitem = STR_NEWS_AIRCRAFT_CRASH;
crash_reason = AIEventVehicleCrashed::CRASH_PLANE_LANDING;
}
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, crash_reason));
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, st == NULL ? AIEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : AIEventVehicleCrashed::CRASH_PLANE_LANDING));
AddVehicleNewsItem(newsitem,
NS_ACCIDENT,

View File

@@ -507,6 +507,7 @@ void StartupCompanies()
_next_competitor_start = 0;
}
#ifdef ENABLE_AI
static void MaybeStartNewCompany()
{
#ifdef ENABLE_NETWORK
@@ -527,6 +528,7 @@ static void MaybeStartNewCompany()
DoCommandP(0, 1, INVALID_COMPANY, CMD_COMPANY_CTRL);
}
}
#endif /* ENABLE_AI */
void InitializeCompanies()
{
@@ -608,6 +610,7 @@ void OnTick_Companies()
if (c->bankrupt_asked != 0) HandleBankruptcyTakeover(c);
}
#ifdef ENABLE_AI
if (_next_competitor_start == 0) {
_next_competitor_start = AI::GetStartNextTime() * DAY_TICKS;
}
@@ -615,6 +618,7 @@ void OnTick_Companies()
if (AI::CanStartNew() && _game_mode != GM_MENU && --_next_competitor_start == 0) {
MaybeStartNewCompany();
}
#endif /* ENABLE_AI */
_cur_company_tick_index = (_cur_company_tick_index + 1) % MAX_COMPANIES;
}

View File

@@ -991,6 +991,7 @@ DEF_CONSOLE_CMD(ConRestart)
return true;
}
#ifdef ENABLE_AI
DEF_CONSOLE_CMD(ConListAI)
{
char buf[4096];
@@ -1157,6 +1158,7 @@ DEF_CONSOLE_CMD(ConRescanAI)
return true;
}
#endif /* ENABLE_AI */
DEF_CONSOLE_CMD(ConGetSeed)
{
@@ -1793,7 +1795,6 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("help", ConHelp);
IConsoleCmdRegister("info_cmd", ConInfoCmd);
IConsoleCmdRegister("info_var", ConInfoVar);
IConsoleCmdRegister("list_ai", ConListAI);
IConsoleCmdRegister("list_cmds", ConListCommands);
IConsoleCmdRegister("list_vars", ConListVariables);
IConsoleCmdRegister("list_aliases", ConListAliases);
@@ -1802,8 +1803,6 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("getseed", ConGetSeed);
IConsoleCmdRegister("getdate", ConGetDate);
IConsoleCmdRegister("quit", ConExit);
IConsoleCmdRegister("reload_ai", ConReloadAI);
IConsoleCmdRegister("rescan_ai", ConRescanAI);
IConsoleCmdRegister("resetengines", ConResetEngines);
IConsoleCmdRegister("return", ConReturn);
IConsoleCmdRegister("screenshot", ConScreenShot);
@@ -1814,8 +1813,6 @@ void IConsoleStdLibRegister()
IConsoleCmdRegister("rm", ConRemove);
IConsoleCmdRegister("save", ConSave);
IConsoleCmdRegister("saveconfig", ConSaveConfig);
IConsoleCmdRegister("start_ai", ConStartAI);
IConsoleCmdRegister("stop_ai", ConStopAI);
IConsoleCmdRegister("ls", ConListFiles);
IConsoleCmdRegister("cd", ConChangeDirectory);
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
@@ -1835,7 +1832,13 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("set_newgame", "setting_newgame %+");
IConsoleAliasRegister("list_patches", "list_settings %+");
#ifdef ENABLE_AI
IConsoleCmdRegister("list_ai", ConListAI);
IConsoleCmdRegister("reload_ai", ConReloadAI);
IConsoleCmdRegister("rescan_ai", ConRescanAI);
IConsoleCmdRegister("start_ai", ConStartAI);
IConsoleCmdRegister("stop_ai", ConStopAI);
#endif /* ENABLE_AI */
IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE, "Redirect debugging output from the console/command line to the ingame console (value 2). Default value: 1");

View File

@@ -134,7 +134,9 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
if (c->ai_info == NULL) {
buffer += seprintf(buffer, last, " %2i: Human\n", (int)c->index);
} else {
#ifdef ENABLE_AI
buffer += seprintf(buffer, last, " %2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
#endif /* ENABLE_AI */
}
}
buffer += seprintf(buffer, last, "\n");

View File

@@ -3218,6 +3218,9 @@ STR_AI_DEBUG_SETTINGS_TOOLTIP :{BLACK}Change t
STR_AI_DEBUG_RELOAD :{BLACK}Reload AI
STR_AI_DEBUG_RELOAD_TOOLTIP :{BLACK}Kill the AI, reload the script, and restart the AI
STR_ERROR_NO_AI :{WHITE}OpenTTD is build without AI support...
STR_ERROR_NO_AI_SUB :{WHITE}... no AIs are available!
STR_ERROR_AI_NO_AI_FOUND :No suitable AI found to load.{}This AI is a dummy AI and won't do anything.{}You can download several AIs via the 'Online Content' system.
STR_ERROR_AI_PLEASE_REPORT_CRASH :{WHITE}One of the running AIs crashed. Please report this to the AI author with a screenshot of the AI Debug Window.
STR_ERROR_AI_DEBUG_SERVER_ONLY :{YELLOW}AI Debug window is only available for the server

View File

@@ -38,7 +38,11 @@ static CommandCallback * const _callback_table[] = {
/* 0x0F */ CcPlaySound1E,
/* 0x10 */ CcStation,
/* 0x11 */ CcTerraform,
#ifdef ENABLE_AI
/* 0x12 */ CcAI,
#else
/* 0x12 */ NULL,
#endif /* ENABLE_AI */
/* 0x13 */ CcCloneVehicle,
/* 0x14 */ CcGiveMoney,
/* 0x15 */ CcCreateGroup,

View File

@@ -167,9 +167,11 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type)
this->RequestContentList(CONTENT_TYPE_BASE_SOUNDS);
this->RequestContentList(CONTENT_TYPE_SCENARIO);
this->RequestContentList(CONTENT_TYPE_HEIGHTMAP);
#ifdef ENABLE_AI
this->RequestContentList(CONTENT_TYPE_AI);
this->RequestContentList(CONTENT_TYPE_NEWGRF);
this->RequestContentList(CONTENT_TYPE_AI_LIBRARY);
#endif /* ENABLE_AI */
this->RequestContentList(CONTENT_TYPE_NEWGRF);
return;
}

View File

@@ -385,20 +385,24 @@ static void LoadIntroGame()
void MakeNewgameSettingsLive()
{
#ifdef ENABLE_AI
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
if (_settings_game.ai_config[c] != NULL) {
delete _settings_game.ai_config[c];
}
}
#endif /* ENABLE_AI */
_settings_game = _settings_newgame;
#ifdef ENABLE_AI
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
_settings_game.ai_config[c] = NULL;
if (_settings_newgame.ai_config[c] != NULL) {
_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
}
}
#endif /* ENABLE_AI */
}
byte _savegame_sort_order;

View File

@@ -14,10 +14,6 @@
#include "../debug.h"
#include "saveload.h"
#include "../string_func.h"
#include "../ai/ai.hpp"
#include "../ai/ai_config.hpp"
#include "../network/network.h"
#include "../ai/ai_instance.hpp"
static char _ai_saveload_name[64];
static int _ai_saveload_version;
@@ -32,6 +28,12 @@ static const SaveLoad _ai_company[] = {
SLE_END()
};
#ifdef ENABLE_AI
#include "../ai/ai.hpp"
#include "../ai/ai_config.hpp"
#include "../network/network.h"
#include "../ai/ai_instance.hpp"
static void SaveReal_AIPL(int *index_ptr)
{
CompanyID index = (CompanyID)*index_ptr;
@@ -121,3 +123,80 @@ static void Save_AIPL()
extern const ChunkHandler _ai_chunk_handlers[] = {
{ 'AIPL', Save_AIPL, Load_AIPL, NULL, CH_ARRAY | CH_LAST},
};
#else
/** The type of the data that follows in the savegame. */
enum SQSaveLoadType {
SQSL_INT = 0x00, ///< The following data is an integer.
SQSL_STRING = 0x01, ///< The following data is an string.
SQSL_ARRAY = 0x02, ///< The following data is an array.
SQSL_TABLE = 0x03, ///< The following data is an table.
SQSL_BOOL = 0x04, ///< The following data is a boolean.
SQSL_NULL = 0x05, ///< A null variable.
SQSL_ARRAY_TABLE_END = 0xFF, ///< Marks the end of an array or table, no data follows.
};
static byte _ai_sl_byte;
static const SaveLoad _ai_byte[] = {
SLEG_VAR(_ai_sl_byte, SLE_UINT8),
SLE_END()
};
static bool LoadObjects()
{
SlObject(NULL, _ai_byte);
switch (_ai_sl_byte) {
case SQSL_INT: {
int value;
SlArray(&value, 1, SLE_INT32);
return true;
}
case SQSL_STRING: {
SlObject(NULL, _ai_byte);
static char buf[256];
SlArray(buf, _ai_sl_byte, SLE_CHAR);
return true;
}
case SQSL_ARRAY:
while (LoadObjects()) { }
return true;
case SQSL_TABLE:
while (LoadObjects()) { LoadObjects(); }
return true;
case SQSL_BOOL:
SlObject(NULL, _ai_byte);
return true;
case SQSL_NULL:
return true;
case SQSL_ARRAY_TABLE_END:
return false;
default: NOT_REACHED();
}
}
static void Load_AIPL()
{
CompanyID index;
while ((index = (CompanyID)SlIterateArray()) != (CompanyID)-1) {
SlObject(NULL, _ai_company);
if (!Company::IsValidAiID(index)) continue;
SlObject(NULL, _ai_byte);
/* Check if there was anything saved at all. */
if (_ai_sl_byte == 0) continue;
LoadObjects();
}
}
extern const ChunkHandler _ai_chunk_handlers[] = {
{ 'AIPL', NULL, Load_AIPL, NULL, CH_ARRAY | CH_LAST},
};
#endif /* ENABLE_AI */

View File

@@ -866,7 +866,10 @@ static bool DifficultyChange(int32)
}
if (((_game_mode == GM_MENU) ? _settings_newgame.difficulty : _settings_game.difficulty).max_no_competitors != 0 &&
AI::GetInfoList()->size() == 0 && (!_networking || _network_server)) {
#ifdef ENABLE_AI
AI::GetInfoList()->size() == 0 &&
#endif /* ENABLE_AI */
(!_networking || _network_server)) {
ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, 0, 0, true);
}
@@ -1145,6 +1148,7 @@ static void NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
static void AILoadConfig(IniFile *ini, const char *grpname)
{
#ifdef ENABLE_AI
IniGroup *group = ini->GetGroup(grpname);
IniItem *item;
@@ -1169,6 +1173,7 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
}
if (item->value != NULL) config->StringToSettings(item->value);
}
#endif /* ENABLE_AI */
}
/* Load a GRF configuration from the given group name */
@@ -1254,6 +1259,7 @@ static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname)
static void AISaveConfig(IniFile *ini, const char *grpname)
{
#ifdef ENABLE_AI
IniGroup *group = ini->GetGroup(grpname);
if (group == NULL) return;
@@ -1274,6 +1280,7 @@ static void AISaveConfig(IniFile *ini, const char *grpname)
IniItem *item = new IniItem(group, name, strlen(name));
item->SetValue(value);
}
#endif /* ENABLE_AI */
}
/**

View File

@@ -655,8 +655,11 @@ public:
this->LowerWidget(GDW_LVL_CUSTOM);
this->InvalidateData();
if (widget / 3 == 0 && this->opt_mod_temp.difficulty.max_no_competitors != 0 &&
AI::GetInfoList()->size() == 0) {
if (widget / 3 == 0 &&
#ifdef ENABLE_AI
AI::GetInfoList()->size() == 0 &&
#endif /* ENABLE_AI */
this->opt_mod_temp.difficulty.max_no_competitors != 0) {
ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, 0, 0, true);
}
return;