Beispiel #1
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            m_cameraDummy = Matrix.Identity;
            m_characterDummy = Matrix.Identity;

            base.Init(objectBuilder, cubeGrid);

            var chamberOb = objectBuilder as MyObjectBuilder_CryoChamber;

            if (chamberOb.SteamId != null && chamberOb.SerialId != null)
            {
                m_currentPlayerId = new MyPlayer.PlayerId(chamberOb.SteamId.Value, chamberOb.SerialId.Value);
            }
            else
            {
                m_currentPlayerId = null;
            }

            var overlayTexture = BlockDefinition.OverlayTexture;
            if (!string.IsNullOrEmpty(overlayTexture))
            {
                m_overlayTextureName = overlayTexture;
            }

            var sinkComp = new MyResourceSinkComponent();
			sinkComp.Init(
                MyStringHash.GetOrCompute(BlockDefinition.ResourceSinkGroup),
                BlockDefinition.IdlePowerConsumption,
                this.CalculateRequiredPowerInput);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
	        ResourceSink = sinkComp;

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
Beispiel #2
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

			ResourceSink = new MyResourceSinkComponent();
			ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);
			ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
			ResourceSink.Update();

            if (Physics != null)
            {
                Physics.Close();
            }

            var detectorShape = new HkBoxShape(new Vector3(cubeGrid.GridSize / 3.0f));
            var massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(detectorShape.HalfExtents, BlockDefinition.VirtualMass);
            Physics = new Engine.Physics.MyPhysicsBody(this, RigidBodyFlag.RBF_DEFAULT);
            Physics.IsPhantom = false;
            Physics.CreateFromCollisionObject(detectorShape, Vector3.Zero, WorldMatrix, massProperties, MyPhysics.VirtualMassLayer);
            Physics.Enabled = IsWorking && cubeGrid.Physics != null && cubeGrid.Physics.Enabled;
            Physics.RigidBody.Activate();
            detectorShape.Base.RemoveReference();

            UpdateText();

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

        }
Beispiel #3
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            var def = BlockDefinition as MyPoweredCargoContainerDefinition;
            var ob = objectBuilder as MyObjectBuilder_Collector;
            m_inventory = new MyInventory(def.InventorySize.Volume, def.InventorySize, MyInventoryFlags.CanSend, this);
            m_inventory.Init(ob.Inventory);
            m_inventory.ContentsChanged += Inventory_ContentChangedCallback;
            if (Sync.IsServer && CubeGrid.CreatePhysics)
                LoadDummies();

			var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                MyStringHash.GetOrCompute(def.ResourceSinkGroup),
                MyEnergyConstants.MAX_REQUIRED_POWER_COLLECTOR,
                () => base.CheckIsWorking() ? ResourceSink.MaxRequiredInput : 0f);
	        ResourceSink = sinkComp;
			ResourceSink.Update();
			ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink,this));

            SlimBlock.ComponentStack.IsFunctionalChanged += UpdateReceiver;
            base.EnabledChanged += UpdateReceiver;

            m_useConveyorSystem = ob.UseConveyorSystem;
        }
        public MyGridWheelSystem(MyCubeGrid grid)
        {
            m_wheels = new HashSet<MyMotorSuspension>();
            m_wheelsChanged = false;
            m_grid = grid;

			SinkComp = new MyResourceSinkComponent();
			SinkComp.Init(MyStringHash.GetOrCompute("Utility"), m_maxRequiredPowerInput, () => m_maxRequiredPowerInput);
            SinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;

            grid.OnPhysicsChanged += grid_OnPhysicsChanged;
        }
        public MyGridGyroSystem(MyCubeGrid grid)
        {
            m_grid = grid;
            m_gyros = new HashSet<MyGyro>();
            m_gyrosChanged = false;
			ResourceSink = new MyResourceSinkComponent();
            ResourceSink.Init(
                MyStringHash.GetOrCompute("Gyro"),
                m_maxRequiredPowerInput,
                () => m_maxRequiredPowerInput);
            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            m_cameraDummy = Matrix.Identity;
            m_characterDummy = Matrix.Identity;

            base.Init(objectBuilder, cubeGrid);

            if (ResourceSink == null)
            {
                // we've already created ResourceSink in ancestor!
                var sinkComp = new MyResourceSinkComponent();
                sinkComp.Init(
                    MyStringHash.GetOrCompute(BlockDefinition.ResourceSinkGroup),
                    BlockDefinition.IdlePowerConsumption,
                    this.CalculateRequiredPowerInput);
                sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
                ResourceSink = sinkComp;
            }
            else
            {
                // override electricity settings
                ResourceSink.SetMaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId, BlockDefinition.IdlePowerConsumption);
                ResourceSink.SetRequiredInputFuncByType(MyResourceDistributorComponent.ElectricityId, this.CalculateRequiredPowerInput);
                ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            }

            var chamberOb = objectBuilder as MyObjectBuilder_CryoChamber;

            if (chamberOb.SteamId != null && chamberOb.SerialId != null)
            {
                m_currentPlayerId = new MyPlayer.PlayerId(chamberOb.SteamId.Value, chamberOb.SerialId.Value);
            }
            else
            {
                m_currentPlayerId = null;
            }


            var overlayTexture = BlockDefinition.OverlayTexture;
            if (!string.IsNullOrEmpty(overlayTexture))
            {
                m_overlayTextureName = overlayTexture;
            }

          
            HorizonIndicatorEnabled = false;

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;
        }
