Ejemplo n.º 1
0
    protected float attemptTransferPower()
    {
        VicisMod.log(getPrefix(), "Running LFU");
        lastSearch -= LowFrequencyThread.mrPreviousUpdateTimeStep;
        // Nothing to do
        if (currentPower <= 0)
        {
            return(0);
        }
        lastTransfer1 -= LowFrequencyThread.mrPreviousUpdateTimeStep;
        if (lastTransfer1 > 0)
        {
            return(0);
        }
        lastTransfer1 += transferFrequency;
        VicisMod.log(getPrefix(), "Currently have " + currentPower + " Power");
        cullPCIs();
        if (lastSearch <= 0)
        {
            VicisMod.log(getPrefix(), "Finding PCIs");
            findPCIs();
            lastSearch = scanFrequency;
        }

        VicisMod.log(getPrefix(), "Aware of " + pcis.Count + " PCIs");
        // Now lets charge these guys up!
        float transferedThisTime = 0;

        for (int i = 0; i < pcis.Count; ++i)
        {
            PowerConsumerInterface pci = pcis[i];
            if (pci.WantsPowerFromEntity(this))
            {
                float transfer = transferCap;
                transfer = Math.Min(transfer, currentPower);
                transfer = Math.Min(transfer, pci.GetMaximumDeliveryRate());
                transfer = Math.Min(transfer, pci.GetRemainingPowerCapacity());
                if (transfer > 0 && pci.DeliverPower(transfer))
                {
                    VicisMod.log(getPrefix(), "Adding " + transfer + " to PCI " + pci.ToString());
                    currentPower       -= transfer;
                    totalTransfered    += transfer;
                    transferedThisTime += transfer;
                    // And we're done
                    if (currentPower == 0)
                    {
                        return(transferedThisTime);
                    }
                }
            }
        }
        return(transferedThisTime);
    }
        void FeedConsumer(PowerConsumerInterface consumer, float ticks)
        {
            var powerToHoldOn = 0f;

            if (consumer as PowerStorageInterface != null)
            {
                powerToHoldOn = EqualisedPower(consumer);
            }
            if (Power > powerToHoldOn)
            {
                var transferAmount = new [] {
                    OutputRate *ticks,
                    Power - powerToHoldOn,
                    consumer.GetRemainingPowerCapacity(),
                    consumer.GetMaximumDeliveryRate() *ticks,
                }.Min();
                if (consumer.DeliverPower(transferAmount))
                {
                    Power -= transferAmount;
                }
            }
        }