本文整理汇总了C++中Town::update_product_supply方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::update_product_supply方法的具体用法?C++ Town::update_product_supply怎么用?C++ Town::update_product_supply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Town
的用法示例。
在下文中一共展示了Town::update_product_supply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: think_import_new_product
//------- Begin of function FirmMarket::think_import_new_product ------//
//
// Think about importing goods to sell in this market place.
//
int FirmMarket::think_import_new_product()
{
//--- update what products are needed for this market place ---//
int i, j;
Town* townPtr;
short needProductSupplyPop[MAX_PRODUCT]; // the total population in the towns linked to the market that needs the supply of the product
Nation* nationPtr = nation_array[nation_recno];
memset( needProductSupplyPop, 0, sizeof(needProductSupplyPop) );
for( i=0; i<linked_town_count; i++ )
{
err_when(!linked_town_array[i] || town_array.is_deleted(linked_town_array[i]));
if( linked_town_enable_array[i] != LINK_EE )
continue;
townPtr = town_array[linked_town_array[i]];
if( townPtr->region_id != region_id )
continue;
if( !townPtr->is_base_town ) // don't import if it isn't a base town
continue;
//------------------------------------------------//
//
// Only if the population of the town is equal or
// larger than minTradePop, the AI will try to do trade.
// The minTradePop is between 10 to 20 depending on the
// pref_trading_tendency.
//
//------------------------------------------------//
townPtr->update_product_supply();
for( j=0 ; j<MAX_PRODUCT ; j++ )
{
if( !townPtr->has_product_supply[j] )
needProductSupplyPop[j] += townPtr->population;
}
}
//---- think about importing the products that need supply ----//
int minTradePop = 10;
for( int productId=1 ; productId<=MAX_PRODUCT ; productId++ )
{
if( needProductSupplyPop[productId-1] >= minTradePop )
{
if( think_import_specific_product(productId) )
{
last_import_new_goods_date = info.game_date;
return 1;
}
}
}
//----------------------------------------------------------//
// Think about importing the raw materials of the needed
// products and build factories to manufacture them ourselves
//----------------------------------------------------------//
//--- first check if we can build a new factory to manufacture the products ---//
if( is_market_linked_to_town(1) ) // 1-only count towns that are our own and are base towns
{
if( !no_neighbor_space &&
nationPtr->total_jobless_population >= MAX_WORKER*2 &&
can_hire_caravan() >= 2 ) // if there is a shortage of caravan supplies, use it for transporting finished products instead of raw materials
{
if( nationPtr->can_ai_build(FIRM_FACTORY) )
{
for( int productId=1 ; productId<=MAX_PRODUCT ; productId++ )
{
if( needProductSupplyPop[productId-1] >= minTradePop )
{
if( think_mft_specific_product(productId) )
{
last_import_new_goods_date = info.game_date;
return 1;
}
}
}
}
}
}
return 0;
}