Ejemplo n.º 1
0
        public static void AirNetsUpdate()
        {
            for (var layerInt = 0; layerInt < Common.NetLayerCount(); layerInt++)
            {
                if (!newComps[layerInt].Any() && !oldComps[layerInt].Any())
                {
                    continue;
                }

                //Deregister the whole net that should be merged (deregister adjacent AirNet)
                foreach (var current in newComps[layerInt])
                {
#if DEBUG
                    Log.Message("Cleaning.");
#endif
                    //Check for adjacent cells
                    foreach (var adjPos in GenAdj.CellsAdjacentCardinal(current.parent))
                    {
                        if (!adjPos.InBounds())
                        {
                            continue;
                        }

                        var oldNet = AirNetGrid.NetAt(adjPos, (NetLayer)layerInt);

                        if (oldNet != null)
                        {
                            DeregisterAirNet(oldNet);
                        }
                    }
                }

                //Deregister comps marked as old
                foreach (var current in oldComps[layerInt])
                {
#if DEBUG
                    Log.Message("Deleting.");
#endif
                    var oldNet = AirNetGrid.NetAt(current.parent.Position, (NetLayer)layerInt);

                    if (oldNet != null)
                    {
                        DeregisterAirNet(oldNet);
                    }
                }


                //Make a new, merged net
                foreach (var current in newComps[layerInt])
                {
#if DEBUG
                    Log.Message("Merging.");
#endif
                    if (AirNetGrid.NetAt(current.parent.Position, (NetLayer)layerInt) == null)
                    {
                        RegisterAirNet(AirNetMaker.NewAirNetStartingFrom((Building)current.parent,
                                                                         (NetLayer)layerInt));
                    }
                }

                //Split nets
                foreach (var current in oldComps[layerInt])
                {
#if DEBUG
                    Log.Message("Splitting.");
#endif
                    foreach (var adjPos in GenAdj.CellsAdjacentCardinal(current.parent))
                    {
                        if (!adjPos.InBounds())
                        {
                            continue;
                        }

                        var airNode = GetAirNodeAt(adjPos, (NetLayer)layerInt);
                        if (airNode != null)
                        {
                            RegisterAirNet(AirNetMaker.NewAirNetStartingFrom(airNode, (NetLayer)layerInt));
                        }
                    }
                }

                newComps[layerInt].Clear();
                oldComps[layerInt].Clear();
            }
        }