@@ -68,7 +68,7 @@ void GoodMarket::add_market_sell_order(GoodMarketSellOrder&& market_sell_order)
6868void GoodMarket::execute_orders (
6969 IndexedFlatMap<CountryInstance, fixed_point_t >& reusable_country_map_0,
7070 IndexedFlatMap<CountryInstance, fixed_point_t >& reusable_country_map_1,
71- utility::forwardable_span <
71+ std::span <
7272 memory::vector<fixed_point_t >,
7373 VECTORS_FOR_EXECUTE_ORDERS
7474 > reusable_vectors
@@ -123,9 +123,9 @@ void GoodMarket::execute_orders(
123123 IndexedFlatMap<CountryInstance, fixed_point_t >& supply_per_country = reusable_country_map_0;
124124 IndexedFlatMap<CountryInstance, fixed_point_t >& actual_bought_per_country = reusable_country_map_1;
125125 for (GoodMarketSellOrder const & market_sell_order : market_sell_orders) {
126- CountryInstance const * const country_nullable = market_sell_order.country_nullable ;
127- if (country_nullable != nullptr ) {
128- supply_per_country.at (*country_nullable ) += market_sell_order.quantity ;
126+ const std::optional< size_t > country_index_optional = market_sell_order.country_index_optional ;
127+ if (country_index_optional. has_value () ) {
128+ supply_per_country.at_index (country_index_optional. value () ) += market_sell_order.quantity ;
129129 }
130130 supply_sum += market_sell_order.quantity ;
131131 }
@@ -191,10 +191,10 @@ void GoodMarket::execute_orders(
191191 continue ;
192192 }
193193
194- CountryInstance const * const country_nullable = buy_up_to_order.country_nullable ;
195- if (country_nullable != nullptr ) {
194+ const std::optional< size_t > country_index_optional = buy_up_to_order.country_index_optional ;
195+ if (country_index_optional. has_value () ) {
196196 // subtract as it might be updated below
197- actual_bought_per_country.at (*country_nullable ) -= distributed_supply;
197+ actual_bought_per_country.at_index (country_index_optional. value () ) -= distributed_supply;
198198 }
199199
200200 distributed_supply = fixed_point_t::mul_div (
@@ -210,8 +210,8 @@ void GoodMarket::execute_orders(
210210 purchasing_power_sum -= purchasing_power_per_order[i];
211211 }
212212
213- if (country_nullable != nullptr ) {
214- actual_bought_per_country.at (*country_nullable ) += distributed_supply;
213+ if (country_index_optional. has_value () ) {
214+ actual_bought_per_country.at_index (country_index_optional. value () ) += distributed_supply;
215215 }
216216
217217 if (someone_bought_max_quantity) {
@@ -278,9 +278,9 @@ void GoodMarket::execute_orders(
278278 buy_up_to_order.money_to_spend / new_price
279279 );
280280
281- CountryInstance const * const country_nullable = buy_up_to_order.country_nullable ;
282- if (country_nullable != nullptr ) {
283- actual_bought_per_country.at (*country_nullable ) += quantity_bought_per_order[i];
281+ const std::optional< size_t > country_index_optional = buy_up_to_order.country_index_optional ;
282+ if (country_index_optional. has_value () ) {
283+ actual_bought_per_country.at_index (country_index_optional. value () ) += quantity_bought_per_order[i];
284284 }
285285 }
286286
@@ -335,13 +335,14 @@ void GoodMarket::execute_orders(
335335
336336 fixed_point_t quantity_sold_domestically;
337337 fixed_point_t quantity_offered_as_export;
338- CountryInstance const * const country_nullable = market_sell_order.country_nullable ;
339- if (country_nullable == nullptr ) {
338+ const std::optional< size_t > country_index_optional = market_sell_order.country_index_optional ;
339+ if (!country_index_optional. has_value () ) {
340340 quantity_sold_domestically = 0 ;
341341 quantity_offered_as_export = quantity_offered;
342342 } else {
343- const fixed_point_t total_bought_domestically = actual_bought_per_country.at (*country_nullable);
344- const fixed_point_t total_domestic_supply = supply_per_country.at (*country_nullable);
343+ const size_t country_index = country_index_optional.value ();
344+ const fixed_point_t total_bought_domestically = actual_bought_per_country.at_index (country_index);
345+ const fixed_point_t total_domestic_supply = supply_per_country.at_index (country_index);
345346 quantity_sold_domestically = total_bought_domestically >= total_domestic_supply
346347 ? quantity_offered
347348 : fixed_point_t::mul_div (
@@ -416,15 +417,16 @@ void GoodMarket::execute_buy_orders(
416417 fixed_point_t ::epsilon // we know from purchasing power that you can afford it.
417418 );
418419
419- fixed_point_t money_spent_on_imports;
420- CountryInstance const * const country_nullable = buy_up_to_order.country_nullable ;
421- if (country_nullable == nullptr ) {
420+ fixed_point_t money_spent_on_imports;
421+ const std::optional< size_t > country_index_optional = buy_up_to_order.country_index_optional ;
422+ if (!country_index_optional. has_value () ) {
422423 // could be trade between native Americans and tribal Africa, so it's all imported
423424 money_spent_on_imports = money_spent_total;
424425 } else {
426+ const size_t country_index = country_index_optional.value ();
425427 // must be > 0, since quantity_bought > 0
426- const fixed_point_t actual_bought_in_my_country = actual_bought_per_country.at (*country_nullable );
427- const fixed_point_t supply_in_my_country = supply_per_country.at (*country_nullable );
428+ const fixed_point_t actual_bought_in_my_country = actual_bought_per_country.at_index (country_index );
429+ const fixed_point_t supply_in_my_country = supply_per_country.at_index (country_index );
428430
429431 if (supply_in_my_country >= actual_bought_in_my_country) {
430432 // no imports
0 commit comments