/// <summary> /// Removes generated blocks in the given locations. /// </summary> protected void RemoveGeneratedBlock(MyStringId generatedBlockType, MyGeneratedBlockLocation[] locations) { if (locations == null) { return; } foreach (var location in locations) { RemoveBlock(location, null, generatedBlockType); { // Also try to postpone block remove to possible splits MyGeneratedBlockLocation locToRemove = location; locToRemove.GeneratedBlockType = generatedBlockType; m_removeLocationsForGridSplits.Add(locToRemove); } // Also process added locations if (m_addLocations.Count > 0) { // Check the same remove/add blocks m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { return(MyGeneratedBlockLocation.IsSameGeneratedBlockLocation(loc, location, generatedBlockType)); }); } } }
private void UpdateInternal() { Debug.Assert(MyFakes.ENABLE_GENERATED_BLOCKS); if (m_addLocations.Count > 0) { // Remove other grid blocks. m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { return(loc.RefBlock != null && loc.RefBlock.CubeGrid != m_grid); }); // Check if the block can be placed to grid - must be before check the same remove/add m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { return(!m_grid.CanAddCube(loc.Position, loc.Orientation, loc.BlockDefinition, ignoreSame: true)); }); // Check the same remove/add blocks m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { MyGeneratedBlockLocation?remLocSame = null; foreach (var remLoc in m_removeLocations) { if (MyGeneratedBlockLocation.IsSameGeneratedBlockLocation(loc, remLoc)) { remLocSame = remLoc; break; } } if (remLocSame.HasValue) { m_removeLocations.Remove(remLocSame.Value); return(true); } return(false); }); } if (m_removeLocations.Count > 0) { RemoveBlocks(); } if (m_addLocations.Count > 0) { AddBlocks(); } m_addLocations.Clear(); m_removeLocations.Clear(); m_removeLocationsForGridSplits.Clear(); m_splitGridInfos.Clear(); }
protected void RemoveGeneratedBlock(MyStringId generatedBlockType, List <MyGeneratedBlockLocation> locations) { if ((locations != null) && (locations.Count != 0)) { using (List <MyGeneratedBlockLocation> .Enumerator enumerator = locations.GetEnumerator()) { while (enumerator.MoveNext()) { MyGeneratedBlockLocation location; this.RemoveBlock(location, null, generatedBlockType); MyGeneratedBlockLocation item = location; item.GeneratedBlockType = generatedBlockType; this.m_removeLocationsForGridSplits.Add(item); if (this.m_addLocations.Count > 0) { this.m_addLocations.RemoveWhere(loc => MyGeneratedBlockLocation.IsSameGeneratedBlockLocation(loc, location, generatedBlockType)); } } } } }
private void UpdateInternal() { if (this.m_addLocations.Count > 0) { this.m_addLocations.RemoveWhere(loc => (loc.RefBlock != null) && !ReferenceEquals(loc.RefBlock.CubeGrid, this.m_grid)); this.m_addLocations.RemoveWhere(loc => !this.m_grid.CanAddCube(loc.Position, new MyBlockOrientation?(loc.Orientation), loc.BlockDefinition, true)); this.m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { MyGeneratedBlockLocation?nullable = null; foreach (MyGeneratedBlockLocation location in this.m_removeLocations) { if (MyGeneratedBlockLocation.IsSameGeneratedBlockLocation(loc, location)) { nullable = new MyGeneratedBlockLocation?(location); break; } } if (nullable == null) { return(false); } this.m_removeLocations.Remove(nullable.Value); return(true); }); } if (this.m_removeLocations.Count > 0) { this.RemoveBlocks(true); } if (this.m_addLocations.Count > 0) { this.AddBlocks(); } this.m_addLocations.Clear(); this.m_removeLocations.Clear(); this.m_removeLocationsForGridSplits.Clear(); this.m_splitGridInfos.Clear(); }
public virtual void UpdateAfterSimulation() { Debug.Assert(MyFakes.ENABLE_GENERATED_BLOCKS); if (m_addLocations.Count > 0) { // Remove ather grid blocks. m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { return(loc.RefBlock != null && loc.RefBlock.CubeGrid != m_grid); }); // Check the same remove/add blocks m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { MyGeneratedBlockLocation?remLocSame = null; foreach (var remLoc in m_removeLocations) { if (MyGeneratedBlockLocation.IsSameGeneratedBlockLocation(loc, remLoc)) { remLocSame = remLoc; break; } } if (remLocSame.HasValue) { m_removeLocations.Remove(remLocSame.Value); return(true); } return(false); }); // Check if there is already placed the same block in the grid m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc) { MySlimBlock existingBlock = m_grid.GetCubeBlock(loc.Position); if (existingBlock != null) { if (existingBlock.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = existingBlock.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { if (blockInCompound.BlockDefinition == loc.BlockDefinition && blockInCompound.Orientation == loc.Orientation) { return(true); } } } else { if (existingBlock.BlockDefinition == loc.BlockDefinition && existingBlock.Orientation == loc.Orientation) { return(true); } } } return(false); }); } if (m_removeLocations.Count > 0) { RemoveBlocks(); } if (m_addLocations.Count > 0) { AddBlocks(); } m_addLocations.Clear(); m_removeLocations.Clear(); m_removeLocationsForGridSplits.Clear(); m_splitGridInfos.Clear(); }