/// <summary> /// Tries to add the block, but skips the CanAddBlock test. /// </summary> private bool AddBlock(BlockPosition position, BlockInfo info, byte rotation) { if (info is SingleBlockInfo single) { _blocks.Add(position, BlockFactory.MakeSinglePlaced(transform, single, rotation, position)); } else { PlacedMultiBlockParent parent = BlockFactory.MakeMultiPlaced(transform, (MultiBlockInfo)info, rotation, position, out PlacedMultiBlockPart[] parts); if (parent == null) { return(false); } _blocks.Add(position, parent); foreach (PlacedMultiBlockPart part in parts) { _blocks.Add(part.Position, part); } } RealBlockCount++; if (info.Type == BlockType.Mainframe) { _mainframePosition = position; } else if (SystemFactory.IsAnySystem(info.Type)) { if (SystemFactory.IsActiveSystem(info.Type)) { _activeSystemPresent = true; } else { WeaponSystem.Type weaponType = SystemFactory.GetWeaponType(info.Type); if (weaponType != WeaponSystem.Type.None) { _weaponType = weaponType; //may or may not be first time set _weaponCount++; } } } return(true); }
/// <summary> /// Determines whether the block can be added checking whether a block is already /// present at the position and whether this new block can connect to another block. /// </summary> public bool CanAddBlock(BlockPosition position, BlockInfo info, byte rotation) { if (info.Type == BlockType.Mainframe) { if (_mainframePosition != null) { return(false); } } else if (SystemFactory.IsAnySystem(info.Type)) { if (SystemFactory.IsActiveSystem(info.Type)) { if (_activeSystemPresent) { return(false); } } else { WeaponSystem.Type weaponType = SystemFactory.GetWeaponType(info.Type); if (weaponType != WeaponSystem.Type.None && weaponType != _weaponType && _weaponType != WeaponSystem.Type.None) { return(false); } } } if (info is SingleBlockInfo single) { return(!_blocks.ContainsKey(position) && CanConnect(position, Rotation.RotateSides(single.ConnectSides, rotation))); } else { return(((MultiBlockInfo)info).GetRotatedPositions(position, rotation, out KeyValuePair <BlockPosition, BlockSides>[] positions) && !positions.Any(pair => _blocks.ContainsKey(pair.Key)) && positions.Any(pair => CanConnect(pair.Key, pair.Value))); } }