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


C++ WorldMap::VoxelHit方法代码示例

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


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

示例1: DoTick


//.........这里部分代码省略.........
				++same;
			}

			if (wgAdj.RockHeight()) {
				// Water or rock runoff increase water.
				rain += 0.25f * rainBase;
			}
			if (wgAdj.IsFluid()) {
				rain += 0.25f;	// just a lot of water.
			}
			if (wgAdj.IsWater()) {
				rain += 0.25f;	// more water
				temperature = Mean(0.5f, temperature); // moderate temperature
			}
		}
		// Nutrient depletion? Too packed in?
		if (same == NADJ) {
			growth *= 0.25f;
		}

		// Are we under water?
		float fluidHeight = wg.FluidHeight();
		if (fluidHeight > 0.01f) {
			// Any amount of water goes to rain 100%
			rain = 1.0f;
			// not sure what to do with temp...assume a little cooler?
			temperature *= 0.8f;

			// blocks light...
			float sizeY = PlantScript::PlantRes(wg.Plant() - 1, wg.PlantStage())->AABB().SizeY();
			if (fluidHeight > sizeY)
				sun = 0;
			else if (fluidHeight > sizeY * 0.5f)
				sun = sun * (1.0f - fluidHeight / sizeY);
		}

		rain = Clamp(rain, 0.0f, 1.0f);
		temperature = Clamp(temperature, 0.0f, 1.0f);
		sun = Clamp(sun, 0.0f, 1.0f);

		// ------- calc ------- //
		Vector3F actual = { sun, rain, temperature };
		Vector3F optimal = { 0.5f, 0.5f, 0.5f };

		const GameItem* item = PlantScript::PlantDef(wg.Plant() - 1);
		item->keyValues.Get(ISC::sun, &optimal.x);
		item->keyValues.Get(ISC::rain, &optimal.y);
		item->keyValues.Get(ISC::temp, &optimal.z);

		float distance = (optimal - actual).Length();
		distance = distance / growth;

		const float GROW = Lerp(0.2f, 0.1f, (float)wg.PlantStage() / (float)(MAX_PLANT_STAGES - 1));
		const float DIE = 0.4f;
		float seconds = float(DELTA) / 1000.0f;

		if (distance < GROW) {
			// Heal.
			float hp = HP_PER_SECOND*seconds;
			DamageDesc heal( -hp, 0 );
			worldMap->VoxelHit(pos2i, heal);

			// Grow
			int nStage = wg.IsFlower() ? PLANT_BLOCKING_STAGE : MAX_PLANT_STAGES;

			if (wg.HPFraction() > 0.8f) {
				if (wg.PlantStage() < (nStage - 1)) {
					int hp = wg.HP();
					worldMap->SetPlant(pos2i.x, pos2i.y, wg.Plant(), wg.PlantStage() + 1);
					worldMap->SetWorldGridHP(pos2i.x, pos2i.y, hp);
				}
				if (random.Rand(GROWTH_CHANCE) < wg.PlantStage()) {
					// Number range reflects wind direction.
					int dx = -1 + random.Rand(4);	// [-1,2]
					int dy = -1 + random.Rand(3);	// [-1,1]

					// Remember that create plant will favor creating
					// existing plants, so we don't need to specify
					// what to create.
					Sim* sim = context->chitBag->GetSim();
					GLASSERT(sim);
					sim->CreatePlant(pos2i.x + dx, pos2i.y + dy, -1);
				}
			}
			int stage = wg.PlantStage();	// 0-3
			CoreScript* cs = CoreScript::GetCore(ToSector(pos2i));
			// Totally "what feels right in world gen" constant in the random.Rand()
			if ((census->wildFruit < MAX_WILD_FRUIT) && cs && (!cs->InUse()) && int(random.Rand(200)) < (stage*stage)) {
				context->chitBag->NewWildFruit(pos2i);
			}
		}
		else if (distance > DIE) {
			DamageDesc dd(HP_PER_SECOND * seconds, 0);
			worldMap->VoxelHit(pos2i, dd);
			if (wg.HP() == 0) {
				worldMap->SetPlant(pos2i.x, pos2i.y, 0, 0);
			}
		}
	}
}
开发者ID:fordream,项目名称:alteraorbis,代码行数:101,代码来源:plantscript.cpp


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