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


C++ InfoMap::GetGameInfoFromMapSquare方法代码示例

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


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

示例1: BuildTask

BuildTask *ResourceUnitHandler::GetNewBuildTask ()
{
	// task for metal or energy?
	ResourceManager *rm = globals->resourceManager;
	IAICallback *cb = globals->cb;
	InfoMap *imap = globals->map;

	// check if storage has to be build
	if (rm->averageProd.metal > config.StorageConfig.MinMetalIncome && cb->GetMetal () > cb->GetMetalStorage () * config.StorageConfig.MaxRatio &&
		cb->GetMetalStorage() <= rm->averageProd.metal * config.StorageConfig.MaxMetalFactor)
	{
		BuildTask *t = CreateStorageTask (config.StorageConfig.MetalStorage.front());
		if (t) return t;
	}

	if (rm->averageProd.energy > config.StorageConfig.MinEnergyIncome && cb->GetEnergy () > cb->GetEnergyStorage () * config.StorageConfig.MaxRatio &&
		cb->GetEnergyStorage() <= rm->averageProd.energy * config.StorageConfig.MaxEnergyFactor)
	{
		BuildTask *t = CreateStorageTask (config.StorageConfig.EnergyStorage.front());
		if (t) return t;
	}

	if (rm->buildMultiplier.energy * config.MetalBuildRatio < rm->buildMultiplier.metal * config.EnergyBuildRatio) {
		// pick an energy producing unit to build

        // find the unit type that has the highest energyMake/ResourceValue(buildcost) ratio and
		// does not  with MaxResourceUpscale

		int best = -1;
		float bestRatio;
		float minWind = globals->cb->GetMinWind ();
		float maxWind = globals->cb->GetMaxWind ();

		for (int a=0;a<config.EnergyMakers.size();a++)
		{
			BuildTable::UDef*d = buildTable.GetCachedDef (config.EnergyMakers[a]);

			if (rm->averageProd.energy + d->make.energy > config.EnergyHeuristic.MaxUpscale * rm->averageProd.energy)
				continue;

			// calculate costs based on the heuristic parameters
			float cost = 
				d->buildTime * config.EnergyHeuristic.BuildTime +
				d->cost.metal * config.EnergyHeuristic.MetalCost +
				d->cost.energy * config.EnergyHeuristic.EnergyCost;

			float energyProduction = d->make.energy;

			if (d->flags & CUD_WindGen)
				energyProduction += 0.5f * (minWind + maxWind);

			float ratio = energyProduction / cost;

			if (best < 0 || ratio > bestRatio)
			{
				best = config.EnergyMakers[a];
				bestRatio = ratio;
			}
		}

		if (best >= 0)
			return new BuildTask (buildTable.GetDef (best));
	}
	else {
		// pick a metal producing unit to build
		float3 st (globals->map->baseCenter.x, 0.0f, globals->map->baseCenter.y);

		int best=0;
		float bestScore;
		MetalSpot* bestSpot=0;

		// sector has been found, now calculate the best suitable metal extractor
		for (int a=0;a<config.MetalExtracters.size();a++)
		{
			BuildTable::UDef *d = buildTable.GetCachedDef (config.MetalExtracters[a]);
			const UnitDef* def= buildTable.GetDef (config.MetalExtracters[a]);
			MetalSpotID spotID = globals->metalmap->FindSpot(st, imap, def->extractsMetal);
			if (spotID<0) break;

			MetalSpot* spot = globals->metalmap->GetSpot (spotID);
			if (!spot->metalProduction)
			{
				logPrintf ("Metalmap error: No metal production on spot.\n");
				spot->extractDepth=100;
				break;
			}

			// get threat info
			GameInfo *gi = imap->GetGameInfoFromMapSquare (spot->pos.x,spot->pos.y);
			float metalMake = spot->metalProduction * d->metalExtractDepth;
			float PaybackTime = d->cost.metal + gi->threat * config.MetalHeuristic.ThreatConversionFactor;
			PaybackTime /= metalMake;

			float score = config.MetalHeuristic.PaybackTimeFactor * PaybackTime + 
				d->energyUse * config.MetalHeuristic.EnergyUsageFactor;

			float upscale = 1.0f + metalMake / (1.0f + rm->averageProd.metal);
			if (upscale > config.MetalHeuristic.PrefUpscale)
				score += config.MetalHeuristic.UpscaleOvershootFactor * (upscale - config.MetalHeuristic.PrefUpscale);

//.........这里部分代码省略.........
开发者ID:achoum,项目名称:spring,代码行数:101,代码来源:ResourceUnitHandler.cpp


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