diff options
author | krzys-h <krzys_h@interia.pl> | 2013-05-19 21:48:29 +0200 |
---|---|---|
committer | krzys-h <krzys_h@interia.pl> | 2013-05-19 21:48:29 +0200 |
commit | f90a4b48f5ecdc498c32b1b4a35d57f107f36fd5 (patch) | |
tree | a44f5a61c7729db9fd0e37aafce2140e88d7991f /src/script | |
parent | 6798641a71e18e1e3ea798617deb38f557b3c497 (diff) | |
download | colobot-f90a4b48f5ecdc498c32b1b4a35d57f107f36fd5.tar.gz colobot-f90a4b48f5ecdc498c32b1b4a35d57f107f36fd5.tar.bz2 colobot-f90a4b48f5ecdc498c32b1b4a35d57f107f36fd5.zip |
Added object.research(type)
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cbottoken.cpp | 3 | ||||
-rw-r--r-- | src/script/script.cpp | 92 | ||||
-rw-r--r-- | src/script/script.h | 2 |
3 files changed, 95 insertions, 2 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 1747e5c..b5af5c3 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -256,6 +256,7 @@ std::string GetHelpFilename(const char *token) 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, "research" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/research.txt"); if ( strcmp(token, "destroy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/destroy.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"); @@ -382,6 +383,7 @@ bool IsFunction(const char *token) if ( strcmp(token, "progfunc" ) == 0 ) return true; if ( strcmp(token, "busy" ) == 0 ) return true; if ( strcmp(token, "factory" ) == 0 ) return true; + if ( strcmp(token, "research" ) == 0 ) return true; if ( strcmp(token, "destroy" ) == 0 ) return true; if ( strcmp(token, "search" ) == 0 ) return true; if ( strcmp(token, "radar" ) == 0 ) return true; @@ -474,6 +476,7 @@ const char* GetHelpText(const char *token) 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, "research" ) == 0 ) return "object.research ( type );"; if ( strcmp(token, "destroy" ) == 0 ) return "object.destroy ( );"; 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 e2fb302..3c04575 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -86,6 +86,11 @@ CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user) return CBotTypResult(CBotTypFloat); } +CBotTypResult CScript::cClassOneFloat(CBotVar* thisclass, CBotVar* &var) +{ + return CScript::cOneFloat(var, nullptr); +} + // Compiling a procedure with two real numbers. CBotTypResult CScript::cTwoFloat(CBotVar* &var, void* user) @@ -534,6 +539,7 @@ bool CScript::rProgFunc(CBotVar* var, CBotVar* result, int& exception, void* use return true; } + // Compilation of instruction "object.busy()" CBotTypResult CScript::cBusy(CBotVar* thisclass, CBotVar* &var) { @@ -619,7 +625,7 @@ bool CScript::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e } -// Compilation of instruction "object.factory(cat)" +// Compilation of instruction "object.factory(cat, program)" CBotTypResult CScript::cFactory(CBotVar* thisclass, CBotVar* &var) { @@ -635,7 +641,7 @@ CBotTypResult CScript::cFactory(CBotVar* thisclass, CBotVar* &var) return CBotTypResult(CBotTypFloat); } -// Instruction "object.factory(cat)" +// Instruction "object.factory(cat, program)" bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) { @@ -812,6 +818,88 @@ bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e return true; } +// Instruction "object.research(type)" + +bool CScript::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + Error err; + + exception = 0; + + ResearchType type = static_cast<ResearchType>(var->GetValInt()); + + CBotVar* classVars = thisclass->GetItemList(); // "category" + ObjectType thisType = static_cast<ObjectType>(classVars->GetValInt()); + 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* center = CObjectManager::GetInstancePointer()->SearchInstance(rank); + CAuto* automat = center->GetAuto(); + + if ( thisType == OBJECT_RESEARCH || + thisType == OBJECT_LABO ) + { + bool ok = false; + if ( type == RESEARCH_iPAW || + type == RESEARCH_iGUN ) + { + if ( thisType != OBJECT_LABO ) + err = ERR_WRONG_OBJ; + else + ok = true; + } + else + { + if ( thisType != OBJECT_RESEARCH ) + err = ERR_WRONG_OBJ; + else + ok = true; + } + if ( ok ) + { + bool bEnable = ( g_researchEnable & type ); + if ( bEnable ) + { + if ( automat != nullptr ) + { + err = automat->StartAction(type); + } + else + err = ERR_GENERIC; + } + else + err = ERR_BUILD_DISABLED; + } + } + else + err = ERR_WRONG_OBJ; + + if ( err != ERR_OK ) + { + result->SetValInt(err); // return error +//TODO: if ( script->m_errMode == ERM_STOP ) + if( true ) + { + exception = err; + return false; + } + return true; + } + + return true; +} + // Compilation of the instruction "delete(rank[, exploType[, force]])". CBotTypResult CScript::cDelete(CBotVar* &var, void* user) diff --git a/src/script/script.h b/src/script/script.h index 1c02daf..74b81df 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -196,9 +196,11 @@ public: static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var); static CBotTypResult cFactory(CBotVar* thisclass, CBotVar* &var); static CBotTypResult cClassNull(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); + static bool rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); private: |