diff options
-rw-r--r-- | src/script/cbottoken.cpp | 3 | ||||
-rw-r--r-- | src/script/script.cpp | 45 | ||||
-rw-r--r-- | src/script/script.h | 2 |
3 files changed, 49 insertions, 1 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 9f99752..81219df 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -334,6 +334,7 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "penup" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penup.txt"); if ( strcmp(token, "pencolor" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pencolor.txt"); if ( strcmp(token, "penwidth" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penwidth.txt"); + if ( strcmp(token, "camerafocus" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/camerafocus.txt"); if ( strcmp(token, "extern" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/extern.txt"); if ( strcmp(token, "class" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/class.txt"); if ( strcmp(token, "static" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/static.txt"); @@ -441,6 +442,7 @@ bool IsFunction(const char *token) if ( strcmp(token, "penup" ) == 0 ) return true; if ( strcmp(token, "pencolor" ) == 0 ) return true; if ( strcmp(token, "penwidth" ) == 0 ) return true; + if ( strcmp(token, "camerafocus" ) == 0 ) return true; if ( strcmp(token, "sizeof" ) == 0 ) return true; return false; } @@ -535,6 +537,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "penup" ) == 0 ) return "penup ( );"; if ( strcmp(token, "pencolor" ) == 0 ) return "pencolor ( color );"; if ( strcmp(token, "penwidth" ) == 0 ) return "penwidth ( width );"; + if ( strcmp(token, "camerafocus") == 0 ) return "camerafocus ( object );"; return ""; } diff --git a/src/script/script.cpp b/src/script/script.cpp index 0b3eec4..6fcd883 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1639,7 +1639,7 @@ CBotTypResult CScript::cCanBuild(CBotVar* &var, void* user) return CBotTypResult(CBotTypBoolean); } -// Instruction "canbuid ( category );" +// Instruction "canbuild ( category );" // returns true if this building can be built bool CScript::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user) @@ -3407,6 +3407,47 @@ bool CScript::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* use return true; } +// Compilation of the instruction with one object parameter + +CBotTypResult CScript::cOneObject(CBotVar* &var, void* user) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + var = var->GetNext(); + if ( var == 0 ) return CBotTypResult(CBotTypFloat); + + return CBotTypResult(CBotErrOverParam); +} + +// Instruction "camerafocus(object)". + +bool CScript::rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CScript* script = (static_cast<CObject *>(user))->GetRunScript(); + + CBotVar* classVars = var->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* object = CObjectManager::GetInstancePointer()->SearchInstance(rank); + + script->m_main->SelectObject(object, false); + + result->SetValInt(ERR_OK); + exception = ERR_OK; + return true; +} + // Object's constructor. @@ -3507,6 +3548,8 @@ void CScript::InitFonctions() CBotProgram::AddFunction("penup", rPenUp, CScript::cNull); CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat); CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat); + + CBotProgram::AddFunction("camerafocus", rCameraFocus, CScript::cOneObject); CBotProgram::AddFunction("canbuild", rCanBuild, CScript::cCanBuild); CBotProgram::AddFunction("build", rBuild, CScript::cOneFloat); diff --git a/src/script/script.h b/src/script/script.h index 177d40a..afb89c8 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -128,6 +128,7 @@ private: static CBotTypResult cPenDown(CBotVar* &var, void* user); static CBotTypResult cOnePoint(CBotVar* &var, void* user); static CBotTypResult cPoint(CBotVar* &var, void* user); + static CBotTypResult cOneObject(CBotVar* &var, void* user); static bool rSin(CBotVar* var, CBotVar* result, int& exception, void* user); @@ -192,6 +193,7 @@ private: static bool rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user); public: static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var); |