本文整理汇总了C++中Town::auto_defense方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::auto_defense方法的具体用法?C++ Town::auto_defense怎么用?C++ Town::auto_defense使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Town
的用法示例。
在下文中一共展示了Town::auto_defense方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: auto_defense
//--------- Begin of function FirmInn::auto_defense ---------//
void FirmInn::auto_defense(short targetRecno)
{
//---------- the area to check -----------//
int xLoc1 = center_x - EFFECTIVE_FIRM_TOWN_DISTANCE;
int yLoc1 = center_y - EFFECTIVE_FIRM_TOWN_DISTANCE;
int xLoc2 = center_x + EFFECTIVE_FIRM_TOWN_DISTANCE;
int yLoc2 = center_y + EFFECTIVE_FIRM_TOWN_DISTANCE;
//----------- boundary checking ----------//
if(xLoc1<0) xLoc1 = 0;
if(yLoc1<0) yLoc1 = 0;
if(xLoc2>=MAX_WORLD_X_LOC) xLoc2 = MAX_WORLD_X_LOC-1;
if(yLoc2>=MAX_WORLD_Y_LOC) yLoc2 = MAX_WORLD_Y_LOC-1;
int skipWidthDist = STD_TOWN_LOC_WIDTH;
int skipHeightDist = STD_TOWN_LOC_HEIGHT;
int xEnd, yEnd, xLimit, yLimit;
int i, j, dist;
Location *locPtr;
Town *townPtr;
//--------------------------------------------------//
// check for our town in the effective area
//--------------------------------------------------//
xLimit = xLoc2+skipWidthDist-1;
yLimit = yLoc2+skipHeightDist-1;
for(xEnd=0, i=xLoc1; i<=xLimit && !xEnd; i+=skipWidthDist)
{
if(i>=xLoc2)
{
xEnd++; // final
i = xLoc2;
}
for(yEnd=0, j=yLoc1; j<=yLimit && !yEnd; j+=skipHeightDist)
{
if(j>=yLoc2)
{
yEnd++; // final
j = yLoc2;
}
err_when(i<xLoc1 || i>xLoc2 || j<yLoc1 || j>yLoc2);
locPtr = world.get_loc(i, j);
if(!locPtr->is_town())
continue;
err_when(!locPtr->town_recno() || town_array.is_deleted(locPtr->town_recno()));
townPtr = town_array[locPtr->town_recno()];
if(townPtr->nation_recno!=nation_recno)
continue;
dist = misc.points_distance(center_x, center_y, townPtr->center_x, townPtr->center_y);
if(dist <= EFFECTIVE_FIRM_TOWN_DISTANCE)
townPtr->auto_defense(targetRecno);
}
}
}