Disallow controlling enemy objects from CBot

master
krzys-h 2015-07-13 18:53:56 +02:00
parent 0e66104829
commit 78f4749134
8 changed files with 74 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -1575,6 +1575,9 @@ msgstr "Повернуть налево\\Поворот налево"
msgid "Type declaration missing"
msgstr "Не задан тип"
msgid "Unable to control enemy objects"
msgstr ""
msgid "Undo (Ctrl+z)"
msgstr "Отмена (Ctrl+Z)"

View File

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

View File

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

View File

@ -416,7 +416,7 @@ bool CScriptFunctions::rEndMission(CBotVar* var, CBotVar* result, int& exception
Error ended;
float delay;
ended = static_cast<Error>(static_cast<int>(var->GetValFloat())); // TODO: is this correct?!
ended = static_cast<Error>(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<CObject*>(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<CObject*>(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<CObject *>(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<CObject *>(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<CObject *>(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<CAutoFactory*>(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<CObject *>(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<CObject *>(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<CAutoBase*>(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;