void KRProfileSys::SetEQCoeffs() { for (int i = 0; i < Crits.GetSize(); i++) { int base = Crits.GetPriority(0); int index = Crits.GetPriority(i); int value = GetSpecial(A_EQ)->GetValue(index); float res = GraphValue(base, value); GetSpecial(A_EQ)->ChangeCoeff(index, res); } }
void Outputer::OutputToFile() { QString filename = sConfig.get(CONF_STRING_OUTPUT_LOG); if (filename.isEmpty()) return; QFile file(filename); if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) return; QTextStream str(&file); for(int p = 0; p <= cur_phase; ++p) { str << PhaseHeader[p]+endline; str << GetPercentBar(p)+space+GetSpecial(p)+space+Errors(p)+endline; if (p != cur_phase) { if (!current[p]) { str << PhaseSkipped[p]+endline; break; } if (!PhaseHeader[p].isNull()) str << PhaseEnd[p]+endline; str << "Total downloaded: "+getSizeFromLong(phaseDLed[p])+" total time: "+Timestamp(phaseLenght[p]/1000, 0).write(FORMAT_TIME)+endline; } str << endline; } str << "Current speed: "+getSpeedFormFromFloat(totalSpeed())+" Downloaded: "+getSizeFromLong(totalDLed)+" Total time: "+Timestamp(totalLenght()/1000, 0).write(FORMAT_TIME); file.close(); }
void Outputer::Refresh() { #ifdef WIN32 QString line = GetPercentBar(cur_phase)+space+GetSpecial(cur_phase)+space+Errors(cur_phase)+space+DataFlow(); printf(QString("\r"+line).toStdString().c_str()); OutputToFile(); #endif }
void KRProfileSys::SetLambdas() { std::vector<float>X; float sum = 1; for (unsigned int i = 1; i < Crits.GetSize(); i++) { int index = Crits.GetPriority(i); sum += GetSpecial(A_EQ)->GetCoeff(index); } X.push_back(1 / sum); for (int i = 1; i < Crits.GetSize(); i++) { int index = Crits.GetPriority(i); float a = GetSpecial(A_EQ)->GetCoeff(index); X.push_back(a * X[0]); } std::vector<float>L; for (int i = 0; i < Crits.GetSize(); i++) { int index = Crits.GetPriority(i); L.push_back(X[index]); } Crits.SetLambdas(L); }
KEYS ReadKey() { KEYS current, last; current = 0; // while (current == 0) // { current = PeekKey(); // } last = current; while (current != 0) { current = GetSpecial(); if (current != 0) { return current; } current = PeekKey(); ReadCommand(); } //switch key 3 with key 4 // switch 6 - 5 switch (last) { case KEY3: last = KEY4; break; case KEY4: last =KEY3; break; case KEY5: last =KEY6; break; case KEY6: last =KEY5; break; } return last; }
void Outputer::PrintScreen() { QString screenLine = "\f"; for(int p = 0; p <= cur_phase; ++p) { screenLine.append(PhaseHeader[p]+endline); screenLine += GetPercentBar(p)+space+GetSpecial(p)+space+Errors(p)+endline; if (p != cur_phase) { if (!current[p]) { str << PhaseSkipped[p]+endline; break; } if (!PhaseHeader[p].isNull()) screenLine.append(PhaseEnd[p]+endline); screenLine += "Total downloaded: "+getSizeFromLong(phaseDLed[p])+" total time: "+Timestamp(phaseLenght[p]/1000, 0).write(FORMAT_TIME)+endline; } screenLine.append(endline); } screenLine += "Current speed: "+getSpeedFormFromFloat(totalSpeed())+" Downloaded: "+getSizeFromLong(totalDLed)+" Total time: "+Timestamp(totalLenght()/1000, 0).write(FORMAT_TIME)+endline; printf(screenLine.toStdString().c_str()); OutputToFile(); }
KRProfileSys::KRProfileSys(KRProfile *W, KRProfile *B, KRCritSys Crt) { Crits = Crt; Worst = W; Best = B; AddSpecial(A_25, new KRProfile("A25", Crits)); AddSpecial(A_50, new KRProfile("A50", Crits)); AddSpecial(A_75, new KRProfile("A75", Crits)); AddSpecial(A_EQ, new KRProfile("AEQ", Crits)); GetSpecial(A_WORST)->ChangeCoeff(0.0); GetSpecial(A_25)->ChangeCoeff(0.25); GetSpecial(A_50)->ChangeCoeff(0.50); GetSpecial(A_75)->ChangeCoeff(0.75); GetSpecial(A_BEST)->ChangeCoeff(1.0); GetSpecial(A_EQ)->ChangeCoeff(0); for (int i = 0; i < Crits.GetSize(); i++) { int Worst = 0, Best = 0; if (!Crits.GetByIndex(i).dec) { Worst = GetWorst()->GetValue(i); Best = GetBest()->GetValue(i); } else { Worst = GetWorst()->GetValue(i); Best = GetBest()->GetValue(i); } ChangeSpecial(A_25, i, (Worst + (Worst + Best) / 2.0) / 2.0); ChangeSpecial(A_50, i, (Worst + Best) / 2.0); ChangeSpecial(A_75, i, (Best + (Worst + Best) / 2.0) / 2.0); ChangeSpecial(A_EQ, i, (Worst + Best) / 2.0); } std::vector<int>P; P.resize(Crits.GetSize()); Crits.SetPrority(P); }
float KRProfileSys::GraphValue(int Index, int Value) { // int Value = GetSpecial(A_EQ)->GetValue(iEQ); int Val1 = 0, Val2 = 0; float Coeff1 = 0, Coeff2 = 0; int index = 0; bool dec = Crits.GetByIndex(Index).dec; if (!dec) { if (Value <= GetSpecial(A_WORST)->GetValue(Index)) return 0.0; if (Value >= GetSpecial(A_BEST)->GetValue(Index)) return 1.0; } else { if (Value >= GetSpecial(A_WORST)->GetValue(Index)) return 0.0; if (Value <= GetSpecial(A_BEST)->GetValue(Index)) return 1.0; } if (!dec) { for (int i = A_WORST; i < A_BEST; i++) { if (Value >= GetSpecial(i)->GetValue(Index) && Value < GetSpecial(i + 1)->GetValue(Index)) { Val1 = GetSpecial(i)->GetValue(Index); Val2 = GetSpecial(i + 1)->GetValue(Index); Coeff1 = GetSpecial(i)->GetCoeff(Index); Coeff2 = GetSpecial(i + 1)->GetCoeff(Index); index = i; }; } } else { for (int i = A_BEST; i > A_WORST; i--) { index = i; if (Value >= GetSpecial(i)->GetValue(Index) && Value < GetSpecial(i - 1)->GetValue(Index)) { Val2 = GetSpecial(i)->GetValue(Index); Val1 = GetSpecial(i - 1)->GetValue(Index); Coeff2 = GetSpecial(i)->GetCoeff(Index); Coeff1 = GetSpecial(i - 1)->GetCoeff(Index); }; } } float result; int W = GetSpecial(A_WORST)->GetValue(Index); int A25 = GetSpecial(A_25)->GetValue(Index); int A50 = GetSpecial(A_50)->GetValue(Index); int A75 = GetSpecial(A_75)->GetValue(Index); int B = GetSpecial(A_BEST)->GetValue(Index); if (!dec) { int A1 = Val2 - Val1; int A2 = Value - Val1; float C2 = Coeff2 - Coeff1; result = (float)A2 / (float)A1 * (float)C2 + Coeff1; } else { int A1 = Val2 - Val1; int A2 = Value - Val1; float C2 = Coeff2 - Coeff1; result = (float)A2 / (float)A1 * (float)C2 + Coeff1; } return result; }
void SpecialsPanel::Update() { //std::cout << "SpecialsPanel::Update" << std::endl; for (std::map<std::string, StatisticIcon*>::iterator it = m_icons.begin(); it != m_icons.end(); ++it) DeleteChild(it->second); m_icons.clear(); // get specials to display TemporaryPtr<const UniverseObject> obj = GetUniverseObject(m_object_id); if (!obj) { ErrorLogger() << "SpecialsPanel::Update couldn't get object with id " << m_object_id; return; } const std::map<std::string, std::pair<int, float> >& specials = obj->Specials(); // get specials and use them to create specials icons // for specials with a nonzero for (std::map<std::string, std::pair<int, float> >::const_iterator it = specials.begin(); it != specials.end(); ++it) { const Special* special = GetSpecial(it->first); StatisticIcon* graphic = 0; if (it->second.second > 0.0f) graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name()), it->second.second, 2, false); else graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name())); graphic->SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); std::string desc = UserString(special->Description()); if (it->second.second > 0.0f) desc += "\n" + boost::io::str(FlexibleFormat(UserString("SPECIAL_CAPACITY")) % DoubleToString(it->second.second, 2, false)); if (it->second.first > 0) desc += "\n" + boost::io::str(FlexibleFormat(UserString("ADDED_ON_TURN")) % boost::lexical_cast<std::string>(it->second.first)); else desc += "\n" + UserString("ADDED_ON_INITIAL_TURN"); if (GetOptionsDB().Get<bool>("UI.autogenerated-effects-descriptions") && !special->Effects().empty()) { desc += boost::io::str(FlexibleFormat(UserString("ENC_EFFECTS_STR")) % EffectsDescription(special->Effects())); } graphic->SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>( new IconTextBrowseWnd(ClientUI::SpecialIcon(special->Name()), UserString(special->Name()), desc))); m_icons[it->first] = graphic; graphic->InstallEventFilter(this); } const GG::X AVAILABLE_WIDTH = Width() - EDGE_PAD; GG::X x(EDGE_PAD); GG::Y y(EDGE_PAD); for (std::map<std::string, StatisticIcon*>::iterator it = m_icons.begin(); it != m_icons.end(); ++it) { StatisticIcon* icon = it->second; icon->SizeMove(GG::Pt(x, y), GG::Pt(x,y) + GG::Pt(SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT)); AttachChild(icon); x += SPECIAL_ICON_WIDTH + EDGE_PAD; if (x + SPECIAL_ICON_WIDTH + EDGE_PAD > AVAILABLE_WIDTH) { x = GG::X(EDGE_PAD); y += SPECIAL_ICON_HEIGHT + EDGE_PAD; } } if (m_icons.empty()) { Resize(GG::Pt(Width(), GG::Y0)); } else { Resize(GG::Pt(Width(), y + SPECIAL_ICON_HEIGHT + EDGE_PAD*2)); } }
void SpecialsPanel::Update() { //std::cout << "SpecialsPanel::Update" << std::endl; for (std::map<std::string, StatisticIcon*>::value_type& entry : m_icons) DeleteChild(entry.second); m_icons.clear(); // get specials to display std::shared_ptr<const UniverseObject> obj = GetUniverseObject(m_object_id); if (!obj) { ErrorLogger() << "SpecialsPanel::Update couldn't get object with id " << m_object_id; return; } // get specials and use them to create specials icons // for specials with a nonzero for (const std::map<std::string, std::pair<int, float>>::value_type& entry : obj->Specials()) { const Special* special = GetSpecial(entry.first); StatisticIcon* graphic = nullptr; if (entry.second.second > 0.0f) graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name()), entry.second.second, 2, false, SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT); else graphic = new StatisticIcon(ClientUI::SpecialIcon(special->Name()), SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT); graphic->SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); std::string desc = special->Description(); if (entry.second.second > 0.0f) desc += "\n" + boost::io::str(FlexibleFormat(UserString("SPECIAL_CAPACITY")) % DoubleToString(entry.second.second, 2, false)); if (entry.second.first > 0) desc += "\n" + boost::io::str(FlexibleFormat(UserString("ADDED_ON_TURN")) % entry.second.first); else desc += "\n" + UserString("ADDED_ON_INITIAL_TURN"); if (GetOptionsDB().Get<bool>("UI.dump-effects-descriptions") && !special->Effects().empty()) { desc += "\n" + Dump(special->Effects()); } graphic->SetBrowseInfoWnd(std::make_shared<IconTextBrowseWnd>( ClientUI::SpecialIcon(special->Name()), UserString(special->Name()), desc)); m_icons[entry.first] = graphic; graphic->InstallEventFilter(this); } const GG::X AVAILABLE_WIDTH = Width() - EDGE_PAD; GG::X x(EDGE_PAD); GG::Y y(EDGE_PAD); for (std::map<std::string, StatisticIcon*>::value_type& entry : m_icons) { StatisticIcon* icon = entry.second; icon->SizeMove(GG::Pt(x, y), GG::Pt(x,y) + GG::Pt(SPECIAL_ICON_WIDTH, SPECIAL_ICON_HEIGHT)); AttachChild(icon); x += SPECIAL_ICON_WIDTH + EDGE_PAD; if (x + SPECIAL_ICON_WIDTH + EDGE_PAD > AVAILABLE_WIDTH) { x = GG::X(EDGE_PAD); y += SPECIAL_ICON_HEIGHT + EDGE_PAD; } } if (m_icons.empty()) { Resize(GG::Pt(Width(), GG::Y0)); } else { Resize(GG::Pt(Width(), y + SPECIAL_ICON_HEIGHT + EDGE_PAD*2)); } }
void RegExpContext::Parse(const char *exp, bool regular, bool CaseSensitive, bool matchesWord) { invalid = false; caseSensitive = CaseSensitive; Clear(); if (matchesWord) { RegExpMatch *m = new RegExpMatch(RegExpMatch::RE_M_BWORD, caseSensitive); if (m) matches.push_back(m); else invalid = true; } if (regular) { RegExpMatch *lastMatch = nullptr; while (!invalid && *exp) { RegExpMatch *currentMatch = nullptr; switch(*exp) { case '.': currentMatch = new RegExpMatch(true); if (!currentMatch) invalid = true; exp++; break; case '*': if (lastMatch) { lastMatch->SetInterval(0, INT_MAX); lastMatch = nullptr; } else invalid = true; exp++; break; case '+': if (lastMatch) { lastMatch->SetInterval(1, INT_MAX); lastMatch = nullptr; } else invalid = true; exp++; break; case '?': if (lastMatch) { lastMatch->SetInterval(0,1); lastMatch = nullptr; } else invalid = true; exp++; break; case '[': currentMatch = new RegExpMatch(&exp, caseSensitive); invalid = !currentMatch->IsValid(); break; case '^': currentMatch = new RegExpMatch(RegExpMatch::RE_M_SOL, caseSensitive); if (!currentMatch) invalid = true; exp++; break; case '$': currentMatch = new RegExpMatch(RegExpMatch::RE_M_EOL, caseSensitive); if (!currentMatch) invalid = true; exp++; break; case '\\': switch (*++exp) { case '{': exp++; if (!lastMatch || !isdigit(*exp)) { invalid = true; } else { int n1, n2; n1 = n2 = atoi(exp); while (isdigit(*exp)) exp++; if (*exp == ',') { exp++; if (!isdigit(*exp)) invalid = true; else { n2 = atoi(exp); while (isdigit(*exp)) exp++; } } if (*exp != '\\' || exp[1] != '}' || n2 < n1) invalid = true; else { exp += 2; lastMatch->SetInterval(n1, n2); } } break; case '(': exp++; if (matchCount >= 10) invalid = true; else { matchStack[matchStackTop++] = matchCount; currentMatch = new RegExpMatch(RegExpMatch::M_START, matchCount++); if (!currentMatch) invalid = true; } break; case ')': exp++; if (!matchStackTop) { invalid = true; } else { currentMatch = new RegExpMatch(RegExpMatch::M_END, matchStack[-matchStackTop]); if (!currentMatch) invalid = true; } break; default: if (isdigit (*exp)) { currentMatch = new RegExpMatch(RegExpMatch::M_MATCH, *exp++-'0', caseSensitive); if (!currentMatch) invalid = true; } else { currentMatch = new RegExpMatch(GetSpecial(*exp++), caseSensitive); if (!currentMatch) invalid = true; } break; } break; case '|': if (!lastMatch) { invalid = true; } else { switch (*++exp) { case '\\': exp++; lastMatch->SetChar(GetSpecial(*exp++), caseSensitive); lastMatch = nullptr; break; case '[': exp++; lastMatch->SetSet(&exp, caseSensitive); if (!lastMatch->IsValid()) invalid = true; break; default: lastMatch->SetChar(*exp++, caseSensitive); break; } } lastMatch = nullptr; break; default: currentMatch = new RegExpMatch(*exp++, caseSensitive); if (!currentMatch) invalid = true; break; } if (currentMatch) matches.push_back(currentMatch); lastMatch = currentMatch; } } else { while (*exp) { RegExpMatch *m = new RegExpMatch(*exp++, caseSensitive); matches.push_back(m); } } if (!invalid && matchesWord) { RegExpMatch *m = new RegExpMatch(RegExpMatch::RE_M_EWORD, caseSensitive); if (m) matches.push_back(m); else invalid = true; } }