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


C++ CvPlot::seeThroughLevel方法代码示例

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


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

示例1: CanSeeDisplacementPlot_Strict

//	---------------------------------------------------------------------------
//	Test if the team can see from the supplied hex to a displacement in HEXSPACE
//	from the start hex.
//	This is the strict version that prevents you from seeing through partially blocked hexes
//	after a certain distance threshold is reached.  Even when below the distance threshold
//	more than one blockage will cause the LOS to fail.
static bool CanSeeDisplacementPlot_Strict(int startX, int startY, int dx, int dy, int fromLevel)
{
	int originalDX = dx;
	int originalDY = dy;

	CvMap& kMap = GC.getMap();

	// Use Bresenham's line algorithm, with a slight modification, to step through the cells.
	// The modification is that if we are stepping in the upper-right or lower-left quadrant,
	// and we need to take a step on the 'short' axis, we will check the plot with just the
	// adjustment to the X axis, before we do the normal check for the step on the X and Y
	// axis.  This is needed because in those quadrants a change on both the X and Y axis 
	// is not contiguous.

	// Because the hex grid is low-resolution, checks are also made to allow the ray to continue 
	// around a blockage if that blockage obscures only part of the next hex cell along the ray.
	// This is done by 'looking back' at the alternate path the ray could have taken as it is 
	// traversing the hex grid.

	// Make DX and DY positive and adjust the step constant for the opposite axis.
	int stepY;
	if (dy < 0) 
	{ 
		dy = -dy;  
		stepY = -1; 
	} 
	else 
		stepY = 1; 

	int stepX;
	if (dx < 0) 
	{ 
		dx = -dx;  
		stepX = -1; 
	} 
	else 
		stepX = 1;

	dy <<= 1;
	dx <<= 1;

	int currentDX = 0;
	int currentDY = 0;

	// If in an odd quadrant, stepping down on the short axis requires two checks to be contiguous
	bool oddQuadrant = stepX != stepY;
	// Is the line going to go such that it travels through the centers of the hexes?
	// If so, we don't have to worry about testing to see if we can look around blocked hexes.
	bool straightThrough = dx == 0 || dy == 0;

	// Start from the next cell after the source plot
	int lastDX = currentDX;
	int lastDY = currentDY;
	int lookbackDirection = -1;
	int stepCount = 0;
	int iBlockedCount = 0;

	// If dx is greater than dy, scan along the x axis, adjusting the Y as needed
	if (dx > dy) 
	{
		int shortAxisStepFactor = (dx >> 1); 
		while (currentDX != originalDX) 
		{
			shortAxisStepFactor += dy;

			if (shortAxisStepFactor >= dx) 
			{
				shortAxisStepFactor -= dx;

				if (oddQuadrant)
				{
					currentDX += stepX;
					currentDY += stepY;
				}
				else
				{
					currentDX += stepX;

					// Look back to see if we were possibly blocked by the alternate route to this hex.  We will ignore the check if inside the rings that allow the user to look around obstacles.
					if (!straightThrough && lookbackDirection != -1)
					{
						CvPlot* passThroughPlot = PlotFromHex(kMap, startX + currentDX + ms_LookBackX[lookbackDirection], startY + currentDY + ms_LookBackY[lookbackDirection]);
						TRACK_LAST_TARGET_PATH_ENTRY(passThroughPlot);
						if(!passThroughPlot || fromLevel < passThroughPlot->seeThroughLevel())
						{
							++iBlockedCount;
							if (stepCount > STRICT_LOOSE_CUTOFF || iBlockedCount >= 2)
								return false;
						}
					}

					// Don't test the destination, we only want to test the plots between the start and the destination
					if (currentDX == originalDX && currentDY == originalDY)
						break;	
//.........这里部分代码省略.........
开发者ID:GravitasShortfall,项目名称:Community-Patch-DLL,代码行数:101,代码来源:CvTargeting.cpp


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