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


C++ float3::distance2D方法代码示例

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


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

示例1: SearchOffsetComparator

/*
// Callback Clone Functions
const int SQUARE_SIZE = 8;
#include <algorithm>
// Stolen directly from ALCallback.cpp
struct SearchOffset {
	int dx,dy;
	int qdist; // dx*dx+dy*dy
};
// Stolen directly from ALCallback.cpp
bool SearchOffsetComparator (const SearchOffset& a, const SearchOffset& b)
{	return a.qdist < b.qdist;	}
// Stolen directly from ALCallback.cpp
const vector<SearchOffset>& GetSearchOffsetTable (int radius)
{	static vector <SearchOffset> searchOffsets;
	int size = radius*radius*4;
	if (size > searchOffsets.size()) {
		searchOffsets.resize (size);
		for (int y=0;y<radius*2;y++)
			for (int x=0;x<radius*2;x++)
			{	SearchOffset& i = searchOffsets[y*radius*2+x];
				i.dx = x-radius;
				i.dy = y-radius;
				i.qdist = i.dx*i.dx+i.dy*i.dy;
			}
		sort (searchOffsets.begin(), searchOffsets.end(), SearchOffsetComparator);
	}
	return searchOffsets;
}
float3 cBuilderPlacement::ClosestBuildSite(const UnitDef* ud, float3 p, float sRadius, int facing)
{
	if (!ud) return float3(-1.0f,0.0f,0.0f);
	int endr = (int)(sRadius/(SQUARE_SIZE*2));
	const vector<SearchOffset>& ofs = GetSearchOffsetTable (endr);
	for(int so=0;so<endr*endr*4;so++)
	{
		float x = p.x+ofs[so].dx*SQUARE_SIZE*2;
		float z = p.z+ofs[so].dy*SQUARE_SIZE*2;
		if( cb->CanBuildAt(ud,float3(x,0,z),facing) )
		{
			return float3(x,0,z);
		}
	}
	return float3(-1.0f,0.0f,0.0f);
}
*/
bool cBuilderPlacement::FindWeaponPlacement(UnitInfo *U, float3& position)
{
	if( U->BuildQ->creationUD->WeaponGuardRange == 0 )
		return false;

	if( U->BuildQ->creationUD->ud->minWaterDepth < 0 && U->BuildQ->creationUD->WeaponSeaEff.BestRange > 0 )
	{
		int iS = G->TM->GetSectorIndex(position);
		if( !G->TM->sector[iS].isWater )
			position = G->TM->GetClosestSector(G->TM->waterSectorType,iS)->position;
		return true;
	}

	int BID = -1;
	float3 buildPosition;
	for(map<int,UnitInfo*>::iterator i=G->UImmobile.begin(); i!=G->UImmobile.end(); ++i )
	{
		buildPosition = cb->GetUnitPos(i->first);
		if( i->second->udr->WeaponGuardRange == 0 && int(i->second->UDefences.size()) == 0 &&
			CanBuildAt(U,position,buildPosition) && CanBeBuiltAt(U->BuildQ->creationUD,buildPosition,i->second->udr->WeaponGuardRange) )
			if( BID == -1 || position.distance2D(buildPosition) < position.distance2D(cb->GetUnitPos(BID)) )
				BID = i->first;
	}

	if( BID > 0 )
	{
		position = cb->GetUnitPos(BID);
		return true;
	}

	return false;
}
开发者ID:9heart,项目名称:spring,代码行数:78,代码来源:BuilderPlacement.cpp

示例2: MoveAlongPath

