示例#1
0
        public long GetCurrentVolumeInPercent()
        {
            currentVolume = m_block.GetInventory(0).CurrentVolume.RawValue;
            maxVolume     = m_block.GetInventory(0).MaxVolume.RawValue;

            if (maxVolume > 0)
            {
                return(currentVolume * 100 / maxVolume);
            }

            return(0);
        }
示例#2
0
        public override void UpdateBeforeSimulation()
        {
            if (MyAPIGateway.Utilities.IsDedicated || MyAPIGateway.Session == null)
            {
                return;
            }

            IMyCockpit cockpit = MyAPIGateway.Session.Player?.Controller?.ControlledEntity?.Entity as IMyCockpit;

            if (cockpit == null)
            {
                JustGotInCockpit = true;
                return;
            }

            if (JustGotInCockpit)
            {
                JustGotInCockpit = false;
                slims.Clear();
                cockpit.CubeGrid.GetBlocks(slims, b => b.FatBlock != null && !b.FatBlock.BlockDefinition.IsNull() && FuelStorage.Contains(b.FatBlock.BlockDefinition.SubtypeId));
            }

            int          blockCount      = 0;
            double       consumptionRate = 0;
            MyFixedPoint total           = 0;
            MyFixedPoint current         = 0;

            foreach (IMySlimBlock slim in slims)
            {
                IMyCubeBlock block   = slim.FatBlock;
                IMyReactor   reactor = block as IMyReactor;
                IMyInventory inv     = block.GetInventory(0);
                if (!block.IsFunctional || !block.IsWorking || inv == null)
                {
                    continue;
                }

                switch (block.BlockDefinition.SubtypeId)
                {
                case "V8Engine":
                    consumptionRate += 0.06666666666666666666666666666667d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;

                case "V8EngineTurbo":
                    consumptionRate += 0.11666666666666666666666666666667d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;

                case "hmdieselgenerator3_Large":
                    consumptionRate += 0.05d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;

                case "hmdieselgenerator1_Large":
                    consumptionRate += 0.00833333333333333333333333333333d * (reactor.CurrentOutput / reactor.MaxOutput);
                    break;
                }

                blockCount++;
                total   += inv.MaxVolume;
                current += inv.CurrentVolume;
            }

            if (total > 0 && consumptionRate > 0)
            {
                double percent = (((double)current * 1000d) / ((double)total * 1000d) * 100d);
                double tick    = (((double)current * 1000d) / consumptionRate);

                MyAPIGateway.Utilities.ShowNotification($"Fuel: {percent.ToString("n0")}% {TimeSpan.FromMilliseconds((tick / 60d) * 1000d).ToString("g").Split('.')[0]}", 1);
            }
        }