Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/openvic-simulation/military/UnitInstanceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,40 @@ bool UnitInstanceManager::create_leader(
});

return true;
}
}

bool UnitInstanceManager::create_regiment(
RegimentType const& regiment_type,
Pop& pop,
ProvinceInstance& location
) {
CountryInstance* country = location.get_owner();
if (OV_unlikely(country == nullptr)) {
spdlog::error_s("Trying to recruit regiment in unowned province \"{}\"", location.get_identifier());
return false;
}

if (!Pop::is_culture_status_allowed(regiment_type.allowed_cultures, pop.get_culture_status())) {
return false;
}

if (!pop.try_recruit()) {
return false;
}

//right now the regiment is created at full strength immediately
//XXX TODO: add recruitment times
RegimentInstance& regiment = *get_unit_instances<LAND>().insert(
[this, &regiment_type, &pop]() -> RegimentInstance {
return { unique_id_counter++, regiment_type.get_identifier(), regiment_type, &pop, false };
}()
);
unit_instance_map.emplace(regiment.unique_id, regiment);

//always spawns a new army for now
ArmyInstance& army = *armies.emplace(unique_id_counter++, regiment_type.get_identifier(), *country, location);
unit_instance_group_map.emplace(army.unique_id, army);
army.add_unit(regiment);

return true;
}
8 changes: 8 additions & 0 deletions src/openvic-simulation/military/UnitInstanceGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ namespace OpenVic {
LeaderInstance* get_leader_instance_by_unique_id(unique_id_t unique_id);
UnitInstance* get_unit_instance_by_unique_id(unique_id_t unique_id);
UnitInstanceGroup* get_unit_instance_group_by_unique_id(unique_id_t unique_id);


// Creates a new leader of the specified branch and adds it to the specified country. The leader's name and traits
// can be specified, but if they are not, the leader will be generated with a random name and traits. The country's
Expand All @@ -230,5 +231,12 @@ namespace OpenVic {
LeaderTrait const* personality = nullptr,
LeaderTrait const* background = nullptr
);
//this seems too minimal, am i missing something?
bool create_regiment(
RegimentType const& regiment_type,
Pop& pop,
ProvinceInstance& location
);

};
}
6 changes: 1 addition & 5 deletions src/openvic-simulation/misc/GameAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,5 @@ bool GameActionManager::VariantVisitor::operator() (start_land_unit_recruitment_
return false;
}

//these TODO's should be implemented in ProvinceInstance and/or some military type
//TODO verify pop's cultural status is acceptable for regiment type
//TODO verify pop is recruitable and has enough size (pop.try_recruit())
//TODO actually instantiate a regiment in recruitment state
return false;
return instance_manager.get_unit_instance_manager().create_regiment(*regiment_type, *pop, *province);
}