public void Init(MyCubeBlock myBlock, ConveyorLinePosition a, ConveyorLinePosition b, MyObjectBuilder_ConveyorLine.LineType type, MyObjectBuilder_ConveyorLine.LineConductivity conductivity = MyObjectBuilder_ConveyorLine.LineConductivity.FULL) { CubeBlock = myBlock; ConnectingPosition1 = a; ConnectingPosition2 = b; // Neighbour grid position of one of the connecting positions is inside this block var linePosition = (myBlock as IMyConveyorSegmentBlock).ConveyorSegment.ConnectingPosition1.NeighbourGridPosition; ConveyorLine = myBlock.CubeGrid.GridSystems.ConveyorSystem.GetDeserializingLine(linePosition); if (ConveyorLine == null) { ConveyorLine = new MyConveyorLine(); if (IsCorner) ConveyorLine.Init(a, b, myBlock.CubeGrid, type, conductivity, CalculateCornerPosition()); else ConveyorLine.Init(a, b, myBlock.CubeGrid, type, conductivity, (Vector3I?)null); } else { Debug.Assert(ConveyorLine.Type == type, "Conveyor line type mismatch on segment deserialization"); } myBlock.SlimBlock.ComponentStack.IsFunctionalChanged += CubeBlock_IsFunctionalChanged; }
public MyUpgradableBlockComponent(MyCubeBlock parent) { Debug.Assert(parent != null); ConnectionPositions = new HashSet<ConveyorLinePosition>(); Refresh(parent); }
private static bool RemoveGenerated(HkdBreakableBody b, MyCubeBlock block) { if (MyFakes.REMOVE_GENERATED_BLOCK_FRACTURES && ContainsGenerated(block)) { if (b.BreakableShape.IsCompound()) { b.BreakableShape.GetChildren(m_tmpInfos); for (int i = 0; i < m_tmpInfos.Count; i++) { if (DontCreateFracture(m_tmpInfos[i].Shape)) { m_tmpInfos.RemoveAt(i); i--; } } if (m_tmpInfos.Count == 0) { return true; } m_tmpInfos.Clear(); } else if (DontCreateFracture(b.BreakableShape)) { return true; } } return false; }
public void Refresh(MyCubeBlock parent) { ConnectionPositions.Clear(); var positions = MyMultilineConveyorEndpoint.GetLinePositions(parent, "detector_upgrade"); foreach (var position in positions) { ConnectionPositions.Add(MyMultilineConveyorEndpoint.PositionToGridCoords(position, parent)); } }
public MyGuiScreenCubeBuilder(int scrollOffset = 0, MyCubeBlock owner = null) : base(scrollOffset, owner) { MySandboxGame.Log.WriteLine("MyGuiScreenCubeBuilder.ctor START"); Static = this; m_scrollOffset = scrollOffset / 6.5f; m_size = new Vector2(1, 1); m_canShareInput = true; m_drawEvenWithoutFocus = true; EnabledBackgroundFade = true; m_screenOwner = owner; RecreateControls(true); MySandboxGame.Log.WriteLine("MyGuiScreenCubeBuilder.ctor END"); }
public static MyFracturedPiece CreateFracturePiece(HkdBreakableBody b, ref MatrixD worldMatrix, List<MyDefinitionId> originalBlocks, MyCubeBlock block = null, bool sync = true) { System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server"); if (block != null) { if (RemoveGenerated(b, block)) { return null; } } ProfilerShort.Begin("CreateFracturePiece"); var fracturedPiece = MyFracturedPiecesManager.Static.GetPieceFromPool(0); fracturedPiece.InitFromBreakableBody(b, worldMatrix, block); fracturedPiece.NeedsUpdate |= Common.MyEntityUpdateEnum.BEFORE_NEXT_FRAME; //fracturedPiece.Physics.RigidBody.ContactPointCallbackDelay = 0; //fracturedPiece.Physics.RigidBody.ContactPointCallbackEnabled = true; ProfilerShort.End(); ProfilerShort.Begin("MyEntities.Add"); MyEntities.Add(fracturedPiece); ProfilerShort.End(); if (block == null) { fracturedPiece.OriginalBlocks.Clear(); fracturedPiece.OriginalBlocks.AddRange(originalBlocks); MyPhysicalModelDefinition def; if(MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(originalBlocks[0], out def)) fracturedPiece.Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId; } if (sync) MySyncDestructions.CreateFracturePiece((Sandbox.Common.ObjectBuilders.MyObjectBuilder_FracturedPiece)fracturedPiece.GetObjectBuilder()); return fracturedPiece; }
public static MyFracturedPiece CreateFracturePiece(HkdBreakableBody b, ref MatrixD worldMatrix, List<MyDefinitionId> originalBlocks, MyCubeBlock block = null, bool sync = true) { System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server"); if (IsBodyWithoutGeneratedFracturedPieces(b, block)) return null; ProfilerShort.Begin("CreateFracturePiece"); var fracturedPiece = MyFracturedPiecesManager.Static.GetPieceFromPool(0); fracturedPiece.InitFromBreakableBody(b, worldMatrix, block); fracturedPiece.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME; //fracturedPiece.Physics.RigidBody.ContactPointCallbackDelay = 0; //fracturedPiece.Physics.RigidBody.ContactPointCallbackEnabled = true; ProfilerShort.End(); if (originalBlocks != null && originalBlocks.Count != 0) { fracturedPiece.OriginalBlocks.Clear(); fracturedPiece.OriginalBlocks.AddRange(originalBlocks); MyPhysicalModelDefinition def; if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(originalBlocks[0], out def)) fracturedPiece.Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId; } // Check valid shapes from block definitions. if (MyFakes.ENABLE_FRACTURE_PIECE_SHAPE_CHECK) fracturedPiece.DebugCheckValidShapes(); ProfilerShort.Begin("MyEntities.Add"); MyEntities.RaiseEntityCreated(fracturedPiece); MyEntities.Add(fracturedPiece); ProfilerShort.End(); return fracturedPiece; }
/// <summary> /// Returns true if the block (or any block in compound) does not generate generate fractured pieces. /// </summary> private static bool ContainsBlockWithoutGeneratedFracturedPieces(MyCubeBlock block) { if (!block.BlockDefinition.CreateFracturedPieces) return true; if (block is MyCompoundCubeBlock) { foreach (var b in (block as MyCompoundCubeBlock).GetBlocks()) if (!b.BlockDefinition.CreateFracturedPieces) return true; } if (block is MyFracturedBlock) { foreach (var def in (block as MyFracturedBlock).OriginalBlocks) if (!MyDefinitionManager.Static.GetCubeBlockDefinition(def).CreateFracturedPieces) return true; } return false; }
private void MyJumpDrive_IsWorkingChanged(MyCubeBlock obj) { CheckForAbort(); }
private static bool ContainsGenerated(MyCubeBlock block) { if (block.BlockDefinition.IsGeneratedBlock) return true; if (block is MyCompoundCubeBlock) { foreach (var b in (block as MyCompoundCubeBlock).GetBlocks()) if (b.BlockDefinition.IsGeneratedBlock) return true; } if (block is MyFracturedBlock) { foreach (var def in (block as MyFracturedBlock).OriginalBlocks) if (MyDefinitionManager.Static.GetCubeBlockDefinition(def).IsGeneratedBlock) return true; } return false; }
private void PreviousCubeBlock_IsWorkingChanged(MyCubeBlock obj) { if (!obj.IsWorking && !(obj.Closed || obj.MarkedForClose)) { RequestRelease(false); } }
public static List <CollectibleInfo> FindCollectiblesInRadius(Vector3D fromPosition, double radius, bool doRaycast = false) { Debug.Assert(m_retvalCollectibleInfos.Count == 0, "The result of the last call of FindComponentsInRadius was not cleared!"); List <MyPhysics.HitInfo> hits = new List <MyPhysics.HitInfo>(); BoundingSphereD sphere = new BoundingSphereD(fromPosition, radius); var entities = MyEntities.GetEntitiesInSphere(ref sphere); foreach (var entity in entities) { bool addCollectibleInfo = false; CollectibleInfo info = new CollectibleInfo(); MyCubeBlock block = null; MyCubeGrid grid = TryGetAsComponent(entity, out block); if (grid != null) { info.EntityId = grid.EntityId; info.DefinitionId = GetComponentId(block.SlimBlock); if (block.BlockDefinition.Components != null) { info.Amount = block.BlockDefinition.Components[0].Count; } else { Debug.Assert(false, "Block definition does not have any components!"); info.Amount = 0; } addCollectibleInfo = true; } else if (entity is MyFloatingObject) { var floatingObj = entity as MyFloatingObject; var defId = floatingObj.Item.Content.GetObjectId(); if (MyDefinitionManager.Static.GetPhysicalItemDefinition(defId).Public) { info.EntityId = floatingObj.EntityId; info.DefinitionId = defId; info.Amount = floatingObj.Item.Amount; addCollectibleInfo = true; } } if (addCollectibleInfo) { bool hitSomething = false; MyPhysics.CastRay(fromPosition, entity.WorldMatrix.Translation, hits, MyPhysics.CollisionLayers.DefaultCollisionLayer); foreach (var hit in hits) { var hitEntity = hit.HkHitInfo.GetHitEntity(); if (hitEntity == entity) { continue; } if (hitEntity is MyCharacter) { continue; } if (hitEntity is MyFracturedPiece) { continue; } if (hitEntity is MyFloatingObject) { continue; } MyCubeBlock dummy = null; if (TryGetAsComponent(hitEntity as MyEntity, out dummy) != null) { continue; } hitSomething = true; break; } if (!hitSomething) { m_retvalCollectibleInfos.Add(info); } } } entities.Clear(); return(m_retvalCollectibleInfos); }
/// <summary> /// Returns subblock data from dummy, subblock matrix can be offset (according to useOffset parameter) so the dummy position output is also provided. /// </summary> /// <returns>true when dummy is subblock otherwise false</returns> public static bool GetSubBlockDataFromDummy(MyCubeBlockDefinition ownerBlockDefinition, string dummyName, MyModelDummy dummy, bool useOffset, out MyCubeBlockDefinition subBlockDefinition, out MatrixD subBlockMatrix, out Vector3 dummyPosition) { subBlockDefinition = null; subBlockMatrix = MatrixD.Identity; dummyPosition = Vector3.Zero; if (!dummyName.ToLower().StartsWith(MyCubeBlock.DUMMY_SUBBLOCK_ID)) { return(false); } if (ownerBlockDefinition.SubBlockDefinitions == null) { return(false); } string dummyNameShort = dummyName.Substring(MyCubeBlock.DUMMY_SUBBLOCK_ID.Length); MyDefinitionId definitiondId; if (!ownerBlockDefinition.SubBlockDefinitions.TryGetValue(dummyNameShort, out definitiondId)) { Debug.Assert(false, "SubBlock definition not found!"); return(false); } MyDefinitionManager.Static.TryGetCubeBlockDefinition(definitiondId, out subBlockDefinition); if (subBlockDefinition == null) { Debug.Assert(false, "SubBlock definition not found!"); return(false); } const double dotEpsilon = 0.00000001; subBlockMatrix = MatrixD.Normalize(dummy.Matrix); Vector3I forward = Base6Directions.GetIntVector(Base6Directions.GetClosestDirection(subBlockMatrix.Forward)); double forwardDot = Vector3D.Dot(subBlockMatrix.Forward, (Vector3D)forward); if (Math.Abs(1 - forwardDot) <= dotEpsilon) { subBlockMatrix.Forward = forward; } Vector3I right = Base6Directions.GetIntVector(Base6Directions.GetClosestDirection(subBlockMatrix.Right)); double rightDot = Vector3D.Dot(subBlockMatrix.Right, (Vector3D)right); if (Math.Abs(1 - rightDot) <= dotEpsilon) { subBlockMatrix.Right = right; } Vector3I up = Base6Directions.GetIntVector(Base6Directions.GetClosestDirection(subBlockMatrix.Up)); double upDot = Vector3D.Dot(subBlockMatrix.Up, (Vector3D)up); if (Math.Abs(1 - upDot) <= dotEpsilon) { subBlockMatrix.Up = up; } dummyPosition = subBlockMatrix.Translation; if (useOffset) { Vector3 offset = MyCubeBlock.GetBlockGridOffset(subBlockDefinition); subBlockMatrix.Translation -= Vector3D.TransformNormal(offset, subBlockMatrix); } return(true); }
private void MySpaceBall_IsWorkingChanged(MyCubeBlock obj) { UpdateRadios(IsWorking); }
private void RemoveEffectFromBlock(MyCubeBlock block) { foreach (var upgrade in m_upgrades) { float valFloat; double val; if (block.UpgradeValues.TryGetValue(upgrade.UpgradeType, out valFloat)) { val = valFloat; if (upgrade.ModifierType == MyUpgradeModifierType.Additive) { val -= upgrade.Modifier; if (val < 0f) { val = 0f; Debug.Fail("Additive modifier cannot be negative!"); } } else { val /= upgrade.Modifier; if (val < 1f) { //GR: this is caused due to numerical overflow of floats (max 7 digits for float) //Did the multiplications of val with double and then save to float //Still there are numerical incosistencies because of storing to float so compare within very small threshold if( (val + 1e-7) < 1f) Debug.Fail("Multiplicative modifier cannot be < 1.0f!"); val = 1f; } } block.UpgradeValues[upgrade.UpgradeType] = (float)val; } } block.CommitUpgradeValues(); }
void MyBatteryBlock_IsWorkingChanged(MyCubeBlock obj) { UpdateMaxOutputAndEmissivity(); PowerReceiver.Update(); }
private MyCubeGrid TryGetHostingGrid() { MyCubeBlock entity = base.Entity as MyCubeBlock; return(entity?.CubeGrid); }
public static MyCubeGrid TryGetAsComponent(MyEntity entity, out MyCubeBlock block, bool blockManipulatedEntity = true, Vector3D?hitPosition = null) { block = null; if (MyManipulationTool.IsEntityManipulated(entity) && blockManipulatedEntity) { return(null); } if (entity.MarkedForClose) { return(null); } var grid = entity as MyCubeGrid; if (grid == null) { return(null); } if (grid.GridSizeEnum != MyCubeSize.Small) { return(null); } MyCubeGrid returnedGrid = null; if (MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID && hitPosition != null) { var gridLocalPos = Vector3D.Transform(hitPosition.Value, grid.PositionComp.WorldMatrixNormalizedInv); Vector3I cubePosition; grid.FixTargetCube(out cubePosition, gridLocalPos / grid.GridSize); MySlimBlock slimBlock = grid.GetCubeBlock(cubePosition); if (slimBlock != null && slimBlock.IsFullIntegrity) { block = slimBlock.FatBlock; } } else { if (grid.CubeBlocks.Count != 1) { return(null); } if (grid.IsStatic) { return(null); } if (!MyCubeGrid.IsGridInCompleteState(grid)) { return(null); } if (MyCubeGridSmallToLargeConnection.Static.TestGridSmallToLargeConnection(grid)) { return(null); } var enumerator = grid.CubeBlocks.GetEnumerator(); enumerator.MoveNext(); block = enumerator.Current.FatBlock; enumerator.Dispose(); returnedGrid = grid; } if (block == null) { return(null); } if (!MyDefinitionManager.Static.IsComponentBlock(block.BlockDefinition.Id)) { return(null); } if (block.IsSubBlock) { return(null); } var subBlocks = block.GetSubBlocks(); if (subBlocks.HasValue && subBlocks.Count() > 0) { return(null); } return(returnedGrid); }
protected virtual void InitSubBlocks() { if (!MyFakes.ENABLE_SUBBLOCKS) { return; } if (m_subBlocksInitialized) { return; } // if (!Sync.IsServer) // return; try { MyCubeBlockDefinition subBlockDefinition; MatrixD subBlockMatrix; Vector3 dummyPosition; var finalModel = Sandbox.Engine.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model); foreach (var dummy in finalModel.Dummies) { if (!MyCubeBlock.GetSubBlockDataFromDummy(BlockDefinition, dummy.Key, dummy.Value, true, out subBlockDefinition, out subBlockMatrix, out dummyPosition)) { continue; } string dummyName = dummy.Key.Substring(DUMMY_SUBBLOCK_ID.Length); MySlimBlock subblock = null; MyCubeGrid subgrid = null; MySubBlockLoadInfo subBlockLoadInfo; if (m_subBlockIds.TryGetValue(dummyName, out subBlockLoadInfo)) { MyEntity entity; if (MyEntities.TryGetEntityById(subBlockLoadInfo.GridId, out entity)) { subgrid = entity as MyCubeGrid; if (subgrid != null) { subblock = subgrid.GetCubeBlock(subBlockLoadInfo.SubBlockPosition); Debug.Assert(subblock != null, "Cannot find subblock in subgrid!"); if (subblock == null) { continue; } } else { Debug.Assert(false, "Loaded entity is not grid!"); continue; } } else { Debug.Assert(false, "Cannot load subgrid!"); continue; } } if (!m_subBlocksLoaded) { if (subgrid == null) { Debug.Assert(!subBlockMatrix.IsMirrored()); Matrix subGridWorldMatrix = subBlockMatrix * PositionComp.LocalMatrix * CubeGrid.WorldMatrix; //TODO: Try to find better way how to sync entity ID of subblocks.. subgrid = MyCubeBuilder.SpawnDynamicGrid(subBlockDefinition, subGridWorldMatrix, CubeGrid.EntityId + CubeGrid.BlocksCount * 128 + SubBlocks.Count * 16); if (subgrid != null) { subblock = subgrid.GetCubeBlock(Vector3I.Zero); } } if (subgrid == null) { Debug.Assert(false, "SubGrid has not been set!"); continue; } if (subblock == null || subblock.FatBlock == null) { Debug.Assert(false, "Fatblock cannot be null for subblocks!"); continue; } } if (subblock != null) { SubBlocks.Add(dummyName, subblock); subblock.FatBlock.SubBlockName = dummyName; subblock.FatBlock.OwnerBlock = SlimBlock; subblock.FatBlock.OnClosing += SubBlock_OnClosing; Debug.Assert(SlimBlock != null); } } } finally { m_subBlockIds.Clear(); m_subBlocksInitialized = true; } }
protected int GetBlockConnectionCount(MyCubeBlock cubeBlock) { int count = 0; foreach (var value in m_connectedBlocks.Values) { if (value == cubeBlock) { count++; } } return count; }
public void Remove(MyCubeBlock block) { bool removed = m_inventoryBlocks.Remove(block); System.Diagnostics.Debug.Assert(removed, "Double remove or removing something not added"); var handler = BlockRemoved; if (handler != null) handler(block); }
private void ConveyorSystem_BlockRemoved(MyCubeBlock obj) { m_interactedGridOwners.Remove(obj); if (m_leftShowsGrid) LeftTypeGroup_SelectedChanged(m_leftTypeGroup); if (m_rightShowsGrid) RightTypeGroup_SelectedChanged(m_rightTypeGroup); if (m_dragAndDropInfo != null) { ClearDisabledControls(); DisableInvalidWhileDragging(); } }
void MyAirVent_IsWorkingChanged(MyCubeBlock obj) { SourceComp.Enabled = IsWorking; UpdateEmissivity(); }
public MyUseObjectWardrobe(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key) : base(owner, dummyData) { Block = owner as MyCubeBlock; LocalMatrix = dummyData.Matrix; }
private bool CanAffectBlock(MyCubeBlock block) { foreach (var upgrade in m_upgrades) { if (block.UpgradeValues.ContainsKey(upgrade.UpgradeType)) { return true; } } return false; }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition, float gridScale) { if (string.IsNullOrEmpty(blockDefinition.Model)) { return; } matrices.Add(matrix); models.Add(blockDefinition.Model); var data = new MyEntitySubpart.Data(); MyCubeBlockDefinition subBlockDefinition; MatrixD subBlockMatrix; Vector3 dummyPosition; MyModel modelData = VRage.Game.Models.MyModels.GetModelOnlyData(blockDefinition.Model); modelData.Rescale(gridScale); foreach (var dummy in modelData.Dummies) { if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, dummy.Key, dummy.Value, ref data)) { // Rescale model var model = VRage.Game.Models.MyModels.GetModelOnlyData(data.File); if (model != null) { model.Rescale(gridScale); } MatrixD mCopy = MatrixD.Multiply(data.InitialTransform, matrix); matrices.Add(mCopy); models.Add(data.File); } else if (MyFakes.ENABLE_SUBBLOCKS && MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, dummy.Key, dummy.Value, false, out subBlockDefinition, out subBlockMatrix, out dummyPosition)) { if (!string.IsNullOrEmpty(subBlockDefinition.Model)) { // Rescale model var model = VRage.Game.Models.MyModels.GetModelOnlyData(subBlockDefinition.Model); if (model != null) { model.Rescale(gridScale); } // Repair subblock matrix to have int axes (because preview renderer does not allow such non integer rotation). Vector3I forward = Vector3I.Round(Vector3.DominantAxisProjection(subBlockMatrix.Forward)); Vector3I invForward = Vector3I.One - Vector3I.Abs(forward); Vector3I right = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)subBlockMatrix.Right * invForward)); Vector3I up; Vector3I.Cross(ref right, ref forward, out up); subBlockMatrix.Forward = forward; subBlockMatrix.Right = right; subBlockMatrix.Up = up; MatrixD mCopy = MatrixD.Multiply(subBlockMatrix, matrix); matrices.Add(mCopy); models.Add(subBlockDefinition.Model); } } } // Precache models for generated blocks if (MyFakes.ENABLE_GENERATED_BLOCKS && !blockDefinition.IsGeneratedBlock && blockDefinition.GeneratedBlockDefinitions != null) { foreach (var generatedBlockDefId in blockDefinition.GeneratedBlockDefinitions) { MyCubeBlockDefinition generatedBlockDef; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(generatedBlockDefId, out generatedBlockDef)) { var model = VRage.Game.Models.MyModels.GetModelOnlyData(generatedBlockDef.Model); if (model != null) { model.Rescale(gridScale); } } } } }
private void AddEffectToBlock(MyCubeBlock block) { foreach (var upgrade in m_upgrades) { float valFloat; double val; if (block.UpgradeValues.TryGetValue(upgrade.UpgradeType, out valFloat)) { val = valFloat; if (upgrade.ModifierType == MyUpgradeModifierType.Additive) { val += upgrade.Modifier; } else { val *= upgrade.Modifier; } block.UpgradeValues[upgrade.UpgradeType] = (float)val; } } block.CommitUpgradeValues(); }
void MyBatteryBlock_IsWorkingChanged(MyCubeBlock obj) { UpdateMaxOutputAndEmissivity(); ResourceSink.Update(); }
void MyUpgradeModule_IsWorkingChanged(MyCubeBlock obj) { RefreshEffects(); UpdateEmissivity(); }
public static MyCubeGrid TryGetAsComponent(MyEntity entity, out MyCubeBlock block, bool blockManipulatedEntity = true) { block = null; if (MyManipulationTool.IsEntityManipulated(entity) && blockManipulatedEntity) { return(null); } if (entity.MarkedForClose) { return(null); } var grid = entity as MyCubeGrid; if (grid == null) { return(null); } if (grid.GridSizeEnum != MyCubeSize.Small) { return(null); } if (grid.CubeBlocks.Count != 1) { return(null); } if (grid.IsStatic) { return(null); } if (!MyCubeGrid.IsGridInCompleteState(grid)) { return(null); } var enumerator = grid.CubeBlocks.GetEnumerator(); enumerator.MoveNext(); block = enumerator.Current.FatBlock; enumerator.Dispose(); if (block == null) { return(null); } if (!MyDefinitionManager.Static.IsComponentBlock(block.BlockDefinition.Id)) { return(null); } if (block.IsSubBlock) { return(null); } if (block.GetSubBlocks().Count() > 0) { return(null); } if (MyCubeGridSmallToLargeConnection.Static.TestGridSmallToLargeConnection(grid)) { return(null); } return(grid); }
public override void OnAddedToContainer() { base.OnAddedToContainer(); m_cubeBlock = Container.Entity as MyCubeBlock; }
internal void InitFromBreakableBody(HkdBreakableBody b, MatrixD worldMatrix, MyCubeBlock block) { ProfilerShort.Begin("RemoveGen&SetFixed"); OriginalBlocks.Clear(); if (block != null) { if (block is MyCompoundCubeBlock) { foreach (var block2 in (block as MyCompoundCubeBlock).GetBlocks()) { OriginalBlocks.Add(block2.BlockDefinition.Id); } } else if (block is MyFracturedBlock) { OriginalBlocks.AddRange((block as MyFracturedBlock).OriginalBlocks); } else { OriginalBlocks.Add(block.BlockDefinition.Id); } } var rigidBody = b.GetRigidBody(); bool isFixed = MyDestructionHelper.IsFixed(b.BreakableShape); if (isFixed) { rigidBody.UpdateMotionType(HkMotionType.Fixed); rigidBody.LinearVelocity = Vector3.Zero; rigidBody.AngularVelocity = Vector3.Zero; } ProfilerShort.Begin("Sync"); if (SyncFlag) { CreateSync(); } ProfilerShort.End(); PositionComp.WorldMatrix = worldMatrix; Physics.Flags = isFixed ? RigidBodyFlag.RBF_STATIC : RigidBodyFlag.RBF_DEBRIS; Physics.BreakableBody = b; rigidBody.UserObject = Physics; if (!isFixed) { rigidBody.Motion.SetDeactivationClass(HkSolverDeactivation.High); rigidBody.EnableDeactivation = true; if (MyFakes.REDUCE_FRACTURES_COUNT) { if (b.BreakableShape.Volume < 1 && MyRandom.Instance.Next(6) > 1) { rigidBody.Layer = MyFracturedPiecesManager.FakePieceLayer; } else { rigidBody.Layer = MyPhysics.DefaultCollisionLayer; } } else { rigidBody.Layer = MyPhysics.DefaultCollisionLayer; } } else { rigidBody.Layer = MyPhysics.StaticCollisionLayer; } Physics.BreakableBody.AfterReplaceBody += Physics.FracturedBody_AfterReplaceBody; if (OriginalBlocks.Count > 0) { MyPhysicalModelDefinition def; if (MyDefinitionManager.Static.TryGetDefinition <MyPhysicalModelDefinition>(OriginalBlocks[0], out def)) { Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId; } } ProfilerShort.BeginNextBlock("Enable"); Physics.Enabled = true; MyDestructionHelper.FixPosition(this); SetDataFromHavok(b.BreakableShape); var coml = b.GetRigidBody().CenterOfMassLocal; var comw = b.GetRigidBody().CenterOfMassWorld; var com = b.BreakableShape.CoM; b.GetRigidBody().CenterOfMassLocal = com; b.BreakableShape.RemoveReference(); ProfilerShort.End(); }
private void DebugDrawModelTextures(MyCubeBlock block, ref int row) { MyModel model = null; if (block != null) { model = block.Model; } if (model == null) return; row += 2; MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ * 10), "SubTypeId: " + block.BlockDefinition.Id.SubtypeName, Color.Yellow, DebugScale); MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ * 10), "Display name: " + block.BlockDefinition.DisplayNameText, Color.Yellow, DebugScale); if (block.SlimBlock.IsMultiBlockPart) { var multiblockInfo = block.CubeGrid.GetMultiBlockInfo(block.SlimBlock.MultiBlockId); if (multiblockInfo != null) MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ * 10), "Multiblock: " + multiblockInfo.MultiBlockDefinition.Id.SubtypeName + " (Id:" + block.SlimBlock.MultiBlockId + ")", Color.Yellow, DebugScale); } if (block.BlockDefinition.IsGeneratedBlock) MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ * 10), "Generated block: " + block.BlockDefinition.GeneratedBlockType, Color.Yellow, DebugScale); MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ * 10), "Asset: " + model.AssetName, Color.Yellow, DebugScale); // Enables to copy asset name to windows clipboard through * key in MyTomasInputComponent var lastIndex = model.AssetName.LastIndexOf("\\") + 1; if (lastIndex != -1 && lastIndex < model.AssetName.Length) { MyTomasInputComponent.ClipboardText = model.AssetName.Substring(lastIndex); } else { MyTomasInputComponent.ClipboardText = model.AssetName; } DebugDrawTexturesInfo(model, ref row); }
public override void OnAddedToContainer(MyComponentContainer container) { base.OnAddedToContainer(container); m_cubeBlock = Entity as MyCubeBlock; }
public MyFractureComponentBlockDebugRender(MyCubeBlock b) { m_block = b; }
private void MyShipMergeBlock_IsWorkingChanged(MyCubeBlock obj) { Debug.Assert(Physics != null || !InScene); if (Physics != null) Physics.Enabled = this.IsWorking; if (!this.IsWorking) { var otherBlock = GetOtherMergeBlock(); if (otherBlock != null) { } else if (InConstraint) RemoveConstraintInBoth(); } CheckConnectionAllowed = !this.IsWorking; CubeGrid.UpdateBlockNeighbours(this.SlimBlock); CheckEmissivity(); }
public void Add(MyCubeBlock block) { bool added = m_inventoryBlocks.Add(block); System.Diagnostics.Debug.Assert(added, "Double add"); var handler = BlockAdded; if (handler != null) handler(block); }
/// <summary> /// Returns true if the body does not generate fractured pieces. /// </summary> private static bool IsBodyWithoutGeneratedFracturedPieces(HkdBreakableBody b, MyCubeBlock block) { if (MyFakes.REMOVE_GENERATED_BLOCK_FRACTURES && (block == null || ContainsBlockWithoutGeneratedFracturedPieces(block))) { if (b.BreakableShape.IsCompound()) { Debug.Assert(m_tmpInfos.Count == 0); b.BreakableShape.GetChildren(m_tmpInfos); for (int i = m_tmpInfos.Count - 1; i >= 0; --i) { if (DontCreateFracture(m_tmpInfos[i].Shape)) m_tmpInfos.RemoveAt(i); else break; // Break because we know that there is block which creates fracture pieces and condition "m_tmpInfos.Count == 0" in bellow code cannot be true } if (m_tmpInfos.Count == 0) { return true; } m_tmpInfos.Clear(); } else if (DontCreateFracture(b.BreakableShape)) { return true; } } return false; }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition, float gridScale) { if (!string.IsNullOrEmpty(blockDefinition.Model)) { matrices.Add(matrix); models.Add(blockDefinition.Model); MyEntitySubpart.Data outData = new MyEntitySubpart.Data(); MyModel modelOnlyData = MyModels.GetModelOnlyData(blockDefinition.Model); modelOnlyData.Rescale(gridScale); foreach (KeyValuePair <string, MyModelDummy> pair in modelOnlyData.Dummies) { MyCubeBlockDefinition definition; MatrixD xd; Vector3 vector; if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, pair.Key, pair.Value, ref outData)) { MyModel model = MyModels.GetModelOnlyData(outData.File); if (model != null) { model.Rescale(gridScale); } MatrixD item = MatrixD.Multiply(outData.InitialTransform, matrix); matrices.Add(item); models.Add(outData.File); continue; } if (MyFakes.ENABLE_SUBBLOCKS && (MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, pair.Key, pair.Value, false, out definition, out xd, out vector) && !string.IsNullOrEmpty(definition.Model))) { Vector3I vectori4; MyModel model2 = MyModels.GetModelOnlyData(definition.Model); if (model2 != null) { model2.Rescale(gridScale); } Vector3I vectori = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)xd.Forward)); Vector3I vectori2 = Vector3I.One - Vector3I.Abs(vectori); Vector3I vectori3 = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)(xd.Right * vectori2))); Vector3I.Cross(ref vectori3, ref vectori, out vectori4); xd.Forward = (Vector3D)vectori; xd.Right = (Vector3D)vectori3; xd.Up = (Vector3D)vectori4; MatrixD item = MatrixD.Multiply(xd, matrix); matrices.Add(item); models.Add(definition.Model); } } if ((MyFakes.ENABLE_GENERATED_BLOCKS && !blockDefinition.IsGeneratedBlock) && (blockDefinition.GeneratedBlockDefinitions != null)) { foreach (MyDefinitionId id in blockDefinition.GeneratedBlockDefinitions) { MyCubeBlockDefinition definition2; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(id, out definition2)) { MyModel model3 = MyModels.GetModelOnlyData(definition2.Model); if (model3 != null) { model3.Rescale(gridScale); } } } } } }