コード例 #1
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            try
            {
                npcCrewBlock = Entity as IMyUpgradeModule;
                //MyAPIGateway.Utilities.ShowMessage("DEBUG", "Init Ran");
                NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
                npcCrewBlock.CubeGrid.ColorBlocks(npcCrewBlock.SlimBlock.Position, npcCrewBlock.SlimBlock.Position, Color.Red.ColorToHSV());

                NPCCrewConfig loadconfig = NPCCrewConfig.LoadConfigFile();
                forceColor = loadconfig.forceColor;

                if (Sink == null)
                {
                    Sink = new MyResourceSinkComponent();
                }
                ResourceInfo = new MyResourceSinkInfo()
                {
                    ResourceTypeId    = GId,
                    MaxRequiredInput  = 0.02f,
                    RequiredInputFunc = () => Power
                };
                Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo);
                Sink.AddType(ref ResourceInfo);
                Entity.Components.Add(Sink);
                Sink.Update();
            }
            catch (Exception e)
            {
                MyVisualScriptLogicProvider.ShowNotificationToAll("Init Error" + e, 10000, "Red");
            }
        }
コード例 #2
0
        public override void Close()
        {
            try
            {
                if (Session.Instance.Modulators.Contains(this))
                {
                    Session.Instance.Modulators.Remove(this);
                }
                if (ShieldComp?.Modulator == this)
                {
                    ShieldComp.Modulator = null;
                }
                ShieldComp = null;

                if (ModulatorComp?.Modulator == this)
                {
                    ModulatorComp.Modulator = null;
                }
                ModulatorComp = null;

                if (Sink != null)
                {
                    ResourceInfo = new MyResourceSinkInfo
                    {
                        ResourceTypeId    = _gId,
                        MaxRequiredInput  = 0f,
                        RequiredInputFunc = null
                    };
                    Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo);
                    Sink = null;
                }
            }
            catch (Exception ex) { Log.Line($"Exception in Close: {ex}"); }
            base.Close();
        }
コード例 #3
0
        public void AddType(ref MyResourceSinkInfo sinkData)
        {
            if (m_resourceIds.Contains(sinkData.ResourceTypeId) || m_resourceTypeToIndex.ContainsKey(sinkData.ResourceTypeId))
            {
                return;
            }

            var newDataPerType = new PerTypeData[m_resourceIds.Count + 1];

            for (int dataIndex = 0; dataIndex < m_dataPerType.Length; ++dataIndex)
            {
                newDataPerType[dataIndex] = m_dataPerType[dataIndex];
            }
            m_dataPerType = newDataPerType;
            m_dataPerType[m_dataPerType.Length - 1] = new PerTypeData
            {
                MaxRequiredInput  = sinkData.MaxRequiredInput,
                RequiredInputFunc = sinkData.RequiredInputFunc
            };
            m_resourceIds.Add(sinkData.ResourceTypeId);
            m_resourceTypeToIndex.Add(sinkData.ResourceTypeId, m_dataPerType.Length - 1);
            if (OnAddType != null)
            {
                OnAddType(this, sinkData.ResourceTypeId);
            }
        }
コード例 #4
0
        public override void UpdateOnceBeforeFrame()
        {
            if (!IsReal((MyCubeBlock)block) || !MyAPIGateway.Multiplayer.IsServer) // ignore projected and other non-physical grids
            {
                return;
            }



            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;


            myNotUsedRespawn = block.Components.Get <MyEntityRespawnComponentBase>();
            _respawnAllowed  = myNotUsedRespawn != null;

            // setup resources
            sink = Entity.Components.Get <MyResourceSinkComponent>();


            var fleshSink = new MyResourceSinkInfo()
            {
                ResourceTypeId    = Gasses.Flesh, // people are flesh
                MaxRequiredInput  = MaxFillRate,
                RequiredInputFunc = GetFleshRequired
            };

            sink.AddType(ref fleshSink);
            sink.Update();
        }