// give move orders to units along previously generated pathToTarget
void CAttackGroup::MoveAlongPath(float3& groupPosition, int numUnits) {
	const int maxStepsAhead = 8;
	int pathMaxIndex = (int) pathToTarget.size() - 1;
	int step1 = std::min(pathIterator + maxStepsAhead / 2, pathMaxIndex);
	int step2 = std::min(pathIterator + maxStepsAhead, pathMaxIndex);

	const float3& moveToHereFirst = pathToTarget[step1];
	const float3& moveToHere = pathToTarget[step2];

	// if we aren't there yet
	if (groupPosition.distance2D(pathToTarget[pathMaxIndex]) > GROUP_DESTINATION_SLACK) {
		// TODO: give a group the order instead of each unit
		assert(numUnits >= 0);

		for (unsigned int i = 0; i < (unsigned int)numUnits; i++) {
			CUNIT* unit = ai->GetUnit(units[i]);

			if (ai->cb->GetUnitDef(unit->uid) != NULL) {
				// TODO: when they are near target, change this so they eg. line up
				// while some are here and some aren't, there's also something that
				// should be done with the units in front that are given the same
				// order+shiftorder and skittle around back and forth meanwhile if
				// the single unit isn't there yet
				if ((unit->pos()).distance2D(pathToTarget[pathMaxIndex]) > UNIT_DESTINATION_SLACK) {
					unit->Move(moveToHereFirst);

					if (moveToHere != moveToHereFirst) {
						unit->MoveShift(moveToHere);
					}
				}
			}
		}

		// if group is as close as the pathiterator-indicated target
		// is to the end of the path, increase pathIterator

		pathIterator = 0;
		float3 endOfPathPos = pathToTarget[pathMaxIndex];
		float groupDistanceToEnemy = groupPosition.distance2D(endOfPathPos);
		float pathIteratorTargetDistanceToEnemy = pathToTarget[pathIterator].distance2D(endOfPathPos);
		int increment = maxStepsAhead / 2;

		while (groupDistanceToEnemy <= pathIteratorTargetDistanceToEnemy && pathIterator < pathMaxIndex) {
			pathIterator = std::min(pathIterator + increment, pathMaxIndex);
			pathIteratorTargetDistanceToEnemy = pathToTarget[pathIterator].distance2D(endOfPathPos);
		}

		pathIterator = std::min(pathIterator, pathMaxIndex);
	}
	else {
		// group thinks it has arrived at the destination
		this->ClearTarget();
	}
}
开发者ID:rlcevg,项目名称:KAIK,代码行数:55,代码来源:AttackGroup.cpp

示例3: DistanceToBase

