public void Update(float dt) { if (m_subsystemTime.PeriodicGameTimeEvent(5.0, 0.0)) { m_updateIndex++; foreach (Point3 key in m_particleSystemsByCell.Keys) { PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(key.X, key.Z); if ((precipitationShaftInfo.Intensity > 0f && key.Y >= precipitationShaftInfo.YLimit - 1) || m_updateIndex % 5 == 0) { m_toReduce.Add(key); } } foreach (Point3 item in m_toReduce) { ResizeCampfire(item.X, item.Y, item.Z, -1, playSound: true); } m_toReduce.Clear(); } if (Time.PeriodicEvent(0.5, 0.0)) { float num = float.MaxValue; foreach (Point3 key2 in m_particleSystemsByCell.Keys) { float x = m_subsystemAmbientSounds.SubsystemAudio.CalculateListenerDistanceSquared(new Vector3(key2.X, key2.Y, key2.Z)); num = MathUtils.Min(num, x); } m_fireSoundVolume = m_subsystemAmbientSounds.SubsystemAudio.CalculateVolume(MathUtils.Sqrt(num), 2f); } m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_fireSoundVolume); }
public void FreezeThawAndDepositSnow(TerrainChunk chunk) { Terrain terrain = SubsystemTerrain.Terrain; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { if (m_random.Int() % 2 == 0) { continue; } int topHeightFast = chunk.GetTopHeightFast(i, j); int cellValueFast = chunk.GetCellValueFast(i, topHeightFast, j); int num = Terrain.ExtractContents(cellValueFast); int num2 = chunk.Origin.X + i; int num3 = topHeightFast; int num4 = chunk.Origin.Y + j; PrecipitationShaftInfo precipitationShaftInfo = GetPrecipitationShaftInfo(num2, num4); if (precipitationShaftInfo.Type == PrecipitationType.Snow) { if (num == 18) { int cellContents = terrain.GetCellContents(num2 + 1, num3, num4); int cellContents2 = terrain.GetCellContents(num2 - 1, num3, num4); int cellContents3 = terrain.GetCellContents(num2, num3, num4 - 1); int cellContents4 = terrain.GetCellContents(num2, num3, num4 + 1); bool num5 = cellContents != 18 && cellContents != 0; bool flag = cellContents2 != 18 && cellContents2 != 0; bool flag2 = cellContents3 != 18 && cellContents3 != 0; bool flag3 = cellContents4 != 18 && cellContents4 != 0; if (num5 | flag | flag2 | flag3) { SubsystemTerrain.ChangeCell(num2, num3, num4, Terrain.MakeBlockValue(62)); } } else if (precipitationShaftInfo.Intensity > 0.5f && SubsystemSnowBlockBehavior.CanSupportSnow(cellValueFast) && (num != 62 || ShaftHasSnowOnIce(num2, num4)) && num3 + 1 < 255) { SubsystemTerrain.ChangeCell(num2, num3 + 1, num4, Terrain.MakeBlockValue(61)); } } else { switch (num) { case 61: SubsystemTerrain.DestroyCell(0, num2, num3, num4, 0, noDrop: true, noParticleSystem: true); break; case 62: SubsystemTerrain.DestroyCell(0, num2, num3, num4, 0, noDrop: false, noParticleSystem: true); break; } } } } }
public override void OnPoll(int value, int x, int y, int z, int pollPass) { if (m_random.Float(0f, 1f) < 0.25f) { PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(x, z); if (precipitationShaftInfo.Intensity > 0f && y >= precipitationShaftInfo.YLimit - 1) { base.SubsystemTerrain.DestroyCell(0, x, y, z, 0, noDrop: true, noParticleSystem: false); } } }
public void Update(float dt) { if (m_subsystemGameInfo.TotalElapsedGameTime > m_precipitationEndTime) { if (m_precipitationEndTime == 0.0) { if (m_subsystemGameInfo.WorldSettings.StartingPositionMode == StartingPositionMode.Hard) { m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(2f, 3f)); m_lightningIntensity = m_random.Float(0.5f, 1f); } else { m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(3f, 6f)); m_lightningIntensity = m_random.Float(0.33f, 0.66f); } } else { m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(5f, 45f)); m_lightningIntensity = ((m_random.Float(0f, 1f) < 0.5f) ? m_random.Float(0.33f, 1f) : 0f); } m_precipitationEndTime = m_precipitationStartTime + (double)(60f * m_random.Float(3f, 6f)); } float num = (float)MathUtils.Max(0.0, MathUtils.Min(m_subsystemGameInfo.TotalElapsedGameTime - m_precipitationStartTime, m_precipitationEndTime - m_subsystemGameInfo.TotalElapsedGameTime)); GlobalPrecipitationIntensity = (m_subsystemGameInfo.WorldSettings.AreWeatherEffectsEnabled ? MathUtils.Saturate(num * 0.04f) : 0f); if (GlobalPrecipitationIntensity == 1f && SubsystemTime.PeriodicGameTimeEvent(1.0, 0.0)) { TerrainChunk[] allocatedChunks = SubsystemTerrain.Terrain.AllocatedChunks; for (int i = 0; i < allocatedChunks.Length; i++) { TerrainChunk terrainChunk = allocatedChunks[m_random.Int(0, allocatedChunks.Length - 1)]; if (terrainChunk.State < TerrainChunkState.InvalidVertices1 || !m_random.Bool(m_lightningIntensity * 0.0002f)) { continue; } int num2 = terrainChunk.Origin.X + m_random.Int(0, 15); int num3 = terrainChunk.Origin.Y + m_random.Int(0, 15); Vector3?vector = null; for (int j = num2 - 8; j < num2 + 8; j++) { for (int k = num3 - 8; k < num3 + 8; k++) { int topHeight = SubsystemTerrain.Terrain.GetTopHeight(j, k); if (!vector.HasValue || (float)topHeight > vector.Value.Y) { vector = new Vector3(j, topHeight, k); } } } if (vector.HasValue) { SubsystemSky.MakeLightningStrike(vector.Value); return; } } } if (Time.PeriodicEvent(0.5, 0.0)) { float num4 = 0f; if (GlobalPrecipitationIntensity > 0f) { float num5 = 0f; foreach (Vector3 listenerPosition in m_subsystemAudio.ListenerPositions) { int num6 = Terrain.ToCell(listenerPosition.X) - 5; int num7 = Terrain.ToCell(listenerPosition.Z) - 5; int num8 = Terrain.ToCell(listenerPosition.X) + 5; int num9 = Terrain.ToCell(listenerPosition.Z) + 5; Vector3 vector2 = default(Vector3); for (int l = num6; l <= num8; l++) { for (int m = num7; m <= num9; m++) { PrecipitationShaftInfo precipitationShaftInfo = GetPrecipitationShaftInfo(l, m); if (precipitationShaftInfo.Type == PrecipitationType.Rain && precipitationShaftInfo.Intensity > 0f) { vector2.X = (float)l + 0.5f; vector2.Y = MathUtils.Max(precipitationShaftInfo.YLimit, listenerPosition.Y); vector2.Z = (float)m + 0.5f; float num10 = vector2.X - listenerPosition.X; float num11 = 8f * (vector2.Y - listenerPosition.Y); float num12 = vector2.Z - listenerPosition.Z; float distance = MathUtils.Sqrt(num10 * num10 + num11 * num11 + num12 * num12); num5 += m_subsystemAudio.CalculateVolume(distance, 1.5f) * precipitationShaftInfo.Intensity; } } } } num4 = MathUtils.Max(num4, num5); } m_targetRainSoundVolume = MathUtils.Saturate(1.5f * num4 / m_rainVolumeFactor); } m_rainSound.Volume = MathUtils.Saturate(MathUtils.Lerp(m_rainSound.Volume, SettingsManager.SoundsVolume * m_targetRainSoundVolume, 5f * dt)); if (m_rainSound.Volume > AudioManager.MinAudibleVolume) { m_rainSound.Play(); } else { m_rainSound.Pause(); } }
public void UpdateWetness() { float gameTimeDelta = m_subsystemTime.GameTimeDelta; if (m_componentPlayer.ComponentBody.ImmersionFactor > 0.2f && m_componentPlayer.ComponentBody.ImmersionFluidBlock is WaterBlock) { float num = 2f * m_componentPlayer.ComponentBody.ImmersionFactor; Wetness += MathUtils.Saturate(3f * gameTimeDelta) * (num - Wetness); } int x = Terrain.ToCell(m_componentPlayer.ComponentBody.Position.X); int num2 = Terrain.ToCell(m_componentPlayer.ComponentBody.Position.Y + 0.1f); int z = Terrain.ToCell(m_componentPlayer.ComponentBody.Position.Z); PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(x, z); if (num2 >= precipitationShaftInfo.YLimit && precipitationShaftInfo.Type == PrecipitationType.Rain) { Wetness += 0.05f * precipitationShaftInfo.Intensity * gameTimeDelta; } float num3 = 180f; if (m_environmentTemperature > 8f) { num3 = 120f; } if (m_environmentTemperature > 16f) { num3 = 60f; } if (m_environmentTemperature > 24f) { num3 = 30f; } Wetness -= gameTimeDelta / num3; if (Wetness > 0.8f && m_lastWetness <= 0.8f) { Time.QueueTimeDelayedExecution(Time.FrameStartTime + 2.0, delegate { if (Wetness > 0.8f) { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 38), Color.White, blinking: true, playNotificationSound: true); } }); } else if (Wetness > 0.2f && m_lastWetness <= 0.2f) { Time.QueueTimeDelayedExecution(Time.FrameStartTime + 2.0, delegate { if (Wetness > 0.2f && Wetness <= 0.8f && Wetness > m_lastWetness) { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 39), Color.White, blinking: true, playNotificationSound: true); } }); } else if (Wetness <= 0f && m_lastWetness > 0f) { Time.QueueTimeDelayedExecution(Time.FrameStartTime + 2.0, delegate { if (Wetness <= 0f) { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 40), Color.White, blinking: true, playNotificationSound: true); } }); } m_lastWetness = Wetness; }
public override bool Simulate(float dt) { if (m_subsystemWeather.SubsystemTime.GameTime - m_lastUpdateTime > 1.0 || MathUtils.Abs(m_lastSkylightIntensity - m_subsystemWeather.SubsystemSky.SkyLightIntensity) > 0.1f) { m_lastUpdateTime = m_subsystemWeather.SubsystemTime.GameTime; m_lastSkylightIntensity = m_subsystemWeather.SubsystemSky.SkyLightIntensity; PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(Point.X, Point.Y); m_intensity = precipitationShaftInfo.Intensity; m_yLimit = precipitationShaftInfo.YLimit; m_topmostValue = m_subsystemWeather.SubsystemTerrain.Terrain.GetCellValue(Point.X, precipitationShaftInfo.YLimit - 1, Point.Y); m_topmostBelowValue = m_subsystemWeather.SubsystemTerrain.Terrain.GetCellValue(Point.X, precipitationShaftInfo.YLimit - 2, Point.Y); } Camera activeCamera = m_gameWidget.ActiveCamera; if (!m_isEmpty || (m_intensity > 0f && (float)m_yLimit < activeCamera.ViewPosition.Y + 5f)) { Vector2 v = Vector2.Normalize(new Vector2(activeCamera.ViewDirection.X, activeCamera.ViewDirection.Z)); Vector2 v2 = Vector2.Normalize(new Vector2((float)Point.X + 0.5f - activeCamera.ViewPosition.X + 0.7f * v.X, (float)Point.Y + 0.5f - activeCamera.ViewPosition.Z + 0.7f * v.Y)); float num = Vector2.Dot(v, v2); m_isVisible = (num > 0.5f); if (m_isVisible) { if (m_needsInitialize) { m_needsInitialize = false; Initialize(); } float y = activeCamera.ViewPosition.Y; float num2 = y - 5f; float num3 = y + 5f; float num4 = 0f; float num5 = 0f; if (m_lastViewY.HasValue) { if (y < m_lastViewY.Value) { num4 = num2; num5 = m_lastViewY.Value - 5f; } else { num4 = m_lastViewY.Value + 5f; num5 = num3; } } else { num4 = num2; num5 = num3; } float num6 = (num5 - num4) / 10f * (float)m_particles.Length * m_intensity; int num7 = (int)num6 + ((m_random.Float(0f, 1f) < num6 - (float)(int)num6) ? 1 : 0); m_lastViewY = y; m_toCreate += (float)m_particles.Length * m_intensity / 10f * m_averageSpeed * dt; m_isEmpty = true; float num8 = (m_precipitationType == PrecipitationType.Rain) ? 0f : 0.03f; for (int i = 0; i < m_particles.Length; i++) { Particle particle = m_particles[i]; if (particle.IsActive) { if (particle.YLimit == 0f && particle.Position.Y <= (float)m_yLimit + num8) { RaycastParticle(particle); } bool flag = particle.YLimit != 0f && particle.Position.Y <= particle.YLimit + num8; if (!flag && particle.Position.Y >= num2 && particle.Position.Y <= num3) { particle.Position.Y -= particle.Speed * dt; m_isEmpty = false; continue; } particle.IsActive = false; if (particle.GenerateSplash && flag) { if (m_precipitationType == PrecipitationType.Rain && m_random.Bool(0.5f)) { m_subsystemWeather.RainSplashParticleSystem.AddSplash(m_topmostValue, new Vector3(particle.Position.X, particle.YLimit + num8, particle.Position.Z), m_subsystemWeather.RainColor); } if (m_precipitationType == PrecipitationType.Snow) { m_subsystemWeather.SnowSplashParticleSystem.AddSplash(m_topmostValue, new Vector3(particle.Position.X, particle.YLimit + num8, particle.Position.Z), m_size, m_subsystemWeather.SnowColor, particle.TextureSlot); } } } else if (num7 > 0) { particle.Position.X = (float)Point.X + m_random.Float(0f, 1f); particle.Position.Y = m_random.Float(num4, num5); particle.Position.Z = (float)Point.Y + m_random.Float(0f, 1f); particle.IsActive = (particle.Position.Y >= (float)m_yLimit); particle.YLimit = 0f; num7--; } else if (m_toCreate >= 1f) { particle.Position.X = (float)Point.X + m_random.Float(0f, 1f); particle.Position.Y = m_random.Float(num3 - m_averageSpeed * dt, num3); particle.Position.Z = (float)Point.Y + m_random.Float(0f, 1f); particle.IsActive = (particle.Position.Y >= (float)m_yLimit); particle.YLimit = 0f; m_toCreate -= 1f; } } m_toCreate -= MathUtils.Floor(m_toCreate); } else { m_needsInitialize = true; } } return(false); }
public void CalculateTemperature(int x, int y, int z, float meterTemperature, float meterInsulation, out float temperature, out float temperatureFlux) { m_toVisit.Clear(); for (int i = 0; i < m_visited.Length; i++) { m_visited[i] = 0; } float num = 0f; float num2 = 0f; float num3 = 0f; float num4 = 0f; float num5 = 0f; float num6 = 0f; m_toVisit.Add(133152); for (int j = 0; j < m_toVisit.Count; j++) { int num7 = m_toVisit.Array[j]; if ((m_visited[num7 / 32] & (1 << num7)) != 0) { continue; } m_visited[num7 / 32] |= 1 << num7; int num8 = (num7 & 0x3F) - 32; int num9 = ((num7 >> 6) & 0x3F) - 32; int num10 = ((num7 >> 12) & 0x3F) - 32; int num11 = num8 + x; int num12 = num9 + y; int num13 = num10 + z; Terrain terrain = base.SubsystemTerrain.Terrain; TerrainChunk chunkAtCell = terrain.GetChunkAtCell(num11, num13); if (chunkAtCell == null || num12 < 0 || num12 >= 256) { continue; } int x2 = num11 & 0xF; int y2 = num12; int z2 = num13 & 0xF; int cellValueFast = chunkAtCell.GetCellValueFast(x2, y2, z2); int num14 = Terrain.ExtractContents(cellValueFast); Block block = BlocksManager.Blocks[num14]; float heat = GetHeat(cellValueFast); if (heat > 0f) { int num15 = MathUtils.Abs(num8) + MathUtils.Abs(num9) + MathUtils.Abs(num10); int num16 = (num15 <= 0) ? 1 : (4 * num15 * num15 + 2); float num17 = 1f / (float)num16; num5 += num17 * 36f * heat; num6 += num17; } else if (block.IsHeatBlocker(cellValueFast)) { int num18 = MathUtils.Abs(num8) + MathUtils.Abs(num9) + MathUtils.Abs(num10); int num19 = (num18 <= 0) ? 1 : (4 * num18 * num18 + 2); float num20 = 1f / (float)num19; float num21 = terrain.SeasonTemperature; float num22 = SubsystemWeather.GetTemperatureAdjustmentAtHeight(y2); float num23 = (block is WaterBlock) ? (MathUtils.Max((float)chunkAtCell.GetTemperatureFast(x2, z2) + num21 - 6f, 0f) + num22) : ((!(block is IceBlock)) ? ((float)chunkAtCell.GetTemperatureFast(x2, z2) + num21 + num22) : (0f + num21 + num22)); num += num20 * num23; num2 += num20; } else if (y >= chunkAtCell.GetTopHeightFast(x2, z2)) { int num24 = MathUtils.Abs(num8) + MathUtils.Abs(num9) + MathUtils.Abs(num10); int num25 = (num24 <= 0) ? 1 : (4 * num24 * num24 + 2); float num26 = 1f / (float)num25; PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(x, z); float num27 = terrain.SeasonTemperature; float num28 = (y >= precipitationShaftInfo.YLimit) ? MathUtils.Lerp(0f, -2f, precipitationShaftInfo.Intensity) : 0f; float num29 = MathUtils.Lerp(-6f, 0f, m_subsystemSky.SkyLightIntensity); float num30 = SubsystemWeather.GetTemperatureAdjustmentAtHeight(y2); num3 += num26 * ((float)chunkAtCell.GetTemperatureFast(x2, z2) + num27 + num28 + num29 + num30); num4 += num26; } else if (m_toVisit.Count < 4090) { if (num8 > -30) { m_toVisit.Add(num7 - 1); } if (num8 < 30) { m_toVisit.Add(num7 + 1); } if (num9 > -30) { m_toVisit.Add(num7 - 64); } if (num9 < 30) { m_toVisit.Add(num7 + 64); } if (num10 > -30) { m_toVisit.Add(num7 - 4096); } if (num10 < 30) { m_toVisit.Add(num7 + 4096); } } } float num31 = 0f; for (int k = -7; k <= 7; k++) { for (int l = -7; l <= 7; l++) { TerrainChunk chunkAtCell2 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + k, z + l); if (chunkAtCell2 == null || chunkAtCell2.State < TerrainChunkState.InvalidVertices1) { continue; } for (int m = -7; m <= 7; m++) { int num32 = k * k + m * m + l * l; if (num32 > 49 || num32 <= 0) { continue; } int x3 = (x + k) & 0xF; int num33 = y + m; int z3 = (z + l) & 0xF; if (num33 >= 0 && num33 < 256) { float heat2 = GetHeat(chunkAtCell2.GetCellValueFast(x3, num33, z3)); if (heat2 > 0f && !base.SubsystemTerrain.Raycast(new Vector3(x, y, z) + new Vector3(0.5f, 0.75f, 0.5f), new Vector3(x + k, y + m, z + l) + new Vector3(0.5f, 0.75f, 0.5f), useInteractionBoxes: false, skipAirBlocks: true, delegate(int raycastValue, float d) { Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(raycastValue)]; return(block2.IsCollidable && !block2.IsTransparent); }).HasValue) { num31 += heat2 * 3f / (float)(num32 + 2); } } } } } float num34 = 0f; float num35 = 0f; if (num31 > 0f) { float num36 = 3f * num31; num34 += 35f * num36; num35 += num36; } if (num2 > 0f) { float num37 = 1f; num34 += num / num2 * num37; num35 += num37; } if (num4 > 0f) { float num38 = 4f * MathUtils.Pow(num4, 0.25f); num34 += num3 / num4 * num38; num35 += num38; } if (num6 > 0f) { float num39 = 1.5f * MathUtils.Pow(num6, 0.25f); num34 += num5 / num6 * num39; num35 += num39; } if (meterInsulation > 0f) { num34 += meterTemperature * meterInsulation; num35 += meterInsulation; } temperature = ((num35 > 0f) ? (num34 / num35) : meterTemperature); temperatureFlux = num35 - meterInsulation; }