Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create combinations #610

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/hoi4_world/roles/stories_creator.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
#include "src/hoi4_world/roles/stories_creator.h"

#include <ranges>

#include "external/fmt/include/fmt/format.h"
#include "src/hoi4_world/roles/roles_importer.h"



void hoi4::CreateStories()
namespace
{

using Tag = std::string;
using CombinationName = std::string;


std::vector<std::pair<Tag, CombinationName>> MakeCombinations(const std::map<std::string, hoi4::Role>& roles,
const std::map<std::string, hoi4::Country>& countries)
{
std::vector<std::pair<Tag, CombinationName>> combinations;

for (const auto& [role_name, role]: roles)
{
// scan for 'tag=TAG' constructs
std::regex tag_match_regex(R"([\s\S]+tag=(.+)[\s\S]+)");
std::smatch match;
if (!std::regex_match(role.GetRequirements(), match, tag_match_regex))
{
continue;
}
std::string required_tag = match[1];

for (const std::string& country_tag: countries | std::views::keys)
Idhrendur marked this conversation as resolved.
Show resolved Hide resolved
{
if (required_tag == country_tag)
{
combinations.emplace_back(country_tag, role_name);
}
}
}

return combinations;
}

} // namespace



void hoi4::CreateStories(const std::map<std::string, hoi4::Country>& countries)
{
Log(LogLevel::Info) << "Writing stories";
std::map<std::string, Role> roles = ImportRoles();

const std::map<std::string, Role> roles = ImportRoles();
Log(LogLevel::Info) << fmt::format("\tImported {} roles.", roles.size());

const std::vector<std::pair<Tag, CombinationName>> role_combinations = MakeCombinations(roles, countries);
Log(LogLevel::Info) << fmt::format("\tCreated {} role combinations.", role_combinations.size());
}
8 changes: 7 additions & 1 deletion src/hoi4_world/roles/stories_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
#define SRC_HOI4WORLD_ROLES_STORIESCREATOR_H


#include <map>
#include <string>

#include "src/hoi4_world/countries/hoi4_country.h"



namespace hoi4
{

void CreateStories();
void CreateStories(const std::map<std::string, hoi4::Country>& countries);

} // namespace hoi4

Expand Down
2 changes: 1 addition & 1 deletion src/hoi4_world/world/hoi4_world_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ hoi4::World hoi4::ConvertWorld(const commonItems::ModFilesystem& hoi4_mod_filesy
hoi4::Railways railways = railways_future.get();
hoi4::Buildings buildings = buildings_future.get();

CreateStories();
CreateStories(countries);

return hoi4::World(hoi4::WorldOptions{.countries = countries,
.great_powers = great_powers,
Expand Down