Пример #1
0
    protected void findMk4AndMk5Bats()
    {
        VicisMod.log(getPrefix(), "Looking for T4 and T5 batteries");
        long[] coords = new long[3];
        for (int i = 0; i < 3; ++i)
        {
            for (int j = -1; j <= 1; j += 2)
            {
                Array.Clear(coords, 0, 3);
                coords[i] = j;

                long x = mnX + coords[0];
                long y = mnY + coords[1];
                long z = mnZ + coords[2];

                Segment segment = base.AttemptGetSegment(x, y, z);
                // Check if segment was generated (skip this point if it doesn't
                if (segment == null)
                {
                    continue;
                }
                ushort cube = segment.GetCube(x, y, z);
                // If this isn't an entity, skip it
                if (!CubeHelper.HasEntity((int)cube))
                {
                    continue;
                }
                PowerConsumerInterface pci = segment.SearchEntity(x, y, z) as PowerConsumerInterface;
                if (pci == null)
                {
                    continue;
                }
                // We're only looking for T4 and T5 batteries
                if (!(pci is T4_Battery) && !(pci is T5_Battery))
                {
                    continue;
                }
                VicisMod.log(getPrefix(), "Found one: " + pci.ToString());
                // Let's only keep track of PCIs that will accept power from the PowWow
                if (!pci.WantsPowerFromEntity(this))
                {
                    continue;
                }
                for (int l = mk4AndMk5Bats.Count - 1; l >= 0 && pci != null; --l)
                {
                    PowerConsumerInterface pci2 = mk4AndMk5Bats[l];
                    if (pci2 != null && !(pci2 as SegmentEntity).mbDelete && pci2 == pci)
                    {
                        pci = null;
                    }
                }
                VicisMod.log(getPrefix(), "End, checking " + pci);
                if (pci != null)
                {
                    mk4AndMk5Bats.Add(pci);
                }
            }
        }
    }
Пример #2
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);
    }