diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/global.h | 2 | ||||
-rw-r--r-- | src/common/restext.cpp | 2 | ||||
-rw-r--r-- | src/script/cbottoken.cpp | 3 | ||||
-rw-r--r-- | src/script/script.cpp | 85 | ||||
-rw-r--r-- | src/script/script.h | 3 |
5 files changed, 94 insertions, 1 deletions
diff --git a/src/common/global.h b/src/common/global.h index 7a5fdfd..db601df 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -55,6 +55,8 @@ enum Error ERR_BUILD_BASE = 129, //! < too close to the rocket ERR_BUILD_NARROW = 130, //! < buildings too close ERR_BUILD_MOTOR = 131, //! < built: not possible in movement + ERR_BUILD_DISABLED = 132, //! < built: can not produce this object in this mission + ERR_BUILD_RESEARCH = 133, //! < built: can not produce not researched object ERR_SEARCH_FLY = 140, //! < not possible in flight ERR_SEARCH_VEH = 141, //! < inappropriate vehicle ERR_SEARCH_MOTOR = 142, //! < impossible in movement diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 729a883..9af73e4 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -563,6 +563,8 @@ void InitializeRestext() stringsErr[ERR_BUILD_NARROW] = "Too close to a building"; stringsErr[ERR_BUILD_MOTOR] = "Impossible when moving"; stringsErr[ERR_SEARCH_FLY] = "Impossible when flying"; + stringsErr[ERR_BUILD_DISABLED] = "Can not produce this object in this mission"; + stringsErr[ERR_BUILD_RESEARCH] = "Can not produce not researched object"; stringsErr[ERR_SEARCH_VEH] = "Inappropriate bot"; stringsErr[ERR_SEARCH_MOTOR] = "Impossible when moving"; stringsErr[ERR_TERRA_VEH] = "Inappropriate bot"; diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 19b0f78..0bd52da 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -262,6 +262,7 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "turn" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/turn.txt"); if ( strcmp(token, "goto" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/goto.txt"); if ( strcmp(token, "grab" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt"); + if ( strcmp(token, "build" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/build.txt"); if ( strcmp(token, "drop" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/drop.txt"); if ( strcmp(token, "sniff" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/sniff.txt"); if ( strcmp(token, "receive" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/receive.txt"); @@ -379,6 +380,7 @@ bool IsFunction(const char *token) if ( strcmp(token, "turn" ) == 0 ) return true; if ( strcmp(token, "goto" ) == 0 ) return true; if ( strcmp(token, "grab" ) == 0 ) return true; + if ( strcmp(token, "build" ) == 0 ) return true; if ( strcmp(token, "drop" ) == 0 ) return true; if ( strcmp(token, "sniff" ) == 0 ) return true; if ( strcmp(token, "receive" ) == 0 ) return true; @@ -461,6 +463,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "turn" ) == 0 ) return "turn ( angle );"; if ( strcmp(token, "goto" ) == 0 ) return "goto ( position, altitude );"; if ( strcmp(token, "grab" ) == 0 ) return "grab ( order );"; + if ( strcmp(token, "build" ) == 0 ) return "build ( category );"; if ( strcmp(token, "drop" ) == 0 ) return "drop ( order );"; if ( strcmp(token, "sniff" ) == 0 ) return "sniff ( );"; if ( strcmp(token, "receive" ) == 0 ) return "receive ( name, power );"; diff --git a/src/script/script.cpp b/src/script/script.cpp index 9174971..c95cd4b 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1003,6 +1003,88 @@ bool CScript::rDirection(CBotVar* var, CBotVar* result, int& exception, void* us return true; } +// Instruction "build(type)" +// draws error if can not build (wher errormode stop), otherwise 0 <- 1 + +bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CScript* script = (static_cast<CObject *>(user))->GetRunScript(); + CObject* pThis = static_cast<CObject *>(user); + ObjectType oType; + ObjectType category; + Error err; + + exception = 0; + + oType = pThis->GetType(); + + if ( oType != OBJECT_MOBILEfa && // allowed only for grabber bots + oType != OBJECT_MOBILEta && + oType != OBJECT_MOBILEwa && + oType != OBJECT_MOBILEia) + { + err = ERR_MANIP_VEH; //Wrong vehicle; + } + else + { + category = static_cast<ObjectType>(var->GetValInt()); //get category parameter + + //if we want to produce one of these buildings + if ( (category == OBJECT_DERRICK && (g_build & BUILD_DERRICK)) || + (category == OBJECT_FACTORY && (g_build & BUILD_FACTORY)) || + (category == OBJECT_STATION && (g_build & BUILD_STATION)) || + (category == OBJECT_CONVERT && (g_build & BUILD_CONVERT)) || + (category == OBJECT_REPAIR && (g_build & BUILD_REPAIR)) || + (category == OBJECT_TOWER && (g_build & BUILD_TOWER)) || + (category == OBJECT_RESEARCH && (g_build & BUILD_RESEARCH)) || + (category == OBJECT_RADAR && (g_build & BUILD_RADAR)) || + (category == OBJECT_ENERGY && (g_build & BUILD_ENERGY)) || + (category == OBJECT_LABO && (g_build & BUILD_LABO)) || + (category == OBJECT_NUCLEAR && (g_build & BUILD_NUCLEAR)) || + (category == OBJECT_INFO && (g_build & BUILD_INFO )) || + (category == OBJECT_PARA && (g_build & BUILD_PARA ))) + { + + //if we want to build not researched one + if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) || + (category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC)) + ) + { + err = ERR_BUILD_RESEARCH; + } + else if (script->m_primaryTask == 0) //if we have no other tasks + { + script->m_primaryTask = new CTaskManager(script->m_object); + err = script->m_primaryTask->StartTaskBuild(category); + + if (err != ERR_OK) + { + delete script->m_primaryTask; + script->m_primaryTask = 0; + } + } + + } + else //if we can't build this object + { + err = ERR_BUILD_DISABLED; + } + } + + if ( err != ERR_OK ) + { + result->SetValInt(err); // return error + if ( script->m_errMode == ERM_STOP ) + { + exception = err; + return false; + } + return true; + } + + return Process(script, result, exception); + +} // Compilation of the instruction "produce(pos, angle, type[, scriptName[, power]])" // or "produce(type[, power])". @@ -2856,6 +2938,9 @@ void CScript::InitFonctions() CBotProgram::AddFunction("penup", rPenUp, CScript::cNull); CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat); CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat); + + CBotProgram::AddFunction("build", rBuild, CScript::cOneFloat); + } // Object's destructor. diff --git a/src/script/script.h b/src/script/script.h index 0d2726a..597486b 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -104,7 +104,7 @@ private: static CBotTypResult cSearch(CBotVar* &var, void* user); static CBotTypResult cRadar(CBotVar* &var, void* user); static CBotTypResult cDetect(CBotVar* &var, void* user); - static CBotTypResult cDirection(CBotVar* &var, void* user); + static CBotTypResult cDirection(CBotVar* &var, void* user); static CBotTypResult cProduce(CBotVar* &var, void* user); static CBotTypResult cDistance(CBotVar* &var, void* user); static CBotTypResult cSpace(CBotVar* &var, void* user); @@ -139,6 +139,7 @@ private: static bool rRadar(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDetect(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDirection(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rBuild(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rProduce(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDistance(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rDistance2d(CBotVar* var, CBotVar* result, int& exception, void* user); |