Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Government salaries and social income #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wvpm
Copy link
Contributor

@wvpm wvpm commented Mar 2, 2025

Implements administration, education & military spending as well as pensions and unemployment subsidies.

@wvpm wvpm added the enhancement New feature or request label Mar 3, 2025
@wvpm wvpm force-pushed the government_salaries_and_social_income branch 19 times, most recently from 6e6b63b to 3ca3458 Compare March 14, 2025 08:50
@wvpm wvpm force-pushed the government_salaries_and_social_income branch 7 times, most recently from 04e3b44 to 98e6a59 Compare April 8, 2025 10:07
@wvpm wvpm force-pushed the government_salaries_and_social_income branch from 98e6a59 to 3f67419 Compare April 10, 2025 07:37
@wvpm wvpm marked this pull request as ready for review April 10, 2025 12:02
@@ -13,6 +13,7 @@
#include "openvic-simulation/politics/Rebel.hpp"
#include "openvic-simulation/utility/Logger.hpp"
#include "openvic-simulation/utility/TslHelper.hpp"
#include "dataloader/NodeTools.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this include was added by clangd automatically, you can disable that behaviour by adding this to your user settings JSON file:

"clangd.arguments": [
	"-header-insertion=never"
]


public:
void update_costs(PopType const& pop_type, PopsDefines const& pop_defines, GoodInstanceManager const& good_instance_manager);
constexpr fixed_point_t get_social_income_form_base() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be get_social_income_from_base?

IndexedMap<PopType, SharedPopTypeValues> PROPERTY(shared_pop_type_values);

public:
SharedCountryValues(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to give this a default move constructor so shared_pop_type_values doesn't ever get copied unnecessarily

Comment on lines +39 to +47
if ((pop_type.get_##need_category##_needs_income_types() & ADMINISTRATION) == ADMINISTRATION) { \
administration_salary_base += base_##need_category##_need_costs; \
} \
if ((pop_type.get_##need_category##_needs_income_types() & EDUCATION) == EDUCATION) { \
education_salary_base += base_##need_category##_need_costs; \
} \
if ((pop_type.get_##need_category##_needs_income_types() & MILITARY) == MILITARY) { \
military_salary_base += base_##need_category##_need_costs; \
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the if statements here could use share_income_type rather than manually doing the bitwise operations


fixed_point_t PROPERTY(administrative_efficiency);
constexpr fixed_point_t get_corruption_cost_multiplier() const {
return 2 - administrative_efficiency;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there definitely no need for a std::max(0, ...) here or any other bounds check?

Comment on lines +673 to +675
constexpr SharedCountryValues const& get_shared_country_values() const {
return shared_country_values;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put PROPERTY around the shared_country_values declaration above?

Comment on lines +1065 to +1070
projected_administration_spending_unscaled_by_slider += size * calculate_administration_salary_base(pop_type, shared_country_values);
projected_education_spending_unscaled_by_slider += size * calculate_education_salary_base(pop_type, shared_country_values);
projected_military_spending_unscaled_by_slider += size * calculate_military_salary_base(pop_type, shared_country_values);
projected_pensions_spending_unscaled_by_slider += size * calculate_pensions_base(pop_type, shared_country_values);
projected_unemployment_subsidies_spending_unscaled_by_slider += pop_type_unemployed_count[pop_type]
* calculate_unemployment_subsidies_base(pop_type, shared_country_values);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in previous comments, the functions called here involve many repeated lookups/calculations which could be avoided with caching

}
}

for (auto const& [good_instance, data] : goods_data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto const& [good_instance, data] : goods_data) {
for (auto& data : goods_data.get_values()) {

You can iterate over an IndexedMap's values directly

@@ -1691,6 +1822,68 @@ void CountryInstance::report_output(ProductionType const& production_type, const
good_data.production_per_production_type[&production_type] += quantity;
}

void CountryInstance::request_salaries_and_welfare(Pop& pop, SharedCountryValues const& shared_country_values) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could also benefit from caching rather than always looking up/calculating new values in every function call

}

#undef DO_FOR_ALL_NEED_CATEGORIES
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the PopNeedsMacro.hpp include at the top of the file can be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants