当前位置: 首页>>代码示例>>C++>>正文


C++ Town::tribute_to_lair方法代码示例

本文整理汇总了C++中Town::tribute_to_lair方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::tribute_to_lair方法的具体用法?C++ Town::tribute_to_lair怎么用?C++ Town::tribute_to_lair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Town的用法示例。


在下文中一共展示了Town::tribute_to_lair方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: invoke_camp_defense

//-------- Begin of function Place::invoke_camp_defense ---------//
//
// Call out defenders from neighboring camps to help.
//
void Place::invoke_camp_defense(BaseObj* attackerObj)
{
	if( !attackerObj )
		return;

	//----- if this is an independent town -----//

	if( !nation_recno )
	{
		//---- if this is a slave town ----//

		if( cast_to_Town() && cast_to_Town()->is_pay_tribute_to_monster() )
		{
			//---- reckon the net attacking power in the battling area ----//

			int hasWar;			// ref var for returning the result

			int netAttackerPower = world.net_attacker_power_in_area(center_x, center_y,
									  attackerObj->nation_recno, nation_recno, 0, hasWar, EFFECTIVE_DEFEND_DISTANCE);

			//-- no need to call for reinforcement if the defense force is more powerful than the attacking force --//

			if( netAttackerPower <= 0 )
				return;

			//------ call enslaving lair's AI to protect it ------//

			Town* thisTown = cast_to_Town();

			for( int i=0 ; i<thisTown->linked_firm_count ; i++ )
			{
				//--- if this linked firm is a lair enslaving the town ---//

				if( thisTown->tribute_to_lair( thisTown->linked_firm_array[i], 1 ) )
				{
					FirmLair* firmLair = firm_array[ thisTown->linked_firm_array[i] ]->cast_to_FirmLair();

					if( firmLair && firmLair->is_ai )
						firmLair->invoke_defense(attackerObj, netAttackerPower);
				}
			}
		}

		return;
	}

	//---- reckon the net attacking power in the battling area ----//

	int hasWar;			// ref var for returning the result

	int netAttackerPower = world.net_attacker_power_in_area(center_x, center_y,
							  attackerObj->nation_recno, nation_recno, 0, hasWar, EFFECTIVE_DEFEND_DISTANCE);

	//-- no need to call for reinforcement if the defense force is more powerful than the attacking force --//

	if( netAttackerPower <= 0 )
		return;

	//--------- call for reinforcement now -------//

	for( int i=firm_array.size() ; i>0 ; i-- )
	{
		if( firm_array.is_deleted(i) )
			continue;

		Firm* firmPtr = firm_array[i];

		//--- look for our camp ----//

		// ###### begin Gilbert 15/4 #########//
		// if( !firmPtr->cast_to_FirmCamp() || firmPtr->nation_recno!=nation_recno )
		if( !firmPtr->cast_to_FirmCamp() || firmPtr->nation_recno!=nation_recno || nation_recno == 0 )
		// ###### end Gilbert 15/4 #########//
			continue;

		//--- only if the camp's within the effective defense distance ---//

		if( misc.points_distance(firmPtr->center_x, firmPtr->center_y, center_x, center_y )
			 > EFFECTIVE_DEFEND_DISTANCE )
		{
			continue;
		}

		//----- ask the camp to send out defenders now ------//

		int defensePower = firmPtr->cast_to_FirmCamp()->invoke_defense(attackerObj, netAttackerPower);

		netAttackerPower -= defensePower;

		if( netAttackerPower <= 0 )
			break;
	}
}
开发者ID:112212,项目名称:7k2,代码行数:97,代码来源:oplace.cpp


注:本文中的Town::tribute_to_lair方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。