# ai_info_dummy.cpp

    00001 /* $Id: ai_info_dummy.cpp 15090 2009-01-15 14:37:44Z truebrain $ */
    00002
    00003 #include <squirrel.h>
    00004 #include "../stdafx.h"
    00005
    00006 /* The reason this exists in C++, is that a user can trash his ai/ dir,
    00007  *  leaving no AIs available. The complexity to solve this is insane, and
    00008  *  therefor the alternative is used, and make sure there is always an AI
    00009  *  available, no matter what the situation is. By defining it in C++, there
    00010  *  is simply now way a user can delete it, and therefor safe to use. It has
    00011  *  to be noted that this AI is complete invisible for the user, and impossible
    00012  *  to select manual. It is a fail-over in case no AIs are available.
    00013  */
    00014
    00015 const SQChar dummy_script_info[] = _SC("                                                        \n\
    00016 class DummyAI extends AIInfo {                                                                  \n\
    00017   function GetAuthor()      { return \"OpenTTD NoAI Developers Team\"; }                        \n\
    00018   function GetName()        { return \"DummyAI\"; }                                             \n\
    00019   function GetShortName()   { return \"DUMM\"; }                                                \n\
    00020   function GetDescription() { return \"A Dummy AI that is loaded when your ai/ dir is empty\"; }\n\
    00021   function GetVersion()     { return 1; }                                                       \n\
    00022   function GetDate()        { return \"2008-07-26\"; }                                          \n\
    00023   function CreateInstance() { return \"DummyAI\"; }                                             \n\
    00024 }                                                                                               \n\
    00025                                                                                                 \n\
    00026 RegisterDummyAI(DummyAI());                                                                     \n\
    00027 ");
    00028
    00029 const SQChar dummy_script[] = _SC("                                                             \n\
    00030 class DummyAI extends AIController {                                                            \n\
    00031   function Start() {                                                                            \n\
    00032     AILog.Error(\"No suitable AI found to load.\");                                             \n\
    00033     AILog.Error(\"This AI is a dummy AI and won't do anything.\");                              \n\
    00034     AILog.Error(\"Please add one or several AIs in your ai/ directory.\");                      \n\
    00035   }                                                                                             \n\
    00036 }                                                                                               \n\
    00037 ");
    00038
    00039 void AI_CreateAIInfoDummy(HSQUIRRELVM vm)
    00040 {
    00041   sq_pushroottable(vm);
    00042
    00043   /* Load and run the script */
    00044   if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script_info, scstrlen(dummy_script_info), _SC("dummy"), SQTrue))) {
    00045     sq_push(vm, -2);
    00046     if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
    00047       sq_pop(vm, 1);
    00048       return;
    00049     }
    00050   }
    00051   NOT_REACHED();
    00052 }
    00053
    00054 void AI_CreateAIDummy(HSQUIRRELVM vm)
    00055 {
    00056   sq_pushroottable(vm);
    00057
    00058   /* Load and run the script */
    00059   if (SQ_SUCCEEDED(sq_compilebuffer(vm, dummy_script, scstrlen(dummy_script), _SC("dummy"), SQTrue))) {
    00060     sq_push(vm, -2);
    00061     if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue))) {
    00062       sq_pop(vm, 1);
    00063       return;
    00064     }
    00065   }
    00066   NOT_REACHED();
    00067 }