summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-02-10 16:24:05 +0000
committerrubidium <rubidium@openttd.org>2010-02-10 16:24:05 +0000
commit21bd2722cd89995370523385c213da32c8d47100 (patch)
treee7f3bb43657b1f8a59f89899dfc582d480bedad0 /src/saveload
parent78ce2858fc2704a5aafbc0b76cdb636338122f63 (diff)
downloadopenttd-21bd2722cd89995370523385c213da32c8d47100.tar.xz
(svn r19081) -Codechange: make it possible to disable compilation of the AI+Squirrel
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/ai_sl.cpp87
1 files changed, 83 insertions, 4 deletions
diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp
index 2a0e5d4ad..a9ae30020 100644
--- 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 @@ 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 */