public static void AssignConnections(IHabitatModule alpha, IHabitatModule beta)
    {
        bool alphaHasHab = alpha.LinkedHabitat != null;
        bool betaHasHab  = beta.LinkedHabitat != null;

        if (!alphaHasHab && betaHasHab)
        {
            alpha.SetHabitat(beta.LinkedHabitat);
        }
        else if (alphaHasHab && !betaHasHab)
        {
            beta.SetHabitat(alpha.LinkedHabitat);
        }

        if (alpha.AdjacentModules == null)
        {
            alpha.AdjacentModules = new List <IHabitatModule>();
        }

        if (beta.AdjacentModules == null)
        {
            beta.AdjacentModules = new List <IHabitatModule>();
        }

        alpha.AdjacentModules.Add(beta);
        beta.AdjacentModules.Add(alpha);
    }
    public static int GetBulkheadIndex(this IHabitatModule self, Transform t)
    {
        if (self.Bulkheads == null)
        {
            UnityEngine.Debug.LogWarning("Looking for bulkhead when no bulkheads array is extant!");
            return(-1);
        }

        for (int i = 0; i < self.Bulkheads.Length; i++)
        {
            if (self.Bulkheads[i] == t)
            {
                return(i);
            }
        }
        return(-1);
    }
    public static void SetHabitat(this IHabitatModule self, Habitat habitat)
    {
        self.LinkedHabitat = habitat;

        if (self is Converter)
        {
            (self as Converter).OnSinkConnected(habitat);
        }

        if (self.AdjacentModules != null)
        {
            foreach (IHabitatModule sibling in self.AdjacentModules)
            {
                if (sibling.LinkedHabitat == null)
                {
                    sibling.SetHabitat(habitat);
                }
            }
        }
    }
Esempio n. 4
0
    protected override void OnAssign(IPowerable from, IPowerable to, Transform fromT, Transform toT)
    {
        this.Data.Type = PowerlineType.Corridor;

        IHabitatModule fromH = from as IHabitatModule;
        IHabitatModule toH   = to as IHabitatModule;

        if (fromH != null && toH != null)
        {
            HabitatModuleExtensions.AssignConnections(fromH, toH);

            if (this.FlexData == null) //new corridor
            {
                if (fromT == null || toT == null)
                {
                    UnityEngine.Debug.LogWarning("Assigning corridor connections does not have flex data or transforms!");
                }
                else
                {
                    this.FlexData = new CorridorFlexData()
                    {
                        FromBulkheadIndex = fromH.GetBulkheadIndex(fromT),
                        ToBulkheadIndex   = toH.GetBulkheadIndex(toT)
                    };

                    Ends[0] = fromT;
                    Ends[1] = toT;
                }
            }
            else //loading corridor from file
            {
                Ends[0] = fromH.Bulkheads[this.FlexData.FromBulkheadIndex];
                Ends[1] = toH.Bulkheads[this.FlexData.ToBulkheadIndex];
            }
        }
    }
    public static void RemoveConnection(IHabitatModule alpha, IHabitatModule beta)
    {
#warning does not reset linked habitat state
        alpha.AdjacentModules.Remove(beta);
        beta.AdjacentModules.Remove(alpha);
    }