/// <summary> /// Writes all surrounding blocks around the given one with the given size. /// </summary> private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks) { outBlocks.Clear(); BoundingBoxD aabb = new BoundingBoxD(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2, block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2); if (block.FatBlock != null) { aabb = (BoundingBoxD)block.FatBlock.Model.BoundingBox; aabb.Translate(block.Position * block.CubeGrid.GridSize); } aabb = aabb.Transform(block.CubeGrid.WorldMatrix); aabb.Inflate(0.125); List <MyEntity> boxOverlapList = new List <MyEntity>(); MyEntities.GetElementsInBox(ref aabb, boxOverlapList); for (int i = 0; i < boxOverlapList.Count; i++) { var otherBlock = boxOverlapList[i] as MyCubeBlock; if (otherBlock != null && otherBlock.CubeGrid.IsStatic && otherBlock.CubeGrid.EnableSmallToLargeConnections && otherBlock.SlimBlock != block && otherBlock.CubeGrid != block.CubeGrid && otherBlock.CubeGrid.GridSizeEnum == cubeSizeEnum && !(otherBlock is MyCompoundCubeBlock) && !(otherBlock is MyFracturedBlock)) { outBlocks.Add(otherBlock); } } boxOverlapList.Clear(); }
public void Load(MyCubeSize cubeSize, MyObjectBuilderType typeId, string subTypeId) { CubeList.Clear(); var list = new SortedList<string, ComponentItemModel>(); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var cubeDefinitions = SpaceEngineersCore.Resources.CubeBlockDefinitions.Where(c => c.CubeSize == cubeSize); foreach (var cubeDefinition in cubeDefinitions) { var c = new ComponentItemModel { Name = cubeDefinition.DisplayNameText, TypeId = cubeDefinition.Id.TypeId, TypeIdString = cubeDefinition.Id.TypeId.ToString(), SubtypeId = cubeDefinition.Id.SubtypeName, TextureFile = (cubeDefinition.Icons == null || cubeDefinition.Icons.First() == null) ? null : SpaceEngineersCore.GetDataPathOrDefault(cubeDefinition.Icons.First(), Path.Combine(contentPath, cubeDefinition.Icons.First())), Time = TimeSpan.FromSeconds(cubeDefinition.MaxIntegrity / cubeDefinition.IntegrityPointsPerSec), Accessible = cubeDefinition.Public, Mass = SpaceEngineersApi.FetchCubeBlockMass(cubeDefinition.Id.TypeId, cubeDefinition.CubeSize, cubeDefinition.Id.SubtypeName), CubeSize = cubeDefinition.CubeSize, Size = new BindableSize3DIModel(cubeDefinition.Size), }; list.Add(c.FriendlyName + c.TypeIdString + c.SubtypeId, c); } foreach (var kvp in list) { CubeList.Add(kvp.Value); } CubeItem = CubeList.FirstOrDefault(c => c.TypeId == typeId && c.SubtypeId == subTypeId); }
public void Reset(WaypointTask holdTask, WaypointTask approachTask, WaypointTask enterTask, WaypointTask closeTask, DockTask dockTask, MyTuple <IntelItemType, long> intelKey, MyGridProgram program, MyCubeSize dockSize, IMyTerminalBlock connector, IMyTerminalBlock indicator = null) { Reset(); if (indicator != null) { Indicator = indicator; Connector = connector; } EnterHoldingPattern = holdTask; WaitForClearance = new WaitTask(); ApproachEntrance = approachTask; ApproachDock = enterTask; FinalAdjustToDock = closeTask; DockTask = dockTask; IntelKey = intelKey; DockSize = dockSize; Program = program; closeTask.Destination.MaxSpeed = 0.5f; enterTask.Destination.MaxSpeed = 5; TaskQueue.Enqueue(EnterHoldingPattern); TaskQueue.Enqueue(WaitForClearance); TaskQueue.Enqueue(ApproachEntrance); TaskQueue.Enqueue(ApproachDock); TaskQueue.Enqueue(FinalAdjustToDock); TaskQueue.Enqueue(DockTask); }
// Create additional model generators from plugins using reflection. public void CreateAdditionalModelGenerators(MyCubeSize gridSizeEnum) { Assembly[] assemblies = new Assembly[] { Assembly.GetExecutingAssembly(), MyPlugins.GameAssembly, MyPlugins.UserAssembly, }; foreach (var assembly in assemblies) { if (assembly == null) { continue; } // Lookup Type lookupType = typeof(IMyBlockAdditionalModelGenerator); IEnumerable <Type> lookupTypes = assembly.GetTypes().Where( t => lookupType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract); // Create instances foreach (var type in lookupTypes) { IMyBlockAdditionalModelGenerator generator = Activator.CreateInstance(type) as IMyBlockAdditionalModelGenerator; if (generator.Initialize(m_grid, gridSizeEnum)) { AdditionalModelGenerators.Add(generator); } else { generator.Close(); } } } }
// Create additional model generators from plugins using reflection. public void CreateAdditionalModelGenerators(MyCubeSize gridSizeEnum) { Assembly[] assemblies = new Assembly[] { Assembly.GetExecutingAssembly(), MyPlugins.GameAssembly, MyPlugins.SandboxAssembly, MyPlugins.UserAssembly, }; foreach (var assembly in assemblies) { if (assembly == null) continue; // Lookup Type lookupType = typeof(IMyBlockAdditionalModelGenerator); IEnumerable<Type> lookupTypes = assembly.GetTypes().Where( t => lookupType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract); // Create instances foreach (var type in lookupTypes) { IMyBlockAdditionalModelGenerator generator = Activator.CreateInstance(type) as IMyBlockAdditionalModelGenerator; if (generator.Initialize(m_grid, gridSizeEnum)) AdditionalModelGenerators.Add(generator); else generator.Close(); } } }
private static MyCubeBlockDefinition GetTopDef(IMyPistonBase block, MyCubeSize size) { MyPistonBaseDefinition myDef = (MyPistonBaseDefinition)((MyCubeBlock)block).BlockDefinition; MyCubeBlockDefinitionGroup defGroup = MyDefinitionManager.Static.TryGetDefinitionGroup(myDef.TopPart); return(defGroup[size]); }
public void CreateAdditionalModelGenerators(MyCubeSize gridSizeEnum) { Assembly[] first = new Assembly[] { Assembly.GetExecutingAssembly(), MyPlugins.GameAssembly, MyPlugins.SandboxAssembly }; if (MyPlugins.UserAssemblies != null) { first = first.Union <Assembly>(MyPlugins.UserAssemblies).ToArray <Assembly>(); } foreach (Assembly assembly in first) { if (assembly != null) { Type lookupType = typeof(IMyBlockAdditionalModelGenerator); using (IEnumerator <Type> enumerator = (from t in assembly.GetTypes() where lookupType.IsAssignableFrom(t) && (t.IsClass && !t.IsAbstract) select t).GetEnumerator()) { while (enumerator.MoveNext()) { IMyBlockAdditionalModelGenerator item = Activator.CreateInstance(enumerator.Current) as IMyBlockAdditionalModelGenerator; if (item.Initialize(this.m_grid, gridSizeEnum)) { this.AdditionalModelGenerators.Add(item); continue; } item.Close(); } } } } }
/// <summary>Creates a new power wheel</summary> /// <param name="wheel">The actual wheel it wraps</param> /// <param name="wb">The wheel base, to which the power wheel will be added</param> /// <param name="tform">Coordinates transformer, should be one that makes the Z axis parallel the wheel direction and Y axis the up axis</param> public PowerWheel(IMyMotorSuspension wheel, WheelBase wb, CoordinatesTransformer tform) { this.wheelBase = wb; this.CubeSize = wheel.CubeGrid.GridSizeEnum; this.Position = tform.Pos(wheel.GetPosition()); this.IsRight = RIGHT.Dot(tform.Dir(wheel.WorldMatrix.Up)) > 0; this.reverseY = UP.Dot(tform.Dir(wheel.WorldMatrix.Backward)) > 0; this.transformer = tform; this.wheel = wheel; wheel.Height = 10; this.maxY = wheel.Height; wheel.Height = -10; this.minY = wheel.Height; if (this.reverseY) { float tmp = this.minY; this.minY = -this.maxY; this.maxY = -tmp; } this.WheelSize = (wheel.Top.Max - wheel.Top.Min).X + 1; this.Mass = this.CubeSize == MyCubeSize.Small ? this.WheelSize == 1 ? 105 : (this.WheelSize == 3 ? 205 : 310) : this.WheelSize == 1 ? 420 : (this.WheelSize == 3 ? 590 : 760); // real center of rotation of the wheel this.Position += tform.Dir(wheel.WorldMatrix.Up) * wheel.CubeGrid.GridSize; this.wheelBase.AddWheel(this); }
/// <summary> /// Used in order to get material requirements from prefabs of the new station/ship and draw them to the hud /// </summary> void CreateToolTipForNewGrid(MyCubeSize size, bool isStatic) { bool isLarge = (size == MyCubeSize.Large); MyGuiControlBlockInfo usedInfo = isLarge ? m_blockInfoLarge : m_blockInfoSmall; MyGuiControlBlockInfo unusedInfo = !isLarge ? m_blockInfoLarge : m_blockInfoSmall; string prefabName; MyDefinitionManager.Static.GetBaseBlockPrefabName(size, isStatic, MySession.Static.CreativeMode, out prefabName); if (prefabName == null) { return; } var gridBuilders = MyPrefabManager.Static.GetGridPrefab(prefabName); Debug.Assert(gridBuilders != null && gridBuilders.Length > 0); if (gridBuilders == null || gridBuilders.Length == 0) { return; } MyCubeBlockDefinition blockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(gridBuilders[0].CubeBlocks[0].GetId()); if (blockDefinition != null) { usedInfo.BlockInfo.LoadDefinition(blockDefinition); usedInfo.Visible = true; } else { usedInfo.Visible = false; } unusedInfo.Visible = false; }
public void Load(MyCubeSize cubeSize, MyObjectBuilderType typeId, string subTypeId) { CubeList.Clear(); var list = new SortedList <string, ComponentItemModel>(); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var cubeDefinitions = SpaceEngineersCore.Resources.CubeBlockDefinitions.Where(c => c.CubeSize == cubeSize); foreach (var cubeDefinition in cubeDefinitions) { var c = new ComponentItemModel { Name = cubeDefinition.DisplayNameText, TypeId = cubeDefinition.Id.TypeId, TypeIdString = cubeDefinition.Id.TypeId.ToString(), SubtypeId = cubeDefinition.Id.SubtypeName, TextureFile = (cubeDefinition.Icons == null || cubeDefinition.Icons.First() == null) ? null : SpaceEngineersCore.GetDataPathOrDefault(cubeDefinition.Icons.First(), Path.Combine(contentPath, cubeDefinition.Icons.First())), Time = TimeSpan.FromSeconds(cubeDefinition.MaxIntegrity / cubeDefinition.IntegrityPointsPerSec), Accessible = cubeDefinition.Public, Mass = SpaceEngineersApi.FetchCubeBlockMass(cubeDefinition.Id.TypeId, cubeDefinition.CubeSize, cubeDefinition.Id.SubtypeName), CubeSize = cubeDefinition.CubeSize, Size = new BindableSize3DIModel(cubeDefinition.Size), }; list.Add(c.FriendlyName + c.TypeIdString + c.SubtypeId, c); } foreach (var kvp in list) { CubeList.Add(kvp.Value); } CubeItem = CubeList.FirstOrDefault(c => c.TypeId == typeId && c.SubtypeId == subTypeId); }
/// <summary>Requests the autoconnector to connect</summary> /// <param name="size">Size of the requesting connector</param> /// <param name="position">Position of the requesting connector</param> /// <param name="orientation">Orientation of the requesting connector</param> public void Connect(MyCubeSize size, Vector3D position, Vector3D orientation) { double offset = this.getOffset(size) + this.getOffset((this.frontConnector ?? this.downConnector).CubeGrid.GridSizeEnum); Vector3D finalTarget = position + (offset * orientation); this.queueConnectionRoute(finalTarget, orientation); }
public MyCubeBlockDefinition this[MyCubeSize size] { get { return m_definitions[(int)size]; } set { Debug.Assert(m_definitions[(int)size] == null, "You're overwriting an existing definition in the group. Is this what you want?"); m_definitions[(int)size] = value; } }
public MyCubeBlockDefinition this[MyCubeSize size] { get { return(m_definitions[(int)size]); } set { Debug.Assert(m_definitions[(int)size] == null, "You're overwriting an existing definition in the group. Is this what you want?"); m_definitions[(int)size] = value; } }
/// <summary> /// Returns block size. /// </summary> /// <remarks>see: http://spaceengineerswiki.com/index.php?title=FAQs /// Why are the blocks 0.5 and 2.5 meter blocks? /// </remarks> /// <param name="cubeSize"></param> /// <returns></returns> public static float ToLength(this MyCubeSize cubeSize) { switch (cubeSize) { case MyCubeSize.Large: return(SpaceEngineersCore.Resources.Definitions.Configuration.CubeSizes.Large); case MyCubeSize.Small: return(SpaceEngineersCore.Resources.Definitions.Configuration.CubeSizes.Small); } return(0f); }
private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks) { outBlocks.Clear(); BoundingBoxD boundingBox = new BoundingBoxD((Vector3D)((block.Min * block.CubeGrid.GridSize) - (block.CubeGrid.GridSize / 2f)), (block.Max * block.CubeGrid.GridSize) + (block.CubeGrid.GridSize / 2f)); if (block.FatBlock != null) { Matrix matrix; boundingBox = block.FatBlock.Model.BoundingBox; block.FatBlock.Orientation.GetMatrix(out matrix); boundingBox = boundingBox.TransformFast(matrix); boundingBox.Translate(boundingBox.Center); } boundingBox = boundingBox.TransformFast(block.CubeGrid.WorldMatrix); boundingBox.Inflate((double)0.125); List <VRage.Game.Entity.MyEntity> foundElements = new List <VRage.Game.Entity.MyEntity>(); Sandbox.Game.Entities.MyEntities.GetElementsInBox(ref boundingBox, foundElements); int num = 0; while (true) { while (true) { if (num >= foundElements.Count) { foundElements.Clear(); return; } MyCubeBlock item = foundElements[num] as MyCubeBlock; if (((item != null) && (!ReferenceEquals(item.SlimBlock, block) && (item.CubeGrid.IsStatic && (item.CubeGrid.EnableSmallToLargeConnections && (item.CubeGrid.SmallToLargeConnectionsInitialized && (!ReferenceEquals(item.CubeGrid, block.CubeGrid) && ((item.CubeGrid.GridSizeEnum == cubeSizeEnum) && !(item is MyFracturedBlock)))))))) && !item.Components.Has <MyFractureComponentBase>()) { MyCompoundCubeBlock block3 = item as MyCompoundCubeBlock; if (block3 != null) { foreach (MySlimBlock block4 in block3.GetBlocks()) { if (ReferenceEquals(block4, block)) { continue; } if (!block4.FatBlock.Components.Has <MyFractureComponentBase>()) { outBlocks.Add(block4.FatBlock); } } break; } outBlocks.Add(item); } break; } num++; } }
private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MySlimBlock> outBlocks) { outBlocks.Clear(); BoundingBoxD aabbForNeighbors = new BoundingBoxD((Vector3D)(block.Min * block.CubeGrid.GridSize), (Vector3D)(block.Max * block.CubeGrid.GridSize)); BoundingBoxD box = new BoundingBoxD((Vector3D)((block.Min * block.CubeGrid.GridSize) - (block.CubeGrid.GridSize / 2f)), (block.Max * block.CubeGrid.GridSize) + (block.CubeGrid.GridSize / 2f)); if (block.FatBlock != null) { Matrix matrix; box = block.FatBlock.Model.BoundingBox; block.FatBlock.Orientation.GetMatrix(out matrix); box = box.TransformFast(matrix); box.Translate(box.Center); } box.Inflate((double)0.125); BoundingBoxD boundingBox = box.TransformFast(block.CubeGrid.WorldMatrix); List <VRage.Game.Entity.MyEntity> foundElements = new List <VRage.Game.Entity.MyEntity>(); Sandbox.Game.Entities.MyEntities.GetElementsInBox(ref boundingBox, foundElements); for (int i = 0; i < foundElements.Count; i++) { MyCubeGrid objA = foundElements[i] as MyCubeGrid; if (((objA != null) && (objA.IsStatic && (!ReferenceEquals(objA, block.CubeGrid) && (objA.EnableSmallToLargeConnections && objA.SmallToLargeConnectionsInitialized)))) && (objA.GridSizeEnum == cubeSizeEnum)) { m_tmpSlimBlocksList.Clear(); objA.GetBlocksIntersectingOBB(box, block.CubeGrid.WorldMatrix, m_tmpSlimBlocksList); CheckNeighborBlocks(block, aabbForNeighbors, objA, m_tmpSlimBlocksList); foreach (MySlimBlock block2 in m_tmpSlimBlocksList) { if (block2.FatBlock == null) { outBlocks.Add(block2); continue; } if (!(block2.FatBlock is MyFracturedBlock) && !block2.FatBlock.Components.Has <MyFractureComponentBase>()) { if (block2.FatBlock is MyCompoundCubeBlock) { foreach (MySlimBlock block3 in (block2.FatBlock as MyCompoundCubeBlock).GetBlocks()) { if (!block3.FatBlock.Components.Has <MyFractureComponentBase>()) { outBlocks.Add(block3); } } continue; } outBlocks.Add(block2); } } m_tmpSlimBlocksList.Clear(); } } foundElements.Clear(); }
private void CreateTool(MyCubeSize size, string toolBuilderText) { var toolObject = toolBuilderText; if (size == MyCubeSize.Large) { toolObject = string.Format(toolObject, "Small"); } else { toolObject = string.Format(toolObject, "Tiny"); } MyObjectBuilder_CubeGrid cubeGrid = MyAPIGateway.Utilities.SerializeFromXML <MyObjectBuilder_CubeGrid>(toolObject); foreach (var item in cubeGrid.CubeBlocks) { item.Owner = m_constructionBlock.ConstructionBlock.OwnerId; } m_toolEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(cubeGrid); m_toolEntity.PositionComp.Scale = 0.001f; m_toolEntity.PositionComp.SetPosition(GetTargetPosition()); m_toolEntity.Physics.Enabled = false; m_toolEntity.Save = false; var toolGrid = (MyCubeGrid)m_toolEntity; toolGrid.IsSplit = true; toolGrid.IsPreview = true; List <IMySlimBlock> blocks = new List <IMySlimBlock>(); ((IMyCubeGrid)m_toolEntity).GetBlocks(blocks); foreach (var slimBlock in blocks) { if (slimBlock.FatBlock == null) { continue; } var block = slimBlock.FatBlock; if (block is Sandbox.ModAPI.Ingame.IMyShipWelder || block is Sandbox.ModAPI.Ingame.IMyShipGrinder) { MyCubeBlock toolBlock = (MyCubeBlock)block; toolBlock.IDModule.ShareMode = MyOwnershipShareModeEnum.Faction; IMyFunctionalBlock tool = (IMyFunctionalBlock)block; m_tool = tool; break; } } MyAPIGateway.Entities.AddEntity(m_toolEntity); //m_toolEntity.RemoveFromGamePruningStructure(); }
private static double GetMaxVolume(MyObjectBuilder_Base block, MyCubeSize size) { Func <MyCubeSize, MyStringHash, double> volumeFunc; Definitions.MaxInventoryVolume.TryGetValue(block.TypeId, out volumeFunc); if (volumeFunc == null) { return(0); } return(volumeFunc.Invoke(size, block.SubtypeId)); }
public void IGCUnpackInto(MyTuple <MyTuple <Vector3D, Vector3D, double, double>, MyTuple <string, long, float, int> > unpacked) { CurrentPosition = unpacked.Item1.Item1; CurrentVelocity = unpacked.Item1.Item2; CurrentCanonicalTime = TimeSpan.FromMilliseconds(unpacked.Item1.Item3); LastValidatedCanonicalTime = TimeSpan.FromMilliseconds(unpacked.Item1.Item4); DisplayName = unpacked.Item2.Item1; ID = unpacked.Item2.Item2; Radius = unpacked.Item2.Item3; CubeSize = (MyCubeSize)unpacked.Item2.Item4; }
public MyGridPlacementSettings GetGridPlacementSettings(MyCubeSize cubeSize, bool isStatic) { switch (cubeSize) { case MyCubeSize.Large: return (isStatic) ? LargeStaticGrid : LargeGrid; case MyCubeSize.Small: return (isStatic) ? SmallStaticGrid : SmallGrid; default: Debug.Fail("Invalid branch."); return LargeGrid; } }
public MyGridPlacementSettings GetGridPlacementSettings(MyCubeSize cubeSize) { switch (cubeSize) { case MyCubeSize.Large: return LargeGrid; case MyCubeSize.Small: return SmallGrid; default: Debug.Fail("Invalid branch."); return LargeGrid; } }
protected void RefreshTextField() { if (m_textField == null) { return; } var displayName = m_blueprintName; if (displayName.Length > 25) { displayName = displayName.Substring(0, 25) + "..."; } m_textField.Clear(); m_textField.AppendText("Name: " + displayName);//zxc translate m_textField.AppendLine(); MyCubeSize type = m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].GridSizeEnum; m_textField.AppendText(MyTexts.GetString(MyCommonTexts.BlockPropertiesText_Type)); if (m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].IsStatic && type == MyCubeSize.Large) { m_textField.AppendText(MyTexts.GetString(MyCommonTexts.DetailStaticGrid)); } else { if (type == MyCubeSize.Small) { m_textField.AppendText(MyTexts.GetString(MyCommonTexts.DetailSmallGrid)); } else { m_textField.AppendText(MyTexts.GetString(MyCommonTexts.DetailLargeGrid)); } } m_textField.AppendLine(); m_textField.AppendText("Number of blocks: " + GetNumberOfBlocks());//zxc translate m_textField.AppendLine(); if (MyFakes.ENABLE_BATTLE_SYSTEM) { int battlePoints = GetNumberOfBattlePoints(); if (battlePoints != 0) { m_textField.AppendText("Castle siege points: " + battlePoints);//zxc translate m_textField.AppendLine(); } } m_textField.AppendText("Author: " + m_loadedPrefab.ShipBlueprints[0].DisplayName);//zxc translate m_textField.AppendLine(); }
public static float GetBuoyancyMultiplier(Vector3D Position, MyCubeSize GridSize, long?ID = 0) { Water Water = (ID == null) ? WaterMod.Static.GetClosestWater(Position) : WaterMod.Static.Waters[ID.Value]; if (GridSize == MyCubeSize.Large) { return((1 + (-Water.GetDepth(ref Position) / 5000f)) / 50f * Water.buoyancy); } else { return((1 + (-Water.GetDepth(ref Position) / 5000f)) / 20f * Water.buoyancy); } }
public virtual bool Initialize(MyCubeGrid grid, MyCubeSize gridSizeEnum) { this.m_grid = grid; this.m_enabled = true; if (!this.IsValid(gridSizeEnum)) { return(false); } this.m_grid.OnBlockAdded += new Action <MySlimBlock>(this.Grid_OnBlockAdded); this.m_grid.OnBlockRemoved += new Action <MySlimBlock>(this.Grid_OnBlockRemoved); this.m_grid.OnGridSplit += new Action <MyCubeGrid, MyCubeGrid>(this.Grid_OnGridSplit); return(true); }
public MyGridPlacementSettings GetGridPlacementSettings(MyCubeSize cubeSize) { switch (cubeSize) { case MyCubeSize.Large: return(LargeGrid); case MyCubeSize.Small: return(SmallGrid); default: Debug.Fail("Invalid branch."); return(LargeGrid); } }
public MyGridPlacementSettings GetGridPlacementSettings(MyCubeSize cubeSize, bool isStatic) { switch (cubeSize) { case MyCubeSize.Large: return((isStatic) ? LargeStaticGrid : LargeGrid); case MyCubeSize.Small: return((isStatic) ? SmallStaticGrid : SmallGrid); default: Debug.Fail("Invalid branch."); return(LargeGrid); } }
//public static long GenerateEntityId() //{ // // Not the offical SE way of generating IDs, but its fast and we don't have to worry about a random seed. // var buffer = Guid.NewGuid().ToByteArray(); // return BitConverter.ToInt64(buffer, 0); //} #endregion #region FetchCubeBlockMass public static float FetchCubeBlockMass(MyObjectBuilderType typeId, MyCubeSize cubeSize, string subTypeid) { float mass = 0; var cubeBlockDefinition = GetCubeDefinition(typeId, cubeSize, subTypeid); if (cubeBlockDefinition != null) { return(cubeBlockDefinition.Mass); } return(mass); }
/// <summary> /// Writes all surrounding blocks around the given one with the given size. /// </summary> private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks) { outBlocks.Clear(); BoundingBoxD aabb = new BoundingBoxD(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2, block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2); if (block.FatBlock != null) { var aabbCenter = aabb.Center; aabb = (BoundingBoxD)block.FatBlock.Model.BoundingBox; Matrix m; block.FatBlock.Orientation.GetMatrix(out m); aabb = aabb.TransformFast(m); aabb.Translate(aabbCenter); } aabb = aabb.TransformFast(block.CubeGrid.WorldMatrix); aabb.Inflate(0.125); List <MyEntity> boxOverlapList = new List <MyEntity>(); MyEntities.GetElementsInBox(ref aabb, boxOverlapList); for (int i = 0; i < boxOverlapList.Count; i++) { var otherBlock = boxOverlapList[i] as MyCubeBlock; if (otherBlock != null && otherBlock.SlimBlock != block && otherBlock.CubeGrid.IsStatic && otherBlock.CubeGrid.EnableSmallToLargeConnections && otherBlock.CubeGrid.SmallToLargeConnectionsInitialized && otherBlock.CubeGrid != block.CubeGrid && otherBlock.CubeGrid.GridSizeEnum == cubeSizeEnum && !(otherBlock is MyFracturedBlock) && !(otherBlock.Components.Has <MyFractureComponentBase>())) { var compound = otherBlock as MyCompoundCubeBlock; if (compound != null) { foreach (var blockInCompound in compound.GetBlocks()) { if (blockInCompound != block && !(blockInCompound.FatBlock.Components.Has <MyFractureComponentBase>())) { outBlocks.Add(blockInCompound.FatBlock); } } } else { outBlocks.Add(otherBlock); } } } boxOverlapList.Clear(); }
void connect(List <string> args) { this.log("received a connection request"); try { MyCubeSize size = MyCubeSize.Small; Enum.TryParse(args[0], out size); var wPos = new Vector3D(double.Parse(args[1]), double.Parse(args[2]), double.Parse(args[3])); var wOrientation = new Vector3D(double.Parse(args[4]), double.Parse(args[5]), double.Parse(args[6])); long address = long.Parse(args[7]); this.connect(size, wPos, wOrientation, address); } catch (Exception e) { this.log($"could not parse value received: {e.Message}"); } }
public static float GetSizeM(this MyCubeSize size) { switch (size) { case MyCubeSize.Large: return(2.5f); case MyCubeSize.Small: return(0.5f); default: return(float.NaN); } }
/// <summary> /// Writes all surrounding blocks around the given one with the given size. /// </summary> private void GetSurroundingBlocksFromStaticGrids(MySlimBlock block, MyCubeSize cubeSizeEnum, HashSet <MyCubeBlock> outBlocks) { outBlocks.Clear(); BoundingBoxD aabb = new BoundingBoxD(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2, block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2); if (block.FatBlock != null) { aabb = (BoundingBoxD)block.FatBlock.Model.BoundingBox; aabb.Translate(block.Position * block.CubeGrid.GridSize); } aabb = aabb.Transform(block.CubeGrid.WorldMatrix); aabb.Inflate(0.125); List <MyEntity> boxOverlapList = new List <MyEntity>(); MyEntities.GetElementsInBox(ref aabb, boxOverlapList); for (int i = 0; i < boxOverlapList.Count; i++) { var otherGrid = boxOverlapList[i] as MyCubeGrid; if (otherGrid != null) { foreach (var gridBlock in otherGrid.CubeBlocks) { if (IsValidForConnection(gridBlock.FatBlock, block, cubeSizeEnum)) { if (!IsCompoundAndProcessed(gridBlock.FatBlock, block, outBlocks)) { outBlocks.Add(gridBlock.FatBlock); } } } } else { var otherBlock = boxOverlapList[i] as MyCubeBlock; if (IsValidForConnection(otherBlock, block, cubeSizeEnum)) { if (!IsCompoundAndProcessed(otherBlock, block, outBlocks)) { outBlocks.Add(otherBlock); } } } } boxOverlapList.Clear(); }
public virtual bool Initialize(MyCubeGrid grid, MyCubeSize gridSizeEnum) { m_grid = grid; m_enabled = true; if (IsValid(gridSizeEnum)) { m_grid.OnBlockAdded += Grid_OnBlockAdded; m_grid.OnBlockRemoved += Grid_OnBlockRemoved; m_grid.OnGridSplit += Grid_OnGridSplit; return(true); } return(false); }
public WeaponInformation(List <BlockSideEnum> mountPoints, MyCubeSize myCubeSize, int sizeX, int sizeY, int sizeZ, MyStringHash subtypeId, string subtypeName, MyObjectBuilderType typeId, string modName, string id, MyWeaponBlockDefinition myWeaponBlock = null, MyLargeTurretBaseDefinition myLargeTurret = null) { MountPoints = mountPoints; MyCubeSize = myCubeSize; SizeX = sizeX; SizeY = sizeY; SizeZ = sizeZ; SubtypeId = subtypeId; SubtypeName = subtypeName; TypeId = typeId; ModName = modName; Id = id; MyWeaponBlock = myWeaponBlock; MyLargeTurret = myLargeTurret; }
//public static long GenerateEntityId() //{ // // Not the offical SE way of generating IDs, but its fast and we don't have to worry about a random seed. // var buffer = Guid.NewGuid().ToByteArray(); // return BitConverter.ToInt64(buffer, 0); //} #endregion #region FetchCubeBlockMass public static float FetchCubeBlockMass(MyObjectBuilderType typeId, MyCubeSize cubeSize, string subTypeid) { float mass = 0; var cubeBlockDefinition = GetCubeDefinition(typeId, cubeSize, subTypeid); if (cubeBlockDefinition != null) { foreach (var component in cubeBlockDefinition.Components) { mass += SpaceEngineersCore.Resources.Definitions.Components.Where(c => c.Id.SubtypeId == component.Subtype).Sum(c => c.Mass) * component.Count; } } return(mass); }
void CreateGrid(MyCubeSize cubeSize, bool isStatic) { if (!MyEntities.MemoryLimitReachedReport && !MySandboxGame.IsPaused) { MySessionComponentVoxelHand.Static.Enabled = false; MyCubeBuilder.Static.StartNewGridPlacement(cubeSize, isStatic); var character = MySession.Static.LocalCharacter; Debug.Assert(character != null); if (character != null) { MyDefinitionId weaponDefinition = new MyDefinitionId(typeof(MyObjectBuilder_CubePlacer)); character.SwitchToWeapon(weaponDefinition); } } }
public void StartNewGridPlacement(MyCubeSize cubeSize, bool isStatic) { var character = MySession.LocalCharacter; if (character != null) { character.SwitchToWeapon(null); } string prefabName; MyDefinitionManager.Static.GetBaseBlockPrefabName(cubeSize, isStatic, MySession.Static.CreativeMode, out prefabName); if (prefabName == null) return; var gridBuilders = MyPrefabManager.Static.GetGridPrefab(prefabName); Debug.Assert(gridBuilders != null && gridBuilders.Count() > 0); if (gridBuilders == null || gridBuilders.Count() == 0) return; var blockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(gridBuilders[0].CubeBlocks.First().GetId()); var sizeInMeters = MyDefinitionManager.Static.GetCubeSize(cubeSize); Vector3 blockDiagonal = new Vector3(blockDefinition.Size) * sizeInMeters; Vector3 centerDisplacement; if (isStatic) centerDisplacement = Vector3.Zero; else centerDisplacement = new Vector3(0.0f, 0.55f, -1.0f) * sizeInMeters; foreach (var gridBuilder in gridBuilders) { foreach (var blockBuilder in gridBuilder.CubeBlocks) { blockBuilder.ColorMaskHSV = MyToolbar.ColorMaskHSV; } } MyCubeBuilder.Static.ActivateShipCreationClipboard(gridBuilders, centerDisplacement, 5.0f + blockDiagonal.Length() * 0.5f); }
public void StartNewGridPlacement(MyCubeSize cubeSize, bool isStatic) { var character = MySession.Static.LocalCharacter; if (character != null) { character.SwitchToWeapon(null); } string prefabName; MyDefinitionManager.Static.GetBaseBlockPrefabName(cubeSize, isStatic, MySession.Static.CreativeMode, out prefabName); if (prefabName == null) return; var gridBuilders = MyPrefabManager.Static.GetGridPrefab(prefabName); Debug.Assert(gridBuilders != null && gridBuilders.Length > 0); if (gridBuilders == null || gridBuilders.Length == 0) return; var blockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(gridBuilders[0].CubeBlocks.First().GetId()); var sizeInMeters = MyDefinitionManager.Static.GetCubeSize(cubeSize); Vector3 blockDiagonal = new Vector3(blockDefinition.Size) * sizeInMeters; Vector3 centerDisplacement; if (isStatic) centerDisplacement = Vector3.Zero; else centerDisplacement = new Vector3(0.0f, 0.55f, -1.0f) * sizeInMeters; foreach (var gridBuilder in gridBuilders) { if (gridBuilder.IsStatic && gridBuilder.PositionAndOrientation.HasValue) { gridBuilder.PositionAndOrientation = MyPositionAndOrientation.Default; } foreach (var blockBuilder in gridBuilder.CubeBlocks) { blockBuilder.ColorMaskHSV = MyPlayer.SelectedColor; } } ActivateShipCreationClipboard(gridBuilders, centerDisplacement, (character.IsUsing is MyCockpit?10f:5.0f) + blockDiagonal.Length() * 0.5f,true,cubeSize,isStatic); if (MySector.MainCamera != null) { Vector3 gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(MySector.MainCamera.Position); if (gravity.LengthSquared() > 0.01f) { m_shipCreationClipboard.EnableStationRotation = true; m_shipCreationClipboard.AlignClipboardToGravity(gravity); ShowStationRotationNotification(); } } if (isStatic) { ShowStationRotationNotification(); } else { HideStationRotationNotification(); } }
public void StartNewGridPlacement(MyCubeSize cubeSize, bool isStatic) { var character = MySession.Static.LocalCharacter; if (character != null) { character.SwitchToWeapon(null); } string prefabName; MyDefinitionManager.Static.GetBaseBlockPrefabName(cubeSize, isStatic, MySession.Static.CreativeMode, out prefabName); if (prefabName == null) return; var gridBuilders = MyPrefabManager.Static.GetGridPrefab(prefabName); Debug.Assert(gridBuilders != null && gridBuilders.Length > 0); if (gridBuilders == null || gridBuilders.Length == 0) return; foreach (var gridBuilder in gridBuilders) { if (gridBuilder.IsStatic && gridBuilder.PositionAndOrientation.HasValue) { gridBuilder.PositionAndOrientation = MyPositionAndOrientation.Default; } foreach (var blockBuilder in gridBuilder.CubeBlocks) { blockBuilder.ColorMaskHSV = MyPlayer.SelectedColor; } } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = builder as MyObjectBuilder_CubeBlockDefinition; MyDebug.AssertDebug(ob != null); this.Size = ob.Size; this.Model = ob.Model; this.UseModelIntersection = ob.UseModelIntersection; this.CubeSize = ob.CubeSize; this.ModelOffset = ob.ModelOffset; this.BlockTopology = ob.BlockTopology; this.PhysicsOption = ob.PhysicsOption; this.BlockPairName = ob.BlockPairName; this.m_center = ob.Center ?? ((Size - 1) / 2); this.m_symmetryX = ob.MirroringX; this.m_symmetryY = ob.MirroringY; this.m_symmetryZ = ob.MirroringZ; this.DeformationRatio = ob.DeformationRatio; this.SilenceableByShipSoundSystem = ob.SilenceableByShipSoundSystem; this.EdgeType = ob.EdgeType; this.AutorotateMode = ob.AutorotateMode; this.m_mirroringBlock = ob.MirroringBlock; this.MultiBlock = ob.MultiBlock; this.GuiVisible = ob.GuiVisible; this.Rotation = ob.Rotation; this.Direction = ob.Direction; this.Mirrored = ob.Mirrored; this.RandomRotation = ob.RandomRotation; this.BuildType = MyStringId.GetOrCompute(ob.BuildType != null ? ob.BuildType.ToLower() : null); this.BuildMaterial = ob.BuildMaterial != null ? ob.BuildMaterial.ToLower() : null; this.BuildProgressToPlaceGeneratedBlocks = ob.BuildProgressToPlaceGeneratedBlocks; this.GeneratedBlockType = MyStringId.GetOrCompute(ob.GeneratedBlockType != null ? ob.GeneratedBlockType.ToLower() : null); this.CompoundEnabled = ob.CompoundEnabled; this.CreateFracturedPieces = ob.CreateFracturedPieces; this.VoxelPlacement = ob.VoxelPlacement; if (ob.PhysicalMaterial != null) { this.PhysicalMaterial = MyDefinitionManager.Static.GetPhysicalMaterialDefinition(ob.PhysicalMaterial); } if (ob.Effects != null) { this.Effects = new CubeBlockEffectBase[ob.Effects.Length]; for (int i = 0; i < ob.Effects.Length; i++) { this.Effects[i] = new CubeBlockEffectBase(ob.Effects[i].Name, ob.Effects[i].ParameterMin, ob.Effects[i].ParameterMax); if (ob.Effects[i].ParticleEffects != null && ob.Effects[i].ParticleEffects.Length > 0) { this.Effects[i].ParticleEffects = new CubeBlockEffect[ob.Effects[i].ParticleEffects.Length]; for (int j = 0; j < ob.Effects[i].ParticleEffects.Length; j++) { this.Effects[i].ParticleEffects[j] = new CubeBlockEffect(ob.Effects[i].ParticleEffects[j]); } } else this.Effects[i].ParticleEffects = null; } } if (ob.DamageEffectId != 0) this.DamageEffectID = ob.DamageEffectId; this.Points = ob.Points; InitEntityComponents(ob.EntityComponents); this.CompoundTemplates = ob.CompoundTemplates; Debug.Assert(this.CompoundTemplates == null || this.CompoundTemplates.Length > 0, "Wrong compound templates, array is empty"); if (ob.SubBlockDefinitions != null) { SubBlockDefinitions = new Dictionary<string, MyDefinitionId>(); foreach (var definition in ob.SubBlockDefinitions) { MyDefinitionId defId; if (SubBlockDefinitions.TryGetValue(definition.SubBlock, out defId)) { MyDebug.AssertDebug(false, "Subblock definition already defined!"); continue; } defId = definition.Id; SubBlockDefinitions.Add(definition.SubBlock, defId); } } if (ob.BlockVariants != null) { BlockStages = new MyDefinitionId[ob.BlockVariants.Length]; for (int i = 0; i < ob.BlockVariants.Length; ++i) { BlockStages[i] = ob.BlockVariants[i]; } } var cubeDef = ob.CubeDefinition; if (cubeDef != null) { MyCubeDefinition tmp = new MyCubeDefinition(); tmp.CubeTopology = cubeDef.CubeTopology; tmp.ShowEdges = cubeDef.ShowEdges; var sides = cubeDef.Sides; tmp.Model = new string[sides.Length]; tmp.PatternSize = new Vector2I[sides.Length]; for (int j = 0; j < sides.Length; ++j) { var side = sides[j]; tmp.Model[j] = side.Model; tmp.PatternSize[j] = side.PatternSize; } this.CubeDefinition = tmp; } var components = ob.Components; MyDebug.AssertDebug(components != null); MyDebug.AssertDebug(components.Length != 0); float mass = 0.0f; float criticalIntegrity = 0f; float ownershipIntegrity = 0f; MaxIntegrityRatio = 1; if (components != null && components.Length != 0) { Components = new MyCubeBlockDefinition.Component[components.Length]; float integrity = 0.0f; int criticalTypeCounter = 0; for (int j = 0; j < components.Length; ++j) { var component = components[j]; var definition = MyDefinitionManager.Static.GetComponentDefinition(new MyDefinitionId(component.Type, component.Subtype)); MyPhysicalItemDefinition deconstructDefinition = null; if (!component.DeconstructId.IsNull() && !MyDefinitionManager.Static.TryGetPhysicalItemDefinition(component.DeconstructId, out deconstructDefinition)) deconstructDefinition = definition; if (deconstructDefinition == null) deconstructDefinition = definition; MyCubeBlockDefinition.Component tmp = new MyCubeBlockDefinition.Component() { Definition = definition, Count = component.Count, DeconstructItem = deconstructDefinition, }; if (component.Type == typeof(MyObjectBuilder_Component) && component.Subtype == "Computer") { if (ownershipIntegrity == 0) ownershipIntegrity = integrity + tmp.Definition.MaxIntegrity; } integrity += tmp.Count * tmp.Definition.MaxIntegrity; if (component.Type == ob.CriticalComponent.Type && component.Subtype == ob.CriticalComponent.Subtype) { if (criticalTypeCounter == ob.CriticalComponent.Index) { CriticalGroup = (UInt16)j; criticalIntegrity = integrity-1; } ++criticalTypeCounter; } mass += tmp.Count * tmp.Definition.Mass; Components[j] = tmp; } MaxIntegrity = integrity; IntegrityPointsPerSec = MaxIntegrity / ob.BuildTimeSeconds; DisassembleRatio = ob.DisassembleRatio; if (ob.MaxIntegrity != 0) { // If we specify MaxIntegrity for a block, it conflicts with the original integrity // So instead of overriding the MaxIntegrity, we multiply DeformationRatio so that the block // behaves as if it had the integrity that we want! MaxIntegrityRatio = ob.MaxIntegrity / MaxIntegrity; DeformationRatio = DeformationRatio / MaxIntegrityRatio; } if(!MyPerGameSettings.Destruction) Mass = mass; } else { if (ob.MaxIntegrity != 0) MaxIntegrity = ob.MaxIntegrity; } CriticalIntegrityRatio = criticalIntegrity / MaxIntegrity; OwnershipIntegrityRatio = ownershipIntegrity / MaxIntegrity; if (ob.BuildProgressModels != null) { ob.BuildProgressModels.Sort((a, b) => a.BuildPercentUpperBound.CompareTo(b.BuildPercentUpperBound)); this.BuildProgressModels = new BuildProgressModel[ob.BuildProgressModels.Count]; for (int i = 0; i < BuildProgressModels.Length; ++i) { var builderModel = ob.BuildProgressModels[i]; if (!string.IsNullOrEmpty(builderModel.File)) { this.BuildProgressModels[i] = new BuildProgressModel() { BuildRatioUpperBound = builderModel.BuildPercentUpperBound * CriticalIntegrityRatio, File = builderModel.File, RandomOrientation = builderModel.RandomOrientation }; } } } if (ob.GeneratedBlocks != null) { this.GeneratedBlockDefinitions = new MyDefinitionId[ob.GeneratedBlocks.Length]; for (int i = 0; i < ob.GeneratedBlocks.Length; ++i) { var genBlockId = ob.GeneratedBlocks[i]; Debug.Assert(!string.IsNullOrEmpty(genBlockId.SubtypeName)); Debug.Assert(!string.IsNullOrEmpty(genBlockId.TypeIdString)); this.GeneratedBlockDefinitions[i] = genBlockId; } } Skeleton = ob.Skeleton; if (Skeleton != null) { Bones = new Dictionary<Vector3I,Vector3>(ob.Skeleton.Count); foreach (var bone in Skeleton) { Bones[bone.BonePosition] = Vector3UByte.Denormalize(bone.BoneOffset, MyDefinitionManager.Static.GetCubeSize(ob.CubeSize)); } } IsAirTight = ob.IsAirTight; InitMountPoints(ob); InitPressurization(); InitNavigationInfo(ob, ob.NavigationDefinition); CheckBuildProgressModels(); // Components and CriticalComponent will be initialized elsewhere PrimarySound = new MySoundPair(ob.PrimarySound); ActionSound = new MySoundPair(ob.ActionSound); if (ob.DamagedSound!=null) DamagedSound = new MySoundPair(ob.DamagedSound); }
public static float GetShipMaxAngularVelocity(MyCubeSize size) { return size == MyCubeSize.Large ? GetLargeShipMaxAngularVelocity() : GetSmallShipMaxAngularVelocity(); }
public void StartStaticGridPlacement(MyCubeSize cubeSize, bool isStatic) { var character = MySession.Static.LocalCharacter; if (character != null) { character.SwitchToWeapon(null); } MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock"); MyCubeBlockDefinition def; MyDefinitionManager.Static.TryGetCubeBlockDefinition(id, out def); Activate(def.Id); m_stationPlacement = true; }
// TODO: deal with cubes that need to be rotated. // LargeBlockBeacon, SmallBlockBeacon, ConveyorTube, ConveyorTubeSmall public static bool ScaleShip(IMyCubeGrid shipEntity, MyCubeSize newScale) { if (shipEntity == null) return false; if (shipEntity.GridSizeEnum == newScale) { MyAPIGateway.Utilities.ShowMessage("scaledown", "Ship is already the right scale."); return true; } var grids = shipEntity.GetAttachedGrids(); var newGrids = new MyObjectBuilder_CubeGrid[grids.Count]; foreach (var cubeGrid in grids) { // ejects any player prior to deleting the grid. cubeGrid.EjectControllingPlayers(); cubeGrid.Physics.Enabled = false; } var tempList = new List<MyObjectBuilder_EntityBase>(); var gridIndex = 0; foreach (var cubeGrid in grids) { var blocks = new List<Sandbox.ModAPI.IMySlimBlock>(); cubeGrid.GetBlocks(blocks); var gridObjectBuilder = cubeGrid.GetObjectBuilder(true) as MyObjectBuilder_CubeGrid; gridObjectBuilder.EntityId = 0; Regex rgx = new Regex(Regex.Escape(gridObjectBuilder.GridSizeEnum.ToString())); var rgxScale = Regex.Escape(newScale.ToString()); gridObjectBuilder.GridSizeEnum = newScale; var removeList = new List<MyObjectBuilder_CubeBlock>(); foreach (var block in gridObjectBuilder.CubeBlocks) { MyCubeBlockDefinition defintion; string newSubType = null; if (newScale == MyCubeSize.Small && LargeToSmall.ContainsKey(block.SubtypeName)) newSubType = LargeToSmall[block.SubtypeName]; else if (newScale == MyCubeSize.Large && SmallToLarge.ContainsKey(block.SubtypeName)) newSubType = SmallToLarge[block.SubtypeName]; else { newSubType = rgx.Replace(block.SubtypeName, rgxScale, 1); // Match using the BlockPairName if there is a matching cube. if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(new MyDefinitionId(block.GetType(), block.SubtypeName), out defintion)) { var newDef = MyDefinitionManager.Static.GetAllDefinitions().Where(d => d is MyCubeBlockDefinition && ((MyCubeBlockDefinition)d).BlockPairName == defintion.BlockPairName && ((MyCubeBlockDefinition)d).CubeSize == newScale).FirstOrDefault(); if (newDef != null) newSubType = newDef.Id.SubtypeName; } } if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(new MyDefinitionId(block.GetType(), newSubType), out defintion) && defintion.CubeSize == newScale) { block.SubtypeName = newSubType; //block.EntityId = 0; } else { removeList.Add(block); } } foreach (var block in removeList) { gridObjectBuilder.CubeBlocks.Remove(block); } // This will Delete the entity and sync to all. // Using this, also works with player ejection in the same Tick. cubeGrid.SyncObject.SendCloseRequest(); var name = cubeGrid.DisplayName; MyAPIGateway.Utilities.ShowMessage("ship", "'{0}' resized.", name); tempList.Add(gridObjectBuilder); gridIndex++; } // TODO: reposition multiple grids so rotors and pistons re-attach. tempList.CreateAndSyncEntities(); return true; }
void IMyCubeBuilder.StartNewGridPlacement(MyCubeSize cubeSize, bool isStatic) { StartNewGridPlacement(cubeSize, isStatic); }
public virtual bool Initialize(MyCubeGrid grid, MyCubeSize gridSizeEnum) { m_grid = grid; m_enabled = true; if (IsValid(gridSizeEnum)) { m_grid.OnBlockAdded += Grid_OnBlockAdded; m_grid.OnBlockRemoved += Grid_OnBlockRemoved; m_grid.OnGridSplit += Grid_OnGridSplit; return true; } return false; }
protected abstract bool IsValid(MyCubeSize gridSizeEnum);
public void ActivateShipCreationClipboard(MyObjectBuilder_CubeGrid[] grids, Vector3 centerDeltaDirection, float dragVectorLength, bool creation, MyCubeSize cubeSize, bool isStatic) { if (m_shipCreationClipboard.IsActive) return; MySessionComponentVoxelHand.Static.Enabled = false; DeactivateMultiBlockClipboard(); if(creation) { m_shipCreationClipboard.CubeSize = cubeSize; m_shipCreationClipboard.IsStatic = isStatic; m_shipCreationClipboard.CreationMode = true; } m_shipCreationClipboard.SetGridFromBuilders(grids, centerDeltaDirection, dragVectorLength); }
public static bool IsGroupGridSize( GridGroup group, MyCubeSize size, bool isStatic = false ) { if( isStatic ) return group.Grids.Any( x => x?.Physics !=null && x.Physics.IsStatic ); else return group.Grids.All( x => x.GridSizeEnum == size ); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = builder as MyObjectBuilder_CubeBlockDefinition; MyDebug.AssertDebug(ob != null); this.Size = ob.Size; this.Model = ob.Model; this.UseModelIntersection = ob.UseModelIntersection; this.CubeSize = ob.CubeSize; this.ModelOffset = ob.ModelOffset; this.BlockTopology = ob.BlockTopology; this.PhysicsOption = ob.PhysicsOption; this.BlockPairName = ob.BlockPairName; this.m_center = ob.Center ?? ((Size - 1) / 2); this.m_symmetryX = ob.MirroringX; this.m_symmetryY = ob.MirroringY; this.m_symmetryZ = ob.MirroringZ; this.DeformationRatio = ob.DeformationRatio; this.EdgeType = ob.EdgeType; this.AutorotateMode = ob.AutorotateMode; this.m_mirroringBlock = ob.MirroringBlock; this.MultiBlock = ob.MultiBlock; this.GuiVisible = ob.GuiVisible; this.Rotation = ob.Rotation; this.Direction = ob.Direction; this.Mirrored = ob.Mirrored; this.RandomRotation = ob.RandomRotation; this.BuildType = ob.BuildType != null ? ob.BuildType.ToLower() : null; this.GeneratedBlockType = MyStringId.GetOrCompute(ob.GeneratedBlockType != null ? ob.GeneratedBlockType.ToLower() : null); if (ob.DamageEffectId != 0) this.DamageEffectID = ob.DamageEffectId; this.CompoundTemplates = ob.CompoundTemplates; Debug.Assert(this.CompoundTemplates == null || this.CompoundTemplates.Length > 0, "Wrong compound templates, array is empty"); if (ob.SubBlockDefinitions != null) { SubBlockDefinitions = new Dictionary<string, MyDefinitionId>(); foreach (var definition in ob.SubBlockDefinitions) { MyDefinitionId defId; if (SubBlockDefinitions.TryGetValue(definition.SubBlock, out defId)) { MyDebug.AssertDebug(false, "Subblock definition already defined!"); continue; } defId = definition.Id; SubBlockDefinitions.Add(definition.SubBlock, defId); } } if (ob.BlockVariants != null) { BlockStages = new MyDefinitionId[ob.BlockVariants.Length]; for (int i = 0; i < ob.BlockVariants.Length; ++i) { BlockStages[i] = ob.BlockVariants[i]; } } var cubeDef = ob.CubeDefinition; if (cubeDef != null) { MyCubeDefinition tmp = new MyCubeDefinition(); tmp.CubeTopology = cubeDef.CubeTopology; tmp.ShowEdges = cubeDef.ShowEdges; var sides = cubeDef.Sides; tmp.Model = new string[sides.Length]; tmp.PatternSize = new Vector2I[sides.Length]; for (int j = 0; j < sides.Length; ++j) { var side = sides[j]; tmp.Model[j] = side.Model; tmp.PatternSize[j] = side.PatternSize; } this.CubeDefinition = tmp; } var components = ob.Components; MyDebug.AssertDebug(components != null); MyDebug.AssertDebug(components.Length != 0); float mass = 0.0f; float criticalIntegrity = 0f; float ownershipIntegrity = 0f; if (components != null && components.Length != 0) { Components = new MyCubeBlockDefinition.Component[components.Length]; float integrity = 0.0f; int criticalTypeCounter = 0; for (int j = 0; j < components.Length; ++j) { var component = components[j]; MyCubeBlockDefinition.Component tmp = new MyCubeBlockDefinition.Component() { Count = component.Count, Definition = MyDefinitionManager.Static.GetComponentDefinition(new MyDefinitionId(component.Type, component.Subtype)) }; if (component.Type == typeof(MyObjectBuilder_Component) && component.Subtype == "Computer") { if (ownershipIntegrity == 0) ownershipIntegrity = integrity + tmp.Definition.MaxIntegrity; } integrity += tmp.Count * tmp.Definition.MaxIntegrity; if (component.Type == ob.CriticalComponent.Type && component.Subtype == ob.CriticalComponent.Subtype) { if (criticalTypeCounter == ob.CriticalComponent.Index) { CriticalGroup = (UInt16)j; criticalIntegrity = integrity-1; } ++criticalTypeCounter; } mass += tmp.Count * tmp.Definition.Mass; Components[j] = tmp; } MaxIntegrity = integrity; IntegrityPointsPerSec = integrity / ob.BuildTimeSeconds; DisassembleRatio = ob.DisassembleRatio; Mass = mass; } CriticalIntegrityRatio = criticalIntegrity / MaxIntegrity; OwnershipIntegrityRatio = ownershipIntegrity / MaxIntegrity; if (ob.BuildProgressModels != null) { ob.BuildProgressModels.Sort((a, b) => a.BuildPercentUpperBound.CompareTo(b.BuildPercentUpperBound)); this.BuildProgressModels = new BuildProgressModel[ob.BuildProgressModels.Count]; for (int i = 0; i < BuildProgressModels.Length; ++i) { var builderModel = ob.BuildProgressModels[i]; if (!string.IsNullOrEmpty(builderModel.File)) { this.BuildProgressModels[i] = new BuildProgressModel() { BuildRatioUpperBound = builderModel.BuildPercentUpperBound * CriticalIntegrityRatio, File = builderModel.File, RandomOrientation = builderModel.RandomOrientation }; } } } if (ob.GeneratedBlocks != null) { this.GeneratedBlockDefinitions = new MyDefinitionId[ob.GeneratedBlocks.Length]; for (int i = 0; i < ob.GeneratedBlocks.Length; ++i) { var genBlockId = ob.GeneratedBlocks[i]; Debug.Assert(!string.IsNullOrEmpty(genBlockId.SubtypeName)); Debug.Assert(!string.IsNullOrEmpty(genBlockId.TypeIdString)); this.GeneratedBlockDefinitions[i] = genBlockId; } } Skeleton = ob.Skeleton; if (Skeleton != null) { Bones = new Dictionary<Vector3I,Vector3>(ob.Skeleton.Count); foreach (var bone in Skeleton) { Bones[bone.BonePosition] = Vector3UByte.Denormalize(bone.BoneOffset, MyDefinitionManager.Static.GetCubeSize(ob.CubeSize)); } } IsAirTight = ob.IsAirTight; InitMountPoints(ob); InitPressurization(); InitNavigationInfo(ob, ob.NavigationDefinition); CheckBuildProgressModels(); // Components and CriticalComponent will be initialized elsewhere this.PrimarySound = new MySoundPair(ob.PrimarySound); }
public bool SpectatorToNextGrid(MyCubeSize size) { MyCubeGrid nextGrid = null; MyCubeGrid prevGrid = null; foreach (var entity in MyEntities.GetEntities()) { MyCubeGrid grid = entity as MyCubeGrid; if (grid != null && grid.GridSizeEnum == size) { if (m_previousSpectatorGridId == 0) { nextGrid = grid; break; } if (prevGrid != null) { nextGrid = grid; break; } if (grid.EntityId == m_previousSpectatorGridId) { prevGrid = grid; } if (nextGrid == null) { nextGrid = grid; } } } if (nextGrid == null) { return false; } BoundingSphere bSphere = nextGrid.PositionComp.WorldVolume; Vector3D rotatedFW = Vector3D.Transform(Vector3D.Forward, MySpectator.Static.Orientation); MySpectator.Static.Position = nextGrid.PositionComp.GetPosition() - rotatedFW * bSphere.Radius * 2; m_previousSpectatorGridId = nextGrid.EntityId; return true; }
/// <summary> /// Sets cube size mode. /// </summary> /// <param name="newCubeSize">New cube size mode.</param> public void SetCubeSize(MyCubeSize newCubeSize) { m_cubeSizeMode = newCubeSize; UpdateComplementBlock(); }