Ejemplo n.º 1
0
        public override void OnRemovedFromScene()
        {
            if (m_inventory != null)
            {
                m_inventory.RemoveItemsOfType(m_inventory.GetItemAmount(m_remoteEnergyId), m_remoteEnergyBuilder);
            }

            base.OnRemovedFromScene();
        }
 public override void Close()
 {
     if (m_inventory != null)
     {
         for (int i = 0; i < pulseWeaponInfo.classes; i++)
         {
             m_inventory.RemoveItemsOfType(m_inventory.GetItemAmount(chargeDefinitionIds[i]), chargeObjectBuilders[i]);
         }
     }
     base.Close();
 }
        public void ClearInventory()
        {
            try
            {
                if (m_inventory != null)
                {
                    m_inventory.RemoveItemsOfType(m_inventory.GetItemAmount(m_chargeDefinitionId), m_magDefId);
                }

                m_inventoryCleared = true;
            }
            catch (Exception e)
            { Debug.HandleException(e); }
        }
        public static double RemoveFromInventory(IMyInventory inventory, MyDefinitionId itemDefinition, double amount)
        {
            var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(itemDefinition);
            MyObjectBuilder_InventoryItem item = new MyObjectBuilder_InventoryItem
            {
                Amount = new MyFixedPoint {
                    RawValue = (long)(amount * _multi)
                },
                PhysicalContent = content
            };
            MyFixedPoint inventoryAmount = inventory.GetItemAmount(itemDefinition);

            if (inventoryAmount >= item.Amount)
            {
                inventory.RemoveItemsOfType(item.Amount, item.PhysicalContent);

                return(amount);
            }

            if (inventoryAmount <= 0)
            {
                return(0);
            }

            inventory.RemoveItemsOfType(inventoryAmount, item.PhysicalContent);

            return(inventoryAmount.RawValue == 0 ? 0 : inventoryAmount.RawValue / _multi);
        }
