public static void CircuitSearchLoop(IElectricityIO Thiswire, IProvidePower ProvidingPower) { InputOutputFunctions.DirectionOutput(ElectricalSynchronisation.currentTick, Thiswire.GameObject(), Thiswire); bool Break = true; List <IElectricityIO> IterateDirectionWorkOnNextList = new List <IElectricityIO> (); while (Break) { IterateDirectionWorkOnNextList = new List <IElectricityIO> (ProvidingPower.DirectionWorkOnNextList); ProvidingPower.DirectionWorkOnNextList.Clear(); for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++) { IterateDirectionWorkOnNextList [i].DirectionOutput(ElectricalSynchronisation.currentTick, Thiswire.GameObject()); } if (ProvidingPower.DirectionWorkOnNextList.Count <= 0) { IterateDirectionWorkOnNextList = new List <IElectricityIO> (ProvidingPower.DirectionWorkOnNextListWait); ProvidingPower.DirectionWorkOnNextListWait.Clear(); for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++) { IterateDirectionWorkOnNextList [i].DirectionOutput(ElectricalSynchronisation.currentTick, Thiswire.GameObject()); } } if (ProvidingPower.DirectionWorkOnNextList.Count <= 0 && ProvidingPower.DirectionWorkOnNextListWait.Count <= 0) { //Logger.Log ("stop!"); Break = false; } } }
public void DirectionInput(int tick, GameObject SourceInstance, IElectricityIO ComingFrom, IElectricityIO PassOn = null) { //Logger.Log(SourceInstance.ToString() + " < SourceInstance " + ComingFrom.ToString() + " < ComingFrom " + this.name + " < this " ); if (connections.Count > 2) { ElectricityFunctions.DirectionInput(tick, SourceInstance, ComingFrom, this); FirstPresentInspector = FirstPresent; } else { int SourceInstanceID = SourceInstance.GetInstanceID(); if (!(Upstream.ContainsKey(SourceInstanceID))) { Upstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (!(Downstream.ContainsKey(SourceInstanceID))) { Downstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (FirstPresent == 0) { //Logger.Log ("to It's been claimed", Category.Electrical); FirstPresent = SourceInstanceID; //Thiswire.FirstPresentInspector = SourceInstanceID; } if (ComingFrom != null) { Upstream [SourceInstanceID].Add(ComingFrom); } CameFromMemory = PassOn; SourceInstance.GetComponent <IProvidePower> ().DirectionWorkOnNextList.Add(this); } }
public static void ElectricityOutput(float Current, GameObject SourceInstance, IElectricityIO Thiswire) { int SourceInstanceID = SourceInstance.GetInstanceID(); float SimplyTimesBy = 0; float SupplyingCurrent = 0; Dictionary <IElectricityIO, float> ThiswireResistance = new Dictionary <IElectricityIO, float>(); if (Thiswire.Data.ResistanceComingFrom.ContainsKey(SourceInstanceID)) { ThiswireResistance = Thiswire.Data.ResistanceComingFrom[SourceInstanceID]; } else { Logger.LogError("now It doesn't" + SourceInstanceID.ToString() + " with this " + Thiswire.GameObject().name.ToString(), Category.Electrical); } float Voltage = Current * (ElectricityFunctions.WorkOutResistance(ThiswireResistance)); foreach (KeyValuePair <IElectricityIO, float> JumpTo in Thiswire.Data.ResistanceComingFrom[SourceInstanceID]) { if (Voltage > 0) { SupplyingCurrent = (Voltage / JumpTo.Value); } else { SupplyingCurrent = Current; } if (!(Thiswire.Data.CurrentGoingTo.ContainsKey(SourceInstanceID))) { Thiswire.Data.CurrentGoingTo[SourceInstanceID] = new Dictionary <IElectricityIO, float>(); } Thiswire.Data.CurrentGoingTo[SourceInstanceID][JumpTo.Key] = SupplyingCurrent; JumpTo.Key.ElectricityInput(SupplyingCurrent, SourceInstance, Thiswire); } }
public static bool CalculateDirectionBool(IElectricityIO From, IElectricityIO To, bool Upstream) { bool isTrue = false; int UesID = From.Data.FirstPresent; if (Upstream) { if (From.Data.Upstream [UesID].Contains(To)) { isTrue = true; return(isTrue); } else { return(isTrue); } } else { if (From.Data.Downstream[UesID].Contains(To)) { isTrue = true; return(isTrue); } else { return(isTrue); } } }
public static void DirectionOutput(int tick, GameObject SourceInstance, IElectricityIO Thiswire) { int SourceInstanceID = SourceInstance.GetInstanceID(); if (!(Thiswire.Data.Upstream.ContainsKey(SourceInstanceID))) { Thiswire.Data.Upstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (!(Thiswire.Data.Downstream.ContainsKey(SourceInstanceID))) { Thiswire.Data.Downstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (Thiswire.Data.connections.Count <= 0) { Thiswire.FindPossibleConnections(); } for (int i = 0; i < Thiswire.Data.connections.Count; i++) { if (!(Thiswire.Data.Upstream [SourceInstanceID].Contains(Thiswire.Data.connections [i])) && (!(Thiswire == Thiswire.Data.connections [i]))) { if (!(Thiswire.Data.Downstream.ContainsKey(SourceInstanceID))) { Thiswire.Data.Downstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (!(Thiswire.Data.Downstream[SourceInstanceID].Contains(Thiswire.Data.connections [i]))) { Thiswire.Data.Downstream [SourceInstanceID].Add(Thiswire.Data.connections [i]); Thiswire.Data.connections [i].DirectionInput(tick, SourceInstance, Thiswire); } } } }
public void ElectricityInput(int tick, float Current, GameObject SourceInstance, IElectricityIO ComingFrom) { Current = RelatedDevice.ModifyElectricityInput(tick, Current, SourceInstance, ComingFrom); //Logger.Log(Current.ToString() + "yoree"); ElectricityFunctions.ElectricityInput(tick, Current, SourceInstance, ComingFrom, this); }
//CalculateDirectionFromID public static bool CalculateDirectionFromID(IElectricityIO On, int TheID) { bool isTrue = false; if (!(On.ResistanceComingFrom.ContainsKey(TheID))) { return(true); } if (!(On.ResistanceComingFrom.ContainsKey(On.FirstPresent))) { return(true); } isTrue = true; foreach (KeyValuePair <IElectricityIO, float> CurrentItem in On.ResistanceComingFrom[On.FirstPresent]) { if (!(On.ResistanceComingFrom [TheID].ContainsKey(CurrentItem.Key))) { isTrue = false; } } //if (On.ResistanceComingFrom [TheID] == On.ResistanceComingFrom [On.FirstPresent]) { //isTrue = true; //} return(isTrue); }
public float ModifyResistanceInput(float Resistance, GameObject SourceInstance, IElectricityIO ComingFrom) { Tuple <float, float> ResistanceM = TransformerCalculations.TransformerCalculate(this, ResistanceToModify: Resistance); //return(Resistance); return(ResistanceM.Item1); }
public static void TurnOnSupply(IElectricityIO Supply) { ElectricalSynchronisation.AddSupply(Supply.InData.ControllingUpdate, Supply.InData.Categorytype); ElectricalSynchronisation.NUStructureChangeReact.Add(Supply.InData.ControllingUpdate); ElectricalSynchronisation.NUResistanceChange.Add(Supply.InData.ControllingUpdate); ElectricalSynchronisation.NUCurrentChange.Add(Supply.InData.ControllingUpdate); }
public static void DirectionInput(int tick, GameObject SourceInstance, IElectricityIO ComingFrom, IElectricityIO Thiswire) { int SourceInstanceID = SourceInstance.GetInstanceID(); if (Thiswire.FirstPresent == 0) { //Logger.Log ("to It's been claimed", Category.Electrical); Thiswire.FirstPresent = SourceInstanceID; //Thiswire.FirstPresentInspector = SourceInstanceID; } if (!(Thiswire.Upstream.ContainsKey(SourceInstanceID))) { Thiswire.Upstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (!(Thiswire.Downstream.ContainsKey(SourceInstanceID))) { Thiswire.Downstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (ComingFrom != null) { Thiswire.Upstream [SourceInstanceID].Add(ComingFrom); } SourceInstance.GetComponent <IProvidePower> ().DirectionWorkOnNextList.Add(Thiswire); //Thiswire.DirectionOutput(tick, SourceInstance); }
public static Electricity WorkOutActualNumbers(IElectricityIO ElectricItem) //add Resistance to SMso they get properly worked out { float Current = 0; float Voltage = 0; Dictionary <IElectricityIO, float> AnInterestingDictionary = new Dictionary <IElectricityIO, float> (); foreach (KeyValuePair <int, float> CurrentIDItem in ElectricItem.SourceVoltages) { Voltage += CurrentIDItem.Value; //Logger.Log ("yeah no" + Voltage.ToString ()); } //Logger.Log("yeah no Number > " + ElectricItem.SourceVoltages.Count.ToString ()); foreach (KeyValuePair <int, Dictionary <IElectricityIO, float> > CurrentIDItem in ElectricItem.CurrentComingFrom) { foreach (KeyValuePair <IElectricityIO, float> CurrentItem in CurrentIDItem.Value) { if (AnInterestingDictionary.ContainsKey(CurrentItem.Key)) { AnInterestingDictionary [CurrentItem.Key] += CurrentItem.Value; } else { AnInterestingDictionary [CurrentItem.Key] = CurrentItem.Value; } } if (ElectricItem.CurrentGoingTo.ContainsKey(CurrentIDItem.Key)) { foreach (KeyValuePair <IElectricityIO, float> CurrentItem in ElectricItem.CurrentGoingTo[CurrentIDItem.Key]) { if (AnInterestingDictionary.ContainsKey(CurrentItem.Key)) { AnInterestingDictionary [CurrentItem.Key] += -CurrentItem.Value; } else { AnInterestingDictionary [CurrentItem.Key] = -CurrentItem.Value; } } } } // foreach (KeyValuePair<IElectricityIO,float> CurrentItem in AnInterestingDictionary) { // Logger.Log (CurrentItem.Key.ToString () + " <key yeah Value> " + CurrentItem.Value.ToString () + " THSo> " + ElectricItem.GameObject().name.ToString(), Category.Electrical ); // } foreach (KeyValuePair <IElectricityIO, float> CurrentItem in AnInterestingDictionary) //!! It's not working somewhere at 17 and 9? { 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); Electricity Cabledata = new Electricity(); Cabledata.Current = Current; Cabledata.Voltage = Voltage; Cabledata.EstimatedResistant = Voltage / Current; return(Cabledata); }
public static void CircuitResistanceLoop(IElectricityIO Thiswire, IProvidePower ProvidingPower) { bool Break = true; List <IElectricityIO> IterateDirectionWorkOnNextList = new List <IElectricityIO> (); while (Break) { IterateDirectionWorkOnNextList = new List <IElectricityIO> (ProvidingPower.ResistanceWorkOnNextList); ProvidingPower.ResistanceWorkOnNextList.Clear(); for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++) { IterateDirectionWorkOnNextList [i].ResistancyOutput(ElectricalSynchronisation.currentTick, Thiswire.GameObject()); } if (ProvidingPower.ResistanceWorkOnNextList.Count <= 0) { IterateDirectionWorkOnNextList = new List <IElectricityIO> (ProvidingPower.ResistanceWorkOnNextListWait); ProvidingPower.ResistanceWorkOnNextListWait.Clear(); for (int i = 0; i < IterateDirectionWorkOnNextList.Count; i++) { IterateDirectionWorkOnNextList [i].ResistancyOutput(ElectricalSynchronisation.currentTick, Thiswire.GameObject()); } } if (ProvidingPower.ResistanceWorkOnNextList.Count <= 0 && ProvidingPower.ResistanceWorkOnNextListWait.Count <= 0) { Break = false; } } }
public static void DirectionInput(int tick, GameObject SourceInstance, IElectricityIO ComingFrom, IElectricityIO Thiswire) { int SourceInstanceID = SourceInstance.GetInstanceID(); if (Thiswire.Data.FirstPresent == 0) { Thiswire.Data.FirstPresent = SourceInstanceID; } if (!(Thiswire.Data.Upstream.ContainsKey(SourceInstanceID))) { Thiswire.Data.Upstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (!(Thiswire.Data.Downstream.ContainsKey(SourceInstanceID))) { Thiswire.Data.Downstream [SourceInstanceID] = new HashSet <IElectricityIO> (); } if (ComingFrom != null) { Thiswire.Data.Upstream [SourceInstanceID].Add(ComingFrom); } bool CanPass = true; if (Thiswire.InData.ConnectionReaction.ContainsKey(ComingFrom.InData.Categorytype)) { if (Thiswire.InData.ConnectionReaction [ComingFrom.InData.Categorytype].DirectionReaction) { if (Thiswire.InData.ConnectionReaction [ComingFrom.InData.Categorytype].DirectionReactionA.AddResistanceCall.Bool) { IProvidePower SourceInstancPowerSupply = SourceInstance.GetComponent <IProvidePower> (); if (SourceInstancPowerSupply != null) { IElectricityIO IElectricityIOPowerSupply = SourceInstance.GetComponent <IElectricityIO> (); if (!Thiswire.Data.ResistanceToConnectedDevices.ContainsKey(IElectricityIOPowerSupply)) { Thiswire.Data.ResistanceToConnectedDevices [IElectricityIOPowerSupply] = new HashSet <PowerTypeCategory> (); } Thiswire.Data.ResistanceToConnectedDevices [IElectricityIOPowerSupply].Add(ComingFrom.InData.Categorytype); SourceInstancPowerSupply.connectedDevices.Add(Thiswire); } } if (Thiswire.InData.ConnectionReaction [ComingFrom.InData.Categorytype].DirectionReactionA.YouShallNotPass) { CanPass = false; } } } if (CanPass) { if (Thiswire.Data.connections.Count > 2) { SourceInstance.GetComponent <IProvidePower> ().DirectionWorkOnNextListWait.Add(Thiswire); } else { SourceInstance.GetComponent <IProvidePower> ().DirectionWorkOnNextList.Add(Thiswire); } } }
public void UpdateCoveringCable(IElectricityIO ComingFrom) { for (int i = 0; i < Covering.Count; i++) { Covering[i].Data.ActualVoltage = ComingFrom.Data.ActualVoltage; Covering[i].Data.CurrentInWire = ComingFrom.Data.CurrentInWire; Covering[i].Data.EstimatedResistance = ComingFrom.Data.EstimatedResistance; } }
public static void CleanConnectedDevicesFromPower(IElectricityIO Thiswire) { Logger.Log("Cleaning it out"); foreach (IElectricityIO IsConnectedTo in Thiswire.connectedDevices) { IsConnectedTo.Data.ResistanceToConnectedDevices.Remove(Thiswire); } Thiswire.connectedDevices.Clear(); }
public static void CleanConnectedDevices(IElectricityIO Thiswire) { Logger.Log("Cleaning it out"); foreach (KeyValuePair <IElectricityIO, HashSet <PowerTypeCategory> > IsConnectedTo in Thiswire.Data.ResistanceToConnectedDevices) { IsConnectedTo.Key.connectedDevices.Remove(Thiswire); } Thiswire.Data.ResistanceToConnectedDevices.Clear(); }
public static void ResistanceInput(float Resistance, GameObject SourceInstance, IElectricityIO ComingFrom, IElectricityIO Thiswire) { if (ComingFrom == null) { var IElec = SourceInstance.GetComponent <IElectricityIO>(); if (Thiswire.Data.ResistanceToConnectedDevices.ContainsKey(IElec)) { if (Thiswire.Data.ResistanceToConnectedDevices [SourceInstance.GetComponent <IElectricityIO> ()].Count > 1) { Logger.Log("oh no!, problem!!!!"); } foreach (PowerTypeCategory ConnectionFrom in Thiswire.Data.ResistanceToConnectedDevices[SourceInstance.GetComponent <IElectricityIO>()]) { Resistance = Thiswire.InData.ConnectionReaction[ConnectionFrom].ResistanceReactionA.Resistance.Ohms; //Logger.Log (Resistance.ToString () + " < to man Resistance | " + ConnectionFrom.ToString() + " < to man ConnectionFrom | " + Thiswire.GameObject().name + " < to man IS "); ComingFrom = ElectricalSynchronisation.DeadEnd; } } } if (ComingFrom != null) { int SourceInstanceID = SourceInstance.GetInstanceID(); if (!(Thiswire.Data.ResistanceComingFrom.ContainsKey(SourceInstanceID))) { Thiswire.Data.ResistanceComingFrom [SourceInstanceID] = new Dictionary <IElectricityIO, float> (); } if (!(Thiswire.Data.ResistanceGoingTo.ContainsKey(SourceInstanceID))) { Thiswire.Data.ResistanceGoingTo[SourceInstanceID] = new Dictionary <IElectricityIO, float>(); } if (Resistance == 0) { Thiswire.Data.ResistanceComingFrom [SourceInstanceID].Remove(ComingFrom); } else { Thiswire.Data.ResistanceComingFrom[SourceInstanceID][ComingFrom] = Resistance; } if (Thiswire.Data.connections.Count > 2) { KeyValuePair <IElectricityIO, IElectricityIO> edd = new KeyValuePair <IElectricityIO, IElectricityIO> (SourceInstance.GetComponent <IElectricityIO> (), Thiswire); ElectricalSynchronisation.ResistanceWorkOnNextListWait.Add(edd); //Logger.Log("Bdded"); } else { KeyValuePair <IElectricityIO, IElectricityIO> edd = new KeyValuePair <IElectricityIO, IElectricityIO> (SourceInstance.GetComponent <IElectricityIO> (), Thiswire); ElectricalSynchronisation.ResistanceWorkOnNextList.Add(edd); //Logger.Log("added"); } } }
public static void PowerUpdateCurrentChange(IElectricityIO Supply) { Supply.FlushSupplyAndUp(Supply.GameObject()); if (Supply.connectedDevices.Count > 0) { if (Supply.Data.SupplyingCurrent != 0) { Supply.ElectricityOutput(ElectricalSynchronisation.currentTick, Supply.Data.SupplyingCurrent, Supply.GameObject()); } } }
public static void PowerUpdateStructureChangeReact(IElectricityIO Supply) { ElectricityFunctions.CircuitSearchLoop(Supply, Supply.GameObject().GetComponent <IProvidePower>()); if (Supply.Data.ChangeToOff) { Supply.Data.ChangeToOff = false; TurnOffSupply(Supply); Supply.InData.ControllingDevice.TurnOffCleanup(); ElectricalSynchronisation.RemoveSupply(Supply.InData.ControllingUpdate, Supply.InData.Categorytype); } }
public void JumpToOtherEnd(GameObject SourceInstance, IElectricityIO ComingFrom) { if (ComingFrom == TheStart) { TheEnd.DirectionInput(SourceInstance, ComingFrom); } else if (ComingFrom == TheEnd) { TheStart.DirectionInput(SourceInstance, ComingFrom); } }
public void PassOnFlushSupplyAndUp(IElectricityIO ComingFrom, GameObject SourceInstance = null) { if (ComingFrom == TheStart) { TheEnd.FlushSupplyAndUp(SourceInstance); } else if (ComingFrom == TheEnd) { TheStart.FlushSupplyAndUp(SourceInstance); } }
public static Electricity WorkOutActualNumbers(IElectricityIO 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; Dictionary <IElectricityIO, float> AnInterestingDictionary = new Dictionary <IElectricityIO, float>(); foreach (KeyValuePair <int, float> CurrentIDItem in ElectricItem.Data.SourceVoltages) //Voltages easy to work out just add up all the voltages from different sources { Voltage += CurrentIDItem.Value; } foreach (KeyValuePair <int, Dictionary <IElectricityIO, float> > CurrentIDItem in ElectricItem.Data.CurrentComingFrom) { foreach (KeyValuePair <IElectricityIO, float> CurrentItem in CurrentIDItem.Value) //Tricky for current since it can flow one way or the other { if (AnInterestingDictionary.ContainsKey(CurrentItem.Key)) { AnInterestingDictionary[CurrentItem.Key] += CurrentItem.Value; } else { AnInterestingDictionary[CurrentItem.Key] = CurrentItem.Value; } } if (ElectricItem.Data.CurrentGoingTo.ContainsKey(CurrentIDItem.Key)) { foreach (KeyValuePair <IElectricityIO, float> CurrentItem in ElectricItem.Data.CurrentGoingTo[CurrentIDItem.Key]) { if (AnInterestingDictionary.ContainsKey(CurrentItem.Key)) { AnInterestingDictionary[CurrentItem.Key] += -CurrentItem.Value; } else { AnInterestingDictionary[CurrentItem.Key] = -CurrentItem.Value; } } } } foreach (KeyValuePair <IElectricityIO, float> 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); Electricity Cabledata = new Electricity(); Cabledata.Current = Current; Cabledata.Voltage = Voltage; Cabledata.EstimatedResistant = Voltage / Current; return(Cabledata); }
public static void FlushSupplyAndUp(IElectricityIO Object, GameObject SourceInstance = null) { if (SourceInstance == null) { if (Object.CurrentComingFrom.Count > 0) { //Logger.Log ("Flushing!!", Category.Electrical); Object.CurrentComingFrom.Clear(); foreach (IElectricityIO JumpTo in Object.connections) { JumpTo.FlushSupplyAndUp(); } Object.CurrentGoingTo.Clear(); Object.SourceVoltages.Clear(); Object.CurrentInWire = new float(); Object.ActualVoltage = new float(); } } else { int InstanceID = SourceInstance.GetInstanceID(); if (Object.CurrentComingFrom.ContainsKey(InstanceID)) { //Logger.Log ("Flushing!!", Category.Electrical); Object.CurrentGoingTo.Remove(InstanceID); Object.CurrentComingFrom.Remove(InstanceID); foreach (IElectricityIO JumpTo in Object.connections) { JumpTo.FlushSupplyAndUp(SourceInstance); } } else if (Object.CurrentGoingTo.ContainsKey(InstanceID)) { //Logger.Log ("Flushing!!", Category.Electrical); Object.CurrentGoingTo.Remove(InstanceID); Object.CurrentComingFrom.Remove(InstanceID); foreach (IElectricityIO JumpTo in Object.connections) { JumpTo.FlushSupplyAndUp(SourceInstance); } } Object.CurrentGoingTo.Remove(InstanceID); Object.SourceVoltages.Remove(InstanceID); Object.ActualCurrentChargeInWire = ElectricityFunctions.WorkOutActualNumbers(Object); Object.CurrentInWire = Object.ActualCurrentChargeInWire.Current; Object.ActualVoltage = Object.ActualCurrentChargeInWire.Voltage; Object.EstimatedResistance = Object.ActualCurrentChargeInWire.EstimatedResistant; } }
public static void PowerUpdateCurrentChange(IElectricityIO Supply) { Supply.FlushSupplyAndUp(Supply.GameObject()); if (Supply.connectedDevices.Count > 0) { if (Supply.Data.SupplyingCurrent != 0) { Supply.ElectricityOutput(Supply.Data.SupplyingCurrent, Supply.GameObject()); } else if (Supply.Data.SupplyingVoltage != 0) { int SourceInstanceID = Supply.GameObject().GetInstanceID(); Supply.ElectricityOutput((Supply.Data.SupplyingVoltage) / (Supply.Data.InternalResistance + ElectricityFunctions.WorkOutResistance(Supply.Data.ResistanceComingFrom[SourceInstanceID])), Supply.GameObject()); } } }
void FindPossibleConnections() { var conns = matrix.GetElectricalConnections(Vector3Int.RoundToInt(transform.localPosition)); foreach (IElectricityIO io in conns) { //Check if InputPosition and OutputPosition connect with this wire if (ConnectionMap.IsConnectedToTile(GetConnPoints(), AdjDir.Overlap, io.GetConnPoints()) && io.GameObject() != gameObject) { connectedWire = io; connected = true; break; } } }
public static void ElectricityInput(float Current, GameObject SourceInstance, IElectricityIO ComingFrom, IElectricityIO Thiswire) { //Logger.Log (tick.ToString () + " <tick " + Current.ToString () + " <Current " + SourceInstance.ToString () + " <SourceInstance " + ComingFrom.ToString () + " <ComingFrom " + Thiswire.ToString () + " <Thiswire ", Category.Electrical); int SourceInstanceID = SourceInstance.GetInstanceID(); if (!(Thiswire.Data.SourceVoltages.ContainsKey(SourceInstanceID))) { Thiswire.Data.SourceVoltages[SourceInstanceID] = new float(); } if (!(Thiswire.Data.CurrentComingFrom.ContainsKey(SourceInstanceID))) { Thiswire.Data.CurrentComingFrom[SourceInstanceID] = new Dictionary <IElectricityIO, float>(); } Thiswire.Data.CurrentComingFrom[SourceInstanceID][ComingFrom] = Current; Thiswire.Data.SourceVoltages[SourceInstanceID] = Current * (ElectricityFunctions.WorkOutResistance(Thiswire.Data.ResistanceComingFrom[SourceInstanceID])); Thiswire.ElectricityOutput(ElectricityFunctions.WorkOutCurrent(Thiswire.Data.CurrentComingFrom[SourceInstanceID]), SourceInstance); }
public void PassOnRemoveSupply(IElectricityIO ComingFrom, GameObject SourceInstance = null) { if (ComingFrom == TheStart) { TheEnd.RemoveSupply(SourceInstance); } else if (ComingFrom == TheEnd) { TheStart.RemoveSupply(SourceInstance); } for (int i = 0; i < Covering.Count; i++) { Covering[i].Data.ActualVoltage = 0; Covering[i].Data.CurrentInWire = 0; Covering[i].Data.EstimatedResistance = 0; } }
public static void FlushResistanceAndUp(IElectricityIO Object, GameObject SourceInstance = null) { if (SourceInstance == null) { if (Object.ResistanceComingFrom.Count > 0) { Object.ResistanceComingFrom.Clear(); foreach (IElectricityIO JumpTo in Object.connections) { JumpTo.FlushResistanceAndUp(); } Object.ResistanceGoingTo.Clear(); Object.CurrentGoingTo.Clear(); Object.CurrentComingFrom.Clear(); Object.SourceVoltages.Clear(); Object.CurrentInWire = new float(); Object.ActualVoltage = new float(); } } else { //Logger.Log ("FlushResistanceAndUp"); int InstanceID = SourceInstance.GetInstanceID(); if (Object.ResistanceComingFrom.ContainsKey(InstanceID) || Object.ResistanceGoingTo.ContainsKey(InstanceID)) { //if (Object.ResistanceComingFrom [InstanceID].Count > 0) { Object.ResistanceComingFrom.Remove(InstanceID); Object.ResistanceGoingTo.Remove(InstanceID); foreach (IElectricityIO JumpTo in Object.connections) { JumpTo.FlushResistanceAndUp(SourceInstance); } Object.CurrentGoingTo.Remove(InstanceID); Object.CurrentComingFrom.Remove(InstanceID); Object.SourceVoltages.Remove(InstanceID); Object.CurrentInWire = new float(); Object.ActualVoltage = new float(); } } }
public override void DirectionInput(GameObject SourceInstance, IElectricityIO ComingFrom, CableLine PassOn = null) { InputOutputFunctions.DirectionInput(SourceInstance, ComingFrom, this); if (PassOn == null) { if (RelatedLine != null) { if (RelatedLine.TheEnd == this.GetComponent <IElectricityIO> ()) { //Logger.Log ("looc"); } else if (RelatedLine.TheStart == this.GetComponent <IElectricityIO> ()) { //Logger.Log ("cool"); } else { //Logger.Log ("hELP{!!!"); } } else { if (!(Data.connections.Count > 2)) { RelatedLine = new CableLine(); if (RelatedLine == null) { Logger.Log("HE:LP:::::::::::::::::::niniinininininin"); } RelatedLine.InitialGenerator = SourceInstance; RelatedLine.TheStart = this; lineExplore(RelatedLine, SourceInstance); if (RelatedLine.TheEnd == null) { RelatedLine = null; } } } } }
public float ModifyElectricityInput(float Current, GameObject SourceInstance, IElectricityIO ComingFrom) { int InstanceID = SourceInstance.GetInstanceID(); float ActualCurrent = RelatedDevice.Data.CurrentInWire; float Resistance = ElectricityFunctions.WorkOutResistance(RelatedDevice.Data.ResistanceComingFrom[InstanceID]); float Voltage = (Current * Resistance); //Logger.Log (Voltage.ToString() + " < Voltage " + Resistance.ToString() + " < Resistance" + ActualCurrent.ToString() + " < ActualCurrent" + Current.ToString() + " < Current"); Tuple <float, float> Currentandoffcut = TransformerCalculations.TransformerCalculate(this, Voltage: Voltage, ResistanceModified: Resistance, ActualCurrent: ActualCurrent); if (Currentandoffcut.Item2 > 0) { if (!(RelatedDevice.Data.CurrentGoingTo.ContainsKey(InstanceID))) { RelatedDevice.Data.CurrentGoingTo[InstanceID] = new Dictionary <IElectricityIO, float>(); } RelatedDevice.Data.CurrentGoingTo[InstanceID][RelatedDevice.GameObject().GetComponent <IElectricityIO>()] = Currentandoffcut.Item2; } //return (Current); return(Currentandoffcut.Item1); }