Example #1
0
        public static void ElectricityInput(VIRCurrent current,
                                            ElectricalOIinheritance sourceInstance,
                                            IntrinsicElectronicData comingFrom,
                                            IntrinsicElectronicData thiswire)
        {
            if (thiswire.Data.SupplyDependent.TryGetValue(sourceInstance, out ElectronicSupplyData supplyDep))
            {
                if (supplyDep.CurrentComingFrom.TryGetValue(comingFrom, out VIRCurrent currentComFrom))
                {
                    currentComFrom.addCurrent(current);
                }
                else
                {
                    supplyDep.CurrentComingFrom[comingFrom] = current;
                }

                if (!(supplyDep.ResistanceComingFrom.Count > 0))
                {
                    var sync = ElectricalManager.Instance.electricalSync;
                    sync.StructureChange = true;
                    sync.NUStructureChangeReact.Add(thiswire.ControllingDevice);
                    sync.NUResistanceChange.Add(thiswire.ControllingDevice);
                    sync.NUCurrentChange.Add(thiswire.ControllingDevice);
                    Logger.LogErrorFormat("Resistance isn't initialised on", Category.Electrical);
                    return;
                }

                supplyDep.SourceVoltage = (float)current.Current() * ElectricityFunctions.WorkOutResistance(supplyDep.ResistanceComingFrom);
            }

            //ELCurrent.CurrentWorkOnNextListADD(Thiswire);
            thiswire.ElectricityOutput(current, sourceInstance);
        }
            public static void FlushConnectionAndUp(IntrinsicElectronicData Object)
            {
                Object.Data.CurrentInWire = 0;
                Object.Data.ActualVoltage = 0;
                foreach (var IsConnectedTo in Object.Data.ResistanceToConnectedDevices)
                {
                    IsConnectedTo.Key.Pool();
                }
                Object.Data.ResistanceToConnectedDevices.Clear();
                //Object.connectedDevices.Clear();//#
                if (Object.Data.connections.Count > 0)
                {
                    List <IntrinsicElectronicData> Backupconnections = new List <IntrinsicElectronicData>(Object.Data.connections);                   //GC
                    Object.Data.connections.Clear();

                    foreach (IntrinsicElectronicData JumpTo in Backupconnections)
                    {
                        JumpTo.FlushConnectionAndUp();
                    }
                }
                foreach (KeyValuePair <ElectricalOIinheritance, ElectronicSupplyData> Supply in Object.Data.SupplyDependent)
                {
                    Pool(Supply.Value.CurrentGoingTo);
                    Pool(Supply.Value.CurrentComingFrom);
                    Pool(Supply.Value.ResistanceGoingTo);
                    Pool(Supply.Value.ResistanceComingFrom);
                    Supply.Value.Upstream.Clear();
                    Supply.Value.Downstream.Clear();
                    Supply.Value.SourceVoltage = 0;
                }
            }
Example #3
0
        public static void ElectricityOutput(VIRCurrent Current,
                                             ElectricalOIinheritance SourceInstance,
                                             IntrinsicElectronicData Thiswire)
        {
            //Logger.Log("4 > " + Current);
            //Logger.Log("poke > " + SourceInstance.InData.Data.SupplyDependent[SourceInstance].ToString());
            var        OutputSupplyingUsingData = Thiswire.Data.SupplyDependent[SourceInstance];
            VIRCurrent SupplyingCurrent         = null;
            float      Divider = (ElectricityFunctions.WorkOutResistance(OutputSupplyingUsingData.ResistanceComingFrom));

            foreach (KeyValuePair <IntrinsicElectronicData, VIRResistances> JumpTo in OutputSupplyingUsingData
                     .ResistanceComingFrom)
            {
                if (OutputSupplyingUsingData.ResistanceComingFrom.Count > 1)
                {
                    SupplyingCurrent = Current.SplitCurrent(Divider / JumpTo.Value.Resistance());
                }
                else
                {
                    SupplyingCurrent = Current;
                }

                OutputSupplyingUsingData.CurrentGoingTo[JumpTo.Key] = SupplyingCurrent;
                if (JumpTo.Key != null && JumpTo.Key.Categorytype != PowerTypeCategory.DeadEndConnection)
                {
                    JumpTo.Key.ElectricityInput(SupplyingCurrent, SourceInstance, Thiswire);
                }
            }
        }
