public override void Load(ValuesDictionary valuesDictionary) { base.Load(valuesDictionary); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemWeather = base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true); m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_subsystemMetersBlockBehavior = base.Project.FindSubsystem <SubsystemMetersBlockBehavior>(throwOnError: true); m_subsystemWeather = base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true); m_componentPlayer = base.Entity.FindComponent <ComponentPlayer>(throwOnError: true); m_pantingSound = m_subsystemAudio.CreateSound("Audio/HumanPanting"); m_pantingSound.IsLooped = true; Food = valuesDictionary.GetValue <float>("Food"); Stamina = valuesDictionary.GetValue <float>("Stamina"); Sleep = valuesDictionary.GetValue <float>("Sleep"); Temperature = valuesDictionary.GetValue <float>("Temperature"); Wetness = valuesDictionary.GetValue <float>("Wetness"); m_lastFood = Food; m_lastStamina = Stamina; m_lastSleep = Sleep; m_lastTemperature = Temperature; m_lastWetness = Wetness; m_environmentTemperature = Temperature; foreach (KeyValuePair <string, object> item in valuesDictionary.GetValue <ValuesDictionary>("Satiation")) { m_satiation[int.Parse(item.Key, CultureInfo.InvariantCulture)] = (float)item.Value; } m_componentPlayer.ComponentHealth.Attacked += delegate { m_lastAttackedTime = m_subsystemTime.GameTime; }; }
public Color Lookup(Terrain terrain, int x, int y, int z) { int shaftValue = terrain.GetShaftValue(x, z); int temperature = terrain.GetSeasonalTemperature(shaftValue) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y); int seasonalHumidity = terrain.GetSeasonalHumidity(shaftValue); return(Lookup(temperature, seasonalHumidity)); }
public override void Load(ValuesDictionary valuesDictionary) { base.Load(valuesDictionary); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); m_subsystemWeather = base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true); m_subsystemAmbientSounds = base.Project.FindSubsystem <SubsystemAmbientSounds>(throwOnError: true); }
public override void OnItemHarvested(int x, int y, int z, int blockValue, ref BlockDropValue dropValue, ref int newBlockValue) { if (y > 80 && SubsystemWeather.IsPlaceFrozen(base.SubsystemTerrain.Terrain.GetSeasonalTemperature(x, z), y)) { dropValue.Value = Terrain.MakeBlockValue(62); } else { base.OnItemHarvested(x, y, z, blockValue, ref dropValue, ref newBlockValue); } }
public PrecipitationShaftParticleSystem(GameWidget gameWidget, SubsystemWeather subsystemWeather, Random random, Point2 point, PrecipitationType precipitationType) { m_gameWidget = gameWidget; m_subsystemWeather = subsystemWeather; m_random = random; Point = point; m_precipitationType = precipitationType; for (int i = 0; i < m_particles.Length; i++) { m_particles[i] = new Particle(); } Initialize(); }
public override void Load(ValuesDictionary valuesDictionary) { m_subsystemTimeOfDay = base.Project.FindSubsystem <SubsystemTimeOfDay>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemWeather = base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_subsystemBodies = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true); m_subsystemFluidBlockBehavior = base.Project.FindSubsystem <SubsystemFluidBlockBehavior>(throwOnError: true); m_sunTexture = ContentManager.Get <Texture2D>("Textures/Sun"); m_glowTexture = ContentManager.Get <Texture2D>("Textures/SkyGlow"); m_cloudsTexture = ContentManager.Get <Texture2D>("Textures/Clouds"); for (int i = 0; i < 8; i++) { m_moonTextures[i] = ContentManager.Get <Texture2D>("Textures/Moon" + (i + 1).ToString(CultureInfo.InvariantCulture)); } UpdateLightAndViewParameters(); Display.DeviceReset += Display_DeviceReset; }
public static int GenerateRandomPlantValue(Random random, int groundValue, int temperature, int humidity, int y) { switch (Terrain.ExtractContents(groundValue)) { case 2: case 8: if (humidity >= 6) { if (!(random.Float(0f, 1f) < (float)humidity / 60f)) { break; } int result = Terrain.MakeBlockValue(19, 0, TallGrassBlock.SetIsSmall(0, isSmall: false)); if (!SubsystemWeather.IsPlaceFrozen(temperature, y)) { float num = random.Float(0f, 1f); if (num < 0.04f) { result = Terrain.MakeBlockValue(20); } else if (num < 0.07f) { result = Terrain.MakeBlockValue(24); } else if (num < 0.09f) { result = Terrain.MakeBlockValue(25); } else if (num < 0.17f) { result = Terrain.MakeBlockValue(174, 0, RyeBlock.SetIsWild(RyeBlock.SetSize(0, 7), isWild: true)); } else if (num < 0.19f) { result = Terrain.MakeBlockValue(204, 0, CottonBlock.SetIsWild(CottonBlock.SetSize(0, 2), isWild: true)); } } return(result); } if (random.Float(0f, 1f) < 0.025f) { if (random.Float(0f, 1f) < 0.2f) { return(Terrain.MakeBlockValue(99, 0, 0)); } return(Terrain.MakeBlockValue(28, 0, 0)); } break; case 7: if (humidity < 8 && random.Float(0f, 1f) < 0.01f) { if (random.Float(0f, 1f) < 0.05f) { return(Terrain.MakeBlockValue(99, 0, 0)); } return(Terrain.MakeBlockValue(28, 0, 0)); } break; } return(0); }
public void Draw(Camera camera, int drawOrder) { if (drawOrder == m_drawOrders[0]) { ViewUnderWaterDepth = 0f; ViewUnderMagmaDepth = 0f; Vector3 viewPosition = camera.ViewPosition; int x = Terrain.ToCell(viewPosition.X); int y = Terrain.ToCell(viewPosition.Y); int z = Terrain.ToCell(viewPosition.Z); FluidBlock surfaceFluidBlock; float? surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(x, y, z, out surfaceFluidBlock); if (surfaceHeight.HasValue) { if (surfaceFluidBlock is WaterBlock) { ViewUnderWaterDepth = surfaceHeight.Value + 0.1f - viewPosition.Y; } else if (surfaceFluidBlock is MagmaBlock) { ViewUnderMagmaDepth = surfaceHeight.Value + 1f - viewPosition.Y; } } if (ViewUnderWaterDepth > 0f) { int seasonalHumidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z); int temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y); Color c = BlockColorsMap.WaterColorsMap.Lookup(temperature, seasonalHumidity); float num = MathUtils.Lerp(1f, 0.5f, (float)seasonalHumidity / 15f); float num2 = MathUtils.Lerp(1f, 0.2f, MathUtils.Saturate(0.075f * (ViewUnderWaterDepth - 2f))); float num3 = MathUtils.Lerp(0.33f, 1f, SkyLightIntensity); m_viewFogRange.X = 0f; m_viewFogRange.Y = MathUtils.Lerp(4f, 10f, num * num2 * num3); m_viewFogColor = Color.MultiplyColorOnly(c, 0.66f * num2 * num3); VisibilityRangeYMultiplier = 1f; m_viewIsSkyVisible = false; } else if (ViewUnderMagmaDepth > 0f) { m_viewFogRange.X = 0f; m_viewFogRange.Y = 0.1f; m_viewFogColor = new Color(255, 80, 0); VisibilityRangeYMultiplier = 1f; m_viewIsSkyVisible = false; } else { float num4 = 1024f; float num5 = 128f; int seasonalTemperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(Terrain.ToCell(viewPosition.X), Terrain.ToCell(viewPosition.Z)); float num6 = MathUtils.Lerp(0.5f, 0f, m_subsystemWeather.GlobalPrecipitationIntensity); float num7 = MathUtils.Lerp(1f, 0.8f, m_subsystemWeather.GlobalPrecipitationIntensity); m_viewFogRange.X = VisibilityRange * num6; m_viewFogRange.Y = VisibilityRange * num7; m_viewFogColor = CalculateSkyColor(new Vector3(camera.ViewDirection.X, 0f, camera.ViewDirection.Z), m_subsystemTimeOfDay.TimeOfDay, m_subsystemWeather.GlobalPrecipitationIntensity, seasonalTemperature); VisibilityRangeYMultiplier = MathUtils.Lerp(VisibilityRange / num4, VisibilityRange / num5, MathUtils.Pow(m_subsystemWeather.GlobalPrecipitationIntensity, 4f)); m_viewIsSkyVisible = true; } if (!FogEnabled) { m_viewFogRange = new Vector2(100000f, 100000f); } if (!DrawSkyEnabled || !m_viewIsSkyVisible || SettingsManager.SkyRenderingMode == SkyRenderingMode.Disabled) { FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch(-1, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.Opaque); int count = flatBatch2D.TriangleVertices.Count; flatBatch2D.QueueQuad(Vector2.Zero, camera.ViewportSize, 0f, m_viewFogColor); flatBatch2D.TransformTriangles(camera.ViewportMatrix, count); m_primitivesRenderer2d.Flush(); } } else if (drawOrder == m_drawOrders[1]) { if (DrawSkyEnabled && m_viewIsSkyVisible && SettingsManager.SkyRenderingMode != SkyRenderingMode.Disabled) { DrawSkydome(camera); DrawStars(camera); DrawSunAndMoon(camera); DrawClouds(camera); m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix); } } else { DrawLightning(camera); m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix); } }
public override void DrawExtras(Camera camera) { if (m_componentCreature.ComponentHealth.Health > 0f && m_componentMiner != null && m_componentMiner.ActiveBlockValue != 0) { int num = Terrain.ExtractContents(m_componentMiner.ActiveBlockValue); Block block = BlocksManager.Blocks[num]; Matrix m = base.AbsoluteBoneTransformsForCamera[m_hand2Bone.Index]; m *= camera.InvertedViewMatrix; m.Right = Vector3.Normalize(m.Right); m.Up = Vector3.Normalize(m.Up); m.Forward = Vector3.Normalize(m.Forward); Matrix matrix = Matrix.CreateRotationY(MathUtils.DegToRad(block.InHandRotation.Y) + m_inHandItemRotation.Y) * Matrix.CreateRotationZ(MathUtils.DegToRad(block.InHandRotation.Z) + m_inHandItemRotation.Z) * Matrix.CreateRotationX(MathUtils.DegToRad(block.InHandRotation.X) + m_inHandItemRotation.X) * Matrix.CreateTranslation(block.InHandOffset + m_inHandItemOffset) * Matrix.CreateTranslation(new Vector3(0.05f, 0.05f, -0.56f) * (m_componentCreature.ComponentBody.BoxSize.Y / 1.77f)) * m; int x = Terrain.ToCell(matrix.Translation.X); int y = Terrain.ToCell(matrix.Translation.Y); int z = Terrain.ToCell(matrix.Translation.Z); m_drawBlockEnvironmentData.InWorldMatrix = matrix; m_drawBlockEnvironmentData.Humidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z); m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y); m_drawBlockEnvironmentData.Light = m_subsystemTerrain.Terrain.GetCellLight(x, y, z); m_drawBlockEnvironmentData.BillboardDirection = -Vector3.UnitZ; m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain; Matrix matrix2 = matrix * camera.ViewMatrix; block.DrawBlock(m_subsystemModelsRenderer.PrimitivesRenderer, m_componentMiner.ActiveBlockValue, Color.White, block.InHandScale, ref matrix2, m_drawBlockEnvironmentData); } if (m_componentPlayer != null && camera.GameWidget.PlayerData != m_componentPlayer.PlayerData) { Vector3 position = Vector3.Transform(m_componentCreature.ComponentBody.Position + 1.02f * Vector3.UnitY * m_componentCreature.ComponentBody.BoxSize.Y, camera.ViewMatrix); if (position.Z < 0f) { Color color = Color.Lerp(Color.White, Color.Transparent, MathUtils.Saturate((position.Length() - 4f) / 3f)); if (color.A > 8) { Vector3 right = Vector3.TransformNormal(0.005f * Vector3.Normalize(Vector3.Cross(camera.ViewDirection, Vector3.UnitY)), camera.ViewMatrix); Vector3 down = Vector3.TransformNormal(-0.005f * Vector3.UnitY, camera.ViewMatrix); BitmapFont font = ContentManager.Get <BitmapFont>("Fonts/Pericles"); m_subsystemModelsRenderer.PrimitivesRenderer.FontBatch(font, 1, DepthStencilState.DepthRead, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.LinearClamp).QueueText(m_componentPlayer.PlayerData.Name, position, right, down, color, TextAnchor.HorizontalCenter | TextAnchor.Bottom); } } } base.DrawExtras(camera); }
public void Draw(Camera camera, int drawOrder) { double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime; m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain; Matrix matrix = Matrix.CreateRotationY((float)MathUtils.Remainder(totalElapsedGameTime, 6.2831854820251465)); float num = MathUtils.Min(m_subsystemSky.VisibilityRange, 30f); foreach (Pickable pickable in m_pickables) { Vector3 position = pickable.Position; float num2 = Vector3.Dot(camera.ViewDirection, position - camera.ViewPosition); if (num2 > -0.5f && num2 < num) { int num3 = Terrain.ExtractContents(pickable.Value); Block block = BlocksManager.Blocks[num3]; float num4 = (float)(totalElapsedGameTime - pickable.CreationTime); if (!pickable.StuckMatrix.HasValue) { position.Y += 0.25f * MathUtils.Saturate(3f * num4); } int x = Terrain.ToCell(position.X); int num5 = Terrain.ToCell(position.Y); int z = Terrain.ToCell(position.Z); TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z); if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1 && num5 >= 0 && num5 < 255) { m_drawBlockEnvironmentData.Humidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z); m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5); float f = MathUtils.Max(position.Y - (float)num5 - 0.75f, 0f) / 0.25f; int num6 = pickable.Light = (int)MathUtils.Lerp(m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z), m_subsystemTerrain.Terrain.GetCellLightFast(x, num5 + 1, z), f); } m_drawBlockEnvironmentData.Light = pickable.Light; m_drawBlockEnvironmentData.BillboardDirection = pickable.Position - camera.ViewPosition; m_drawBlockEnvironmentData.InWorldMatrix.Translation = position; if (pickable.StuckMatrix.HasValue) { Matrix matrix2 = pickable.StuckMatrix.Value; block.DrawBlock(m_primitivesRenderer, pickable.Value, Color.White, 0.3f, ref matrix2, m_drawBlockEnvironmentData); } else { matrix.Translation = position + new Vector3(0f, 0.04f * MathUtils.Sin(3f * num4), 0f); block.DrawBlock(m_primitivesRenderer, pickable.Value, Color.White, 0.3f, ref matrix, m_drawBlockEnvironmentData); } } } m_primitivesRenderer.Flush(camera.ViewProjectionMatrix); }
public void MatureSapling(SaplingData saplingData) { if (!(m_subsystemGameInfo.TotalElapsedGameTime >= saplingData.MatureTime)) { return; } int x = saplingData.Point.X; int y = saplingData.Point.Y; int z = saplingData.Point.Z; TerrainChunk chunkAtCell = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z - 6); TerrainChunk chunkAtCell2 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z + 6); TerrainChunk chunkAtCell3 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z - 6); TerrainChunk chunkAtCell4 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z + 6); if (chunkAtCell != null && chunkAtCell.State == TerrainChunkState.Valid && chunkAtCell2 != null && chunkAtCell2.State == TerrainChunkState.Valid && chunkAtCell3 != null && chunkAtCell3.State == TerrainChunkState.Valid && chunkAtCell4 != null && chunkAtCell4.State == TerrainChunkState.Valid) { int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(x, y - 1, z); if (cellContents == 2 || cellContents == 8) { if (base.SubsystemTerrain.Terrain.GetCellLight(x, y + 1, z) >= 9) { bool flag = false; for (int i = x - 1; i <= x + 1; i++) { for (int j = z - 1; j <= z + 1; j++) { int cellContents2 = base.SubsystemTerrain.Terrain.GetCellContents(i, y - 1, j); if (BlocksManager.Blocks[cellContents2] is WaterBlock) { flag = true; break; } } } float num = 0f; if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) { num = 1f; } else { int num2 = base.SubsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y); int num3 = base.SubsystemTerrain.Terrain.GetHumidity(x, z); if (flag) { num2 = (num2 + 10) / 2; num3 = MathUtils.Max(num3, 12); } num = 2f * PlantsManager.CalculateTreeProbability(saplingData.Type, num2, num3, y); } if (m_random.Bool(num)) { base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(0, 0, 0)); if (!GrowTree(x, y, z, saplingData.Type)) { base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0)); } } else { base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0)); } } else if (m_subsystemGameInfo.TotalElapsedGameTime > saplingData.MatureTime + 1200.0) { base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0)); } } else { base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0)); } } else { saplingData.MatureTime = m_subsystemGameInfo.TotalElapsedGameTime; } }
public void Draw(Camera camera, int drawOrder) { m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain; m_drawBlockEnvironmentData.InWorldMatrix = Matrix.Identity; float num = MathUtils.Sqr(m_subsystemSky.VisibilityRange); foreach (Projectile projectile in m_projectiles) { Vector3 position = projectile.Position; if (!projectile.NoChunk && Vector3.DistanceSquared(camera.ViewPosition, position) < num && camera.ViewFrustum.Intersection(position)) { int x = Terrain.ToCell(position.X); int num2 = Terrain.ToCell(position.Y); int z = Terrain.ToCell(position.Z); int num3 = Terrain.ExtractContents(projectile.Value); Block block = BlocksManager.Blocks[num3]; TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z); if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1 && num2 >= 0 && num2 < 255) { m_drawBlockEnvironmentData.Humidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z); m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num2); projectile.Light = m_subsystemTerrain.Terrain.GetCellLightFast(x, num2, z); } m_drawBlockEnvironmentData.Light = projectile.Light; m_drawBlockEnvironmentData.BillboardDirection = (block.AlignToVelocity ? null : new Vector3?(camera.ViewDirection)); m_drawBlockEnvironmentData.InWorldMatrix.Translation = position; Matrix matrix; if (block.AlignToVelocity) { CalculateVelocityAlignMatrix(block, position, projectile.Velocity, out matrix); } else if (projectile.Rotation != Vector3.Zero) { matrix = Matrix.CreateFromAxisAngle(Vector3.Normalize(projectile.Rotation), projectile.Rotation.Length()); matrix.Translation = projectile.Position; } else { matrix = Matrix.CreateTranslation(projectile.Position); } block.DrawBlock(m_primitivesRenderer, projectile.Value, Color.White, 0.3f, ref matrix, m_drawBlockEnvironmentData); } } m_primitivesRenderer.Flush(camera.ViewProjectionMatrix); }
public void Draw(Camera camera, int drawOrder) { if (!(m_componentPlayer.ComponentHealth.Health > 0f) || !camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) || !m_componentPlayer.ComponentInput.IsControlledByVr) { return; } Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition; int x = Terrain.ToCell(eyePosition.X); int num = Terrain.ToCell(eyePosition.Y); int z = Terrain.ToCell(eyePosition.Z); int activeBlockValue = m_componentMiner.ActiveBlockValue; if (Time.FrameStartTime >= m_nextHandLightTime) { float?num2 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition); if (num2.HasValue) { m_nextHandLightTime = Time.FrameStartTime + 0.1; m_handLight = num2.Value; } } Matrix identity = Matrix.Identity; if (m_pokeAnimationTime > 0f) { float num3 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI); if (activeBlockValue != 0) { identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num3); } else { identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num3); } } if (!VrManager.IsControllerPresent(VrController.Right)) { return; } Matrix m = VrManager.HmdMatrixInverted * Matrix.CreateWorld(camera.ViewPosition, camera.ViewDirection, camera.ViewUp) * camera.ViewMatrix; Matrix controllerMatrix = VrManager.GetControllerMatrix(VrController.Right); if (activeBlockValue == 0) { Display.DepthStencilState = DepthStencilState.Default; Display.RasterizerState = RasterizerState.CullCounterClockwiseScissor; m_shader.Texture = m_componentPlayer.ComponentCreatureModel.TextureOverride; m_shader.SamplerState = SamplerState.PointClamp; m_shader.MaterialColor = Vector4.One; m_shader.AmbientLightColor = new Vector3(m_handLight * LightingManager.LightAmbient); m_shader.DiffuseLightColor1 = new Vector3(m_handLight); m_shader.DiffuseLightColor2 = new Vector3(m_handLight); m_shader.LightDirection1 = -Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix); m_shader.LightDirection2 = -Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix); m_shader.Transforms.View = Matrix.Identity; m_shader.Transforms.Projection = camera.ProjectionMatrix; m_shader.Transforms.World[0] = Matrix.CreateScale(0.01f) * identity * controllerMatrix * m; foreach (ModelMesh mesh in m_vrHandModel.Meshes) { foreach (ModelMeshPart meshPart in mesh.MeshParts) { Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount); } } } else { if (num >= 0 && num <= 255) { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z); if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1) { m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num, z); } } int num4 = Terrain.ExtractContents(activeBlockValue); Block block = BlocksManager.Blocks[num4]; Vector3 vector = block.InHandRotation * ((float)Math.PI / 180f) + m_itemRotation; Matrix matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * Matrix.CreateTranslation(block.InHandOffset) * identity * Matrix.CreateTranslation(m_itemOffset) * controllerMatrix * m; m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain; m_drawBlockEnvironmentData.InWorldMatrix = matrix; m_drawBlockEnvironmentData.Light = m_itemLight; m_drawBlockEnvironmentData.Humidity = m_subsystemTerrain.Terrain.GetHumidity(x, z); m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num); block.DrawBlock(m_primitivesRenderer, activeBlockValue, Color.White, block.InHandScale, ref matrix, m_drawBlockEnvironmentData); } m_primitivesRenderer.Flush(camera.ProjectionMatrix); }
public void Draw(Camera camera, int drawOrder) { if (m_componentPlayer.ComponentHealth.Health > 0f && camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) && !m_componentPlayer.ComponentInput.IsControlledByVr) { Viewport viewport = Display.Viewport; Viewport viewport2 = viewport; viewport2.MaxDepth *= 0.1f; Display.Viewport = viewport2; try { Matrix identity = Matrix.Identity; if (m_swapAnimationTime > 0f) { float num = MathUtils.Pow(MathUtils.Sin(m_swapAnimationTime * (float)Math.PI), 3f); identity *= Matrix.CreateTranslation(0f, -0.8f * num, 0.2f * num); } if (m_pokeAnimationTime > 0f) { float num2 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI); if (m_value != 0) { identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num2); identity *= Matrix.CreateTranslation(-0.5f * num2, 0.1f * num2, 0f * num2); } else { identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num2); identity *= Matrix.CreateTranslation(-0.1f * num2, 0.2f * num2, -0.05f * num2); } } if (m_componentRider.Mount != null) { ComponentCreatureModel componentCreatureModel = m_componentRider.Mount.Entity.FindComponent <ComponentCreatureModel>(); if (componentCreatureModel != null) { float num3 = componentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f + 0.5f; Vector3 position = default(Vector3); position.Y = 0.02f * MathUtils.Sin(num3); position.Z = 0.02f * MathUtils.Sin(num3); identity *= Matrix.CreateRotationX(0.05f * MathUtils.Sin(num3 * 1f)) * Matrix.CreateTranslation(position); } } else { float num4 = m_componentPlayer.ComponentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f; Vector3 position2 = default(Vector3); position2.X = 0.03f * MathUtils.Sin(num4 * 1f); position2.Y = 0.02f * MathUtils.Sin(num4 * 2f); position2.Z = 0.02f * MathUtils.Sin(num4 * 1f); identity *= Matrix.CreateRotationZ(1f * position2.X) * Matrix.CreateTranslation(position2); } Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition; int x = Terrain.ToCell(eyePosition.X); int num5 = Terrain.ToCell(eyePosition.Y); int z = Terrain.ToCell(eyePosition.Z); Matrix m = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation); m.Translation = m_componentPlayer.ComponentCreatureModel.EyePosition; if (m_value != 0) { if (num5 >= 0 && num5 <= 255) { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z); if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1) { m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z); } } int num6 = Terrain.ExtractContents(m_value); Block block = BlocksManager.Blocks[num6]; Vector3 vector = block.FirstPersonRotation * ((float)Math.PI / 180f) + m_itemRotation; Vector3 position3 = block.FirstPersonOffset + m_itemOffset; position3 += m_itemOffset; Matrix matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * identity * Matrix.CreateTranslation(position3) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m; m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain; m_drawBlockEnvironmentData.InWorldMatrix = matrix; m_drawBlockEnvironmentData.Light = m_itemLight; m_drawBlockEnvironmentData.Humidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z); m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5); block.DrawBlock(m_primitivesRenderer, m_value, Color.White, block.FirstPersonScale, ref matrix, m_drawBlockEnvironmentData); m_primitivesRenderer.Flush(camera.ViewProjectionMatrix); } else { if (Time.FrameStartTime >= m_nextHandLightTime) { float?num7 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition); if (num7.HasValue) { m_nextHandLightTime = Time.FrameStartTime + 0.1; m_handLight = num7.Value; } } Vector3 position4 = new Vector3(0.25f, -0.3f, -0.05f); Matrix matrix2 = Matrix.CreateScale(0.01f) * Matrix.CreateRotationX(0.8f) * Matrix.CreateRotationY(0.4f) * identity * Matrix.CreateTranslation(position4) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m * camera.ViewMatrix; Display.DepthStencilState = DepthStencilState.Default; Display.RasterizerState = RasterizerState.CullCounterClockwiseScissor; m_shader.Texture = m_componentPlayer.ComponentCreatureModel.TextureOverride; m_shader.SamplerState = SamplerState.PointClamp; m_shader.MaterialColor = Vector4.One; m_shader.AmbientLightColor = new Vector3(m_handLight * LightingManager.LightAmbient); m_shader.DiffuseLightColor1 = new Vector3(m_handLight); m_shader.DiffuseLightColor2 = new Vector3(m_handLight); m_shader.LightDirection1 = Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix); m_shader.LightDirection2 = Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix); m_shader.Transforms.World[0] = matrix2; m_shader.Transforms.View = Matrix.Identity; m_shader.Transforms.Projection = camera.ProjectionMatrix; foreach (ModelMesh mesh in m_handModel.Meshes) { foreach (ModelMeshPart meshPart in mesh.MeshParts) { Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount); } } } } finally { Display.Viewport = viewport; } } }
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; }