コード例 #1
0
ファイル: WireConnector.cs プロジェクト: DmitryMI/TileEngine
        private IPowerConsumer[] GetConsumers(Wire initialWire, List <Wire> wires)
        {
            List <Wire> connectedWires = initialWire.GetConnectedWires();

            connectedWires.Remove(initialWire);
            List <IPowerConsumer> result = new List <IPowerConsumer>();

            wires.Add(initialWire);
            foreach (var connectedWire in connectedWires)
            {
                if (wires.Contains(connectedWire))
                {
                    continue;
                }

                wires.Add(connectedWire);

                IPowerConsumer[] consumers = GetConsumers(connectedWire, wires);
                result.AddRange(consumers);
            }

            List <IPowerSpreader> connectors = initialWire.GetConnectors();

            foreach (var connector in connectors)
            {
                IPowerConsumer connectedDevice = connector.GetConnectedDevice();
                if (connectedDevice != null)
                {
                    result.Add(connectedDevice);
                }
            }

            return(result.ToArray());
        }
コード例 #2
0
        private void RenderConsumer(Listing_Standard list, IPowerConsumer consumer)
        {
            var section = list.BeginSection(ConsumerHeight);

            DrawIcon(section, 32);
            DrawLabel(section, consumer);

            if (!consumer.Essential && SelPawn.Faction == Faction.OfPlayer)
            {
                var enableWhileDrafted    = consumer.EnableWhileDrafted;
                var enableWhileNotDrafted = consumer.EnabledWhileNotDrafted;
                var enableInCombat        = consumer.EnabledInCombat;
                var enableOutOfCombat     = consumer.EnabledOutOfCombat;
                section.CheckboxLabeled("Cyberization.ITab.Power.WhileDrafted".Translate(), ref enableWhileDrafted);
                section.CheckboxLabeled("Cyberization.ITab.Power.WhileNotDrafted".Translate(), ref enableWhileNotDrafted);
                section.CheckboxLabeled("Cyberization.ITab.Power.InCombat".Translate(), ref enableInCombat);
                section.CheckboxLabeled("Cyberization.ITab.Power.OutOfCombat".Translate(), ref enableOutOfCombat);
                consumer.EnableWhileDrafted     = enableWhileDrafted;
                consumer.EnabledWhileNotDrafted = enableWhileNotDrafted;
                consumer.EnabledInCombat        = enableInCombat;
                consumer.EnabledOutOfCombat     = enableOutOfCombat;
            }
            else
            {
                section.Label("Cyberization.ITab.Power.CantDisable".Translate());
            }
            DrawPowerSlider(section, consumer);

            list.EndSection(section);
            list.Gap();
        }
        private static int GetSorting(IPowerConsumer consumer)
        {
            var ordering = consumer.Tags
                           .Select(tag => PartOrdering.FirstIndexOf(a => a == tag))
                           .ToList();

            return((!ordering.NullOrEmpty() ? ordering.First() : 100) * consumer.Priority);
        }
コード例 #4
0
 public override void ExposeData()
 {
     base.ExposeData();
     if (Scribe.mode == LoadSaveMode.PostLoadInit)
     {
         _consumer = comps.OfType <IPowerConsumer>().First();
     }
 }
コード例 #5
0
 private void SendPowerTo(IPowerConsumer consumer, float amount)
 {
     if (_powerStored >= amount)
     {
         consumer.SendPower(amount);
         _powerStored -= amount;
     }
 }
コード例 #6
0
 public static void TurnOnPower(this IPowerConsumer consumer)
 {
     UnityEngine.Debug.Log("turning on consumer");
     if (!consumer.HasPower)
     {
         consumer.HasPower = true;
         consumer.RefreshVisualization();
         consumer.OnPowerChanged();
     }
 }
コード例 #7
0
 public static void RefreshVisualization(this IPowerConsumer c)
 {
     if (c is IVariablePowerConsumer)
     {
         (c as IVariablePowerConsumer).RefreshVisualization();
     }
     else if (c.PowerViz.PowerActive != null)
     {
         c.PowerViz.PowerActive.gameObject.SetActive((!(c.FaultedPercentage > 0f)) && c.IsOn);
     }
 }
コード例 #8
0
        public static void EmergencyShutdown(this IPowerConsumer c)
        {
            if (c.HasPower)
            {
                c.HasPower = false;
                c.OnPowerChanged();
            }
            if (c.IsOn)
            {
                c.IsOn = false;
                c.OnEmergencyShutdown();
            }

            c.RefreshVisualization();
        }
コード例 #9
0
        /// <summary>
        /// Event called when a new module is mounted at a module mount.
        /// </summary>
        /// <param name="moduleMount"></param>
        protected override void OnModuleMounted(Module module)
        {
            PowerPlant newPowerPlant = module == null ? null : module.transform.GetComponent <PowerPlant>();

            if (newPowerPlant != null)
            {
                mountedPowerPlant = newPowerPlant;
                hasPowerPlant     = true;
            }

            IPowerConsumer powerConsumer = module.GetComponent <IPowerConsumer>();

            if (powerConsumer != null)
            {
                powerConsumer.Power = this;
            }
        }
コード例 #10
0
        /// <summary>
        /// Event called when a new module is mounted at a module mount.
        /// </summary>
        /// <param name="moduleMount"></param>
        protected override void OnModuleMounted(Module module)
        {
            PowerPlant newPowerPlant = module == null ? null : module.transform.GetComponent <PowerPlant>();

            if (newPowerPlant != null)
            {
                powerPlant = newPowerPlant;

                if (fillStorageOnPowerPlantLoaded)
                {
                    for (int i = 0; i < poweredSubsystems.Count; ++i)
                    {
                        poweredSubsystems[i].currentStorageValue = poweredSubsystems[i].storageCapacity;
                    }
                }
            }

            IPowerConsumer powerConsumer = module.GetComponent <IPowerConsumer>();

            if (powerConsumer != null)
            {
                powerConsumer.Power = this;
            }
        }
コード例 #11
0
 public static int ConsumptionInPowerUnits(this IPowerConsumer c)
 {
     return(Math.Max(1, Mathf.RoundToInt(c.WattsConsumed / ElectricityConstants.WattsPerBlock)));
 }
コード例 #12
0
 public override void PostMake()
 {
     base.PostMake();
     _consumer = comps.OfType <IPowerConsumer>().First();
 }
コード例 #13
0
 public void Add(IPowerConsumer powerConsumer)
 {
 }
コード例 #14
0
 private static void DrawPowerSlider(Listing_Standard section, IPowerConsumer consumer)
 {
     consumer.RateWanted = Mathf.RoundToInt(section.Slider(Mathf.RoundToInt(consumer.RateWanted), consumer.MinRate, consumer.MaxRate));
     section.Gap();
 }