private BlockPos BfsSearchPath(IWorldAccessor world, Queue <BlockPos> uncheckedPositions, BlockPos target, Block ourBlock)
        {
            BlockPos pos, npos = new BlockPos();

            while (uncheckedPositions.Count > 0)
            {
                pos = uncheckedPositions.Dequeue();
                int curDist = pos.ManhattenDistance(target);

                for (int i = 0; i < BlockFacing.HORIZONTALS.Length; i++)
                {
                    BlockFacing facing = BlockFacing.HORIZONTALS[i];
                    npos.Set(pos.X + facing.Normali.X, target.Y, pos.Z + facing.Normali.Z);
                    if (npos.ManhattenDistance(target) > curDist)
                    {
                        continue;
                    }

                    if (npos.Equals(target))
                    {
                        return(pos);
                    }

                    Block block = world.BlockAccessor.GetBlock(npos);
                    if (!block.IsLiquid() && block.Replaceable < ReplacableThreshold)
                    {
                        continue;
                    }

                    uncheckedPositions.Enqueue(npos.Copy());
                }
            }

            return(null);
        }
Пример #2
0
 public void onNeighbourChange(BlockPos neibpos)
 {
     if (Engaged && neibpos.Equals(transmissionPos))
     {
         Engaged = false;
     }
 }
Пример #3
0
        // Unused and untested.
        private void makeExplosionRay(Vector3 orgin, Vector3 direction, float distance)
        {
            float traveled = 0f;

            BlockPos lastPos = new BlockPos(orgin);
            BlockPos pos;

            direction /= 2;

            while (traveled <= distance)
            {
                orgin += direction;
                pos    = new BlockPos(orgin);
                if (!(pos.Equals(lastPos)))
                {
                    // Got to a new block.
                    if (this.getBlock(pos) == Block.air)
                    {
                        if (UnityEngine.Random.Range(0, 3) == 0)
                        {
                            this.breakBlock(pos, null);
                        }
                        else
                        {
                            this.setBlock(pos, Block.air);
                        }
                    }
                    lastPos = pos;
                }
                traveled += 0.5f;
            }
        }
Пример #4
0
 public bool Equals(NodePos otherPos)
 {
     if (otherPos == null)
     {
         return(false);
     }
     return(blockPos.Equals(otherPos.blockPos) && index == otherPos.index);
 }
Пример #5
0
        public virtual bool isInvertedNetworkFor(BlockPos pos)
        {
            if (propagationDir == null || pos == null)
            {
                return(false);
            }
            BlockPos testPos = this.Position.AddCopy(propagationDir);

            return(!testPos.Equals(pos));
        }
Пример #6
0
 public void RemoveGearAt(BlockPos pos)
 {
     if (gear == null)
     {
         return;
     }
     for (int i = 0; i < 4; i++)
     {
         if (pos.Equals(gear[i]))
         {
             gear[i] = null;
             return;
         }
     }
 }
Пример #7
0
    void ProcessBest()
    {
        float    shortestDist = (distanceFromStartToTarget * maxDistToTravelMultiplier) + maxDistToTravelAfterDirect;
        BlockPos bestPos      = new BlockPos(0, 10000, 0);

        foreach (var tile in open)
        {
            if (tile.Value.g + tile.Value.h < shortestDist)
            {
                bestPos      = tile.Key;
                shortestDist = tile.Value.g + tile.Value.h;
            }
        }

        Heuristics parent;

        open.TryGetValue(bestPos, out parent);

        if (Distance(((Vector3)bestPos) + (Vector3.up * 2), targetLocation) <= range)
        {
            PathComplete(bestPos);
            return;
        }

        if (bestPos.Equals(new BlockPos(0, 10000, 0)))
        {
            Debug.Log("Failed to pf " + targetLocation.x + ", " + targetLocation.y + ", " + targetLocation.z);
            bestPos = new BlockPos(0, 10000, 0);

            foreach (var tile in open)
            {
                if (tile.Value.g + tile.Value.h < shortestDist)
                {
                    bestPos      = tile.Key;
                    shortestDist = tile.Value.g + tile.Value.h;
                }
            }
            PathComplete(bestPos);
        }

        ProcessTile(bestPos);
    }
