public override void UpdateBeforeSimulation10() { base.UpdateBeforeSimulation10(); Debug.Assert(m_wantsToDrill || Enabled); if (Parent == null || Parent.Physics == null) { return; } m_drillFrameCountdown -= 10; if (m_drillFrameCountdown > 0) { return; } m_drillFrameCountdown += MyDrillConstants.DRILL_UPDATE_INTERVAL_IN_FRAMES; m_drillBase.IgnoredEntities.Add(Parent); if (m_drillBase.Drill(collectOre: Enabled || m_wantsToCollect, performCutout: true)) { foreach (var c in CubeGrid.GetBlocks()) { if (c.FatBlock != null && c.FatBlock is MyCockpit) { ((MyCockpit)c.FatBlock).AddShake(ShakeAmount); } } } }
public override void UpdateBeforeSimulation10() { base.UpdateBeforeSimulation10(); if (!CheckUnobstructed()) { if (SafeConstraint != null) { RemoveConstraintInBoth(); } return; } if (SafeConstraint != null) { bool staticOk = this.CubeGrid.IsStatic || !m_other.CubeGrid.IsStatic; if (!staticOk || !IsWorking || !m_other.IsWorking) { return; } Debug.Assert(!m_other.CubeGrid.MarkedForClose && !CubeGrid.MarkedForClose); var mergeBlockDefinition = this.BlockDefinition as MyMergeBlockDefinition; float maxStrength = mergeBlockDefinition != null ? mergeBlockDefinition.Strength : 0.1f; float dist = (float)(WorldMatrix.Translation - m_other.WorldMatrix.Translation).Length() - CubeGrid.GridSize; if (dist > CubeGrid.GridSize * 3) { RemoveConstraintInBoth(); return; } MergeData data = new MergeData(); CalculateMergeData(ref data); (m_constraint.ConstraintData as HkMalleableConstraintData).Strength = data.ConstraintStrength; if (data.PositionOk && data.AxisOk && data.RotationOk) { if (m_frameCounter++ >= 3) { Vector3I gridOffset = CalculateOtherGridOffset(); Vector3I otherGridOffset = m_other.CalculateOtherGridOffset(); bool canMerge = this.CubeGrid.CanMergeCubes(m_other.CubeGrid, gridOffset); if (!canMerge) { if (this.CubeGrid.GridSystems.ControlSystem.IsLocallyControlled || m_other.CubeGrid.GridSystems.ControlSystem.IsLocallyControlled) { MyHud.Notifications.Add(MyNotificationSingletons.ObstructingBlockDuringMerge); } return; } var handle = BeforeMerge; if (handle != null) { BeforeMerge(); } if (Sync.IsServer) { foreach (var block in CubeGrid.GetBlocks()) { var mergeBlock = block.FatBlock as MyShipMergeBlock; if (mergeBlock != null && mergeBlock != this && mergeBlock.InConstraint) { (block.FatBlock as MyShipMergeBlock).RemoveConstraintInBoth(); } } MyCubeGrid mergedGrid = this.CubeGrid.MergeGrid_MergeBlock(m_other.CubeGrid, gridOffset); if (mergedGrid == null) { mergedGrid = m_other.CubeGrid.MergeGrid_MergeBlock(this.CubeGrid, otherGridOffset); } Debug.Assert(mergedGrid != null); RemoveConstraintInBoth(); } } } else { m_frameCounter = 0; } return; } foreach (var other in m_gridList) { if (other.MarkedForClose) { continue; } Vector3I pos = Vector3I.Zero; double dist = double.MaxValue; LineD l = new LineD(Physics.ClusterToWorld(Physics.RigidBody.Position), Physics.ClusterToWorld(Physics.RigidBody.Position) + GetMergeNormalWorld()); if (other.GetLineIntersectionExactGrid(ref l, ref pos, ref dist)) { var block = other.GetCubeBlock(pos).FatBlock as MyShipMergeBlock; if (block == null) { continue; } if (block.InConstraint || !block.IsWorking || !block.CheckUnobstructed() || block.GetMergeNormalWorld().Dot(GetMergeNormalWorld()) > 0.0f) { return; } if (!block.FriendlyWithBlock(this)) { return; } CreateConstraint(other, block); NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; m_updateBeforeFlags |= UpdateBeforeFlags.EnableConstraint; break; } } }