コード例 #5
0
        public NaniteOreDetector(IMyFunctionalBlock entity)
        {
            m_block             = entity as IMyOreDetector;
            m_lastUpdate        = DateTime.MinValue;
            m_scanStart         = DateTime.MinValue;
            m_scanEnd           = DateTime.MinValue;
            m_lock              = new FastResourceLock();
            m_oreListCache      = new StringBuilder();
            m_detectorState     = DetectorStates.Disabled;
            m_lastDetectorState = DetectorStates.Disabled;

            m_block.Components.TryGet(out Sink);
            ResourceInfo = new MyResourceSinkInfo()
            {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = 0f,
                RequiredInputFunc = () => (m_block.Enabled && m_block.IsFunctional) ? _power : 0f
            };
            Sink.RemoveType(ref ResourceInfo.ResourceTypeId);
            Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo);
            Sink.AddType(ref ResourceInfo);

            m_effects.Add(new OreDetectorEffect((MyCubeBlock)m_block));

            if (!NaniteConstructionManager.OreDetectors.ContainsKey(entity.EntityId))
            {
                NaniteConstructionManager.OreDetectors.Add(entity.EntityId, this);
            }
        }
コード例 #6
0
        private void SinkChanged(MyResourceSinkComponent old, MyResourceSinkComponent @new)
        {
            if (old != null)
            {
                foreach (var key in old.AcceptedResources)
                {
                    old.SetMaxRequiredInputByType(key, 0);
                    old.SetRequiredInputFuncByType(key, () => 0);
                }

                RemoveDelegate(ref old.CurrentInputChanged, OnInputChanged);
            }

            if (@new == null)
            {
                return;
            }
            foreach (var kv in _sinks)
            {
                var info = new MyResourceSinkInfo()
                {
                    MaxRequiredInput  = kv.Value.CalculateMaxInput(),
                    RequiredInputFunc = kv.Value.DelCalculateRequiredInput,
                    ResourceTypeId    = kv.Key
                };
                @new.AddType(ref info);
                @new.SetMaxRequiredInputByType(kv.Key, kv.Value.CalculateMaxInput());
                @new.SetRequiredInputFuncByType(kv.Key, kv.Value.DelCalculateRequiredInput);
            }

            AddDelegate(ref @new.CurrentInputChanged, OnInputChanged);
        }
コード例 #7
0
        private void PowerPreInit()
        {
            try
            {
                if (Sink == null)
                {
                    Sink = new MyResourceSinkComponent();
                }

                ResourceInfo = new MyResourceSinkInfo()
                {
                    ResourceTypeId    = _gId,
                    MaxRequiredInput  = 0.02f,
                    RequiredInputFunc = () => Power
                };

                Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo);
                Sink.AddType(ref ResourceInfo);
                Entity.Components.Add(Sink);
            }
            catch (Exception ex)
            {
                Log.Line($"Exception in PowerPreInit: {ex}");
            }
        }
コード例 #8
0
 public void Init(MyStringHash group, MyResourceSinkInfo sinkData)
 {
     MyUtils.Init(ref m_singleHelperList);
     m_singleHelperList.Add(sinkData);
     Init(group, m_singleHelperList);
     m_singleHelperList.Clear();
 }