Example #4
0
 ///// <summary>
 /////  Sets the upstream
 ///// </summary>
 public virtual void DirectionInput(ElectricalOIinheritance SourceInstance, IntrinsicElectronicData ComingFrom, CableLine PassOn = null)
 {
     if (Logall)
     {
         Logger.Log("this > " + this + "DirectionInput SourceInstance > " + SourceInstance + " ComingFrom > " + ComingFrom + "  PassOn > " + PassOn, Category.Electrical);
     }
     InputOutputFunctions.DirectionInput(SourceInstance, ComingFrom, InData);
 }
        public static void WorkOutActualNumbers(IntrinsicElectronicData ElectricItem)
        {
            //Sometimes gives wrong readings at junctions, Needs to be looked into
            float Current = 0;             //Calculates the actual voltage and current flowing through the Node
            float Voltage = 0;

            foreach (var Supply in ElectricItem.Data.SupplyDependent)
            {
                Voltage += Supply.Value.SourceVoltage;
            }

            lock (AnInterestingDictionary)
            {
                AnInterestingDictionary.Clear();                 //Voltages easy to work out just add up all the voltages from different sources
                foreach (var CurrentIDItem in ElectricItem.Data.SupplyDependent)
                {
                    foreach (var CurrentItem in CurrentIDItem.Value.CurrentComingFrom)
                    {
                        if (AnInterestingDictionary.ContainsKey(CurrentItem.Key))
                        {
                            AnInterestingDictionary[CurrentItem.Key] += (float)CurrentItem.Value.Current();
                        }
                        else
                        {
                            AnInterestingDictionary[CurrentItem.Key] = (float)CurrentItem.Value.Current();
                        }
                    }

                    foreach (var CurrentItem in CurrentIDItem.Value.CurrentGoingTo)
                    {
                        if (AnInterestingDictionary.ContainsKey(CurrentItem.Key))
                        {
                            AnInterestingDictionary[CurrentItem.Key] += (float)-CurrentItem.Value.Current();
                        }
                        else
                        {
                            AnInterestingDictionary[CurrentItem.Key] = (float)-CurrentItem.Value.Current();
                        }
                    }
                }

                foreach (var CurrentItem in AnInterestingDictionary)
                {
                    if (CurrentItem.Value > 0)
                    {
                        Current += CurrentItem.Value;
                    }
                }
            }

            //Logger.Log (Voltage.ToString () + " < yeah Those voltage " + Current.ToString() + " < yeah Those Current " + (Voltage/Current).ToString() + " < yeah Those Resistance" + ElectricItem.GameObject().name.ToString() + " < at", Category.Electrical);

            ElectricItem.Data.CurrentInWire       = Current;
            ElectricItem.Data.ActualVoltage       = Voltage;
            ElectricItem.Data.EstimatedResistance = (Voltage / Current);
        }
Example #6
0
 public void SetUp(IntrinsicElectronicData indata)
 {
     Categorytype       = indata.Categorytype;
     ConnectionReaction = indata.ConnectionReaction;
     Present            = indata.Present;
     MetaDataPresent    = indata.MetaDataPresent;
     CanConnectTo       = indata.CanConnectTo;
     WireEndB           = indata.WireEndB;
     WireEndA           = indata.WireEndA;
 }
Example #7
0
 public void Initialise(WireConnect DataToTake, MetaDataNode metaDataNode, Vector3Int searchVec, Matrix locatedon)
 {
     IsOn   = metaDataNode;
     InData = new IntrinsicElectronicData();
     InData.SetUp(DataToTake.InData);
     NodeLocation           = searchVec;
     Locatedon              = locatedon;
     InData.MetaDataPresent = this;
     InData.Present         = null;
 }
