bool CBotSwitch :: Execute(CBotStack* &pj) { CBotStack* pile1 = pj->AddStack(this); // adds an item to the stack // if ( pile1 == EOX ) return true; CBotInstr* p = m_Block; // first expression int state = pile1->GetState(); if (state == 0) { if ( !m_Value->Execute(pile1) ) return false; pile1->SetState(state = -1); } if ( pile1->IfStep() ) return false; if ( state == -1 ) { state = 0; int val = pile1->GetVal(); // result of the value CBotStack* pile2 = pile1->AddStack(); while ( p != nullptr ) // search for the corresponding case in a list { state++; if ( p->CompCase( pile2, val ) ) break; // found the case p = p->GetNext(); } pile2->Delete(); if ( p == nullptr ) return pj->Return(pile1); // completed if nothing if ( !pile1->SetState(state) ) return false; } p = m_Block; // returns to the beginning while (state-->0) p = p->GetNext(); // advance in the list while( p != nullptr ) { if ( !p->Execute(pile1) ) return pj->BreakReturn(pile1); if ( !pile1->IncState() ) return false; p = p->GetNext(); } return pj->Return(pile1); }