• 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

87.23
/src/mappers/unit/unit_mapper.cpp
1
#include "src/mappers/unit/unit_mapper.h"
2

3
#include <external/commonItems/Log.h>
4
#include <external/fmt/include/fmt/format.h>
5

6
#include <algorithm>
7
#include <ranges>
8

9

10

11
namespace
12
{
13

14
void WarnForMissingMapping(const std::string& pm, std::set<std::string>& warned)
3✔
15
{
16
   if (warned.contains(pm))
3✔
17
   {
18
      Log(LogLevel::Warning) << fmt::format("Missing unit mapping rule for {}", pm);
×
19
   }
20
   warned.insert(pm);
3✔
21
}
3✔
22

23
}  // namespace
24

25

26
std::vector<hoi4::Battalion> mappers::UnitMapper::MakeBattalions(const std::vector<std::string>& methods,
5✔
27
    int scale) const
28
{
29
   int equip = 0;
5✔
30
   BattalionMap current;
5✔
31
   for (const auto& pm: methods)
18✔
32
   {
33
      const auto& itr = templates_.find(pm);
13✔
34
      if (itr == templates_.end())
13✔
35
      {
36
         WarnForMissingMapping(pm, warned_);
3✔
37
         continue;
3✔
38
      }
39

40
      equip += itr->second.equipment;
10✔
41
      for (const auto& [ut, str]: itr->second.units)
17✔
42
      {
43
         current[ut] += str * static_cast<float>(scale);
7✔
44
      }
45
   }
46

47
   std::vector<hoi4::Battalion> units;
5✔
48
   for (const auto& [ut, str]: current)
12✔
49
   {
50
      units.emplace_back(ut, equip, str);
7✔
51
   }
52
   return units;
10✔
53
}
5✔
54

55

56
std::vector<hoi4::Battalion> mappers::UnitMapper::MakeBattalions(const vic3::MilitaryFormation& formation) const
1✔
57
{
58
   int equip = 0;
1✔
59
   BattalionMap current;
1✔
60
   for (const auto& [unit_type, amount]: formation.units)
2✔
61
   {
62
      const auto& itr = templates_.find(unit_type);
1✔
63
      if (itr == templates_.end())
1✔
64
      {
65
         WarnForMissingMapping(unit_type, warned_);
×
66
         continue;
×
67
      }
68

69
      equip += itr->second.equipment;
1✔
70
      for (const auto& [ut, str]: itr->second.units)
2✔
71
      {
72
         current[ut] += str * static_cast<float>(amount);
1✔
73
      }
74
   }
75
   for (const vic3::CombatUnit& combat_unit: formation.combat_units)
3✔
76
   {
77
      if (!combat_unit.type)
2✔
78
      {
NEW
79
         continue;
×
80
      }
81
      const auto& itr = templates_.find(combat_unit.type.value());
2✔
82
      if (itr == templates_.end())
2✔
83
      {
NEW
84
         WarnForMissingMapping(combat_unit.type.value(), warned_);
×
NEW
85
         continue;
×
86
      }
87

88
      equip += itr->second.equipment;
2✔
89
      for (const auto& [ut, str]: itr->second.units)
3✔
90
      {
91
         current[ut] += str * combat_unit.current_manpower / 1000.0F;
1✔
92
      }
93
   }
94

95

96
   std::vector<hoi4::Battalion> units;
1✔
97
   for (const auto& [ut, str]: current)
3✔
98
   {
99
      units.emplace_back(ut, equip, str);
2✔
100
   }
101
   return units;
2✔
102
}
1✔
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