• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ParadoxGameConverters / Vic3ToHoI4 / 16384372731

19 Jul 2025 03:18AM UTC coverage: 94.208% (+0.02%) from 94.185%
16384372731

push

github

web-flow
Fix military conversion. (#740)

* Import and use combat units

* Ignore unregistered items

* Clean up cmake changes

* More cmake cleanup

* Add tests for combat unit importer

* Fix linux build

* Fix naming.

* Add tests for combat units importer

* Add another test for unit mapper

147 of 163 new or added lines in 7 files covered. (90.18%)

4 existing lines in 1 file now uncovered.

22155 of 23517 relevant lines covered (94.21%)

56339.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.66
/src/vic3_world/countries/vic3_country_importer.cpp
1
#include "src/vic3_world/countries/vic3_country_importer.h"
2

3
#include <external/commonItems/CommonRegexes.h>
4
#include <external/commonItems/Log.h>
5
#include <external/commonItems/ParserHelpers.h>
6
#include <external/commonItems/StringUtils.h>
7
#include <external/fmt/include/fmt/format.h>
8

9

10

11
namespace
12
{
13

14
vic3::BudgetLevel ParseBudgetLevel(const std::string& level_string)
×
15
{
16
   if (level_string == "very_low")
×
17
   {
18
      return vic3::BudgetLevel::kVeryLow;
×
19
   }
20
   if (level_string == "low")
×
21
   {
22
      return vic3::BudgetLevel::kLow;
×
23
   }
24
   if (level_string == "medium")
×
25
   {
26
      return vic3::BudgetLevel::kMedium;
×
27
   }
28
   if (level_string == "high")
×
29
   {
30
      return vic3::BudgetLevel::kHigh;
×
31
   }
32
   if (level_string == "very_high")
×
33
   {
34
      return vic3::BudgetLevel::kVeryHigh;
×
35
   }
36

37
   Log(LogLevel::Error) << fmt::format("Unknown budget level {}", level_string);
×
38
   return vic3::BudgetLevel::kMedium;
×
39
}
40

41
}  // namespace
42

43

44
vic3::CountryImporter::CountryImporter()
18✔
45
{
46
   dynamic_name_parser_.registerKeyword("dynamic_country_name", [this](std::istream& input_stream) {
18✔
47
      options_.dynamic_name = commonItems::getString(input_stream);
1✔
48
   });
1✔
49
   dynamic_name_parser_.registerKeyword("dynamic_country_adjective", [this](std::istream& input_stream) {
18✔
50
      options_.dynamic_adjective = commonItems::getString(input_stream);
1✔
51
   });
1✔
52
   dynamic_name_parser_.registerKeyword("use_overlord_prefix", [this](std::istream& input_stream) {
18✔
53
      options_.use_overlord_prefix = (commonItems::getString(input_stream) == "yes");
1✔
54
   });
1✔
55
   dynamic_name_parser_.registerKeyword("state_region_template", [this](std::istream& input_stream) {
18✔
UNCOV
56
      options_.use_overlord_prefix = (commonItems::getString(input_stream) == "yes");
×
UNCOV
57
   });
×
58

59
   country_parser_.registerKeyword("definition", [this](std::istream& input_stream) {
18✔
60
      options_.tag = commonItems::getString(input_stream);
19✔
61
   });
19✔
62
   country_parser_.registerKeyword("dynamic_country_name", [this](std::istream& input_stream) {
18✔
63
      options_.dynamic_name = commonItems::getString(input_stream);
1✔
64
   });
1✔
65
   country_parser_.registerKeyword("dynamic_country_adjective", [this](std::istream& input_stream) {
18✔
66
      options_.dynamic_adjective = commonItems::getString(input_stream);
1✔
67
   });
1✔
68
   country_parser_.registerKeyword("dynamic_name", [this](std::istream& input_stream) {
18✔
69
      dynamic_name_parser_.parseStream(input_stream);
1✔
70
   });
1✔
71
   country_parser_.registerKeyword("map_color", [this](std::istream& input_stream) {
18✔
72
      options_.color = commonItems::Color::Factory{}.getColor(input_stream);
1✔
73
   });
1✔
74
   country_parser_.registerKeyword("capital", [this](std::istream& input_stream) {
18✔
75
      const int64_t temp_number = commonItems::getLlong(input_stream);
6✔
76
      if (temp_number == 4294967295)
6✔
77
      {
78
         options_.capital_state = -1;
1✔
79
      }
80
      else
81
      {
82
         options_.capital_state = static_cast<int>(temp_number);
5✔
83
      }
84
   });
6✔
85
   country_parser_.registerKeyword("country_type", [this](std::istream& input_stream) {
18✔
86
      options_.country_type = commonItems::getString(input_stream);
1✔
87
   });
1✔
88
   country_parser_.registerKeyword("tax_level", [this](std::istream& input_stream) {
18✔
89
      options_.tax_level = ParseBudgetLevel(commonItems::getString(input_stream));
×
90
   });
×
91
   country_parser_.registerKeyword("salaries", [this](std::istream& input_stream) {
18✔
92
      options_.salary_level = ParseBudgetLevel(commonItems::getString(input_stream));
×
93
   });
×
94
   country_parser_.registerKeyword("mil_salaries", [this](std::istream& input_stream) {
18✔
UNCOV
95
      options_.mil_salary_level = ParseBudgetLevel(commonItems::getString(input_stream));
×
UNCOV
96
   });
×
97
   country_parser_.registerKeyword("civil_war", [this](std::istream& input_stream) {
18✔
98
      options_.is_civil_war = commonItems::getString(input_stream) == "yes";
1✔
99
   });
1✔
100
   country_parser_.registerKeyword("cultures", [this](std::istream& input_stream) {
18✔
101
      for (const auto& culture_id: commonItems::getInts(input_stream))
23✔
102
      {
103
         options_.primary_culture_ids.emplace(culture_id);
12✔
104
      }
11✔
105
   });
11✔
106
   country_parser_.registerKeyword("ruler", [this](std::istream& input_stream) {
18✔
107
      const int64_t temp_number = commonItems::getLlong(input_stream);
12✔
108
      if (temp_number == 4294967295)
12✔
109
      {
110
         options_.head_of_state_id = -1;
1✔
111
      }
112
      else
113
      {
114
         options_.head_of_state_id = static_cast<int>(temp_number);
11✔
115
      }
116
   });
12✔
117

118
   country_parser_.registerKeyword("dead", [this](std::istream& input_stream) {
18✔
119
      options_.is_dead = commonItems::getString(input_stream) == "yes";
1✔
120
   });
1✔
121

122
   /// ---- counters parser ----
123

124
   counters_parser_.registerKeyword("legitimacy", [this](std::istream& input_stream) {
18✔
125
      options_.legitimacy = commonItems::getInt(input_stream);
1✔
126
   });
1✔
127

128
   counters_parser_.IgnoreUnregisteredItems();
18✔
129

130
   country_parser_.registerKeyword("counters", [this](std::istream& input_stream) {
18✔
131
      counters_parser_.parseStream(input_stream);
1✔
132
   });
1✔
133

134
   country_parser_.IgnoreUnregisteredItems();
18✔
135
}
18✔
136

137

138
std::optional<vic3::Country> vic3::CountryImporter::ImportCountry(const int number,
24✔
139
    std::istream& input_stream,
140
    const std::map<std::string, commonItems::Color>& color_definitions)
141
{
142
   options_ = {};
24✔
143
   country_parser_.parseStream(input_stream);
24✔
144

145
   if (options_.color == commonItems::Color())
24✔
146
   {
147
      if (const auto color_itr = color_definitions.find(options_.tag); color_itr != color_definitions.end())
23✔
148
      {
149
         options_.color = color_itr->second;
17✔
150
      }
151
   }
152

153
   options_.number = number;
24✔
154

155
   return Country(options_);
24✔
156
}
24✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc