From 9bdc8b67a7d03c91669c3c966b3bb5de20561137 Mon Sep 17 00:00:00 2001 From: Idhrendur Date: Sun, 23 Aug 2026 17:39:01 -0700 Subject: [PATCH 1/2] Identify county capitals --- CMakeLists.txt | 4 +- .../common/landed_titles/00_landed_titles.txt | 28 +++++ .../common/landed_titles/01_more_titles.txt | 14 +++ src/ck3_world/county_capital_identifier.cpp | 116 ++++++++++++++++++ src/ck3_world/county_capital_identifier.hpp | 15 +++ .../county_capital_identifier_tests.cpp | 24 ++++ src/hello_world.cpp | 18 --- src/hello_world.hpp | 16 --- src/hello_world_test.cpp | 15 --- src/main.cpp | 10 +- 10 files changed, 204 insertions(+), 56 deletions(-) create mode 100644 data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/00_landed_titles.txt create mode 100644 data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/01_more_titles.txt create mode 100644 src/ck3_world/county_capital_identifier.cpp create mode 100644 src/ck3_world/county_capital_identifier.hpp create mode 100644 src/ck3_world/county_capital_identifier_tests.cpp delete mode 100644 src/hello_world.cpp delete mode 100644 src/hello_world.hpp delete mode 100644 src/hello_world_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 603015a..ef51ab5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,7 +203,7 @@ endif() set(MAIN_SOURCE "src/main.cpp") -set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/hello_world.cpp") +set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/ck3_world/county_capital_identifier.cpp") set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/ck3_world/titles_importer.cpp") set(GENERATOR_SOURCES ${GENERATOR_SOURCES} "src/output/ck3/output_titles.cpp") @@ -257,7 +257,7 @@ include_directories("./external/commonItems/external/googletest/googletest/inclu include_directories("./external/commonItems/external/googletest/googlemock") include_directories("./external/commonItems/external/googletest/googlemock/include") -set(TEST_SOURCES ${TEST_SOURCES} "src/hello_world_test.cpp") +set(TEST_SOURCES ${TEST_SOURCES} "src/ck3_world/county_capital_identifier_tests.cpp") set(TEST_SOURCES ${TEST_SOURCES} "src/ck3_world/titles_importer_tests.cpp") set(TEST_SOURCES ${TEST_SOURCES} "src/output/ck3/output_titles_tests.cpp") diff --git a/data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/00_landed_titles.txt b/data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/00_landed_titles.txt new file mode 100644 index 0000000..aa80c33 --- /dev/null +++ b/data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/00_landed_titles.txt @@ -0,0 +1,28 @@ +e_test_empire = { + k_test_kingdom = { + d_test_duchy = { + c_test_county = { + b_test_barony = { + province = 1 + } + b_test_barony_two = { + province = 2 + } + } + } + } +} +e_test_empire_two = { + k_test_kingdom_two = { + d_test_duchy_two = { + c_test_county_two = { + b_test_barony_two = { + province = 3 + } + b_test_barony_four = { + province = 4 + } + } + } + } +} \ No newline at end of file diff --git a/data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/01_more_titles.txt b/data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/01_more_titles.txt new file mode 100644 index 0000000..cf1ff5d --- /dev/null +++ b/data/test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified/game/common/landed_titles/01_more_titles.txt @@ -0,0 +1,14 @@ +e_test_empire_three = { + k_test_kingdom_three = { + d_test_duchy_three = { + c_test_county_three = { + b_test_barony_three = { + province = 5 + } + b_test_barony_six = { + province = 6 + } + } + } + } +} \ No newline at end of file diff --git a/src/ck3_world/county_capital_identifier.cpp b/src/ck3_world/county_capital_identifier.cpp new file mode 100644 index 0000000..505b05d --- /dev/null +++ b/src/ck3_world/county_capital_identifier.cpp @@ -0,0 +1,116 @@ +#include "src/ck3_world/county_capital_identifier.hpp" + +#include +#include +#include +#include + +#include +#include +#include + + + +namespace ck3_world +{ + +std::set IdentifyCountyCapitals(const commonItems::ModFilesystem& ck3_root) +{ + std::set county_capitals; + + commonItems::parser barony_parser; + barony_parser.registerKeyword("province", [&county_capitals](std::istream& input) { + county_capitals.emplace(commonItems::getInt(input)); + }); + barony_parser.IgnoreUnregisteredItems(); + + commonItems::parser county_parser; + bool found_a_barony = false; + county_parser.registerRegex("b_.*", [&barony_parser, &found_a_barony](const std::string&, std::istream& input) { + if (found_a_barony) + { + commonItems::ignoreItem("", input); + } + else + { + barony_parser.parseStream(input); + found_a_barony = true; + } + }); + county_parser.IgnoreUnregisteredItems(); + + commonItems::parser duchy_parser; + duchy_parser.registerRegex("c_.*", [&county_parser, &found_a_barony](const std::string&, std::istream& input) { + found_a_barony = false; + county_parser.parseStream(input); + }); + duchy_parser.IgnoreUnregisteredItems(); + + commonItems::parser kingdom_parser; + kingdom_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) { + duchy_parser.parseStream(input); + }); + kingdom_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) { + county_parser.parseStream(input); + }); + kingdom_parser.IgnoreUnregisteredItems(); + + commonItems::parser empire_parser; + empire_parser.registerRegex("k_.*", [&kingdom_parser](const std::string&, std::istream& input) { + kingdom_parser.parseStream(input); + }); + empire_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) { + duchy_parser.parseStream(input); + }); + empire_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) { + county_parser.parseStream(input); + }); + empire_parser.IgnoreUnregisteredItems(); + + commonItems::parser hegemony_parser; + hegemony_parser.registerRegex("e_.*", [&empire_parser](const std::string&, std::istream& input) { + empire_parser.parseStream(input); + }); + hegemony_parser.registerRegex("k_.*", [&kingdom_parser](const std::string&, std::istream& input) { + kingdom_parser.parseStream(input); + }); + hegemony_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) { + duchy_parser.parseStream(input); + }); + hegemony_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) { + county_parser.parseStream(input); + }); + hegemony_parser.IgnoreUnregisteredItems(); + + commonItems::parser file_parser; + file_parser.registerRegex("h_.*", [&hegemony_parser](const std::string&, std::istream& input) { + hegemony_parser.parseStream(input); + }); + file_parser.registerRegex("e_.*", [&empire_parser](const std::string&, std::istream& input) { + empire_parser.parseStream(input); + }); + file_parser.registerRegex("k_.*", [&kingdom_parser](const std::string&, std::istream& input) { + kingdom_parser.parseStream(input); + }); + file_parser.registerRegex("d_.*", [&duchy_parser](const std::string&, std::istream& input) { + duchy_parser.parseStream(input); + }); + file_parser.registerRegex("c_.*", [&county_parser](const std::string&, std::istream& input) { + county_parser.parseStream(input); + }); + file_parser.IgnoreUnregisteredItems(); + + for (const auto& file: ck3_root.GetAllFilesInFolder("game/common/landed_titles")) + { + if (file.extension() != ".txt") + { + continue; + } + file_parser.parseFile(file); + } + + Log(LogLevel::Info) << std::format("Identified {} capitals", county_capitals.size()); + return county_capitals; +} + +} // namespace ck3_world \ No newline at end of file diff --git a/src/ck3_world/county_capital_identifier.hpp b/src/ck3_world/county_capital_identifier.hpp new file mode 100644 index 0000000..1c36811 --- /dev/null +++ b/src/ck3_world/county_capital_identifier.hpp @@ -0,0 +1,15 @@ +#pragma once + + +#include + +#include + + + +namespace ck3_world +{ + +std::set IdentifyCountyCapitals(const commonItems::ModFilesystem& ck3_root); + +} // namespace ck3_world \ No newline at end of file diff --git a/src/ck3_world/county_capital_identifier_tests.cpp b/src/ck3_world/county_capital_identifier_tests.cpp new file mode 100644 index 0000000..b2c62c4 --- /dev/null +++ b/src/ck3_world/county_capital_identifier_tests.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +#include + +#include "src/ck3_world/county_capital_identifier.hpp" + + + +namespace ck3_world +{ + +TEST(Ck3worldCountyCapitalIdentifierTests, CountyCapitalsCanBeIdentified) +{ + const commonItems::ModFilesystem mod_filesystem( + "./test_files/Ck3worldCountyCapitalIdentifierTests/CountyCapitalsCanBeIdentified", + {}); + const std::set county_capitals = IdentifyCountyCapitals(mod_filesystem); + + EXPECT_THAT(county_capitals, testing::ElementsAre(1, 3, 5)); +} + +} // namespace ck3_world \ No newline at end of file diff --git a/src/hello_world.cpp b/src/hello_world.cpp deleted file mode 100644 index 8b58f8d..0000000 --- a/src/hello_world.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "hello_world.hpp" - -#pragma warning(push) -#pragma warning(disable : 4702) -#include -#pragma warning(pop) - - - -namespace scenario_generator -{ - -void HelloWorld() -{ - fmt::println("Hello world!"); -} - -} // namespace scenario_generator \ No newline at end of file diff --git a/src/hello_world.hpp b/src/hello_world.hpp deleted file mode 100644 index 3ff47c1..0000000 --- a/src/hello_world.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SRC_HELLO_WORLD_HPP -#define SRC_HELLO_WORLD_HPP - - - -namespace scenario_generator -{ - -void HelloWorld(); - - -} // namespace scenario_generator - - - -#endif // SRC_HELLO_WORLD_HPP \ No newline at end of file diff --git a/src/hello_world_test.cpp b/src/hello_world_test.cpp deleted file mode 100644 index 2fda1c3..0000000 --- a/src/hello_world_test.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - - - -namespace scenario_generator -{ - -// NOLINTBEGIN(cppcoreguidelines-owning-memory) -TEST(HelloWorldTest, Success) -{ - SUCCEED(); -} -// NOLINTEND(cppcoreguidelines-owning-memory) - -} // namespace scenario_generator \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 954f6ff..0ae76ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,12 +3,13 @@ #include #include +#include #include #include -#include "ck3_world/titles_importer.hpp" -#include "hello_world.hpp" -#include "output/ck3/output_titles.hpp" +#include "src/ck3_world/county_capital_identifier.hpp" +#include "src/ck3_world/titles_importer.hpp" +#include "src/output/ck3/output_titles.hpp" @@ -20,9 +21,8 @@ int main() "C:/Program Files (x86)/Steam/steamapps/common/Crusader Kings III", {}); const std::map> titles = ck3_world::ImportTitles(mod_filesystem); + const std::set county_capitals = ck3_world::IdentifyCountyCapitals(mod_filesystem); output::OutputCk3Titles("test_mod", titles); - - scenario_generator::HelloWorld(); } catch (std::exception& e) { From 461c1fb616eb7f2b9bb7ada9f5092f001124f067 Mon Sep 17 00:00:00 2001 From: Idhrendur Date: Sun, 23 Aug 2026 17:45:15 -0700 Subject: [PATCH 2/2] Codacy finding --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0ae76ad..c1fc920 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ int main() "C:/Program Files (x86)/Steam/steamapps/common/Crusader Kings III", {}); const std::map> titles = ck3_world::ImportTitles(mod_filesystem); - const std::set county_capitals = ck3_world::IdentifyCountyCapitals(mod_filesystem); + [[maybe_unused]] const std::set county_capitals = ck3_world::IdentifyCountyCapitals(mod_filesystem); output::OutputCk3Titles("test_mod", titles); } catch (std::exception& e)