Example #8
0
 public override void ResistanceInput(ResistanceWrap Resistance,
                                      ElectricalOIinheritance SourceInstance,
                                      IntrinsicElectronicData ComingFrom)
 {
     Resistance = InData.ControllingDevice.ModifyResistanceInput(Resistance, SourceInstance, ComingFrom);
     if (Logall)
     {
         Logger.Log("this > " + this + "ResistanceInput, Resistance > " + Resistance + " SourceInstance  > " + SourceInstance + " ComingFrom > " + ComingFrom, Category.Electrical);
     }
     InputOutputFunctions.ResistanceInput(Resistance, SourceInstance, ComingFrom, InData);
 }
        public static void FindPossibleConnections(Matrix matrix,
                                                   HashSet <PowerTypeCategory> CanConnectTo,
                                                   ConnPoint ConnPoints,
                                                   IntrinsicElectronicData OIinheritance,
                                                   HashSet <IntrinsicElectronicData> InPutHashSet)
        {
            Vector2 searchVec = OIinheritance.GetLocation();

            SwitchCaseConnections(searchVec, matrix, CanConnectTo, ConnPoints.pointA, OIinheritance, InPutHashSet, ConnPoints.pointB);
            SwitchCaseConnections(searchVec, matrix, CanConnectTo, ConnPoints.pointB, OIinheritance, InPutHashSet, ConnPoints.pointA);
        }
Example #10
0
 public void DirectionWorkOnNextListWaitADD(IntrinsicElectronicData wire)
 {
     if (UesAlternativeDirectionWorkOnNextList)
     {
         _DirectionWorkOnNextListWait.Add(wire);
     }
     else
     {
         DirectionWorkOnNextListWait.Add(wire);
     }
 }
Example #11
0
 /// <summary>
 ///  Sets the upstream
 /// </summary>
 public virtual void DirectionInput(ElectricalOIinheritance SourceInstance, IntrinsicElectronicData ComingFrom, CableLine PassOn = null)
 {
     if (Present != null)
     {
         Present.DirectionInput(SourceInstance, ComingFrom);
     }
     else
     {
         InputOutputFunctions.DirectionInput(SourceInstance, ComingFrom, this);
     }
 }
Example #12
0
        public override void ElectricityInput(VIRCurrent Current,
                                              ElectricalOIinheritance SourceInstance,
                                              IntrinsicElectronicData ComingFrom)
        {
            Current = InData.ControllingDevice.ModifyElectricityInput(Current, SourceInstance, ComingFrom);

            if (Logall)
            {
                Logger.Log("this > " + this + "ElectricityInput, Current > " + Current + " SourceInstance  > " + SourceInstance + " ComingFrom > " + ComingFrom, Category.Electrical);
            }
            InputOutputFunctions.ElectricityInput(Current, SourceInstance, ComingFrom, InData);
        }
Example #13
0
 public void Initialise(ElectricalCableTile DataToTake, MetaDataNode metaDataNode, Vector3Int searchVec, Matrix locatedon)
 {
     RelatedTile = DataToTake;
     IsOn        = metaDataNode;
     InData      = new IntrinsicElectronicData();
     InData.SetUp(DataToTake);
     InData.MetaDataPresent = this;
     NodeLocation           = searchVec;
     Locatedon = locatedon;
     InData.MetaDataPresent = this;
     InData.Present         = null;
 }
Example #14
0
 /// <summary>
 /// Pass resistance with GameObject of the Machine it is heading toward
 /// </summary>
 public virtual void ResistanceInput(ResistanceWrap Resistance,
                                     ElectricalOIinheritance SourceInstance,
                                     IntrinsicElectronicData ComingFrom)
 {
     if (Logall)
     {
         Logger.Log("this > " + this
                    + "ResistanceInput, Resistance > " + Resistance
                    + " SourceInstance  > " + SourceInstance
                    + " ComingFrom > " + ComingFrom, Category.Electrical);
     }
     InputOutputFunctions.ResistanceInput(Resistance, SourceInstance, ComingFrom, InData);
 }
Example #15
0
 /// <summary>
 /// Inputs a current from a device, with the supply
 /// </summary>
 public virtual void ElectricityInput(VIRCurrent Current,
                                      ElectricalOIinheritance SourceInstance,
                                      IntrinsicElectronicData ComingFrom)
 {
     if (Logall)
     {
         Logger.Log("this > " + this
                    + "ElectricityInput, Current > " + Current
                    + " SourceInstance  > " + SourceInstance
                    + " ComingFrom > " + ComingFrom, Category.Electrical);
     }
     InputOutputFunctions.ElectricityInput(Current, SourceInstance, ComingFrom, InData);
 }
