diff options
author | krzys-h <krzys_h@interia.pl> | 2013-05-18 16:44:22 +0200 |
---|---|---|
committer | krzys-h <krzys_h@interia.pl> | 2013-05-18 18:04:48 +0200 |
commit | 47d7b805070e317894efbed653b1d44cd789f2fa (patch) | |
tree | feb09d4dd408f53371b2fbd6fd2f8d37a70554a3 /src/script | |
parent | 07839a561fa876539484fdc44e68d3f17e20a89b (diff) | |
download | colobot-47d7b805070e317894efbed653b1d44cd789f2fa.tar.gz colobot-47d7b805070e317894efbed653b1d44cd789f2fa.tar.bz2 colobot-47d7b805070e317894efbed653b1d44cd789f2fa.zip |
Added object.factory(cat)
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cbottoken.cpp | 3 | ||||
-rw-r--r-- | src/script/script.cpp | 165 | ||||
-rw-r--r-- | src/script/script.h | 6 |
3 files changed, 173 insertions, 1 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index f24aba1..c101f17 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, "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"); if ( strcmp(token, "direction" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/direct.txt"); @@ -375,6 +376,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, "factory" ) == 0 ) return true; if ( strcmp(token, "search" ) == 0 ) return true; if ( strcmp(token, "radar" ) == 0 ) return true; if ( strcmp(token, "detect" ) == 0 ) return true; @@ -463,6 +465,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, "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 );"; if ( strcmp(token, "detect" ) == 0 ) return "detect ( cat );"; diff --git a/src/script/script.cpp b/src/script/script.cpp index 0d2238d..25a7e73 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -35,6 +35,9 @@ #include "object/task/taskmanager.h" #include "object/objman.h" +#include "object/auto/auto.h" +#include "object/auto/autofactory.h" + #include "physics/physics.h" #include "script/cbottoken.h" @@ -78,6 +81,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) @@ -491,6 +499,163 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us return true; } +// Instruction "object.factory(cat)" + +bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + Error err; + + exception = 0; + + 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* factory = CObjectManager::GetInstancePointer()->SearchInstance(rank); + CAuto* automat = factory->GetAuto(); + + if ( thisType == OBJECT_FACTORY ) + { + ObjectType type = static_cast<ObjectType>(var->GetValInt()); + bool bEnable = false; + + if ( type == OBJECT_MOBILEwa ) + { + bEnable = true; + } + if ( type == OBJECT_MOBILEta ) + { + bEnable = g_researchDone&RESEARCH_TANK; + } + if ( type == OBJECT_MOBILEfa ) + { + bEnable = g_researchDone&RESEARCH_FLY; + } + if ( type == OBJECT_MOBILEia ) + { + bEnable = g_researchDone&RESEARCH_iPAW; + } + + if ( type == OBJECT_MOBILEws ) + { + bEnable = g_researchDone&RESEARCH_SNIFFER; + } + if ( type == OBJECT_MOBILEts ) + { + bEnable = ( (g_researchDone&RESEARCH_SNIFFER) && + (g_researchDone&RESEARCH_TANK) ); + } + if ( type == OBJECT_MOBILEfs ) + { + bEnable = ( (g_researchDone&RESEARCH_SNIFFER) && + (g_researchDone&RESEARCH_FLY) ); + } + if ( type == OBJECT_MOBILEis ) + { + bEnable = ( (g_researchDone&RESEARCH_SNIFFER) && + (g_researchDone&RESEARCH_iPAW) ); + } + + if ( type == OBJECT_MOBILEwc ) + { + bEnable = g_researchDone&RESEARCH_CANON; + } + if ( type == OBJECT_MOBILEtc ) + { + bEnable = ( (g_researchDone&RESEARCH_CANON) && + (g_researchDone&RESEARCH_TANK) ); + } + if ( type == OBJECT_MOBILEfc ) + { + bEnable = ( (g_researchDone&RESEARCH_CANON) && + (g_researchDone&RESEARCH_FLY) ); + } + if ( type == OBJECT_MOBILEic ) + { + bEnable = ( (g_researchDone&RESEARCH_CANON) && + (g_researchDone&RESEARCH_iPAW) ); + } + + if ( type == OBJECT_MOBILEwi ) + { + bEnable = g_researchDone&RESEARCH_iGUN; + } + if ( type == OBJECT_MOBILEti ) + { + bEnable = ( (g_researchDone&RESEARCH_iGUN) && + (g_researchDone&RESEARCH_TANK) ); + } + if ( type == OBJECT_MOBILEfi ) + { + bEnable = ( (g_researchDone&RESEARCH_iGUN) && + (g_researchDone&RESEARCH_FLY) ); + } + if ( type == OBJECT_MOBILEii ) + { + bEnable = ( (g_researchDone&RESEARCH_iGUN) && + (g_researchDone&RESEARCH_iPAW) ); + } + + if ( type == OBJECT_MOBILErt ) + { + bEnable = ( (g_researchDone&RESEARCH_THUMP) && + (g_researchDone&RESEARCH_TANK) ); + } + if ( type == OBJECT_MOBILErc ) + { + bEnable = ( (g_researchDone&RESEARCH_PHAZER) && + (g_researchDone&RESEARCH_TANK) ); + } + if ( type == OBJECT_MOBILErr ) + { + bEnable = ( (g_researchDone&RESEARCH_RECYCLER) && + (g_researchDone&RESEARCH_TANK) ); + } + if ( type == OBJECT_MOBILErs ) + { + bEnable = ( (g_researchDone&RESEARCH_SHIELD) && + (g_researchDone&RESEARCH_TANK) ); + } + + if ( type == OBJECT_MOBILEsa ) + { + bEnable = g_researchDone&RESEARCH_SUBM; + } + + if ( bEnable ) + err = automat->StartAction(type); + else + err = ERR_BUILD_DISABLED; + } else + err = ERR_MANIP_VEH; + + 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 "destroy(rank[, exploType[, force]])". CBotTypResult CScript::cDestroy(CBotVar* &var, void* user) diff --git a/src/script/script.h b/src/script/script.h index cd2a122..481df8e 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -94,7 +94,6 @@ protected: bool Compile(); private: - static CBotTypResult cNull(CBotVar* &var, void* user); static CBotTypResult cOneFloat(CBotVar* &var, void* user); static CBotTypResult cTwoFloat(CBotVar* &var, void* user); @@ -191,6 +190,11 @@ private: static bool rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user); +public: + static CBotTypResult cClassOneFloat(CBotVar* thisclass, CBotVar* &var); + static bool rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); + +private: static bool Process(CScript* script, CBotVar* result, int &exception); static CObject* SearchInfo(CScript* script, CObject* object, float power); |