Пример #8
0
    void ProcessBest()
    {
        float    shortestDist = (distanceFromStartToTarget * maxDistToTravelMultiplier) + maxDistToTravelAfterDirect;
        BlockPos bestPos      = new BlockPos(0, 10000, 0);

        foreach (var tile in open)
        {
            if (tile.Value.g + tile.Value.h < shortestDist)
            {
                bestPos      = tile.Key;
                shortestDist = tile.Value.g + tile.Value.h;
            }
        }

        Heuristics parent;

        open.TryGetValue(bestPos, out parent);
        Debug.DrawLine(new Vector3(parent.parent.x, parent.parent.y + 1, parent.parent.z),
                       new Vector3(bestPos.x, bestPos.y + 1, bestPos.z), Color.blue, 40);

        if (Distance(((Vector3)bestPos) + (Vector3.up * 2), targetLocation) <= range)
        {
            PathComplete(bestPos);
            return;
        }

        if (bestPos.Equals(new BlockPos(0, 10000, 0)))
        {
            noRoute = true;
            Debug.Log("Failed to pf " + targetLocation.x + ", " + targetLocation.y + ", " + targetLocation.z);
            complete = true;
            path.Clear();
            path.Add(startLocation);

            open.Clear();
            closed.Clear();
            return;
        }

        ProcessTile(bestPos);
    }
Пример #9
0
        /// <summary>
        /// Returns a PlayerHitObject, representing what the player is looking at, or null if they are not looking at anything.
        /// </summary>
        private PlayerRayHit getPlayerRayHit()
        {
            RaycastHit hit;

            if (Physics.Raycast(new Ray(this.mainCamera.position, this.mainCamera.forward), out hit, this.getReach(), ~(Layers.IGNORE_RAYCAST | Layers.ISLAND_MESH | Layers.ENTITY_PLAYER)))
            {
                // We hit something.
                BlockPos newLookPos = BlockPos.fromRaycastHit(hit);

                if (this.posLookingAt == null || !(newLookPos.Equals(this.posLookingAt)) || !Input.GetMouseButton(0))
                {
                    //We are either looking at a new thing or no longer holding the mouse button down
                    this.blockBreakEffect.terminate();
                }
                this.posLookingAt = newLookPos;

                if (hit.transform.CompareTag(Tags.CHUNK) || hit.transform.CompareTag(Tags.BLOCK))
                {
                    return(new PlayerRayHit(this.world.getBlock(newLookPos), this.world.getMeta(newLookPos), newLookPos, hit));
                }
                else if (hit.transform.CompareTag(Tags.ENTITY))
                {
                    return(new PlayerRayHit(hit.transform.GetComponent <Entity>(), hit));
                }
                else
                {
                    Debug.Log("Player is looking at an object with an unknown tag, " + hit.transform.tag + "!");
                    return(null);
                }
            }
            else
            {
                // We're not looking at anything
                this.blockBreakEffect.terminate();
                this.posLookingAt = null;
            }

            return(null);
        }
