Exemplo n.º 1
0
 public void AppendSourceData(List <MyResourceSourceInfo> sourceData)
 {
     for (int i = 0; i < this.m_storedGases.Length; i++)
     {
         MyResourceSourceInfo item = new MyResourceSourceInfo {
             ResourceTypeId = this.m_storedGases[i].Id,
             DefinedOutput  = this.m_storedGases[i].Throughput,
             ProductionToCapacityMultiplier = 1f,
             IsInfiniteCapacity             = false
         };
         sourceData.Add(item);
     }
 }
Exemplo n.º 2
0
        public void AddResourceSourceComponent()
        {
            MyResourceSourceComponent source = new MyResourceSourceComponent();
            MyResourceSourceInfo      info   = new MyResourceSourceInfo();

            info.ResourceTypeId = defId;
            info.DefinedOutput  = maxOutput;
            source.Init(MyStringHash.GetOrCompute("Battery"), info);
            source.Enabled = true;
            source.SetMaxOutput(maxOutput);

            cockpit.Components.Add(source);
        }
Exemplo n.º 3
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            MyResourceSourceInfo item = new MyResourceSourceInfo {
                ResourceTypeId = MyResourceDistributorComponent.ElectricityId,
                DefinedOutput  = this.BlockDefinition.MaxPowerOutput,
                ProductionToCapacityMultiplier = 3600f
            };
            List <MyResourceSourceInfo> list1 = new List <MyResourceSourceInfo>();

            list1.Add(item);
            List <MyResourceSourceInfo> sourceResourceData = list1;

            this.SourceComp.Init(this.BlockDefinition.ResourceSourceGroup, sourceResourceData);
            this.SourceComp.HasCapacityRemainingChanged += (id, source) => base.UpdateIsWorking();
            this.SourceComp.ProductionEnabledChanged    += new MyResourceCapacityRemainingChangedDelegate(this.Source_ProductionEnabledChanged);
            MyObjectBuilder_BatteryBlock block = (MyObjectBuilder_BatteryBlock)objectBuilder;

            this.SourceComp.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, block.ProducerEnabled);
            this.MaxStoredPower = this.BlockDefinition.MaxStoredPower;
            base.ResourceSink.Init(this.BlockDefinition.ResourceSinkGroup, this.BlockDefinition.RequiredPowerInput, new Func <float>(this.Sink_ComputeRequiredPower));
            base.Init(objectBuilder, cubeGrid);
            this.CurrentStoredPower = (block.CurrentStoredPower < 0f) ? (this.BlockDefinition.InitialStoredPowerRatio * this.BlockDefinition.MaxStoredPower) : block.CurrentStoredPower;
            if (Sync.IsServer)
            {
                this.m_storedPower.Value = this.CurrentStoredPower;
            }
            if (block.OnlyDischargeEnabled)
            {
                this.m_chargeMode.SetLocalValue(Sandbox.ModAPI.Ingame.ChargeMode.Discharge);
            }
            else
            {
                this.m_chargeMode.SetLocalValue((Sandbox.ModAPI.Ingame.ChargeMode)block.ChargeMode);
            }
            this.UpdateMaxOutputAndEmissivity();
            this.UpdateText();
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            base.IsWorkingChanged += new Action <MyCubeBlock>(this.MyBatteryBlock_IsWorkingChanged);
            base.NeedsUpdate      |= MyEntityUpdateEnum.EACH_100TH_FRAME;
            this.m_lastUpdateTime  = MySession.Static.GameplayFrameCounter;
            if (base.IsWorking)
            {
                this.OnStartWorking();
            }
            base.ResourceSink.Update();
        }
Exemplo n.º 4
0
            public SubTankImpl(TankComponent tank, ISubTankDef def)
            {
                Tank = tank;

                StoresId = def.StoresId;
                Capacity = def.Capacity;
                MaxRate  = def.MaxRate;
                Provide  = def.Provide;
                Take     = def.Take;
                Provide  = def.Provide;

                sinkInfo = new MyResourceSinkInfo()
                {
                    ResourceTypeId    = StoresId,
                    MaxRequiredInput  = MaxRate,
                    RequiredInputFunc = GetRequired
                };

                sourceInfo = new MyResourceSourceInfo()
                {
                    ResourceTypeId = StoresId,
                    DefinedOutput  = MaxRate
                };
            }
