From 8004e689481d01decbde351d1925e0efe23daf94 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 18 May 2013 16:58:35 +0200 Subject: Added object.busy() --- src/object/robotmain.cpp | 1 + src/script/cbottoken.cpp | 3 +++ src/script/script.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/script/script.h | 3 +++ 4 files changed, 46 insertions(+) diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index dbd69f3..52387f8 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -873,6 +873,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) bc->AddItem("energyCell", CBotTypResult(CBotTypPointer, "object"), PR_READ); bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), PR_READ); bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ); + bc->AddFunction("busy", CScript::rBusy, CScript::cBusy); bc->AddFunction("factory", CScript::rFactory, CScript::cClassOneFloat); // Initializes the class FILE. diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index c101f17..c56482f 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -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, "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, "search" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/search.txt"); if ( strcmp(token, "radar" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/radar.txt"); @@ -376,6 +377,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, "busy" ) == 0 ) return true; if ( strcmp(token, "factory" ) == 0 ) return true; if ( strcmp(token, "search" ) == 0 ) return true; if ( strcmp(token, "radar" ) == 0 ) return true; @@ -465,6 +467,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, "busy" ) == 0 ) return "object.busy ( cat );"; if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat );"; if ( strcmp(token, "search" ) == 0 ) return "search ( );"; if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );"; diff --git a/src/script/script.cpp b/src/script/script.cpp index 25a7e73..31ede8d 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -499,6 +499,45 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us return true; } +// Compilation of instruction "object.busy()" +CBotTypResult CScript::cBusy(CBotVar* thisclass, CBotVar* &var) +{ + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypBoolean); +} + +// Instruction "object.busy()" + +bool CScript::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + exception = 0; + + CBotVar* classVars = thisclass->GetItemList(); // "category" + classVars = classVars->GetNext(); // "position" + classVars = classVars->GetNext(); // "orientation" + classVars = classVars->GetNext(); // "pitch" + classVars = classVars->GetNext(); // "roll" + classVars = classVars->GetNext(); // "energyLevel" + classVars = classVars->GetNext(); // "shieldLevel" + classVars = classVars->GetNext(); // "temperature" + classVars = classVars->GetNext(); // "altitude" + classVars = classVars->GetNext(); // "lifeTime" + classVars = classVars->GetNext(); // "material" + classVars = classVars->GetNext(); // "energyCell" + classVars = classVars->GetNext(); // "load" + classVars = classVars->GetNext(); // "id" + int rank = classVars->GetValInt(); + CObject* obj = CObjectManager::GetInstancePointer()->SearchInstance(rank); + CAuto* automat = obj->GetAuto(); + + if ( automat != nullptr ) + result->SetValInt(automat->GetBusy()); + else + exception = ERR_MANIP_VEH; + + return true; +} + // Instruction "object.factory(cat)" bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) diff --git a/src/script/script.h b/src/script/script.h index 481df8e..62e95b3 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -191,7 +191,10 @@ private: static bool rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user); public: + static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var); static CBotTypResult cClassOneFloat(CBotVar* thisclass, CBotVar* &var); + + static bool rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); private: -- cgit v1.2.3-1-g7c22