Skip to content

Commit

Permalink
Hand out basic division templates (#306)
Browse files Browse the repository at this point in the history
* Hand out basic division templates.

* Formatting
  • Loading branch information
Idhrendur committed Mar 30, 2023
1 parent 9f1b57b commit 19459f0
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 9 deletions.
190 changes: 190 additions & 0 deletions data/configurables/division_templates.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
division_template = {
name = "Armored Division"
regiments = {
light_armor = { x = 0 y = 0 }
light_armor = { x = 0 y = 1 }
light_armor = { x = 0 y = 2 }

light_armor = { x = 1 y = 0 }
light_armor = { x = 1 y = 1 }
light_armor = { x = 1 y = 2 }

motorized = { x = 2 y = 0 }
motorized = { x = 2 y = 1 }
motorized = { x = 2 y = 2 }
}
support = {
artillery = { x = 0 y = 0 }
}
priority = 2
}

division_template = {
name = "Mechanized Division"
regiments = {
light_armor = { x = 0 y = 0 }
light_armor = { x = 0 y = 1 }
light_armor = { x = 0 y = 2 }

motorized = { x = 1 y = 0 }
motorized = { x = 1 y = 1 }
motorized = { x = 1 y = 2 }

motorized = { x = 2 y = 0 }
motorized = { x = 2 y = 1 }
motorized = { x = 2 y = 2 }
}
support = {
artillery = { x = 0 y = 0 }
}
priority = 2
}

division_template = {
name = "Motorized Division"
regiments = {
motorized = { x = 0 y = 0 }
motorized = { x = 0 y = 1 }
motorized = { x = 0 y = 2 }

motorized = { x = 1 y = 0 }
motorized = { x = 1 y = 1 }
motorized = { x = 1 y = 2 }

motorized = { x = 2 y = 0 }
motorized = { x = 2 y = 1 }
motorized = { x = 2 y = 2 }
}
support = {
artillery = { x = 0 y = 0 }
}
priority = 2
}

division_template = {
name = "Assault Division"
regiments = {
infantry = { x = 0 y = 0 }
infantry = { x = 0 y = 1 }
infantry = { x = 0 y = 2 }

infantry = { x = 1 y = 0 }
infantry = { x = 1 y = 1 }
infantry = { x = 1 y = 2 }

infantry = { x = 2 y = 0 }
infantry = { x = 2 y = 1 }
infantry = { x = 2 y = 2 }

artillery_brigade = { x = 3 y = 0 }
artillery_brigade = { x = 3 y = 1 }
artillery_brigade = { x = 3 y = 2 }

light_armor = { x = 4 y = 0 }
}
priority = 2
}

division_template = {
name = "Assault Brigade"
regiments = {
infantry = { x = 0 y = 0 }
infantry = { x = 0 y = 1 }
infantry = { x = 0 y = 2 }

artillery_brigade = { x = 1 y = 0 }

light_armor = { x = 2 y = 0 }
}
priority = 2
}

division_template = {
name = "Infantry Division"
regiments = {
infantry = { x = 0 y = 0 }
infantry = { x = 0 y = 1 }
infantry = { x = 0 y = 2 }

infantry = { x = 1 y = 0 }
infantry = { x = 1 y = 1 }
infantry = { x = 1 y = 2 }

infantry = { x = 2 y = 0 }
infantry = { x = 2 y = 1 }
infantry = { x = 2 y = 2 }

artillery_brigade = { x = 3 y = 0 }
artillery_brigade = { x = 3 y = 1 }
artillery_brigade = { x = 3 y = 2 }
}
priority = 1
}

division_template = {
name = "Infantry Brigade"
regiments = {
infantry = { x = 0 y = 0 }
infantry = { x = 0 y = 1 }
infantry = { x = 0 y = 2 }

artillery_brigade = { x = 1 y = 0 }
}
priority = 1
}

division_template = {
name = "Light Infantry Division"
regiments = {
infantry = { x = 0 y = 0 }
infantry = { x = 0 y = 1 }
infantry = { x = 0 y = 2 }

infantry = { x = 1 y = 0 }
infantry = { x = 1 y = 1 }
infantry = { x = 1 y = 2 }

infantry = { x = 2 y = 0 }
infantry = { x = 2 y = 1 }
infantry = { x = 2 y = 2 }
}
priority = 0
}

division_template = {
name = "Light Infantry Brigade"
regiments = {
infantry = { x = 0 y = 0 }
infantry = { x = 0 y = 1 }
infantry = { x = 0 y = 2 }
}
priority = 0
}

division_template = {
name = "Cavalry Division"
regiments = {
cavalry = { x = 0 y = 0 }
cavalry = { x = 0 y = 1 }
cavalry = { x = 0 y = 2 }

cavalry = { x = 1 y = 0 }
cavalry = { x = 1 y = 1 }
cavalry = { x = 1 y = 2 }

cavalry = { x = 2 y = 0 }
cavalry = { x = 2 y = 1 }
cavalry = { x = 2 y = 2 }
}
priority = 2
}

division_template = {
name = "Cavalry Brigade"
regiments = {
cavalry = { x = 0 y = 0 }
cavalry = { x = 0 y = 1 }
cavalry = { x = 0 y = 2 }
}
priority = 2
}
1 change: 1 addition & 0 deletions data/test_files/configurables/division_templates.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contents don't matter for tests
3 changes: 3 additions & 0 deletions src/out_hoi4/countries/out_countries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fstream>
#include <ranges>

#include "external/commonItems/OSCompatibilityLayer.h"
#include "external/fmt/include/fmt/format.h"
#include "src/out_hoi4/countries/out_country.h"

Expand All @@ -22,6 +23,8 @@ void out::OutputCountries(std::string_view output_name, const std::map<std::stri
OutputCommonCountryTag(country, tags_file);
OutputCommonCountriesFile(output_name, country);
OutputCountryHistory(output_name, country);
commonItems::TryCopyFile("configurables/division_templates.txt",
fmt::format("output/{}/history/units/{}_1936.txt", output_name, country.GetTag()));
}

tags_file.close();
Expand Down
22 changes: 22 additions & 0 deletions src/out_hoi4/countries/out_countries_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ TEST(Outhoi4CountriesOutcountriesTests, CountriesFilesAreCreated)
commonItems::TryCreateFolder("output/CountriesFilesAreCreated/common/country_tags");
commonItems::TryCreateFolder("output/CountriesFilesAreCreated/history");
commonItems::TryCreateFolder("output/CountriesFilesAreCreated/history/countries");
commonItems::TryCreateFolder("output/CountriesFilesAreCreated/history/units");

OutputCountries("CountriesFilesAreCreated",
{{"TAG", hoi4::Country({.tag = "TAG"})}, {"TWO", hoi4::Country({.tag = "TWO"})}});
Expand Down Expand Up @@ -56,6 +57,7 @@ TEST(Outhoi4CountriesOutcountriesTests, TagsFileIsCreated)
commonItems::TryCreateFolder("output/TagsFileIsCreated/common/country_tags");
commonItems::TryCreateFolder("output/TagsFileIsCreated/history");
commonItems::TryCreateFolder("output/TagsFileIsCreated/history/countries");
commonItems::TryCreateFolder("output/TagsFileIsCreated/history/units");

OutputCountries("TagsFileIsCreated",
{{"TAG", hoi4::Country({.tag = "TAG"})}, {"TWO", hoi4::Country({.tag = "TWO"})}});
Expand Down Expand Up @@ -90,6 +92,7 @@ TEST(Outhoi4CountriesOutcountriesTests, CountryHistoryFilesAreCreated)
commonItems::TryCreateFolder("output/CountryHistoryFilesAreCreated/common/country_tags");
commonItems::TryCreateFolder("output/CountryHistoryFilesAreCreated/history");
commonItems::TryCreateFolder("output/CountryHistoryFilesAreCreated/history/countries");
commonItems::TryCreateFolder("output/CountryHistoryFilesAreCreated/history/units");

OutputCountries("CountryHistoryFilesAreCreated",
{{"TAG", hoi4::Country({.tag = "TAG"})}, {"TWO", hoi4::Country({.tag = "TWO"})}});
Expand All @@ -113,4 +116,23 @@ TEST(Outhoi4CountriesOutcountriesTests, CountryHistoryFilesAreCreated)
country_file_two.close();
}