コード例 #9
0
        internal void CloseComps(MyEntity ent)
        {
            try
            {
                var cube = (MyCubeBlock)ent;
                cube.OnClose -= CloseComps;
                if (cube.CubeGrid.IsPreview)
                {
                    return;
                }

                CoreComponent comp;
                if (!cube.Components.TryGet(out comp))
                {
                    return;
                }

                for (int i = 0; i < comp.Monitors.Length; i++)
                {
                    comp.Monitors[i].Clear();
                    comp.Monitors[i] = null;
                }

                //IdToCompMap.Remove(comp.MyCube.EntityId);

                if (comp.Platform.State == CorePlatform.PlatformState.Ready)
                {
                    comp.GeneralWeaponCleanUp();
                    comp.StopAllSounds();
                    comp.CleanCompParticles();
                    comp.CleanCompSounds();
                    comp.Platform.RemoveParts(comp);
                }

                if (comp.Ai != null)
                {
                    Log.Line("Comp still had AI on close");
                    comp.Ai = null;
                }

                if (comp.Registered)
                {
                    Log.Line($"comp still registered");
                    comp.RegisterEvents(false);
                }

                PlatFormPool.Return(comp.Platform);
                comp.Platform = null;
                var sinkInfo = new MyResourceSinkInfo()
                {
                    ResourceTypeId    = comp.GId,
                    MaxRequiredInput  = 0f,
                    RequiredInputFunc = null,
                };

                comp.MyCube.ResourceSink.Init(MyStringHash.GetOrCompute("Charging"), sinkInfo);
            }
            catch (Exception ex) { Log.Line($"Exception in DelayedCompClose: {ex}"); }
        }
コード例 #10
0
        private int InitializeType(MyDefinitionId fuelType)
        {
            m_dataByFuelType.Add(new FuelTypeData
            {
                ThrustsByDirection         = new Dictionary <Vector3I, HashSet <MyEntity> >(6, m_directionComparer),
                MaxRequirementsByDirection = new Dictionary <Vector3I, float>(6, m_directionComparer),
                FuelConversionDirty        = true,
                CurrentPowerFromFuel       = 0f,
                CurrentRequiredFuelInput   = 0f,
                Efficiency    = 0f,
                EnergyDensity = 0f,
            });

            int typeIndex = m_dataByFuelType.Count - 1;

            m_fuelTypeToIndex.Add(fuelType, typeIndex);
            m_fuelTypes.Add(fuelType);

            foreach (var direction in Base6Directions.IntDirections)
            {
                m_dataByFuelType[typeIndex].ThrustsByDirection[direction] = new HashSet <MyEntity>();
            }

            var sinkData = new MyResourceSinkInfo
            {
                ResourceTypeId    = fuelType,
                MaxRequiredInput  = 0,
                RequiredInputFunc = () => RequiredFuelInput(ref fuelType)
            };

            if (m_fuelTypes.Count == 1)
            {
                ResourceSink.Init(MyStringHash.GetOrCompute("Thrust"), sinkData);
                ResourceSink.IsPoweredChanged    += Sink_IsPoweredChanged;
                ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged;

                var cubeGrid = Container.Entity as MyCubeGrid;
                if (cubeGrid != null)
                {
                    var gridSystems = cubeGrid.GridSystems;
                    if (gridSystems != null)
                    {
                        if (gridSystems.ResourceDistributor != null)
                        {
                            gridSystems.ResourceDistributor.AddSink(ResourceSink);
                        }
                    }
                }
            }
            else
            {
                ResourceSink.AddType(ref sinkData);
            }

            return(typeIndex);
        }
コード例 #11
0
 public RadarPowerModule(MyRadar Radar) : base(Radar)
 {
     if (!RadarBlock.TryGetComponent(out MyRadarPowerSink))
     {
         MyRadarPowerSink = new MyResourceSinkComponent();
         MyResourceSinkInfo info = new MyResourceSinkInfo();
         info.ResourceTypeId = Electricity;
         MyRadarPowerSink.AddType(ref info);
         RadarBlock.Components.Add(MyRadarPowerSink);
     }
 }
コード例 #12
0
 public void AppendSinkData(List <MyResourceSinkInfo> sinkData)
 {
     for (int i = 0; i < this.m_storedGases.Length; i++)
     {
         int captureIndex        = i;
         MyResourceSinkInfo item = new MyResourceSinkInfo {
             ResourceTypeId    = this.m_storedGases[i].Id,
             MaxRequiredInput  = this.m_storedGases[i].Throughput,
             RequiredInputFunc = () => this.Sink_ComputeRequiredGas(this.m_storedGases[captureIndex])
         };
         sinkData.Add(item);
     }
 }
