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

ParadoxGameConverters / Vic3ToHoI4 / 16833341297

08 Aug 2025 02:47PM UTC coverage: 94.208% (+0.007%) from 94.201%
16833341297

Pull #746

github

web-flow
Merge 7d1d5deee into 27b1ac9ea
Pull Request #746: More triggers

320 of 377 new or added lines in 32 files covered. (84.88%)

1 existing line in 1 file now uncovered.

22464 of 23845 relevant lines covered (94.21%)

56652.68 hits per line

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

96.55
/src/hoi4_world/map/hoi4_province_definition_importer.cpp
1
#include "src/hoi4_world/map/hoi4_province_definition_importer.h"
2

3
#include <external/commonItems/CommonRegexes.h>
4
#include <external/commonItems/Parser.h>
5
#include <external/fmt/include/fmt/format.h>
6

7
#include <fstream>
8

9
#include "src/maps/utility.h"
10
#include "src/vic3_world/provinces/vic3_province_definitions.h"
11

12

13

14
namespace
15
{
16

17
std::map<int, std::string> ImportContinentDefinitions(const commonItems::ModFilesystem& mod_filesystem)
14✔
18
{
19
   std::map<int, std::string> continent_definitions;
14✔
20
   int continent_index = 1;
14✔
21

22
   commonItems::parser continent_parser;
14✔
23
   continent_parser.registerRegex(commonItems::catchallRegex,
14✔
24
       [&continent_definitions, &continent_index](const std::string& continent, [[maybe_unused]] std::istream& stream) {
14✔
25
          continent_definitions.emplace(continent_index, continent);
91✔
26
          ++continent_index;
91✔
27
       });
91✔
28

29
   commonItems::parser continents_parser;
14✔
30
   continents_parser.registerKeyword("continents", [&continent_parser](std::istream& stream) {
14✔
31
      continent_parser.parseStream(stream);
13✔
32
   });
13✔
33

34
   const auto path = mod_filesystem.GetActualFileLocation("map/continent.txt");
14✔
35
   if (!path)
14✔
36
   {
37
      throw std::runtime_error("Could not find /map/continent.txt");
1✔
38
   }
39
   continents_parser.parseFile(*path);
13✔
40

41
   return continent_definitions;
26✔
42
}
17✔
43

44
}  // namespace
45

46

47
maps::ProvinceDefinitionsOptions hoi4::ImportProvinceDefinitions(const commonItems::ModFilesystem& mod_filesystem)
14✔
48
{
49
   const std::map<int, std::string> continent_definitions = ImportContinentDefinitions(mod_filesystem);
14✔
50

51
   const auto path = mod_filesystem.GetActualFileLocation("map/definition.csv");
13✔
52
   if (!path)
13✔
53
   {
UNCOV
54
      throw std::runtime_error("Could not find /map/definition.csv");
×
55
   }
56

57
   std::ifstream definitions(*path);
13✔
58
   if (!definitions.is_open())
13✔
59
   {
60
      throw std::runtime_error(fmt::format("Could not open {}/map/definition.csv", path->string()));
×
61
   }
62

63
   std::set<std::string> land_provinces;
13✔
64
   std::set<std::string> sea_provinces;
13✔
65
   std::map<std::string, std::string> terrain_types;
13✔
66
   std::map<std::string, std::string> continents;
13✔
67
   std::map<int, std::string> color_to_province_map;
13✔
68

69
   while (true)
70
   {
71
      if (definitions.eof())
271✔
72
      {
73
         break;
13✔
74
      }
75
      std::string line;
258✔
76
      getline(definitions, line);
258✔
77
      if (line.empty())
258✔
78
      {
79
         continue;
×
80
      }
81

82
      // number
83
      auto pos = line.find_first_of(';');
258✔
84
      if (pos == std::string::npos)
258✔
85
      {
86
         continue;
9✔
87
      }
88
      auto province_name = line.substr(0, pos);
249✔
89
      if (province_name == "0")
249✔
90
      {
91
         continue;
9✔
92
      }
93
      line = line.substr(pos + 1U, line.length());
240✔
94

95
      // red
96
      pos = line.find_first_of(';');
240✔
97
      if (pos == std::string::npos)
240✔
98
      {
99
         continue;
9✔
100
      }
101
      const int red(std::stoi(line.substr(0, pos)));
231✔
102
      line = line.substr(pos + 1, line.length());
231✔
103

104
      // green
105
      pos = line.find_first_of(';');
231✔
106
      if (pos == std::string::npos)
231✔
107
      {
108
         continue;
9✔
109
      }
110
      const int green(std::stoi(line.substr(0, pos)));
222✔
111
      line = line.substr(pos + 1U, line.length());
222✔
112

113
      // blue
114
      pos = line.find_first_of(';');
222✔
115
      if (pos == std::string::npos)
222✔
116
      {
117
         continue;
9✔
118
      }
119
      const int blue(std::stoi(line.substr(0, pos)));
213✔
120
      line = line.substr(pos + 1U, line.length());
213✔
121

122
      // land or sea
123
      pos = line.find_first_of(';');
213✔
124
      if (pos == std::string::npos)
213✔
125
      {
126
         continue;
9✔
127
      }
128
      const std::string land_or_sea = line.substr(0, pos);
204✔
129
      line = line.substr(pos + 1U, line.length());
204✔
130

131
      // false or true
132
      pos = line.find_first_of(';');
204✔
133
      if (pos == std::string::npos)
204✔
134
      {
135
         continue;
9✔
136
      }
137
      line = line.substr(pos + 1, line.length());
195✔
138

139
      // terrain
140
      pos = line.find_first_of(';');
195✔
141
      if (pos == std::string::npos)
195✔
142
      {
143
         continue;
9✔
144
      }
145
      const std::string terrain = line.substr(0, pos);
186✔
146
      line = line.substr(pos + 1U, line.length());
186✔
147

148
      auto color_int = maps::GetIntFromColor(commonItems::Color(std::array{red, green, blue}));
186✔
149
      color_to_province_map.emplace(color_int, province_name);
186✔
150
      if (land_or_sea == "land")
186✔
151
      {
152
         land_provinces.insert(province_name);
165✔
153
      }
154
      else if (land_or_sea == "sea")
21✔
155
      {
156
         sea_provinces.insert(province_name);
11✔
157
      }
158
      terrain_types.emplace(province_name, terrain);
186✔
159

160
      const int continent_number = std::stoi(line);
186✔
161
      if (const auto itr = continent_definitions.find(continent_number); itr != continent_definitions.end())
186✔
162
      {
163
         continents.emplace(province_name, itr->second);
53✔
164
      }
165
   }
597✔
166

167
   return {.land_provinces = land_provinces,
168
       .sea_provinces = sea_provinces,
169
       .terrain_types = terrain_types,
170
       .continents = continents,
171
       .color_to_province_map = color_to_province_map};
13✔
172
}
13✔
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