本文整理汇总了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;
}