Exemplo 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!
            }
        }