Exemplo n.º 1
0
 /// <summary>
 /// Register a continuous load from a device connected to the powernet
 /// </summary>
 public void AddDevice(PowerDeviceComponent device)
 {
     Deviceloadlist.Add(device);
     Load += device.Load;
     if (!device.Powered)
     {
         DepoweredDevices.Add(device);
     }
 }
Exemplo n.º 2
0
        public void Update(float frametime)
        {
            float activesupply = Supply;
            float activeload   = Load;

            float storagedemand = 0;

            foreach (var supply in PowerStorageConsumerlist)
            {
                storagedemand += supply.RequestCharge();
            }

            float passivesupply = 0;
            float passivedemand = 0;

            foreach (var supply in PowerStorageSupplierlist)
            {
                passivesupply += supply.AvailableCharge();
                passivedemand += supply.RequestCharge();
            }


            //If we have enough power to feed all load and storage demand, then feed everything
            if (activesupply > activeload + storagedemand + passivedemand)
            {
                PowerAllDevices();
                ChargeActiveStorage();
                ChargePassiveStorage();
            }
            //We don't have enough power for the storage powernet suppliers, ignore powering them
            else if (activesupply > activeload + storagedemand)
            {
                PowerAllDevices();
                ChargeActiveStorage();
            }
            //We require the storage powernet suppliers to power the remaining storage components and device load
            else if (activesupply + passivesupply > activeload + storagedemand)
            {
                PowerAllDevices();
                ChargeActiveStorage();
                RetrievePassiveStorage();
            }
            //We cant afford to fund the storage components, so lets try to power the basic load using our supply and storage supply
            else if (activesupply + passivesupply > activeload)
            {
                PowerAllDevices();
                RetrievePassiveStorage();
            }
            //We cant even cover the basic device load, start disabling devices in order of priority until the remaining load is lowered enough to be met
            else if (activesupply + passivesupply < activeload)
            {
                PowerAllDevices(); //This merely makes our inevitable betrayal all the sweeter
                RetrievePassiveStorage();

                var depowervalue = activeload - (activesupply + passivesupply);

                //Providers use same method to recreate functionality
                foreach (var device in Deviceloadlist)
                {
                    device.Powered = false;
                    DepoweredDevices.Add(device);
                    depowervalue -= device.Load;
                    if (depowervalue < 0)
                    {
                        break;
                    }
                }
            }
        }