Added progfunc( funcname );
For simple creating of programs executing public functions :) Example: public void object::SecondBot() { message("It works!"); } extern void object::FirstBot() { object item = radar(BotFactory); item.factory(WheeledGrabber, progfunc("SecondBot")); }dev-ui
parent
b9d0ee034e
commit
6b25608e69
|
@ -253,6 +253,7 @@ std::string GetHelpFilename(const char *token)
|
|||
if ( strcmp(token, "getresearchenable" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresen.txt");
|
||||
if ( strcmp(token, "getresearchdone" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresdo.txt");
|
||||
if ( strcmp(token, "retobject" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/retobj.txt");
|
||||
if ( strcmp(token, "progfunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt");
|
||||
if ( strcmp(token, "busy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/busy.txt");
|
||||
if ( strcmp(token, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt");
|
||||
if ( strcmp(token, "destroy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/destroy.txt");
|
||||
|
@ -378,6 +379,7 @@ bool IsFunction(const char *token)
|
|||
if ( strcmp(token, "getresearchdone" ) == 0 ) return true;
|
||||
if ( strcmp(token, "retobjectbyid") == 0 ) return true;
|
||||
if ( strcmp(token, "retobject" ) == 0 ) return true;
|
||||
if ( strcmp(token, "progfunc" ) == 0 ) return true;
|
||||
if ( strcmp(token, "busy" ) == 0 ) return true;
|
||||
if ( strcmp(token, "factory" ) == 0 ) return true;
|
||||
if ( strcmp(token, "destroy" ) == 0 ) return true;
|
||||
|
@ -469,6 +471,7 @@ const char* GetHelpText(const char *token)
|
|||
if ( strcmp(token, "getresearchdone" ) == 0 ) return "getresearchdone ( );";
|
||||
if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( rank );";
|
||||
if ( strcmp(token, "retobjectbyid") == 0 ) return "retobjectbyid ( rank );";
|
||||
if ( strcmp(token, "progfunc" ) == 0 ) return "progfunc ( funcname );";
|
||||
if ( strcmp(token, "busy" ) == 0 ) return "object.busy ( );";
|
||||
if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat, program );";
|
||||
if ( strcmp(token, "destroy" ) == 0 ) return "object.destroy ( );";
|
||||
|
|
|
@ -155,6 +155,18 @@ CBotTypResult CScript::cString(CBotVar* &var, void* user)
|
|||
return CBotTypResult(CBotTypFloat);
|
||||
}
|
||||
|
||||
// Compiling a procedure with a single string, returning string.
|
||||
|
||||
CBotTypResult CScript::cStringString(CBotVar* &var, void* user)
|
||||
{
|
||||
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
||||
if ( var->GetType() != CBotTypString &&
|
||||
var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
||||
var = var->GetNext();
|
||||
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
||||
return CBotTypResult(CBotTypString);
|
||||
}
|
||||
|
||||
|
||||
// Seeking value in an array of integers.
|
||||
|
||||
|
@ -499,6 +511,29 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Instruction "progfunc(funcname)".
|
||||
|
||||
bool CScript::rProgFunc(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
CBotString cbs;
|
||||
const char* funcname;
|
||||
std::string program;
|
||||
|
||||
cbs = var->GetValString();
|
||||
funcname = cbs;
|
||||
|
||||
//TODO: Translation :)
|
||||
program = "extern void object::Auto()\n{\n\t\n\t//Automatically generated by progfunc(\"";
|
||||
program += funcname;
|
||||
program += "\");\n\t";
|
||||
program += funcname;
|
||||
program += "();\n\t\n}\n";
|
||||
|
||||
result->SetValString(program.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
// Compilation of instruction "object.busy()"
|
||||
CBotTypResult CScript::cBusy(CBotVar* thisclass, CBotVar* &var)
|
||||
{
|
||||
|
@ -3402,6 +3437,7 @@ void CScript::InitFonctions()
|
|||
CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, CScript::cOneFloat);
|
||||
CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScript::cOneFloat);
|
||||
|
||||
CBotProgram::AddFunction("progfunc", rProgFunc, CScript::cStringString);
|
||||
CBotProgram::AddFunction("retobject", rGetObject, CScript::cGetObject);
|
||||
CBotProgram::AddFunction("retobjectbyid", rGetObjectById, CScript::cGetObject);
|
||||
CBotProgram::AddFunction("delete", rDelete, CScript::cDelete);
|
||||
|
|
|
@ -98,6 +98,7 @@ private:
|
|||
static CBotTypResult cOneFloat(CBotVar* &var, void* user);
|
||||
static CBotTypResult cTwoFloat(CBotVar* &var, void* user);
|
||||
static CBotTypResult cString(CBotVar* &var, void* user);
|
||||
static CBotTypResult cStringString(CBotVar* &var, void* user);
|
||||
static CBotTypResult cEndMission(CBotVar* &var, void* user);
|
||||
static CBotTypResult cPlayMusic(CBotVar* &var, void* user);
|
||||
static CBotTypResult cGetObject(CBotVar* &var, void* user);
|
||||
|
@ -146,6 +147,7 @@ private:
|
|||
static bool rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rGetObjectById(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rGetObject(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rProgFunc(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rDelete(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rSearch(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rRadar(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
|
|
Loading…
Reference in New Issue