Exemplo n.º 5
0
        public void Init(MyObjectBuilder_Battery builder, List <MyResourceSinkInfo> additionalSinks = null, List <MyResourceSourceInfo> additionalSources = null)
        {
            var defaultSinkInfo = new MyResourceSinkInfo
            {
                MaxRequiredInput  = MyEnergyConstants.BATTERY_MAX_POWER_INPUT,
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                RequiredInputFunc = () => (ResourceSource.RemainingCapacity < MyEnergyConstants.BATTERY_MAX_CAPACITY) ? MyEnergyConstants.BATTERY_MAX_POWER_INPUT : 0f,
            };

            if (additionalSinks != null)
            {
                additionalSinks.Insert(0, defaultSinkInfo);
                ResourceSink.Init(m_resourceSinkGroup, additionalSinks);
            }
            else
            {
                ResourceSink.Init(m_resourceSinkGroup, defaultSinkInfo);
            }

            ResourceSink.TemporaryConnectedEntity = m_owner;

            var defaultSourceInfo = new MyResourceSourceInfo
            {
                ResourceTypeId = MyResourceDistributorComponent.ElectricityId,
                DefinedOutput  = MyEnergyConstants.BATTERY_MAX_POWER_OUTPUT, // TODO: Load max output from definitions
                ProductionToCapacityMultiplier = 60 * 60
            };

            if (additionalSources != null)
            {
                additionalSources.Insert(0, defaultSourceInfo);
                ResourceSource.Init(m_resourceSourceGroup, additionalSources);
            }
            else
            {
                ResourceSource.Init(m_resourceSourceGroup, defaultSourceInfo);
            }

            ResourceSource.TemporaryConnectedEntity = m_owner;
            m_lastUpdateTime = MySession.Static.GameplayFrameCounter;

            if (builder == null)
            {
                ResourceSource.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, true);
                ResourceSource.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, MyEnergyConstants.BATTERY_MAX_CAPACITY);
                ResourceSink.Update();
                return;
            }

            ResourceSource.SetProductionEnabledByType(MyResourceDistributorComponent.ElectricityId, builder.ProducerEnabled);
            if (MySession.Static.SurvivalMode)
            {
                ResourceSource.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, MathHelper.Clamp(builder.CurrentCapacity, 0f, MyEnergyConstants.BATTERY_MAX_CAPACITY));
            }
            else
            {
                ResourceSource.SetRemainingCapacityByType(MyResourceDistributorComponent.ElectricityId, MyEnergyConstants.BATTERY_MAX_CAPACITY);
            }

            ResourceSink.Update();
        }
Exemplo n.º 6
0
        public override unsafe void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.SyncFlag = true;
            List <MyResourceSourceInfo> sourceResourceData = new List <MyResourceSourceInfo>();

            foreach (MyOxygenGeneratorDefinition.MyGasGeneratorResourceInfo info in this.BlockDefinition.ProducedGases)
            {
                MyResourceSourceInfo *infoPtr1;
                MyResourceSourceInfo  item = new MyResourceSourceInfo {
                    ResourceTypeId = info.Id
                };
                infoPtr1->DefinedOutput = (this.BlockDefinition.IceConsumptionPerSecond * info.IceToGasRatio) * (MySession.Static.CreativeMode ? 10f : 1f);
                infoPtr1 = (MyResourceSourceInfo *)ref item;
                item.ProductionToCapacityMultiplier = 1f;
                sourceResourceData.Add(item);
            }
            this.SourceComp.Init(this.BlockDefinition.ResourceSourceGroup, sourceResourceData);
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_OxygenGenerator generator = objectBuilder as MyObjectBuilder_OxygenGenerator;

            this.InitializeConveyorEndpoint();
            this.m_useConveyorSystem.SetLocalValue(generator.UseConveyorSystem);
            base.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME;
            MyInventory component = this.GetInventory(0);

            if (component != null)
            {
                component.Constraint = this.BlockDefinition.InputInventoryConstraint;
            }
            else
            {
                component = new MyInventory(this.BlockDefinition.InventoryMaxVolume, this.BlockDefinition.InventorySize, MyInventoryFlags.CanReceive)
                {
                    Constraint = this.BlockDefinition.InputInventoryConstraint
                };
                base.Components.Add <MyInventoryBase>(component);
            }
            this.m_oreConstraint = new MyInventoryConstraint(component.Constraint.Description, component.Constraint.Icon, component.Constraint.IsWhitelist);
            foreach (MyDefinitionId id in component.Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject))
                {
                    this.m_oreConstraint.Add(id);
                }
            }
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                base.FixSingleInventory();
            }
            if (component != null)
            {
                component.Init(generator.Inventory);
            }
            this.AutoRefill         = generator.AutoRefill;
            this.SourceComp.Enabled = base.Enabled;
            if (Sync.IsServer)
            {
                this.SourceComp.OutputChanged += new MyResourceOutputChangedDelegate(this.Source_OutputChanged);
            }
            float num = this.IceAmount();

            foreach (MyDefinitionId id2 in this.SourceComp.ResourceTypes)
            {
                MyDefinitionId gasId = id2;
                this.m_sourceComp.SetRemainingCapacityByType(id2, (float)this.IceToGas(ref gasId, (double)num));
            }
            MyResourceSinkInfo sinkData = new MyResourceSinkInfo {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = this.BlockDefinition.OperationalPowerConsumption,
                RequiredInputFunc = new Func <float>(this.ComputeRequiredPower)
            };

            base.ResourceSink.Init(this.BlockDefinition.ResourceSinkGroup, sinkData);
            base.ResourceSink.IsPoweredChanged += new Action(this.PowerReceiver_IsPoweredChanged);
            base.ResourceSink.Update();
            this.UpdateText();
            base.AddDebugRenderComponent(new MyDebugRenderComponentDrawConveyorEndpoint(this.m_conveyorEndpoint));
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            base.IsWorkingChanged += new Action <MyCubeBlock>(this.MyGasGenerator_IsWorkingChanged);
        }
