From 78f47491345cc69f14e2e7d823b1fcea731c7ab5 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 13 Jul 2015 18:53:56 +0200 Subject: [PATCH] Disallow controlling enemy objects from CBot --- po/colobot.pot | 3 ++ po/de.po | 3 ++ po/fr.po | 3 ++ po/pl.po | 3 ++ po/ru.po | 3 ++ src/common/global.h | 3 +- src/common/restext.cpp | 2 +- src/script/scriptfunc.cpp | 69 +++++++++++++++++++++++++++++++-------- 8 files changed, 74 insertions(+), 15 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 3d411f9e..ba56abd9 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -1530,6 +1530,9 @@ msgstr "" msgid "Can not create this; there are too many objects" msgstr "" +msgid "Unable to control enemy objects" +msgstr "" + #, c-format msgid "\"%s\" missing in this exercise" msgstr "" diff --git a/po/de.po b/po/de.po index 70f3eeab..2ea63225 100644 --- a/po/de.po +++ b/po/de.po @@ -1583,6 +1583,9 @@ msgstr "Drehung nach rechts\\Steuer rechts" msgid "Type declaration missing" msgstr "Hier muss ein Variablentyp stehen" +msgid "Unable to control enemy objects" +msgstr "" + msgid "Undo (Ctrl+z)" msgstr "Widerrufen (Ctrl+z)" diff --git a/po/fr.po b/po/fr.po index 3eef7581..f5ca72da 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1578,6 +1578,9 @@ msgstr "Tourner à droite\\Moteur à droite" msgid "Type declaration missing" msgstr "Déclaration de type attendu" +msgid "Unable to control enemy objects" +msgstr "" + msgid "Undo (Ctrl+z)" msgstr "Annuler (Ctrl+z)" diff --git a/po/pl.po b/po/pl.po index 6df509e7..b6b6b7eb 100644 --- a/po/pl.po +++ b/po/pl.po @@ -1580,6 +1580,9 @@ msgstr "Obróć w prawo\\Obraca robota w prawo" msgid "Type declaration missing" msgstr "Brak deklaracji typu" +msgid "Unable to control enemy objects" +msgstr "Nie można kontrolować wrogich obiektów" + msgid "Undo (Ctrl+z)" msgstr "Cofnij (Ctrl+Z)" diff --git a/po/ru.po b/po/ru.po index 7b063707..6142762f 100644 --- a/po/ru.po +++ b/po/ru.po @@ -1575,6 +1575,9 @@ msgstr "Повернуть налево\\Поворот налево" msgid "Type declaration missing" msgstr "Не задан тип" +msgid "Unable to control enemy objects" +msgstr "" + msgid "Undo (Ctrl+z)" msgstr "Отмена (Ctrl+Z)" diff --git a/src/common/global.h b/src/common/global.h index 11eeecd9..3d5998c8 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -124,6 +124,7 @@ enum Error ERR_DELETEMOBILE = 700, //! < vehicle destroyed ERR_DELETEBUILDING = 701, //! < building destroyed ERR_TOOMANY = 702, //! < too many objects + ERR_ENEMY_OBJECT = 703, //! < can't control enemy object ERR_OBLIGATORYTOKEN = 800, //! < compulsory instruction missing ERR_PROHIBITEDTOKEN = 801, //! < instruction prohibited ERR_AIM_IMPOSSIBLE = 900, //! < cannot aim at specified angle(s) @@ -136,7 +137,7 @@ enum Error INFO_LABO = 10005, //! < analysis ended INFO_ENERGY = 10006, //! < battery available INFO_NUCLEAR = 10007, //! < nuclear battery available - INFO_FINDING = 10008, //! < nuclear battery available + INFO_FINDING = 10008, //! < useful object found INFO_MARKPOWER = 10020, //! < location for station found INFO_MARKURANIUM = 10021, //! < location for derrick found INFO_MARKSTONE = 10022, //! < location for derrick found diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 0d89d031..0f5e901b 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -653,6 +653,7 @@ void InitializeRestext() stringsErr[ERR_DELETEMOBILE] = TR("Bot destroyed"); stringsErr[ERR_DELETEBUILDING] = TR("Building destroyed"); stringsErr[ERR_TOOMANY] = TR("Can not create this; there are too many objects"); + stringsErr[ERR_ENEMY_OBJECT] = TR("Unable to control enemy objects"); stringsErr[ERR_OBLIGATORYTOKEN] = TR("\"%s\" missing in this exercise"); stringsErr[ERR_PROHIBITEDTOKEN] = TR("Do not use in this exercise"); @@ -883,4 +884,3 @@ bool GetResource(ResType type, unsigned int num, std::string& text) return true; } } - diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index cea10390..8c4ce43b 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -416,7 +416,7 @@ bool CScriptFunctions::rEndMission(CBotVar* var, CBotVar* result, int& exception Error ended; float delay; - ended = static_cast(static_cast(var->GetValFloat())); // TODO: is this correct?! + ended = static_cast(var->GetValInt()); var = var->GetNext(); delay = var->GetValFloat(); @@ -486,7 +486,8 @@ bool CScriptFunctions::rGetResearchEnable(CBotVar* var, CBotVar* result, int& ex bool CScriptFunctions::rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user) { - result->SetValInt(CRobotMain::GetInstancePointer()->GetDoneResearch(0)); + CObject* pThis = static_cast(user); + result->SetValInt(CRobotMain::GetInstancePointer()->GetDoneResearch(pThis->GetTeam())); return true; } @@ -512,7 +513,8 @@ bool CScriptFunctions::rSetResearchEnable(CBotVar* var, CBotVar* result, int& ex bool CScriptFunctions::rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user) { - CRobotMain::GetInstancePointer()->SetDoneResearch(var->GetValInt(), 0); + CObject* pThis = static_cast(user); + CRobotMain::GetInstancePointer()->SetDoneResearch(var->GetValInt(), pThis->GetTeam()); CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE)); return true; } @@ -607,6 +609,8 @@ CBotTypResult CScriptFunctions::cBusy(CBotVar* thisclass, CBotVar* &var) bool CScriptFunctions::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { + CObject* pThis = static_cast(user); + exception = 0; CBotVar* classVars = thisclass->GetItemList(); // "category" @@ -626,6 +630,13 @@ bool CScriptFunctions::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, CObject* obj = CObjectManager::GetInstancePointer()->GetObjectById(rank); CAuto* automat = obj->GetAuto(); + if ( pThis->GetTeam() != obj->GetTeam() && obj->GetTeam() != 0 ) + { + exception = ERR_ENEMY_OBJECT; + result->SetValInt(ERR_ENEMY_OBJECT); + return false; + } + if ( automat != nullptr ) result->SetValInt(automat->GetBusy()); else @@ -636,6 +647,9 @@ bool CScriptFunctions::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, bool CScriptFunctions::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { + CObject* pThis = static_cast(user); + CScript* script = pThis->GetRunScript(); + exception = 0; Error err; @@ -657,6 +671,13 @@ bool CScriptFunctions::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* resul CObject* obj = CObjectManager::GetInstancePointer()->GetObjectById(rank); CAuto* automat = obj->GetAuto(); + if ( pThis->GetTeam() != obj->GetTeam() && obj->GetTeam() != 0 ) + { + exception = ERR_ENEMY_OBJECT; + result->SetValInt(ERR_ENEMY_OBJECT); + return false; + } + if ( thisType == OBJECT_DESTROYER ) err = automat->StartAction(0); else @@ -665,8 +686,7 @@ bool CScriptFunctions::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* resul if ( err != ERR_OK ) { result->SetValInt(err); // return error - //TODO: if ( script->m_errMode == ERM_STOP ) - if ( true ) + if ( script->m_errMode == ERM_STOP ) { exception = err; return false; @@ -699,8 +719,7 @@ CBotTypResult CScriptFunctions::cFactory(CBotVar* thisclass, CBotVar* &var) bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { CObject* pThis = static_cast(user); - assert(pThis != nullptr); - printf("Executing factory() as team %d\n", pThis->GetTeam()); + CScript* script = pThis->GetRunScript(); Error err; @@ -742,6 +761,13 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul return false; } + if ( pThis->GetTeam() != factory->GetTeam() && factory->GetTeam() != 0 ) + { + exception = ERR_ENEMY_OBJECT; + result->SetValInt(ERR_ENEMY_OBJECT); + return false; + } + if ( thisType == OBJECT_FACTORY ) { CAutoFactory* automat = static_cast(factory->GetAuto()); @@ -772,8 +798,7 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul if ( err != ERR_OK ) { result->SetValInt(err); // return error - //TODO: if ( script->m_errMode == ERM_STOP ) - if ( true ) + if ( script->m_errMode == ERM_STOP ) { exception = err; return false; @@ -788,6 +813,9 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { + CObject* pThis = static_cast(user); + CScript* script = pThis->GetRunScript(); + Error err; exception = 0; @@ -812,6 +840,13 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu CObject* center = CObjectManager::GetInstancePointer()->GetObjectById(rank); CAuto* automat = center->GetAuto(); + if ( pThis->GetTeam() != center->GetTeam() && center->GetTeam() != 0 ) + { + exception = ERR_ENEMY_OBJECT; + result->SetValInt(ERR_ENEMY_OBJECT); + return false; + } + if ( thisType == OBJECT_RESEARCH || thisType == OBJECT_LABO ) { @@ -853,8 +888,7 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu if ( err != ERR_OK ) { result->SetValInt(err); // return error - //TODO: if ( script->m_errMode == ERM_STOP ) - if ( true ) + if( script->m_errMode == ERM_STOP ) { exception = err; return false; @@ -869,6 +903,9 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu bool CScriptFunctions::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user) { + CObject* pThis = static_cast(user); + CScript* script = pThis->GetRunScript(); + Error err; exception = 0; @@ -891,6 +928,13 @@ bool CScriptFunctions::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* resul CObject* center = CObjectManager::GetInstancePointer()->GetObjectById(rank); CAuto* automat = center->GetAuto(); + if ( pThis->GetTeam() != center->GetTeam() && center->GetTeam() != 0 ) + { + exception = ERR_ENEMY_OBJECT; + result->SetValInt(ERR_ENEMY_OBJECT); + return false; + } + if ( thisType == OBJECT_BASE ) err = (static_cast(automat))->TakeOff(false); else @@ -899,8 +943,7 @@ bool CScriptFunctions::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* resul if ( err != ERR_OK ) { result->SetValInt(err); // return error - //TODO: if ( script->m_errMode == ERM_STOP ) - if ( true ) + if ( script->m_errMode == ERM_STOP ) { exception = err; return false;