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


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

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


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

示例1: recruit_peasant

//--------- Begin of function Nation::recruit_peasant --------//
//
// <int>		raceId  - the race the selected unit should have
//							 (0 for any races)
//	<short>	destX	  - the x location the unit will move to
//	<short>	destY	  - the y location the unit will move to
//
// <int&>   recruitTownRecno - the recno of the town where this unit is recruited.
//
// return: <int> recno of the unit recruited.
//
int Nation::recruit_peasant(int raceId, short destX, short destY, int& recruitTownRecno)
{
	//----- locate the best town for training the unit -----//

	int 	 i;
	Town	 *townPtr;
	int	 curDist, curRating, bestRating=0;
	int    destRegionId = world.get_loc(destX, destY)->region_id;

	recruitTownRecno = 0;

	for(i=0; i<ai_town_count; i++)
	{
		townPtr = town_array[ai_town_array[i]];

		if( !townPtr->jobless_population ||	// no jobless population or currently a unit is being trained
			 !townPtr->can_recruit_peasant() )
		{
			continue;
		}

		if( townPtr->region_id != destRegionId )
			continue;

		if( raceId && townPtr->race_id != raceId )
			continue;

		//--------------------------------------//

		curDist = m.points_distance(townPtr->center_x, townPtr->center_y, destX, destY);

		curRating = 100-100*curDist/MAX_WORLD_X_LOC;

		if( curRating > bestRating )
		{
			bestRating 	   = curRating;
			recruitTownRecno = townPtr->town_recno;
		}
	}

	if( !recruitTownRecno )
		return 0;

	//--- if the chosen race is not recruitable, pick any recruitable race ---//

	townPtr = town_array[recruitTownRecno];

	if( !townPtr->can_recruit_peasant() )
	{
		//---- if the loyalty is too low to recruit, grant the town people first ---//

		if( cash > 0 && townPtr->accumulated_reward_penalty < 10 )
			townPtr->reward(COMMAND_AI);

		//---- if the loyalty is still too low, return now ----//

		if( !townPtr->can_recruit_peasant() )
			return 0;
	}

	return townPtr->recruit(0, COMMAND_AI);	// 0-not recruit wagon
}
开发者ID:mecirt,项目名称:7k2,代码行数:73,代码来源:oai_unit.cpp


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