예제 #1
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            base.Init(builder, cubeGrid);
            m_defId = builder.GetId();
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(m_defId) as MyShipDrillDefinition;

            m_blockLength    = def.Size.Z;
            m_cubeSideLength = MyDefinitionManager.Static.GetCubeSize(def.CubeSize);

            float   inventoryVolume = def.Size.X * def.Size.Y * def.Size.Z * m_cubeSideLength * m_cubeSideLength * m_cubeSideLength * 0.5f;
            Vector3 inventorySize   = new Vector3(def.Size.X, def.Size.Y, def.Size.Z * 0.5f);

            m_inventory            = new MyInventory(inventoryVolume, inventorySize, MyInventoryFlags.CanSend, this);
            m_inventory.Constraint = new MyInventoryConstraint(MySpaceTexts.ToolTipItemFilter_AnyOre)
                                     .AddObjectBuilderType(typeof(MyObjectBuilder_Ore));

            SlimBlock.UsesDeformation  = false;
            SlimBlock.DeformationRatio = def.DeformationRatio; // 3x times harder for destruction by high speed

            m_drillBase = new MyDrillBase(this,
                                          MyDrillConstants.DRILL_SHIP_DUST_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_DUST_STONES_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_SPARKS_EFFECT,
                                          new MyDrillSensorSphere(def.SensorRadius, def.SensorOffset),
                                          new MyDrillCutOut(def.SensorOffset, def.SensorRadius),
                                          HEAD_SLOWDOWN_TIME_IN_SECONDS,
                                          floatingObjectSpawnOffset: -0.4f,
                                          floatingObjectSpawnRadius: 0.4f,
                                          sounds: m_sounds,
                                          inventoryCollectionRatio: 0.7f
                                          );
            m_drillBase.OutputInventory = m_inventory;
            m_drillBase.IgnoredEntities.Add(this);
            m_drillBase.OnWorldPositionChanged(WorldMatrix);
            m_wantsToDrill   = false;
            m_wantsToCollect = false;
            AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase));

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Defense,
                false,
                ComputeMaxRequiredPower(),
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            PowerReceiver.Update();

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

            var obDrill = (MyObjectBuilder_Drill)builder;

            m_inventory.Init(obDrill.Inventory);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            m_useConveyorSystem = obDrill.UseConveyorSystem;

            UpdateDetailedInfo();
        }
예제 #2
0
        protected override void WorldPositionChanged(object source)
        {
            base.WorldPositionChanged(source);

            // OnWorldPositionChanged() gets called from Init() as well.
            // At that point, however, DrillBase was not yet created so check this.
            if (m_drillBase != null)
                m_drillBase.OnWorldPositionChanged(WorldMatrix);
        }
예제 #3
0
        public void WorldPositionChanged(object source)
        {
            // pass logical position to drill base!
            MatrixD logicalPositioning = MatrixD.Identity;

            logicalPositioning.Right       = m_owner.WorldMatrix.Right;
            logicalPositioning.Forward     = m_owner.ShootDirection;
            logicalPositioning.Up          = Vector3D.Normalize(logicalPositioning.Right.Cross(logicalPositioning.Forward));
            logicalPositioning.Translation = m_owner.WeaponPosition.LogicalPositionWorld;
            m_drillBase.OnWorldPositionChanged(logicalPositioning);
        }
예제 #4
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_drillBase = new MyDrillBase(this,
                                          MyDrillConstants.DRILL_HAND_DUST_EFFECT,
                                          MyDrillConstants.DRILL_HAND_DUST_STONES_EFFECT,
                                          MyDrillConstants.DRILL_HAND_SPARKS_EFFECT,
                                          new MyDrillSensorRayCast(-0.5f, 1.8f),
                                          new MyDrillCutOut(0.5f, 0.7f),
                                          SPIKE_SLOWDOWN_TIME_IN_SECONDS,
                                          floatingObjectSpawnOffset: -0.25f,
                                          floatingObjectSpawnRadius: 1.4f * 0.25f,
                                          sounds: m_sounds
                                          );
            AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase));
            m_handItemDefId = objectBuilder.GetId();
            base.Init(objectBuilder);

            Init(null, "Models\\Weapons\\HandDrill.mwm", null, null, null);
            Render.CastShadows            = true;
            Render.NeedsResolveCastShadow = false;

            m_spike        = Subparts["Spike"];
            m_spikeBasePos = m_spike.PositionComp.LocalMatrix.Translation;

            m_drillBase.IgnoredEntities.Add(this);
            m_drillBase.OnWorldPositionChanged(PositionComp.WorldMatrix);

            PhysicalObject.GunEntity          = (MyObjectBuilder_EntityBase)objectBuilder.Clone();
            PhysicalObject.GunEntity.EntityId = this.EntityId;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
            m_oreDetectorBase.DetectionRadius = 20;
            m_oreDetectorBase.OnCheckControl  = OnCheckControl;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute("Utility"),
                MyEnergyConstants.REQUIRED_INPUT_HAND_DRILL,
                () => m_tryingToDrill ? SinkComp.MaxRequiredInput : 0f);
            SinkComp = sinkComp;
        }
