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


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

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


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

示例1: settle

//--------- Begin of function TownArray::settle --------//
//
// A unit settles on a given location and form a town town.
//
// return: <int> 1 - settled and a town town is formed successfully.
//					  0 - settling failed. too close to a town of another nation.
//
int TownArray::settle(int unitRecno, int xLoc, int yLoc)
{
	if(!world.can_build_town(xLoc, yLoc, unitRecno))
		return 0;

	//--------- get the nearest town town ------------//

	Unit* unitPtr = unit_array[unitRecno];

	char nationRecno = unitPtr->nation_recno;

	//----- it's far enough to form another town --------//

	int townRecno = town_array.add_town( nationRecno, unitPtr->race_id, xLoc, yLoc );

	//---------- init town population ----------//

	Town* townPtr = town_array[townRecno];

	//----------------------------------------------------//
	// if the settle unit is standing in the town area
	// cargo_recno of that location is unchange in town_array.add_town
	// so update the location now
	//----------------------------------------------------//

	short uXLoc = unitPtr->next_x_loc();
	short uYLoc = unitPtr->next_y_loc();
	Location *locPtr = world.get_loc(uXLoc, uYLoc);

	townPtr->assign_unit(unitRecno);

	if( uXLoc>=townPtr->loc_x1 && uXLoc<=townPtr->loc_x2 && uYLoc>=townPtr->loc_y1 && uYLoc<=townPtr->loc_y2 )
		locPtr->set_town(townPtr->town_recno);

#ifdef DEBUG
	// make sure cargo recno is set to town's
	for( uYLoc = townPtr->loc_y1; uYLoc <= townPtr->loc_y2; ++uYLoc)
	{
		for( uXLoc = townPtr->loc_x1; uXLoc <= townPtr->loc_x2; ++uXLoc)
		{
			err_when( world.get_loc(uXLoc, uYLoc)->town_recno() != townPtr->town_recno );
		}
	}
#endif

	townPtr->update_target_loyalty();

	//--------- hide the unit from the map ----------//

	return 1;
}
开发者ID:brianV,项目名称:7kaa,代码行数:58,代码来源:OTOWNA.cpp


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