Beispiel #7
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var ob = objectBuilder as MyObjectBuilder_Collector;

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                MyStringHash.GetOrCompute(BlockDefinition.ResourceSinkGroup),
                BlockDefinition.RequiredPowerInput,
                ComputeRequiredPower);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            m_useConveyorSystem.Value = true;
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(BlockDefinition.InventorySize.Volume, BlockDefinition.InventorySize, MyInventoryFlags.CanSend);
                Components.Add<MyInventoryBase>(inventory);
                inventory.Init(ob.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            if (Sync.IsServer && CubeGrid.CreatePhysics)
                LoadDummies();

            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink,this));

            SlimBlock.ComponentStack.IsFunctionalChanged += UpdateReceiver;
            base.EnabledChanged += UpdateReceiver;

            m_useConveyorSystem.Value = ob.UseConveyorSystem;

            ResourceSink.Update();
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var def = BlockDefinition as MyPoweredCargoContainerDefinition;
            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                MyStringHash.GetOrCompute(def.ResourceSinkGroup),
                MyEnergyConstants.MAX_REQUIRED_POWER_COLLECTOR,
                () => base.CheckIsWorking() ? ResourceSink.MaxRequiredInput : 0f);
            ResourceSink = sinkComp;
            ResourceSink.Update();

            base.Init(objectBuilder, cubeGrid);
           
            var ob = objectBuilder as MyObjectBuilder_Collector;

            m_useConveyorSystem.Value = true;
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

            if (this.GetInventory() == null)
            {
               Components.Add<MyInventoryBase>( new MyInventory(def.InventorySize.Volume, def.InventorySize, MyInventoryFlags.CanSend, this));
               this.GetInventory().Init(ob.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            if (Sync.IsServer && CubeGrid.CreatePhysics)
                LoadDummies();

			
			ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink,this));

            SlimBlock.ComponentStack.IsFunctionalChanged += UpdateReceiver;
            base.EnabledChanged += UpdateReceiver;

            m_useConveyorSystem.Value = ob.UseConveyorSystem;
        }
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            ResourceSink = new MyResourceSinkComponent();
            ResourceSink.Init(
                MyStringHash.GetOrCompute(BlockDefinition.ResourceSinkGroup),
                BlockDefinition.PowerConsumptionMoving,
                UpdatePowerInput);

            base.Init(builder, cubeGrid);

            var ob = (MyObjectBuilder_AirtightDoorGeneric)builder;
            m_open.Value = ob.Open;
            m_currOpening = ob.CurrOpening;

            m_openingSpeed = BlockDefinition.OpeningSpeed;
            m_sound = new MySoundPair(BlockDefinition.Sound);
            m_subpartMovementDistance = BlockDefinition.SubpartMovementDistance;
	
			if (!Enabled || !ResourceSink.IsPoweredByType(MyResourceDistributorComponent.ElectricityId))
                UpdateDoorPosition();

            OnStateChange();

            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink.Update();
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
			ResourceSink.Update();
        }
        public MyGridConveyorSystem(MyCubeGrid grid)
        {
            m_grid = grid;

            m_lineEndpoints = null;
            m_linePoints = null;
            m_deserializedLines = null;

            ResourceSink = new MyResourceSinkComponent();
            ResourceSink.Init(
                MyStringHash.GetOrCompute("Conveyors"),
                CONVEYOR_SYSTEM_CONSUMPTION,
                CalculateConsumption);

            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink.Update();
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            m_inputInventory = new MyInventory(
                ProductionBlockDefinition.InventoryMaxVolume,
                ProductionBlockDefinition.InventorySize,
                MyInventoryFlags.CanReceive,
                this);

            m_outputInventory = new MyInventory(
                ProductionBlockDefinition.InventoryMaxVolume,
                ProductionBlockDefinition.InventorySize,
                MyInventoryFlags.CanSend,
                this);

            var ob = (MyObjectBuilder_ProductionBlock)objectBuilder;
            if (ob.InputInventory != null)
                InputInventory.Init(ob.InputInventory);
            if (ob.OutputInventory != null)
                OutputInventory.Init(ob.OutputInventory);

            m_nextItemId = ob.NextItemId;
            bool nextIdWasZero = m_nextItemId == 0;

            base.IsWorkingChanged += CubeBlock_IsWorkingChanged;

			var sinkComp = new MyResourceSinkComponent();
			sinkComp.Init(ProductionBlockDefinition.ResourceSinkGroup, ProductionBlockDefinition.OperationalPowerConsumption, ComputeRequiredPower);
			sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
			ResourceSink = sinkComp;
			ResourceSink.Update();

			AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            if (ob.Queue != null)
            {
                m_queue.Clear();
                if (m_queue.Capacity < ob.Queue.Length)
                    m_queue.Capacity = ob.Queue.Length;
                for (int i = 0; i < ob.Queue.Length; ++i)
                {
                    var item = ob.Queue[i];
                    Debug.Assert(item.ItemId != null || nextIdWasZero, "Item index was null while next id for production block was given non-zero. This is inconsistency.");

                    var deserializedItem = DeserializeQueueItem(item);
                    Debug.Assert(deserializedItem.Blueprint != null, "Could not add item into production block's queue: Blueprint was not found.");
                    if (deserializedItem.Blueprint != null)
                    {
                        m_queue.Add(deserializedItem);
                        MySandboxGame.Log.WriteLine(string.Format("Could not add item into production block's queue: Blueprint {0} was not found.", item.Id));
                    }
                }

                UpdatePower();
            }

            m_useConveyorSystem = ob.UseConveyorSystem;

            m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }
