Пример #1
0
 public void setConnections(BlockVector v)
 {
     data[v].Mask = getConnections(v);
     foreach (Direction d in CompassDir)
     {
         data[v.Dir(d)].Mask = getConnections(v.Dir(d));
     }
 }
Пример #2
0
 void SearchWire(BlockVector v)
 {
     foreach (Direction d in CompassDir)
     {
         if (data[v.Dir(d)].isWire)
         {
             followWire(v.Dir(d), 15);
         }
     }
 }
Пример #3
0
        public void newTick()
        {
            // Turn on all torches that are powered by a block, this is where we tick the repeater when I get to it
            for (int x = 0; x < lenX; x++)
            {
                for (int y = 0; y < lenY; y++)
                {
                    for (int z = 0; z < lenZ; z++)
                    {
                        BlockVector v = new BlockVector(x, y, z);
                        Block       b = data[x, y, z];
                        switch (b.ID)
                        { // Check torches and count down button, pad timers.
                        case BlockType.BLOCK:
                            foreach (Direction d in Directions)
                            {
                                if (!(d == Direction.DOWN))
                                {
                                    if (data[v.Dir(d)].isTorch)
                                    {
                                        data[v.Dir(d)].Powered = !b.Source;
                                    }
                                }
                            }
                            //  case BlockType.TORCH: // Power a torch from a powered block
                            //     b.Powered = !data[v.Flip(b.Place)].Source;
                            break;

                        case BlockType.PREASUREPAD:
                        case BlockType.BUTTON:
                            if (b.Powered)
                            {
                                b.Charge--;
                            }
                            break;
                        }
                    }
                }
            }


            updateT();
        }
Пример #4
0
        /*   private DirectionMask isValid(BlockVector v)
         * {
         *     DirectionMask d;
         *     d |= z == 0?DirectionMask.DOWN;
         *     d |= y == 0?Direction.EAST;
         *     d |= x == lenX - 1?DirectionMask.SOUTH;
         *     d |= y == lenY - 1?DirectionMask.WEST;
         *     d |= x == 0?DirectionMask.;
         *     d |= z == lenZ - 1?;
         *
         * }*/

        private void Power(BlockVector v, Direction dir, BlockType target, int charge)
        {
            if (isValid(v, dir))
            {
                BlockVector t = v.Dir(dir);
                if (data[t].ID == target)
                {
                    data[t].Charge = charge;
                    source.Add(v);
                    update.Add(v);
                }
            }
        }
Пример #5
0
        public bool getSingleConnection(BlockVector v, Direction dir)
        {
            BlockVector n = v.Dir(dir);

            if (data[n].isAir && data[n.Down].canConnect)
            {
                return(true);
            }
            if (data[n].canConnect)
            {
                return(true);
            }
            if (data[v.Up].isAir && data[n].isBlock && data[n.Up].canConnect)
            {
                return(true);
            }
            return(false);
        }
Пример #6
0
        public bool WireConn(BlockVector v, Direction dir)
        {
            // Fix for repeater
            BlockVector n = v.Dir(dir); // Cache the current direction we are facing

            if (data[n].isAir)
            {
                return(data[n.Down].canConnect);              // if
            }
            if (data[n].isBlock)
            {
                return(!data[v.Up].isBlock && data[n.Up].canConnect);
            }
            else
            {
                return(true);
            }
        }
Пример #7
0
        void followWireQ(BlockVector v, Direction d, int pow)
        {
            BlockVector n = v.Dir(d);

            if (data[n].isWire)
            {
                followWire(n, pow);
            }
            if (data[n].isBlock)
            {
                if (data[n.Up].isWire && !data[v.Up].isBlock)
                {
                    followWire(n.Up, pow);
                }
            }
            else
            if (data[n.Down].isWire)
            {
                followWire(n.Down, pow);
            }
        }
Пример #8
0
        bool blockConnect(BlockVector v, Direction d, bool pow)
        {
            BlockVector n  = v.Dir(d);
            BlockVector t1 = n.RotateLeft(d);
            BlockVector t2 = n.RotateRight(d);

            if (!data[n].isWire || !data[n].Powered && pow)
            {
                return(false);
            }
            if (data[t1].isBlock)
            {
                if (!data[n].isBlock && data[t1.Up].canConnect)
                {
                    return(false);
                }
            }
            else if (data[t1].isAir)
            {
                if (data[t1.Down].canConnect)
                {
                    return(false);
                }
            }
            if (data[t2].isBlock)
            {
                return(data[n.Up].isBlock || !data[t2.Up].canConnect);
            }
            if (data[t2].isAir)
            {
                return(!data[t2.Down].canConnect);
            }
            else
            {
                return(false);
            }
        }
Пример #9
0
        public void updateT()
        {
            // Change this to be using a stack
            // Clear all wires and torches, power blocks by hard power (switches, or under torch)
            for (int x = 0; x < lenX; x++)
            {
                for (int y = 0; y < lenY; y++)
                {
                    for (int z = 0; z < lenZ; z++)
                    {
                        BlockVector v = new BlockVector(x, y, z);
                        Block       b = data[v];
                        switch (b.ID)
                        {
                        case BlockType.WIRE: b.Powered = false; break;

                        case BlockType.BLOCK:
                            b.Source = false;
                            if (data[v.Down].Powered && data[v.Down].isTorch)
                            {
                                b.Source = true;     // Block is powered by a torch
                            }
                            break;

                        case BlockType.LEVER:
                            if (b.Powered)
                            {
                                data[v.Flip(b.Place)].Source = true;
                            }
                            break;
                        }
                    }
                }
            }

            // Power on all the wires
            for (int x = 0; x < lenX; x++)
            {
                for (int y = 0; y < lenY; y++)
                {
                    for (int z = 0; z < lenZ; z++)
                    {
                        BlockVector v = new BlockVector(x, y, z);
                        Block       b = data[v];
                        switch (b.ID)
                        {
                        case BlockType.BUTTON:
                            break;

                        case BlockType.PREASUREPAD:
                        case BlockType.TORCH:
                        case BlockType.LEVER:
                            if (b.Powered)
                            {
                                SearchWire(v);
                            }
                            break;

                        case BlockType.BLOCK:
                            //if (b.Charge == 17)
                            //   SearchWire(v);
                            break;
                        }
                    }
                }
            }

            for (int x = 0; x < lenX; x++)
            {
                for (int y = 0; y < lenY; y++)
                {
                    for (int z = 0; z < lenZ; z++)
                    {
                        BlockVector v = new BlockVector(x, y, z);
                        Block       b = data[v];
                        if (b.isBlock && !b.Source)
                        {
                            foreach (Direction d in Directions)
                            {
                                if (!(d == Direction.DOWN))
                                {
                                    Block c = data[v.Dir(d)];
                                    if (c.isWire && c.Powered && c.Mask.HasFlag(WireMask.BlockPower))
                                    {
                                        b.Source = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }