# HG changeset patch # User rubidium # Date 1265819045 0 # Node ID 38952764f91f2b1f5d2fcfeedc788f5e1a2eeaf8 # Parent 48f9a3fd032ce4c827c9f1bab3506c46c17e50eb (svn r19081) -Codechange: make it possible to disable compilation of the AI+Squirrel diff --git a/Doxyfile b/Doxyfile --- a/Doxyfile +++ b/Doxyfile @@ -196,7 +196,7 @@ SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = -PREDEFINED = +PREDEFINED = ENABLE_NETWORK ENABLE_AI EXPAND_AS_DEFINED = DEF_COMMAND SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- diff --git a/Makefile.src.in b/Makefile.src.in --- a/Makefile.src.in +++ b/Makefile.src.in @@ -58,7 +58,10 @@ # Make sure endian_target.h is reasable as if it was in the src/ dir CFLAGS += -I $(SRC_OBJS_DIR) -I $(LANG_OBJS_DIR) -CFLAGS_MAKEDEP += -I $(SRC_OBJS_DIR) -I $(LANG_OBJS_DIR) -I $(SCRIPT_SRC_DIR) +CFLAGS_MAKEDEP += -I $(SRC_OBJS_DIR) -I $(LANG_OBJS_DIR) +ifdef SCRIPT_SRC_DIR + CFLAGS_MAKEDEP += -I $(SCRIPT_SRC_DIR) +endif ENDIAN_TARGETS := endian_target.h $(ENDIAN_CHECK) diff --git a/config.lib b/config.lib --- a/config.lib +++ b/config.lib @@ -51,6 +51,7 @@ enable_lto="0" enable_dedicated="0" enable_network="1" + enable_ai="1" enable_static="1" enable_translator="0" enable_unicode="1" @@ -122,6 +123,7 @@ enable_lto enable_dedicated enable_network + enable_ai enable_static enable_translator enable_unicode @@ -277,6 +279,9 @@ --enable-network) enable_network="2";; --enable-network=*) enable_network="$optarg";; --disable-network) enable_network="0";; + --enable-ai) enable_ai="2";; + --enable-ai=*) enable_ai="$optarg";; + --disable-ai) enable_ai="0";; --disable-static) enable_static="0";; --enable-static) enable_static="2";; --enable-static=*) enable_static="$optarg";; @@ -713,6 +718,14 @@ log 1 "checking network... disabled" fi + if [ "$enable_ai" != "0" ]; then + log 1 "checking ai... found" + SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include" + else + log 1 "checking ai... disabled" + SCRIPT_SRC_DIR="" + fi + if [ "$enable_translator" != "0" ]; then log 1 "checking translator... debug" # -t shows TODO items, normally they are muted @@ -728,15 +741,6 @@ log 1 "checking assert... disabled" fi - SCRIPT_SRC_DIR="$ROOT_DIR/src/3rdparty/squirrel/include" - if [ ! -d "$SCRIPT_SRC_DIR" ]; then - log 1 "checking 3rdparty... NOT FOUND" - log 1 "ERROR: please make sure you have src/3rdparty/squirrel" - log 1 "ERROR: you can find the source at svn://svn.openttd.org/3rdparty/squirrel" - exit 1 - fi - log 1 "checking 3rdparty... found" - pre_detect_with_zlib=$with_zlib detect_zlib @@ -1429,7 +1433,9 @@ if [ "$cpu_type" = "64" ] && [ "$enable_universal" = "0" ]; then CFLAGS="$CFLAGS -D_SQ64" fi - CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR" + if [ "$enable_ai" != "0" ]; then + CFLAGS="$CFLAGS -I$SCRIPT_SRC_DIR -DENABLE_AI" + fi if [ -n "$png_config" ]; then CFLAGS="$CFLAGS -DWITH_PNG" diff --git a/configure b/configure --- a/configure +++ b/configure @@ -113,6 +113,7 @@ if ($0 == "OS2" && "'$os'" != "OS2") { next; } if ($0 == "PSP" && "'$os'" != "PSP") { next; } if ($0 == "DEDICATED" && "'$enable_dedicated'" != "1") { next; } + if ($0 == "AI" && "'$enable_ai'" == "0") { next; } if ($0 == "COCOA" && "'$with_cocoa'" == "0") { next; } if ($0 == "DOS" && "'$os'" != "DOS") { next; } if ($0 == "BEOS" && "'$os'" != "BEOS" && diff --git a/projects/generate b/projects/generate --- a/projects/generate +++ b/projects/generate @@ -40,6 +40,7 @@ png_config="1" os="MSVC" enable_dedicated="0" +enable_ai="1" with_cocoa="0" enable_directmusic="1" with_threads="1" @@ -94,6 +95,7 @@ if ($0 == "PSP" && "'$os'" != "PSP") { next; } if ($0 == "DOS" && "'$os'" != "DOS") { next; } if ($0 == "DEDICATED" && "'$enable_dedicated'" != "1") { next; } + if ($0 == "AI" && "'$enable_ai'" == "0") { next; } if ($0 == "COCOA" && "'$with_cocoa'" == "0") { next; } if ($0 == "BEOS" && "'$os'" != "BEOS") { next; } if ($0 == "WIN32" && "'$os'" != "MINGW" && diff --git a/source.list b/source.list --- a/source.list +++ b/source.list @@ -517,6 +517,7 @@ 3rdparty/md5/md5.cpp 3rdparty/md5/md5.h +#if AI # Script script/script_info.cpp script/script_info.hpp @@ -697,6 +698,7 @@ ai/api/ai_vehiclelist.cpp ai/api/ai_waypoint.cpp ai/api/ai_waypointlist.cpp +#end # Blitters #if DEDICATED diff --git a/src/ai/ai.hpp b/src/ai/ai.hpp --- a/src/ai/ai.hpp +++ b/src/ai/ai.hpp @@ -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 @@ 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 */ diff --git a/src/ai/ai_config.hpp b/src/ai/ai_config.hpp --- a/src/ai/ai_config.hpp +++ b/src/ai/ai_config.hpp @@ -11,6 +11,7 @@ #ifndef AI_CONFIG_HPP #define AI_CONFIG_HPP +#ifdef ENABLE_AI #include #include "ai_info.hpp" @@ -130,4 +131,5 @@ bool is_random_ai; }; +#endif /* ENABLE_AI */ #endif /* AI_CONFIG_HPP */ diff --git a/src/ai/ai_gui.hpp b/src/ai/ai_gui.hpp --- a/src/ai/ai_gui.hpp +++ b/src/ai/ai_gui.hpp @@ -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 */ diff --git a/src/ai/ai_info.hpp b/src/ai/ai_info.hpp --- a/src/ai/ai_info.hpp +++ b/src/ai/ai_info.hpp @@ -12,6 +12,8 @@ #ifndef AI_INFO #define AI_INFO +#ifdef ENABLE_AI + #include #include "../core/smallmap_type.hpp" #include "../script/script_info.hpp" @@ -141,4 +143,5 @@ const char *category; }; +#endif /* ENABLE_AI */ #endif /* AI_INFO */ diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1269,17 +1269,14 @@ 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, diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -507,6 +507,7 @@ _next_competitor_start = 0; } +#ifdef ENABLE_AI static void MaybeStartNewCompany() { #ifdef ENABLE_NETWORK @@ -527,6 +528,7 @@ DoCommandP(0, 1, INVALID_COMPANY, CMD_COMPANY_CTRL); } } +#endif /* ENABLE_AI */ void InitializeCompanies() { @@ -608,6 +610,7 @@ 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 @@ 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; } diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -991,6 +991,7 @@ return true; } +#ifdef ENABLE_AI DEF_CONSOLE_CMD(ConListAI) { char buf[4096]; @@ -1157,6 +1158,7 @@ return true; } +#endif /* ENABLE_AI */ DEF_CONSOLE_CMD(ConGetSeed) { @@ -1793,7 +1795,6 @@ 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 @@ 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 @@ 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 @@ 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"); diff --git a/src/crashlog.cpp b/src/crashlog.cpp --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -134,7 +134,9 @@ 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"); diff --git a/src/lang/english.txt b/src/lang/english.txt --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3218,6 +3218,9 @@ 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 diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp --- a/src/network/network_command.cpp +++ b/src/network/network_command.cpp @@ -38,7 +38,11 @@ /* 0x0F */ CcPlaySound1E, /* 0x10 */ CcStation, /* 0x11 */ CcTerraform, +#ifdef ENABLE_AI /* 0x12 */ CcAI, +#else + /* 0x12 */ NULL, +#endif /* ENABLE_AI */ /* 0x13 */ CcCloneVehicle, /* 0x14 */ CcGiveMoney, /* 0x15 */ CcCreateGroup, diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -167,9 +167,11 @@ 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_AI_LIBRARY); +#endif /* ENABLE_AI */ this->RequestContentList(CONTENT_TYPE_NEWGRF); - this->RequestContentList(CONTENT_TYPE_AI_LIBRARY); return; } diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -385,20 +385,24 @@ 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; diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp --- a/src/saveload/ai_sl.cpp +++ b/src/saveload/ai_sl.cpp @@ -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 @@ 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 @@ 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 */ diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -866,7 +866,10 @@ } 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 AILoadConfig(IniFile *ini, const char *grpname) { +#ifdef ENABLE_AI IniGroup *group = ini->GetGroup(grpname); IniItem *item; @@ -1169,6 +1173,7 @@ } 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 AISaveConfig(IniFile *ini, const char *grpname) { +#ifdef ENABLE_AI IniGroup *group = ini->GetGroup(grpname); if (group == NULL) return; @@ -1274,6 +1280,7 @@ IniItem *item = new IniItem(group, name, strlen(name)); item->SetValue(value); } +#endif /* ENABLE_AI */ } /** diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -655,8 +655,11 @@ 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;