Beispiel #12
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true; 

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                0.0001f,
                () => IsFunctional ? 0.0001f : 0);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            sinkComp.IsPoweredChanged += ComponentStack_IsFunctionalChanged;
            ResourceSink = sinkComp;

            base.Init(builder, cubeGrid);
            m_emissiveNames = new List<string>(BlockDefinition.ButtonCount);
            for (int i = 1; i <= BlockDefinition.ButtonCount; i++) //button dummies have 1-based index
            {
                m_emissiveNames.Add(string.Format("Emissive{0}", i)); // because of modding
            }
            var ob = builder as MyObjectBuilder_ButtonPanel;
            Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, Math.Min(BlockDefinition.ButtonCount, MyToolbar.DEF_SLOT_COUNT), (BlockDefinition.ButtonCount / MyToolbar.DEF_SLOT_COUNT) + 1);
            Toolbar.DrawNumbers = false;
            Toolbar.GetSymbol = (slot) =>
                {
                    var ret = new Sandbox.Graphics.GUI.MyGuiControlGrid.ColoredIcon();
                    if(Toolbar.SlotToIndex(slot) < BlockDefinition.ButtonCount) 
                    {
                        ret.Icon = BlockDefinition.ButtonSymbols[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonSymbols.Length];
                        var color = BlockDefinition.ButtonColors[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonColors.Length];
                        color.W = 1;
                        ret.Color = color;
                    }
                    return ret;
                };

            Toolbar.Init(ob.Toolbar, this);
            Toolbar.ItemChanged += Toolbar_ItemChanged;
            AnyoneCanUse = ob.AnyoneCanUse;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
		
            ResourceSink.Update();

            if (ob.CustomButtonNames != null)
            {
                m_customButtonNames = ob.CustomButtonNames;
            }

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME;

            UseObjectsComponent.GetInteractiveObjects<MyUseObjectPanelButton>(m_buttonsUseObjects);
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                CalculateRequiredPowerInput);
           
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);
            if (!MyFakes.ENABLE_PROJECTOR_BLOCK)
            {
                return;
            }

            var projectorBuilder = (MyObjectBuilder_ProjectorBase)objectBuilder;
            if (projectorBuilder.ProjectedGrid != null)
            {
                m_projectionOffset = projectorBuilder.ProjectionOffset;
                m_projectionRotation = projectorBuilder.ProjectionRotation;

                m_savedProjection = projectorBuilder.ProjectedGrid;
                KeepProjection = projectorBuilder.KeepProjection;
            }

            m_showOnlyBuildable = projectorBuilder.ShowOnlyBuildable;
            InstantBuildingEnabled = projectorBuilder.InstantBuildingEnabled;
            MaxNumberOfProjections = projectorBuilder.MaxNumberOfProjections;
            MaxNumberOfBlocksPerProjection = projectorBuilder.MaxNumberOfBlocks;
            GetOwnershipFromProjector = projectorBuilder.GetOwnershipFromProjector;

            m_projectionsRemaining = MathHelper.Clamp(projectorBuilder.ProjectionsRemaining, 0, m_maxNumberOfProjections);

			
            IsWorkingChanged += MyProjector_IsWorkingChanged;
            sinkComp.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
			ResourceSink.Update();
            m_statsDirty = true;
            UpdateText();

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            CubeGrid.OnBlockAdded += previewGrid_OnBlockAdded;
            CubeGrid.OnBlockRemoved += previewGrid_OnBlockRemoved;
        
            CubeGrid.OnGridSplit += CubeGrid_OnGridSplit;
        }