예제 #5
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            m_defId = builder.GetId();
            var def = MyDefinitionManager.Static.GetCubeBlockDefinition(m_defId) as MyShipDrillDefinition;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                def.ResourceSinkGroup,
                ComputeMaxRequiredPower(),
                ComputeRequiredPower);
            ResourceSink = sinkComp;

            m_drillBase = new MyDrillBase(this,
                                          MyDrillConstants.DRILL_SHIP_DUST_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_DUST_STONES_EFFECT,
                                          MyDrillConstants.DRILL_SHIP_SPARKS_EFFECT,
                                          new MyDrillSensorSphere(def.SensorRadius, def.SensorOffset),
                                          new MyDrillCutOut(def.SensorOffset, def.SensorRadius),
                                          HEAD_SLOWDOWN_TIME_IN_SECONDS, -0.4f, 0.4f, 1
                                          );

            base.Init(builder, cubeGrid);

            m_blockLength    = def.Size.Z;
            m_cubeSideLength = MyDefinitionManager.Static.GetCubeSize(def.CubeSize);

            float   inventoryVolume = def.Size.X * def.Size.Y * def.Size.Z * m_cubeSideLength * m_cubeSideLength * m_cubeSideLength * 0.5f;
            Vector3 inventorySize   = new Vector3(def.Size.X, def.Size.Y, def.Size.Z * 0.5f);

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

            this.GetInventory().Constraint = new MyInventoryConstraint(MySpaceTexts.ToolTipItemFilter_AnyOre)
                                             .AddObjectBuilderType(typeof(MyObjectBuilder_Ore));

            SlimBlock.UsesDeformation  = false;
            SlimBlock.DeformationRatio = def.DeformationRatio; // 3x times harder for destruction by high speed


            m_drillBase.OutputInventory = this.GetInventory();
            m_drillBase.IgnoredEntities.Add(this);
            m_drillBase.OnWorldPositionChanged(WorldMatrix);
            m_wantsToCollect = false;
            AddDebugRenderComponent(new MyDebugRenderCompomentDrawDrillBase(m_drillBase));


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

            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            var obDrill = (MyObjectBuilder_Drill)builder;

            this.GetInventory().Init(obDrill.Inventory);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            m_useConveyorSystem.Value = obDrill.UseConveyorSystem;

            UpdateDetailedInfo();

            m_wantsToDrill    = obDrill.Enabled;
            IsWorkingChanged += OnIsWorkingChanged;

            m_drillBase.m_drillMaterial = MyStringHash.GetOrCompute("ShipDrill");
            m_drillBase.m_idleSoundLoop = new MySoundPair("ToolShipDrillIdle");
        }
예제 #6
0
 private void WorldPositionChanged(object source)
 {
     m_drillBase.OnWorldPositionChanged(PositionComp.WorldMatrix);
 }
예제 #7
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            if (objectBuilder.SubtypeName != null && objectBuilder.SubtypeName.Length > 0)
            {
                PhysicalObject = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>(objectBuilder.SubtypeName + "Item");
                m_physItemDef  = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), objectBuilder.SubtypeName + "Item"));
            }
            else
            {
                PhysicalObject = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>("HandDrillItem");
                m_physItemDef  = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), "HandDrillItem"));
            }

            (PositionComp as MyPositionComponent).WorldPositionChanged = WorldPositionChanged;

            m_handItemDefId = objectBuilder.GetId();

            var definition = MyDefinitionManager.Static.TryGetHandItemDefinition(ref m_handItemDefId);

            m_speedMultiplier = 1f / (definition as MyHandDrillDefinition).SpeedMultiplier;
            m_drillBase       = new MyDrillBase(this,
                                                MyDrillConstants.DRILL_HAND_DUST_EFFECT,
                                                MyDrillConstants.DRILL_HAND_DUST_STONES_EFFECT,
                                                MyDrillConstants.DRILL_HAND_SPARKS_EFFECT,
                                                new MyDrillSensorRayCast(-0.5f, 1.8f),
                                                new MyDrillCutOut(0.5f, 0.35f * (definition as MyHandDrillDefinition).DistanceMultiplier),
                                                SPIKE_SLOWDOWN_TIME_IN_SECONDS,
                                                floatingObjectSpawnOffset: -0.25f,
                                                floatingObjectSpawnRadius: 1.4f * 0.25f
                                                );
            m_drillBase.VoxelHarvestRatio = MyDrillConstants.VOXEL_HARVEST_RATIO * (definition as MyHandDrillDefinition).HarvestRatioMultiplier;
            AddDebugRenderComponent(new Components.MyDebugRenderCompomentDrawDrillBase(m_drillBase));
            base.Init(objectBuilder);

            var physDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(definition.PhysicalItemId);

            Init(null, physDefinition.Model, null, null, null);
            Render.CastShadows            = true;
            Render.NeedsResolveCastShadow = false;

            m_spike        = Subparts["Spike"];
            m_spikeBasePos = m_spike.PositionComp.LocalMatrix.Translation;

            m_drillBase.IgnoredEntities.Add(this);
            m_drillBase.OnWorldPositionChanged(PositionComp.WorldMatrix);

            PhysicalObject.GunEntity          = (MyObjectBuilder_EntityBase)objectBuilder.Clone();
            PhysicalObject.GunEntity.EntityId = this.EntityId;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
            m_oreDetectorBase.DetectionRadius = 20;
            m_oreDetectorBase.OnCheckControl  = OnCheckControl;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute("Utility"),
                MyEnergyConstants.REQUIRED_INPUT_HAND_DRILL,
                () => m_tryingToDrill ? SinkComp.MaxRequiredInput : 0f);
            SinkComp = sinkComp;

            foreach (ToolSound toolSound in definition.ToolSounds)
            {
                if (toolSound.type == null || toolSound.subtype == null || toolSound.sound == null)
                {
                    continue;
                }
                if (toolSound.type.Equals("Main"))
                {
                    if (toolSound.subtype.Equals("Idle"))
                    {
                        m_drillBase.m_idleSoundLoop = new MySoundPair(toolSound.sound);
                    }
                    if (toolSound.subtype.Equals("Soundset"))
                    {
                        m_drillBase.m_drillMaterial = MyStringHash.GetOrCompute(toolSound.sound);
                    }
                }
            }
        }