Exemplo n.º 7
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_OxygenTank tank = (MyObjectBuilder_OxygenTank)objectBuilder;

            this.InitializeConveyorEndpoint();
            if (Sync.IsServer)
            {
                base.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_FRAME;
            }
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                base.FixSingleInventory();
                if (this.GetInventory(0) != null)
                {
                    this.GetInventory(0).Constraint = this.BlockDefinition.InputInventoryConstraint;
                }
            }
            MyInventory component = this.GetInventory(0);

            if (component == null)
            {
                component = new MyInventory(this.BlockDefinition.InventoryMaxVolume, this.BlockDefinition.InventorySize, MyInventoryFlags.CanReceive)
                {
                    Constraint = this.BlockDefinition.InputInventoryConstraint
                };
                base.Components.Add <MyInventoryBase>(component);
                component.Init(tank.Inventory);
            }
            component.ContentsChanged += new Action <MyInventoryBase>(this.MyGasTank_ContentsChanged);
            this.m_autoRefill.SetLocalValue(tank.AutoRefill);
            MyResourceSourceInfo item = new MyResourceSourceInfo {
                ResourceTypeId = this.BlockDefinition.StoredGasId,
                DefinedOutput  = 0.05f * this.BlockDefinition.Capacity
            };
            List <MyResourceSourceInfo> list1 = new List <MyResourceSourceInfo>();

            list1.Add(item);
            List <MyResourceSourceInfo> sourceResourceData = list1;

            this.SourceComp.Init(this.BlockDefinition.ResourceSourceGroup, sourceResourceData);
            this.SourceComp.OutputChanged += new MyResourceOutputChangedDelegate(this.Source_OutputChanged);
            this.SourceComp.Enabled        = base.Enabled;
            this.IsStockpiling             = tank.IsStockpiling;
            MyResourceSinkInfo info2 = new MyResourceSinkInfo {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = this.BlockDefinition.OperationalPowerConsumption,
                RequiredInputFunc = new Func <float>(this.ComputeRequiredPower)
            };
            List <MyResourceSinkInfo> list3 = new List <MyResourceSinkInfo>();

            list3.Add(info2);
            info2 = new MyResourceSinkInfo {
                ResourceTypeId    = this.BlockDefinition.StoredGasId,
                MaxRequiredInput  = this.Capacity,
                RequiredInputFunc = new Func <float>(this.ComputeRequiredGas)
            };
            list3.Add(info2);
            List <MyResourceSinkInfo> sinkData = list3;

            base.ResourceSink.Init(this.BlockDefinition.ResourceSinkGroup, sinkData);
            base.ResourceSink.IsPoweredChanged    += new Action(this.PowerReceiver_IsPoweredChanged);
            base.ResourceSink.CurrentInputChanged += new MyCurrentResourceInputChangedDelegate(this.Sink_CurrentInputChanged);
            float filledRatio = tank.FilledRatio;

            if (MySession.Static.CreativeMode && (filledRatio == 0f))
            {
                filledRatio = 0.5f;
            }
            this.ChangeFilledRatio((double)MathHelper.Clamp(filledRatio, 0f, 1f), false);
            base.ResourceSink.Update();
            base.AddDebugRenderComponent(new MyDebugRenderComponentDrawConveyorEndpoint(this.m_conveyorEndpoint));
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            base.IsWorkingChanged += new Action <MyCubeBlock>(this.MyOxygenTank_IsWorkingChanged);
        }