Пример #10
0
    public override void OnBlockRemoved(IWorldAccessor world, BlockPos pos)
    {
        base.OnBlockRemoved(world, pos);
        BlockPos tmpPos = new BlockPos();

        for (int d1 = -1; d1 <= 1; d1++)
        {
            for (int d2 = -1; d2 <= 1; d2++)
            {
                if (d1 == 0 && d2 == 0)
                {
                    continue;
                }
                if (powerOutFacing == BlockFacing.EAST || powerOutFacing == BlockFacing.WEST)
                {
                    tmpPos.Set(pos.X, pos.Y + d1, pos.Z + d2);
                }
                else
                {
                    tmpPos.Set(pos.X + d2, pos.Y + d1, pos.Z);
                }

                //Destroy any fake blocks; revert small gears to their normal peg gear type
                BEMPMultiblockBase be = world.BlockAccessor.GetBlockEntity(tmpPos) as BEMPMultiblockBase;
                if (be != null && pos.Equals(be.Principal))
                {
                    be.Principal = null;  //signal to BlockMPMultiblockWood that it can be broken normally without triggering this in a loop
                    world.BlockAccessor.SetBlock(0, tmpPos);
                }
                else
                {
                    //BlockAngledGears smallgear = world.BlockAccessor.GetBlock(tmpPos) as BlockAngledGears;
                    //if (smallgear != null) smallgear.ToPegGear(world, tmpPos);
                }
            }
        }
    }
Пример #11
0
        public override void carvePiece(Chunk chunk, System.Random rnd)
        {
            BlockPos pos1 = this.getPosMin() + BlockPos.up;
            BlockPos pos2 = this.getPosMax() - (this.is3High ? BlockPos.up : BlockPos.zero);
            int      i, j, k, x, y, z;
            int      i1 = Mathf.Max(pos1.x, pos2.x);
            int      j1 = Mathf.Max(pos1.y, pos2.y);
            int      k1 = Mathf.Max(pos1.z, pos2.z);

            for (i = Mathf.Min(pos1.x, pos2.x); i <= i1; i++)
            {
                for (j = Mathf.Min(pos1.y, pos2.y); j <= j1; j++)
                {
                    for (k = Mathf.Min(pos1.z, pos2.z); k <= k1; k++)
                    {
                        x = i - chunk.worldPos.x;
                        y = j - chunk.worldPos.y;
                        z = k - chunk.worldPos.z;
                        if (x >= 0 && x < Chunk.SIZE && y >= 0 && y < Chunk.SIZE && z >= 0 && z < Chunk.SIZE)
                        {
                            chunk.setBlock(x, y, z, Block.air);
                        }
                    }
                }
            }

            // Add the supports, torch and rails.
            BlockPos  pos               = this.orgin;
            BlockPos  endPoint          = this.end + this.pointing.blockPos;
            int       axis              = (int)(this.pointing.axis);
            int       perpAxis          = (int)(this.pointing.axis == EnumAxis.X ? EnumAxis.Z : EnumAxis.X); // Perpendicular to axis
            int       distanceToSupport = 0;
            Direction right             = this.pointing.getClockwise();
            Direction left              = this.pointing.getCounterClockwise();
            BlockPos  rightDir          = right.blockPos;
            BlockPos  leftDir           = left.blockPos;

            i = (this.is3High ? 3 : 4);
            k = i - 1;
            do
            {
                distanceToSupport++;
                if (distanceToSupport == 3)
                {
                    if (chunk.isInChunk(pos.x, pos.y + 3, pos.z) && rnd.Next(0, 3) == 0)
                    {
                        this.addTorch(chunk, pos.x, pos.y + k, pos.z, this.pointing);
                    }
                }
                else if (distanceToSupport == 4)
                {
                    // Top middle
                    this.setStateIfInChunk(chunk, pos.x, pos.y + k, pos.z, Block.wood, perpAxis);

                    // Column.
                    for (j = 0; j < i; j++)
                    {
                        this.setStateIfInChunk(chunk, pos.x + rightDir.x * 2, pos.y + j, pos.z + rightDir.z * 2, Block.wood, j == 3 ? perpAxis : 1);
                        this.setStateIfInChunk(chunk, pos.x + leftDir.x * 2, pos.y + j, pos.z + leftDir.z * 2, Block.wood, j == 3 ? perpAxis : 1);
                    }

                    // Top beam, one away from middle.
                    this.setStateIfInChunk(chunk, pos.x + rightDir.x, pos.y + k, pos.z + rightDir.z, Block.wood, perpAxis);
                    this.setStateIfInChunk(chunk, pos.x + leftDir.x, pos.y + k, pos.z + leftDir.z, Block.wood, perpAxis);

                    // Web.
                    j = rnd.Next(0, 100);
                    if (j < 10)
                    {
                        this.setStateIfInChunk(chunk, pos.x + rightDir.x, pos.y + k - 1, pos.z + rightDir.z, Block.cobweb, BlockCobweb.getMetaForState(right, true));
                    }
                    else if (j < 20)
                    {
                        this.setStateIfInChunk(chunk, pos.x + leftDir.x, pos.y + k - 1, pos.z + leftDir.z, Block.cobweb, BlockCobweb.getMetaForState(left, true));
                    }

                    distanceToSupport = -4;
                }
                // Rail
                if (rnd.Next(0, 10) != 0)
                {
                    this.setStateIfInChunk(chunk, pos.x, pos.y, pos.z, Block.rail, axis == 0 ? 0 : 1);
                }

                // Gravel
                this.placeRndGravel(pos, chunk);
                this.placeRndGravel(pos + rightDir, chunk);
                this.placeRndGravel(pos + leftDir, chunk);

                pos += this.pointing.blockPos;
            } while (!pos.Equals(endPoint));
        }
