Beispiel #1
0
        public WireMask getConnections(BlockVector v)
        { //note: 5. boolean value is showing, if it should power blocks
            // This is only on blocks DUH
            if (!data[v].isWire)
            {
                return(WireMask.NotConnected);
            }

            WireMask o  = WireMask.NotConnected;
            int      no = 0;

            if (getSingleConnection(v, Direction.NORTH))
            {
                o |= WireMask.North; no++;
            }
            if (getSingleConnection(v, Direction.SOUTH))
            {
                o |= WireMask.South; no++;
            }
            if (getSingleConnection(v, Direction.EAST))
            {
                o |= WireMask.East; no++;
            }
            if (getSingleConnection(v, Direction.WEST))
            {
                o |= WireMask.West; no++;
            }
            //in special cases

            switch (no)
            {
            case 0:     // Not connected
                return(WireMask.North | WireMask.South | WireMask.East | WireMask.West | WireMask.BlockPower);

            case 1:     // One Connected
                switch (o)
                {
                case WireMask.North: o |= WireMask.South; break;

                case WireMask.South: o |= WireMask.North; break;

                case WireMask.West: o |= WireMask.East; break;

                case WireMask.East: o |= WireMask.West; break;
                }
                o |= WireMask.BlockPower;
                break;

            case 2:
                if ((o & WireMask.North & WireMask.South) == (WireMask.North & WireMask.South) ||
                    (o & WireMask.East & WireMask.West) == (WireMask.East & WireMask.West))
                {
                    o |= WireMask.BlockPower;
                }
                break;
            }
            return(o);
        }
Beispiel #2
0
        public void drawWire(Graphics g, Rectangle r, int x, int y, int z)
        {
            WireMask m = WireMask.None;

            if (currentSim.canConnect(x, y, x - 1, y, z))
            {
                m |= WireMask.West;
            }
            if (currentSim.canConnect(x, y, x + 1, y, z))
            {
                m |= WireMask.East;
            }
            if (currentSim.canConnect(x, y, x, y - 1, z))
            {
                m |= WireMask.North;
            }
            if (currentSim.canConnect(x, y, x, y + 1, z))
            {
                m |= WireMask.South;
            }

            BlockImages.gDrawBlock(g, r, new BlockDrawSettings(currentSim.GetBlock(x, y, z), m));
        }
 public bool canBePoweredByRepeaterTorch(WireMask dir,WireMask test)
 {
     return isTorch && ((dir & test) == test) && charge > 0;
 }
 public BlockDrawSettings(Blocks Block, WireMask Mask, bool On)
     : this(Block,Mask)
 {
     block.Power = On ? 16 : 0;
 }
 public BlockDrawSettings(Blocks Block, WireMask Mask)
     : this(Block)
 {
     this.Mask = Mask;
 }
Beispiel #6
0
 public bool canBePoweredByRepeaterTorch(WireMask dir, WireMask test)
 {
     return(isTorch && ((dir & test) == test) && charge > 0);
 }
