diff --git a/src/MeoAssistant/Assistant.cpp b/src/MeoAssistant/Assistant.cpp index bb99b5e71b..c5f3852ca6 100644 --- a/src/MeoAssistant/Assistant.cpp +++ b/src/MeoAssistant/Assistant.cpp @@ -493,12 +493,12 @@ void Assistant::working_proc() std::unique_lock lock(m_mutex); if (!m_thread_idle && !m_tasks_queue.empty()) { - auto task_ptr = m_tasks_queue.front(); + const auto& task_ptr = m_tasks_queue.front(); m_tasks_queue.pop(); std::string cur_taskchain = task_ptr->get_task_chain(); std::string next_taskchain = m_tasks_queue.empty() ? std::string() : m_tasks_queue.front()->get_task_chain(); - json::value callback_json = json::object{ + json::value callback_json = json::object { { "taskchain", cur_taskchain }, { "pre_taskchain", pre_taskchain } }; diff --git a/src/MeoAssistant/AsstUtils.hpp b/src/MeoAssistant/AsstUtils.hpp index b1b6a65157..64a5079574 100644 --- a/src/MeoAssistant/AsstUtils.hpp +++ b/src/MeoAssistant/AsstUtils.hpp @@ -88,10 +88,14 @@ namespace asst memset(str, 0, len + 1); WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, nullptr, nullptr); std::string strTemp = str; - if (wstr) + if (wstr) { delete[] wstr; - if (str) + wstr = nullptr; + } + if (str) { delete[] str; + str = nullptr; + } return strTemp; #else // Don't fucking use gbk in linux! return gbk_str; @@ -104,17 +108,21 @@ namespace asst const char* src_str = utf8_str.c_str(); int len = MultiByteToWideChar(CP_UTF8, 0, src_str, -1, nullptr, 0); wchar_t* wszGBK = new wchar_t[len + 1]; - memset(wszGBK, 0, len * 2 + 2); + memset(wszGBK, 0, len * 2LLU + 2LLU); MultiByteToWideChar(CP_UTF8, 0, src_str, -1, wszGBK, len); len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, nullptr, 0, nullptr, nullptr); char* szGBK = new char[len + 1]; - memset(szGBK, 0, len + 1); + memset(szGBK, 0, len + 1LLU); WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, nullptr, nullptr); std::string strTemp(szGBK); - if (wszGBK) + if (wszGBK) { delete[] wszGBK; - if (szGBK) + wszGBK = nullptr; + } + if (szGBK) { delete[] szGBK; + szGBK = nullptr; + } return strTemp; #else // Don't fucking use gbk in linux! return utf8_str; diff --git a/src/MeoAssistant/BattleImageAnalyzer.cpp b/src/MeoAssistant/BattleImageAnalyzer.cpp index 8f244cef4c..90fc1b6c6e 100644 --- a/src/MeoAssistant/BattleImageAnalyzer.cpp +++ b/src/MeoAssistant/BattleImageAnalyzer.cpp @@ -294,7 +294,7 @@ bool asst::BattleImageAnalyzer::hp_analyze() range_upper = cv::Scalar(h_u, s_u, v_u); std::unordered_map num_hashs; for (auto&& num : NumName) { - auto hashs_vec = std::dynamic_pointer_cast( + const auto &hashs_vec = std::dynamic_pointer_cast( Task.get("BattleHp" + num))->hashs; for (size_t i = 0; i != hashs_vec.size(); ++i) { num_hashs.emplace(num + "_" + std::to_string(i), hashs_vec.at(i)); diff --git a/src/MeoAssistant/HashImageAnalyzer.cpp b/src/MeoAssistant/HashImageAnalyzer.cpp index c61aee7b4c..ed6318df5c 100644 --- a/src/MeoAssistant/HashImageAnalyzer.cpp +++ b/src/MeoAssistant/HashImageAnalyzer.cpp @@ -1,4 +1,4 @@ -#include "HashImageAnalyzer.h" +#include "HashImageAnalyzer.h" #include "AsstUtils.hpp" #include "Logger.hpp" @@ -163,7 +163,7 @@ int asst::HashImageAnalyzer::hamming(std::string hash1, std::string hash2) unsigned long long x = strtoull(hash1.substr(i, 16).c_str(), nullptr, 16) ^ strtoull(hash2.substr(i, 16).c_str(), nullptr, 16); while (x) { - dist++; + ++dist; x = x & (x - 1); } } diff --git a/src/MeoAssistant/InfrastControlTask.cpp b/src/MeoAssistant/InfrastControlTask.cpp index db2540389f..09d2fa6c1b 100644 --- a/src/MeoAssistant/InfrastControlTask.cpp +++ b/src/MeoAssistant/InfrastControlTask.cpp @@ -26,8 +26,7 @@ bool asst::InfrastControlTask::_run() swipe_to_the_left_of_operlist(); optimal_calc(); - bool ret = opers_choose(); - if (!ret) { + if (!opers_choose()) { m_all_available_opers.clear(); swipe_to_the_left_of_operlist(); continue; diff --git a/src/MeoAssistant/InfrastOfficeTask.cpp b/src/MeoAssistant/InfrastOfficeTask.cpp index 441f405b52..5b6fef9bf0 100644 --- a/src/MeoAssistant/InfrastOfficeTask.cpp +++ b/src/MeoAssistant/InfrastOfficeTask.cpp @@ -51,8 +51,7 @@ bool asst::InfrastOfficeTask::_run() } if (need_shift) { optimal_calc(); - bool ret = opers_choose(); - if (!ret) { + if (!opers_choose()) { m_all_available_opers.clear(); swipe_to_the_left_of_operlist(); continue; diff --git a/src/MeoAssistant/InfrastPowerTask.cpp b/src/MeoAssistant/InfrastPowerTask.cpp index cd1bd9ff50..fbcc9ba619 100644 --- a/src/MeoAssistant/InfrastPowerTask.cpp +++ b/src/MeoAssistant/InfrastPowerTask.cpp @@ -62,8 +62,7 @@ bool asst::InfrastPowerTask::_run() } if (need_shift) { optimal_calc(); - bool ret = opers_choose(); - if (!ret) { + if (!opers_choose()) { m_all_available_opers.clear(); swipe_to_the_left_of_operlist(); continue; diff --git a/src/MeoAssistant/InfrastProductionTask.cpp b/src/MeoAssistant/InfrastProductionTask.cpp index 951b4c9518..3b9813d3c9 100644 --- a/src/MeoAssistant/InfrastProductionTask.cpp +++ b/src/MeoAssistant/InfrastProductionTask.cpp @@ -37,10 +37,7 @@ void asst::InfrastProductionTask::set_product(std::string product_name) noexcept bool asst::InfrastProductionTask::shift_facility_list() { LogTraceFunction; - if (!facility_list_detect()) { - return false; - } - if (need_exit()) { + if (!facility_list_detect() || need_exit()) { return false; } const auto tab_task_ptr = Task.get("InfrastFacilityListTab" + facility_name()); @@ -124,8 +121,7 @@ bool asst::InfrastProductionTask::shift_facility_list() opers_detect(); } optimal_calc(); - bool ret = opers_choose(); - if (!ret) { + if (!opers_choose()) { m_all_available_opers.clear(); swipe_to_the_left_of_operlist(2); continue; @@ -254,7 +250,7 @@ bool asst::InfrastProductionTask::optimal_calc() std::unordered_map skills_num; for (int i = 0; i != m_all_available_opers.size(); ++i) { - auto comb = all_avaliable_combs.at(i); + const auto& comb = all_avaliable_combs.at(i); bool out_of_num = false; for (auto&& skill : comb.skills) { @@ -451,7 +447,6 @@ bool asst::InfrastProductionTask::opers_choose() LogTraceFunction; bool has_error = false; - int count = 0; auto& facility_info = Resrc.infrast().get_facility_info(facility_name()); int cur_max_num_of_opers = facility_info.max_num_of_opers - m_cur_num_of_lokced_opers; @@ -495,7 +490,7 @@ bool asst::InfrastProductionTask::opers_choose() }); cur_all_opers.erase(remove_iter, cur_all_opers.end()); Log.trace("after mood filter, opers size:", cur_all_opers.size()); - + int count = 0; for (auto opt_iter = m_optimal_combs.begin(); opt_iter != m_optimal_combs.end();) { Log.trace("to find", opt_iter->skills.begin()->names.front()); auto find_iter = std::find_if( diff --git a/src/MeoAssistant/OcrImageAnalyzer.cpp b/src/MeoAssistant/OcrImageAnalyzer.cpp index cf151c2dcc..8164b8eacd 100644 --- a/src/MeoAssistant/OcrImageAnalyzer.cpp +++ b/src/MeoAssistant/OcrImageAnalyzer.cpp @@ -48,7 +48,7 @@ bool asst::OcrImageAnalyzer::analyze() preds_vec.emplace_back(m_pred); TextRectProc all_pred = [&](TextRect& tr) -> bool { - for (auto pred : preds_vec) { + for (const auto &pred : preds_vec) { if (pred && !pred(tr)) { return false; } diff --git a/src/MeoAssistant/RecruitTask.cpp b/src/MeoAssistant/RecruitTask.cpp index 3feb9bc288..50ea4df009 100644 --- a/src/MeoAssistant/RecruitTask.cpp +++ b/src/MeoAssistant/RecruitTask.cpp @@ -44,7 +44,7 @@ bool RecruitTask::_run() } json::value info = basic_info(); info["what"] = "RecruitTagsDetected"; - info["details"] = json::object{ + info["details"] = json::object { { "tags", json::array(all_tags_json_vector) } }; callback(AsstMsg::SubTaskExtraInfo, info); @@ -56,7 +56,7 @@ bool RecruitTask::_run() auto special_iter = std::find_first_of(SpecialTags.cbegin(), SpecialTags.cend(), all_tags_name.cbegin(), all_tags_name.cend()); if (special_iter != SpecialTags.cend()) { info["what"] = "RecruitSpecialTag"; - info["details"] = json::object{ + info["details"] = json::object { { "tag", *special_iter } }; callback(AsstMsg::SubTaskExtraInfo, info); diff --git a/src/MeoAssistant/RoguelikeFormationImageAnalyzer.cpp b/src/MeoAssistant/RoguelikeFormationImageAnalyzer.cpp index 9dc5d0dc6b..478b1f2bc9 100644 --- a/src/MeoAssistant/RoguelikeFormationImageAnalyzer.cpp +++ b/src/MeoAssistant/RoguelikeFormationImageAnalyzer.cpp @@ -13,7 +13,7 @@ bool asst::RoguelikeFormationImageAnalyzer::analyze() return false; } opers_analyzer.sort_result(); - const auto all_opers = opers_analyzer.get_result(); + const auto& all_opers = opers_analyzer.get_result(); for (const MatchRect& oper_mr : all_opers) { Oper oper; oper.rect = oper_mr.rect; diff --git a/src/MeoAssistant/TemplResource.cpp b/src/MeoAssistant/TemplResource.cpp index 4566327ada..3c22eaa893 100644 --- a/src/MeoAssistant/TemplResource.cpp +++ b/src/MeoAssistant/TemplResource.cpp @@ -40,8 +40,7 @@ const cv::Mat asst::TemplResource::get_templ(const std::string& key) const noexc return iter->second; } else { - const static cv::Mat empty; - return empty; + return cv::Mat(); } }