Example #16
0
 /// <summary>
 /// Pass resistance with GameObject of the Machine it is heading toward
 /// </summary>
 public virtual void ResistanceInput(ResistanceWrap Resistance,
                                     ElectricalOIinheritance SourceInstance,
                                     IntrinsicElectronicData ComingFrom)
 {
     if (Present != null)
     {
         Present.ResistanceInput(Resistance, SourceInstance, ComingFrom);
     }
     else
     {
         InputOutputFunctions.ResistanceInput(Resistance, SourceInstance, ComingFrom, this);
     }
 }
Example #17
0
 /// <summary>
 /// Inputs a current from a device, with the supply
 /// </summary>
 public virtual void ElectricityInput(VIRCurrent Current,
                                      ElectricalOIinheritance SourceInstance,
                                      IntrinsicElectronicData ComingFrom)
 {
     if (Present != null)
     {
         Present.ElectricityInput(Current, SourceInstance, ComingFrom);
     }
     else
     {
         InputOutputFunctions.ElectricityInput(Current, SourceInstance, ComingFrom, this);
     }
 }
Example #18
0
        private int NumberOfReactiveSupplies(IntrinsicElectronicData devices)
        {
            var counting = 0;

            foreach (var device in devices.Data.ResistanceToConnectedDevices)
            {
                if (ReactiveSuppliesSet.Contains(device.Key.Data.InData.Categorytype))
                {
                    counting++;
                }
            }

            return(counting);
        }
 public static void FlushResistanceAndUp(IntrinsicElectronicData Object, ElectricalOIinheritance SourceInstance = null)
 {
     if (SourceInstance == null)
     {
         bool pass = false;
         foreach (var Supply in Object.Data.SupplyDependent)
         {
             if (Supply.Value.ResistanceComingFrom.Count > 0)
             {
                 pass = true;
                 break;
             }
         }
         if (pass)
         {
             foreach (var Supply in Object.Data.SupplyDependent)
             {
                 Pool(Supply.Value.ResistanceComingFrom);
                 Pool(Supply.Value.ResistanceGoingTo);
                 Pool(Supply.Value.CurrentGoingTo);
                 Pool(Supply.Value.CurrentComingFrom);
                 Supply.Value.SourceVoltage = 0;
             }
             foreach (IntrinsicElectronicData JumpTo in Object.Data.connections)
             {
                 JumpTo.FlushResistanceAndUp();
             }
             Object.Data.CurrentInWire = 0;
             Object.Data.ActualVoltage = 0;
         }
     }
     else
     {
         ElectronicSupplyData supplyDep = Object.Data.SupplyDependent[SourceInstance];
         if (supplyDep.ResistanceComingFrom.Count > 0 || supplyDep.ResistanceGoingTo.Count > 0)
         {
             Pool(supplyDep.ResistanceComingFrom);
             Pool(supplyDep.ResistanceGoingTo);
             foreach (IntrinsicElectronicData JumpTo in Object.Data.connections)
             {
                 JumpTo.FlushResistanceAndUp(SourceInstance);
             }
             Pool(supplyDep.CurrentGoingTo);
             Pool(supplyDep.CurrentComingFrom);
             supplyDep.SourceVoltage   = 0;
             Object.Data.CurrentInWire = new float();
             Object.Data.ActualVoltage = new float();
         }
     }
 }
Example #20
0
        public static void ResistanceInput(ResistanceWrap Resistance,
                                           ElectricalOIinheritance SourceInstance,
                                           IntrinsicElectronicData ComingFrom,
                                           IntrinsicElectronicData Thiswire)
        {
            if (Thiswire.Data.SupplyDependent.TryGetValue(SourceInstance, out ElectronicSupplyData supplyDep))
            {
                if (!supplyDep.ResistanceComingFrom.TryGetValue(ComingFrom, out VIRResistances resComeFrom))
                {
                    resComeFrom = supplyDep.ResistanceComingFrom[ComingFrom] = ElectricalPool.GetVIRResistances();
                }

                resComeFrom.AddResistance(Resistance);
            }

            Thiswire.ResistancyOutput(Resistance, SourceInstance);
        }
