Skip to content

Commit

Permalink
Fix navy conversion (#562)
Browse files Browse the repository at this point in the history
* Place navies in capital states when possible.

* Get non-capital naval base locations.

* Don't miss ships because your tech's too good.

* Formatting
  • Loading branch information
Idhrendur committed Jan 27, 2024
1 parent 683fa5d commit 979f2a5
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 91 deletions.
15 changes: 0 additions & 15 deletions data/configurables/legacy_ship_types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ legacy_ship_type = {
required_techs = {
early_submarine
}
blocking_techs = {
basic_submarine
}
name = "Early Submarine"
type = submarine_1
upgrades = {
Expand Down Expand Up @@ -35,9 +32,6 @@ legacy_ship_type = {
required_techs = {
early_destroyer
}
blocking_techs = {
basic_destroyer
}
name = "Early Destroyer"
type = destroyer_1
upgrades = {
Expand All @@ -52,9 +46,6 @@ legacy_ship_type = {
required_techs = {
early_light_cruiser
}
blocking_techs = {
basic_light_cruiser
}
name = "Early Light Cruiser"
type = light_cruiser_1
upgrades = {
Expand All @@ -69,9 +60,6 @@ legacy_ship_type = {
required_techs = {
early_heavy_cruiser
}
blocking_techs = {
basic_heavy_cruiser
}
name = "Early Heavy Cruiser"
type = heavy_cruiser_1
upgrades = {
Expand All @@ -86,9 +74,6 @@ legacy_ship_type = {
required_techs = {
early_battleship
}
blocking_techs = {
basic_battleship
}
name = "Early Battleship"
type = battleship_1
upgrades = {
Expand Down
30 changes: 0 additions & 30 deletions data/configurables/ship_types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ mtg_ship_type = {
required_techs = {
early_ship_hull_submarine
}
blocking_techs = {
basic_ship_hull_submarine
}
name = "Early Submarine"
type = ship_hull_submarine_1
name_group = SS_HISTORICAL
Expand Down Expand Up @@ -35,9 +32,6 @@ mtg_ship_type = {
required_techs = {
early_ship_hull_heavy
}
blocking_techs = {
basic_ship_hull_heavy
}
name = "Early Battleship"
type = ship_hull_heavy_1
name_group = BB_HISTORICAL
Expand Down Expand Up @@ -84,9 +78,6 @@ mtg_ship_type = {
required_techs = {
early_ship_hull_light
}
blocking_techs = {
basic_ship_hull_light
}
name = "Early Destroyer"
type = ship_hull_light_1
name_group = DD_HISTORICAL
Expand Down Expand Up @@ -127,9 +118,6 @@ mtg_ship_type = {
required_techs = {
early_ship_hull_cruiser
}
blocking_techs = {
basic_ship_hull_cruiser
}
name = "Early Heavy Cruiser"
type = ship_hull_cruiser_1
name_group = CA_HISTORICAL
Expand Down Expand Up @@ -174,9 +162,6 @@ mtg_ship_type = {
required_techs = {
early_ship_hull_cruiser
}
blocking_techs = {
basic_ship_hull_cruiser
}
name = "Early Light Cruiser"
type = ship_hull_cruiser_1
name_group = CL_HISTORICAL
Expand Down Expand Up @@ -222,9 +207,6 @@ legacy_ship_type = {
required_techs = {
early_submarine
}
blocking_techs = {
basic_submarine
}
name = "Early Submarine"
type = submarine_1
upgrades = {
Expand Down Expand Up @@ -255,9 +237,6 @@ legacy_ship_type = {
required_techs = {
early_destroyer
}
blocking_techs = {
basic_destroyer
}
name = "Early Destroyer"
type = destroyer_1
upgrades = {
Expand All @@ -272,9 +251,6 @@ legacy_ship_type = {
required_techs = {
early_light_cruiser
}
blocking_techs = {
basic_light_cruiser
}
name = "Early Light Cruiser"
type = light_cruiser_1
upgrades = {
Expand All @@ -289,9 +265,6 @@ legacy_ship_type = {
required_techs = {
early_heavy_cruiser
}
blocking_techs = {
basic_heavy_cruiser
}
name = "Early Heavy Cruiser"
type = heavy_cruiser_1
upgrades = {
Expand All @@ -306,9 +279,6 @@ legacy_ship_type = {
required_techs = {
early_battleship
}
blocking_techs = {
basic_battleship
}
name = "Early Battleship"
type = battleship_1
upgrades = {
Expand Down
49 changes: 42 additions & 7 deletions data/configurables/task_force_templates.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Modern battleship group.
task_force = {
cost = {
combat_unit_type_battleship = 20
combat_unit_type_carrier = 20
combat_unit_type_battleship = 2
combat_unit_type_carrier = 2
}
ship = {
name = "Battleship"
Expand Down Expand Up @@ -58,8 +58,8 @@ task_force = {
# Heavy cruiser backup.
task_force = {
cost = {
combat_unit_type_battleship = 10
combat_unit_type_carrier = 10
combat_unit_type_battleship = 1
combat_unit_type_carrier = 1
}
ship = {
name = "Heavy Cruiser"
Expand Down Expand Up @@ -94,7 +94,7 @@ task_force = {
# Older battleship group.
task_force = {
cost = {
combat_unit_type_dreadnought = 20
combat_unit_type_dreadnought = 2
}
ship = {
name = "Battleship"
Expand Down Expand Up @@ -150,7 +150,7 @@ task_force = {
# Heavy cruiser backup.
task_force = {
cost = {
combat_unit_type_dreadnought = 10
combat_unit_type_dreadnought = 1
}
ship = {
name = "Heavy Cruiser"
Expand Down Expand Up @@ -185,7 +185,7 @@ task_force = {
# Modern destroyer flotilla.
task_force = {
cost = {
combat_unit_type_carrier = 10
combat_unit_type_carrier = 1
}
ship = {
name = "Destroyer"
Expand Down Expand Up @@ -288,6 +288,41 @@ task_force = {
}
}

# Older submarines.
task_force = {
cost = {
combat_unit_type_submarine = 10
}
ship = {
name = "Submarine"
definition = submarine
equipment = ship_hull_submarine_1
legacy_equipment = submarine_1
version = "Early Submarine"
}
ship = {
name = "Submarine"
definition = submarine
equipment = ship_hull_submarine_1
legacy_equipment = submarine_1
version = "Early Submarine"
}
ship = {
name = "Submarine"
definition = submarine
equipment = ship_hull_submarine_1
legacy_equipment = submarine_1
version = "Early Submarine"
}
ship = {
name = "Submarine"
definition = submarine
equipment = ship_hull_submarine_1
legacy_equipment = submarine_1
version = "Early Submarine"
}
}


### Pre 1.5

Expand Down
115 changes: 76 additions & 39 deletions src/hoi4_world/countries/hoi4_country_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ std::vector<hoi4::TaskForce> ConvertNavies(const std::string& tag,
const std::vector<hoi4::TaskForceTemplate>& task_force_templates,
const std::vector<hoi4::EquipmentVariant>& active_ship_variants,
const std::vector<hoi4::EquipmentVariant>& active_legacy_ship_variants,
const hoi4::States& states)
const hoi4::States& states,
const std::optional<int> capital_state)
{
std::vector<hoi4::TaskForce> forces;
std::map<std::string, float> pm_amounts;
Expand Down Expand Up @@ -346,43 +347,78 @@ std::vector<hoi4::TaskForce> ConvertNavies(const std::string& tag,
}
}

// Disable converting navies until naval bases can be converted
// Without naval bases set, navies crash hoi4
// for (const vic3::MilitaryFormation& naval_formation: naval_formations | std::views::values)
//{
// for (const auto& [ship_type, number]: naval_formation.units)
// {
// pm_amounts[ship_type] += number;
// }

// hoi4::TaskForce task_force;
// if (naval_formation.name)
// {
// task_force.name = *naval_formation.name;
// }
// else if (naval_formation.ordinal_number)
// {
// task_force.name = fmt::format("{}. Fleet", *naval_formation.ordinal_number);
// }
// else
// {
// task_force.name = fmt::format("{}. Fleet", num_fleets);
// }

// for (const auto& task_force_template: task_force_templates)
// {
// if (!task_force_template.AllVariantsActive(active_variants))
// {
// continue;
// }
// task_force_template.AddShipsIfPossible(task_force.ships, ship_names, pm_amounts);
// }
// if (!task_force.ships.empty())
// {
// forces.push_back(task_force);
// ++num_fleets;
// }
//}
std::optional<int> default_naval_base;
if (capital_state)
{
const auto state_id_to_naval_base = naval_base_locations.find(*capital_state);
if (state_id_to_naval_base != naval_base_locations.end())
{
default_naval_base = state_id_to_naval_base->second;
}
}
if (!default_naval_base)
{
for (const auto& hoi4_id: states.vic3_state_ids_to_hoi4_state_ids | std::views::values)
{
const auto itr = states.hoi4_state_ids_to_owner.find(hoi4_id);
if (itr == states.hoi4_state_ids_to_owner.end())
{
continue;
}
if (itr->second != tag)
{
continue;
}

const auto state_id_to_naval_base = naval_base_locations.find(hoi4_id);
if (state_id_to_naval_base != naval_base_locations.end())
{
default_naval_base = state_id_to_naval_base->second;
break;
}
}
}

if (!default_naval_base)
{
return forces;
}

for (const vic3::MilitaryFormation& naval_formation: naval_formations | std::views::values)
{
for (const auto& [ship_type, number]: naval_formation.units)
{
pm_amounts[ship_type] += number;
}

hoi4::TaskForce task_force{.location = *default_naval_base};
if (naval_formation.name)
{
task_force.name = *naval_formation.name;
}
else if (naval_formation.ordinal_number)
{
task_force.name = fmt::format("{}. Fleet", *naval_formation.ordinal_number);
}
else
{
task_force.name = fmt::format("{}. Fleet", num_fleets);
}

for (const auto& task_force_template: task_force_templates)
{
if (!task_force_template.AllVariantsActive(active_variants))
{
continue;
}
task_force_template.AddShipsIfPossible(task_force.ships, ship_names, pm_amounts);
}
if (!task_force.ships.empty())
{
forces.push_back(task_force);
++num_fleets;
}
}

return forces;
}
Expand Down Expand Up @@ -829,7 +865,8 @@ std::optional<hoi4::Country> hoi4::ConvertCountry(const vic3::World& source_worl
task_force_templates,
active_ship_variants,
active_legacy_ship_variants,
states);
states,
capital_state);

const auto& [economy_law, trade_law, military_law] = ConvertLaws(source_country.GetActiveLaws(), ideology);

Expand Down

0 comments on commit 979f2a5

Please sign in to comment.