Ejemplo n.º 1
0
        private void PropagateExplosions(List <int> templateIds, List <Explosion> propagateList, List <Placement> propagateListPlacement)
        {
            for (int explosionIndex = 0; explosionIndex < propagateList.Count; explosionIndex++)
            {
                Explosion explosion       = propagateList[explosionIndex];
                Placement placement       = propagateListPlacement[explosionIndex];
                Vector3   currentPosition = placement.Position;

                // Consider all directions
                for (int considerIndex = 0; considerIndex < propagationOffsets.Length; considerIndex++)
                {
                    PropagationDirection consideredDirection = (PropagationDirection)(0x1 << considerIndex);
                    if ((explosion.State.PropagationDirection & consideredDirection) == consideredDirection)
                    {
                        Point   offset      = propagationOffsets[considerIndex];
                        Vector3 newPosition = new Vector3(currentPosition.X + offset.X, currentPosition.Y + offset.Y, 0f);

                        // We need to check that there aren't any hard barriers here. Explosions shouldn't go there (unless we have hard pass-through)
                        ExplosionBarrier barrier      = GetBarrierAtLocation(newPosition.ToInteger());
                        bool             shouldGoHere = (barrier != ExplosionBarrier.Hard) || explosion.State.IsHardPassThrough;
                        if (shouldGoHere)
                        {
                            // When creating the new wexplosion, use the same template as the previous.
                            Entity    newEntity    = EntityManager.AllocateForGeneratedContent(EntityTemplateManager.GetTemplateById(templateIds[explosionIndex]), Universe.TopLevelGroupUniqueIdBase);
                            Explosion newExplosion = (Explosion)EntityManager.GetComponent(newEntity, ComponentTypeIds.Explosion);
                            newExplosion.State = explosion.State;
                            newExplosion.State.Range--; // Reduce the range of course...
                            // If we explode into a soft block, we don't propagate (unless we're passthrough)
                            if (!ShouldExplosionPropagateThroughBarrier(barrier, explosion))
                            {
                                newExplosion.State.Range = 0;
                            }
                            newExplosion.State.PropagationDirection = inheritedPropagationDirections[considerIndex];

                            // Assign its position
                            Placement newPlacement = (Placement)EntityManager.GetComponent(newEntity, ComponentTypeIds.Placement);
                            newPlacement.Position         = newPosition;
                            newPlacement.OrientationAngle = (float)(random.NextDouble() * 360.0);
                        }
                    }
                }
                explosion.State.PropagationDirection = PropagationDirection.None; // Mark this explosion so it doesn't propagate anymore!
            }
        }
Ejemplo n.º 2
0
        // Returns the strongest barrier at that location
        private ExplosionBarrier GetBarrierAtLocation(Point point)
        {
            ExplosionBarrier strongestBarrier = ExplosionBarrier.None;

            entityGrid.QueryUniqueIdsAt(point.X, point.Y, barrierQueryList);
            foreach (int uniqueId in barrierQueryList)
            {
                Entity there = EntityManager.TryGetEntityByUniqueId(uniqueId);
                if (there != null)
                {
                    ExplosionImpact explosionImpact = (ExplosionImpact)EntityManager.GetComponent(there, ComponentTypeIds.ExplosionImpact);
                    if (explosionImpact != null)
                    {
                        strongestBarrier = (ExplosionBarrier)Math.Max((int)explosionImpact.Barrier, (int)strongestBarrier);
                    }
                }
            }
            return(strongestBarrier);
        }
Ejemplo n.º 3
0
        private bool ShouldExplosionPropagateThroughBarrier(ExplosionBarrier barrier, Explosion explosion)
        {
            bool propagate = false;

            if (barrier == ExplosionBarrier.None)
            {
                propagate = true;
            }
            else
            {
                if ((barrier == ExplosionBarrier.Soft) && (explosion.State.IsPassThrough || explosion.State.IsHardPassThrough))
                {
                    propagate = true;
                }
                if ((barrier == ExplosionBarrier.Hard) && explosion.State.IsHardPassThrough)
                {
                    propagate = true;
                }
            }
            return(propagate);
        }