From 69e52e5f24d3e02dde20bda5ee322697bafc92c8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 12 Apr 2013 23:28:44 +0200 Subject: Removed find() & repeat() functions Issue #168 --- src/CBot/CBot.cpp | 5 +- src/CBot/CBot.h | 27 --------- src/CBot/CBotString.cpp | 1 - src/CBot/CBotWhile.cpp | 143 ----------------------------------------------- src/CBot/resource.h | 1 - src/script/cbottoken.cpp | 5 -- src/script/script.cpp | 142 ---------------------------------------------- 7 files changed, 1 insertion(+), 323 deletions(-) (limited to 'src') diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index ed6831d..4a16b6b 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -186,7 +186,7 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) { type = pp->GetType(); // these instructions accept only lable - if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, ID_REPEAT, 0)) + if (!IsOfTypeList(pp, ID_WHILE, ID_FOR, ID_DO, 0)) { pStack->SetError(TX_LABEL, pp->GetStart()); return NULL; @@ -205,9 +205,6 @@ CBotInstr* CBotInstr::Compile(CBotToken* &p, CBotCStack* pStack) case ID_DO: return CBotDo::Compile(p, pStack); - case ID_REPEAT: - return CBotRepeat::Compile(p, pStack); - case ID_BREAK: case ID_CONTINUE: return CBotBreak::Compile(p, pStack); diff --git a/src/CBot/CBot.h b/src/CBot/CBot.h index 8886308..f5d78c8 100644 --- a/src/CBot/CBot.h +++ b/src/CBot/CBot.h @@ -57,7 +57,6 @@ class CBotExprVar; // a variable name as class CBotWhile; // while (...) {...}; class CBotIf; // if (...) {...} else {...} class CBotDefParam; // paramerer list of a function -class CBotRepeat; // repeat (nb) {...} @@ -492,32 +491,6 @@ public: void RestoreState(CBotStack* &pj, bool bMain); }; -class CBotRepeat : public CBotInstr -{ -private: - /// Number of iterations - CBotInstr* m_NbIter; - - /// Instructions - CBotInstr* m_Block; - - /// Label - CBotString m_label; // a label if there is - -public: - CBotRepeat(); - ~CBotRepeat(); - - /// Static method used for compilation - static CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack); - - /// Execute - bool Execute(CBotStack* &pj); - - /// Restore state - void RestoreState(CBotStack* &pj, bool bMain); -}; - class CBotDo : public CBotInstr { private: diff --git a/src/CBot/CBotString.cpp b/src/CBot/CBotString.cpp index b1b5fc4..51cae52 100644 --- a/src/CBot/CBotString.cpp +++ b/src/CBot/CBotString.cpp @@ -54,7 +54,6 @@ const std::map CBotString::s_keywordString = {ID_STATIC, "static"}, {ID_PROTECTED, "protected"}, {ID_PRIVATE, "private"}, - {ID_REPEAT, "repeat"}, {ID_DEBUGDD, "STARTDEBUGDD"}, {ID_INT, "int"}, {ID_FLOAT, "float"}, diff --git a/src/CBot/CBotWhile.cpp b/src/CBot/CBotWhile.cpp index dfd69bf..d24dc4b 100644 --- a/src/CBot/CBotWhile.cpp +++ b/src/CBot/CBotWhile.cpp @@ -155,149 +155,6 @@ void CBotWhile :: RestoreState(CBotStack* &pj, bool bMain) } -/////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////// -// compiles instruction "repeat" - -CBotRepeat::CBotRepeat() -{ - m_NbIter = - m_Block = NULL; // NULL so that delete is not possible further - name = "CBotRepeat"; // debug -} - -CBotRepeat::~CBotRepeat() -{ - delete m_NbIter; // frees the condition - delete m_Block; // frees the instruction block -} - -CBotInstr* CBotRepeat::Compile(CBotToken* &p, CBotCStack* pStack) -{ - CBotRepeat* inst = new CBotRepeat(); // creates the object - CBotToken* pp = p; // preserves at the ^ token (starting position) - - if ( IsOfType( p, TokenTypVar ) && - IsOfType( p, ID_DOTS ) ) - { - inst->m_label = pp->GetString(); // register the name of label - } - - inst->SetToken(p); - if (!IsOfType(p, ID_REPEAT)) return NULL; // should never happen - - CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp - - if ( IsOfType(p, ID_OPENPAR ) ) - { - CBotToken* ppp = p; // preserves the ^ token (starting position) - if ( NULL != (inst->m_NbIter = CBotExpression::Compile( p, pStk )) ) - { - if ( pStk->GetType() < CBotTypLong ) - { - if ( IsOfType(p, ID_CLOSEPAR ) ) - { - - IncLvl(inst->m_label); - inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true ); - DecLvl(); - - if ( pStk->IsOk() ) - { - // the statement block is ok (it may be empty! - - return pStack->Return(inst, pStk); // return an object to the application - } - } - pStack->SetError(TX_CLOSEPAR, p->GetStart()); - } - pStk->SetStartError(ppp->GetStart()); - pStk->SetError( TX_BADTYPE, p->GetStart() ); - } - pStack->SetError(TX_ENDOF, p); - } - pStack->SetError(TX_OPENPAR, p->GetStart()); // missing parenthesis - - delete inst; // error, frees up - return pStack->Return(NULL, pStk); // no object, the error is on the stack -} - -// execution of intruction "repeat" - -bool CBotRepeat :: Execute(CBotStack* &pj) -{ - CBotStack* pile = pj->AddStack(this); // adds an item to the stack - // or find in case of recovery -// if ( pile == EOX ) return true; - - if ( pile->IfStep() ) return false; - - while( true ) switch( pile->GetState() ) // executes the loop - { // there are two possible states (depending on recovery) - case 0: - // evaluates the number of iterations - if ( !m_NbIter->Execute(pile) ) return false; // interrupted here ? - - // the result of the condition is on the stack - - // terminates if an error or if the condition is false - int n; - if ( !pile->IsOk() || ( n = pile->GetVal() ) < 1 ) - { - return pj->Return(pile); // sends the results and releases the stack - } - - // puts the number of iterations +1 to the "state" - - if (!pile->SetState(n+1)) return false; // ready for further - continue; // continue as a result - - case 1: - // normal end of the loop - return pj->Return(pile); // sends the results and releases the stack - - default: - // evaluates the associated statement block - if ( m_Block != NULL && - !m_Block->Execute(pile) ) - { - if (pile->IfContinue(pile->GetState()-1, m_label)) continue; // if continued, will return to test - return pj->BreakReturn(pile, m_label); // sends the results and releases the stack - } - - // terminates if there is an error - if ( !pile->IsOk() ) - { - return pj->Return(pile); // sends the results and releases the stack - } - - // returns to the test again - if (!pile->SetState(pile->GetState()-1, 0)) return false; - continue; - } -} - -void CBotRepeat :: RestoreState(CBotStack* &pj, bool bMain) -{ - if ( !bMain ) return; - CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack - if ( pile == NULL ) return; - - switch( pile->GetState() ) - { // there are two possible states (depending on recovery) - case 0: - // evaluates the condition - m_NbIter->RestoreState(pile, bMain); - return; - - case 1: - // evaluates the associated statement block - if ( m_Block != NULL ) m_Block->RestoreState(pile, bMain); - return; - } -} - /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/resource.h b/src/CBot/resource.h index ed14240..f0449b0 100644 --- a/src/CBot/resource.h +++ b/src/CBot/resource.h @@ -47,7 +47,6 @@ enum EID ID_STATIC, ID_PROTECTED, ID_PRIVATE, - ID_REPEAT, ID_DEBUGDD, ID_INT, ID_FLOAT, diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 95b259b..19b0f78 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -220,7 +220,6 @@ std::string GetHelpFilename(const char *token) { if ( strcmp(token, "if" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/if.txt"); if ( strcmp(token, "else" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/if.txt"); - if ( strcmp(token, "repeat" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/repeat.txt"); if ( strcmp(token, "for" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/for.txt"); if ( strcmp(token, "while" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/while.txt"); if ( strcmp(token, "do" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/do.txt"); @@ -262,7 +261,6 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "move" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/move.txt"); if ( strcmp(token, "turn" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/turn.txt"); if ( strcmp(token, "goto" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/goto.txt"); - if ( strcmp(token, "find" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/find.txt"); if ( strcmp(token, "grab" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt"); if ( strcmp(token, "drop" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/drop.txt"); if ( strcmp(token, "sniff" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/sniff.txt"); @@ -380,7 +378,6 @@ bool IsFunction(const char *token) if ( strcmp(token, "move" ) == 0 ) return true; if ( strcmp(token, "turn" ) == 0 ) return true; if ( strcmp(token, "goto" ) == 0 ) return true; - if ( strcmp(token, "find" ) == 0 ) return true; if ( strcmp(token, "grab" ) == 0 ) return true; if ( strcmp(token, "drop" ) == 0 ) return true; if ( strcmp(token, "sniff" ) == 0 ) return true; @@ -432,7 +429,6 @@ const char* GetHelpText(const char *token) { if ( strcmp(token, "if" ) == 0 ) return "if ( condition ) { bloc }"; if ( strcmp(token, "else" ) == 0 ) return "else { bloc }"; - if ( strcmp(token, "repeat" ) == 0 ) return "repeat ( number )"; if ( strcmp(token, "for" ) == 0 ) return "for ( before ; condition ; end )"; if ( strcmp(token, "while" ) == 0 ) return "while ( condition ) { bloc }"; if ( strcmp(token, "do" ) == 0 ) return "do { bloc } while ( condition );"; @@ -464,7 +460,6 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "move" ) == 0 ) return "move ( distance );"; if ( strcmp(token, "turn" ) == 0 ) return "turn ( angle );"; if ( strcmp(token, "goto" ) == 0 ) return "goto ( position, altitude );"; - if ( strcmp(token, "find" ) == 0 ) return "find ( cat );"; if ( strcmp(token, "grab" ) == 0 ) return "grab ( order );"; if ( strcmp(token, "drop" ) == 0 ) return "drop ( order );"; if ( strcmp(token, "sniff" ) == 0 ) return "sniff ( );"; diff --git a/src/script/script.cpp b/src/script/script.cpp index 6095e05..b3fd6ce 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1632,147 +1632,6 @@ bool CScript::rGoto(CBotVar* var, CBotVar* result, int& exception, void* user) return Process(script, result, exception); } -// Instruction "find(type)". - -bool CScript::rFind(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - CScript* script = (static_cast(user))->GetRunScript(); - Math::Vector pos; - TaskGotoGoal goal; - TaskGotoCrash crash; - float altitude; - Error err; - CObject* pThis = static_cast(user); - CObject *pObj, *pBest; - CBotVar* array; - Math::Vector iPos, oPos; - float best, minDist, maxDist, iAngle, focus, d, a; - int type, oType, i; - bool bArray; - - exception = 0; - - if ( script->m_primaryTask == 0 ) // no task in progress? - { - type = OBJECT_NULL; - focus = Math::PI*2.0f; - minDist = 0.0f*g_unit; - maxDist = 1000.0f*g_unit; - - if ( var->GetType() == CBotTypArrayPointer ) - { - array = var->GetItemList(); - bArray = true; - } - else - { - type = var->GetValInt(); - bArray = false; - } - - CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); - - best = 100000.0f; - pBest = 0; - for ( i=0 ; i<1000000 ; i++ ) - { - pObj = static_cast(iMan->SearchInstance(CLASS_OBJECT, i)); - if ( pObj == 0 ) break; - if ( pObj == pThis ) continue; - - if ( pObj->GetTruck() != 0 ) continue; // object transported? - if ( !pObj->GetActif() ) continue; - if ( pObj->GetProxyActivate() ) continue; - - oType = pObj->GetType(); - if ( oType == OBJECT_TOTO ) continue; - - if ( oType == OBJECT_RUINmobilew2 || - oType == OBJECT_RUINmobilet1 || - oType == OBJECT_RUINmobilet2 || - oType == OBJECT_RUINmobiler1 || - oType == OBJECT_RUINmobiler2 ) - { - oType = OBJECT_RUINmobilew1; // any ruin - } - - if ( oType == OBJECT_SCRAP2 || - oType == OBJECT_SCRAP3 || - oType == OBJECT_SCRAP4 || - oType == OBJECT_SCRAP5 ) // wastes? - { - oType = OBJECT_SCRAP1; // any waste - } - - if ( oType == OBJECT_BARRIER2 || - oType == OBJECT_BARRIER3 ) // barriers? - { - oType = OBJECT_BARRIER1; // any barrier - } - - if ( bArray ) - { - if ( !FindList(array, oType) ) continue; - } - else - { - if ( type != oType && type != OBJECT_NULL ) continue; - } - - oPos = pObj->GetPosition(0); - d = Math::DistanceProjected(iPos, oPos); - if ( d < minDist || d > maxDist ) continue; // too close or too far? - - if ( focus >= Math::PI*2.0f ) - { - if ( d < best ) - { - best = d; - pBest = pObj; - } - continue; - } - - a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW ! - if ( Math::TestAngle(a, iAngle-focus/2.0f, iAngle+focus/2.0f) ) - { - if ( d < best ) - { - best = d; - pBest = pObj; - } - } - } - - if ( pBest == 0 ) - { - exception = ERR_FIND_IMPOSSIBLE; - return false; - } - - pos = pBest->GetPosition(0); - goal = TGG_DEFAULT; - crash = TGC_DEFAULT; - altitude = 0.0f*g_unit; - - script->m_primaryTask = new CTaskManager(script->m_object); - err = script->m_primaryTask->StartTaskGoto(pos, altitude, goal, crash); - if ( err != ERR_OK ) - { - delete script->m_primaryTask; - script->m_primaryTask = 0; - result->SetValInt(err); // shows the error - if ( script->m_errMode == ERM_STOP ) - { - exception = err; - return false; - } - return true; - } - } - return Process(script, result, exception); -} - // Compilation "grab/drop(oper)". CBotTypResult CScript::cGrabDrop(CBotVar* &var, void* user) @@ -2968,7 +2827,6 @@ void CScript::InitFonctions() CBotProgram::AddFunction("move", rMove, CScript::cOneFloat); CBotProgram::AddFunction("turn", rTurn, CScript::cOneFloat); CBotProgram::AddFunction("goto", rGoto, CScript::cGoto); - CBotProgram::AddFunction("find", rFind, CScript::cOneFloat); CBotProgram::AddFunction("grab", rGrab, CScript::cGrabDrop); CBotProgram::AddFunction("drop", rDrop, CScript::cGrabDrop); CBotProgram::AddFunction("sniff", rSniff, CScript::cNull); -- cgit v1.2.3-1-g7c22