Beispiel #14
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            base.Init(builder, cubeGrid);

            //m_subpartsSize = 0.5f * (0.5f * SlimBlock.CubeGrid.GridSize - 0.3f);
            var doorDefinition = BlockDefinition as MyDoorDefinition;
	        MyStringHash resourceSinkGroup;
            if (doorDefinition != null)
            {
                MaxOpen = doorDefinition.MaxOpen;
                m_openSound = new MySoundPair(doorDefinition.OpenSound);
                m_closeSound = new MySoundPair(doorDefinition.CloseSound);
				resourceSinkGroup = MyStringHash.GetOrCompute(doorDefinition.ResourceSinkGroup);
            }
            else
            {
                MaxOpen = 1.2f;
                m_openSound = new MySoundPair("BlockDoorSmallOpen");
                m_closeSound = new MySoundPair("BlockDoorSmallClose");
				resourceSinkGroup = MyStringHash.GetOrCompute("Doors");
            }

            var ob = (MyObjectBuilder_Door)builder;
            m_open = ob.State;
            m_currOpening = ob.Opening;

			var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
				resourceSinkGroup, 
                MyEnergyConstants.MAX_REQUIRED_POWER_DOOR,
				() => (Enabled && IsFunctional) ? sinkComp.MaxRequiredInput : 0f);
			sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
			sinkComp.Update();

	        ResourceSink = sinkComp;
			if (!Enabled || !ResourceSink.IsPowered)
                UpdateSlidingDoorsPosition(true);


            OnStateChange();

            if (m_open)
            {
                // required when reinitializing a door after the armor beneath it is destroyed
                if (Open && (m_currOpening == MaxOpen))
                    UpdateSlidingDoorsPosition(true);
            }

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true; 
            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                m_powerNeeded,
                this.CalculateRequiredPowerInput);

           
            ResourceSink = sinkComp;
            base.Init(objectBuilder, cubeGrid);
            NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;

            var remoteOb = (MyObjectBuilder_RemoteControl)objectBuilder;
            m_savedPreviousControlledEntityId = remoteOb.PreviousControlledEntityId;

            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            sinkComp.RequiredInputChanged += Receiver_RequiredInputChanged;
			
            sinkComp.Update();

            m_autoPilotEnabled.Value = remoteOb.AutoPilotEnabled;
            m_dockingModeEnabled.Value = remoteOb.DockingModeEnabled;
            m_currentFlightMode.Value = (FlightMode)remoteOb.FlightMode;
            m_currentDirection.Value = (Base6Directions.Direction)remoteOb.Direction;
            m_autopilotSpeedLimit.Value = remoteOb.AutopilotSpeedLimit;
            m_bindedCamera.Value = remoteOb.BindedCamera;
            m_waypointThresholdDistance.Value = remoteOb.WaypointThresholdDistance;
            m_currentAutopilotSpeedLimit = m_autopilotSpeedLimit;

            m_stuckDetection = new MyStuckDetection(0.03f, 0.01f, this.CubeGrid.PositionComp.WorldAABB);

            if (remoteOb.Coords == null || remoteOb.Coords.Count == 0)
            {
                if (remoteOb.Waypoints == null)
                {
                    m_waypoints = new List<MyAutopilotWaypoint>();
                    CurrentWaypoint = null;
                }
                else
                {
                    m_waypoints = new List<MyAutopilotWaypoint>(remoteOb.Waypoints.Count);
                    for (int i = 0; i < remoteOb.Waypoints.Count; i++)
                    {
                        m_waypoints.Add(new MyAutopilotWaypoint(remoteOb.Waypoints[i], this));
                    }
                }
            }
            else
            {
                m_waypoints = new List<MyAutopilotWaypoint>(remoteOb.Coords.Count);
                for (int i = 0; i < remoteOb.Coords.Count; i++)
                {
                    m_waypoints.Add(new MyAutopilotWaypoint(remoteOb.Coords[i], remoteOb.Names[i], this));
                }

                if (remoteOb.AutoPilotToolbar != null && m_currentFlightMode == FlightMode.OneWay)
                {
                    m_waypoints[m_waypoints.Count - 1].SetActions(remoteOb.AutoPilotToolbar.Slots);
                }
            }

            if (remoteOb.CurrentWaypointIndex == -1 || remoteOb.CurrentWaypointIndex >= m_waypoints.Count)
            {
                CurrentWaypoint = null;
            }
            else
            {
                CurrentWaypoint = m_waypoints[remoteOb.CurrentWaypointIndex];
            }

            UpdatePlanetWaypointInfo();

            m_actionToolbar = new MyToolbar(MyToolbarType.ButtonPanel, pageCount: 1);
            m_actionToolbar.DrawNumbers = false;
            m_actionToolbar.Init(null, this);

            m_selectedGpsLocations = new List<IMyGps>();
            m_selectedWaypoints = new List<MyAutopilotWaypoint>();
            UpdateText();

            AddDebugRenderComponent(new MyDebugRenderComponentRemoteControl(this));

            m_useCollisionAvoidance.Value = remoteOb.CollisionAvoidance;

            for (int i = 0; i < TERRAIN_HEIGHT_DETECTION_SAMPLES; i++)
            {
                m_terrainHeightDetection[i] = 0.0f;
            }
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var blockDefinition = BlockDefinition as MyProgrammableBlockDefinition;

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
              blockDefinition.ResourceSinkGroup,
              0.0005f,
              () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0f);
            sinkComp.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);
            var programmableBlockBuilder = (MyObjectBuilder_MyProgrammableBlock)objectBuilder;
            m_editorData = m_programData = programmableBlockBuilder.Program;
            m_storageData = programmableBlockBuilder.Storage;
            this.m_terminalRunArgument = programmableBlockBuilder.DefaultRunArgument;

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
	    	
			ResourceSink.Update();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyProgrammableBlock_IsWorkingChanged;

            if (Sync.IsServer && Sync.Clients != null)
            {
                Sync.Clients.ClientRemoved += ProgrammableBlock_ClientRemoved;
            }
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0f);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);
            this.IsLargeLight = cubeGrid.GridSizeEnum == MyCubeSize.Large;

            var builder = (MyObjectBuilder_LightingBlock)objectBuilder;
            MyModel lightModel = VRage.Game.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model);
            foreach (var pair in lightModel.Dummies)
            {
                if (!pair.Key.ToLower().Contains("light"))
                    continue;

                m_lightLocalPosition = pair.Value.Matrix.Translation;
                break;
            }

            Vector4 color = (builder.ColorAlpha == -1)
                ? LightColorDef
                : new Vector4(builder.ColorRed, builder.ColorGreen, builder.ColorBlue, builder.ColorAlpha);

            float radius = RadiusBounds.Clamp((builder.Radius == -1f) ? RadiusBounds.Default : builder.Radius);
            float falloff = FalloffBounds.Clamp(builder.Falloff);

            m_blinkIntervalSeconds.Value = BlinkIntervalSecondsBounds.Clamp((builder.BlinkIntervalSeconds == -1f) ? BlinkIntervalSecondsBounds.Default : builder.BlinkIntervalSeconds);

            m_blinkLength.Value = BlinkLenghtBounds.Clamp((builder.BlinkLenght == -1f) ? BlinkLenghtBounds.Default : builder.BlinkLenght);

            m_blinkOffset.Value = BlinkOffsetBounds.Clamp((builder.BlinkOffset == -1f) ? BlinkOffsetBounds.Default : builder.BlinkOffset);

            m_intesity.Value = IntensityBounds.Clamp((builder.Intensity == -1f) ? IntensityBounds.Default : builder.Intensity);


            m_positionDirty = true;
            m_light = MyLights.AddLight();
            InitLight(m_light, color, radius, falloff);
            
            m_light.ReflectorRange = ShortReflectorRangeDef;
            m_light.Range = radius;
            m_light.PointLightOffset = 0.5f;
            m_light.ReflectorOn = false;
            m_light.LightOn = false;
            m_light.GlareOn = false;
            
            UpdateIntensity();
            UpdateLightPosition();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
            Render.NeedsDrawFromParent = true;

			
			AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));
			ResourceSink.Update();
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += CubeBlock_OnWorkingChanged;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var timerBlockDefinition = BlockDefinition as MyTimerBlockDefinition;

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                timerBlockDefinition.ResourceSinkGroup,
                0.0000001f,
                () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0f);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_TimerBlock;

            Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 9, 10);
            Toolbar.Init(ob.Toolbar, this);
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            if (ob.JustTriggered) NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            IsCountingDown = ob.IsCountingDown;
            m_countdownMsStart = ob.Delay;
            m_countdownMsCurrent = ob.CurrentTime;
            Silent = ob.Silent;

            if (m_countdownMsCurrent > 0)
                NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink.Update();

            AddDebugRenderComponent(new Sandbox.Game.Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            m_beepStart = new MySoundPair(timerBlockDefinition.TimerSoundStart);
            m_beepMid = new MySoundPair(timerBlockDefinition.TimerSoundMid);
            m_beepEnd = new MySoundPair(timerBlockDefinition.TimerSoundEnd);
            m_beepEmitter = new MyEntity3DSoundEmitter(this);
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
             BlockDefinition.ResourceSinkGroup,
             BlockDefinition.RequiredPowerInput,
             () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0f);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_TextPanel ob = (MyObjectBuilder_TextPanel)objectBuilder;

            PrivateTitle.Append(ob.Title);
            PrivateDescription.Append(ob.Description);
            PublicDescription.Append(ob.PublicDescription);
            PublicTitle.Append(ob.PublicTitle);

            m_currentPos = ob.CurrentShownTexture;
            AccessFlag = ob.AccessFlag;

            if (Sync.IsServer && Sync.Clients != null)
            {
                Sync.Clients.ClientRemoved += TextPanel_ClientRemoved;
            }

            FontColor = ob.FontColor;
            BackgroundColor = ob.BackgroundColor;
            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
            Render.NeedsDrawFromParent = true;
            this.ChangeInterval = ob.ChangeInterval;
            FontSize = ob.FontSize;
            ShowTextFlag = ob.ShowText;
            if (ob.SelectedImages != null)
            {
                foreach (var savedTextureName in ob.SelectedImages)
                {
                    foreach (var textureDefinition in m_definitions)
                    {
                        if (textureDefinition.Id.SubtypeName == savedTextureName)
                        {
                            m_selectedTexturesToDraw.Add(textureDefinition);
                            break;
                        }
                    }
                }
                m_currentPos = Math.Min(m_currentPos, m_selectedTexturesToDraw.Count);
                RaisePropertiesChanged();
            }

            ResourceSink.Update();
            ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
