本文整理汇总了C++中WorldMap::CalcPath方法的典型用法代码示例。如果您正苦于以下问题:C++ WorldMap::CalcPath方法的具体用法?C++ WorldMap::CalcPath怎么用?C++ WorldMap::CalcPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorldMap
的用法示例。
在下文中一共展示了WorldMap::CalcPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvalIndustrial
double EvalBuildingScript::EvalIndustrial( bool debugLog )
{
Chit* building = ParentChit();
int hitB = 0, hitIBuilding = 0, hitNBuilding = 0, hitWater = 0, hitPlant = 0, hitRock = 0, hitWaterfall = 0;
int hitShrub = 0; // doesn't terminate a ray.
if (lastEval == 0 || (Context()->chitBag->AbsTime() - lastEval) > 2000) {
lastEval = Context()->chitBag->AbsTime();
GameItem* item = building->GetItem();
GLASSERT(item);
reachable = true;
IString consume = item->keyValues.GetIString(ISC::zone);
if (consume.empty()) {
eval = 0;
return eval;
}
MapSpatialComponent* msc = GET_SUB_COMPONENT(building, SpatialComponent, MapSpatialComponent);
GLASSERT(msc);
if (!msc) {
eval = 0;
return eval;
}
Rectangle2I porch = msc->PorchPos();
static const int RAD = 4;
Rectangle2I bounds = porch;
if (porch.min.x == 0) { // shouldn't happen, but be sure.
GLASSERT(0);
eval = 0;
return eval;
}
bounds.Outset(RAD);
Vector2I sector = ToSector(building->Position());
WorldMap* worldMap = Context()->worldMap;
Rectangle2I mapBounds = worldMap->Bounds();
if (!mapBounds.Contains(bounds)) {
eval = 0;
return eval; // not worth dealing with edge of world
}
// Check if we can go from the core to the porch.
// And make sure the core is inUse!
CoreScript* cs = CoreScript::GetCore(ToSector(porch.min));
if (!cs || !cs->InUse())
reachable = false;
if (reachable) {
const SectorData& sd = worldMap->GetSectorData(ToSector(porch.min));
reachable = worldMap->CalcPath(ToWorld2F(sd.core), ToWorld2F(porch.min), 0, 0, false);
}
CChitArray arr;
BuildingFilter buildingFilter;
const FluidSim* fluidSim = Context()->physicsSims->GetFluidSim(sector);
bool hasWaterfalls = fluidSim->NumWaterfalls() > 0;
LumosChitBag* chitBag = Context()->chitBag;
Rectangle2IEdgeIterator it(bounds);
while (!it.Done()) {
Vector2I pos = { it.Pos().x >= porch.max.x ? porch.max.x : porch.min.x,
it.Pos().y >= porch.max.y ? porch.max.y : porch.min.y };
LineWalk walk(pos.x, pos.y, it.Pos().x, it.Pos().y);
walk.Step(); // ignore where we are standing.
while ( !walk.Done() ) { // non-intuitive iterator. See linewalk docs.
// - building
// - plant
// - ice
// - rock
// - waterfall
// - water
// Buildings. Can be 2x2. Extend out beyond current check.
bool hitBuilding = false;
Vector2I p = walk.P();
// Don't count self as a hit, but stops the ray cast.
// Also, use a larger radius because buildings can be 2x2
chitBag->QuerySpatialHash(&arr, ToWorld2F(p), 0.8f, 0, &buildingFilter);
for (int i = 0; i < arr.Size(); ++i) {
if (arr[i] != building) {
MapSpatialComponent* buildingMSC = GET_SUB_COMPONENT(arr[i], SpatialComponent, MapSpatialComponent);
GLASSERT(buildingMSC);
if (buildingMSC->Bounds().Contains(p)) {
hitBuilding = true;
double thisSys = arr[i]->GetItem()->GetBuildingIndustrial();
hitB++;
if (thisSys <= -0.5) hitNBuilding++;
if (thisSys >= 0.5) hitIBuilding++;
break;
//.........这里部分代码省略.........