示例#1
0
 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());
         }
     }
 }
 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 ElectricityInput(int tick, 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(tick, ElectricityFunctions.WorkOutCurrent(Thiswire.Data.CurrentComingFrom [SourceInstanceID]), SourceInstance);
    }
    public static void ElectricityInput(int tick, 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 (electricity.voltage > 1f) {
        //	connected = true;
        //}
        if (!(Thiswire.SourceVoltages.ContainsKey(SourceInstanceID)))
        {
            Thiswire.SourceVoltages [SourceInstanceID] = new float();
        }

        if (!(Thiswire.CurrentComingFrom.ContainsKey(SourceInstanceID)))
        {
            Thiswire.CurrentComingFrom [SourceInstanceID] = new Dictionary <IElectricityIO, float> ();
        }
        Thiswire.CurrentComingFrom [SourceInstanceID] [ComingFrom] = Current;
        //Logger.Log (Current.ToString () + " <Current Using Resistance> " + WorkOutResistance (Thiswire.ResistanceComingFrom [SourceInstanceID]).ToString (), Category.Electrical);
        Thiswire.SourceVoltages[SourceInstanceID] = Current * (WorkOutResistance(Thiswire.ResistanceComingFrom [SourceInstanceID]));
        //Logger.Log (Thiswire.ActualCurrentChargeInWire.ToString () + " How much current", Category.Electrical);
        //Pass the charge on:

        if (Thiswire.CanProvideResistance)
        {
            IProvidePower SourceInstancPowerSupply = SourceInstance.GetComponent <IProvidePower> ();

            if (SourceInstancPowerSupply != null)
            {
                IElectricityIO IElectricityIOPowerSupply = SourceInstance.GetComponent <IElectricityIO> ();
                Thiswire.ResistanceToConnectedDevices.Add(IElectricityIOPowerSupply);
                SourceInstancPowerSupply.connectedDevices.Add(Thiswire);
            }
        }

        Thiswire.ElectricityOutput(tick, ElectricityFunctions.WorkOutCurrent(Thiswire.CurrentComingFrom [SourceInstanceID]), SourceInstance);
    }