float CAttackHandler::DistanceToBase(float3 pos) {
	float closestDistance = FLT_MAX;
	for(int i = 0; i < this->kMeansK; i++) {
		float3 mean = this->kMeansBase[i];
		float distance = pos.distance2D(mean);
		closestDistance = min(distance, closestDistance);
	}
	return closestDistance;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:9,代码来源:AttackHandler.cpp

示例4: NextWaypoint

/*
Removes and return the next waypoint in the multipath corresponding to given id.
*/
float3 CPathManager::NextWaypoint(unsigned int pathId, float3 callerPos, float minDistance, int numRetries) {
	SCOPED_TIMER("AI:PFS");

	//0 indicate a no-path id.
	if(pathId == 0)
		return float3(-1,-1,-1);

	if(numRetries>4)
		return float3(-1,-1,-1);

	//Find corresponding multipath.
	std::map<unsigned int, MultiPath*>::iterator pi = pathMap.find(pathId);
	if(pi == pathMap.end())
		return float3(-1,-1,-1);
	MultiPath* multiPath = pi->second;

	if(callerPos==ZeroVector){
		if(!multiPath->detailedPath.path.empty())
			callerPos=multiPath->detailedPath.path.back();
	}

	//check if detailed path need bettering
	if(!multiPath->estimatedPath.path.empty()
	&& (multiPath->estimatedPath.path.back().distance2D(callerPos) < MIN_DETAILED_DISTANCE * SQUARE_SIZE
	|| multiPath->detailedPath.path.size() <= 2)){

		if(!multiPath->estimatedPath2.path.empty()		//if so check if estimated path also need bettering
			&& (multiPath->estimatedPath2.path.back().distance2D(callerPos) < MIN_ESTIMATE_DISTANCE * SQUARE_SIZE
			|| multiPath->estimatedPath.path.size() <= 2)){
				Estimate2ToEstimate(*multiPath, callerPos);
		}

		if(multiPath->caller)
			multiPath->caller->UnBlock();
		EstimateToDetailed(*multiPath, callerPos);
		if(multiPath->caller)
			multiPath->caller->Block();
	}

	//Repeat until a waypoint distant enought are found.
	float3 waypoint;
	do {
		//Get next waypoint.
		if(multiPath->detailedPath.path.empty()) {
			if(multiPath->estimatedPath2.path.empty() && multiPath->estimatedPath.path.empty())
				return multiPath->finalGoal;
			else
				return NextWaypoint(pathId,callerPos,minDistance,numRetries+1);
		} else {
			waypoint = multiPath->detailedPath.path.back();
			multiPath->detailedPath.path.pop_back();
		}
	} while(callerPos.distance2D(waypoint) < minDistance && waypoint != multiPath->detailedPath.pathGoal);

	return waypoint;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:59,代码来源:PathManager.cpp

示例5: TaskPlanCreate

void CUnitHandler::TaskPlanCreate(int builder, float3 pos, const UnitDef* builtdef) {
	UnitCategory category = ai->ut->GetCategory(builtdef);

	// HACK
	if (category >= CAT_LAST) {
		return;
	}

	// find this builder
	BuilderTracker* builderTracker = GetBuilderTracker(builder);

	// make sure this builder is free
	bool b1 = (builderTracker->taskPlanId == 0);
	bool b2 = (builderTracker->buildTaskId == 0);
	bool b3 = (builderTracker->factoryId == 0);

	if (!b1 || !b2 || !b3) {
		return;
	}


	bool existingTP = false;
	for (std::list<TaskPlan>::iterator i = TaskPlans[category].begin(); i != TaskPlans[category].end(); i++) {
		if (pos.distance2D(i->pos) < 20.0f && builtdef == i->def) {
			// make sure there are no other TaskPlans
			if (!existingTP) {
				existingTP = true;
				TaskPlanAdd(&*i, builderTracker);
			} else {
				std::stringstream msg;
					msg << "[CUnitHandler::TaskPlanCreate()][frame=" << ai->cb->GetCurrentFrame() << "]\n";
					msg << "\ttask-plan for \"" << builtdef->humanName << "\" already present";
					msg << " at position <" << pos.x << ", " << pos.y << ", " << pos.z << ">\n";
				ai->GetLogger()->Log(msg.str());
			}
		}
	}
	if (!existingTP) {
		TaskPlan tp;
		tp.pos = pos;
		tp.def = builtdef;
		tp.defName = builtdef->name;
		tp.currentBuildPower = 0;
		tp.id = taskPlanCounter++;
		TaskPlanAdd(&tp, builderTracker);

		if (category == CAT_DEFENCE)
			ai->dm->AddDefense(pos, builtdef);

		TaskPlans[category].push_back(tp);
	}
}
开发者ID:BrainDamage,项目名称:spring,代码行数:52,代码来源:UnitHandler.cpp

示例6: GetClosestBaseSpot

float3 CAttackHandler::GetClosestBaseSpot(float3 pos) {
	float closestDistance = FLT_MAX;
	int index = 0;
	for(int i = 0; i < this->kMeansK; i++) {
		float3 mean = this->kMeansBase[i];
		float distance = pos.distance2D(mean);
		if (distance < closestDistance) {
			closestDistance = distance, closestDistance;
			index = i;
		}
	}
	return kMeansBase[index];
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:13,代码来源:AttackHandler.cpp

示例7: CanBuildAt

bool cBuilderPlacement::CanBuildAt(UnitInfo *U, const float3& position, const float3& destination)
{
	if( U->udr->immobileType != 0 ) // A hub or factory
		return position.distance2D(destination) < U->ud->buildDistance;
	if( U->area == 0 ) // A flying unit
		return true;
	int iS = G->TM->GetSectorIndex(destination);
	if( U->area->sector.find(iS) != U->area->sector.end() )
		return true;
	if( G->TM->GetClosestSector(U->area,iS)->S->position.distance2D(destination) < U->ud->buildDistance - G->TM->convertStoP )
		return true;
	return false;
}
开发者ID:9heart,项目名称:spring,代码行数:13,代码来源:BuilderPlacement.cpp

示例8: TaskPlanCreate

void CUnitHandler::TaskPlanCreate(int builder, float3 pos, const UnitDef* builtdef) {
	int category = ai->ut->GetCategory(builtdef);

	// HACK
	if (category == -1)
		return;

	assert(category >= 0);
	assert(category < LASTCATEGORY);

	// find this builder
	BuilderTracker* builderTracker = GetBuilderTracker(builder);

	// make sure this builder is free
	// KLOOTNOTE: no longer use assertions
	// since new code for extractor upgrading
	// (in CBuildUp) seems to trigger them?
	bool b1 = (builderTracker->taskPlanId == 0);
	bool b2 = (builderTracker->buildTaskId == 0);
	bool b3 = (builderTracker->factoryId == 0);
	bool b4 = (builderTracker->customOrderId == 0);

	if (!b1 || !b2 || !b3 || !b4) {
		return;
	}


	bool existingtp = false;
	for (list<TaskPlan>::iterator i = TaskPlans[category].begin(); i != TaskPlans[category].end(); i++) {
		if (pos.distance2D(i->pos) < 20 && builtdef == i->def) {
			// make sure there are no other TaskPlans
			assert(!existingtp);
			existingtp = true;
			TaskPlanAdd(&*i, builderTracker);
		}
	}
	if (!existingtp) {
		TaskPlan tp;
		tp.pos = pos;
		tp.def = builtdef;
		tp.defName = builtdef->name;
		tp.currentBuildPower = 0;
		tp.id = taskPlanCounter++;
		TaskPlanAdd(&tp, builderTracker);

		if (category == CAT_DEFENCE)
			ai->dm->AddDefense(pos,builtdef);

		TaskPlans[category].push_back(tp);
	}
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:51,代码来源:UnitHandler.cpp

示例9: ValidMapPos

	bool CGridManager::ValidMapPos(float3 MapPos){
		bool rvalue = true;
		if (MapPos.z > MapDimensions.z){
			rvalue = false;
		}else if (MapPos.x > MapDimensions.x){
			rvalue=false;
		}else if (MapPos.z < 0){
			rvalue=false;
		}else if (MapPos.x < 0){
			rvalue=false;
		}else if (MapPos == UpVector){
			rvalue=false;
		}else if (MapPos==ZeroVector){
			rvalue=false;
		}else if(MapPos.distance2D(ZeroVector)<50){
			rvalue=false;
		}
		return rvalue;
	}
开发者ID:SocietalEclipse,项目名称:spring-Societal,代码行数:19,代码来源:CGridManager.cpp

示例10: distfrom

	float3 CMap::distfrom(float3 Start, float3 Target, float distance){
		NLOG("CMap::distfrom");

		if(!CheckFloat3(Start)){
			return UpVector;
		}

		if(!CheckFloat3(Target)){
			return UpVector;
		}

		float p = distance/Start.distance2D(Target);
		if(p < 0) p *= -1;

		float dx = Start.x-Target.x;
		if(dx < 0) dx *= -1;

		float dz = Start.z-Target.z;
		if(dz < 0) dz *= -1;

		dz *= p;
		dx *= p;

		float x = Target.x;

		if(Start.x > Target.x){
			x += dx;
		} else{
			x -= dx;
		}

		float z = Target.z;

		if(Start.z > Target.z){
			z += dz;
		}else{
			z -= dz;
		}

		return float3(x,0,z);

	}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:42,代码来源:Map.cpp

示例11: SelectEnemy

int CAttackGroup::SelectEnemy(int numEnemies, const float3& groupPos) {
	int enemySelected = -1;
	float shortestDistanceFound = MY_FLT_MAX;
	float temp;

	for (int i = 0; i < numEnemies; i++) {
		// my range not considered in picking the closest one
		// TODO: is it air? is it cloaked?
		bool b1 = ((temp = groupPos.distance2D(ai->cheat->GetUnitPos(ai->unitIDs[i]))) < shortestDistanceFound);
		bool b2 = (ai->cheat->GetUnitDef(ai->unitIDs[i]) != NULL);
		bool b3 = CloakedFix(ai->unitIDs[i]);
		bool b4 = ai->cheat->GetUnitDef(ai->unitIDs[i])->canfly;

		if (b1 && b2 && b3 && !b4) {
			enemySelected = i;
			shortestDistanceFound = temp;
		}
	}

	return enemySelected;
}
开发者ID:,项目名称:,代码行数:21,代码来源:

示例12: update

void CCoverageCell::update(std::list<CUnit*>& uncovered) {
	if (isVacant())	return;

	float newRange = ai->coverage->getCoreRange(type, unit->type);
	if (newRange < range) {
		const float3 center = getCenter();
		for (std::map<int, CUnit*>::iterator it = units.begin(); it != units.end(); ) {
			const float3 pos = it->second->pos();
			if (center.distance2D(pos) > newRange) {
				uncovered.push_back(it->second);
				it->second->unreg(*this);
				units.erase(it++);
			}
			else
				++it;
		}

		range = newRange;
	}

	// TODO: if core is mobile then update it when position has changed
}
开发者ID:Error323,项目名称:E323AI,代码行数:22,代码来源:CCoverageCell.cpp

示例13: if

	bool CMap::CheckFloat3(float3 pos){
		NLOG("CMap::CheckFloat3");
		if(pos == UpVector){ //error codes
			return false;
		}else if(pos == ZeroVector){ //error codes
			return false;
		}else if(pos == float3(-1,0,0)){ //error codes
			return false;
		}else if(pos.distance2D(UpVector) <50){ // top corner!!!!!
			return false;
		}/*else if(pos.x > G->cb->GetMapWidth()*SQUARE_SIZE){ // offmap
			return false;
		}else if(pos.z > G->cb->GetMapHeight()*SQUARE_SIZE){ // offmap
			return false;
		}else if(pos.x < 0){ // offmap
			return false;
		}else if(pos.z < 0){ // offmap
			return false;
		}*/else{
			return true;
		}
	}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:22,代码来源:Map.cpp

示例14: TaskPlanCreate

void  CUnitHandler::TaskPlanCreate(int builder, float3 pos, const UnitDef* builtdef)
{
	int category = ai->ut->GetCategory(builtdef);
	// TODO: Temp hack
	if(category == -1)
		return;
	assert(category >= 0);
	assert(category < LASTCATEGORY);
	
	// Find this builder:
	BuilderTracker * builderTracker = GetBuilderTracker(builder);
	// Make shure this builder is free:
	assert(builderTracker->buildTaskId == 0);
	assert(builderTracker->taskPlanId == 0);
	assert(builderTracker->factoryId == 0);
	assert(builderTracker->customOrderId == 0);
	
	bool existingtp = false;
	for(list<TaskPlan>::iterator i = TaskPlans[category]->begin(); i != TaskPlans[category]->end(); i++){
		if(pos.distance2D(i->pos) < 20 && builtdef == i->def){
			assert(!existingtp); // Make shure there are no other TaskPlan there
			existingtp = true;
			TaskPlanAdd(&*i, builderTracker);
		}
	}
	if(!existingtp){
		TaskPlan tp;
		tp.pos = pos;
		tp.def = builtdef;
		tp.currentBuildPower = 0;
		tp.id = taskPlanCounter++;
		TaskPlanAdd(&tp, builderTracker);
		
		if(category == CAT_DEFENCE)
				ai->dm->AddDefense(pos,builtdef);
		TaskPlans[category]->push_back(tp);
	}
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:38,代码来源:UnitHandler.cpp

示例15: GetDefensePos

float3 CDefenseMatrix::GetDefensePos(const UnitDef* def, float3 builderpos) {
	ai -> ut -> UpdateChokePointArray();
	int f3multiplier = 8 * THREATRES;
	int Range = int(ai -> ut -> GetMaxRange(def) / f3multiplier);
	int bestspotx = 0;
	int bestspoty = 0;
	// L("GetDefensePos: Range: " << Range);
	float averagemapsize = sqrt(float(ai -> pather -> PathMapXSize*ai -> pather -> PathMapYSize)) * f3multiplier;
	float bestscore_fast = 0;
	int bestspotx_fast = 0;
	int bestspoty_fast = 0;
	ai -> math -> TimerStart();

	spotFinder -> SetRadius(Range);
	float* sumMap = spotFinder -> GetSumMap();

	// hack to find a good start
	{
		int x = (int) (builderpos.x / f3multiplier);
		int y = (int) (builderpos.z / f3multiplier);
		float fastSumMap = sumMap[y * ai -> pather -> PathMapXSize + x];
		float3 spotpos = float3(x*f3multiplier,0,y*f3multiplier);
		float myscore = fastSumMap/(builderpos.distance2D(spotpos) + averagemapsize / 8) * ((ai -> pather -> HeightMap[y * ai -> pather -> PathMapXSize + x] + 200) / (ai -> pather -> AverageHeight + 10)) / (ai -> tm -> ThreatAtThisPoint(spotpos)+0.01);
		bestscore_fast = myscore;
		bestspotx_fast = x;
		bestspoty_fast = y;
		// L("Starting with bestscore_fast: " << bestscore_fast);
	}



	// L("ai -> pather -> PathMapXSize: " << ai -> pather -> PathMapXSize);
	// L("ai -> pather -> PathMapYSize: " << ai -> pather -> PathMapYSize);
	// L("ai -> pather -> PathMapXSize / CACHEFACTOR: " << ai -> pather -> PathMapXSize / CACHEFACTOR);
	// L("ai -> pather -> PathMapYSize / CACHEFACTOR: " << ai -> pather -> PathMapYSize / CACHEFACTOR);

	int skipCount = 0;
	int testCount = 0;
	for (int x = 0; x < ai -> pather -> PathMapXSize / CACHEFACTOR; x++) {
		for (int y = 0; y < ai -> pather -> PathMapYSize / CACHEFACTOR; y++) {
			// L("x: " << x << ", y: " << y);

			CachePoint* cachePoint = spotFinder -> GetBestCachePoint(x, y);
			float bestScoreInThisBox = cachePoint -> maxValueInBox;

			// guess that this point is as good as posible

			// make best posible build spot (nearest to builder)
			float bestX = builderpos.x / f3multiplier;
			float bestY = builderpos.z / f3multiplier;

			if (bestX > x * CACHEFACTOR) {
				if (bestX > (x * CACHEFACTOR + CACHEFACTOR)) {
					bestX = x * CACHEFACTOR + CACHEFACTOR;
				}
			}
			else {
				bestX = x * CACHEFACTOR;
			}

			if (bestY > y * CACHEFACTOR) {
				if (bestY > (y * CACHEFACTOR + CACHEFACTOR)) {
					bestY = y * CACHEFACTOR + CACHEFACTOR;
				}
			}
			else {
				bestY = y * CACHEFACTOR;
			}

			// L("bestX: " << bestX << ", bestY: " << bestY);

			float3 bestPosibleSpotpos = float3(bestX*f3multiplier,0,bestY*f3multiplier);
 			// this must be guessed, set it to the best posible (slow)
			float bestThreatAtThisPoint = 0.01 + ai -> tm -> GetAverageThreat() - 1;
			// L("bestThreatAtThisPoint: " << bestThreatAtThisPoint);
			float bestDistance = builderpos.distance2D(bestPosibleSpotpos);
			// L("bestDistance: " << bestDistance);
			// L("cachePoint -> maxValueInBox: " << cachePoint -> maxValueInBox << ", cachePoint -> x: " << cachePoint -> x << ", cachePoint -> y: " << cachePoint -> y);
			float bestHeight = ai -> pather -> HeightMap[cachePoint -> y * ai -> pather -> PathMapXSize + cachePoint -> x] + 200;
			// L("bestHeight: " << bestHeight);
			float bestPosibleMyScore = bestScoreInThisBox / (bestDistance + averagemapsize / 4) * (bestHeight + 200) / bestThreatAtThisPoint;
			// L("bestPosibleMyScore: " << bestPosibleMyScore);
			// have a best posible score for all points inside the size of the cache box
			// if this is better than the current known best, test if any point inside the box is better
			// L("bestscore_fast: " << bestscore_fast);

			if (bestPosibleMyScore > bestscore_fast) {
				testCount++;
				// must test all the points inside this box
				for (int sx = x * CACHEFACTOR; sx < ai -> pather -> PathMapXSize && sx < (x * CACHEFACTOR + CACHEFACTOR); sx++) {
					for (int sy = y * CACHEFACTOR; sy < ai -> pather -> PathMapYSize && sy < (y * CACHEFACTOR + CACHEFACTOR); sy++) {
						float fastSumMap = sumMap[sy * ai -> pather -> PathMapXSize + sx];
						float3 spotpos = float3(sx * f3multiplier, 0, sy * f3multiplier);
						float myscore = fastSumMap / (builderpos.distance2D(spotpos) + averagemapsize / 4) * (ai -> pather -> HeightMap[sy * ai -> pather -> PathMapXSize + sx]+200) / (ai -> tm -> ThreatAtThisPoint(spotpos) + 0.01);
						// L("Checking defense spot. fastSumMap: " << fastSumMap << ", Distance: " << builderpos.distance2D(spotpos) << " Height: " << ai -> pather -> HeightMap[sy * ai -> pather -> PathMapXSize + sx] << " Threat " << ai -> tm -> ThreatAtThisPoint(spotpos)<< " Score: " << myscore);
						// THIS COULD BE REALLY SLOW!
						if (myscore > bestscore_fast && BuildMaskArray[sy * ai -> pather -> PathMapXSize + sx] == 0 && ai -> cb -> CanBuildAt(def, spotpos)) {
							bestscore_fast = myscore;
							bestspotx_fast = sx;
							bestspoty_fast = sy;
//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,代码来源:DefenseMatrix.cpp


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