public static void CleanConnectedDevicesFromPower(ElectricalOIinheritance Thiswire)
 {
     //Logger.Log ("CleanConnectedDevicesFromPower" + Thiswire, Category.Electrical);
     foreach (var IsConnectedTo in Thiswire.connectedDevices)
     {
         SupplyBool supplyBool = null;
         foreach (var KeysValleys in IsConnectedTo.Data.ResistanceToConnectedDevices)
         {
             if (KeysValleys.Key.Data == Thiswire)
             {
                 supplyBool = KeysValleys.Key;
                 break;
             }
         }
         if (supplyBool != null)
         {
             IsConnectedTo.Data.ResistanceToConnectedDevices.Remove(supplyBool);
             supplyBool.Pool();
         }
     }
     Thiswire.connectedDevices.Clear();
 }
Exemplo n.º 2
0
        public static void DirectionInput(ElectricalOIinheritance SourceInstance,
                                          IntrinsicElectronicData ComingFrom,
                                          IntrinsicElectronicData Thiswire)
        {
            if (Thiswire.Data.connections.Count == 0)
            {
                Thiswire.FindPossibleConnections();                 //plz don't remove it is necessary for preventing incomplete cleanups when there has been multiple
            }

            if (!Thiswire.Data.SupplyDependent.TryGetValue(SourceInstance, out ElectronicSupplyData supplyDep))
            {
                supplyDep = Thiswire.Data.SupplyDependent[SourceInstance] = ElectricalPool.GetElectronicSupplyData();
            }

            if (ComingFrom != null)
            {
                supplyDep.Upstream.Add(ComingFrom);
            }

            if (Thiswire.ConnectionReaction.TryGetValue(ComingFrom.Categorytype, out PowerInputReactions reaction))
            {
                if (reaction.DirectionReaction || reaction.ResistanceReaction)
                {
                    if (SourceInstance != null)
                    {
                        SupplyBool SupplyBool = null;
                        foreach (var keysvasl in Thiswire.Data.ResistanceToConnectedDevices)
                        {
                            if (keysvasl.Key.Equals(SourceInstance))
                            {
                                SupplyBool = keysvasl.Key;
                            }
                        }

                        if (SupplyBool == null)
                        {
                            SupplyBool                = ElectricalPool.GetSupplyBool();
                            SupplyBool.Data           = SourceInstance;
                            SupplyBool.RequiresUpdate = true;
                            Thiswire.Data.ResistanceToConnectedDevices[SupplyBool] =
                                new Dictionary <Resistance, HashSet <IntrinsicElectronicData> >();
                        }

                        var resToConDev = Thiswire.Data.ResistanceToConnectedDevices[SupplyBool];

                        if (!resToConDev.TryGetValue(reaction.ResistanceReactionA.Resistance,
                                                     out HashSet <IntrinsicElectronicData> resToConDevHash))
                        {
                            resToConDevHash = resToConDev[reaction.ResistanceReactionA.Resistance] =
                                new HashSet <IntrinsicElectronicData>();
                        }

                        resToConDevHash.Add(ComingFrom);
                        SupplyBool.RequiresUpdate = true;
                        SourceInstance.connectedDevices.Add(Thiswire);
                        ElectricalManager.Instance.electricalSync.InitialiseResistanceChange
                        .Add(Thiswire.ControllingDevice);
                    }

                    if (reaction.DirectionReactionA.YouShallNotPass)
                    {
                        return;
                    }
                }
            }

            if (Thiswire.Data.connections.Count > 2)
            {
                ElectricalManager.Instance.electricalSync.DirectionWorkOnNextListWaitADD(Thiswire);
            }
            else
            {
                ElectricalManager.Instance.electricalSync.DirectionWorkOnNextListADD(Thiswire);
            }
        }