summaryrefslogtreecommitdiff
path: root/src/ai/ai_info_dummy.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/ai/ai_info_dummy.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/ai/ai_info_dummy.cpp')
-rw-r--r--src/ai/ai_info_dummy.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/ai/ai_info_dummy.cpp b/src/ai/ai_info_dummy.cpp
new file mode 100644
index 000000000..a060a0a65
--- /dev/null
+++ b/src/ai/ai_info_dummy.cpp
@@ -0,0 +1,66 @@
+/* $Id$ */
+
+#include <squirrel.h>
+#include "../stdafx.h"
+
+/* The reason this exists in C++, is that a user can trash his ai/ dir,
+ * leaving no AIs available. The complexity to solve this is insane, and
+ * therefor the alternative is used, and make sure there is always an AI
+ * available, no matter what the situation is. By defining it in C++, there
+ * is simply now way a user can delete it, and therefor safe to use. It has
+ * to be noted that this AI is complete invisible for the user, and impossible
+ * to select manual. It is a fail-over in case no AIs are available.
+ */
+
+const SQChar dummy_script_info[] = _SC(" \n\
+class DummyAI extends AIInfo { \n\
+ function GetAuthor() { return \"OpenTTD NoAI Developers Team\"; } \n\
+ function GetName() { return \"DummyAI\"; } \n\
+ function GetDescription() { return \"A Dummy AI that is loaded when your ai/ dir is empty\"; }\n\
+ function GetVersion() { return 1; } \n\
+ function GetDate() { return \"2008-07-26\"; } \n\
+ function CreateInstance() { return \"DummyAI\"; } \n\
+} \n\
+ \n\
+RegisterDummyAI(DummyAI()); \n\
+");
+
+const SQChar dummy_script[] = _SC(" \n\
+class DummyAI extends AIController { \n\
+ function Start() { \n\
+ AILog.Error(\"No suitable AI found to load.\"); \n\
+ AILog.Error(\"This AI is a dummy AI and won't do anything.\"); \n\
+ AILog.Error(\"Please add one or several AIs in your ai/ directory.\"); \n\
+ } \n\
+} \n\
+");
+
+void AI_CreateAIInfoDummy(HSQUIRRELVM vm)
+{
+ sq_pushroottable(vm);
+
+ /* Load and run the script */
+ if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script_info, scstrlen(dummy_script_info), _SC("dummy"), SQTrue))) {
+ sq_push(vm, -2);
+ if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
+ sq_pop(vm, 1);
+ return;
+ }
+ }
+ NOT_REACHED();
+}
+
+void AI_CreateAIDummy(HSQUIRRELVM vm)
+{
+ sq_pushroottable(vm);
+
+ /* Load and run the script */
+ if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script, scstrlen(dummy_script), _SC("dummy"), SQTrue))) {
+ sq_push(vm, -2);
+ if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
+ sq_pop(vm, 1);
+ return;
+ }
+ }
+ NOT_REACHED();
+}