Skip to content

Commit dbab1d5

Browse files
authored
Merge pull request #354 from OpenVicProject/rgo_employment
Record pop employment for RGOs and calculate unemployment fraction.
2 parents 4dbb5f6 + f8f60f6 commit dbab1d5

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,13 @@ void ResourceGatheringOperation::hire() {
208208
for (Job const& job : jobs) {
209209
if (job.get_pop_type() == &pop_type) {
210210
const pop_size_t pop_size_to_hire = static_cast<pop_size_t>((proportion_to_hire * pop.get_size()).floor());
211+
if (pop_size_to_hire <= 0) {
212+
continue;
213+
}
214+
211215
employee_count_per_type_cache[pop_type] += pop_size_to_hire;
212216
employees.emplace_back(pop, pop_size_to_hire);
217+
pop.hire(pop_size_to_hire);
213218
total_employees_count_cache += pop_size_to_hire;
214219
if (!pop_type.get_is_slave()) {
215220
total_paid_employees_count_cache += pop_size_to_hire;

src/openvic-simulation/map/MapInstance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ void MapInstance::update_gamestate(const Date today, DefineManager const& define
155155

156156
void MapInstance::map_tick() {
157157
thread_pool.process_province_ticks();
158+
//state tick
159+
//after provice tick as province tick sets pop employment to 0
160+
//state tick will update pop employment via factories
158161
}
159162

160163
void MapInstance::initialise_for_new_game(

src/openvic-simulation/pop/Pop.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "openvic-simulation/modifier/ModifierEffectCache.hpp"
2121
#include "openvic-simulation/pop/PopValuesFromProvince.hpp"
2222
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
23+
#include "openvic-simulation/utility/Logger.hpp"
2324
#include "openvic-simulation/utility/Utility.hpp"
2425

2526
using namespace OpenVic;
@@ -108,7 +109,6 @@ void Pop::setup_pop_test_values(IssueManager const& issue_manager) {
108109
return (rand() % 256) * max / 256;
109110
};
110111

111-
unemployment = test_range();
112112
cash = test_range(20);
113113
income = test_range(5);
114114
expenses = test_range(5);
@@ -353,6 +353,7 @@ void Pop::pop_tick_without_cleanup(PopValuesFromProvince& shared_values) {
353353
DO_FOR_ALL_TYPES_OF_POP_EXPENSES(SET_TO_ZERO)
354354
#undef SET_TO_ZERO
355355
income = expenses = fixed_point_t::_0();
356+
employed = 0;
356357

357358
auto& [
358359
reusable_map_0,
@@ -543,6 +544,18 @@ void Pop::report_artisanal_produce(const fixed_point_t quantity) {
543544
artisanal_produce_left_to_sell = quantity;
544545
}
545546

547+
void Pop::hire(pop_size_t count) {
548+
if (OV_unlikely(count <= 0)) {
549+
Logger::warning("Tried employing non-positive number of pops. ", count, " Context", get_pop_context_text().str());
550+
}
551+
employed += count;
552+
if (OV_unlikely(employed > size)) {
553+
Logger::error("Employed count became greater than pop size. ", employed, " Context", get_pop_context_text().str());
554+
} else if (OV_unlikely(employed < 0)) {
555+
Logger::error("Employed count became negative. ", employed ," Context", get_pop_context_text().str());
556+
}
557+
}
558+
546559
#undef DO_FOR_ALL_TYPES_OF_POP_INCOME
547560
#undef DO_FOR_ALL_TYPES_OF_POP_EXPENSES
548561
#undef DO_FOR_ALL_NEED_CATEGORIES

src/openvic-simulation/pop/Pop.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "openvic-simulation/economy/production/ArtisanalProducerFactoryPattern.hpp"
77
#include "openvic-simulation/pop/PopType.hpp"
88
#include "openvic-simulation/types/fixed_point/Atomic.hpp"
9+
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
10+
#include "openvic-simulation/types/PopSize.hpp"
911

1012
namespace OpenVic {
1113
struct CountryInstance;
@@ -99,7 +101,18 @@ namespace OpenVic {
99101
fixed_point_map_t<Issue const*> PROPERTY(issue_distribution);
100102
IndexedMap<CountryParty, fixed_point_t> PROPERTY(vote_distribution);
101103

102-
fixed_point_t PROPERTY(unemployment);
104+
pop_size_t employed = 0;
105+
public:
106+
constexpr pop_size_t get_unemployed() const {
107+
return size - employed;
108+
}
109+
constexpr fixed_point_t get_unemployment_fraction() const {
110+
if (!type->get_can_be_unemployed()) {
111+
return fixed_point_t::_0();
112+
}
113+
return fixed_point_t::parse(get_unemployed()) / size;
114+
}
115+
private:
103116
fixed_point_t PROPERTY(income);
104117
fixed_point_t PROPERTY(savings);
105118
moveable_atomic_fixed_point_t PROPERTY(cash);
@@ -172,6 +185,7 @@ namespace OpenVic {
172185
void pop_tick(PopValuesFromProvince& shared_values);
173186
void allocate_cash_for_artisanal_spending(const fixed_point_t money_to_spend);
174187
void report_artisanal_produce(const fixed_point_t quantity);
188+
void hire(pop_size_t count);
175189
};
176190
}
177191
#ifndef KEEP_DO_FOR_ALL_TYPES_OF_INCOME

src/openvic-simulation/pop/PopType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PopType::PopType(
4848
bool new_can_invest,
4949
bool new_factory,
5050
bool new_can_work_factory,
51-
bool new_unemployment,
51+
bool new_can_be_unemployed,
5252
fixed_point_t new_research_points,
5353
fixed_point_t new_leadership_points,
5454
fixed_point_t new_research_leadership_optimum,
@@ -83,7 +83,7 @@ PopType::PopType(
8383
can_invest { new_can_invest },
8484
factory { new_factory },
8585
can_work_factory { new_can_work_factory },
86-
unemployment { new_unemployment },
86+
can_be_unemployed { new_can_be_unemployed },
8787
research_points { new_research_points },
8888
leadership_points { new_leadership_points },
8989
research_leadership_optimum { new_research_leadership_optimum },

src/openvic-simulation/pop/PopType.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace OpenVic {
7676
const bool PROPERTY(can_invest);
7777
const bool PROPERTY(factory);
7878
const bool PROPERTY(can_work_factory);
79-
const bool PROPERTY(unemployment);
79+
const bool PROPERTY(can_be_unemployed);
8080
const fixed_point_t PROPERTY(research_points);
8181
const fixed_point_t PROPERTY(leadership_points);
8282
const fixed_point_t PROPERTY(research_leadership_optimum);
@@ -115,7 +115,7 @@ namespace OpenVic {
115115
bool new_can_invest,
116116
bool new_factory,
117117
bool new_can_work_factory,
118-
bool new_unemployment,
118+
bool new_can_be_unemployed,
119119
fixed_point_t new_research_points,
120120
fixed_point_t new_leadership_points,
121121
fixed_point_t new_research_leadership_optimum,

0 commit comments

Comments
 (0)