Ejemplo n.º 5
0
        private void RemoveInventory(IMyInventory playerInventory, List <Sandbox.Game.Entities.MyEntity> cargoBlocks, MyFixedPoint amount, MyDefinitionId definitionId)
        {
            var available = playerInventory.GetItemAmount(definitionId);

            if (amount <= available)
            {
                playerInventory.RemoveItemsOfType(amount, definitionId);
                amount = 0;
            }
            else
            {
                playerInventory.RemoveItemsOfType(available, definitionId);
                amount -= available;
            }

            foreach (var cubeBlock in cargoBlocks)
            {
                if (amount > 0)
                {
                    var cubeInventory = cubeBlock.GetInventory();
                    available = cubeInventory.GetItemAmount(definitionId);
                    if (amount <= available)
                    {
                        cubeInventory.RemoveItemsOfType(amount, definitionId);
                        amount = 0;
                    }
                    else
                    {
                        cubeInventory.RemoveItemsOfType(available, definitionId);
                        amount -= available;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public int GetItemCountFromInventory(IMyInventory inventory, string itemName)
        {
            MyDefinitionId myDefinitionId = GetMyDefinitionIdByName(itemName);
            MyItemType     myItemType     = MyItemType.MakeComponent(myDefinitionId.SubtypeId.ToString());

            return((int)inventory.GetItemAmount(myItemType));
        }
Ejemplo n.º 7
0
        void Recharge()
        {
            int chargesInInventory = (int)m_inventory.GetItemAmount(chargeDefinitionIds[damageUpgrades]);

            if (chargesInInventory < attractorWeaponInfo.keepAtCharge)
            {
                if (resourceSink.RequiredInputByType(electricityDefinition) != (attractorWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, (attractorWeaponInfo.powerUsage / efficiencyUpgrades));

                    setPowerConsumption = (attractorWeaponInfo.powerUsage / efficiencyUpgrades);
                    powerConsumption    = (attractorWeaponInfo.powerUsage / efficiencyUpgrades);
                }
                else
                {
                    if (!functionalBlock.Enabled)
                    {
                        powerConsumption = 0.0001f;
                    }
                }

                if (resourceSink.CurrentInputByType(electricityDefinition) == (attractorWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    if (!overheated)
                    {
                        m_inventory.AddItems((MyFixedPoint)(attractorWeaponInfo.keepAtCharge - chargesInInventory), chargeObjectBuilders [damageUpgrades]);
                    }
                }
            }
            else if (chargesInInventory > attractorWeaponInfo.keepAtCharge)
            {
                m_inventory.RemoveItemsOfType((MyFixedPoint)(chargesInInventory - attractorWeaponInfo.keepAtCharge), chargeObjectBuilders [damageUpgrades]);
            }
            else
            {
                if (setPowerConsumption != 0.0001f)
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f);

                    setPowerConsumption = 0.0001f;
                    powerConsumption    = 0.0001f;
                }
            }

//            terminalBlock.RefreshCustomInfo ();
        }
Ejemplo n.º 8
0
        private void RemoveInventory(IMyInventory playerInventory, List <MyCubeBlock> cargoBlocks, List <MyCubeBlock> tankBlocks, MyFixedPoint amount, MyDefinitionId definitionId)
        {
            if (definitionId.TypeId == typeof(MyObjectBuilder_GasProperties))
            {
                foreach (MyCubeBlock cubeBlock in tankBlocks)
                {
                    MyGasTankDefinition gasTankDefintion = cubeBlock.BlockDefinition as MyGasTankDefinition;

                    if (gasTankDefintion == null || gasTankDefintion.StoredGasId != definitionId)
                    {
                        continue;
                    }

                    var tank = ((IMyGasTank)cubeBlock);

                    // TODO: Cannot set oxygen level of tank yet.
                    //tank.le
                    //var tankLevel = ((IMyGasTank)cubeBlock).FilledRatio;
                    //storedAmount += (MyFixedPoint)((decimal)tankLevel * (decimal)gasTankDefintion.Capacity);
                }
            }
            else
            {
                var available = playerInventory.GetItemAmount(definitionId);
                if (amount <= available)
                {
                    playerInventory.RemoveItemsOfType(amount, definitionId);
                    amount = 0;
                }
                else
                {
                    playerInventory.RemoveItemsOfType(available, definitionId);
                    amount -= available;
                }

                foreach (var cubeBlock in cargoBlocks)
                {
                    if (amount > 0)
                    {
                        var cubeInventory = cubeBlock.GetInventory();
                        available = cubeInventory.GetItemAmount(definitionId);
                        if (amount <= available)
                        {
                            cubeInventory.RemoveItemsOfType(amount, definitionId);
                            amount = 0;
                        }
                        else
                        {
                            cubeInventory.RemoveItemsOfType(available, definitionId);
                            amount -= available;
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static VRage.MyFixedPoint RemoveMaxItems(this IMyInventory srcInventory, VRage.MyFixedPoint maxRemoveFP, MyObjectBuilder_PhysicalObject objectBuilder)
        {
            var contentId = objectBuilder.GetObjectId();

            VRage.MyFixedPoint removedAmount = 0;
            if (!srcInventory.ContainItems(maxRemoveFP, objectBuilder))
            {
                maxRemoveFP = srcInventory.GetItemAmount(contentId);
            }
            if (maxRemoveFP > 0)
            {
                srcInventory.RemoveItemsOfType(maxRemoveFP, contentId, MyItemFlags.None, false);
                removedAmount = maxRemoveFP;
            }
            return(maxRemoveFP);
        }
Ejemplo n.º 10
0
        private void UpdateCurrentInventory()
        {
            foreach (var e in _blocks)
            {
                if (e.HasInventory)
                {
                    for (int i = 0; i < e.InventoryCount; i++)
                    {
                        _inventory = e.GetInventory(i);

                        foreach (var itemT in _itemLookup.Values)
                        {
                            _currentInventory[itemT.ItemName] += (int)_inventory.GetItemAmount(itemT.SEItemType);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
            public Store(IMyInventory inv, MyItemType itemType, string description = "") : base(description)
            {
                MyItemInfo itemInfo = itemType.GetItemInfo();
                float      amount   = (float)inv.GetItemAmount(itemType);

                Max        += (float)inv.MaxVolume;
                DefaultUnit = "kL";

                if (itemInfo.UsesFractions)
                {
                    Mass    = amount;
                    Current = itemInfo.Volume * amount;
                }
                else
                {
                    Mass    = itemInfo.Mass * amount;
                    Current = itemInfo.Volume * amount;
                }
            }
Ejemplo n.º 12
0
        /// <summary>
        /// Get the component amount and index from an inventory.
        /// </summary>
        /// <param name="inventory">Inventory to search.</param>
        /// <param name="defId">Component definition</param>
        /// <param name="amount">Amount of components in inventory</param>
        /// <param name="index">Component position in inventory</param>
        private void GetComponentInInventory(IMyInventory inventory, MyDefinitionId defId, out int amount, out int index)
        {
            amount = (int)inventory.GetItemAmount(defId);
            if (amount == 0)
            {
                index = -1;
                return;
            }

            var allItems = inventory.GetItems();

            for (index = 0; index < allItems.Count; index++)
            {
                if (allItems[index].Content.GetId() == defId)
                {
                    return;
                }
            }
        }
Ejemplo n.º 13
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();


            IMyInventory inventory    = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(0) as IMyInventory;
            double       targetAmount = 10000;

            if (TerminalalBlock.CustomData != null && TerminalalBlock.CustomData != "")
            {
                try
                {
                    targetAmount = double.Parse(TerminalalBlock.CustomData);
                }
                catch (Exception e) { }
            }

            try
            {
                for (int i = 0; i < inventory.ItemCount; i++)
                {
                    MyObjectBuilder_PhysicalObject builder = GetItemBuilder(inventory.GetItemAt(i).Value);
                    if (builder == null)
                    {
                        continue;
                    }

                    double amount = targetAmount - (double)inventory.GetItemAmount(builder);
                    if (amount < 0)
                    {
                        inventory.RemoveItemsOfType((MyFixedPoint)Math.Abs(amount), builder);
                    }
                    else if (amount > 0)
                    {
                        inventory.AddItems((MyFixedPoint)amount, builder);
                    }
                }
            } catch (Exception e) { }

            TerminalalBlock.RefreshCustomInfo();
        }
Ejemplo n.º 14
0
            protected override void update()
            {
                for (; invIndex_ < inventories_.Count &&
                     App.Runtime.CurrentInstructionCount < Default.MaxInstructionCount;
                     invIndex_++)
                {
                    IMyInventory inventory = inventories_[invIndex_];
                    currentVolume_ += (double)inventory.CurrentVolume;

                    foreach (var item in items_)
                    {
                        var amount = inventory.GetItemAmount(item.type);
                        item.currentAmount += (long)amount;
                        currentItems_      += (long)amount;
                    }
                }

                if (invIndex_ >= inventories_.Count)
                {
                    base.update();
                }
            }
Ejemplo n.º 15
0
            private void fillSpecialInventoryWithItem(IMyInventory inventory, int desiredIndex, MyContext context)
            {
                KeyValuePair <MyItemType, int> desired = DESIRED_ITEMS[desiredIndex];
                long amount  = inventory.GetItemAmount(desired.Key).RawValue;
                long deficit = desired.Value * 1000000 - amount;

                if (deficit <= 0)
                {
                    return;
                }

                for (int i = 0; i < context._cargo.Count; ++i)
                {
                    IMyInventory           cargoInventory = context._cargo[i].GetInventory(0);
                    List <MyInventoryItem> items          = _cargoDesiredItems[i][desiredIndex];
                    for (int candidateIndex = 0; candidateIndex < items.Count; ++candidateIndex)
                    {
                        MyInventoryItem candidate  = items[candidateIndex];
                        MyFixedPoint    toTransfer = new MyFixedPoint();
                        toTransfer.RawValue = Math.Min(deficit, candidate.Amount.RawValue);

                        List <IMyTextPanel> panel = new List <IMyTextPanel>();
                        context.Program.GridTerminalSystem.GetBlocksOfType(panel);

                        if (inventory.TransferItemFrom(cargoInventory, candidate, toTransfer))
                        {
                            deficit -= toTransfer.RawValue;
                            // todo really we should adjust our internal state of what amount is in this inventory item
                            // because the game apparently doesn't do it for us
                            //
                            // this means that if 2 welders want an item and there is not enough in one box to fulfil it,
                            // it won't pull from a different box until the next update
                            //
                            // but I can't be bothered to fix it and this will work well enough I think
                        }
                    }
                }
            }
Ejemplo n.º 16
0
            public Store(IMyEntity entity, MyItemType itemType, string description = "") : base(description)
            {
                for (int i = 0; i < entity.InventoryCount; i++)
                {
                    IMyInventory inv = entity.GetInventory(i);

                    MyItemInfo itemInfo = itemType.GetItemInfo();
                    float      amount   = (float)inv.GetItemAmount(itemType);

                    Max        += (float)inv.MaxVolume;
                    DefaultUnit = "kL";

                    if (itemInfo.UsesFractions)
                    {
                        Mass    += amount;
                        Current += itemInfo.Volume * amount;
                    }
                    else
                    {
                        Mass    += itemInfo.Mass * amount;
                        Current += itemInfo.Volume * amount;
                    }
                }
            }
Ejemplo n.º 17
0
        public void Main(string argument, UpdateType updateSource)
        {
            var quantities        = new Dictionary <MyItemType, MyFixedPoint>();
            var future_quantities = new Dictionary <MyItemType, MyFixedPoint>();

            // Init quantities from the content of the coffer
            IMyInventory inventory = cargo.GetInventory();

            foreach (Target target in targets)
            {
                quantities.Add(target.target, inventory.GetItemAmount(target.target));
                future_quantities.Add(target.target, 0);
            }

            var usage = new Dictionary <IMyProductionBlock, long>();

            foreach (IMyProductionBlock factory in factories)
            {
                List <MyProductionItem> queue = new List <MyProductionItem>();
                factory.GetQueue(queue);
                usage.Add(factory, queue.Count());
                foreach (MyProductionItem prod in queue)
                {
                    foreach (Target target in targets)
                    {
                        if (target.recipe != prod.BlueprintId)
                        {
                            continue;
                        }
                        quantities[target.target]        += prod.Amount;
                        future_quantities[target.target] += prod.Amount;
                    }
                }
            }

            int actualFactory = 0;

            // Iterate over targets to produce, one queue item by one queue item,
            // and assign them to factories
            for (int cur_it = 0; cur_it < 2; ++cur_it)
            {
                while (true)
                {
                    // Find next factory
                    int nextFactory = actualFactory;
                    do
                    {
                        nextFactory++;
                        nextFactory %= factories.Count();
                    } while (nextFactory != actualFactory &&
                             usage[factories[nextFactory]] > 3 * (1 - cur_it));
                    actualFactory = nextFactory;
                    if (usage[factories[nextFactory]] > 3 * (1 - cur_it))
                    {
                        break;
                    }

                    // Find next target
                    int nextTarget = actualTarget;
                    do
                    {
                        nextTarget++;
                        nextTarget %= targets.Count();
                        // No target left
                    } while (nextTarget != actualTarget &&
                             ((cur_it == 0 &&
                               future_quantities[targets[nextTarget].target] > 0) ||
                              targets[nextTarget].amount
                              - quantities[targets[nextTarget].target]
                              <= targets[nextTarget].batch()));
                    actualTarget = nextTarget;
                    if ((cur_it == 0 &&
                         future_quantities[targets[nextTarget].target] > 0) ||
                        targets[nextTarget].amount
                        - quantities[targets[nextTarget].target]
                        <= targets[nextTarget].batch())
                    {
                        break;
                    }

                    factories[actualFactory].AddQueueItem(targets[actualTarget].recipe, targets[actualTarget].batch());
                    usage[factories[actualFactory]]++;
                    quantities[targets[actualTarget].target]        += targets[actualTarget].batch();
                    future_quantities[targets[actualTarget].target] += targets[actualTarget].batch();
                }
            }

            // Update displays
            StringBuilder sb_good = new StringBuilder("", 100);
            StringBuilder sb_ok   = new StringBuilder("", 100);
            StringBuilder sb_bad  = new StringBuilder("", 100);

            foreach (Target target in targets)
            {
                long bs       = toLong(inventory.GetItemAmount(target.target));
                long staged   = toLong(quantities[target.target]) - bs;
                long expected = toLong(target.amount);
                long batch    = toLong(target.batch());

                if (expected == 0 && bs == 0)
                {
                    continue;
                }

                if (bs + staged + batch > expected && staged == 0)
                {
                    sb_good.AppendFormat("{0} {1}/{2}/{3}\n", target.target.SubtypeId, bs, staged, expected);
                }
                else if (bs + staged >= expected / 3)
                {
                    sb_ok.AppendFormat("{0} {1}/{2}/{3}\n", target.target.SubtypeId, bs, staged, expected);
                }
                else
                {
                    sb_bad.AppendFormat("{0} {1}/{2}/{3}\n", target.target.SubtypeId, bs, staged, expected);
                }
            }

            panel_good.WriteText(sb_good, false);
            panel_ok.WriteText(sb_ok, false);
            panel_bad.WriteText(sb_bad, false);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Get the component amount and index from an inventory.
        /// </summary>
        /// <param name="inventory">Inventory to search.</param>
        /// <param name="defId">Component definition</param>
        /// <param name="amount">Amount of components in inventory</param>
        /// <param name="index">Component position in inventory</param>
        private void GetComponentInInventory(IMyInventory inventory, MyDefinitionId defId, out int amount, out int index)
        {
            amount = (int)inventory.GetItemAmount(defId);
            if (amount == 0)
            {
                index = -1;
                return;
            }

            var allItems = inventory.GetItems();
            for (index = 0; index < allItems.Count; index++)
                if (allItems[index].Content.GetId() == defId)
                    return;
        }
        public static double CountItemsInventory(IMyInventory inventory, MyDefinitionId itemDefinition)
        {
            var itemsAmount = inventory.GetItemAmount(itemDefinition);

            return(itemsAmount.RawValue == 0 ? 0 : itemsAmount.RawValue / _multi);
        }
Ejemplo n.º 20
0
        public override void UpdateBeforeSimulation()
        {
            int chargesInInventory = (int)m_inventory.GetItemAmount(chargeDefinitionIds [damageUpgrades]);

            IMyCubeBlock cube = Entity as IMyCubeBlock;

            long currentShootTime = ((MyObjectBuilder_InteriorTurret)cube.GetObjectBuilderCubeBlock()).GunBase.LastShootTime;


            if (currentHeat > 0f)
            {
                if ((ticks - lastShootTimeTicks) > beamWeaponInfo.heatDissipationDelay)
                {
                    currentHeat -= beamWeaponInfo.heatDissipationPerTick;

                    if (currentHeat <= 0f)
                    {
                        currentHeat = 0f;

                        overheated = false;
                    }
                }
            }

            //MyAPIGateway.Utilities.ShowNotification("TIME: " + currentShootTime + " :: " + lastShootTime, 17, MyFontEnum.Red);


            if (currentShootTime != lastShootTime)
            {
                // test

                hitBool = false;

                MyEntitySubpart subpart1 = cubeBlock.GetSubpart("InteriorTurretBase1");
                MyEntitySubpart subpart2 = subpart1.GetSubpart("InteriorTurretBase2");;
                //MyAPIGateway.Utilities.ShowNotification("Dif: " + (currentShootTime - lastShootTime), 17, MyFontEnum.Blue);

                from = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 1.25d;
                to   = subpart2.WorldMatrix.Translation + subpart2.WorldMatrix.Forward * 3000d;

                LineD testRay = new LineD(from, to);

                List <MyLineSegmentOverlapResult <MyEntity> > result = new List <MyLineSegmentOverlapResult <MyEntity> >();

                MyGamePruningStructure.GetAllEntitiesInRay(ref testRay, result);


                foreach (var resultItem in result)
                {
                    IMyCubeGrid grid = resultItem.Element as IMyCubeGrid;

                    IMyDestroyableObject destroyableEntity = resultItem.Element as IMyDestroyableObject;

                    if (grid != null)
                    {
                        IMySlimBlock slimblock;

                        double hitd;

                        Vector3D?resultVec = grid.GetLineIntersectionExactAll(ref testRay, out hitd, out slimblock);

                        if (resultVec != null)
                        {
                            hitBool = true;

                            toTarget = from + subpart2.WorldMatrix.Forward * hitd;

                            if (!MyAPIGateway.Session.CreativeMode)
                            {
                                slimblock.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                            }
                            else
                            {
                                slimblock.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                            }
                            //MyAPIGateway.Utilities.ShowNotification("" + s.BlockDefinition.Id.SubtypeId + " ::: " + resultItem.Distance, 17);
                        }
                    }
                    if (destroyableEntity != null)
                    {
                        IMyEntity ent  = (IMyEntity)destroyableEntity;
                        double    hitd = (from - ent.WorldMatrix.Translation).Length();

                        toTarget = from + subpart2.WorldMatrix.Forward * hitd;

                        hitBool = true;

                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            destroyableEntity.DoDamage(beamWeaponInfo.damage * (currentHeat / beamWeaponInfo.maxHeat + 0.2f), MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                        }
                        else
                        {
                            destroyableEntity.DoDamage(beamWeaponInfo.damage * 1.2f, MyStringHash.GetOrCompute("Laser"), false, default(MyHitInfo), cubeBlock.EntityId);
                        }
                    }
                }


                // test

                lastShootTime      = currentShootTime;
                lastShootTimeTicks = ticks;

                currentHeat += beamWeaponInfo.heatPerTick;

                if (currentHeat > beamWeaponInfo.maxHeat)
                {
                    currentHeat = beamWeaponInfo.maxHeat;

                    overheated = true;
                }
            }

            if (ticks - lastShootTimeTicks < 3)
            {
                var beamcolor     = Color.DodgerBlue;
                var beamcolor_aux = Color.LightSkyBlue;
                var maincolor     = new Vector4(beamcolor.X / 30, beamcolor.Y / 30, beamcolor.Z / 30, 1f);
                var auxcolor      = new Vector4(beamcolor_aux.X / 30, beamcolor_aux.Y / 30, beamcolor_aux.Z / 30, 1f);
                var material      = MyStringId.GetOrCompute("WeaponLaser");
                if (hitBool == false)
                {
                    if (!MyAPIGateway.Utilities.IsDedicated)
                    {
                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f);
                        }
                        else
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref auxcolor, 0.30f * 1.2f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, to, material, ref maincolor, 1.0f * 1.2f);
                        }
                    }
                }
                else
                {
                    if (!MyAPIGateway.Utilities.IsDedicated)
                    {
                        if (!MyAPIGateway.Session.CreativeMode)
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f);
                        }
                        else
                        {
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref auxcolor, 0.30f * 1.2f);
                            VRage.Game.MySimpleObjectDraw.DrawLine(from, toTarget, material, ref maincolor, 1.0f * 1.2f);
                        }
                    }
                }
            }

            if (chargesInInventory < beamWeaponInfo.keepAtCharge)
            {
                if (resourceSink.RequiredInputByType(electricityDefinition) != (beamWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, (beamWeaponInfo.powerUsage / efficiencyUpgrades));

                    setPowerConsumption = (beamWeaponInfo.powerUsage / efficiencyUpgrades);
                    powerConsumption    = (beamWeaponInfo.powerUsage / efficiencyUpgrades);
                }
                else
                {
                    if (!functionalBlock.Enabled)
                    {
                        powerConsumption = 0.0001f;
                    }
                }

                if (resourceSink.CurrentInputByType(electricityDefinition) == (beamWeaponInfo.powerUsage / efficiencyUpgrades))
                {
                    if (!overheated)
                    {
                        m_inventory.AddItems((MyFixedPoint)(beamWeaponInfo.keepAtCharge - chargesInInventory), chargeObjectBuilders [damageUpgrades]);
                    }
                }
            }
            else if (chargesInInventory > beamWeaponInfo.keepAtCharge)
            {
                m_inventory.RemoveItemsOfType((MyFixedPoint)(chargesInInventory - beamWeaponInfo.keepAtCharge), chargeObjectBuilders [damageUpgrades]);
            }
            else
            {
                if (setPowerConsumption != 0.0001f)
                {
                    resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f);

                    setPowerConsumption = 0.0001f;
                    powerConsumption    = 0.0001f;
                }
            }

            terminalBlock.RefreshCustomInfo();

            ticks++;
        }
Ejemplo n.º 21
0
        public override void UpdateBeforeSimulation()
        {
            if (!MyAPIGateway.Multiplayer.IsServer ||
                PhysicalFuelObject == null ||
                ModBlock.CurrentOutput == 0 ||
                !ModBlock.IsFunctional ||
                !ModBlock.IsWorking)
            {
                return;
            }

            float  powerRatio        = ModBlock.CurrentOutput / ModBlock.MaxOutput;
            double consumptionAmount = MaxConsumptionPerTick * powerRatio;


            MyFixedPoint quanity = Inventory.GetItemAmount(DefinitionId);

            // refill fuel tanks if they are low because keens pulling system for reactors is extremely slow.
            if (quanity < fuelCheckThreshold && quanity != 0)
            {
                // refreshes the tank inventories if new blocks have been added.
                if (refreshInventory)
                {
                    fuelTanks.Clear();
                    ModBlock.CubeGrid.GetBlocks(temp, (b) =>
                    {
                        if (b.FatBlock != null && !b.FatBlock.BlockDefinition.IsNull() && FuelStorage.Contains(b.FatBlock.BlockDefinition.SubtypeId))
                        {
                            fuelTanks.Add(b.FatBlock.GetInventory(0));
                        }
                        return(false);
                    });

                    refreshInventory = false;
                }

                MyFixedPoint emptySpace = EmptySpace; // no reason to run calculations more than once

                foreach (IMyInventory inv in fuelTanks)
                {
                    if (inv == null)
                    {
                        continue;
                    }
                    if (!Inventory.IsConnectedTo(inv))
                    {
                        continue;
                    }

                    MyFixedPoint value = inv.GetItemAmount(DefinitionId);

                    if (value == null)
                    {
                        continue;
                    }

                    if (value > emptySpace)
                    {
                        inv.RemoveItemsOfType(emptySpace, PhysicalFuelObject, false);
                        Inventory.AddItems(emptySpace, PhysicalFuelObject);
                        break;
                    }
                    else if (value != 0)
                    {
                        inv.RemoveItemsOfType(value, PhysicalFuelObject, false);
                        Inventory.AddItems(value, PhysicalFuelObject);
                        break;
                    }
                }
            }

            if (quanity > (MyFixedPoint)consumptionAmount)
            {
                Inventory.RemoveItemsOfType((MyFixedPoint)consumptionAmount, PhysicalFuelObject, false);
            }
        }