Example #1
0
        public static void Explode(Main main, Voxel map, Voxel.Coord coord, int radius = 8, float physicsRadius = 12.0f)
        {
            Vector3 pos = map.GetAbsolutePosition(coord);

            Explosion.explode(main, map, coord, pos, radius, physicsRadius);
        }
Example #2
0
        public override void Awake()
        {
            base.Awake();

            this.blockFactory = Factory.Get <EffectBlockFactory>();

            this.EnabledWhenPaused = false;

            if (main.EditorEnabled)
            {
                this.BlockQueue.Clear();
            }

            this.particles = ParticleSystem.Get(main, "WhiteShatter");

            for (int i = 0; i < maxSparkLights; i++)
            {
                PointLight light = new PointLight();
                light.Serialize     = false;
                light.Color.Value   = new Vector3(1.0f);
                light.Enabled.Value = false;
                this.Entity.Add(light);
                this.sparkLights.Add(light);
            }

            if (!this.main.EditorEnabled)
            {
                this.Add(new CommandBinding <Voxel, IEnumerable <Voxel.Coord>, Voxel>(Voxel.GlobalCellsFilled, delegate(Voxel map, IEnumerable <Voxel.Coord> coords, Voxel transferredFromMap)
                {
                    foreach (Voxel.Coord c in coords)
                    {
                        Voxel.t id = c.Data.ID;
                        if (id == Voxel.t.Powered || id == Voxel.t.PoweredSwitch || id == Voxel.t.HardPowered || id == Voxel.t.Infected || id == Voxel.t.HardInfected ||
                            (transferredFromMap == null && (id == Voxel.t.Blue || id == Voxel.t.Neutral || id == Voxel.t.Hard)))
                        {
                            Voxel.Coord newCoord = c;
                            newCoord.Data        = Voxel.States.Empty;
                            int generation;
                            EffectBlock.Entry generationsKey = new EffectBlock.Entry {
                                Voxel = map, Coordinate = newCoord
                            };
                            if (this.generations.TryGetValue(generationsKey, out generation))
                            {
                                this.generations.Remove(generationsKey);
                            }
                            if (!this.isInQueue(map.Entity, newCoord, false))
                            {
                                this.BlockQueue.Add(new ScheduledBlock
                                {
                                    Voxel      = map.Entity,
                                    Coordinate = newCoord,
                                    Time       = propagateDelay,
                                    Generation = generation,
                                });
                            }
                        }
                    }
                }));

                this.Add(new CommandBinding <Voxel, IEnumerable <Voxel.Coord>, Voxel>(Voxel.GlobalCellsEmptied, delegate(Voxel map, IEnumerable <Voxel.Coord> coords, Voxel transferringToNewMap)
                {
                    foreach (Voxel.Coord coord in coords)
                    {
                        Voxel.t id = coord.Data.ID;
                        if (id == Voxel.t.Powered || id == Voxel.t.PoweredSwitch || id == Voxel.t.HardPowered || id == Voxel.t.PermanentPowered)
                        {
                            this.removedPoweredCoords.Add(coord);
                        }
                        if (transferringToNewMap != null)
                        {
                            continue;
                        }

                        if (id == Voxel.t.Critical)                         // Critical. Explodes when destroyed.
                        {
                            Explosion.Explode(main, map, coord);
                        }
                        else if (id == Voxel.t.Powered || id == Voxel.t.Blue || id == Voxel.t.Neutral || id == Voxel.t.Infected || id == Voxel.t.Floater)
                        {
                            int generation;
                            Voxel.Coord c = coord;
                            c.Data        = Voxel.States.Empty;
                            EffectBlock.Entry generationKey = new EffectBlock.Entry {
                                Voxel = map, Coordinate = c
                            };
                            if (this.generations.TryGetValue(generationKey, out generation))
                            {
                                this.generations.Remove(generationKey);
                            }

                            if (id == Voxel.t.Floater)
                            {
                                Entity blockEntity      = this.blockFactory.CreateAndBind(main);
                                EffectBlock effectBlock = blockEntity.Get <EffectBlock>();
                                coord.Data.ApplyToEffectBlock(blockEntity.Get <ModelInstance>());
                                effectBlock.Delay            = 4.0f;
                                effectBlock.Offset.Value     = map.GetRelativePosition(coord);
                                effectBlock.StartPosition    = map.GetAbsolutePosition(coord) + new Vector3(2.5f, 5.0f, 2.5f);
                                effectBlock.StartOrientation = Quaternion.CreateFromYawPitchRoll(1.0f, 1.0f, 0);
                                effectBlock.TotalLifetime    = 0.5f;
                                effectBlock.Setup(map.Entity, coord, coord.Data.ID);
                                main.Add(blockEntity);
                            }

                            if (generation == 0)
                            {
                                if (!this.isInQueue(map.Entity, coord, true))
                                {
                                    this.BlockQueue.Add(new ScheduledBlock
                                    {
                                        Voxel      = map.Entity,
                                        Coordinate = coord,
                                        Time       = propagateDelay,
                                        Removing   = true,
                                    });
                                }
                            }
                            else if (generation < maxGenerations)
                            {
                                Direction down = map.GetRelativeDirection(Direction.NegativeY);
                                for (int i = 0; i < 6; i++)
                                {
                                    Direction dir        = DirectionExtensions.Directions[i];
                                    Voxel.Coord adjacent = coord.Move(dir);
                                    if (!coords.Contains(adjacent))
                                    {
                                        Voxel.t adjacentID     = map[adjacent].ID;
                                        bool adjacentIsFloater = adjacentID == Voxel.t.Floater;
                                        if (dir != down || adjacentIsFloater)
                                        {
                                            if (adjacentID == Voxel.t.Powered || adjacentID == Voxel.t.Blue || adjacentID == Voxel.t.Neutral || adjacentID == Voxel.t.Infected || adjacentIsFloater)
                                            {
                                                if (!this.isInQueue(map.Entity, adjacent, true))
                                                {
                                                    this.BlockQueue.Add(new ScheduledBlock
                                                    {
                                                        Voxel      = map.Entity,
                                                        Coordinate = adjacent,
                                                        Time       = propagateDelay,
                                                        Removing   = true,
                                                        Generation = generation + 1,
                                                    });
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (id == Voxel.t.White || id == Voxel.t.Glass)                         // Shatter effects.
                        {
                            ParticleSystem shatter = ParticleSystem.Get(main, "WhiteShatter");
                            Vector3 pos            = map.GetAbsolutePosition(coord);
                            for (int i = 0; i < 50; i++)
                            {
                                Vector3 offset = new Vector3((float)this.random.NextDouble() - 0.5f, (float)this.random.NextDouble() - 0.5f, (float)this.random.NextDouble() - 0.5f);
                                shatter.AddParticle(pos + offset, offset);
                            }
                            float time = this.main.TotalTime;
                            if (time - this.lastShatterSound > 0.3f)
                            {
                                this.lastShatterSound = time;
                                Sound.PostEvent(AK.EVENTS.PLAY_WHITE_SHATTER, pos);
                            }
                        }
                    }

                    if (this.removedPoweredCoords.Count > 0)
                    {
                        IEnumerable <IEnumerable <Voxel.Box> > poweredIslands = map.GetAdjacentIslands(this.removedPoweredCoords, x => x.ID == Voxel.t.Powered || x.ID == Voxel.t.HardPowered, x => x == Voxel.States.PermanentPowered || x == Voxel.States.PoweredSwitch);
                        List <Voxel.Coord> poweredCoords = poweredIslands.SelectMany(x => x).SelectMany(x => x.GetCoords()).ToList();
                        if (poweredCoords.Count > 0)
                        {
                            lock (map.MutationLock)
                            {
                                map.Empty(poweredCoords, true, true, map, false);
                                for (int i = 0; i < poweredCoords.Count; i++)
                                {
                                    Voxel.Coord coord = poweredCoords[i];
                                    if (coord.Data.ID == Voxel.t.HardPowered)
                                    {
                                        map.Fill(coord, Voxel.States.Hard, true, map);
                                    }
                                    else
                                    {
                                        map.Fill(coord, Voxel.States.Blue, true, map);
                                    }
                                }
                            }
                            this.toRegenerate.Add(map);
                        }
                        this.removedPoweredCoords.Clear();
                    }
                }));
            }
        }
Example #3
0
 public static void Explode(Main main, Vector3 pos, int radius = 8, float physicsRadius = 12.0f)
 {
     Explosion.explode(main, null, new Voxel.Coord(), pos, radius, physicsRadius);
 }