Add auto object detection for takeoff, destroy, camerafocus

1164-fix
Fiftytwo 2017-11-30 20:41:44 +01:00
parent 0b36bdf37f
commit 94aa76e7a1
1 changed files with 27 additions and 8 deletions

View File

@ -406,7 +406,12 @@ bool CScriptFunctions::rDestroy(CBotVar* var, CBotVar* result, int& exception, v
exception = 0; exception = 0;
Error err; Error err;
CObject* obj = static_cast<CObject*>(var->GetUserPtr()); CObject* obj;
if (var == nullptr)
obj = CObjectManager::GetInstancePointer()->FindNearest(pThis, OBJECT_DESTROYER);
else
obj = static_cast<CObject*>(var->GetUserPtr());
if (obj == nullptr) if (obj == nullptr)
{ {
exception = ERR_WRONG_OBJ; exception = ERR_WRONG_OBJ;
@ -660,7 +665,12 @@ bool CScriptFunctions::rTakeOff(CBotVar* var, CBotVar* result, int& exception, v
Error err; Error err;
exception = 0; exception = 0;
CObject* base = static_cast<CObject*>(var->GetUserPtr()); CObject* base;
if (var == nullptr)
base = CObjectManager::GetInstancePointer()->FindNearest(pThis, OBJECT_BASE);
else
base = static_cast<CObject*>(var->GetUserPtr());
if (base == nullptr) if (base == nullptr)
{ {
exception = ERR_WRONG_OBJ; exception = ERR_WRONG_OBJ;
@ -3015,20 +3025,29 @@ bool CScriptFunctions::rPenWidth(CBotVar* var, CBotVar* result, int& exception,
CBotTypResult CScriptFunctions::cOneObject(CBotVar* &var, void* user) CBotTypResult CScriptFunctions::cOneObject(CBotVar* &var, void* user)
{ {
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam); if ( var != nullptr )
var = var->GetNext(); {
if ( var == nullptr ) return CBotTypResult(CBotTypFloat); var = var->GetNext();
if ( var == nullptr ) return CBotTypResult(CBotTypFloat);
}
else
return CBotTypResult(CBotTypFloat);
return CBotTypResult(CBotErrOverParam); return CBotTypResult(CBotErrOverParam);
} }
// Instruction "camerafocus(object)". // Instruction "camerafocus(object)".
bool CScriptFunctions::rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user) bool CScriptFunctions::rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user)
{ {
CScript* script = static_cast<CScript*>(user); CScript* script = static_cast<CScript*>(user);
CObject* object = static_cast<CObject*>(var->GetUserPtr()); CObject* object;
if (var == nullptr)
object = script->m_object;
else
object = static_cast<CObject*>(var->GetUserPtr());
script->m_main->SelectObject(object, false); script->m_main->SelectObject(object, false);