Beispiel #20
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            RadioBroadcaster = new MyRadioBroadcaster();
            RadioReceiver = new MyRadioReceiver();

            var antennaDefinition = BlockDefinition as MyRadioAntennaDefinition;
            Debug.Assert(antennaDefinition != null);

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                antennaDefinition.ResourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_ANTENNA,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_RadioAntenna antennaBuilder = (MyObjectBuilder_RadioAntenna)objectBuilder;

            if (antennaBuilder.BroadcastRadius != 0)
            {
                RadioBroadcaster.BroadcastRadius = antennaBuilder.BroadcastRadius;
            }
            else
            {
                RadioBroadcaster.BroadcastRadius = CubeGrid.GridSizeEnum == MyCubeSize.Large ? 10000 : 500;
            }
            ResourceSink.Update();
            RadioBroadcaster.WantsToBeEnabled = antennaBuilder.EnableBroadcasting;

            m_showShipName.Value = antennaBuilder.ShowShipName;

            //if (Sync.IsServer)
            //{
            //    this.IsWorkingChanged += UpdatePirateAntenna;
            //    this.CustomNameChanged += UpdatePirateAntenna;
            //    this.OwnershipChanged += UpdatePirateAntenna;
            //    UpdatePirateAntenna(this);
            //}

            ShowOnHUD = false;

            m_gizmoColor = new Vector4(0.2f, 0.2f, 0.0f, 0.5f);

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            float consumption = MyEnergyConstants.MAX_REQUIRED_POWER_CONNECTOR;
            if (cubeGrid.GridSizeEnum == MyCubeSize.Small)
            {
                consumption *= 0.01f;
            }

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                MyStringHash.GetOrCompute("Conveyors"),
                consumption,
                () => base.CheckIsWorking() ? ResourceSink.MaxRequiredInput : 0f
            );
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;
            

            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_ShipConnector;
            Vector3 inventorySize = (BlockDefinition.Size * CubeGrid.GridSize) * 0.8f; // 0.8 ~= 0.5^(1/3) to make the inventory volume approx. one half of the block size

            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(inventorySize.Volume, inventorySize, MyInventoryFlags.CanReceive | MyInventoryFlags.CanSend);
                Components.Add<MyInventoryBase>(inventory);
                inventory.Init(ob.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            ThrowOut.Value = ob.ThrowOut;
            CollectAll.Value = ob.CollectAll;

            SlimBlock.DeformationRatio = ob.DeformationRatio;
         
            SlimBlock.ComponentStack.IsFunctionalChanged += UpdateReceiver;
            base.EnabledChanged += UpdateReceiver;

            ResourceSink.Update();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

            if (CubeGrid.CreatePhysics)
                LoadDummies();
            if (Physics != null) Physics.Enabled = true;
            if (m_connectorDummy != null)
            {
                m_connectorDummy.Enabled = true;
            }

            Strength.Value = ob.Strength;
            if (ob.ConnectedEntityId != 0)
            {
                MyDeltaTransform? deltaTransform = ob.MasterToSlaveTransform.HasValue ? ob.MasterToSlaveTransform.Value : (MyDeltaTransform?)null;
                if (ob.Connected)
                {
                    // Old saves with connected connector, store ZERO into MasterToSlave transform
                    deltaTransform = default(MyDeltaTransform);
                }
                if(ob.IsMaster.HasValue == false)
                {
                    ob.IsMaster = ob.ConnectedEntityId < EntityId;
                }

                IsMaster = ob.IsMaster.Value;
                m_connectionState.Value = new State() {IsMaster =  ob.IsMaster.Value, OtherEntityId = ob.ConnectedEntityId, MasterToSlave = deltaTransform,MasterToSlaveGrid = ob.MasterToSlaveGrid};
                NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            }

            IsWorkingChanged += MyShipConnector_IsWorkingChanged;                       

            AddDebugRenderComponent(new Components.MyDebugRenderCompoonentShipConnector(this));
        }
        //[TerminalValues(MySpaceTexts.SwitchText_On, MySpaceTexts.SwitchText_Off)]
        //[Terminal(2, MyPropertyDisplayEnum.Switch, MySpaceTexts.Terminal_UseConveyorSystem, MySpaceTexts.Blank)]
        //[Obfuscation(Feature = Obfuscator.NoRename, Exclude = true)]
        //public MyStringId UseConveyorSystemGui
        //{
        //    get { return m_useConveyorSystem ? MySpaceTexts.SwitchText_On : MySpaceTexts.SwitchText_Off; }
        //    set
        //    {
        //        if (m_useConveyorSystem != (value == MySpaceTexts.SwitchText_On))
        //        {
        //            m_useConveyorSystem = (value == MySpaceTexts.SwitchText_On);
        //            OnPropertiesChanged();
        //        }
        //    }
        //}
        //[TerminalValueSetter(2)]
        //public void RequestUseConveyorSystemChange(MyStringId newVal)
        //{
        //    MySyncConveyors.SendChangeUseConveyorSystemRequest(EntityId, newVal == MySpaceTexts.SwitchText_On);
        //}

        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            var ob = builder as MyObjectBuilder_SmallMissileLauncher;
           
 
            MyStringHash resourceSinkGroup;
            var weaponBlockDefinition = BlockDefinition as MyWeaponBlockDefinition;
            if (weaponBlockDefinition != null && this.GetInventory() == null) 
            {
                MyInventory inventory = new MyInventory(weaponBlockDefinition.InventoryMaxVolume, new Vector3(1.2f, 0.98f, 0.98f), MyInventoryFlags.CanReceive);
                Components.Add<MyInventoryBase>(inventory);               
                resourceSinkGroup = weaponBlockDefinition.ResourceSinkGroup;
            }
            else
            {
                if (this.GetInventory() == null) // this could be already inicialized object builder
                {
                    MyInventory inventory = null;
                    if (cubeGrid.GridSizeEnum == MyCubeSize.Small)
                        inventory = new MyInventory(240.0f / 1000, new Vector3(1.2f, 0.45f, 0.45f), MyInventoryFlags.CanReceive); // 4 missiles
                    else
                        inventory = new MyInventory(1140.0f / 1000, new Vector3(1.2f, 0.98f, 0.98f), MyInventoryFlags.CanReceive); // 19 missiles

                    Components.Add(inventory);
                }

                resourceSinkGroup = MyStringHash.GetOrCompute("Defense");
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");
            
            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                resourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_SHIP_GUN,
                () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0.0f);
            ResourceSink = sinkComp;
            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;

            base.Init(builder, cubeGrid);
            
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }
            ResourceSink.Update();
            this.GetInventory().Init(ob.Inventory);
            m_gunBase.Init(ob.GunBase, BlockDefinition, this);
            m_shotsLeftInBurst = m_gunBase.ShotsInBurst;
	
			AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            m_useConveyorSystem.Value = ob.UseConveyorSystem;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            LoadDummies();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                MotorDefinition.ResourceSinkGroup,
                MotorDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? sinkComp.MaxRequiredInput : 0.0f);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
         
            ResourceSink.Update();

            m_dummyDisplacement.Value = 0.0f;
            LoadDummyPosition();

            var ob = objectBuilder as MyObjectBuilder_MotorBase;

            if (ob.RotorEntityId.HasValue && ob.RotorEntityId.Value != 0)
            {
                MyDeltaTransform? deltaTransform = ob.MasterToSlaveTransform.HasValue ? ob.MasterToSlaveTransform.Value : (MyDeltaTransform?)null;
                m_rotorBlockId.Value = new State() { OtherEntityId = ob.RotorEntityId, MasterToSlave = deltaTransform };
            }
          
            m_weldedEntityId.Value = ob.WeldedEntityId;

            AddDebugRenderComponent(new Components.MyDebugRenderComponentMotorBase(this));
            cubeGrid.OnPhysicsChanged += cubeGrid_OnPhysicsChanged;

            float defaultWeldSpeed = ob.weldSpeed; //weld before reaching the max speed
            defaultWeldSpeed *= defaultWeldSpeed;
            m_weldSpeedSq.Value = defaultWeldSpeed;
            m_forceWeld.Value = ob.forceWeld;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_ShipConnector;
            Vector3 inventorySize = (BlockDefinition.Size * CubeGrid.GridSize) * 0.8f; // 0.8 ~= 0.5^(1/3) to make the inventory volume approx. one half of the block size
            m_inventory = new MyInventory(inventorySize.Volume, inventorySize, MyInventoryFlags.CanReceive | MyInventoryFlags.CanSend, this);
            m_inventory.Init(ob.Inventory);
            m_throwOut = ob.ThrowOut;
            m_collectAll = ob.CollectAll;

            SlimBlock.DeformationRatio = ob.DeformationRatio;

            float consumption = MyEnergyConstants.MAX_REQUIRED_POWER_CONNECTOR;
            if (cubeGrid.GridSizeEnum == MyCubeSize.Small)
            {
                consumption *= 0.01f;
            }

			var sinkComp = new MyResourceSinkComponent();
			sinkComp.Init(
                MyStringHash.GetOrCompute("Conveyors"),
                consumption,
				() => base.CheckIsWorking() ? ResourceSink.MaxRequiredInput : 0f
            );
			sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
	        ResourceSink = sinkComp;
			ResourceSink.Update();

            SlimBlock.ComponentStack.IsFunctionalChanged += UpdateReceiver;
            base.EnabledChanged += UpdateReceiver;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            
            if(CubeGrid.CreatePhysics)
                LoadDummies();
            if (Physics != null) Physics.Enabled = true;
            if (m_connectorDummy != null)
            {
                m_connectorDummy.Enabled = true;
            }

            if (ob.ConnectedEntityId != 0) 
            {
                m_previouslyConnected = ob.Connected;
                m_previouslyConnectedEntityId = ob.ConnectedEntityId;
                NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            }

            IsWorkingChanged += MyShipConnector_IsWorkingChanged;

			if (MyPerGameSettings.InventoryMass)
				m_inventory.ContentsChanged += Inventory_ContentsChanged;

            AddDebugRenderComponent(new Components.MyDebugRenderCompoonentShipConnector(this));
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            m_items = new List<ToolbarItem>(2);
            for (int i = 0; i < 2; i++)
            {
                m_items.Add(new ToolbarItem() { EntityID = 0 });
            }
            Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            Toolbar.DrawNumbers = false;

            var builder = (MyObjectBuilder_SensorBlock)objectBuilder;
            
            m_fieldMin.Value = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One);
            m_fieldMax.Value = Vector3.Clamp(builder.FieldMax, Vector3.One, new Vector3(MaxRange));

            PlayProximitySound = builder.PlaySound;
            DetectPlayers = builder.DetectPlayers;
            DetectFloatingObjects = builder.DetectFloatingObjects;
            DetectSmallShips = builder.DetectSmallShips;
            DetectLargeShips = builder.DetectLargeShips;
            DetectStations = builder.DetectStations;
            DetectAsteroids = builder.DetectAsteroids;
            DetectOwner = builder.DetectOwner;
            DetectFriendly = builder.DetectFriendly;
            DetectNeutral = builder.DetectNeutral;
            DetectEnemy = builder.DetectEnemy;
            m_active.Value = builder.IsActive;

            Toolbar.Init(builder.Toolbar, this);

            for (int i = 0; i < 2; i++)
            {
                var item = Toolbar.GetItemAtIndex(i);
                if (item == null)
                    continue;
                m_items.RemoveAt(i);
                m_items.Insert(i, ToolbarItem.FromItem(item));
            }
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

			
			ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
			ResourceSink.RequiredInputChanged += Receiver_RequiredInputChanged;
			ResourceSink.Update();

            m_fieldShape = GetHkShape();

            OnClose += delegate(MyEntity self)
            {
                m_fieldShape.RemoveReference();
            };

            m_gizmoColor = MySandboxGame.IsDirectX11 ? new Vector4(0.35f, 0, 0, 0.5f) : new Vector4(0.1f, 0, 0, 0.1f);

        }
