public MyAirVent() { ResourceSink = new MyResourceSinkComponent(2); SourceComp = new MyResourceSourceComponent(); m_isDepressurizing.ValueChanged += (x) => SetDepressurizing(); }
public override void UpdateOnceBeforeFrame() { if (!U.IsReal((MyCubeBlock)Block) || !MyAPIGateway.Multiplayer.IsServer) // ignore projected and other non-physical grids { return; } NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; // setup resources Sink = Entity.Components.Get <MyResourceSinkComponent>(); if (Sink == null) { Sink = new MyResourceSinkComponent(); Entity.Components.Add(Sink); } Source = Entity.Components.Get <MyResourceSourceComponent>(); if (Source == null) { Source = new MyResourceSourceComponent(); Entity.Components.Add(Source); } var subTanks = tankDefs.Select(def => new SubTankImpl(this, def)).ToList(); Sink.Init(MyStringHash.GetOrCompute("Factory"), subTanks.Select(x => x.sinkInfo).ToList()); Source.Init(MyStringHash.GetOrCompute("Reactors"), subTanks.Select(x => x.sourceInfo).ToList()); }
public MyBattery(MyCharacter owner) { m_owner = owner; SyncObject = new MySyncBattery(this); ResourceSink = new MyResourceSinkComponent(); ResourceSource = new MyResourceSourceComponent(); }
public MyBatteryBlock() { #if XB1 // XB1_SYNC_NOREFLECTION m_isFull = SyncType.CreateAndAddProp <bool>(); m_onlyRecharge = SyncType.CreateAndAddProp <bool>(); m_onlyDischarge = SyncType.CreateAndAddProp <bool>(); m_semiautoEnabled = SyncType.CreateAndAddProp <bool>(); m_producerEnabled = SyncType.CreateAndAddProp <bool>(); m_storedPower = SyncType.CreateAndAddProp <float>(); #endif // XB1 CreateTerminalControls(); SourceComp = new MyResourceSourceComponent(); ResourceSink = new MyResourceSinkComponent(); m_semiautoEnabled.ValueChanged += (x) => UpdateMaxOutputAndEmissivity(); m_onlyRecharge.ValueChanged += (x) => { if (m_onlyRecharge.Value) { m_onlyDischarge.Value = false; } UpdateMaxOutputAndEmissivity(); }; m_onlyDischarge.ValueChanged += (x) => { if (m_onlyDischarge.Value) { m_onlyRecharge.Value = false; } UpdateMaxOutputAndEmissivity(); }; m_producerEnabled.ValueChanged += (x) => ProducerEnadChanged(); m_storedPower.ValueChanged += (x) => CapacityChanged(); }
public MySolarPanel() { SourceComp = new MyResourceSourceComponent(); m_soundEmitter = new MyEntity3DSoundEmitter(this, true); NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; }
private void SetGasSource(MyResourceSourceComponent characterSourceComponent) { foreach (GasData data in this.m_storedGases) { data.LastOutputTime = MySession.Static.GameplayFrameCounter; if (this.m_characterGasSource != null) { this.m_characterGasSource.SetRemainingCapacityByType(data.Id, 0f); if (Sync.IsServer) { this.m_characterGasSource.OutputChanged -= new MyResourceOutputChangedDelegate(this.Source_CurrentOutputChanged); } } if (characterSourceComponent != null) { characterSourceComponent.SetRemainingCapacityByType(data.Id, data.FillLevel * data.MaxCapacity); characterSourceComponent.SetProductionEnabledByType(data.Id, data.FillLevel > 0f); if (Sync.IsServer) { characterSourceComponent.OutputChanged += new MyResourceOutputChangedDelegate(this.Source_CurrentOutputChanged); } } } this.m_characterGasSource = characterSourceComponent; }
public MyGasTank() { CreateTerminalControls(); SourceComp = new MyResourceSourceComponent(); ResourceSink = new MyResourceSinkComponent(2); }
private void SetGasSource(MyResourceSourceComponent characterSourceComponent) { foreach (var gasInfo in m_storedGases) { gasInfo.LastOutputTime = MySession.Static.GameplayFrameCounter; if (m_characterGasSource != null) { m_characterGasSource.SetRemainingCapacityByType(gasInfo.Id, 0); if (Sync.IsServer) { m_characterGasSource.OutputChanged -= Source_CurrentOutputChanged; } } if (characterSourceComponent != null) { characterSourceComponent.SetRemainingCapacityByType(gasInfo.Id, gasInfo.FillLevel * gasInfo.MaxCapacity); characterSourceComponent.SetProductionEnabledByType(gasInfo.Id, gasInfo.FillLevel > 0); if (Sync.IsServer) { characterSourceComponent.OutputChanged += Source_CurrentOutputChanged; } } } m_characterGasSource = characterSourceComponent; }
public MyAirVent() { CreateTerminalControls(); ResourceSink = new MyResourceSinkComponent(2); SourceComp = new MyResourceSourceComponent(); m_isDepressurizing.ValueChanged += (x) => SetDepressurizing(); }
public MyReactor() { CreateTerminalControls(); SourceComp = new MyResourceSourceComponent(); m_remainingPowerCapacity.ValueChanged += (x) => RemainingCapacityChanged(); m_remainingPowerCapacity.ValidateNever(); }
public virtual void OnAddedToGroup(MyGridLogicalGroupData group) { this.TerminalSystem = group.TerminalSystem; this.ResourceDistributor = group.ResourceDistributor; this.WeaponSystem = group.WeaponSystem; if (string.IsNullOrEmpty(this.ResourceDistributor.DebugName)) { this.ResourceDistributor.DebugName = this.m_cubeGrid.ToString(); } this.m_cubeGrid.OnFatBlockAdded += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved); this.m_cubeGrid.OnFatBlockRemoved += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved); this.ResourceDistributor.AddSink(this.GyroSystem.ResourceSink); this.ResourceDistributor.AddSink(this.ConveyorSystem.ResourceSink); this.ConveyorSystem.ResourceSink.IsPoweredChanged += new Action(this.ResourceDistributor.ConveyorSystem_OnPoweredChanged); foreach (MyBlockGroup group2 in this.m_cubeGrid.BlockGroups) { this.TerminalSystem.AddUpdateGroup(group2, false, false); } this.TerminalSystem.GroupAdded += this.m_terminalSystem_GroupAdded; this.TerminalSystem.GroupRemoved += this.m_terminalSystem_GroupRemoved; foreach (MyCubeBlock block in this.m_cubeGrid.GetFatBlocks()) { if (!block.MarkedForClose) { MyTerminalBlock block2 = block as MyTerminalBlock; if (block2 != null) { this.TerminalSystem.Add(block2); } MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = group.ResourceDistributor; } IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } } MyResourceDistributorComponent resourceDistributor = this.ResourceDistributor; resourceDistributor.OnPowerGenerationChanged = (Action <bool>)Delegate.Combine(resourceDistributor.OnPowerGenerationChanged, new Action <bool>(this.OnPowerGenerationChanged)); this.TerminalSystem.BlockManipulationFinishedFunction(); this.ResourceDistributor.UpdateBeforeSimulation(); }
public MyGasGenerator() { #if XB1 // XB1_SYNC_NOREFLECTION m_useConveyorSystem = SyncType.CreateAndAddProp <bool>(); #endif // XB1 CreateTerminalControls(); SourceComp = new MyResourceSourceComponent(2); ResourceSink = new MyResourceSinkComponent(); }
public MyAirVent() { #if XB1 // XB1_SYNC_NOREFLECTION m_isDepressurizing = SyncType.CreateAndAddProp <bool>(); #endif // XB1 CreateTerminalControls(); ResourceSink = new MyResourceSinkComponent(2); SourceComp = new MyResourceSourceComponent(); m_isDepressurizing.ValueChanged += (x) => SetDepressurizing(); }
public MyReactor() { #if XB1 // XB1_SYNC_NOREFLECTION m_remainingPowerCapacity = SyncType.CreateAndAddProp <float>(); m_useConveyorSystem = SyncType.CreateAndAddProp <bool>(); #endif // XB1 CreateTerminalControls(); SourceComp = new MyResourceSourceComponent(); m_remainingPowerCapacity.ValueChanged += (x) => RemainingCapacityChanged(); m_remainingPowerCapacity.ValidateNever(); }
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); }
public MyBatteryBlock() { SourceComp = new MyResourceSourceComponent(); ResourceSink = new MyResourceSinkComponent(); m_semiautoEnabled.ValueChanged += (x) => UpdateMaxOutputAndEmissivity(); m_onlyRecharge.ValueChanged += (x) => { if (m_onlyRecharge.Value) { m_onlyDischarge.Value = false; } UpdateMaxOutputAndEmissivity(); }; m_onlyDischarge.ValueChanged += (x) => { if (m_onlyDischarge.Value) { m_onlyRecharge.Value = false; } UpdateMaxOutputAndEmissivity(); }; m_producerEnabled.ValueChanged += (x) => ProducerEnadChanged(); m_storedPower.ValueChanged += (x) => CapacityChanged(); }
void GetPowerOutput() { currentPower = 0; maxPower = 0; percentPower = 0; GridTerminalSystem.GetBlocksOfType <IMyBatteryBlock>(null, b => { if (!b.IsCharging) { currentPower += b.CurrentOutput; source = b.Components.Get <MyResourceSourceComponent>(); if (source != null) { maxPower += source.MaxOutputByType(new MyDefinitionId(typeof(MyObjectBuilder_GasProperties), "Electricity")); } } return(false); }); GridTerminalSystem.GetBlocksOfType <IMyReactor>(null, b => { if (b.Enabled) { currentPower += b.CurrentOutput; maxPower += b.MaxOutput; } return(false); }); GridTerminalSystem.GetBlocksOfType <IMySolarPanel>(null, b => { currentPower += b.CurrentOutput; maxPower += b.MaxOutput; return(false); }); //all in MW,m need to change to watts maxPower *= 1000000; currentPower *= 1000000; if (maxPower > 0) { percentPower = (currentPower / maxPower) * 100; } else { percentPower = 100; } }
private void SetGasSource(MyResourceSourceComponent characterSourceComponent) { m_gasOutputTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; foreach (var gasInfo in m_storedGases) { if (m_characterGasSource != null) { m_characterGasSource.SetRemainingCapacityByType(gasInfo.Id, 0); m_characterGasSource.OutputChanged -= Source_CurrentOutputChanged; } if (characterSourceComponent != null) { characterSourceComponent.SetRemainingCapacityByType(gasInfo.Id, gasInfo.FillLevel * gasInfo.MaxCapacity); characterSourceComponent.SetProductionEnabledByType(gasInfo.Id, gasInfo.FillLevel > 0); characterSourceComponent.OutputChanged += Source_CurrentOutputChanged; } } m_characterGasSource = characterSourceComponent; }
private void Source_OutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source) { float timeSinceLastUpdateSeconds = (MySession.Static.GameplayFrameCounter - m_lastOutputUpdateTime) / 1000f * VRage.Game.MyEngineConstants.UPDATE_STEPS_PER_SECOND; m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter; float outputAmount = oldOutput * timeSinceLastUpdateSeconds; m_nextGasTransfer -= outputAmount; }
private void Source_ProductionEnabledChanged(MyDefinitionId changedResourceId, MyResourceSourceComponent source) { Enabled = source.Enabled; UpdateIsWorking(); }
public MyOxygenFarm() { ResourceSink = new MyResourceSinkComponent(); SourceComp = new MyResourceSourceComponent(); }
private void Source_CurrentOutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source) { float timeSinceLastOutputSeconds = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_gasOutputTime) / 1000f; float outputAmount = oldOutput * timeSinceLastOutputSeconds; TransferSuitGas(changedResourceId, 0f, outputAmount); }
private void Source_CurrentOutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source) { int num; if (this.TryGetTypeIndex(ref changedResourceId, out num)) { float num2 = (MySession.Static.GameplayFrameCounter - this.m_storedGases[num].LastOutputTime) * 0.01666667f; this.m_storedGases[num].LastOutputTime = MySession.Static.GameplayFrameCounter; float num3 = oldOutput * num2; GasData data1 = this.m_storedGases[num]; data1.NextGasTransfer -= num3; } }
public virtual void RegisterInSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { MyCubeBlock block1; if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (!(block is MyThrust) && (sink != null)) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = this.ResourceDistributor; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block6 = block as MyTerminalBlock; if (block6 != null) { this.TerminalSystem.Add(block6); } } if ((block == null) || !block.HasInventory) { block1 = null; } else { block1 = block; } MyCubeBlock block2 = block1; if (block2 != null) { this.ConveyorSystem.Add(block2); } IMyConveyorEndpointBlock endpointBlock = block as IMyConveyorEndpointBlock; if (endpointBlock != null) { endpointBlock.InitializeConveyorEndpoint(); this.ConveyorSystem.AddConveyorBlock(endpointBlock); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { segmentBlock.InitializeConveyorSegment(); this.ConveyorSystem.AddSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Register(reflector); } if (block.Components.Contains(typeof(MyDataBroadcaster))) { MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); this.RadioSystem.Register(broadcaster); } if (block.Components.Contains(typeof(MyDataReceiver))) { MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); this.RadioSystem.Register(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Register(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Register(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Register(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Register(camera); } } block.OnRegisteredToGridSystems(); }
private void Source_OutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source) { if (BlockDefinition.ProducedGases.TrueForAll((info) => info.Id != changedResourceId)) { return; } float updatesSinceSourceUpdate = (MySession.Static.GameplayFrameCounter - m_lastSourceUpdate); m_lastSourceUpdate = MySession.Static.GameplayFrameCounter; float secondsSinceSourceUpdate = updatesSinceSourceUpdate * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; foreach (var producedGas in BlockDefinition.ProducedGases) { var producedGasId = producedGas.Id; float gasToProduce; if (producedGas.Id == changedResourceId) { gasToProduce = oldOutput * secondsSinceSourceUpdate; } else { gasToProduce = GasOutputPerUpdate(ref producedGasId) * updatesSinceSourceUpdate; } ProduceGas(ref producedGasId, gasToProduce); } }
private void Source_OutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source) { if (changedResourceId != BlockDefinition.StoredGasId) { return; } float timeSinceLastUpdateSeconds = (m_updateCounter - m_lastOutputUpdateTime) / MyEngineConstants.UPDATE_STEPS_PER_SECOND; float outputAmount = oldOutput * timeSinceLastUpdateSeconds; m_nextGasTransfer -= outputAmount; m_lastOutputUpdateTime = m_updateCounter; }
public MyGasTank() { SourceComp = new MyResourceSourceComponent(); ResourceSink = new MyResourceSinkComponent(2); }
private void SolarPanel_MaxOutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source) { //is this possible? if (source?.Entity == null) { return; } //shouldn't happen, should always exist from the OnEntityCreate if (solarPanelData.ContainsKey(source.Entity.EntityId) == false) { return; } var data = solarPanelData[source.Entity.EntityId]; //if the max output matches our current max output, or our original max output don't do anything if (data.CurrentMaxOutput == source.MaxOutput || data.OriginalMaxOutput == source.MaxOutput) { return; } IMyTerminalBlock terminalEntity = source.Entity as IMyTerminalBlock; if (terminalEntity == null) { return; } //set our new original max output then recalculate solarPanelData[source.Entity.EntityId].OriginalMaxOutput = source.MaxOutput; //did we change grids? if (terminalEntity.CubeGrid.EntityId != data.GridEntityId) { //check if we're static again data.IsStatic = terminalEntity.CubeGrid.IsStatic; //force a re-calculation of air density data.CurrentAirDensity = null; } if (data.CurrentAirDensity == null || data.IsStatic == false) { var entityPosition = terminalEntity.GetPosition(); float airDensity = 0f; MyPlanet closestPlanet = MyGamePruningStructure.GetClosestPlanet(entityPosition); if (closestPlanet == null || closestPlanet.PositionComp.WorldAABB.Contains(entityPosition) == ContainmentType.Disjoint) { airDensity = 0f; } else { airDensity = closestPlanet.GetAirDensity(entityPosition); } if (data.CurrentAirDensity != airDensity) { data.CurrentAirDensity = airDensity; terminalEntity.RefreshCustomInfo(); } } //update UpdatePower(source.Entity as IMySolarPanel, data); }
private void Source_OnOutputChanged(MyDefinitionId resourceTypeId, float oldOutput, MyResourceSourceComponent source) { UpdateText(); if ((SoundEmitter != null) && (SoundEmitter.Sound != null) && (SoundEmitter.Sound.IsPlaying)) { if (SourceComp.MaxOutput != 0f) { float semitones = 4f * (SourceComp.CurrentOutput - 0.5f * SourceComp.MaxOutput) / SourceComp.MaxOutput; SoundEmitter.Sound.FrequencyRatio = MyAudio.Static.SemitonesToFrequencyRatio(semitones); } else { SoundEmitter.Sound.FrequencyRatio = 1f; } } }
public virtual void UnregisterFromSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.RemoveSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.RemoveSink(sink, true, false); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = null; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Unregister(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block5 = block as MyTerminalBlock; if (block5 != null) { this.TerminalSystem.Remove(block5); } } if (block.HasInventory) { this.ConveyorSystem.Remove(block); } IMyConveyorEndpointBlock block2 = block as IMyConveyorEndpointBlock; if (block2 != null) { this.ConveyorSystem.RemoveConveyorBlock(block2); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { this.ConveyorSystem.RemoveSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Unregister(reflector); } MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); if (broadcaster != null) { this.RadioSystem.Unregister(broadcaster); } MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); if (reciever != null) { this.RadioSystem.Unregister(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Unregister(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Unregister(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Unregister(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Unregister(camera); } } block.OnUnregisteredFromGridSystems(); }