From 7eaf7e9a0ec958b473ed3793c0d9e7032d14972f Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Tue, 30 Apr 2024 21:24:00 -0400 Subject: [PATCH] fixed some sorting logic issues, enriched side category definition in INI file . --- MissionEditor/ViewObjects.cpp | 53 ++++++++++++++----- MissionEditor/data/FinalAlert2/FAData.ini | 14 +++++ MissionEditor/data/FinalAlert2/FALanguage.ini | 8 +-- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/MissionEditor/ViewObjects.cpp b/MissionEditor/ViewObjects.cpp index d50e96d..940de86 100644 --- a/MissionEditor/ViewObjects.cpp +++ b/MissionEditor/ViewObjects.cpp @@ -575,6 +575,9 @@ TreeViewBuilder::mapSideNodeInfo TreeViewBuilder::collectCategoryInfo() mapSideNodeInfo ret; auto toType = [](const CString& str) -> TechnoTypeMask { + if (str.IsEmpty()) { + return TechnoTypeMask(-1); + } return TechnoTypeMask(atoi(str)); }; @@ -584,15 +587,18 @@ TreeViewBuilder::mapSideNodeInfo TreeViewBuilder::collectCategoryInfo() auto const otherCategoryName = GetLanguageStringACP("Other"); for (auto& [seq, def] : g_data["Sides"]) { + auto sideName = def; auto const commaPos = def.Find(','); //now parse real type if (commaPos >= 0) { + sideName = def.Mid(0, commaPos); typeStr = def.Mid(commaPos + 1); } if (typeStr == otherCategoryName) { continue; } - auto&& info = CatetoryDefinition{ def.Mid(0, commaPos), toType(typeStr) }; + + auto&& info = CatetoryDefinition{ TranslateStringACP(sideName), toType(typeStr) }; ret.insert({ count++, info }); } @@ -640,27 +646,27 @@ const CString& GuessSideHelper::GetSideName(const CString& regName, TreeViewTech return builder.sideInfo.at(-1).CategoryName; } -int GuessSideHelper::GuessSide(const CString& pRegName, TreeViewTechnoType nType, const CIniFile& inWhichIni) +int GuessSideHelper::GuessSide(const CString& regName, TreeViewTechnoType type, const CIniFile& inWhichIni) { - auto const& knownIterator = KnownItem.find(pRegName.operator LPCSTR()); + auto const& knownIterator = KnownItem.find(regName.operator LPCSTR()); if (knownIterator != KnownItem.end()) return knownIterator->second; int result = -1; - switch (nType) { + switch (type) { case TreeViewTechnoType::Set_None: default: break; case TreeViewTechnoType::Building: - result = guessBuildingSide(pRegName, inWhichIni); + result = guessBuildingSide(regName, inWhichIni); break; case TreeViewTechnoType::Infantry: case TreeViewTechnoType::Vehicle: case TreeViewTechnoType::Aircraft: - result = guessGenericSide(pRegName); + result = guessGenericSide(regName); break; } - KnownItem.insert_or_assign(pRegName.operator LPCSTR(), result); + KnownItem.insert_or_assign(std::string(regName), result); return result; } @@ -668,10 +674,10 @@ int GuessSideHelper::guessBuildingSide(const CString& typeId, const CIniFile& in { int planning; planning = inWhichIni.GetInteger(typeId, "AIBasePlanningSide", -1); - if (planning >= rules.GetSection("Sides").Size()) { - return -1; - } if (planning >= 0) { + if (planning >= rules.GetSection("Sides").Size()) { + planning = -1; + } return planning; } auto const& cons = utilities::split_string(rules.GetString("AI", "BuildConst")); @@ -687,13 +693,14 @@ int GuessSideHelper::guessBuildingSide(const CString& typeId, const CIniFile& in return guessGenericSide(typeId); } -int GuessSideHelper::guessGenericSide(const CString& pRegName) +int GuessSideHelper::guessGenericSide(const CString& regName) { auto const& mmh = IniMegaFile::GetRules(); - auto const& owners = utilities::split_string(mmh.GetString(pRegName, "Owner")); + auto const& owners = utilities::split_string(mmh.GetString(regName, "Owner")); if (owners.size() <= 0) { return -1; } + auto const& itr = builder.m_owners.find((std::string)owners[0]); if (itr == builder.m_owners.end()) { return -1; @@ -706,6 +713,8 @@ void TreeViewBuilder::updateBuildingTypes(HTREEITEM parentNode) { GuessSideHelper sideHelper(*this); auto baseOffset = valadded * 2; + structhouses.Preallocate(sideInfo, TreeViewTechnoType::Building); + auto const& bldTypeSec = rules["BuildingTypes"]; for (auto i = 0; i < bldTypeSec.Size(); i++) { @@ -771,6 +780,8 @@ void TreeViewBuilder::updateUnitTypes(HTREEITEM parentNode, const char* typeList GuessSideHelper sideHelper(*this); auto baseOffset = valadded * multiple; + structhouses.Preallocate(sideInfo, technoType); + for (auto i = 0; i < rules[typeListId].Size(); i++) { auto const& typeId = rules[typeListId].Nth(i).second; if (typeId.IsEmpty()) { @@ -1256,13 +1267,27 @@ void CViewObjects::HandleBrushSize(int iTile) } +void TreeViewCategoryHandler::Preallocate(const TreeViewBuilder::mapSideNodeInfo& sideInfo, TreeViewTechnoType type) +{ + for (auto const& [idx, def] : sideInfo) { + if (idx < 0) { + continue; + } + if (!(def.CategoryMask & type)) { + continue; + } + GetOrAdd(def.CategoryName); + } +} + HTREEITEM TreeViewCategoryHandler::GetOrAdd(const CString& name) { - auto const it = structhouses.find((std::string)name); + auto&& nameStd = std::string(name); + auto const it = structhouses.find(nameStd); if (it != structhouses.end()) { return it->second; } auto newItem = tree.InsertItem(TVIF_PARAM | TVIF_TEXT, GetLanguageStringACP(name), 0, 0, 0, 0, -1, parentNode, TVI_LAST); - structhouses.insert({ (std::string)name, newItem }); + structhouses.insert({ std::move(nameStd), newItem }); return newItem; } \ No newline at end of file diff --git a/MissionEditor/data/FinalAlert2/FAData.ini b/MissionEditor/data/FinalAlert2/FAData.ini index 16d63d0..57d796b 100644 --- a/MissionEditor/data/FinalAlert2/FAData.ini +++ b/MissionEditor/data/FinalAlert2/FAData.ini @@ -11,6 +11,20 @@ AllowTunnels=yes AllowUnidirectionalTunnels=yes ;ShowBuildingsWithToTile=no +[Sides] +0=Allied +1=Soviet +2=Yuri +3=安塔列星 +4=科技功能建筑,1 +5=地标建筑类,1 +6=大城市建筑,1 +7=中小城市建筑,1 +8=村庄建筑,1 +9=工业建筑,1 +10=小型装饰摆件,1 +11=中立特殊建筑,1 + [ForceUnitPalettePrefix] 0=TIBTRE diff --git a/MissionEditor/data/FinalAlert2/FALanguage.ini b/MissionEditor/data/FinalAlert2/FALanguage.ini index b0d2028..3081562 100644 --- a/MissionEditor/data/FinalAlert2/FALanguage.ini +++ b/MissionEditor/data/FinalAlert2/FALanguage.ini @@ -1061,10 +1061,10 @@ No=否 NeedsYR=要用此地图进行游戏,需要尤里的复仇。 ; name replacements -;N_AMRADR=American Air Force Command HQ -;N_SENGINEER=Soviet Engineer -;N_ENGINEER=Allied Engineer -;N_YENGINEER=Yuri Engineer +N_AMRADR=美国空指部 +N_SENGINEER=苏军工程师 +N_ENGINEER=盟军工程师 +N_YENGINEER=尤里工程师 ;N_SCHD=Deployed Siege Helicopter ;N_GACSPH=Chronosphere ;N_CALOND04=London Parliament