/** * Показ лога славы (show glory), отсортированного по убыванию даты, с возможностью фильтрациии. * Фильтры: show glory число|transfer|remove|hide */ void show_log(CHAR_DATA *ch , char const * const value) { if (glory_log.empty()) { send_to_char("Пусто, слава те господи!\r\n", ch); return; } int type = 0; int num = 0; std::string buffer; if (value && *value) buffer = value; if (CompareParam(buffer, "transfer")) type = TRANSFER_GLORY; else if (CompareParam(buffer, "remove")) type = REMOVE_GLORY; else if (CompareParam(buffer, "hide")) type = HIDE_GLORY; else { try { num = boost::lexical_cast<int>(buffer); } catch (boost::bad_lexical_cast &) { type = 0; num = 0; } } std::stringstream out; for (GloryLogType::reverse_iterator it = glory_log.rbegin(); it != glory_log.rend(); ++it) { if (type == it->second->type || (type == 0 && num == 0) || (type == 0 && num <= it->second->num)) { char time_buf[17]; strftime(time_buf, sizeof(time_buf), "%H:%M %d-%m-%Y", localtime(&it->first)); out << time_buf << " " << it->second->karma << "\r\n"; } } page_string(ch->desc, out.str()); }
void CallOperatorUnary( gmThread* pThread, gmVariable *operand, gmOperator Op ) { std::map<gmType,gmClassDef*>::const_iterator i = gmMachineEx::ClassList.find( operand->m_type ); if( i != gmMachineEx::ClassList.end() && i->second ) { std::map<gmOperator,gmFuncProxy*>::const_iterator j = i->second->OpList.find( Op ); if( j != i->second->OpList.end() ) { gmFuncProxy* FuncProxy = NULL; gmFuncProxy* TempProxy = j->second; gmUserObject* pGmObj = (gmUserObject*)operand->m_value.m_ref; int isConst = pGmObj->m_properties & GM_IS_CONST; int TotalCoeff, BestCoeff = 0; const gmType* TypeId; while( TempProxy ) { TotalCoeff = 3; TypeId = TempProxy->GetTypeIds(); if( TempProxy->GetFunctionCat() == FUNCTION_OPERATOR_TYPE ) { gmType TempId = isConst ? -(operand->m_type) : operand->m_type; TotalCoeff = CompareParam( TempId, *TypeId ); } else { if( isConst && !TempProxy->isConst() ) TotalCoeff = 0; } if( TotalCoeff == 3 ) { FuncProxy = TempProxy; break; } else if( TotalCoeff > BestCoeff ) { BestCoeff = TotalCoeff; FuncProxy = TempProxy; } TempProxy = TempProxy->pNextOverloaded; } if( FuncProxy ) *operand = (*FuncProxy)(operand,pThread->GetMachine()); else pThread->GetMachine()->GetLog().LogEntry( "Could not find any matching overloaded operator: '%s'", gmGetOperatorName( Op ) ); } } }
void CallOperatorBinary( gmThread* pThread, gmVariable *operand, gmOperator Op ) { int isConst = false; bool SkipMethodOperators; gmType Type1, Type2, TempIdType1, TempIdType2; const gmType *TypeId; gmMachine* VM = pThread->GetMachine(); if( VM ) { gmUserObject* pGmObj; if( operand[0].m_type <= GM_USER ) TempIdType1 = operand[0].m_type; else { pGmObj = (gmUserObject*)operand[0].m_value.m_ref; isConst = pGmObj->m_properties & GM_IS_CONST; TempIdType1 = isConst ? -(operand[0].m_type) : operand[0].m_type; } if( operand[1].m_type <= GM_USER ) TempIdType2 = operand[1].m_type; else { pGmObj = (gmUserObject*)operand[1].m_value.m_ref; TempIdType2 = ( pGmObj->m_properties & GM_IS_CONST ) ? -(operand[1].m_type) : operand[1].m_type; } if( operand[0].m_type > GM_USER && VM->GetTypeNativeOperator( operand[0].m_type, Op ) ) { Type1 = operand[0].m_type; Type2 = operand[1].m_type; SkipMethodOperators = false; } else { Type1 = operand[1].m_type; Type2 = operand[0].m_type; SkipMethodOperators = true; } #ifdef _DEBUG bool Ambiguity = false; #endif int TotalCoeff, TempCoeff, BestCoeff = 0; std::map<gmType,gmClassDef*>::const_iterator i = gmMachineEx::ClassList.find( Type1 ); if( i != gmMachineEx::ClassList.end() && i->second ) { std::map<gmOperator,gmFuncProxy*>::const_iterator j = i->second->OpList.find( Op ); if( j != i->second->OpList.end() ) { gmFuncProxy* FuncProxy = NULL; gmFuncProxy* TempProxy = j->second; while( TempProxy ) { TotalCoeff = 0; TypeId = TempProxy->GetTypeIds(); if( TempProxy->GetFunctionCat() == FUNCTION_OPERATOR_TYPE ) { TotalCoeff = CompareParam( TempIdType1, *TypeId ); if( TotalCoeff ) { TempCoeff = CompareParam( TempIdType2, TypeId[1] ); if(TempCoeff) TotalCoeff += TempCoeff; else TotalCoeff = 0; } } else { if( !SkipMethodOperators ) { if( isConst ) { if( TempProxy->isConst() ) TotalCoeff = 3; } else TotalCoeff = 3; if( TotalCoeff ) { TempCoeff = CompareParam( TempIdType2, *TypeId ); if(TempCoeff) TotalCoeff += TempCoeff; else TotalCoeff = 0; } } } if( TotalCoeff == 6 ) { FuncProxy = TempProxy; #ifdef _DEBUG Ambiguity = false; #endif break; } else if( TotalCoeff > BestCoeff ) { BestCoeff = TotalCoeff; FuncProxy = TempProxy; #ifdef _DEBUG Ambiguity = false; #endif } #ifdef _DEBUG else if( TotalCoeff != 0 && TotalCoeff == BestCoeff ) Ambiguity = true; #endif TempProxy = TempProxy->pNextOverloaded; if( !TempProxy ) { if( Type2 != Type1 && Type2 > GM_USER && VM->GetTypeNativeOperator(Type2,Op) ) { i = gmMachineEx::ClassList.find( Type2 ); if( i != gmMachineEx::ClassList.end() && i->second ) { j = i->second->OpList.find( Op ); if( j != i->second->OpList.end() ) TempProxy = j->second; } Type2 = GM_NULL; } else break; } } #ifdef _DEBUG if( Ambiguity ) VM->GetLog().LogEntry( "Ambiguous call to an overloaded operator: '%s'", gmGetOperatorName( Op ) ); #endif if( FuncProxy ) { if( Op == O_SETIND ) operand->m_type = -operand->m_type; *operand = (*FuncProxy)(operand,VM); } else { VM->GetLog().LogEntry( "Could not find any matching overloaded operator: '%s'", gmGetOperatorName( Op ) ); operand->Nullify(); } } } } }