Exemplo n.º 1
0
 private bool isInQueue(Entity m, Voxel.Coord c, bool removing)
 {
     for (int i = 0; i < this.BlockQueue.Count; i++)
     {
         ScheduledBlock b = this.BlockQueue[i];
         if (b.Removing == removing && m == b.Voxel.Target && b.Coordinate.Equivalent(c))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        public void Update(float dt)
        {
            float sparkLightFade = sparkLightBrightness * dt / sparkLightFadeTime;

            for (int i = 0; i < activeSparkLights; i++)
            {
                PointLight light = this.sparkLights[i];
                float      a     = light.Color.Value.X - sparkLightFade;
                if (a < 0.0f)
                {
                    light.Enabled.Value = false;
                    PointLight swap = this.sparkLights[activeSparkLights - 1];
                    this.sparkLights[i] = swap;
                    this.sparkLights[activeSparkLights - 1] = light;
                    activeSparkLights--;
                    oldestSparkLight = activeSparkLights;
                }
                else
                {
                    light.Color.Value = new Vector3(a);
                }
            }

            for (int i = 0; i < this.BlockQueue.Length; i++)
            {
                ScheduledBlock entry = this.BlockQueue[i];
                entry.Time -= dt;
                if (entry.Time < 0.0f)
                {
                    this.BlockQueue.RemoveAt(i);
                    i--;

                    Entity mapEntity = entry.Voxel.Target;
                    if (mapEntity != null && mapEntity.Active)
                    {
                        Voxel       map = mapEntity.Get <Voxel>();
                        Voxel.Coord c   = entry.Coordinate;
                        Voxel.t     id  = map[c].ID;

                        bool regenerate = false;

                        if (entry.Removing)
                        {
                            if (entry.Generation == 0 && id == 0)
                            {
                                Direction down = map.GetRelativeDirection(Direction.NegativeY);
                                for (int j = 0; j < 6; j++)
                                {
                                    Direction   dir               = DirectionExtensions.Directions[j];
                                    Voxel.Coord adjacent          = c.Move(dir);
                                    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 = 1,
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                            else if (entry.Generation > 0 && (id == Voxel.t.Blue || id == Voxel.t.Infected || id == Voxel.t.Powered || id == Voxel.t.PermanentPowered || id == Voxel.t.HardPowered || id == Voxel.t.PoweredSwitch || id == Voxel.t.Neutral || id == Voxel.t.Floater))
                            {
                                this.generations[new EffectBlock.Entry {
                                                     Voxel = map, Coordinate = c
                                                 }] = entry.Generation;
                                map.Empty(c);
                                this.SparksLowPriority(map.GetAbsolutePosition(c), Spark.Burn);
                                regenerate = true;
                            }
                        }
                        else if (id == Voxel.t.Blue)
                        {
                            for (int j = 0; j < 6; j++)
                            {
                                Direction   dir        = DirectionExtensions.Directions[j];
                                Voxel.Coord adjacent   = c.Move(dir);
                                Voxel.t     adjacentID = map[adjacent].ID;

                                if (adjacentID == Voxel.t.Powered || adjacentID == Voxel.t.PermanentPowered || adjacentID == Voxel.t.HardPowered || adjacentID == Voxel.t.PoweredSwitch)
                                {
                                    map.Empty(c, false, true, map);
                                    map.Fill(c, Voxel.States.Powered);
                                    this.SparksLowPriority(map.GetAbsolutePosition(c), Spark.Normal);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.Neutral && entry.Generation < maxGenerations)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    this.generations[new EffectBlock.Entry {
                                                         Voxel = map, Coordinate = adjacent
                                                     }] = entry.Generation + 1;
                                    map.Fill(adjacent, Voxel.States.Blue);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                            }
                        }
                        else if (id == Voxel.t.Neutral)
                        {
                            for (int j = 0; j < 6; j++)
                            {
                                Direction   dir        = DirectionExtensions.Directions[j];
                                Voxel.Coord adjacent   = c.Move(dir);
                                Voxel.t     adjacentID = map[adjacent].ID;
                                if (adjacentID == Voxel.t.Infected || adjacentID == Voxel.t.Blue || adjacentID == Voxel.t.Powered)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    map.Fill(adjacent, Voxel.States.Neutral);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.HardInfected)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    map.Fill(adjacent, Voxel.States.Hard);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                            }
                        }
                        else if (id == Voxel.t.Hard)
                        {
                            for (int j = 0; j < 6; j++)
                            {
                                Direction   dir        = DirectionExtensions.Directions[j];
                                Voxel.Coord adjacent   = c.Move(dir);
                                Voxel.t     adjacentID = map[adjacent].ID;
                                if (adjacentID == Voxel.t.HardInfected)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    map.Fill(adjacent, Voxel.States.Hard);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                            }
                        }
                        else if (id == Voxel.t.Powered || id == Voxel.t.PermanentPowered || id == Voxel.t.HardPowered || id == Voxel.t.PoweredSwitch)
                        {
                            for (int j = 0; j < 6; j++)
                            {
                                Direction   dir        = DirectionExtensions.Directions[j];
                                Voxel.Coord adjacent   = c.Move(dir);
                                Voxel.t     adjacentID = map[adjacent].ID;

                                if (id == Voxel.t.Powered && adjacentID == Voxel.t.Neutral && entry.Generation < maxGenerations)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    this.generations[new EffectBlock.Entry {
                                                         Voxel = map, Coordinate = adjacent
                                                     }] = entry.Generation + 1;
                                    map.Fill(adjacent, Voxel.States.Powered);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.Blue)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    map.Fill(adjacent, Voxel.States.Powered);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.Switch)
                                {
                                    map.Empty(adjacent, true, true, map);
                                    map.Fill(adjacent, Voxel.States.PoweredSwitch);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.Hard)
                                {
                                    map.Empty(adjacent, true, true, map);
                                    map.Fill(adjacent, Voxel.States.HardPowered);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Normal);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.Critical)
                                {
                                    map.Empty(adjacent);
                                    regenerate = true;
                                }
                            }
                        }
                        else if (id == Voxel.t.Infected || id == Voxel.t.HardInfected)
                        {
                            for (int j = 0; j < 6; j++)
                            {
                                Direction   dir        = DirectionExtensions.Directions[j];
                                Voxel.Coord adjacent   = c.Move(dir);
                                Voxel.t     adjacentID = map[adjacent].ID;
                                if (adjacentID == Voxel.t.Neutral && entry.Generation < maxGenerations)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    this.generations[new EffectBlock.Entry {
                                                         Voxel = map, Coordinate = adjacent
                                                     }] = entry.Generation + 1;
                                    map.Fill(adjacent, Voxel.States.Infected);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Dangerous);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.Hard && entry.Generation < maxGenerations)
                                {
                                    map.Empty(adjacent, false, true, map);
                                    this.generations[new EffectBlock.Entry {
                                                         Voxel = map, Coordinate = adjacent
                                                     }] = entry.Generation + 1;
                                    map.Fill(adjacent, Voxel.States.HardInfected);
                                    this.SparksLowPriority(map.GetAbsolutePosition(adjacent), Spark.Dangerous);
                                    regenerate = true;
                                }
                                else if (adjacentID == Voxel.t.Critical)
                                {
                                    map.Empty(adjacent);
                                    regenerate = true;
                                }
                            }
                        }

                        if (regenerate)
                        {
                            this.toRegenerate.Add(map);
                        }
                    }
                }
            }
            for (int i = 0; i < this.toRegenerate.Count; i++)
            {
                this.toRegenerate[i].Regenerate();
            }
            this.toRegenerate.Clear();
        }