本文整理汇总了C++中Map::GetResourceMapSpotsPositions方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetResourceMapSpotsPositions方法的具体用法?C++ Map::GetResourceMapSpotsPositions怎么用?C++ Map::GetResourceMapSpotsPositions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map::GetResourceMapSpotsPositions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindClosestMetalExtractionSite
///Maybe we should look into Voronoi diagrams to optimize this :P
///@return the closest metal spot to a given position
SAIFloat3 ConstructionUnitGroup::FindClosestMetalExtractionSite(SAIFloat3 pos, bool checkIfItBlocks/*, Resource* metal */ )
{
ai->utility->Log(ALL, MISC, "FindClosestMetalExtractionSite...");
UnitDef *mexDef = ai->utility->GetMexDef();
if (ai->utility->IsMetalMap())
{
ai->utility->Log(ALL, MISC, "FindClosestMetalExtractionSite on MetalMap");
//If this is an all-metal map, we can safely fallback to use FindClosestNonConflictingBuildSite
return FindClosestNonConflictingBuildSite(mexDef, pos, 1000, 0, 0);
//return ai->callback->GetMap()->FindClosestBuildSite( *mexDef, pos, 1000, 0, 0);
}
vector<SAIFloat3> spots;
Map *map = ai->callback->GetMap();
spots = map->GetResourceMapSpotsPositions( *(ai->utility->GetResource("Metal")), &pos );
int numSpots = spots.size();
int lowestIdx = -1;
float closest = 9999999.9f;
for ( int i = 0 ; i < numSpots ; i++ )
{
//u->ChatMsg( "Metal spot: x: %f y: %f z: %f", spots[i].x, spots[i].y, spots[i].z );
double distance = ai->utility->EuclideanDistance( spots[i], pos );
//u->ChatMsg( "Distance: %f", distance );
if ( distance < closest
&& map->IsPossibleToBuildAt( *(ai->utility->GetMexDef()), spots[i], 0 )
&& (!checkIfItBlocks || !BuildBlocksSelf(mexDef, spots[i], 0)) )
{
closest = distance;
lowestIdx = i;
}
}
delete map;
///TODO: What if we didn't find an accaptable spot? (lowestIdx=-1)
if(lowestIdx == -1)
{
// we didnt find a spot
return (SAIFloat3) {0,-1,0};
}
pos = spots[lowestIdx];
return pos;
}