コード例 #13
0
        private void InitPowerSystem()
        {
            m_powerConsumption = MaxHeat * 0.001f;
            var powerSystem = new MyResourceSinkComponent();
            var sinkInfo    = new MyResourceSinkInfo();

            sinkInfo.ResourceTypeId    = m_electricityDefinition;
            sinkInfo.MaxRequiredInput  = m_powerConsumption;
            sinkInfo.RequiredInputFunc = new Func <float>(RequiredInputFunc);
            powerSystem.AddType(ref sinkInfo);
            Entity.Components.Add <MyResourceSinkComponent>(powerSystem);
            m_resourceSink = Entity.Components.Get <MyResourceSinkComponent>();
        }
コード例 #14
0
        public override void Close()
        {
            try
            {
                base.Close();
                if (!_allInited)
                {
                    return;
                }
                if (Session.Enforced.Debug >= 3)
                {
                    Log.Line($"Close: {ShieldMode} - ShieldId [{Shield.EntityId}]");
                }

                if (ShieldComp?.DefenseShields == this)
                {
                    OfflineShield(true, false, true);
                    ShieldComp.DefenseShields = null;
                }

                if (Session.Instance.Controllers.Contains(this))
                {
                    Session.Instance.Controllers.Remove(this);
                }
                bool value1;

                if (Session.Instance.FunctionalShields.ContainsKey(this))
                {
                    Session.Instance.FunctionalShields.TryRemove(this, out value1);
                }

                Icosphere = null;
                InitEntities(false);
                MyAPIGateway.Session.OxygenProviderSystem.RemoveOxygenGenerator(_ellipsoidOxyProvider);
                if (_sink != null)
                {
                    _resourceInfo = new MyResourceSinkInfo
                    {
                        ResourceTypeId    = GId,
                        MaxRequiredInput  = 0f,
                        RequiredInputFunc = null
                    };
                    _sink.Init(MyStringHash.GetOrCompute("Defense"), _resourceInfo);
                    _sink = null;
                }

                ShieldComp = null;
            }
            catch (Exception ex) { Log.Line($"Exception in Close: {ex}"); }
        }
コード例 #15
0
        void SetPowerSink()
        {
            sink = Entity.Components.Get <MyResourceSinkComponent>();
            sink.SetRequiredInputFuncByType(resourceId, () => GetPowerInput());
            MyResourceSinkInfo resourceInfo = new MyResourceSinkInfo()
            {
                ResourceTypeId    = resourceId,
                MaxRequiredInput  = turret == null ? _idlePowerDrawBase : _idlePowerDrawMax,
                RequiredInputFunc = () => GetPowerInput()
            };

            sink.RemoveType(ref resourceInfo.ResourceTypeId);
            sink.Init(MyStringHash.GetOrCompute("Defense"), resourceInfo); //sink.Init(MyStringHash.GetOrCompute("Defense"), turret == null ? _idlePowerDrawBase : _idlePowerDrawMax, () => GetPowerInput());
            sink.AddType(ref resourceInfo);
        }
コード例 #16
0
        public override void Close()
        {
            try
            {
                base.Close();
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"Close: {EmitterMode} - EmitterId [{Entity.EntityId}]");
                }
                if (Session.Instance.Emitters.Contains(this))
                {
                    Session.Instance.Emitters.Remove(this);
                }

                if (ShieldComp?.StationEmitter == this)
                {
                    if ((int)EmitterMode == ShieldComp.EmitterMode)
                    {
                        ShieldComp.EmitterLos   = false;
                        ShieldComp.EmitterEvent = true;
                    }
                    ShieldComp.StationEmitter = null;
                }
                else if (ShieldComp?.ShipEmitter == this)
                {
                    if ((int)EmitterMode == ShieldComp.EmitterMode)
                    {
                        ShieldComp.EmitterLos   = false;
                        ShieldComp.EmitterEvent = true;
                    }
                    ShieldComp.ShipEmitter = null;
                }
                ShieldComp = null;
                if (Sink != null)
                {
                    ResourceInfo = new MyResourceSinkInfo
                    {
                        ResourceTypeId    = _gId,
                        MaxRequiredInput  = 0f,
                        RequiredInputFunc = null
                    };
                    Sink.Init(MyStringHash.GetOrCompute("Utility"), ResourceInfo);
                    Sink = null;
                }
            }
            catch (Exception ex) { Log.Line($"Exception in Close: {ex}"); }
        }
