diff options
author | erihel <erihel@gmail.com> | 2013-04-28 20:09:41 +0200 |
---|---|---|
committer | erihel <erihel@gmail.com> | 2013-04-28 20:09:41 +0200 |
commit | 919b0e8114368132c88d95768b43fc17c70b699d (patch) | |
tree | 50da6747d6e3dad7e2236a01c6c7a40c910e4a30 /src/script | |
parent | 5669053de08bac9726902e96f89aa85b99909399 (diff) | |
parent | c7d289c00bc60d366f8c5c1016fb30717a228495 (diff) | |
download | colobot-919b0e8114368132c88d95768b43fc17c70b699d.tar.gz colobot-919b0e8114368132c88d95768b43fc17c70b699d.tar.bz2 colobot-919b0e8114368132c88d95768b43fc17c70b699d.zip |
Merge branch 'dev' of github:colobot/colobot into dev
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cbottoken.cpp | 10 | ||||
-rw-r--r-- | src/script/script.cpp | 135 | ||||
-rw-r--r-- | src/script/script.h | 5 |
3 files changed, 107 insertions, 43 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 0bd52da..6eb6592 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -262,6 +262,8 @@ 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, "buildinfo" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/buildinfo.txt"); + if ( strcmp(token, "canbuild" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/canbuild.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"); @@ -380,7 +382,9 @@ 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, "buildinfo" ) == 0 ) return true; + if ( strcmp(token, "canbuild" ) == 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; @@ -463,7 +467,9 @@ 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, "buildinfo" ) == 0 ) return "buildinfo ( category );"; + if ( strcmp(token, "canbuild" ) == 0 ) return "canbuild ( category );"; + 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 c95cd4b..c9e3c66 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1003,8 +1003,83 @@ bool CScript::rDirection(CBotVar* var, CBotVar* result, int& exception, void* us return true; } +// compilation of instruction "canbuild ( category );" + +CBotTypResult CScript::cCanBuild(CBotVar* &var, void* user) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypBoolean); +} + +// Instruction "canbuid ( category );" +// returns true if this building can be built + +bool CScript::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + exception = 0; + + CScript::rBuildInfo(var, result, exception, user); + Error err = static_cast<Error>(result->GetValInt()); + + if (err == ERR_OK) + result->SetValInt(true); + else + result->SetValInt(false); + + return true; +} + +// Instruction "buildinfo ( category );" +// This function indicates if this building can be built, and returns a specific value +// +// returns 0(ERR_OK) if this building can be built +// returns 132(ERR_BUILD_DISABLED) if can not build in a current mission +// returns 133(ERR_BUILD_RESEARCH) if this building needs to be researched + +bool CScript::rBuildInfo(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + ObjectType category = static_cast<ObjectType>(var->GetValInt()); //get category parameter + exception = 0; + int value = ERR_BUILD_DISABLED; + + 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)) + ) + { + value = ERR_BUILD_RESEARCH; + } + else + { + value = ERR_OK; + } + + } + + result->SetValInt(value); + return true; +} + // Instruction "build(type)" -// draws error if can not build (wher errormode stop), otherwise 0 <- 1 +// draws error if can not build (wher errormode stop), otherwise 0 <- error bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) { @@ -1027,48 +1102,26 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) } 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); + //Let's check is building this object is possible + CScript::rBuildInfo(var, result, exception, user); + err = static_cast<Error>(result->GetValInt()); - if (err != ERR_OK) - { - delete script->m_primaryTask; - script->m_primaryTask = 0; - } - } - - } - else //if we can't build this object + if (err == ERR_OK && script->m_primaryTask == 0) //if we can build and no task is present { - err = ERR_BUILD_DISABLED; + category = static_cast<ObjectType>(var->GetValInt()); //get category parameter + + 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; + } } + //When script is waiting for finishing this task, it sets ERR_OK, and continues executing Process + //without creating new task. I think, there was a problem with previous version in release configuration + //It did not init error variable in this situation, and code tried to use variable with trash inside } if ( err != ERR_OK ) @@ -2939,6 +2992,8 @@ void CScript::InitFonctions() CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat); CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat); + CBotProgram::AddFunction("buildinfo", rBuildInfo, CScript::cOneFloat); + 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 597486b..702138b 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -104,7 +104,8 @@ 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 cCanBuild(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 +140,8 @@ 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 rBuildInfo(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rCanBuild(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); |