本文整理汇总了C++中Town::resistance方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::resistance方法的具体用法?C++ Town::resistance怎么用?C++ Town::resistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Town
的用法示例。
在下文中一共展示了Town::resistance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_trade_link
//----- Begin of function FirmMarket::update_trade_link -----//
//
// Update the status of links to harbors and towns based
// on the current trade treaty status.
//
void FirmMarket::update_trade_link()
{
Nation* ownNation = nation_array[nation_recno];
int tradeTreaty;
//------ update links to towns -----//
Town* townPtr;
for( int i=0 ; i<linked_town_count ; i++ )
{
townPtr = town_array[linked_town_array[i]];
if( !townPtr->nation_recno )
continue;
if( townPtr->nation_recno )
{
tradeTreaty = ownNation->get_relation(townPtr->nation_recno)->trade_treaty
|| townPtr->nation_recno==nation_recno;
}
else // if this is an independent town, it buys goods from the market if its resistance towards the nation is < 30
{
tradeTreaty = townPtr->resistance(nation_recno) <= INDEPENDENT_LINK_RESISTANCE;
}
if( linked_town_enable_array[i] != (tradeTreaty ? LINK_EE : LINK_DD) )
toggle_town_link( i+1, tradeTreaty, COMMAND_AUTO, 1 ); // 1-toggle both side
}
}
示例2: being_killed
//------- Begin of function Firm::being_killed ------//
//
// <BaseObj*> attackerObj - this can be NULL if the attacker no longer
// exists (the damage is caused by a bullet.)
//
void Firm::being_killed(BaseObj* attackerObj)
{
se_res.sound(center_x, center_y, 1, 'F', firm_id, "DIE" );
if( nation_recno == nation_array.player_recno && attackerObj ) //BUGHERE
news_array.firm_destroyed(firm_recno, attackerObj);
// ######## begin Gilbert 17/6 ########//
if( nation_recno == 0 && firm_id == FIRM_LAIR && is_monster() )
{
news_array.monster_firm_destroyed( monster_id(), center_x, center_y );
}
// ######## end Gilbert 17/6 ########//
if( nation_recno )
{
if( attackerObj && attackerObj->nation_recno )
nation_array[attackerObj->nation_recno]->enemy_firm_destroyed++;
if( nation_recno )
nation_array[nation_recno]->own_firm_destroyed++;
}
//-----------------------------------------//
if( attackerObj && attackerObj->nation_recno )
{
Nation* attackerNation = nation_array[attackerObj->nation_recno];
//-- destroying a monster firm raise the attacking nation's reputation --//
if( is_monster() )
{
float repIncrease = (float) max_hit_points() / 600;
//-- if the lair is enslaving the towns, increase the reputation bonus --//
if( cast_to_FirmLair() )
{
int tributeAmount = cast_to_FirmLair()->collect_town_tribute(0);
repIncrease += (float) tributeAmount / 600;
}
attackerNation->change_reputation(repIncrease);
//--- when destroying an enslaving Fryhtan lair, the independent towns enslaved by it will reduce its resistance towards you by 30 points ---//
if( cast_to_FirmLair() )
{
int i;
Town* townPtr;
for( i=0 ; i<linked_town_count ; i++ )
{
if(town_array.is_deleted(linked_town_array[i]))
continue;
townPtr = town_array[linked_town_array[i]];
//--- if it is a linked independent town ---//
if( townPtr->nation_recno == 0 &&
// ####### begin Gilbert 9/3 ########//
nation_recno &&
// ####### end Gilbert 9/3 ########//
townPtr->resistance(nation_recno) < MONSTER_COLLECT_TOWN_TRIBUTE_LOYALTY )
{
townPtr->change_resistance(attackerObj->nation_recno, -30);
}
}
}
}
//------ destroyng a building gives money ------//
float killMoney = (float) (firm_res[firm_id]->setup_cost + firm_recno%100) / 3; // add some randomness
attackerNation->add_income( INCOME_TREASURE, killMoney );
attackerNation->increased_cash = killMoney;
}
firm_array.del_firm(firm_recno);
}
示例3: think_export_product
//------- Begin of function FirmMarket::think_export_product -----------//
//
// Think about exporting products from this market to another market.
//
int FirmMarket::think_export_product()
{
//--- first check if there is any excessive supply for export ---//
int exportProductId = 0;
MarketGoods *marketGoods = market_goods_array;
for( int i=0 ; i<MAX_MARKET_GOODS ; i++, marketGoods++ )
{
if( marketGoods->product_raw_id )
{
if( marketGoods->stock_qty > MAX_MARKET_STOCK * 3 / 4 &&
marketGoods->month_demand < marketGoods->supply_30days() / 2 ) // the supply is at least double of the demand
{
exportProductId = marketGoods->product_raw_id;
break;
}
}
}
if( !exportProductId )
return 0;
//----- locate for towns that do not have the supply of the product ----//
Town* townPtr;
Nation* nationPtr = nation_array[nation_recno];
for( int townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
{
if( town_array.is_deleted(townRecno) )
continue;
townPtr = town_array[townRecno];
if( townPtr->population < 20 - (10*nationPtr->pref_trading_tendency/100) ) // 10 to 20 as the minimum population for considering trade
continue;
if( townPtr->has_product_supply[exportProductId-1] ) // if the town already has the supply of product, return now
continue;
if( townPtr->region_id != region_id )
continue;
if( townPtr->no_neighbor_space ) // if there is no space in the neighbor area for building a new firm.
continue;
if( m.points_distance( center_x, center_y, townPtr->center_x, center_y ) > MAX_WORLD_X_LOC/4 ) // don't consider if it is too far away
continue;
if( townPtr->town_recno &&
nationPtr->get_relation_status(townPtr->town_recno) < RELATION_FRIENDLY ) // only build markets to friendly nation's town
{
continue;
}
//-----------------------------------------//
if( townPtr->nation_recno )
{
//--- if it's a nation town, only export if we have trade treaty with it ---//
if( !nationPtr->get_relation(townPtr->nation_recno)->trade_treaty )
continue;
}
else
{
//--- if it's an independent town, only export if the resistance is low ---//
if( townPtr->resistance(nation_recno) > INDEPENDENT_LINK_RESISTANCE )
continue;
}
}
return 0;
}
示例4: find_best_place_loc
//.........这里部分代码省略.........
weightAdd = 40;
}
}
refCX1 = firmPtr->loc_x1-distance ; // add negative weights on space around this firm
refCY1 = firmPtr->loc_y1-distance ; // so to prevent firms from building right next to the firm
refCX2 = firmPtr->loc_x2+distance ; // and leave some space for walking path.
refCY2 = firmPtr->loc_y2+distance ;
weightReduce = 20;
}
//------- if there is a town on the location ------//
else if( locPtr->is_town() )
{
townPtr = town_array[locPtr->town_recno()];
effectiveDis = world.effective_distance(0, buildFirmId);
refBX1 = townPtr->center_x - effectiveDis;
refBY1 = townPtr->center_y - effectiveDis;
refBX2 = townPtr->center_x + effectiveDis;
refBY2 = townPtr->center_y + effectiveDis;
weightAdd = townPtr->population*2;
//----- if the town is not our own -----//
if(townPtr->nation_recno != nation_recno)
{
if( townPtr->nation_recno==0 ) // it's an independent town
weightAdd = weightAdd * ( 100-(int)townPtr->resistance(nation_recno) ) / 100;
else // more friendly nations get higher weights
{
int relationStatus = get_relation_status(townPtr->nation_recno);
if( relationStatus >= RELATION_NEUTRAL )
weightAdd = weightAdd * (relationStatus-RELATION_NEUTRAL+1) / 4;
}
}
refCX1 = townPtr->loc_x1-distance ; // add negative weights on space around this firm
refCY1 = townPtr->loc_y1-distance ; // so to prevent firms from building right next to the firm
refCX2 = townPtr->loc_x2+distance ; // and leave some space for walking path.
refCY2 = townPtr->loc_y2+distance ;
weightReduce = 100;
}
else
continue;
//------ add weights to the matrix ------//
if( weightAdd )
{
for( yLocB=max(refY1,refBY1) ; yLocB<=min(refY2,refBY2) ; yLocB++ )
{
xLocB = max(refX1,refBX1);
refMatrixPtr = refMatrix + (yLocB-refY1)*refWidth + (xLocB-refX1);
for( ; xLocB<=min(refX2,refBX2) ; xLocB++ )
{
*refMatrixPtr++ += weightAdd;
}