summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-05-12 15:54:35 +0200
committerkrzys-h <krzys_h@interia.pl>2013-05-12 15:54:35 +0200
commit61841b3f40c3381bd591ca14af290e46d3d9a76c (patch)
treee48cc3beb09edf27997eb39a3c160f2955798584 /src
parent1f77efb9cb3f39fae5567c3af65fd3e9ad8736aa (diff)
downloadcolobot-61841b3f40c3381bd591ca14af290e46d3d9a76c.tar.gz
colobot-61841b3f40c3381bd591ca14af290e46d3d9a76c.tar.bz2
colobot-61841b3f40c3381bd591ca14af290e46d3d9a76c.zip
Backwards combatibility for retobject() (#209)
Diffstat (limited to 'src')
-rw-r--r--src/script/cbottoken.cpp4
-rw-r--r--src/script/script.cpp24
-rw-r--r--src/script/script.h1
3 files changed, 27 insertions, 2 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp
index 2ae2c72..f24aba1 100644
--- a/src/script/cbottoken.cpp
+++ b/src/script/cbottoken.cpp
@@ -373,6 +373,7 @@ bool IsFunction(const char *token)
if ( strcmp(token, "getbuild" ) == 0 ) return true;
if ( strcmp(token, "getresearchenable" ) == 0 ) return true;
if ( strcmp(token, "getresearchdone" ) == 0 ) return true;
+ if ( strcmp(token, "retobjectbyid") == 0 ) return true;
if ( strcmp(token, "retobject" ) == 0 ) return true;
if ( strcmp(token, "search" ) == 0 ) return true;
if ( strcmp(token, "radar" ) == 0 ) return true;
@@ -460,7 +461,8 @@ const char* GetHelpText(const char *token)
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, "retobject" ) == 0 ) return "retobject ( rank );";
+ if ( strcmp(token, "retobjectbyid") == 0 ) return "retobjectbyid ( rank );";
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 ba9b8e6..0d2238d 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -449,6 +449,27 @@ CBotTypResult CScript::cGetObject(CBotVar* &var, void* user)
return CBotTypResult(CBotTypPointer, "object");
}
+// Instruction "retobjectbyid(rank)".
+
+bool CScript::rGetObjectById(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ CObject* pObj;
+ int rank;
+
+ rank = var->GetValInt();
+
+ pObj = static_cast<CObject*>(CObjectManager::GetInstancePointer()->SearchInstance(rank));
+ if ( pObj == 0 )
+ {
+ result->SetPointer(0);
+ }
+ else
+ {
+ result->SetPointer(pObj->GetBotVar());
+ }
+ return true;
+}
+
// Instruction "retobject(rank)".
bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* user)
@@ -458,7 +479,7 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us
rank = var->GetValInt();
- pObj = static_cast<CObject*>(CObjectManager::GetInstancePointer()->SearchInstance(rank));
+ pObj = static_cast<CObject*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_OBJECT, rank));
if ( pObj == 0 )
{
result->SetPointer(0);
@@ -3094,6 +3115,7 @@ void CScript::InitFonctions()
CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScript::cOneFloat);
CBotProgram::AddFunction("retobject", rGetObject, CScript::cGetObject);
+ CBotProgram::AddFunction("retobjectbyid", rGetObjectById, CScript::cGetObject);
CBotProgram::AddFunction("destroy", rDestroy, CScript::cDestroy);
CBotProgram::AddFunction("search", rSearch, CScript::cSearch);
CBotProgram::AddFunction("radar", rRadar, CScript::cRadar);
diff --git a/src/script/script.h b/src/script/script.h
index f0907f3..cd2a122 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -145,6 +145,7 @@ private:
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 rGetObjectById(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);