Skip to content

Commit 6c9475f

Browse files
authored
Merge pull request #652 from OpenVicProject/add_artisans_discard_unsold_non_inputs_game_rule
Add should_artisans_discard_unsold_non_inputs game rule
2 parents f4e24c2 + 2b1ca70 commit 6c9475f

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "openvic-simulation/economy/production/ProductionType.hpp"
1111
#include "openvic-simulation/economy/trading/MarketInstance.hpp"
1212
#include "openvic-simulation/map/ProvinceInstance.hpp"
13+
#include "openvic-simulation/misc/GameRulesManager.hpp"
1314
#include "openvic-simulation/modifier/ModifierEffectCache.hpp"
1415
#include "openvic-simulation/population/Pop.hpp"
1516
#include "openvic-simulation/population/PopValuesFromProvince.hpp"
@@ -297,6 +298,20 @@ void ArtisanalProducer::artisan_tick(
297298
memory::vector<fixed_point_t>& demand_per_input = reusable_map_1;
298299

299300
ProductionType const* const old_production_type_ptr = production_type_nullable;
301+
302+
if (values_from_province.game_rules_manager.get_should_artisans_discard_unsold_non_inputs()) {
303+
if (old_production_type_ptr == nullptr) {
304+
stockpile.fill(0);
305+
} else {
306+
fixed_point_map_t<GoodDefinition const*> const& input_goods = old_production_type_ptr->get_input_goods();
307+
for (auto [good, stockpiled_quantity] : stockpile) {
308+
if (!input_goods.contains(&good)) {
309+
stockpiled_quantity = 0;
310+
}
311+
}
312+
}
313+
}
314+
300315
ProductionType const* new_production_type_ptr = pick_production_type(
301316
pop,
302317
values_from_province,

src/openvic-simulation/misc/GameRulesManager.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace OpenVic {
4040
// if changed during a session, call on_use_exponential_price_changes_changed for each GoodInstance.
4141
bool PROPERTY_RW(use_exponential_price_changes);
4242
bool PROPERTY_RW(prevent_negative_administration_efficiency);
43+
bool PROPERTY_RW(should_artisans_discard_unsold_non_inputs);
4344
demand_category PROPERTY_RW(artisanal_input_demand_category);
4445
country_to_report_economy_t PROPERTY_RW(country_to_report_economy);
4546
artisan_coastal_restriction_t PROPERTY_RW(coastal_restriction_for_artisans);
@@ -61,6 +62,7 @@ namespace OpenVic {
6162
use_simple_farm_mine_logic = true;
6263
use_exponential_price_changes = true;
6364
prevent_negative_administration_efficiency = true;
65+
should_artisans_discard_unsold_non_inputs = false;
6466
artisanal_input_demand_category = demand_category::FactoryNeeds;
6567
country_to_report_economy = country_to_report_economy_t::Controller;
6668
coastal_restriction_for_artisans = artisan_coastal_restriction_t::CoastalProvinces;
@@ -71,6 +73,7 @@ namespace OpenVic {
7173
use_simple_farm_mine_logic = false;
7274
use_exponential_price_changes = false;
7375
prevent_negative_administration_efficiency = false;
76+
should_artisans_discard_unsold_non_inputs = true;
7477
artisanal_input_demand_category = demand_category::None;
7578
country_to_report_economy = country_to_report_economy_t::Owner;
7679
coastal_restriction_for_artisans = artisan_coastal_restriction_t::CountriesWithCoast;

src/openvic-simulation/population/PopValuesFromProvince.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ namespace OpenVic {
3131

3232
struct PopValuesFromProvince {
3333
private:
34-
35-
GameRulesManager const& game_rules_manager;
3634
GoodInstanceManager const& good_instance_manager;
3735
ModifierEffectCache const& modifier_effect_cache;
3836
ProductionTypeManager const& production_type_manager;
@@ -42,6 +40,7 @@ namespace OpenVic {
4240
memory::vector<std::pair<ProductionType const*, fixed_point_t>> SPAN_PROPERTY(ranked_artisanal_production_types);
4341
public:
4442
PopsDefines const& defines;
43+
GameRulesManager const& game_rules_manager;
4544

4645
PopValuesFromProvince(
4746
GameRulesManager const& new_game_rules_manager,

0 commit comments

Comments
 (0)