From e09daaa63be94463850d8328cc8ce39cd7c660e9 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 13 Oct 2024 16:15:08 +0800 Subject: [PATCH] add `Research` field for Stats object --- src/wzapi.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/wzapi.cpp b/src/wzapi.cpp index e0cc2512d64..16f8b8c67ae 100644 --- a/src/wzapi.cpp +++ b/src/wzapi.cpp @@ -4522,6 +4522,35 @@ nlohmann::json wzapi::constructStatsObject() structbase[psStats->name.toUtf8()] = std::move(strct); } stats["Building"] = std::move(structbase); + + //== * ```Research``` Researches + nlohmann::json researchbase = nlohmann::json::object(); + for (int j = 0; j < asResearch.size(); j++) + { + RESEARCH *psStats = &asResearch[j]; + nlohmann::json res = nlohmann::json::object(); + res["Id"] = psStats->id; + nlohmann::json reqs = nlohmann::json::array(); + for (int k = 0; k < psStats->pPRList.size(); k++) + { + reqs.push_back(asResearch[psStats->pPRList[k]].id); + } + res["Requires"] = reqs; + nlohmann::json resstrcts = nlohmann::json::array(); + for (int k = 0; k < psStats->pStructureResults.size(); k++) + { + resstrcts.push_back(asStructureStats[psStats->pStructureResults[k]].id); + } + res["ResultStructures"] = resstrcts; + nlohmann::json rescomps = nlohmann::json::array(); + for (int k = 0; k < psStats->componentResults.size(); k++) + { + rescomps.push_back(psStats->componentResults[k]->id); + } + res["ResultComponents"] = rescomps; + researchbase[psStats->name.toUtf8()] = std::move(res); + } + stats["Research"] = std::move(researchbase); } return stats; }