summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorXienDev <XienDev@gmail.com>2013-04-27 18:11:26 +0300
committerXienDev <XienDev@gmail.com>2013-04-27 18:11:26 +0300
commit41fb814e99adb1bbb6b62aeb821574713c8c799b (patch)
tree05527ae7d5bf60b799cf23d3f34b42d427698a3b /src/script
parent22c3f44c61c9fbb826c5c0e18baba4e6952364af (diff)
downloadcolobot-41fb814e99adb1bbb6b62aeb821574713c8c799b.tar.gz
colobot-41fb814e99adb1bbb6b62aeb821574713c8c799b.tar.bz2
colobot-41fb814e99adb1bbb6b62aeb821574713c8c799b.zip
Added build
Third patch
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cbottoken.cpp3
-rw-r--r--src/script/script.cpp85
-rw-r--r--src/script/script.h3
3 files changed, 90 insertions, 1 deletions
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);