コード例 #17
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate   |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            _objectBuilder = objectBuilder;

            hyperDriveBlock = Entity as IMyUpgradeModule;

            if (!hyperDriveBlock.Components.TryGet <MyResourceSinkComponent>(out ResourceSink))
            {
                ResourceSink = new MyResourceSinkComponent();
                var sinkInfo = new MyResourceSinkInfo();
                sinkInfo.ResourceTypeId = _electricity;
                ResourceSink.AddType(ref sinkInfo);

                hyperDriveBlock.Components.Add(ResourceSink);
            }
        }
コード例 #18
0
        public void AddType(ref MyResourceSinkInfo sinkData)
        {
            var newDataPerType = new PerTypeData[m_dataPerType.Length + 1];

            for (int dataIndex = 0; dataIndex < m_dataPerType.Length; ++dataIndex)
            {
                newDataPerType[dataIndex] = m_dataPerType[dataIndex];
            }
            m_dataPerType = newDataPerType;
            m_dataPerType[m_dataPerType.Length - 1] = new PerTypeData
            {
                MaxRequiredInput  = sinkData.MaxRequiredInput,
                RequiredInputFunc = sinkData.RequiredInputFunc
            };
            m_resourceIds.Add(sinkData.ResourceTypeId);
            m_resourceTypeToIndex.Add(sinkData.ResourceTypeId, m_dataPerType.Length - 1);
            OnAddType(this);
        }
コード例 #19
0
        private void SinkSetup()
        {
            hydrogenSink = Entity.Components.Get <MyResourceSinkComponent>();
            var maxHydrogenRequired = hydrogenSink.MaxRequiredInputByType(hydrogenDef);
            var maxOxygenRequired   = maxHydrogenRequired / 2;

            sinkInfo = new MyResourceSinkInfo()
            {
                ResourceTypeId    = oxygenDef,
                MaxRequiredInput  = maxOxygenRequired,
                RequiredInputFunc = GetOxygenRequired
            };

            sink = hydrogenSink;

            sink.AddType(ref sinkInfo);

            sink.Update();
        }
コード例 #20
0
ファイル: ShieldInit.cs プロジェクト: wellstat/DefenseShields
 private void PowerPreInit()
 {
     try
     {
         if (_sink == null)
         {
             _sink = new MyResourceSinkComponent();
         }
         _resourceInfo = new MyResourceSinkInfo()
         {
             ResourceTypeId    = GId,
             MaxRequiredInput  = 0f,
             RequiredInputFunc = () => _power
         };
         _sink.Init(MyStringHash.GetOrCompute("Defense"), _resourceInfo);
         _sink.AddType(ref _resourceInfo);
         Entity.Components.Add(_sink);
     }
     catch (Exception ex) { Log.Line($"Exception in PowerPreInit: {ex}"); }
 }
コード例 #21
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            if (_isInit)
            {
                return;
            }
            m_block = Container.Entity as IMyTerminalBlock;
            m_block.AppendingCustomInfo += appendCustomInfo;
            _imyUM = Entity as IMyUpgradeModule;
            if (!_imyUM.Components.TryGet(out _sink))
            {
                _sink = new MyResourceSinkComponent();
                MyResourceSinkInfo info = new MyResourceSinkInfo();
                info.ResourceTypeId = Electricity;
                _sink.AddType(ref info);
                _imyUM.Components.Add(_sink);
            }
            this.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
