public void Build(MySlimBlock cubeBlock, long owner, long builder, bool requestInstant = true) { Quaternion quat = Quaternion.Identity; var orientation = cubeBlock.Orientation; Quaternion projQuat = Quaternion.Identity; Orientation.GetQuaternion(out projQuat); orientation.GetQuaternion(out quat); quat = Quaternion.Multiply(ProjectionRotationQuaternion, quat); quat = Quaternion.Multiply(projQuat, quat); var projectorGrid = CubeGrid; var projectedGrid = cubeBlock.CubeGrid; Vector3I cubeMin = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Min : cubeBlock.Position; Vector3I cubeMax = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Max : cubeBlock.Position; Vector3I min = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMin)); Vector3I max = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMax)); Vector3I pos = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeBlock.Position)); Vector3I projectedMin = new Vector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z)); Vector3I projectedMax = new Vector3I(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y), Math.Max(min.Z, max.Z)); MyCubeGrid.MyBlockLocation location = new MyCubeGrid.MyBlockLocation(cubeBlock.BlockDefinition.Id, projectedMin, projectedMax, pos, quat, 0, owner); MyObjectBuilder_CubeBlock objectBuilder = null; //Find original grid builder foreach (var blockBuilder in m_originalGridBuilder.CubeBlocks) { if ((Vector3I)blockBuilder.Min == cubeMin && blockBuilder.GetId() == cubeBlock.BlockDefinition.Id) { objectBuilder = (MyObjectBuilder_CubeBlock)blockBuilder.Clone(); objectBuilder.SetupForProjector(); } } if (objectBuilder == null) { System.Diagnostics.Debug.Fail("Original object builder could not be found! (AlexFlorea)"); objectBuilder = cubeBlock.GetObjectBuilder(); location.EntityId = MyEntityIdentifier.AllocateId(); } objectBuilder.ConstructionInventory = null; bool buildInstant = requestInstant && MySession.Static.IsAdminModeEnabled(Sync.MyId); MyMultiplayer.RaiseEvent(projectorGrid, x => x.BuildBlockRequest, cubeBlock.ColorMaskHSV.PackHSVToUint(), location, objectBuilder, builder, buildInstant, owner); HideCube(cubeBlock); }
private void AddBlocks() { Debug.Assert(m_tmpLocationsAndRefBlocks.Count == 0); Quaternion rotation; foreach (var loc in m_addLocations) { loc.Orientation.GetQuaternion(out rotation); MyCubeGrid.MyBlockLocation blockLocation = new MyCubeGrid.MyBlockLocation( loc.BlockDefinition.Id, loc.Position, loc.Position, loc.Position, rotation, MyEntityIdentifier.AllocateId(), MySession.Static.LocalPlayerId); m_tmpLocationsAndRefBlocks.Add(new Tuple <MyCubeGrid.MyBlockLocation, MySlimBlock>(blockLocation, loc.RefBlock)); } foreach (var location in m_tmpLocationsAndRefBlocks) { var block = m_grid.BuildGeneratedBlock(location.Item1, Vector3I.Zero); if (block != null) { var compound = block.FatBlock as MyCompoundCubeBlock; if (compound != null) { foreach (var blockInCompound in compound.GetBlocks()) { Quaternion q; location.Item1.Orientation.GetQuaternion(out q); MyBlockOrientation r = new MyBlockOrientation(ref q); if (blockInCompound.Orientation == r && blockInCompound.BlockDefinition.Id == location.Item1.BlockDefinition) { block = blockInCompound; break; } } } var refBlock = location.Item2; if (block != null && block.BlockDefinition.IsGeneratedBlock && refBlock != null) { block.SetGeneratedBlockIntegrity(refBlock); } } } m_tmpLocationsAndRefBlocks.Clear(); }
private void AddBlocks() { HashSet <MyCubeGrid.MyBlockLocation> locations = new HashSet <MyCubeGrid.MyBlockLocation>(); Quaternion rotation; foreach (var loc in m_addLocations) { loc.Orientation.GetQuaternion(out rotation); MyCubeGrid.MyBlockLocation blockLocation = new MyCubeGrid.MyBlockLocation( loc.BlockDefinition.Id, loc.Position, loc.Position, loc.Position, rotation, MyEntityIdentifier.AllocateId(), MySession.LocalPlayerId, MySession.LocalCharacter != null ? MySession.LocalCharacter.EntityId : 0); locations.Add(blockLocation); } foreach (var location in locations) { m_grid.BuildGeneratedBlock(location, Vector3I.Zero); } }
private void AddBlocks() { foreach (MyGeneratedBlockLocation location in this.m_addLocations) { Quaternion quaternion; location.Orientation.GetQuaternion(out quaternion); MyCubeGrid.MyBlockLocation location2 = new MyCubeGrid.MyBlockLocation(location.BlockDefinition.Id, location.Position, location.Position, location.Position, quaternion, MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.ENTITY, MyEntityIdentifier.ID_ALLOCATION_METHOD.RANDOM), MySession.Static.LocalPlayerId); m_tmpLocationsAndRefBlocks.Add(new Tuple <MyCubeGrid.MyBlockLocation, MySlimBlock>(location2, location.RefBlock)); } foreach (Tuple <MyCubeGrid.MyBlockLocation, MySlimBlock> tuple in m_tmpLocationsAndRefBlocks) { MySlimBlock block = this.m_grid.BuildGeneratedBlock(tuple.Item1, (Vector3)Vector3I.Zero); if (block != null) { MyCompoundCubeBlock fatBlock = block.FatBlock as MyCompoundCubeBlock; if (fatBlock != null) { foreach (MySlimBlock block4 in fatBlock.GetBlocks()) { Quaternion quaternion2; MyCubeGrid.MyBlockLocation location3 = tuple.Item1; location3.Orientation.GetQuaternion(out quaternion2); MyBlockOrientation orientation2 = new MyBlockOrientation(ref quaternion2); if ((block4.Orientation == orientation2) && (block4.BlockDefinition.Id == tuple.Item1.BlockDefinition)) { block = block4; break; } } } MySlimBlock generatingBlock = tuple.Item2; if (((block != null) && block.BlockDefinition.IsGeneratedBlock) && (generatingBlock != null)) { block.SetGeneratedBlockIntegrity(generatingBlock); } } } m_tmpLocationsAndRefBlocks.Clear(); }
public MySlimBlock PlaceInGrid( MyDefinitionId blockDefinitionId, MyCubeGrid currentGrid, Vector3I min, Vector3I orientationForward, Vector3I orientationUp, long playerId ) { HashSet <MyCubeGrid.MyBlockLocation> blocksBuildQueue = new HashSet <MyCubeGrid.MyBlockLocation>(); var orientation = Quaternion.CreateFromForwardUp(orientationForward, orientationUp); var myBlockLocation = new MyCubeGrid.MyBlockLocation( blockDefinitionId, min, min, min, orientation, MyEntityIdentifier.AllocateId(), playerId ); blocksBuildQueue.Add(myBlockLocation); var blockIds = currentGrid.CubeBlocks.Select(b => b.UniqueId).ToImmutableHashSet(); currentGrid.BuildBlocks(MyPlayer.SelectedColor, MyStringHash.GetOrCompute(MyPlayer.SelectedArmorSkin), blocksBuildQueue, MySession.Static.LocalCharacterEntityId, MySession.Static.LocalPlayerId); var blockIds2 = currentGrid.CubeBlocks.Select(b => b.UniqueId).ToImmutableHashSet(); var newIds = blockIds2.Except(blockIds); if (newIds.IsEmpty) { throw new InvalidOperationException("Couldn't build the block"); } if (newIds.Count > 1) { throw new InvalidOperationException("Built more than one block!"); } var id = newIds.First(); return(currentGrid.CubeBlocks.First(b => b.UniqueId == id)); }
public void Build(MySlimBlock cubeBlock, long owner, long builder, bool requestInstant = true, long builtBy = 0) { Quaternion quat = Quaternion.Identity; var orientation = cubeBlock.Orientation; Quaternion projQuat = Quaternion.Identity; Orientation.GetQuaternion(out projQuat); orientation.GetQuaternion(out quat); quat = Quaternion.Multiply(ProjectionRotationQuaternion, quat); quat = Quaternion.Multiply(projQuat, quat); var projectorGrid = CubeGrid; var projectedGrid = cubeBlock.CubeGrid; Vector3I cubeMin = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Min : cubeBlock.Position; Vector3I cubeMax = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Max : cubeBlock.Position; Vector3I min = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMin)); Vector3I max = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMax)); Vector3I pos = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeBlock.Position)); Vector3I projectedMin = new Vector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z)); Vector3I projectedMax = new Vector3I(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y), Math.Max(min.Z, max.Z)); MyCubeGrid.MyBlockLocation location = new MyCubeGrid.MyBlockLocation(cubeBlock.BlockDefinition.Id, projectedMin, projectedMax, pos, quat, 0, owner); MyObjectBuilder_CubeBlock objectBuilder = null; //Find original grid builder foreach (var blockBuilder in m_originalGridBuilder.CubeBlocks) { if ((Vector3I)blockBuilder.Min == cubeMin && blockBuilder.GetId() == cubeBlock.BlockDefinition.Id) { objectBuilder = (MyObjectBuilder_CubeBlock)blockBuilder.Clone(); objectBuilder.SetupForProjector(); } } if (objectBuilder == null) { System.Diagnostics.Debug.Fail("Original object builder could not be found! (AlexFlorea)"); objectBuilder = cubeBlock.GetObjectBuilder(); location.EntityId = MyEntityIdentifier.AllocateId(); } objectBuilder.ConstructionInventory = null; objectBuilder.BuiltBy = builtBy; bool buildInstant = requestInstant && MySession.Static.IsAdminModeEnabled(Sync.MyId); MyMultiplayer.RaiseEvent(projectorGrid, x => x.BuildBlockRequest, cubeBlock.ColorMaskHSV.PackHSVToUint(), location, objectBuilder, builder, buildInstant, owner); HideCube(cubeBlock); }
public void Build(MySlimBlock cubeBlock, long owner, long builder) { Quaternion quat = Quaternion.Identity; var orientation = cubeBlock.Orientation; Matrix local; orientation.GetMatrix(out local); var gridOrientation = m_clipboard.GetFirstGridOrientationMatrix(); if (gridOrientation != Matrix.Identity) { var afterRotation = Matrix.Multiply(local, gridOrientation); orientation = new MyBlockOrientation(ref afterRotation); } Quaternion projQuat = Quaternion.Identity; Orientation.GetQuaternion(out projQuat); orientation.GetQuaternion(out quat); quat = Quaternion.Multiply(projQuat, quat); var projectorGrid = CubeGrid; var projectedGrid = cubeBlock.CubeGrid; Vector3I cubeMin = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Min : cubeBlock.Position; Vector3I cubeMax = cubeBlock.FatBlock != null ? cubeBlock.FatBlock.Max : cubeBlock.Position; Vector3I min = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMin)); Vector3I max = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeMax)); Vector3I pos = projectorGrid.WorldToGridInteger(projectedGrid.GridIntegerToWorld(cubeBlock.Position)); Vector3I projectedMin = new Vector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z)); Vector3I projectedMax = new Vector3I(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y), Math.Max(min.Z, max.Z)); MyCubeGrid.MyBlockLocation location = new MyCubeGrid.MyBlockLocation(cubeBlock.BlockDefinition.Id, projectedMin, projectedMax, pos, quat, 0, owner, builder); MyObjectBuilder_CubeBlock objectBuilder = null; //Find original grid builder foreach (var blockBuilder in m_originalGridBuilder.CubeBlocks) { if (blockBuilder.Min == cubeMin && blockBuilder.GetId() == cubeBlock.BlockDefinition.Id) { objectBuilder = (MyObjectBuilder_CubeBlock)blockBuilder.Clone(); objectBuilder.SetupForProjector(); } } if (objectBuilder == null) { System.Diagnostics.Debug.Fail("Original object builder could not be found! (AlexFlorea)"); objectBuilder = cubeBlock.GetObjectBuilder(); location.EntityId = MyEntityIdentifier.AllocateId(); } objectBuilder.ConstructionInventory = null; projectorGrid.BuildBlock(cubeBlock.ColorMaskHSV, location, objectBuilder); HideCube(cubeBlock); }
private void BuildBlock(IMySlimBlock block, MyCubeBlock constructionBlock) { MyObjectBuilder_CubeBlock cubeBlock = block.GetObjectBuilder(); MyObjectBuilder_ProjectorBase projectorBuilder = null;// = (MyObjectBuilder_ProjectorBase)constructionBlock.GetObjectBuilderCubeBlock(); MyCubeGrid projectorGrid = null; MyCubeGrid blockGrid = (MyCubeGrid)block.CubeGrid; MyCubeBlock projector = null; foreach (var item in NaniteConstructionManager.ProjectorBlocks) { var projectorTest = item.Value as IMyProjector; if (projectorTest == null) { continue; } if (projectorTest.ProjectedGrid == null) { continue; } if (projectorTest.ProjectedGrid == block.CubeGrid) { projector = (MyCubeBlock)projectorTest; projectorGrid = projector.CubeGrid; projectorBuilder = (MyObjectBuilder_ProjectorBase)projector.GetObjectBuilderCubeBlock(); break; } } /* * Ingame.IMyGridTerminalSystem system = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)m_constructionBlock.ConstructionBlock.CubeGrid); * List<Ingame.IMyTerminalBlock> terminalBlocks = new List<Ingame.IMyTerminalBlock>(); * system.GetBlocks(terminalBlocks); * foreach(var item in terminalBlocks) * { * if (!(item is IMyFunctionalBlock) || !((IMyFunctionalBlock)item).Enabled) * continue; * * if (!(item is Ingame.IMyProjector)) * continue; * * var cube = (MyCubeBlock)item; * MyObjectBuilder_ProjectorBase testBuilder = (MyObjectBuilder_ProjectorBase)cube.GetObjectBuilderCubeBlock(); * if (testBuilder.ProjectedGrid == null) * continue; * * if(testBuilder.ProjectedGrid.DisplayName == blockGrid.DisplayName) * { * projector = cube; * projectorGrid = cube.CubeGrid; * projectorBuilder = testBuilder; * break; * } * } */ if (projectorBuilder == null) { Logging.Instance.WriteLine("PROBLEM Can not locate projector that is projecting target!"); return; } Quaternion quat = Quaternion.Identity; var orientation = block.Orientation; Matrix local; orientation.GetMatrix(out local); var gridOrientation = GetGridOrientation(projectorBuilder); if (gridOrientation != Matrix.Identity) { var afterRotation = Matrix.Multiply(local, gridOrientation); orientation = new MyBlockOrientation(ref afterRotation); } Quaternion projQuat = Quaternion.Identity; projector.Orientation.GetQuaternion(out projQuat); orientation.GetQuaternion(out quat); quat = Quaternion.Multiply(projQuat, quat); // Get real block max MyCubeBlockDefinition blockDefinition = (MyCubeBlockDefinition)block.BlockDefinition; Vector3I blockMax = block.Max; Vector3I blockMin = cubeBlock.Min; Vector3I position = block.Position; Vector3I min = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMin)); Vector3I max = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMax)); Vector3I pos = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(block.Position)); Vector3I projectedMin = new Vector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z)); Vector3I projectedMax = new Vector3I(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y), Math.Max(min.Z, max.Z)); MyCubeGrid.MyBlockLocation location = new MyCubeGrid.MyBlockLocation(blockDefinition.Id, projectedMin, projectedMax, pos, quat, 0, constructionBlock.OwnerId); /* * MyObjectBuilder_CubeGrid originalGridBuilder = (MyObjectBuilder_CubeGrid)blockGrid.GetObjectBuilder(); * MyObjectBuilder_CubeBlock objectBuilder = null; * //Find original grid builder * foreach (var blockBuilder in originalGridBuilder.CubeBlocks) * { * if (blockBuilder.GetId() == blockDefinition.Id) * { * if ((Vector3I)blockBuilder.Min == blockMin) * { * objectBuilder = (MyObjectBuilder_CubeBlock)blockBuilder.Clone(); * objectBuilder.SetupForProjector(); * } * } * } */ MyObjectBuilder_CubeBlock objectBuilder = cubeBlock; objectBuilder.SetupForProjector(); var functionalBuilder = objectBuilder as MyObjectBuilder_FunctionalBlock; if (functionalBuilder != null && !functionalBuilder.Enabled) { functionalBuilder.Enabled = true; } var terminalBuilder = objectBuilder as MyObjectBuilder_TerminalBlock; if (terminalBuilder != null) { terminalBuilder.Owner = constructionBlock.OwnerId; } var shipConnector = objectBuilder as MyObjectBuilder_ShipConnector; if (shipConnector != null) { shipConnector.Connected = false; shipConnector.ConnectedEntityId = 0; shipConnector.MasterToSlaveGrid = null; shipConnector.MasterToSlaveTransform = null; } //if (objectBuilder == null) // objectBuilder = cubeBlock; location.EntityId = 0; // MyEntityIdentifier.AllocateId(); objectBuilder.EntityId = 0; objectBuilder.ConstructionInventory = null; projector.CubeGrid.BuildBlockRequest(block.GetColorMask().PackHSVToUint(), location, objectBuilder, constructionBlock.EntityId, false, constructionBlock.OwnerId); }
private void AddBlocks() { HashSet<MyCubeGrid.MyBlockLocation> locations = new HashSet<MyCubeGrid.MyBlockLocation>(); Quaternion rotation; foreach (var loc in m_addLocations) { loc.Orientation.GetQuaternion(out rotation); MyCubeGrid.MyBlockLocation blockLocation = new MyCubeGrid.MyBlockLocation( loc.BlockDefinition.Id, loc.Position, loc.Position, loc.Position, rotation, MyEntityIdentifier.AllocateId(), MySession.LocalPlayerId); locations.Add(blockLocation); } foreach (var location in locations) m_grid.BuildGeneratedBlock(location, Vector3I.Zero); }
private void AddBlocks() { Debug.Assert(m_tmpLocationsAndRefBlocks.Count == 0); Quaternion rotation; foreach (var loc in m_addLocations) { loc.Orientation.GetQuaternion(out rotation); MyCubeGrid.MyBlockLocation blockLocation = new MyCubeGrid.MyBlockLocation( loc.BlockDefinition.Id, loc.Position, loc.Position, loc.Position, rotation, MyEntityIdentifier.AllocateId(), MySession.Static.LocalPlayerId); m_tmpLocationsAndRefBlocks.Add(new Tuple<MyCubeGrid.MyBlockLocation, MySlimBlock>(blockLocation, loc.RefBlock)); } foreach (var location in m_tmpLocationsAndRefBlocks) { var block = m_grid.BuildGeneratedBlock(location.Item1, Vector3I.Zero); if (block != null) { var compound = block.FatBlock as MyCompoundCubeBlock; if (compound != null) { foreach (var blockInCompound in compound.GetBlocks()) { Quaternion q; location.Item1.Orientation.GetQuaternion(out q); MyBlockOrientation r = new MyBlockOrientation(ref q); if (blockInCompound.Orientation == r && blockInCompound.BlockDefinition.Id == location.Item1.BlockDefinition) { block = blockInCompound; break; } } } var refBlock = location.Item2; if (block != null && block.BlockDefinition.IsGeneratedBlock && refBlock != null) block.SetGeneratedBlockIntegrity(refBlock); } } m_tmpLocationsAndRefBlocks.Clear(); }