Пример #12
0
 public bool HasGearAt(BlockPos pos)
 {
     return(pos.Equals(gear[0]) || pos.Equals(gear[1]) || pos.Equals(gear[2]) || pos.Equals(gear[3]));
 }
Пример #13
0
    void ProcessBest()
    {
        float shortestDist = (distanceFromStartToTarget*maxDistToTravelMultiplier) + maxDistToTravelAfterDirect;
        BlockPos bestPos = new BlockPos(0,10000,0);

        foreach (var tile in open)
        {
            if (tile.Value.g + tile.Value.h < shortestDist)
            {
                bestPos = tile.Key;
                shortestDist = tile.Value.g + tile.Value.h;
            }
        }

        Heuristics parent;
        open.TryGetValue(bestPos, out parent);
        Debug.DrawLine(new Vector3(parent.parent.x, parent.parent.y + 1, parent.parent.z),
            new Vector3(bestPos.x, bestPos.y + 1, bestPos.z), Color.blue, 40);

        if (Distance(((Vector3)bestPos) + (Vector3.up*2), targetLocation) <= range)
        {
            PathComplete(bestPos);
            return;
        }

        if (bestPos.Equals(new BlockPos(0, 10000, 0)))
        {
            noRoute = true;
            Debug.Log("Failed to pf " + targetLocation.x + ", " + targetLocation.y + ", " + targetLocation.z);
            complete = true;
            path.Clear();
            path.Add(startLocation);

            open.Clear();
            closed.Clear();
            return;
        }

        ProcessTile(bestPos);
    }
Пример #14
0
    void ProcessBest()
    {
        float shortestDist = (distanceFromStartToTarget * maxDistToTravelMultiplier) + maxDistToTravelAfterDirect;
        BlockPos bestPos = new BlockPos(0, 10000, 0);

        foreach (var tile in open) {
            if (tile.Value.g + tile.Value.h < shortestDist) {
                bestPos = tile.Key;
                shortestDist = tile.Value.g + tile.Value.h;
            }
        }

        Heuristics parent;
        open.TryGetValue(bestPos, out parent);

        if (Distance(((Vector3)bestPos) + (Vector3.up * 2), targetLocation) <= range) {
            PathComplete(bestPos);
            return;
        }

        if (bestPos.Equals(new BlockPos(0, 10000, 0))) {
            Debug.Log("Failed to pf " + targetLocation.x + ", " + targetLocation.y + ", " + targetLocation.z);
            bestPos = new BlockPos(0, 10000, 0);

            foreach (var tile in open) {
                if (tile.Value.g + tile.Value.h < shortestDist) {
                    bestPos = tile.Key;
                    shortestDist = tile.Value.g + tile.Value.h;
                }
            }
            PathComplete(bestPos);
        }

        ProcessTile(bestPos);
    }