public void AlertPhysicsAround(BlockPosition pos) { for (short x = -3; x <= 3; ++x) { for (short y = -3; y <= 3; ++y) { for (short z = -3; z <= 3; ++z) { short newX = (short)(pos.x + x); short newY = (short)(pos.y + y); short newZ = (short)(pos.z + z); if (BlockInfo.RequiresPhysics(GetTile(newX, newY,newZ))) { AddActiveBlock(new BlockPosition(newX, newY, newZ)); } // Map edges should turn to water if ((GetTile(newX, newY, newZ) == Block.Air) && (newX == 0 || newZ == 0 || newX == xdim-1 || newZ == zdim-1) && (newY == ydim/2 - 1 || newY == ydim/2 - 2)) { SetTile(newX, newY, newZ, Block.Water); } } } } }
public BlockPosition(short X, short Y, short Z) { this = new BlockPosition(); // Using fields in the constructer is messy, so let .NET clear the messiness, then proceed. x = X; y = Y; z = Z; }
public DeleteTextCommand( BlockPosition begin, CharacterPosition end) : base(begin) { End = end; }
public void PlayerLocationUpdated(BlockPosition newPos) { Node goalNode = new Node(); goalNode.pos = newPos; if(playerLocation.Equals(newPos)) return; else playerLocation = newPos; _positionsToGo.Clear(); BlockPosition currPos = getCoordinates(); Node startNode = new Node(); startNode.pos = currPos; datastructures.PriortyQueue<Node> Pqueue = new datastructures.PriortyQueue<Node>(Search.ManhattanDistance, goalNode); List<BlockPosition> path = Search.getInstance().GraphSearch(startNode, goalNode, GameManager.Instance.MazeInfo, Pqueue); print("Monster location =" + currPos.row + " , " + currPos.column); currentDestination = null; foreach (BlockPosition n in path) //put all waypoints into array { _positionsToGo.Push(getBlockCoordinates(n)); } }
public InsertTextCommand( BlockPosition position, string text) : base(position) { Text = text; }
private static List <PathTile> GetWalkableTiles(PathTile currentTile, PathTile targetTile) { int3 currentPos = currentTile.Position; /// ===== UP ===== /// possiblePositions[0] = new int3(currentPos.x + 1, currentPos.y + 1, currentPos.z); // RIGHT possiblePositions[1] = new int3(currentPos.x - 1, currentPos.y + 1, currentPos.z); // LEFT possiblePositions[2] = new int3(currentPos.x, currentPos.y + 1, currentPos.z + 1); // FRONT possiblePositions[3] = new int3(currentPos.x, currentPos.y + 1, currentPos.z - 1); // BACK possiblePositions[4] = new int3(currentPos.x + 1, currentPos.y + 1, currentPos.z + 1); // RIGHT FRONT possiblePositions[5] = new int3(currentPos.x - 1, currentPos.y + 1, currentPos.z + 1); // LEFT FRONT possiblePositions[6] = new int3(currentPos.x + 1, currentPos.y + 1, currentPos.z - 1); // RIGHT BACK possiblePositions[7] = new int3(currentPos.x - 1, currentPos.y + 1, currentPos.z - 1); // LEFT BACK /// ===== CENTER ===== /// possiblePositions[8] = new int3(currentPos.x + 1, currentPos.y, currentPos.z); // RIGHT possiblePositions[9] = new int3(currentPos.x - 1, currentPos.y, currentPos.z); // LEFT possiblePositions[10] = new int3(currentPos.x, currentPos.y, currentPos.z + 1); // FRONT possiblePositions[11] = new int3(currentPos.x, currentPos.y, currentPos.z - 1); // BACK possiblePositions[12] = new int3(currentPos.x + 1, currentPos.y, currentPos.z + 1); // RIGHT FRONT possiblePositions[13] = new int3(currentPos.x - 1, currentPos.y, currentPos.z + 1); // LEFT FRONT possiblePositions[14] = new int3(currentPos.x + 1, currentPos.y, currentPos.z - 1); // RIGHT BACK possiblePositions[15] = new int3(currentPos.x - 1, currentPos.y, currentPos.z - 1); // LEFT BACK /// ===== DOWN ===== /// possiblePositions[16] = new int3(currentPos.x + 1, currentPos.y - 1, currentPos.z); // RIGHT possiblePositions[17] = new int3(currentPos.x - 1, currentPos.y - 1, currentPos.z); // LEFT possiblePositions[18] = new int3(currentPos.x, currentPos.y - 1, currentPos.z + 1); // FRONT possiblePositions[19] = new int3(currentPos.x, currentPos.y - 1, currentPos.z - 1); // BACK possiblePositions[20] = new int3(currentPos.x + 1, currentPos.y - 1, currentPos.z + 1); // RIGHT FRONT possiblePositions[21] = new int3(currentPos.x - 1, currentPos.y - 1, currentPos.z + 1); // LEFT FRONT possiblePositions[22] = new int3(currentPos.x + 1, currentPos.y - 1, currentPos.z - 1); // RIGHT BACK possiblePositions[23] = new int3(currentPos.x - 1, currentPos.y - 1, currentPos.z - 1); // LEFT BACK List <PathTile> pathTiles = new List <PathTile>(); foreach (int3 position in possiblePositions) { if (World.TryGetChunk((float)position.x, (float)position.z, out Chunk chunk)) { int3 releativePosition = new BlockPosition(position).ToInt3();//new int3(position.x - chunk.ChunkPosition.x, position.y, position.z - chunk.ChunkPosition.y); if (IsInRange(ref releativePosition) && CanWalkOn(ref chunk.blocks, ref releativePosition)) { PathTile pathTile = new PathTile() { Position = position, CameFrom = currentTile, }; pathTile.CalculateCost(targetTile.Position); pathTiles.Add(pathTile); } } } return(pathTiles); }
public IEnumerator CannotGetBlockAboveMaxHeight() { Island testCandidate = new Island(64); BlockPosition blockPosition = new BlockPosition(63, 256, 63); yield return(null); Assert.Throws <BlockPositionOutOfBoundsException>(() => testCandidate.GetBlockAt(blockPosition)); }
public IEnumerator CannotGetBlockOutsideZDimension() { Island testCandidate = new Island(64); BlockPosition blockPosition = new BlockPosition(32, 222, 64); yield return(null); Assert.Throws <BlockPositionOutOfBoundsException>(() => testCandidate.GetBlockAt(blockPosition)); }
public void Initialize(BlockSides connectSides, BlockPosition position, MultiBlockInfo info, byte rotation, IMultiBlockPart[] parts) { ConnectSides = connectSides; Position = position; Type = info.Type; Rotation = rotation; Parts = (PlacedMultiBlockPart[])parts; }
public void ShiftVoxelPosition_ZMinus() { var pos = new BlockPosition(); pos = pos.ShiftAlongDirection(5, 5); Assert.AreEqual(0, pos.X); Assert.AreEqual(0, pos.Y); Assert.AreEqual(-5, pos.Z); }
public BoxSelection(BlockPosition cornerOne, BlockPosition cornerTwo) : this() { _left = Math.Min(cornerOne.X, cornerTwo.X); _right = Math.Max(cornerOne.X, cornerTwo.X); _bottom = Math.Min(cornerOne.Y, cornerTwo.Y); _top = Math.Max(cornerOne.Y, cornerTwo.Y); _forward = Math.Min(cornerOne.Z, cornerTwo.Z); _backward = Math.Max(cornerOne.Z, cornerTwo.Z); }
public IEnumerator CannotPlaceBlockOutsideZDimension() { Island testCandidate = new Island(64); Block testBlock = EarthBlock.GetInstance(); BlockPosition blockPosition = new BlockPosition(54, 13, 64); yield return(null); Assert.Throws <BlockPositionOutOfBoundsException>(() => testCandidate.PlaceBlockAt(testBlock, blockPosition)); }
public IEnumerator CannotPlaceBlockAboveMaximumHeight() { Island testCandidate = new Island(64); Block testBlock = RockBlock.GetInstance(); BlockPosition blockPosition = new BlockPosition(63, 256, 63); yield return(null); Assert.Throws <BlockPositionOutOfBoundsException>(() => testCandidate.PlaceBlockAt(testBlock, blockPosition)); }
public void ShiftVoxelPosition_XPlus() { var pos = new BlockPosition(); pos = pos.ShiftAlongDirection(0); Assert.AreEqual(1, pos.X); Assert.AreEqual(0, pos.Y); Assert.AreEqual(0, pos.Z); }
/// <summary> /// Schedule update on block - OnBlockUpdate method will be called with /// delay of "ticks" ticks /// </summary> /// <param name="chunk">target chunk</param> /// <param name="blockPos">local block position</param> /// <param name="ticks">delay (in ticks)</param> public static bool ScheduleUpdate(Chunk chunk, BlockPosition blockPos, int ticks, params int[] args) { if (!updatePositions.Contains(blockPos)) { tickQueue.Add(new WorldEventQueueData(chunk, blockPos, ticks, args)); updatePositions.Add(blockPos); return(true); } return(false); }
public void Initialize(BlockSides connectSides, BlockPosition position, MultiBlockInfo info, byte rotation, IMultiBlockPart[] parts) { ConnectSides = connectSides; Position = position; Info = info; Rotation = rotation; Parts = (LiveMultiBlockPart[])parts; InitializeBase(); }
/// <summary> /// Adds the quad normals to the mesh. /// </summary> /// <param name="side">The side of the block.</param> void AddNormals(int side) { var dir = new BlockPosition(0, 0, 0).ShiftAlongDirection(side); var vec = new Vec3(dir.X, dir.Y, dir.Z); for (int i = 0; i < 4; i++) { Mesh.Normals.Add(vec); } }
private void Start() { if (_blocks.Count == 0) { Assert.IsTrue(BlockPosition.FromVector(transform.position, out BlockPosition position), "Failed to get a BlockPosition from the EditableStructure position."); Assert.IsTrue(AddBlock(position, (MultiBlockInfo)BlockFactory.GetInfo(BlockType.Mainframe), Rotation.GetByte(BlockSides.Top, 0)), "Failed to place the Mainframe."); } }
public void OnBlockDestroy(BlockEventData data, params int[] args) { BlockPosition above = data.LocalPosition.Above(); if (data.chunk.GetBlock(above) == BlockType.GRASS) { data.chunk.AddBlockToBuildList(new BlockData(BlockType.AIR, above)); World.ParticleManager.InstantiateBlockParticle(ParticleType.BLOCK_DESTROY, Utils.LocalToWorldPositionVector3Int(data.chunk.ChunkPosition, above), BlockType.GRASS, true); } }
public IEnumerator BlockAtUninitializedPositionIsAir() { Island testCandidate = new Island(64); BlockPosition blockPosition = new BlockPosition(63, 0, 63); Block blockAt = testCandidate.GetBlockAt(blockPosition); yield return(null); Assert.That(blockAt.GetBlockType(), Is.EqualTo(BlockTypes.AIR)); }
/// <summary> /// Gets the block type at the given relative world position. /// </summary> /// <param name="blockPos">The block position.</param> /// <returns>The block type.</returns> public ServerBlockType GetBlock(BlockPosition blockPos) { var local = blockPos & ChunkSize.Mask; var chunkIndex = ((blockPos.X >> ChunkSize.IntBits) + 1) * 3 * 3 + ((blockPos.Y >> ChunkSize.IntBits) + 1) * 3 + ((blockPos.Z >> ChunkSize.IntBits) + 1); var id = m_Chunks[chunkIndex]?.GetBlockID(local) ?? 0; return(m_BlockList.GetBlockType(id)); }
// TODO: add x,y,z and int3 /// <summary> /// Try to get block at position [check if not out of range] /// </summary> /// <param name="blockPos">position of block</param> /// <param name="blockType">out type of block at position</param> /// <returns>true if chunk contains block at position</returns> public bool TryGetBlock(BlockPosition blockPos, out BlockType blockType) { if (Utils.IsPositionInChunkBounds(blockPos.x, blockPos.y, blockPos.z)) { blockType = blocks[Utils.BlockPosition3DtoIndex(blockPos.x, blockPos.y, blockPos.z)]; return(true); } blockType = BlockType.AIR; return(false); }
private void HandleInput() { if (timeToNextShoot <= 0) { bool shootButtonDown = weaponInHand.IsAutomaticRifle ? Input.GetMouseButton(0) : Input.GetMouseButtonDown(0); if (shootButtonDown) { timeToNextShoot = 1f / weaponInHand.FireRate; currentWeaponFX?.OnShoot(); if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out RaycastHit hitInfo, maxDistance, interactionLayers)) { if (hitInfo.transform.CompareTag("Terrain")) { Vector3 pointInTargetBlock; // move towards block position pointInTargetBlock = hitInfo.point + cameraTransform.forward * .01f; // get block & chunk int3 globalBlockPosition = new int3( Mathf.FloorToInt(pointInTargetBlock.x), Mathf.FloorToInt(pointInTargetBlock.y), Mathf.FloorToInt(pointInTargetBlock.z) ); BlockPosition blockPosition = new BlockPosition(globalBlockPosition); Chunk chunk = World.GetChunk(globalBlockPosition.x, globalBlockPosition.z); BlockType blockType = chunk.GetBlock(blockPosition); currentWeaponFX?.OnBulletHitTerrain(hitInfo, chunk, blockPosition, blockType); // cannot destroy base layer (at y == 0) if (globalBlockPosition.y > 0) { bool shouldBeDestroyed = DamageBlock(globalBlockPosition, blockType, weaponInHand.BlockDamage); if (shouldBeDestroyed) { chunk.SetBlock(blockPosition, BlockType.AIR, new SetBlockSettings(true, false, false, 10)); } } } if (hitInfo.transform.tag.EndsWith("entity")) { Entity entity = hitInfo.transform.GetComponent <Entity>(); entity.Damage(weaponInHand.Damage); } } } } else { timeToNextShoot -= Time.deltaTime; } }
/// <summary> /// Schedule update on block - OnBlockUpdate method will be called with /// delay of between "minTicsk" and "maxTicks" ticks /// </summary> /// <param name="chunk">target chunk</param> /// <param name="blockPos">local block position</param> /// <param name="ticks">minimum(x) and maximum(y) delay (in ticks)</param> public static bool ScheduleUpdate(Chunk chunk, BlockPosition blockPos, int2 ticks, params int[] args) { if (!updatePositions.Contains(blockPos)) { int tick = UnityEngine.Random.Range(ticks.x, ticks.y); tickQueue.Add(new WorldEventQueueData(chunk, blockPos, tick, args)); updatePositions.Add(blockPos); return(true); } return(false); }
public InsertTextFromBlock( BlockPosition destinationPosition, BlockKey sourceBlockKey, CharacterPosition characterBegin, CharacterPosition characterEnd) : base(destinationPosition.BlockKey) { DestinationPosition = destinationPosition; SourceBlockKey = sourceBlockKey; CharacterBegin = characterBegin; CharacterEnd = characterEnd; }
public virtual void FixedUpdate() { if (gameObject && blockPosition != null) { blockPosition = new BlockPosition(Mathf.Clamp(Mathf.RoundToInt(gameObject.transform.position.x), 0, world.sizeX - 1), Mathf.Clamp(Mathf.RoundToInt(gameObject.transform.position.y + 1), 0, world.sizeY - 1), Mathf.Clamp(Mathf.RoundToInt(gameObject.transform.position.z), 0, world.sizeZ - 1)); if (gameObject.GetComponentInChildren <SpriteRenderer>()) { gameObject.GetComponentInChildren <SpriteRenderer>().material.color = new Color(world.block[blockPosition.x, blockPosition.y, blockPosition.z].sunLight, world.block[blockPosition.x, blockPosition.y, blockPosition.z].sunLight, world.block[blockPosition.x, blockPosition.y, blockPosition.z].sunLight, 1); } } }
bool GetBlockPositionByMousePosition(out BlockPosition position) { RaycastHit2D hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { var inverseTransformPoint = hit.collider.transform.InverseTransformPoint(hit.point); position = GetBoardCell(inverseTransformPoint); return(true); } position = new BlockPosition(-1, -1); return(false); }
public override bool Equals(object other) { if (other is BlockPosition) { BlockPosition otherBlockPosition = (BlockPosition)other; return(otherBlockPosition.X == X && otherBlockPosition.Y == Y && otherBlockPosition.Z == Z); } return(false); }
/// <summary> /// Called when scene is loaded first time /// </summary> public static void OnFirstLoadDone() { Vector2Int playerWorldPos = new Vector2Int((int)PlayerController.PlayerTransform.position.x, (int)PlayerController.PlayerTransform.position.z); BlockPosition blockPosition = GetTopBlockPosition(playerWorldPos, out Chunk chunk); chunk.SetBlock(blockPosition, BlockType.OBSIDIAN, SetBlockSettings.PLACE); Vector3 playerPos = blockPosition.ToVector3Int() + new Vector3(0.5f, 3.5f, 0.5f); PlayerController.PlayerTransform.position = playerPos; PlayerController.PlayerTransform.gameObject.SetActive(true); }
private int GetHeightDiff(MapRegionLayer regionLayer, BlockColumnMeta block, int xOffset, int zOffset) { var pos = new BlockPosition(block.Position.X + xOffset, block.Position.Z + zOffset); BlockColumnMeta targetBlock = regionLayer.Layer.Map.GetRegionLayer(pos.GetRegionPosition()).GetBlockData(pos); if (targetBlock != null) { return(targetBlock.Height - block.Height); } return(0); }
/// <summary> /// Get block at provided position /// </summary> /// <param name="x">world position x</param> /// <param name="y">world position y</param> /// <param name="z">world position z</param> /// <returns></returns> public static BlockStructure GetBlock(int x, int y, int z) { Chunk chunk = GetChunk(x, z); if (!chunk) { return(WorldData.GetBlockData(BlockType.AIR)); } BlockPosition bp = new BlockPosition(x, y, z); return(WorldData.GetBlockData(chunk.GetBlock(bp))); }
/// <summary> /// Called whenever the client receives the information that damage was dealt server-side. /// </summary> public void DamagedClient(BitBuffer buffer) { int count = buffer.TotalBitsLeft / (BlockPosition.SerializedBitsSize + 32); KeyValuePair <RealLiveBlock, uint>[] damages = new KeyValuePair <RealLiveBlock, uint> [count]; for (int i = 0; i < count; i++) { RealLiveBlock block = (RealLiveBlock)_blocks[BlockPosition.Deserialize(buffer)]; uint damage = buffer.ReadUInt(); block.Damage(damage); damages[i] = new KeyValuePair <RealLiveBlock, uint>(block, damage); } DamageApply(damages); }
/// <summary> /// Creates a BoxSelection that fits the volume of a chunk. /// </summary> /// <param name="position">The position of the chunk volume.</param> /// <param name="size">The size of the chunk volume.</param> public BoxSelection(ChunkPosition position, ChunkSize size) : this() { var lesser = new BlockPosition(position, new LocalBlockPosition(), size); _left = lesser.X; _bottom = lesser.Y; _forward = lesser.Z; var greater = new BlockPosition(position, new LocalBlockPosition(size.X - 1, size.Y - 1, size.Z - 1), size); _right = greater.X; _top = greater.Y; _backward = greater.Z; }
private void RemoveValue(BlockPosition p) { // If value stored separately, don't clear - we replace it and GC will collect the old one. if (p.Length == ushort.MaxValue) { return; } // Clear the previous space (security) Array.Clear(_batches[p.BatchIndex].Array, p.Position, p.Length); // Add waste for the previous value _batches[p.BatchIndex].WasteSpace += p.Length; }
// ReSharper disable once AnnotateCanBeNullParameter private bool GetSelectedBlock(out GameObject block, out BlockPosition position, out byte rotation) { block = null; position = null; rotation = 0; if (!Physics.Raycast(_camera.transform.position, _camera.transform.forward, out RaycastHit hit) || !BlockPosition.FromVector(hit.point + hit.normal / 2, out position)) { return(false); } rotation = Rotation.GetByte(BlockSide.FromNormal(hit.normal), _facingVariant); block = hit.transform.gameObject; return(true); }
public ReplaceTextCommand( BlockPosition position, int length, string text) : base(position, true) { // Save the text for the changes. Length = length; Text = text; // Create the commands in this command. var deleteCommand = new DeleteTextCommand( position, (int) position.TextIndex + Length); var insertCommand = new InsertTextCommand(position, Text); Commands.Add(deleteCommand); Commands.Add(insertCommand); }
public InsertMultilineTextCommand( BlockPosition position, string text) { // Make sure we have a sane state. if (text.Contains("\r")) { throw new ArgumentException( "text cannot have a return (\\r) character in it.", "text"); } // Save the text for the changes. BlockPosition = position; Text = text; UpdateTextPosition = DoTypes.All; // Set up our collection. addedBlocks = new List<Block>(); }
public DimensionView(ISldWorks swApp, BlockPosition side, bool dimOnlyNew) { _swApp = swApp; _swModel = swApp.IActiveDoc2; _side = side; _dimOnlyNew = dimOnlyNew; ListSize = new List<CoordAndDepth>(); }
private static Common AnalizViewCoefficient(ModelDoc2 swModel, double[] boundBox,ref BlockPosition side, out double[] dimLinDirH, out double[] dimLinDirV, out bool? blockSize,out Ordinate vertex,out Ordinate vertexS,double[] dsDim,double[] deDim,double[] endDim,string dsName,string deName) { double x, y; Annotation annX, annY; using (var a = new GetDimensions()) { bool consider; var tmpSide = GetDimensions.GetBlockPosition(swModel, out consider);//a.GetBlockPosition(swModel,out consider); if (consider) // consider -принимать ли в расчет tmpSide side = tmpSide; dimLinDirH = a.GetDimensionLineDirect(swModel, boundBox, false, side, out x, out annX, out blockSize,out vertex,out vertexS,dsDim,deDim,endDim,dsName,deName); } using (var a = new GetDimensions()) { Ordinate vert, verts; dimLinDirV = a.GetDimensionLineDirect(swModel, boundBox, true, side, out y, out annY, out blockSize, out vert, out verts, dsDim, deDim, endDim, dsName, deName); if (verts != null) vertexS = verts; } return new Common(new Coord(new CoordX(x, annX), new CoordY(y, annY)), null); }
public override bool CanBuild(Player player, BlockPosition pos, Block type) { return (type != Block.Books); }
public override void PlayerBuilds(Player player, BlockPosition pos, Block type, Block oldType) { if (type == Block.Air && oldType == Block.TNT) { Announce(player.name + " asploded!"); } }
public AttackBox(int w, int h, int x, int y, int resetHit = -1, float zDepth = 30, float hitPauseTime = 1 / 60, float painTime = 20 / 60, int hitDamage = 5, int hitPoints = 5, float hitStrength = 0.4f, int comboStep = 1, int juggleCost = 0, AttackPosition attackPosiiton = AttackPosition.NONE, BlockPosition blockPosition = BlockPosition.NONE, SparkRenderType sparkRenderFrame = SparkRenderType.FRAME, Effect.EffectState sparkState = Effect.EffectState.NONE, float sparkX = 0, float sparkY = 0) : base(BoxType.HIT_BOX, w, h, x, y) { sparkOffset = Vector2.Zero; SetResetHit(resetHit); SetZdepth(zDepth); SetHitPauseTime(hitPauseTime); SetPainTime(painTime); SetHitDamage(hitDamage); SetHitPoints(hitPoints); SetHitStrength(hitStrength); SetComboStep(comboStep); SetJuggleCost(juggleCost); SetAttackPosition(attackPosition); SetSparkRenderType(sparkRenderFrame); SetSparkState(sparkState); SetSparkOffset(sparkX, sparkY); }
public void ChangeBlock(BlockPosition pos, Block blockType) { List<Player> temp = new List<Player>(Players); foreach (Player P in temp) { P.BlockSet(pos, blockType); } map.SetTile(pos.x, pos.y, pos.z, blockType); }
void Player_BlockChange(Player sender, BlockPosition pos, Block BlockType) { Block was = map.GetTile(pos.x, pos.y, pos.z); if (!Game.CanBuild(sender, pos, BlockType)) { sender.BlockSet(pos, was); sender.PrintMessage(Color.DarkGreen + "You're not allowed to do that!"); return; } map.SetTile(pos.x, pos.y, pos.z, BlockType); Game.PlayerBuilds(sender, pos, BlockType, was); }
public double[] GetDimensionLineDirect(ModelDoc2 swModel, double[] boundBox, bool vertic,BlockPosition side, out double d, out Annotation annotation,out bool? blockSize,out Ordinate vertex,out Ordinate vertexS, double[] dsDim,double[] deDim,double[] endDim,string dsName,string deName) { blockSize = null; var swDrawing = (DrawingDoc) swModel; var drView = swDrawing.IActiveDrawingView; var scale = (double[]) drView.ScaleRatio; double vScaleRat = scale[1]; double[] doubles = null; d = 0; annotation = null; vertex = GetVertexFromBlock(swModel, drView, vScaleRat,true); if(!(vertex!=null && SelectVertexDatum(swModel, vertex))) vertex = SelectVertexDatumUp(swModel, boundBox, side); if (dsDim != null && deDim != null) { vertexS = GetVertexFromBlock(swModel, drView, vScaleRat, false); //swModel.ClearSelection2(true); swDrawing.ActivateView(drView.Name); bool tmp = swModel.Extension.SelectByID2(@"Точка вставки/" + dsName, "SKETCHPOINT", 0, 0, 0, false, 0, null, 0); tmp = swModel.Extension.SelectByID2(@"Точка вставки/" + deName, "SKETCHPOINT", 0, 0, 0, true, 0, null, 0); DisplayDimension dim1; if (vertic) dim1 = swModel.AddVerticalDimension2(0, 0, 0); else dim1 = swModel.AddHorizontalDimension2(0, 0, 0); dim1.GetDimension().DrivenState = (int)swDimensionDrivenState_e.swDimensionDriven; d = dim1.GetDimension().Value; if (vertic) { doubles = new double[3] { 1, 0, 0 }; } else { doubles = new double[3] {0, 1, 0}; } annotation = dim1.GetAnnotation(); } else { if (vertic) { vertexS = GetVertexFromBlock(swModel, drView, vScaleRat, false); if (!(vertexS != null && SelectVertexDatum(swModel, vertexS))) SelectVertexDatumDown(swModel, boundBox, side); else if (vertex != null) blockSize = vertex.X < vertexS.X; DisplayDimension dim = null; dim = swModel.IAddVerticalDimension2(0, 0, 0); if (dim != null) { d = dim.IGetDimension().Value; doubles = (double[]) dim.IGetDimension().DimensionLineDirection.ArrayData; if (blockSize != null) { vertexS.Y = vertexS.Y + (d/1000)/vScaleRat; } annotation = dim.IGetAnnotation(); } } else { vertexS = GetVertexFromBlock(swModel, drView, vScaleRat, false); if (!(vertexS != null && SelectVertexDatum(swModel, vertexS))) { vertexS = SelectVertexDatumUp(swModel, boundBox, side.Not()); } else if (vertex != null) blockSize = vertex.X < vertexS.X; var dim = swModel.AddHorizontalDimension2(0, 0, 0); if (dim != null) { d = dim.GetDimension().Value; doubles = (double[]) dim.GetDimension().DimensionLineDirection.ArrayData; annotation = dim.GetAnnotation(); } } } swModel.ClearSelection(); return doubles; }
// CanBuild: return whether the given player may build that type at that location. public virtual bool CanBuild(Player player, BlockPosition pos, Block type) { return true; }
public override void BlockSet(BlockPosition pos, Block type) { // do nothing }
public Ordinate SelectVertexDatumUp(ModelDoc2 swModel, double[] boundBox, BlockPosition left, bool clear = false) { var sizeX = boundBox[2] - boundBox[0]; if (sizeX < 0) sizeX = -sizeX; var sizeY = boundBox[3] - boundBox[1]; if (sizeY < 0) sizeY = -sizeY; var etalon = sizeX > sizeY ? sizeY : sizeX; double step = etalon / 40; var ordinate = new Ordinate(0, 0); if (left.AsBoolean()) { for (int iX = 0; iX <= 30; iX++) { for (int iY = 0; iY <= 30; iY++) { var boolstatus = swModel.Extension.SelectByID2("", "VERTEX", boundBox[0] + step * iX, boundBox[3] - step * iY, 0.0, true, (int) swAutodimMark_e.swAutodimMarkOriginDatum, null, 0); if (boolstatus) { ordinate.X = boundBox[0] + step * iX; ordinate.Y = boundBox[3] - step * iY; if (clear) swModel.ClearSelection(); return ordinate; } } } } else { for (int iX = 0; iX <= 30; iX++) { for (int iY = 0; iY <= 30; iY++) { var boolstatus = swModel.Extension.SelectByID2("", "VERTEX", boundBox[2] - step * iX, boundBox[3] - step * iY, 0.0, true, (int) swAutodimMark_e.swAutodimMarkOriginDatum, null, 0); if (boolstatus) { ordinate.X = boundBox[2] - step * iX; ordinate.Y = boundBox[3] - step * iY; if (clear) swModel.ClearSelection(); return ordinate; } } } } if (clear) swModel.ClearSelection(); return ordinate; }
/// <summary> /// Initializes a new instance of the <see cref="SplitBlockCommand"/> class. /// </summary> /// <param name="position">The position to break the paragraph.</param> public SplitBlockCommand( ProjectBlockCollection blocks, BlockPosition position) : base(position, "\n") { }
public void SetBlockPosition(BlockPosition position) { blockPosition = position; }
private static void SetPosition(Dictionary<double, Annotation> dictionary, Ordinate vertex, double vScale, bool xOrY, BlockPosition side) { var x = dictionary.OrderBy(z => z.Key); int k = 1; foreach (var keyValuePair in x) { if (keyValuePair.Value != null) { switch (side) { case BlockPosition.LeftTopToRightBottom: { if (xOrY) { if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X + keyValuePair.Key / 2000 / vScale, vertex.Y + 0.004 * k, 0); else keyValuePair.Value.SetPosition(vertex.X + keyValuePair.Key / 1000 / vScale + 0.006, vertex.Y + 0.004 * k, 0); } else { if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X - 0.004 * k, vertex.Y - keyValuePair.Key / 2000 / vScale, 0); else keyValuePair.Value.SetPosition(vertex.X - 0.004 * k, vertex.Y - keyValuePair.Key / 1000 / vScale - 0.006, 0); } } break; case BlockPosition.RightTopToLeftBottom: { if (xOrY) { if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X - keyValuePair.Key / 2000 / vScale, vertex.Y + 0.004 * k, 0); else keyValuePair.Value.SetPosition(vertex.X - keyValuePair.Key / 1000 / vScale - 0.006, vertex.Y + 0.004 * k, 0); } else { var tt1 = vertex.Y - keyValuePair.Key/2000/vScale; var tt2 = vertex.Y - keyValuePair.Key/1000/vScale - 0.006; if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X + 0.004 * k, tt1, 0); else keyValuePair.Value.SetPosition(vertex.X + 0.004 * k, tt2, 0); } } break; case BlockPosition.LeftBottomToRightTop: { if (xOrY) { if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X + keyValuePair.Key / 2000 / vScale, vertex.Y - 0.004 * k, 0); else keyValuePair.Value.SetPosition(vertex.X + keyValuePair.Key / 1000 / vScale + 0.006, vertex.Y - 0.004 * k, 0); } else { if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X - 0.004 * k, vertex.Y + keyValuePair.Key / 2000 / vScale, 0); else keyValuePair.Value.SetPosition(vertex.X - 0.004 * k, vertex.Y + keyValuePair.Key / 1000 / vScale - 0.006, 0); } } break; case BlockPosition.RigthBottomToLeftTop: { if (xOrY) { if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X - keyValuePair.Key / 2000 / vScale, vertex.Y - 0.004 * k, 0); else keyValuePair.Value.SetPosition(vertex.X - keyValuePair.Key / 1000 / vScale + 0.006, vertex.Y - 0.004 * k, 0); } else { if (keyValuePair.Key > 100) keyValuePair.Value.SetPosition(vertex.X + 0.004 * k, vertex.Y + keyValuePair.Key / 2000 / vScale, 0); else keyValuePair.Value.SetPosition(vertex.X + 0.004 * k, vertex.Y + keyValuePair.Key / 1000 / vScale - 0.006, 0); } } break; } k++; } } }
public override void Run(Player sender, string cmd, string args) { args = args.ToLower(); string[] parts = args.Split(new char[]{' '}); if (parts.Length < 2) { sender.PrintMessage(Color.CommandError + "Too few arguments!"); return; } if(!BlockInfo.NameExists(parts[0])) { sender.PrintMessage(Color.CommandError + "No such block " + parts[0]); return; } else if(!BlockInfo.NameExists(parts[1])) { sender.PrintMessage(Color.CommandError + "No such block " + parts[1]); return; } Block From = BlockInfo.names[parts[0]]; Block To = BlockInfo.names[parts[1]]; Map map = Server.theServ.map; BlockPosition pos = new BlockPosition((short)(sender.pos.x / 32), (short)(sender.pos.y / 32), (short)(sender.pos.z / 32)); int i = 0; for (short x = (short) (pos.x - 20); x <= pos.x + 20; x++) { for (short y = (short) (pos.y - 20); y <= pos.y + 20; y++) { for (short z = (short) (pos.z - 20); z <= pos.z + 20; z++) { if (map.GetTile(x, y, z) == From && (Math.Abs(pos.x - x) + Math.Abs(pos.y - y) + Math.Abs(pos.z - z) < 20)) { ++i; map.SetTile(x, y, z, To); } } } } sender.PrintMessage(Color.CommandResult + "Converted " + i.ToString() + " " + From.ToString() + " to " + To.ToString()); Spacecraft.Log(sender.name + " converted " + From.ToString().ToLower() + " to " + To.ToString().ToLower()); }
public FoundCoordinate(ISldWorks swApp, Entity ent, Ordinate vertex, double[] dimLineH, double[] dimLineV, BlockPosition side,View swView,bool doThroughHoles) { _swApp = swApp; _swModel = swApp.IActiveDoc2; _side = side; _ent = ent; _vertex = vertex; _doThroughHoles = doThroughHoles; _swSelData = _swModel.ISelectionManager.CreateSelectData(); _swView = swView; _coordinate = FindCoord(dimLineH, dimLineV); }
void map_BlockChange(Map map, BlockPosition pos, Block BlockType) { List<Player> temp = new List<Player>(Players); foreach (Player P in temp) { P.BlockSet(pos, BlockType); } }
public void SelectVertexDatumDown(ModelDoc2 swModel, double[] boundBox, BlockPosition left) { var sizeX = boundBox[2] - boundBox[0]; if (sizeX < 0) sizeX = -sizeX; var sizeY = boundBox[3] - boundBox[1]; if (sizeY < 0) sizeY = -sizeY; var etalon = sizeX > sizeY ? sizeY : sizeX; double step = etalon / 40; if (left.AsBoolean()) { for (int iX = 0; iX <= 30; iX++) { for (int iY = 0; iY <= 30; iY++) { var boolstatus = swModel.Extension.SelectByID2("", "VERTEX", boundBox[0] + step * iX, boundBox[1] + step * iY, 0.0, true, (int) swAutodimMark_e.swAutodimMarkOriginDatum, null, 0); if (boolstatus) { return; } } } } else { for (int iX = 0; iX <= 30; iX++) { for (int iY = 0; iY <= 30; iY++) { var boolstatus = swModel.Extension.SelectByID2("", "VERTEX", boundBox[2] - step * iX, boundBox[1] + step * iY, 0.0, true, (int) swAutodimMark_e.swAutodimMarkOriginDatum, null, 0); if (boolstatus) { return; } } } } }
// PlayerBuilds: called when a player places or deletes a block. public virtual void PlayerBuilds(Player player, BlockPosition pos, Block type, Block oldType) { }
/// <summary> /// returns the manhattan distance between two nodes /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public static int ManhattanDistance(BlockPosition start, BlockPosition end) { return Mathf.Abs(start.row - end.row) + Mathf.Abs(start.column - end.column); }
protected BlockPositionCommand(BlockPosition position) : base(position.BlockKey) { TextIndex = (int) position.TextIndex; }
public override LineBufferOperationResults InsertText( int lineIndex, int characterIndex, string text) { using (project.Blocks.AcquireLock(RequestLock.Write)) { Block block = project.Blocks[lineIndex]; var position = new BlockPosition(block.BlockKey, characterIndex); var command = new InsertTextCommand(position, text); var context = new BlockCommandContext(project); project.Commands.Do(command, context); return GetOperationResults(); } }
private void AddActiveBlock(BlockPosition pos) { ActiveBlocks.Add(pos); }