private void Pulse(RadiationPulse Pulse)
        {
            StopWatchlog.Restart();

            //Radiation distance
            int radius = (int)Math.Round(Pulse.Strength / (Math.PI * 75));

            if (radius > 50)
            {
                radius = 50;
            }

            //Logger.Log("Radius > " + Radius);
            //Generates the conference
            circleBres(Pulse.Location.x, Pulse.Location.y, radius);

            //Logger.Log("CircleCircumference.Count > " + CircleCircumference.Count);
            //Logger.Log("Pulse.Strengt> " + Pulse.Strength);
            //Radiation for each line ( Dont worry it stacks)
            float InitialRadiation = Pulse.Strength / CircleCircumference.Count;

            foreach (var ToPoint in CircleCircumference)
            {
                DrawRadiationLine(Pulse.Location.x, Pulse.Location.y, ToPoint.x, ToPoint.y, InitialRadiation, Pulse);
            }

            //Logger.Log("CircleArea.Count > " + CircleArea.Count);
            //Set values on tiles
            foreach (var NodePoint in CircleArea)
            {
                NodePoint.AddRadiationPulse(NodePoint.MidCalculationNumbers, DateTime.Now,
                                            Pulse.SourceID); //Drops off too quickly
                NodePoint.MidCalculationNumbers = 0;
                //Logger.Log("rad onv " + NodePoint.RadiationLevel);
            }

            CircleCircumference.Clear();
            CircleArea.Clear();

            StopWatchlog.Stop();
            Logger.Log("StopWatchlog ElapsedMilliseconds time " + StopWatchlog.ElapsedMilliseconds, Category.Radiation);
        }
        //https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C.23
        void DrawRadiationLine(int x0, int y0, int x1, int y1, float RadiationStrength, RadiationPulse Pulse)
        {
            int   dx = Math.Abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
            int   dy = Math.Abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
            int   err = (dx > dy ? dx : -dy) / 2, e2;
            float RadiationOnStep = RadiationStrength;

            for (;;)
            {
                var NodePoint     = Pulse.Matrix.GetMetaDataNode(new Vector2Int(x0, y0));
                var RadiationNode = NodePoint?.RadiationNode;
                if (RadiationNode != null)
                {
                    foreach (var Layer in Pulse.Matrix.MetaTileMap.Layers)
                    {
                        if (Layer.Key == LayerType.Underfloor)
                        {
                            continue;
                        }
                        var BasicTile_ = Pulse.Matrix.MetaTileMap.GetTile(new Vector2Int(x0, y0).To3Int(), Layer.Key) as BasicTile;
                        if (BasicTile_ != null)
                        {
                            RadiationOnStep *= BasicTile_.RadiationPassability;
                        }
                    }

                    CircleArea.Add(RadiationNode);
                    RadiationNode.MidCalculationNumbers += RadiationOnStep;
                }
                if (x0 == x1 && y0 == y1)
                {
                    break;
                }
                e2 = err;
                if (e2 > -dx)
                {
                    err -= dy;
                    x0  += sx;
                }

                if (e2 < dy)
                {
                    err += dx;
                    y0  += sy;
                }
            }
        }
Beispiel #3
0
        //https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C.23
        void DrawRadiationLine(int x0, int y0, int x1, int y1, float RadiationStrength, RadiationPulse Pulse)
        {
            int   dx = Math.Abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
            int   dy = Math.Abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
            int   err = (dx > dy ? dx : -dy) / 2, e2;
            float RadiationOnStep = RadiationStrength;

            for (;;)
            {
                var NodePoint     = Pulse.Matrix.GetMetaDataNode(new Vector2Int(x0, y0));
                var RadiationNode = NodePoint?.RadiationNode;
                if (RadiationNode != null)
                {
                    if (NodePoint.IsOccupied)
                    {
                        RadiationOnStep *= 0.15f;
                    }
                    //RadiationOnStep *= RadiationNode.RadiationPassability;

                    CircleArea.Add(RadiationNode);
                    RadiationNode.MidCalculationNumbers += RadiationOnStep;
                }
                if (x0 == x1 && y0 == y1)
                {
                    break;
                }
                e2 = err;
                if (e2 > -dx)
                {
                    err -= dy;
                    x0  += sx;
                }

                if (e2 < dy)
                {
                    err += dx;
                    y0  += sy;
                }
            }
        }
        //https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C.23
        void DrawRadiationLine(int x0, int y0, int x1, int y1, float RadiationStrength, RadiationPulse Pulse)
        {
            int   dx = Math.Abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
            int   dy = Math.Abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
            int   err = (dx > dy ? dx : -dy) / 2, e2;
            float RadiationOnStep = RadiationStrength;

            for (;;)
            {
                var WorldPSos     = new Vector3Int(x0, y0, 0);
                var Matrix        = MatrixManager.AtPoint(WorldPSos, CustomNetworkManager.IsServer);
                var Local         = WorldPSos.ToLocal(Matrix.Matrix).RoundToInt();
                var NodePoint     = Matrix.MetaDataLayer.Get(Local);
                var RadiationNode = NodePoint?.RadiationNode;
                if (RadiationNode != null)
                {
                    foreach (var Layer in Matrix.MetaTileMap.Layers)
                    {
                        if (Layer.Key == LayerType.Underfloor)
                        {
                            continue;
                        }
                        var basicTile = Matrix.MetaTileMap.GetTile(Local, Layer.Key) as BasicTile;
                        if (basicTile != null)
                        {
                            RadiationOnStep *= basicTile.RadiationPassability;
                        }
                    }

                    CircleArea.Add(RadiationNode);
                    RadiationNode.MidCalculationNumbers += RadiationOnStep;
                }

                if (x0 == x1 && y0 == y1)
                {
                    break;
                }
                e2 = err;
                if (e2 > -dx)
                {
                    err -= dy;
                    x0  += sx;
                }

                if (e2 < dy)
                {
                    err += dx;
                    y0  += sy;
                }
            }
        }