Beispiel #7
0
        private void WirePower(BlockVector v)
        {
            WireMask c       = getConnections(v);
            Block    current = data[v];

            //up
            if (v.Z < lenZ)
            {
                if (!data[v.Up].isBlock)
                {                                                              //can be lead up
                    if (((c & WireMask.North) == WireMask.North) && (v.Y > 0)) // Connected north and not a wall
                    {
                        if (current.Charge - 1 > data[v.North.Up].Charge)
                        {
                            Power(v.Up, Direction.NORTH, BlockType.WIRE, current.Charge - 1);
                        }
                    }

                    if (((c & WireMask.West) == WireMask.West) && (v.X > 0))  // Connected north and not a wall
                    {
                        if (current.Charge - 1 > data[v.West.Up].Charge)
                        {
                            Power(v.Up, Direction.WEST, BlockType.WIRE, current.Charge - 1);
                        }
                    }

                    if (((c & WireMask.South) == WireMask.South) && (v.Y < lenY - 1))  // Connected north and not a wall
                    {
                        if (current.Charge - 1 > data[v.South.Up].Charge)
                        {
                            Power(v.Up, Direction.SOUTH, BlockType.WIRE, current.Charge - 1);
                        }
                    }

                    if (((c & WireMask.East) == WireMask.East) && (v.X < lenX - 1))  // Connected north and not a wall
                    {
                        if (current.Charge - 1 > data[v.East.Up].Charge)
                        {
                            Power(v.Up, Direction.EAST, BlockType.WIRE, current.Charge - 1);
                        }
                    }
                }
            }

            //down
            if (v.Z > 0)
            {
                if (current.Charge > data[v.Down].Charge) // If block directly under
                {
                    Power(v, Direction.DOWN, BlockType.BLOCK, data[v].Charge);
                }


                if (((c & WireMask.North) == WireMask.North) && (v.Y > 0))  // Connected north and not a wall
                {
                    if (!data[v.North].isBlock && current.Charge - 1 > data[v.North.Down].Charge)
                    {
                        Power(v.Down, Direction.NORTH, BlockType.WIRE, current.Charge - 1);
                    }
                }

                if (((c & WireMask.West) == WireMask.West) && (v.X > 0))   // Connected north and not a wall
                {
                    if (!data[v.West].isBlock && current.Charge - 1 > data[v.West.Down].Charge)
                    {
                        Power(v.Up, Direction.WEST, BlockType.WIRE, current.Charge - 1);
                    }
                }

                if (((c & WireMask.South) == WireMask.South) && (v.Y < lenY - 1))   // Connected north and not a wall
                {
                    if (!data[v.South].isBlock && current.Charge - 1 > data[v.South.Down].Charge)
                    {
                        Power(v.Up, Direction.SOUTH, BlockType.WIRE, current.Charge - 1);
                    }
                }

                if (((c & WireMask.East) == WireMask.East) && (v.X < lenX - 1))   // Connected north and not a wall
                {
                    if (!data[v.East].isBlock && current.Charge - 1 > data[v.East.Down].Charge)
                    {
                        Power(v.Up, Direction.EAST, BlockType.WIRE, current.Charge - 1);
                    }
                }
            }



            //same level
            if (((c & WireMask.North) == WireMask.North) && (v.Y > 0))
            {// Connected north and not a wall
                if (current.Charge - 1 > data[v.North].Charge)
                {
                    Power(v, Direction.NORTH, BlockType.WIRE, current.Charge - 1);
                }
                if ((c & WireMask.BlockPower) == WireMask.BlockPower && (current.Charge > data[v.North].Charge))
                {
                    Power(v, Direction.NORTH, BlockType.BLOCK, current.Charge);
                }
            }
            if (((c & WireMask.West) == WireMask.West) && (v.X > 0))
            { // Connected north and not a wall
                if (current.Charge - 1 > data[v.West].Charge)
                {
                    Power(v, Direction.WEST, BlockType.WIRE, current.Charge - 1);
                }
                if ((c & WireMask.BlockPower) == WireMask.BlockPower && (current.Charge > data[v.West].Charge))
                {
                    Power(v, Direction.NORTH, BlockType.BLOCK, current.Charge);
                }
            }
            if (((c & WireMask.South) == WireMask.South) && (v.Y < lenY - 1))
            { // Connected north and not a wall
                if (current.Charge - 1 > data[v.South].Charge)
                {
                    Power(v, Direction.SOUTH, BlockType.WIRE, current.Charge - 1);
                }
                if ((c & WireMask.BlockPower) == WireMask.BlockPower && (current.Charge > data[v.South].Charge))
                {
                    Power(v, Direction.NORTH, BlockType.BLOCK, current.Charge);
                }
            }
            if (((c & WireMask.East) == WireMask.East) && (v.Y < lenX - 1))
            {  // Connected north and not a wall
                if (current.Charge - 1 > data[v.East].Charge)
                {
                    Power(v, Direction.EAST, BlockType.WIRE, current.Charge - 1);
                }
                if ((c & WireMask.BlockPower) == WireMask.BlockPower && (current.Charge > data[v.East].Charge))
                {
                    Power(v, Direction.NORTH, BlockType.BLOCK, current.Charge);
                }
            }
        }
Beispiel #8
0
 public static bool TestMask(WireMask obj, WireMask toTest)
 {
     return((obj & toTest) == toTest);
 }
Beispiel #9
0
 public BlockDrawSettings(Blocks Block, WireMask Mask, bool On) : this(Block, Mask)
 {
     block.Power = On ? 16 : 0;
 }
Beispiel #10
0
 public BlockDrawSettings(Blocks Block, WireMask Mask) : this(Block) { this.Mask = Mask; }