Beispiel #26
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var medicalRoomDefinition = BlockDefinition as MyMedicalRoomDefinition;
            MyStringHash resourceSinkGroup;
            if (medicalRoomDefinition != null)
            {
                m_idleSound = new MySoundPair(medicalRoomDefinition.IdleSound);
                m_progressSound = new MySoundPair(medicalRoomDefinition.ProgressSound);
                resourceSinkGroup = MyStringHash.GetOrCompute(medicalRoomDefinition.ResourceSinkGroup);
            }
            else
            {
                m_idleSound = new MySoundPair("BlockMedical");
                m_progressSound = new MySoundPair("BlockMedicalProgress");
                resourceSinkGroup = MyStringHash.GetOrCompute("Utility");
            }

            SinkComp = new MyResourceSinkComponent();
            SinkComp.Init(
                resourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_MEDICAL_ROOM,
                () => (Enabled && IsFunctional) ? SinkComp.MaxRequiredInput : 0f);
            SinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;

            base.Init(objectBuilder, cubeGrid);
	         
            m_rechargeSocket = new MyRechargeSocket();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

            SteamUserId = (objectBuilder as MyObjectBuilder_MedicalRoom).SteamUserId;

            if (SteamUserId != 0) //backward compatibility
            {
                MyPlayer controller = Sync.Players.GetPlayerById(new MyPlayer.PlayerId(SteamUserId));
                if (controller != null)
                {
                    IDModule.Owner = controller.Identity.IdentityId;
                    IDModule.ShareMode = MyOwnershipShareModeEnum.Faction;
                }
            }
            SteamUserId = 0;

            m_takeSpawneeOwnership = (objectBuilder as MyObjectBuilder_MedicalRoom).TakeOwnership;
            m_setFactionToSpawnee = (objectBuilder as MyObjectBuilder_MedicalRoom).SetFaction;
       
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            InitializeConveyorEndpoint();
            SinkComp.Update();
			
            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(SinkComp, this));

            if (this.CubeGrid.CreatePhysics)
                Components.Add<MyRespawnComponent>(new MyRespawnComponent());

            m_healingAllowed                = medicalRoomDefinition.HealingAllowed;
            m_refuelAllowed                 = medicalRoomDefinition.RefuelAllowed;
            m_suitChangeAllowed             = medicalRoomDefinition.SuitChangeAllowed;
            m_customWardrobesEnabled        = medicalRoomDefinition.CustomWardrobesEnabled;
            m_forceSuitChangeOnRespawn      = medicalRoomDefinition.ForceSuitChangeOnRespawn;
            m_customWardrobeNames           = medicalRoomDefinition.CustomWardrobeNames;
            m_respawnSuitName               = medicalRoomDefinition.RespawnSuitName;
            m_spawnWithoutOxygenEnabled     = medicalRoomDefinition.SpawnWithoutOxygenEnabled;
            RespawnAllowed                  = medicalRoomDefinition.RespawnAllowed;
        }
