public abstract void GetMultiBlockPlacementMaterials(MyMultiBlockDefinition multiBlockDefinition);
public void StartNewGridPlacement(MyMultiBlockDefinition multiCubeBlockDefinition, Matrix rotationMatrix, bool isStatic) { Debug.Assert(MyFakes.ENABLE_MULTIBLOCKS); //var character = MySession.LocalCharacter; //if (character != null) //{ // character.SwitchToWeapon(null); //} var gridBuilder = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_CubeGrid>(); gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(Vector3.Zero, rotationMatrix.Forward, rotationMatrix.Up); gridBuilder.IsStatic = isStatic; gridBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; if (multiCubeBlockDefinition.BlockDefinitions == null) { Debug.Assert(false); return; } MyCubeSize? cubeSize = null; Vector3I min = Vector3I.MaxValue; Vector3I max = Vector3I.MinValue; foreach (var multiBlockPartDefinition in multiCubeBlockDefinition.BlockDefinitions) { MyCubeBlockDefinition blockDefinition; MyDefinitionManager.Static.TryGetCubeBlockDefinition(multiBlockPartDefinition.Id, out blockDefinition); if (blockDefinition == null) { Debug.Assert(false); continue; } if (cubeSize == null) { cubeSize = blockDefinition.CubeSize; } else if (cubeSize.Value != blockDefinition.CubeSize) { Debug.Assert(false, "Blocks with different sizes cannot be in multi block"); continue; } MyObjectBuilder_CubeBlock blockBuilder = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(blockDefinition.Id) as MyObjectBuilder_CubeBlock; blockBuilder.Orientation = Base6Directions.GetOrientation(multiBlockPartDefinition.Forward, multiBlockPartDefinition.Up); blockBuilder.Min = multiBlockPartDefinition.Position; blockBuilder.ColorMaskHSV = MyToolbar.ColorMaskHSV; // Compound block if (MyFakes.ENABLE_COMPOUND_BLOCKS && blockDefinition.CompoundTemplates != null && blockDefinition.CompoundTemplates.Length > 0) { MyObjectBuilder_CompoundCubeBlock compoundCBBuilder = MyCompoundCubeBlock.CreateBuilder(blockBuilder); gridBuilder.CubeBlocks.Add(compoundCBBuilder); } else { gridBuilder.CubeBlocks.Add(blockBuilder); } min = Vector3I.Min(min, multiBlockPartDefinition.Position); max = Vector3I.Max(max, multiBlockPartDefinition.Position); } if (gridBuilder.CubeBlocks.Count == 0) { Debug.Assert(false); return; } gridBuilder.GridSizeEnum = cubeSize.Value; var blockSizeInMeters = MyDefinitionManager.Static.GetCubeSize(cubeSize.Value); Vector3 gridSizeInMeters = (max - min + Vector3I.One) * blockSizeInMeters; ActivateMultiBlockCreationClipboard(gridBuilder, Vector3.Zero, IntersectionDistance); }
public void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid, MyCubeBlock fatBlock) { ProfilerShort.Begin("SlimBlock.Init(objectBuilder, ...)"); Debug.Assert(cubeGrid != null); FatBlock = fatBlock; if (objectBuilder is MyObjectBuilder_CompoundCubeBlock) BlockDefinition = MyCompoundCubeBlock.GetCompoundCubeBlockDefinition(); else if (!MyDefinitionManager.Static.TryGetCubeBlockDefinition(objectBuilder.GetId(), out BlockDefinition)) { //BlockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "StoneCube")); ProfilerShort.End(); return; } m_componentStack = new MyComponentStack(BlockDefinition, objectBuilder.IntegrityPercent, objectBuilder.BuildPercent); if (MyCubeGridDefinitions.GetCubeRotationOptions(BlockDefinition) == MyRotationOptionsEnum.None) { objectBuilder.BlockOrientation = MyBlockOrientation.Identity; } DeformationRatio = BlockDefinition.DeformationRatio; Min = objectBuilder.Min; Orientation = objectBuilder.BlockOrientation; if (!Orientation.IsValid) Orientation = MyBlockOrientation.Identity; Debug.Assert(Orientation.IsValid, "Orientation of block is not valid."); CubeGrid = cubeGrid; ColorMaskHSV = objectBuilder.ColorMaskHSV; if (BlockDefinition.CubeDefinition != null) { //Ensure we have always only one distinct orientation use Orientation = MyCubeGridDefinitions.GetTopologyUniqueOrientation(BlockDefinition.CubeDefinition.CubeTopology, Orientation); } ComputeMax(BlockDefinition, Orientation, ref Min, out Max); Position = ComputePositionInGrid(new MatrixI(Orientation), BlockDefinition, Min); if (objectBuilder.MultiBlockId != 0 && objectBuilder.MultiBlockDefinition != null && objectBuilder.MultiBlockIndex != -1) { MultiBlockDefinition = MyDefinitionManager.Static.TryGetMultiBlockDefinition(objectBuilder.MultiBlockDefinition.Value); if (MultiBlockDefinition != null) { MultiBlockId = objectBuilder.MultiBlockId; MultiBlockIndex = objectBuilder.MultiBlockIndex; } } UpdateShowParts(); if (FatBlock == null) { bool isRenderedAsModel = !String.IsNullOrEmpty(BlockDefinition.Model); bool showConstructionModel = BlockDefinition.BlockTopology == MyBlockTopology.Cube && !ShowParts; if (isRenderedAsModel || showConstructionModel) { FatBlock = new MyCubeBlock(); } } if (FatBlock != null) { ProfilerShort.Begin("FatBlock.Init(objectBuilder, ...)"); FatBlock.SlimBlock = this; FatBlock.Init(objectBuilder, cubeGrid); ProfilerShort.End(); } if (objectBuilder.ConstructionStockpile != null) { EnsureConstructionStockpileExists(); m_stockpile.Init(objectBuilder.ConstructionStockpile); } else if (objectBuilder.ConstructionInventory != null) // Backwards compatibility { EnsureConstructionStockpileExists(); m_stockpile.Init(objectBuilder.ConstructionInventory); } if (FatBlock == null || FatBlock.GetType() == typeof(MyCubeBlock)) m_objectBuilder = new MyObjectBuilder_CubeBlock(); if (MyFakes.SHOW_DAMAGE_EFFECTS && FatBlock != null && BlockDefinition.RatioEnoughForDamageEffect(BuildIntegrity / MaxIntegrity) == false && BlockDefinition.RatioEnoughForDamageEffect(Integrity / MaxIntegrity)) {//start effect if (CurrentDamage > 0.01f)//fix for weird simple blocks having FatBlock - old save? { FatBlock.SetDamageEffect(true); } } UpdateMaxDeformation(); m_builtByID = objectBuilder.BuiltBy; ProfilerShort.End(); }
/// <summary> /// Writes multiblocks (compound block and block ID) to outMultiBlocks collection with the same multiblockId. /// </summary> public static void GetBlocksInMultiBlock(MyCubeGrid grid, Vector3I minPosition, Vector3I maxPosition, MyMultiBlockDefinition multiBlockDefinition, int multiBlockId, HashSet<Tuple<MySlimBlock, ushort?>> outMultiBlocks) { Debug.Assert(multiBlockId != 0); if (multiBlockId == 0) return; Vector3I cube = minPosition; for (Vector3I.RangeIterator it = new Vector3I.RangeIterator(ref minPosition, ref maxPosition); it.IsValid(); it.GetNext(out cube)) { MySlimBlock slimBlock = grid.GetCubeBlock(cube); if (slimBlock == null) continue; MyCompoundCubeBlock compound = slimBlock.FatBlock as MyCompoundCubeBlock; if (compound != null) { m_tmpSlimBlocks.Clear(); foreach (var blockInCompound in compound.GetBlocks(m_tmpSlimBlocks)) { if (blockInCompound.MultiBlockDefinition == multiBlockDefinition && blockInCompound.MultiBlockId == multiBlockId) { ushort? blockInCompoundId = compound.GetBlockId(blockInCompound); outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, blockInCompoundId)); } } m_tmpSlimBlocks.Clear(); } else { MyFracturedBlock fracturedBlock = slimBlock.FatBlock as MyFracturedBlock; if (fracturedBlock != null) { if (fracturedBlock.IsMultiBlockPart(multiBlockDefinition.Id, multiBlockId)) outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, null)); } else { if (slimBlock.MultiBlockDefinition == multiBlockDefinition && slimBlock.MultiBlockId == multiBlockId) outMultiBlocks.Add(new Tuple<MySlimBlock, ushort?>(slimBlock, null)); } } } }
public override void GetMultiBlockPlacementMaterials(MyMultiBlockDefinition multiBlockDefinition) { }
public void StartNewGridPlacement(MyMultiBlockDefinition multiCubeBlockDefinition, Matrix rotationMatrix, bool isStatic) { var gridBuilder = CreateMultiBlockGridBuilder(multiCubeBlockDefinition, rotationMatrix, isStatic); if (gridBuilder != null) ActivateMultiBlockCreationClipboard(gridBuilder, Vector3.Zero, IntersectionDistance); }
public static void GetBlocksInMultiBlock(MyCubeGrid grid, Vector3I position, MyMultiBlockDefinition multiBlockDefinition, int multiBlockId, HashSet<Tuple<MySlimBlock, ushort?>> outMultiBlocks) { Debug.Assert(multiBlockId != 0); if (multiBlockId == 0) return; int maxSize = multiBlockDefinition.GetMaxSize(); Vector3I minPos = position - maxSize; Vector3I maxPos = position + maxSize; GetBlocksInMultiBlock(grid, minPos, maxPos, multiBlockDefinition, multiBlockId, outMultiBlocks); }
public void SetGridFromBuilder(MyMultiBlockDefinition multiBlockDefinition, MyObjectBuilder_CubeGrid grid, Vector3 dragPointDelta, float dragVectorLength) { Debug.Assert(multiBlockDefinition != null); ChangeClipboardPreview(false); m_multiBlockDefinition = multiBlockDefinition; SetGridFromBuilder(grid, dragPointDelta, dragVectorLength); ChangeClipboardPreview(true); }
public override void Deactivate(bool afterPaste = false) { m_multiBlockDefinition = null; base.Deactivate(afterPaste: afterPaste); }
protected static MyObjectBuilder_CubeGrid CreateMultiBlockGridBuilder(MyMultiBlockDefinition multiCubeBlockDefinition, Matrix rotationMatrix, Vector3D position = default(Vector3D)) { Debug.Assert(MyFakes.ENABLE_MULTIBLOCKS); var gridBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_CubeGrid>(); gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(position, rotationMatrix.Forward, rotationMatrix.Up); gridBuilder.IsStatic = false; gridBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; if (multiCubeBlockDefinition.BlockDefinitions == null) { Debug.Assert(false); return null; } MyCubeSize? cubeSize = null; Vector3I min = Vector3I.MaxValue; Vector3I max = Vector3I.MinValue; int multiblockId = MyRandom.Instance.Next(); while (multiblockId == 0) multiblockId = MyRandom.Instance.Next(); for (int i = 0; i < multiCubeBlockDefinition.BlockDefinitions.Length; ++i) { var multiBlockPartDefinition = multiCubeBlockDefinition.BlockDefinitions[i]; MyCubeBlockDefinition blockDefinition; MyDefinitionManager.Static.TryGetCubeBlockDefinition(multiBlockPartDefinition.Id, out blockDefinition); if (blockDefinition == null) { Debug.Assert(false); continue; } if (cubeSize == null) { cubeSize = blockDefinition.CubeSize; } else if (cubeSize.Value != blockDefinition.CubeSize) { Debug.Assert(false, "Blocks with different sizes cannot be in multi block"); continue; } MyObjectBuilder_CubeBlock blockBuilder = MyObjectBuilderSerializer.CreateNewObject(blockDefinition.Id) as MyObjectBuilder_CubeBlock; blockBuilder.Orientation = Base6Directions.GetOrientation(multiBlockPartDefinition.Forward, multiBlockPartDefinition.Up); blockBuilder.Min = multiBlockPartDefinition.Min; blockBuilder.ColorMaskHSV = MyPlayer.SelectedColor; blockBuilder.MultiBlockId = multiblockId; blockBuilder.MultiBlockIndex = i; blockBuilder.MultiBlockDefinition = multiCubeBlockDefinition.Id; blockBuilder.EntityId = MyEntityIdentifier.AllocateId(); // Check block on existing position bool added = false; { bool canBeAdded = true; bool isValidCompound = MyCompoundCubeBlock.IsCompoundEnabled(blockDefinition); // Find out existing multiblock foreach (var existingBlock in gridBuilder.CubeBlocks) { if (existingBlock.Min == blockBuilder.Min) { if (MyFakes.ENABLE_COMPOUND_BLOCKS && (existingBlock is MyObjectBuilder_CompoundCubeBlock)) { if (isValidCompound) { var existingCB = existingBlock as MyObjectBuilder_CompoundCubeBlock; MyObjectBuilder_CubeBlock[] blocks = new MyObjectBuilder_CubeBlock[existingCB.Blocks.Length + 1]; Array.Copy(existingCB.Blocks, blocks, existingCB.Blocks.Length); blocks[blocks.Length - 1] = blockBuilder; existingCB.Blocks = blocks; added = true; } else { Debug.Assert(false, "Block cannot be added to compound (no compound templated defined) in multiblock"); canBeAdded = false; } } else { Debug.Assert(false, "Block position already used in multiblock"); canBeAdded = false; } break; } } if (!canBeAdded) continue; } if (!added) { // Compound block if (MyFakes.ENABLE_COMPOUND_BLOCKS && MyCompoundCubeBlock.IsCompoundEnabled(blockDefinition)) { MyObjectBuilder_CompoundCubeBlock compoundCBBuilder = MyCompoundCubeBlock.CreateBuilder(blockBuilder); gridBuilder.CubeBlocks.Add(compoundCBBuilder); } else { gridBuilder.CubeBlocks.Add(blockBuilder); } } min = Vector3I.Min(min, multiBlockPartDefinition.Min); max = Vector3I.Max(max, multiBlockPartDefinition.Min); } if (gridBuilder.CubeBlocks.Count == 0) { Debug.Assert(false); return null; } gridBuilder.GridSizeEnum = cubeSize.Value; return gridBuilder; }
public override void Deactivate() { m_multiBlockDefinition = null; base.Deactivate(); }
private void ActivateMultiBlockCreationClipboard(MyMultiBlockDefinition multiBlockDefinition, MyObjectBuilder_CubeGrid grid, Vector3 centerDeltaDirection, float dragVectorLength) { if (m_multiBlockCreationClipboard.IsActive) return; MySessionComponentVoxelHand.Static.Enabled = false; m_multiBlockCreationClipboard.SetGridFromBuilder(multiBlockDefinition, grid, centerDeltaDirection, dragVectorLength); }