本文整理汇总了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);
//.........这里部分代码省略.........