Backwards combatibility for retobject() (#209)

dev-ui
krzys-h 2013-05-12 15:54:35 +02:00
parent 1f77efb9cb
commit 61841b3f40
3 changed files with 27 additions and 2 deletions

View File

@ -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 );";

View File

@ -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);

View File

@ -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);