summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-05-05 14:44:51 +0200
committerkrzys-h <krzys_h@interia.pl>2013-05-05 14:44:51 +0200
commitfcb052cc8d1abb2e1872c9684bba225686f25b34 (patch)
treeed7870f1df1522b7c42828438db7295111396277
parent78e32cf894797fbbe865e67299800292597c92ae (diff)
downloadcolobot-fcb052cc8d1abb2e1872c9684bba225686f25b34.tar.gz
colobot-fcb052cc8d1abb2e1872c9684bba225686f25b34.tar.bz2
colobot-fcb052cc8d1abb2e1872c9684bba225686f25b34.zip
Added [set/get][build/research[done/enable]] ( ); function fo CBot
* setbuild ( ); * setresearchdone ( ); * setresearchenable ( ); * getbuild ( ); * getresearchdone ( ); * getresearchenable ( );
-rw-r--r--src/script/cbottoken.cpp16
-rw-r--r--src/script/script.cpp129
-rw-r--r--src/script/script.h7
3 files changed, 112 insertions, 40 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp
index 6eb6592..2ae2c72 100644
--- a/src/script/cbottoken.cpp
+++ b/src/script/cbottoken.cpp
@@ -249,6 +249,9 @@ std::string GetHelpFilename(const char *token)
if ( strcmp(token, "pow" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
if ( strcmp(token, "rand" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
if ( strcmp(token, "abs" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt");
+ if ( strcmp(token, "getbuild" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getbuild.txt");
+ 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, "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");
@@ -262,7 +265,6 @@ 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");
@@ -368,6 +370,9 @@ bool IsFunction(const char *token)
if ( strcmp(token, "pow" ) == 0 ) return true;
if ( strcmp(token, "rand" ) == 0 ) return true;
if ( strcmp(token, "abs" ) == 0 ) return true;
+ if ( strcmp(token, "getbuild" ) == 0 ) return true;
+ if ( strcmp(token, "getresearchenable" ) == 0 ) return true;
+ if ( strcmp(token, "getresearchdone" ) == 0 ) return true;
if ( strcmp(token, "retobject" ) == 0 ) return true;
if ( strcmp(token, "search" ) == 0 ) return true;
if ( strcmp(token, "radar" ) == 0 ) return true;
@@ -382,9 +387,8 @@ 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, "buildinfo" ) == 0 ) return true;
- if ( strcmp(token, "canbuild" ) == 0 ) return true;
- if ( strcmp(token, "build" ) == 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;
@@ -453,6 +457,9 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "pow" ) == 0 ) return "pow ( x, y );";
if ( strcmp(token, "rand" ) == 0 ) return "rand ( );";
if ( strcmp(token, "abs" ) == 0 ) return "abs ( value );";
+ if ( strcmp(token, "getbuild" ) == 0 ) return "getbuild ( );";
+ if ( strcmp(token, "getresearchenable" ) == 0 ) return "getresearchenable ( );";
+ if ( strcmp(token, "getresearchdone" ) == 0 ) return "getresearchdone ( );";
if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( );";
if ( strcmp(token, "search" ) == 0 ) return "search ( );";
if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );";
@@ -467,7 +474,6 @@ 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, "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 );";
diff --git a/src/script/script.cpp b/src/script/script.cpp
index d108c7a..9537630 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -386,6 +386,56 @@ bool CScript::rStopMusic(CBotVar* var, CBotVar* result, int& exception, void* us
return true;
}
+// Instruction "getbuild()"
+
+bool CScript::rGetBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ result->SetValInt(g_build);
+ return true;
+}
+
+// Instruction "getresearchenable()"
+
+bool CScript::rGetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ result->SetValInt(g_researchEnable);
+ return true;
+}
+
+// Instruction "getresearchdone()"
+
+bool CScript::rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ result->SetValInt(g_researchDone);
+ return true;
+}
+
+// Instruction "setbuild()"
+
+bool CScript::rSetBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ g_build = var->GetValInt();
+ CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
+ return true;
+}
+
+// Instruction "setresearchenable()"
+
+bool CScript::rSetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ g_researchEnable = var->GetValInt();
+ CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
+ return true;
+}
+
+// Instruction "setresearchdone()"
+
+bool CScript::rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ g_researchDone = var->GetValInt();
+ CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
+ return true;
+}
// Compilation of the instruction "retobject(rank)".
@@ -1094,31 +1144,10 @@ CBotTypResult CScript::cCanBuild(CBotVar* &var, void* user)
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;
+
+ bool can = false;
if ( (category == OBJECT_DERRICK && (g_build & BUILD_DERRICK)) ||
(category == OBJECT_FACTORY && (g_build & BUILD_FACTORY)) ||
@@ -1136,20 +1165,22 @@ bool CScript::rBuildInfo(CBotVar* var, CBotVar* result, int& exception, void* us
{
//if we want to build not researched one
- if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) ||
+ if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) ||
(category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC))
)
{
- value = ERR_BUILD_RESEARCH;
+ can = false;
}
else
{
- value = ERR_OK;
+ can = true;
}
}
- result->SetValInt(value);
+ result->SetValInt(can);
+
+
return true;
}
@@ -1162,7 +1193,7 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
CObject* pThis = static_cast<CObject *>(user);
ObjectType oType;
ObjectType category;
- Error err;
+ Error err = ERR_BUILD_DISABLED;
exception = 0;
@@ -1177,14 +1208,38 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
}
else
{
- //Let's check is building this object is possible
- CScript::rBuildInfo(var, result, exception, user);
- err = static_cast<Error>(result->GetValInt());
+ category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
+ 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
+ {
+ err = ERR_OK;
+ }
+
+ }
if (err == ERR_OK && script->m_primaryTask == 0) //if we can build and no task is present
{
- category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
-
script->m_primaryTask = new CTaskManager(script->m_object);
err = script->m_primaryTask->StartTaskBuild(category);
@@ -3029,6 +3084,13 @@ void CScript::InitFonctions()
CBotProgram::AddFunction("playmusic", rPlayMusic ,CScript::cPlayMusic);
CBotProgram::AddFunction("stopmusic", rStopMusic ,CScript::cNull);
+ CBotProgram::AddFunction("getbuild", rGetBuild, CScript::cNull);
+ CBotProgram::AddFunction("getresearchenable", rGetResearchEnable, CScript::cNull);
+ CBotProgram::AddFunction("getresearchdone", rGetResearchDone, CScript::cNull);
+ CBotProgram::AddFunction("setbuild", rSetBuild, CScript::cOneFloat);
+ CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, CScript::cOneFloat);
+ CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScript::cOneFloat);
+
CBotProgram::AddFunction("retobject", rGetObject, CScript::cGetObject);
CBotProgram::AddFunction("destroy", rDestroy, CScript::cDestroy);
CBotProgram::AddFunction("search", rSearch, CScript::cSearch);
@@ -3071,7 +3133,6 @@ 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 535b974..f0907f3 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -139,13 +139,18 @@ private:
static bool rEndMission(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rStopMusic(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rGetBuild(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rGetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rSetBuild(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rSetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rGetObject(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rDestroy(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rSearch(CBotVar* var, CBotVar* result, int& exception, void* user);
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);