#include "GoodInstance.hpp" using namespace OpenVic; GoodInstance::GoodInstance(GoodDefinition const& new_good_definition) : HasIdentifierAndColour { new_good_definition }, good_definition { new_good_definition }, price { new_good_definition.get_base_price() }, is_available { new_good_definition.get_is_available_from_start() }, supply_running_total { fixed_point_t::_0() }, total_supply_yesterday { fixed_point_t::_0() }, market_sell_order_quantities {}, market_sell_order_callbacks {} {} void GoodInstance::add_buy_up_to_order( const fixed_point_t max_quantity, const fixed_point_t money_to_spend, const std::function callback ) { demand_running_total += max_quantity; buy_up_to_order_max_quantities.push_back(max_quantity); buy_up_to_order_money_to_spend.push_back(money_to_spend); buy_up_to_order_callbacks.push_back(callback); } void GoodInstance::add_market_sell_order(const fixed_point_t quantity, const std::function callback) { supply_running_total += quantity; market_sell_order_quantities.push_back(quantity); market_sell_order_callbacks.push_back(callback); } void GoodInstance::clear_orders() { total_demand_yesterday = demand_running_total; demand_running_total = fixed_point_t::_0(); total_supply_yesterday = supply_running_total; supply_running_total = fixed_point_t::_0(); buy_up_to_order_max_quantities.clear(); buy_up_to_order_callbacks.clear(); market_sell_order_quantities.clear(); market_sell_order_callbacks.clear(); } bool GoodInstanceManager::setup(GoodDefinitionManager const& good_definition_manager) { if (good_instances_are_locked()) { Logger::error("Cannot set up good instances - they are already locked!"); return false; } good_instances.reserve(good_definition_manager.get_good_definition_count()); bool ret = true; for (GoodDefinition const& good : good_definition_manager.get_good_definitions()) { ret &= good_instances.add_item({ good }); } lock_good_instances(); return ret; }