コード例 #1
0
        private void UpdateColour()
        {
            if (timer < 7)
            {
                return;
            }
            timer = 0;

            if (firelight == null)
            {
                return;
            }

            var temperature = node.GasMix.Temperature;
            var temp2Colour = Temp2Colour(temperature);
            var heatR       = temp2Colour.r * 255;
            var heatG       = temp2Colour.g * 255;
            var heatB       = temp2Colour.b * 255;
            var heatA       = 255f;

            var greyscaleFire = 1f;             //This determines how greyscaled the fire is.

            //This is where fire is very orange, we turn it into the normal fire texture here.
            if (temperature < 5000)
            {
                var normalAmt = DMMath.GaussLerp(temperature, 1000, 3000);
                heatR          = DMMath.Lerp(heatR, 255, normalAmt);
                heatG          = DMMath.Lerp(heatG, 255, normalAmt);
                heatB          = DMMath.Lerp(heatB, 255, normalAmt);
                heatA         -= DMMath.GaussLerp(temperature, -5000, 5000) * 128;
                greyscaleFire -= normalAmt;
            }

            //Past this temperature the fire will gradually turn a bright purple
            if (temperature > 40000)
            {
                var purpleAmt = temperature < DMMath.Lerp(40000, 200000, 0.5f) ? DMMath.GaussLerp(temperature, 40000, 200000) : 1;
                heatR = DMMath.Lerp(heatR, 255, purpleAmt);
            }

            //Somewhere at this temperature nitryl happens.
            if (temperature > 200000 && temperature < 500000)
            {
                var sparkleAmt = DMMath.GaussLerp(temperature, 200000, 500000);
                var newColour  = new Color(1f, 1f, 1f, sparkleAmt);

                var currentColour = node.PositionMatrix.MetaTileMap.GetColourOfFirstTile(node.Position,
                                                                                         OverlayType.FireSparkles, LayerType.Effects);

                //Only add/remove if we need to
                if (currentColour != newColour)
                {
                    if (currentColour != null && hasSparkle)
                    {
                        //Remove old so it can be replaced by one with different alpha value
                        node.PositionMatrix.MetaTileMap.RemoveOverlaysOfType(
                            node.Position, LayerType.Effects, OverlayType.FireSparkles);
                    }

                    hasSparkle = true;

                    //Add new
                    node.PositionMatrix.MetaTileMap.AddOverlay(
                        node.Position, TileType.Effects, "FireSparkles", color: newColour);
                }
            }
            else if (hasSparkle)
            {
                hasSparkle = false;

                //Remove as its not needed anymore
                node.PositionMatrix.MetaTileMap.RemoveOverlaysOfType(
                    node.Position, LayerType.Effects, OverlayType.FireSparkles);
            }

            //Lightning because very anime.
            if (temperature > 400000 && temperature < 1500000)
            {
                if (hasOvercharge == false)
                {
                    hasOvercharge = true;

                    //Add new
                    node.PositionMatrix.MetaTileMap.AddOverlay(
                        node.Position, TileType.Effects, "FireOverCharged");
                }
            }
            else if (hasOvercharge)
            {
                hasOvercharge = false;

                //Remove overcharge as its not needed anymore
                node.PositionMatrix.MetaTileMap.RemoveOverlaysOfType(
                    node.Position, LayerType.Effects, OverlayType.FireOverCharged);
            }

            //This is where noblium happens. Some fusion-y effects.
            if (temperature > 4500000)
            {
                var fusionAmt = temperature < DMMath.Lerp(4500000, 12000000, 0.5f)
                                        ? DMMath.GaussLerp(temperature, 4500000, 12000000) : 1;
                var newColour = new Color(1f, 1f, 1f, fusionAmt);

                var currentColour = node.PositionMatrix.MetaTileMap.GetColourOfFirstTile(node.Position,
                                                                                         OverlayType.FireSparkles, LayerType.Effects);

                //Only add/remove if we need to
                if (currentColour != newColour)
                {
                    if (currentColour != null && hasFusion)
                    {
                        //Remove old so it can be replaced by one with different alpha value
                        node.PositionMatrix.MetaTileMap.RemoveOverlaysOfType(
                            node.Position, LayerType.Effects, OverlayType.FireFusion);

                        node.PositionMatrix.MetaTileMap.RemoveOverlaysOfType(
                            node.Position, LayerType.Effects, OverlayType.FireRainbow);
                    }

                    hasFusion = true;

                    //Add new
                    node.PositionMatrix.MetaTileMap.AddOverlay(
                        node.Position, TileType.Effects, "FireFusion", color: newColour);

                    //Add new
                    node.PositionMatrix.MetaTileMap.AddOverlay(
                        node.Position, TileType.Effects, "FireRainbow", color: newColour);

                    heatR = DMMath.Lerp(heatR, 255, fusionAmt);
                    heatG = DMMath.Lerp(heatG, 255, fusionAmt);
                    heatB = DMMath.Lerp(heatB, 255, fusionAmt);
                }
            }
            else if (hasFusion)
            {
                hasFusion = false;

                //Remove fusion and rainbow as they are not needed anymore
                node.PositionMatrix.MetaTileMap.RemoveOverlaysOfType(
                    node.Position, LayerType.Effects, OverlayType.FireFusion);

                node.PositionMatrix.MetaTileMap.RemoveOverlaysOfType(
                    node.Position, LayerType.Effects, OverlayType.FireRainbow);
            }

            firelight.SetColour(new Color(
                                    DMMath.Lerp(250, heatR, greyscaleFire) / 255,
                                    DMMath.Lerp(250, heatG, greyscaleFire) / 255,
                                    DMMath.Lerp(250, heatB, greyscaleFire) / 255,
                                    heatA / 255));
        }