summaryrefslogtreecommitdiff
path: root/src/saveload/company_sl.cpp
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/company_sl.cpp
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/company_sl.cpp')
-rw-r--r--src/saveload/company_sl.cpp74
1 files changed, 59 insertions, 15 deletions
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;
}
}