//	deprecated	Container.Entity.NeedsUpdate |=  MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
コード例 #22
0
        private PerTypeData Type(MyDefinitionId id)
        {
            PerTypeData res;

            if (!_sinks.TryGetValue(id, out res))
            {
                _sinks.Add(id, res = new PerTypeData());
                var root = _resourceSink.Value;
                if (root != null)
                {
                    var info = new MyResourceSinkInfo()
                    {
                        MaxRequiredInput  = res.CalculateMaxInput(),
                        RequiredInputFunc = res.DelCalculateRequiredInput,
                        ResourceTypeId    = id
                    };
                    root.AddType(ref info);
                }
            }

            return(res);
        }
コード例 #23
0
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     if (_isInit)
     {
         return;
     }
     Container.Entity.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
     _tblock = Container.Entity as IMyTerminalBlock;
     _tblock.AppendingCustomInfo += appendCustomInfo;
     _ublock   = Entity as IMyUpgradeModule;
     _maxrange = 1000f;
     if (!_ublock.Components.TryGet(out _sink))
     {
         _sink = new MyResourceSinkComponent();
         MyResourceSinkInfo info = new MyResourceSinkInfo();
         info.ResourceTypeId = Electricity;
         _sink.AddType(ref info);
         _ublock.Components.Add(_sink);
     }
     Shields.Add(Entity.EntityId, this);
     _isInit = true;
 }
コード例 #24
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
                };
            }
コード例 #25
0
ファイル: PlasmaGun.cs プロジェクト: LashUp/The-Great-Filter
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_objectBuilder = objectBuilder;

            Entity.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME;

            MyResourceSinkInfo ElectricityResourceSinkInfo = new MyResourceSinkInfo {
                ResourceTypeId    = ElectricityDefinitionsId,
                MaxRequiredInput  = MaxElectricityConsumption,
                RequiredInputFunc = OnUpdateElectricityUsage
            };

            MyResourceSinkComponent ResourceSink = new MyResourceSinkComponent();

            ResourceSink.Init(MyStringHash.GetOrCompute("Factory"), ElectricityResourceSinkInfo);

            Entity.Components.Add <MyResourceSinkComponent>(ResourceSink);

            ResourceSink.Update();

            m_resourceSink = ResourceSink;

            /*
             * // Because a Cargo Container does not produce anything, we need to create a new Resource Source for it and attach it to the block
             * MyResourceSourceComponent ResourceSource = new MyResourceSourceComponent();
             * Entity.Components.Add<MyResourceSourceComponent>(ResourceSource);
             *
             * // We let it produce OxyHydrogen gas with a defined (changed by us later) maximum of 1200MW
             * MyResourceSourceInfo oxyHydrogenResourceSourceInfo = new MyResourceSourceInfo() {ResourceTypeId = ElectricityDefinitionsId, DefinedOutput = 0.0001f, IsInfiniteCapacity = true, ProductionToCapacityMultiplier = 60*60};
             * ResourceSource.Init(MyStringHash.GetOrCompute("Battery"), oxyHydrogenResourceSourceInfo);
             * ResourceSource.SetMaxOutputByType(ElectricityDefinitionsId, 0.00005f);
             * ResourceSource.SetProductionEnabledByType(ElectricityDefinitionsId, true);
             *
             * m_resourceSource = ResourceSource;
             */
        }
コード例 #26
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);
        }
コード例 #27
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();
        }
コード例 #28
0
 private void FillSinkInfo()
 {
     OxygenSinkInfo = new MyResourceSinkInfo {
         ResourceTypeId = m_oxygenGasId, MaxRequiredInput = BlockDefinition.VentilationCapacityPerSecond, RequiredInputFunc = Sink_ComputeRequiredGas
     };
 }
コード例 #29
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);
        }