TEST(Outhoi4CountriesOutcountriesTests, DivisionTemplatesAreCopied)
{
commonItems::TryCreateFolder("output");
commonItems::TryCreateFolder("output/DivisionTemplatesAreCopied");
commonItems::TryCreateFolder("output/DivisionTemplatesAreCopied/common");
commonItems::TryCreateFolder("output/DivisionTemplatesAreCopied/common/countries");
commonItems::TryCreateFolder("output/DivisionTemplatesAreCopied/common/country_tags");
commonItems::TryCreateFolder("output/DivisionTemplatesAreCopied/history");
commonItems::TryCreateFolder("output/DivisionTemplatesAreCopied/history/countries");
commonItems::TryCreateFolder("output/DivisionTemplatesAreCopied/history/units");

OutputCountries("DivisionTemplatesAreCopied",
{{"TAG", hoi4::Country({.tag = "TAG"})}, {"TWO", hoi4::Country({.tag = "TWO"})}});

EXPECT_TRUE(commonItems::DoesFileExist("output/DivisionTemplatesAreCopied/history/units/TAG_1936.txt"));
EXPECT_TRUE(commonItems::DoesFileExist("output/DivisionTemplatesAreCopied/history/units/TWO_1936.txt"));
}

} // namespace out
4 changes: 3 additions & 1 deletion src/out_hoi4/countries/out_country.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void out::OutputCountryHistory(std::string_view output_name, const hoi4::Country
{
country_history << fmt::format("capital = {}\n", *capital);
}

country_history << "\n";
country_history << fmt::format("oob = \"{}_1936\"", country.GetTag());
country_history << "\n";
country_history << "set_research_slots = 3\n";
country_history << "set_convoys = 0\n";
country_history << "\n";
Expand Down
2 changes: 2 additions & 0 deletions src/out_hoi4/countries/out_country_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ TEST(Outhoi4CountriesOutcountryTests, DefaultsAreSetInCountryHistoryFile)
country_file.close();

std::stringstream expected_one;
expected_one << "\n";
expected_one << "oob = \"TAG_1936\"\n";
expected_one << "set_research_slots = 3\n";
expected_one << "set_convoys = 0\n";
expected_one << "\n";
Expand Down
4 changes: 4 additions & 0 deletions src/out_hoi4/out_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ void CreateOutputFolder(const std::string_view output_name)
{
throw std::runtime_error(fmt::format("Could not create output/{}/history/states", output_name));
}
if (!commonItems::TryCreateFolder(fmt::format("output/{}/history/units", output_name)))
{
throw std::runtime_error(fmt::format("Could not create output/{}/history/units", output_name));
}
if (!commonItems::TryCreateFolder(fmt::format("output/{}/map", output_name)))
{
throw std::runtime_error(fmt::format("Could not create output/{}/map", output_name));
Expand Down
28 changes: 20 additions & 8 deletions src/out_hoi4/world/out_world_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void CreateTestFolders(std::string_view test_name)
commonItems::TryCreateFolder(fmt::format("output/{}/history", test_name));
commonItems::TryCreateFolder(fmt::format("output/{}/history/countries", test_name));
commonItems::TryCreateFolder(fmt::format("output/{}/history/states", test_name));
commonItems::TryCreateFolder(fmt::format("output/{}/history/units", test_name));
commonItems::TryCreateFolder(fmt::format("output/{}/localisation", test_name));
commonItems::TryCreateFolder(fmt::format("output/{}/map", test_name));
commonItems::TryCreateFolder(fmt::format("output/{}/map/strategicregions", test_name));
Expand Down Expand Up @@ -51,12 +52,12 @@ TEST(Outhoi4WorldOutworld, CountriesFilesAreCreated)

TEST(Outhoi4WorldOutworld, TagsFileIsCreated)
{
CreateTestFolders("TagsFileIsCreated");
CreateTestFolders("WorldTagsFileIsCreated");

OutputWorld("TagsFileIsCreated",
OutputWorld("WorldTagsFileIsCreated",
hoi4::World({.countries = {{"TAG", hoi4::Country({.tag = "TAG"})}, {"TWO", hoi4::Country({.tag = "TWO"})}}}));

std::ifstream country_file("output/TagsFileIsCreated/common/country_tags/00_countries.txt");
std::ifstream country_file("output/WorldTagsFileIsCreated/common/country_tags/00_countries.txt");
ASSERT_TRUE(country_file.is_open());
std::stringstream country_file_stream;
std::copy(std::istreambuf_iterator<char>(country_file),
Expand All @@ -71,13 +72,25 @@ TEST(Outhoi4WorldOutworld, TagsFileIsCreated)

TEST(Outhoi4WorldOutworld, CountryHistoryFilesAreCreated)
{
CreateTestFolders("CountryHistoryFilesAreCreated");
CreateTestFolders("WorldCountryHistoryFilesAreCreated");

OutputWorld("CountryHistoryFilesAreCreated",
OutputWorld("WorldCountryHistoryFilesAreCreated",
hoi4::World({.countries = {{"TAG", hoi4::Country({.tag = "TAG"})}, {"TWO", hoi4::Country({.tag = "TWO"})}}}));

EXPECT_TRUE(commonItems::DoesFileExist("output/CountryHistoryFilesAreCreated/history/countries/TAG.txt"));
EXPECT_TRUE(commonItems::DoesFileExist("output/CountryHistoryFilesAreCreated/history/countries/TWO.txt"));
EXPECT_TRUE(commonItems::DoesFileExist("output/WorldCountryHistoryFilesAreCreated/history/countries/TAG.txt"));
EXPECT_TRUE(commonItems::DoesFileExist("output/WorldCountryHistoryFilesAreCreated/history/countries/TWO.txt"));
}


TEST(Outhoi4WorldOutworld, DivisionTemplatesAreCopied)
{
CreateTestFolders("WorldDivisionTemplatesAreCopied");

OutputWorld("WorldDivisionTemplatesAreCopied",
hoi4::World({.countries = {{"TAG", hoi4::Country({.tag = "TAG"})}, {"TWO", hoi4::Country({.tag = "TWO"})}}}));

EXPECT_TRUE(commonItems::DoesFileExist("output/WorldDivisionTemplatesAreCopied/history/units/TAG_1936.txt"));
EXPECT_TRUE(commonItems::DoesFileExist("output/WorldDivisionTemplatesAreCopied/history/units/TWO_1936.txt"));
}


Expand Down Expand Up @@ -173,7 +186,6 @@ TEST(Outhoi4WorldOutworld, LocalizationsAreOutput)
const hoi4::Localizations localizations(country_localizations, state_localizations, victory_point_localizations);

OutputWorld("LocalizationsAreOutput", hoi4::World({.localizations = localizations}));

ASSERT_TRUE(
commonItems::DoesFileExist("output/LocalizationsAreOutput/localisation/braz_por/countries_l_braz_por.yml"));
ASSERT_TRUE(
Expand Down

0 comments on commit 19459f0

Please sign in to comment.