Example #21
0
        public static void ResistancyOutput(ResistanceWrap Resistance,
                                            ElectricalOIinheritance SourceInstance,
                                            IntrinsicElectronicData Thiswire)
        {
            if (Thiswire.Data.SupplyDependent.TryGetValue(SourceInstance, out ElectronicSupplyData supplyDep))
            {
                foreach (var JumpTo in supplyDep.Upstream)
                {
                    if (!supplyDep.ResistanceGoingTo.TryGetValue(JumpTo, out VIRResistances resGoTo))
                    {
                        resGoTo = supplyDep.ResistanceGoingTo[JumpTo] = ElectricalPool.GetVIRResistances();
                    }

                    resGoTo.AddResistance(Resistance);
                    JumpTo.ResistanceInput(Resistance, SourceInstance, Thiswire);
                }
            }
        }
Example #22
0
        public static void DirectionOutput(ElectricalOIinheritance SourceInstance,
                                           IntrinsicElectronicData Thiswire,
                                           CableLine RelatedLine = null)
        {
            if (Thiswire.Data.connections.Count == 0)
            {
                Thiswire.FindPossibleConnections();
            }

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

            foreach (IntrinsicElectronicData Relatedindata in Thiswire.Data.connections)
            {
                if (!(outputSupplyingUsingData.Upstream.Contains(Relatedindata)) && (Thiswire != Relatedindata))
                {
                    bool pass = true;
                    if (RelatedLine != null)
                    {
                        if (RelatedLine.Covering.Contains(Relatedindata))
                        {
                            pass = false;
                        }
                    }

                    if (outputSupplyingUsingData.Downstream.Contains(Relatedindata) == false && pass && Relatedindata.Present != SourceInstance)
                    {
                        outputSupplyingUsingData.Downstream.Add(Relatedindata);
                        Relatedindata.DirectionInput(SourceInstance, Thiswire);
                    }
                }
            }
        }
            public static void RemoveSupply(IntrinsicElectronicData Object, ElectricalOIinheritance SourceInstance = null)
            {
                if (SourceInstance == null)
                {
                    bool pass = false;
                    foreach (var Supply in Object.Data.SupplyDependent)
                    {
                        if (Supply.Value.Downstream.Count > 0 || Supply.Value.Upstream.Count > 0)
                        {
                            pass = true;
                            break;
                        }
                    }
                    if (pass)
                    {
                        Pool(Object.Data.SupplyDependent);
                        foreach (IntrinsicElectronicData JumpTo in Object.Data.connections)
                        {
                            JumpTo.RemoveSupply();
                        }
                        Object.Data.CurrentInWire       = 0;
                        Object.Data.ActualVoltage       = 0;
                        Object.Data.EstimatedResistance = 0;
                        foreach (var IsConnectedTo in Object.Data.ResistanceToConnectedDevices)
                        {
                            IsConnectedTo.Key.Pool();
                        }
                        Object.Data.ResistanceToConnectedDevices.Clear();
                        //Object.connectedDevices.Clear();#
                    }
                }
                else
                {
                    bool pass = false;
                    if (Object.Data.SupplyDependent.TryGetValue(SourceInstance, out ElectronicSupplyData supplyDep))
                    {
                        if (supplyDep.Downstream.Count > 0 || supplyDep.Upstream.Count > 0)
                        {
                            pass = true;
                        }
                        supplyDep.Pool();
                        Object.Data.SupplyDependent.Remove(SourceInstance);
                    }

                    if (SourceInstance == Object.Present)
                    {
                        CleanConnectedDevicesFromPower(Object.Present);
                        foreach (var IsConnectedTo in Object.Data.ResistanceToConnectedDevices)
                        {
                            IsConnectedTo.Key.Pool();
                        }
                        Object.Data.ResistanceToConnectedDevices.Clear();
                    }

                    if (pass)
                    {
                        foreach (IntrinsicElectronicData JumpTo in Object.Data.connections)
                        {
                            JumpTo.RemoveSupply(SourceInstance);
                        }
                    }
                }
            }
        public static void SwitchCaseConnections(Vector2 searchVec,
                                                 Matrix matrix,
                                                 HashSet <PowerTypeCategory> CanConnectTo,
                                                 Connection connectionPoint,
                                                 IntrinsicElectronicData OIinheritance,
                                                 HashSet <IntrinsicElectronicData> connections,
                                                 // used in SurroundingTiles connection
                                                 Connection otherConnectionPoint = Connection.NA)
        {
            var searchVecInt = new Vector3Int((int)searchVec.x, (int)searchVec.y, 0);

            {
                // LogError Duplicate wires
                var eConnsAtSearchVec = matrix.GetElectricalConnections(searchVecInt);
                foreach (var con in eConnsAtSearchVec)
                {
                    if (OIinheritance != con)
                    {
                        if ((OIinheritance.WireEndA == con.WireEndA && OIinheritance.WireEndB == con.WireEndB) ||
                            (OIinheritance.WireEndA == con.WireEndB && OIinheritance.WireEndB == con.WireEndA))
                        {
                            Logger.LogError($"{searchVecInt} < duplicate Please remove {OIinheritance.Categorytype}",
                                            Category.Electrical);
                        }
                    }
                }

                eConnsAtSearchVec.Clear();
                ElectricalPool.PooledFPCList.Add(eConnsAtSearchVec);
            }

            if (connectionPoint == Connection.SurroundingTiles)
            {
                foreach (var dir in NeighbourDirections)
                {
                    // check all nearby connections except connection that is specified in other wire end
                    if (dir.Key == otherConnectionPoint)
                    {
                        continue;
                    }

                    var pos   = searchVecInt + dir.Value;
                    var conns = matrix.GetElectricalConnections(pos);

                    // get connections pointing towards our tile [ex. if neighbour is at north, get all south connections(SW, S, SE)]
                    HashSet <Connection> possibleConnections = ConnectionMap.GetConnectionsTargeting(dir.Key);
                    if (possibleConnections != null)
                    {
                        foreach (var con in conns)
                        {
                            if (OIinheritance != con &&
                                CanConnectTo.Contains(con.Categorytype)
                                // check if possibleConnections contains our WireEnd A or B
                                && (possibleConnections.Contains(con.WireEndA) ||
                                    possibleConnections.Contains(con.WireEndB))
                                // check if contains to avoid errors
                                && !connections.Contains(con))
                            {
                                connections.Add(con);
                            }
                        }
                    }

                    conns.Clear();
                    ElectricalPool.PooledFPCList.Add(conns);
                }

                return;
            }

            // Connect to machine connnectors
            if (connectionPoint == Connection.MachineConnect)
            {
                foreach (var dir in MachineConnectorDirections)
                {
                    var pos   = searchVecInt + dir;
                    var conns = matrix.GetElectricalConnections(pos);
                    foreach (var con in conns)
                    {
                        if (OIinheritance != con && CanConnectTo.Contains(con.Categorytype) &&
                            ConnectionMap.IsConnectedToTile(Connection.MachineConnect, con.GetConnPoints()) &&
                            !connections.Contains(con))
                        {
                            connections.Add(con);
                        }
                    }

                    conns.Clear();
                    ElectricalPool.PooledFPCList.Add(conns);
                }

                return;
            }

            // Make a vector representing the connection direction
            Vector3Int connVectorInt = ConnectionMap.GetDirectionFromConnection(connectionPoint);
            Vector3Int position      = searchVecInt + connVectorInt;

            // Connect wires
            {
                var  eConnsAtPosition = matrix.GetElectricalConnections(position);
                bool connectionsAdded = false;
                foreach (var con in eConnsAtPosition)
                {
                    if (CanConnectTo.Contains(con.Categorytype) &&
                        ConnectionMap.IsConnectedToTile(connectionPoint, con.GetConnPoints()))
                    {
                        connections.Add(con);
                        connectionsAdded = true;
                    }
                }

                eConnsAtPosition.Clear();
                ElectricalPool.PooledFPCList.Add(eConnsAtPosition);

                if (connectionsAdded)
                {
                    return;
                }
            }

            // Connect to overlap
            {
                var eConnsAtSearchVec = matrix.GetElectricalConnections(searchVecInt);
                foreach (var con in eConnsAtSearchVec)
                {
                    if (OIinheritance != con && CanConnectTo.Contains(con.Categorytype) &&
                        ConnectionMap.IsConnectedToTileOverlap(connectionPoint, con.GetConnPoints()))
                    {
                        connections.Add(con);
                    }
                }

                eConnsAtSearchVec.Clear();
                ElectricalPool.PooledFPCList.Add(eConnsAtSearchVec);
            }
        }
Example #25
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);
            }
        }