Beispiel #27
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var beaconDefinition = BlockDefinition as MyBeaconDefinition;
            Debug.Assert(beaconDefinition != null);

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                MyStringHash.GetOrCompute(beaconDefinition.ResourceSinkGroup),
                MyEnergyConstants.MAX_REQUIRED_POWER_BEACON,
                UpdatePowerInput);
    
            ResourceSink = sinkComp;

            RadioBroadcaster = new MyRadioBroadcaster(10000);
            if (((MyObjectBuilder_Beacon)objectBuilder).BroadcastRadius != 0)
                RadioBroadcaster.BroadcastRadius = ((MyObjectBuilder_Beacon)objectBuilder).BroadcastRadius;

            base.Init(objectBuilder, cubeGrid);

            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            sinkComp.Update();
        
            RadioBroadcaster.OnBroadcastRadiusChanged += OnBroadcastRadiusChanged;

            m_largeLight = cubeGrid.GridSizeEnum == MyCubeSize.Large;

            m_light = MyLights.AddLight();

            m_light.Start(MyLight.LightTypeEnum.PointLight, 1.5f);
            m_light.LightOwner = m_largeLight ? MyLight.LightOwnerEnum.LargeShip : MyLight.LightOwnerEnum.SmallShip;
            m_light.UseInForwardRender = true;
            m_light.Range = 1;

            m_light.GlareOn = true;
            m_light.GlareIntensity = m_largeLight ? 2 : 1;
            m_light.GlareQuerySize = m_largeLight ? 15f : 0.2f;
            m_light.GlareType = VRageRender.Lights.MyGlareTypeEnum.Distant;
            m_light.GlareMaterial = m_largeLight ? "GlareLsLight"
                                                 : "GlareSsLight";
            m_light.GlareMaxDistance = GLARE_MAX_DISTANCE;

            if (m_largeLight)
                m_lightPositionOffset = new Vector3(0f, CubeGrid.GridSize * 0.5f, 0f);
            else
                m_lightPositionOffset = Vector3.Zero;

            UpdateLightPosition();

	       
            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(ResourceSink,this));

            AnimationRunning = true;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            IsWorkingChanged += MyBeacon_IsWorkingChanged;

            ShowOnHUD = false;

            UpdateText();
        }
	    protected override void InitializeSinkComponent()
	    {
			var sinkComp = new MyResourceSinkComponent();
			sinkComp.Init(
					BlockDefinition.ResourceSinkGroup,
					CalculateRequiredPowerInputForRadius(BlockDefinition.MaxRadius),
					CalculateRequiredPowerInput);
		    ResourceSink = sinkComp;

		    if (CubeGrid.CreatePhysics)
		    {
			    ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
			    ResourceSink.RequiredInputChanged += Receiver_RequiredInputChanged;
			    ResourceSink.Update();
				AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));
		    }
	    }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                ComputeRequiredPower);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_JumpDrive;

            NeedsUpdate |= VRage.ModAPI.MyEntityUpdateEnum.BEFORE_NEXT_FRAME | VRage.ModAPI.MyEntityUpdateEnum.EACH_FRAME | VRage.ModAPI.MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_storedPower.Value = Math.Min(ob.StoredPower,BlockDefinition.PowerNeededForJump);

            m_storedJumpTarget = ob.JumpTarget;
            if (ob.JumpTarget != null)
            {
                m_jumpTarget = MySession.Static.Gpss.GetGps(ob.JumpTarget.Value);
            }

            m_jumpDistanceRatio.Value = ob.JumpRatio;
            m_isRecharging.Value = ob.Recharging;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyJumpDrive_IsWorkingChanged;

			ResourceSink.Update();
            UpdateEmissivity();
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var soundBlockDefinition = BlockDefinition as MySoundBlockDefinition;
            Debug.Assert(soundBlockDefinition != null);

            var sinkComp = new MyResourceSinkComponent();
            sinkComp.Init(
                soundBlockDefinition.ResourceSinkGroup,
                MyEnergyConstants.MAX_REQUIRED_POWER_SOUNDBLOCK,
                UpdateRequiredPowerInput);
            sinkComp.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_SoundBlock)objectBuilder;

            Volume = builder.Volume;
            Range = builder.Range;
            LoopPeriod = builder.LoopPeriod;
            if (builder.IsPlaying)
            {
                m_willStartSound = true;
            }
            InitCue(builder.CueName);

            ResourceSink.Update();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }