summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
committertruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
commita3dd7506d377b1434f913bd65c019eed52b64b6e (patch)
treeced1a262eb143ad6e64ec02f4a4c89835c0c32fd /src/saveload
parent9294f9616866b9778c22076c19b5a32b4f85f788 (diff)
downloadopenttd-a3dd7506d377b1434f913bd65c019eed52b64b6e.tar.xz
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
NoAI is an API (a framework) to build your own AIs in. See: http://wiki.openttd.org/wiki/index.php/AI:Main_Page With many thanks to: - glx and Rubidium for their syncing, feedback and hard work - Yexo for his feedback, patches, and AIs which tested the system very deep - Morloth for his feedback and patches - TJIP for hosting a challenge which kept NoAI on track - All AI authors for testing our AI API, and all other people who helped in one way or another -Remove: all old AIs and their cheats/hacks
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp9
-rw-r--r--src/saveload/ai_sl.cpp138
-rw-r--r--src/saveload/company_sl.cpp74
-rw-r--r--src/saveload/oldloader.cpp156
-rw-r--r--src/saveload/saveload.cpp4
5 files changed, 147 insertions, 234 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 4aa4a2eee..13aeac2af 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -48,6 +48,7 @@
#include "../company_func.h"
#include "../command_func.h"
#include "../road_cmd.h"
+#include "../ai/ai.hpp"
#include "table/strings.h"
@@ -468,6 +469,14 @@ bool AfterLoadGame()
/* Update all vehicles */
AfterLoadVehicles(true);
+ /* Make sure there is an AI attached to an AI company */
+ {
+ Company *c;
+ FOR_ALL_COMPANIES(c) {
+ if (c->is_ai && c->ai_instance == NULL) AI::StartNew(c->index);
+ }
+ }
+
/* Update all waypoints */
if (CheckSavegameVersion(12)) FixOldWaypoints();
diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp
index b4d16a6b5..5e444ea9f 100644
--- a/src/saveload/ai_sl.cpp
+++ b/src/saveload/ai_sl.cpp
@@ -1,79 +1,87 @@
/* $Id$ */
-/** @file ai_sl.cpp Code handling saving and loading of old AI + new AI initialisation after game load */
+/** @file ai_sl.cpp Handles the saveload part of the AIs */
#include "../stdafx.h"
-#include "../ai/ai.h"
-#include "../ai/default/default.h"
-
+#include "../openttd.h"
+#include "../company_base.h"
+#include "../company_func.h"
+#include "../debug.h"
#include "saveload.h"
+#include "../settings_type.h"
+#include "../string_func.h"
+#include "../ai/ai.hpp"
+#include "../ai/ai_config.hpp"
-static const SaveLoad _company_ai_desc[] = {
- SLE_VAR(CompanyAI, state, SLE_UINT8),
- SLE_VAR(CompanyAI, tick, SLE_UINT8),
- SLE_CONDVAR(CompanyAI, state_counter, SLE_FILE_U16 | SLE_VAR_U32, 0, 12),
- SLE_CONDVAR(CompanyAI, state_counter, SLE_UINT32, 13, SL_MAX_VERSION),
- SLE_VAR(CompanyAI, timeout_counter, SLE_UINT16),
-
- SLE_VAR(CompanyAI, state_mode, SLE_UINT8),
- SLE_VAR(CompanyAI, banned_tile_count, SLE_UINT8),
- SLE_VAR(CompanyAI, railtype_to_use, SLE_UINT8),
-
- SLE_VAR(CompanyAI, cargo_type, SLE_UINT8),
- SLE_VAR(CompanyAI, num_wagons, SLE_UINT8),
- SLE_VAR(CompanyAI, build_kind, SLE_UINT8),
- SLE_VAR(CompanyAI, num_build_rec, SLE_UINT8),
- SLE_VAR(CompanyAI, num_loco_to_build, SLE_UINT8),
- SLE_VAR(CompanyAI, num_want_fullload, SLE_UINT8),
-
- SLE_VAR(CompanyAI, route_type_mask, SLE_UINT8),
-
- SLE_CONDVAR(CompanyAI, start_tile_a, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(CompanyAI, start_tile_a, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_CONDVAR(CompanyAI, cur_tile_a, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(CompanyAI, cur_tile_a, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_VAR(CompanyAI, start_dir_a, SLE_UINT8),
- SLE_VAR(CompanyAI, cur_dir_a, SLE_UINT8),
-
- SLE_CONDVAR(CompanyAI, start_tile_b, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(CompanyAI, start_tile_b, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_CONDVAR(CompanyAI, cur_tile_b, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(CompanyAI, cur_tile_b, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_VAR(CompanyAI, start_dir_b, SLE_UINT8),
- SLE_VAR(CompanyAI, cur_dir_b, SLE_UINT8),
-
- SLE_REF(CompanyAI, cur_veh, REF_VEHICLE),
-
- SLE_ARR(CompanyAI, wagon_list, SLE_UINT16, 9),
- SLE_ARR(CompanyAI, order_list_blocks, SLE_UINT8, 20),
- SLE_ARR(CompanyAI, banned_tiles, SLE_UINT16, 16),
-
- SLE_CONDNULL(64, 2, SL_MAX_VERSION),
- SLE_END()
-};
+static char _ai_saveload_ainame[64];
+static char _ai_company_convert_array[1024];
-static const SaveLoad _company_ai_build_rec_desc[] = {
- SLE_CONDVAR(AiBuildRec, spec_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(AiBuildRec, spec_tile, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_CONDVAR(AiBuildRec, use_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(AiBuildRec, use_tile, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_VAR(AiBuildRec, rand_rng, SLE_UINT8),
- SLE_VAR(AiBuildRec, cur_building_rule, SLE_UINT8),
- SLE_VAR(AiBuildRec, unk6, SLE_UINT8),
- SLE_VAR(AiBuildRec, unk7, SLE_UINT8),
- SLE_VAR(AiBuildRec, buildcmd_a, SLE_UINT8),
- SLE_VAR(AiBuildRec, buildcmd_b, SLE_UINT8),
- SLE_VAR(AiBuildRec, direction, SLE_UINT8),
- SLE_VAR(AiBuildRec, cargo, SLE_UINT8),
+static const SaveLoad _ai_company[] = {
+ SLEG_STR(_ai_saveload_ainame, SLE_STRB),
+ SLEG_STR(_ai_company_convert_array, SLE_STRB),
SLE_END()
};
+static void SaveReal_AIPL(int *index_ptr)
+{
+ CompanyID index = (CompanyID)*index_ptr;
+ AIConfig *config = AIConfig::GetConfig(index);
+
+ ttd_strlcpy(_ai_saveload_ainame, config->GetName(), lengthof(_ai_saveload_ainame));
+
+ _ai_company_convert_array[0] = '\0';
+ config->SettingsToString(_ai_company_convert_array, lengthof(_ai_company_convert_array));
+
+ SlObject(NULL, _ai_company);
+ /* If the AI was active, store his data too */
+ if (IsValidCompanyID(index) && !IsHumanCompany(index)) AI::Save(index);
+}
+
+static void Load_AIPL()
+{
+ /* Free all current data */
+ for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
+ AIConfig::GetConfig(c)->ChangeAI(NULL);
+ }
+
+ CompanyID index;
+ while ((index = (CompanyID)SlIterateArray()) != (CompanyID)-1) {
+ AIConfig *config = AIConfig::GetConfig(index);
+ SlObject(NULL, _ai_company);
+
+ if (_ai_saveload_ainame[0] == '\0' || AI::GetCompanyInfo(_ai_saveload_ainame) == NULL) {
+ if (strcmp(_ai_saveload_ainame, "%_dummy") != 0) {
+ DEBUG(ai, 0, "The savegame has an AI by the name '%s' which is no longer available.", _ai_saveload_ainame);
+ DEBUG(ai, 0, "A random other AI will be loaded in its place.");
+ } else {
+ DEBUG(ai, 0, "The savegame had no AIs available at the time of saving.");
+ DEBUG(ai, 0, "A random available AI will be loaded now.");
+ }
+ config->ChangeAI(NULL);
+ } else {
+ config->ChangeAI(_ai_saveload_ainame);
+ }
+
+ config->StringToSettings(_ai_company_convert_array);
+
+ /* Start the AI directly if it was active in the savegame */
+ if (IsValidCompanyID(index) && !IsHumanCompany(index)) {
+ AI::StartNew(index);
+ AI::Load(index);
+ }
+ }
+}
-void SaveLoad_AI(CompanyID company)
+static void Save_AIPL()
{
- CompanyAI *cai = &_companies_ai[company];
- SlObject(cai, _company_ai_desc);
- for (int i = 0; i != cai->num_build_rec; i++) {
- SlObject(&cai->src + i, _company_ai_build_rec_desc);
+ for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
+ if (!AIConfig::GetConfig((CompanyID)i)->HasAI()) continue;
+
+ SlSetArrayIndex(i);
+ SlAutolength((AutolengthProc *)SaveReal_AIPL, &i);
}
}
+
+extern const ChunkHandler _ai_chunk_handlers[] = {
+ { 'AIPL', Save_AIPL, Load_AIPL, CH_ARRAY | CH_LAST},
+};
diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp
index 933cc0bde..ead54be0d 100644
--- a/src/saveload/company_sl.cpp
+++ b/src/saveload/company_sl.cpp
@@ -6,8 +6,7 @@
#include "../company_base.h"
#include "../company_func.h"
#include "../network/network.h"
-#include "../ai/ai.h"
-#include "../ai/trolly/trolly.h"
+#include "../ai/ai.hpp"
#include "../company_manager_face.h"
#include "saveload.h"
@@ -130,7 +129,8 @@ static const SaveLoad _company_desc[] = {
SLE_CONDARR(Company, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1),
SLE_CONDARR(Company, yearly_expenses, SLE_INT64, 3 * 13, 2, SL_MAX_VERSION),
- SLE_CONDVAR(Company, is_ai, SLE_BOOL, 2, SL_MAX_VERSION),
+ SLE_CONDVAR(Company, is_ai, SLE_BOOL, 2, SL_MAX_VERSION),
+ SLE_CONDVAR(Company, is_noai, SLE_BOOL, 107, SL_MAX_VERSION),
SLE_CONDNULL(1, 4, 99),
/* Engine renewal settings */
@@ -141,7 +141,7 @@ static const SaveLoad _company_desc[] = {
SLE_CONDVAR(Company, engine_renew_money, SLE_UINT32, 16, SL_MAX_VERSION),
SLE_CONDVAR(Company, renew_keep_length, SLE_BOOL, 2, SL_MAX_VERSION), // added with 16.1, but was blank since 2
- /* reserve extra space in savegame here. (currently 63 bytes) */
+ /* Reserve extra space in savegame here. (currently 63 bytes) */
SLE_CONDNULL(63, 2, SL_MAX_VERSION),
SLE_END()
@@ -162,6 +162,51 @@ static const SaveLoad _company_economy_desc[] = {
SLE_END()
};
+/* We do need to read this single value, as the bigger it gets, the more data is stored */
+struct CompanyOldAI {
+ uint8 num_build_rec;
+};
+
+static const SaveLoad _company_ai_desc[] = {
+ SLE_CONDNULL(2, 0, 106),
+ SLE_CONDNULL(2, 0, 12),
+ SLE_CONDNULL(4, 13, 106),
+ SLE_CONDNULL(8, 0, 106),
+ SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, 0, 106),
+ SLE_CONDNULL(3, 0, 106),
+
+ SLE_CONDNULL(2, 0, 5),
+ SLE_CONDNULL(4, 6, 106),
+ SLE_CONDNULL(2, 0, 5),
+ SLE_CONDNULL(4, 6, 106),
+ SLE_CONDNULL(2, 0, 106),
+
+ SLE_CONDNULL(2, 0, 5),
+ SLE_CONDNULL(4, 6, 106),
+ SLE_CONDNULL(2, 0, 5),
+ SLE_CONDNULL(4, 6, 106),
+ SLE_CONDNULL(2, 0, 106),
+
+ SLE_CONDNULL(2, 0, 68),
+ SLE_CONDNULL(4, 69, 106),
+
+ SLE_CONDNULL(18, 0, 106),
+ SLE_CONDNULL(20, 0, 106),
+ SLE_CONDNULL(32, 0, 106),
+
+ SLE_CONDNULL(64, 2, 106),
+ SLE_END()
+};
+
+static const SaveLoad _company_ai_build_rec_desc[] = {
+ SLE_CONDNULL(2, 0, 5),
+ SLE_CONDNULL(4, 6, 106),
+ SLE_CONDNULL(2, 0, 5),
+ SLE_CONDNULL(4, 6, 106),
+ SLE_CONDNULL(8, 0, 106),
+ SLE_END()
+};
+
static const SaveLoad _company_livery_desc[] = {
SLE_CONDVAR(Livery, in_use, SLE_BOOL, 34, SL_MAX_VERSION),
SLE_CONDVAR(Livery, colour1, SLE_UINT8, 34, SL_MAX_VERSION),
@@ -175,10 +220,15 @@ static void SaveLoad_PLYR(Company *c)
SlObject(c, _company_desc);
- /* Write AI? */
- if (!IsHumanCompany(c->index)) {
- extern void SaveLoad_AI(CompanyID company);
- SaveLoad_AI(c->index);
+ /* Keep backwards compatible for savegames, so load the old AI block */
+ if (!IsHumanCompany(c->index) && !c->is_noai) {
+ CompanyOldAI old_ai;
+ char nothing;
+
+ SlObject(&old_ai, _company_ai_desc);
+ for (i = 0; i != old_ai.num_build_rec; i++) {
+ SlObject(&nothing, _company_ai_build_rec_desc);
+ }
}
/* Write economy */
@@ -225,13 +275,7 @@ static void Load_PLYR()
Company *c = new (index) Company();
SaveLoad_PLYR(c);
_company_colours[index] = c->colour;
-
- /* This is needed so an AI is attached to a loaded AI */
- if (c->is_ai && (!_networking || _network_server) && _ai.enabled) {
- /* Clear the memory of the new AI, otherwise we might be doing wrong things. */
- memset(&_companies_ainew[index], 0, sizeof(CompanyAiNew));
- AI_StartNewAI(c->index);
- }
+ c->is_noai = true;
}
}
diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp
index 9e503077b..930e8fa2b 100644
--- a/src/saveload/oldloader.cpp
+++ b/src/saveload/oldloader.cpp
@@ -17,8 +17,7 @@
#include "../debug.h"
#include "../depot_base.h"
#include "../newgrf_config.h"
-#include "../ai/ai.h"
-#include "../ai/default/default.h"
+#include "../ai/ai.hpp"
#include "../zoom_func.h"
#include "../functions.h"
#include "../date_func.h"
@@ -805,145 +804,6 @@ static bool OldCompanyEconomy(LoadgameState *ls, int num)
return true;
}
-static const OldChunks _company_ai_build_rec_chunk[] = {
- OCL_SVAR( OC_TILE, AiBuildRec, spec_tile ),
- OCL_SVAR( OC_TILE, AiBuildRec, use_tile ),
- OCL_SVAR( OC_UINT8, AiBuildRec, rand_rng ),
- OCL_SVAR( OC_UINT8, AiBuildRec, cur_building_rule ),
- OCL_SVAR( OC_UINT8, AiBuildRec, unk6 ),
- OCL_SVAR( OC_UINT8, AiBuildRec, unk7 ),
- OCL_SVAR( OC_UINT8, AiBuildRec, buildcmd_a ),
- OCL_SVAR( OC_UINT8, AiBuildRec, buildcmd_b ),
- OCL_SVAR( OC_UINT8, AiBuildRec, direction ),
- OCL_SVAR( OC_UINT8, AiBuildRec, cargo ),
-
- OCL_NULL( 8 ), ///< Junk...
-
- OCL_END()
-};
-
-static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
-{
- Company *c = GetCompany(_current_company_id);
-
- switch (num) {
- case 0: return LoadChunk(ls, &_companies_ai[c->index].src, _company_ai_build_rec_chunk);
- case 1: return LoadChunk(ls, &_companies_ai[c->index].dst, _company_ai_build_rec_chunk);
- case 2: return LoadChunk(ls, &_companies_ai[c->index].mid1, _company_ai_build_rec_chunk);
- case 3: return LoadChunk(ls, &_companies_ai[c->index].mid2, _company_ai_build_rec_chunk);
- }
-
- return false;
-}
-static const OldChunks _company_ai_chunk[] = {
- OCL_SVAR( OC_UINT8, CompanyAI, state ),
- OCL_NULL( 1 ), ///< Junk
- OCL_SVAR( OC_UINT8, CompanyAI, state_mode ),
- OCL_SVAR( OC_UINT16, CompanyAI, state_counter ),
- OCL_SVAR( OC_UINT16, CompanyAI, timeout_counter ),
-
- OCL_CHUNK( 4, OldLoadAIBuildRec ),
-
- OCL_NULL( 20 ), ///< More junk
-
- OCL_SVAR( OC_UINT8, CompanyAI, cargo_type ),
- OCL_SVAR( OC_UINT8, CompanyAI, num_wagons ),
- OCL_SVAR( OC_UINT8, CompanyAI, build_kind ),
- OCL_SVAR( OC_UINT8, CompanyAI, num_build_rec ),
- OCL_SVAR( OC_UINT8, CompanyAI, num_loco_to_build ),
- OCL_SVAR( OC_UINT8, CompanyAI, num_want_fullload ),
-
- OCL_NULL( 14 ), ///< Oh no more junk :|
-
- OCL_NULL( 2 ), ///< Loco-id, not used
-
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[0] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[1] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[2] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[3] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[4] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[5] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[6] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[7] ),
- OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[8] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[0] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[1] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[2] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[3] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[4] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[5] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[6] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[7] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[8] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[9] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[10] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[11] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[12] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[13] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[14] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[15] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[16] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[17] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[18] ),
- OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[19] ),
-
- OCL_SVAR( OC_UINT16, CompanyAI, start_tile_a ),
- OCL_SVAR( OC_UINT16, CompanyAI, start_tile_b ),
- OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_a ),
- OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_b ),
-
- OCL_SVAR( OC_UINT8, CompanyAI, start_dir_a ),
- OCL_SVAR( OC_UINT8, CompanyAI, start_dir_b ),
- OCL_SVAR( OC_UINT8, CompanyAI, cur_dir_a ),
- OCL_SVAR( OC_UINT8, CompanyAI, cur_dir_b ),
-
- OCL_SVAR( OC_UINT8, CompanyAI, banned_tile_count ),
-
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[0] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[0] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[1] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[1] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[2] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[2] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[3] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[3] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[4] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[4] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[5] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[5] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[6] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[6] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[7] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[7] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[8] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[8] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[9] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[9] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[10] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[10] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[11] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[11] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[12] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[12] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[13] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[13] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[14] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[14] ),
- OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[15] ),
- OCL_SVAR( OC_UINT8, CompanyAI, banned_val[15] ),
-
- OCL_SVAR( OC_UINT8, CompanyAI, railtype_to_use ),
- OCL_SVAR( OC_UINT8, CompanyAI, route_type_mask ),
-
- OCL_END()
-};
-
-static bool OldCompanyAI(LoadgameState *ls, int num)
-{
- return LoadChunk(ls, &_companies_ai[_current_company_id], _company_ai_chunk);
-}
-
-uint8 ai_tick;
static const OldChunks _company_chunk[] = {
OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
OCL_SVAR( OC_UINT32, Company, name_2 ),
@@ -970,10 +830,10 @@ static const OldChunks _company_chunk[] = {
OCL_SVAR( OC_TILE, Company, last_build_coordinate ),
OCL_SVAR( OC_UINT8, Company, num_valid_stat_ent ),
- OCL_CHUNK( 1, OldCompanyAI ),
+ OCL_NULL( 230 ), // Old AI
OCL_SVAR( OC_UINT8, Company, block_preview ),
- OCL_VAR( OC_UINT8, 1, &ai_tick ),
+ OCL_NULL( 1 ), // Old AI
OCL_SVAR( OC_UINT8, Company, avail_railtypes ),
OCL_SVAR( OC_TILE, Company, location_of_HQ ),
OCL_SVAR( OC_UINT8, Company, share_owners[0] ),
@@ -1001,7 +861,6 @@ static bool LoadOldCompany(LoadgameState *ls, int num)
c->name_1 = RemapOldStringID(_old_string_id);
c->president_name_1 = RemapOldStringID(_old_string_id_2);
- _companies_ai[_current_company_id].tick = ai_tick;
if (num == 0) {
/* If the first company has no name, make sure we call it UNNAMED */
@@ -1023,15 +882,6 @@ static bool LoadOldCompany(LoadgameState *ls, int num)
_company_colours[num] = c->colour;
c->inaugurated_year -= ORIGINAL_BASE_YEAR;
- /* State 20 for AI companies is sell vehicle. Since the AI struct is not
- * really figured out as of now, _companies_ai[c->index].cur_veh; needed for 'sell vehicle'
- * is NULL and the function will crash. To fix this, just change the state
- * to some harmless state, like 'loop vehicle'; 1 */
- if (!IsHumanCompany((CompanyID)num) && _companies_ai[c->index].state == 20) _companies_ai[c->index].state = 1;
-
- if (c->is_ai && (!_networking || _network_server) && _ai.enabled)
- AI_StartNewAI(c->index);
-
return true;
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 904c7ea44..6e41314f3 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -42,7 +42,7 @@
#include <list>
-extern const uint16 SAVEGAME_VERSION = 106;
+extern const uint16 SAVEGAME_VERSION = 107;
SavegameType _savegame_type; ///< type of savegame we are loading
@@ -1318,6 +1318,7 @@ extern const ChunkHandler _station_chunk_handlers[];
extern const ChunkHandler _industry_chunk_handlers[];
extern const ChunkHandler _economy_chunk_handlers[];
extern const ChunkHandler _subsidy_chunk_handlers[];
+extern const ChunkHandler _ai_chunk_handlers[];
extern const ChunkHandler _animated_tile_chunk_handlers[];
extern const ChunkHandler _newgrf_chunk_handlers[];
extern const ChunkHandler _group_chunk_handlers[];
@@ -1343,6 +1344,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
_sign_chunk_handlers,
_station_chunk_handlers,
_company_chunk_handlers,
+ _ai_chunk_handlers,
_animated_tile_chunk_handlers,
_newgrf_chunk_handlers,
_group_chunk_handlers,