@@ -77,10 +77,11 @@ void ArtisanalProducer::artisan_tick(
7777 memory::vector<fixed_point_t >& demand_per_input = reusable_map_1;
7878 demand_per_input.resize (input_goods.size (), 0 );
7979
80- // throughput scalar, the minimum of stockpile / desired_quantity
81- fixed_point_t inputs_bought_fraction = 1 ,
82- inputs_bought_numerator= 1 ,
83- inputs_bought_denominator= 1 ;
80+ // throughput scalar, the minimum of stockpile / base_desired_quantity
81+ // inputs_bought_fraction uses base_desired_quantity as population size is cancelled in the production and input calculations.
82+ fixed_point_t inputs_bought_numerator = pop.get_size (),
83+ inputs_bought_denominator = production_type.get_base_workforce_size (),
84+ inputs_bought_fraction = inputs_bought_numerator / inputs_bought_denominator;
8485
8586 size_t distinct_goods_to_buy = 0 ;
8687
@@ -102,11 +103,11 @@ void ArtisanalProducer::artisan_tick(
102103 }
103104
104105 const fixed_point_t stockpiled_quantity = stockpile[&input_good];
105- const fixed_point_t good_bought_fraction = stockpiled_quantity / desired_quantity ;
106+ const fixed_point_t good_bought_fraction = stockpiled_quantity / base_desired_quantity ;
106107 if (good_bought_fraction < inputs_bought_fraction) {
107108 inputs_bought_fraction = good_bought_fraction;
108109 inputs_bought_numerator = stockpiled_quantity;
109- inputs_bought_denominator = desired_quantity ;
110+ inputs_bought_denominator = base_desired_quantity ;
110111 }
111112
112113 max_price_per_input[i] = pop.get_market_instance ().get_max_next_price (input_good);
@@ -115,27 +116,26 @@ void ArtisanalProducer::artisan_tick(
115116 }
116117
117118 // Produce output
118- fixed_point_t produce_left_to_sell = current_production = production_type.get_base_output_quantity ()
119- * inputs_bought_numerator * pop.get_size ()
120- / (inputs_bought_denominator * production_type.get_base_workforce_size ());
119+ fixed_point_t produce_left_to_sell = current_production = fixed_point_t::mul_div (
120+ production_type.get_base_output_quantity (),
121+ inputs_bought_numerator,
122+ inputs_bought_denominator
123+ );
121124
122125 if (current_production > 0 ) {
123126 if (country_to_report_economy_nullable != nullptr ) {
124127 country_to_report_economy_nullable->report_output (production_type, current_production);
125128 }
126- }
127129
128- if (inputs_bought_fraction > 0 ) {
129130 for (auto it = input_goods.begin (); it < input_goods.end (); it++) {
130131 GoodDefinition const & input_good = *it.key ();
131132 const fixed_point_t base_desired_quantity = it.value ();
132133 const ptrdiff_t i = it - input_goods.begin ();
133- const fixed_point_t desired_quantity = demand_per_input[i];
134134 fixed_point_t & good_stockpile = stockpile[&input_good];
135135
136136 // Consume input good
137137 fixed_point_t consumed_quantity = fixed_point_t::mul_div (
138- desired_quantity ,
138+ base_desired_quantity ,
139139 inputs_bought_numerator,
140140 inputs_bought_denominator
141141 );
@@ -161,7 +161,7 @@ void ArtisanalProducer::artisan_tick(
161161 good_stockpile - consumed_quantity
162162 );
163163
164- if (good_stockpile >= desired_quantity ) {
164+ if (good_stockpile >= demand_per_input[i] ) {
165165 wants_more_mask.set (input_good, false );
166166 distinct_goods_to_buy--;
167167 }
0 commit comments