private void followWireQ(BlockVector v, int p) { if (GetBlock(v).Type == eBlock.WIRE) followWire(v, p); else if (GetBlock(v).isBlock) { if (GetBlock(v.Up).Type == eBlock.WIRE && !GetBlock(v.Old).isBlock) followWire(v.Up, p); } else if (GetBlock(v.Down).Type == eBlock.WIRE) followWire(v.Down, p); }
public void SetPower(BlockVector v,int p) { if (v.Z < 0 || v.Z >= lenZ || v.Y < 0 || v.Y >= lenY || v.X < 0 || v.X >= lenX) return; data[v.X, v.Y, v.Z].Power = p; }
public void update() { // Clear power, tick to torches. Put in repeater in here for (int z = 0; z < lenZ; z++) for (int y = 0; y < lenY; y++) for (int x = 0; x < lenX; x++) { BlockVector v = new BlockVector(x,y,z); Blocks b = GetBlock(v); if (b.Type == eBlock.WIRE || b.Type == eBlock.DOORB) SetPower(v,0); else if (b.isBlock) { SetPower(v,0); if (GetBlock(v.Down).Powered && GetBlock(v.Down).Type == eBlock.TORCH) { // A torch below a block powers the block SetPower(v,17); } else { // Check if there is a switch on the block and turn it on if(GetBlock(v.North).isControl && GetBlock(v.North).Mount == eMount.NORTH && GetBlock(v).Powered) SetPower(v,17); if(GetBlock(v.South).isControl && GetBlock(v.South).Mount == eMount.SOUTH && GetBlock(v).Powered) SetPower(v,17); if(GetBlock(v.East).isControl && GetBlock(v.East).Mount == eMount.EAST && GetBlock(v).Powered) SetPower(v,17); if(GetBlock(v.West).isControl && GetBlock(v.West).Mount == eMount.WEST && GetBlock(v).Powered) SetPower(v,17); if(GetBlock(v.Up).isControl && GetBlock(v.Up).Mount == eMount.TOP && GetBlock(v).Powered) SetPower(v,17); } } } for (int z = 0; z < lenZ; z++) for (int y = 0; y < lenY; y++) for (int x = 0; x < lenX; x++) { BlockVector v = new BlockVector(x,y,z); Blocks b = GetBlock(v); if (b.Power >= (b.Type != eBlock.BUTTON && b.Type != eBlock.PRESS ? 16 : 1) && (b.Type == eBlock.TORCH || b.isControl || b.isBlock && b.Power == 17)) { if (GetBlock(v.Up).Type == eBlock.WIRE) followWire(v.Up, 15); if (GetBlock(v.Down).Type == eBlock.WIRE) followWire(v.Down, 15); if (GetBlock(v.North).Type == eBlock.WIRE) followWire(v.North, 15); if (GetBlock(v.South).Type == eBlock.WIRE) followWire(v.South, 15); if (GetBlock(v.East).Type == eBlock.WIRE) followWire(v.East, 15); if (GetBlock(v.West).Type == eBlock.WIRE) followWire(v.West, 15); } } for (int z = 0; z < lenZ; z++) for (int y = 0; y < lenY; y++) for (int x = 0; x < lenX; x++) { BlockVector v = new BlockVector(x,y,z); Blocks b = GetBlock(v); if ((b.isBlock && !b.Powered || b.Type == eBlock.DOORA) && (GetBlock(v.Up).Type == eBlock.WIRE && GetBlock(v.Up).Powered || blockConnect(x, y, 0, 1, z, true) || blockConnect(x, y, 0, -1, z, true) || blockConnect(x, y, 1, 0, z, true) || blockConnect(x, y, -1, 0, z, true))) data[x, y, z].Power = 16; } }
public Blocks GetBlock(BlockVector v) { if (v.Z < 0) return Blocks.BLOCK; if (v.Z >= lenZ || v.Y < 0 || v.Y >= lenY || v.X < 0 || v.X >= lenX) return Blocks.AIR; return data[v.X, v.Y, v.Z]; }
public int GetPower(BlockVector v) { if (v.Z < 0 || v.Z >= lenZ || v.Y < 0 || v.Y >= lenY || v.X < 0 || v.X >= lenX) return 0; return data[v.X, v.Y, v.Z].Power; }
private void place(BlockVector v, bool rotate) { if (currentSim[v].ID == selectedBlock) { Block b = currentSim[v]; Direction old = b.Place; switch (selectedBlock) { case BlockType.TORCH: case BlockType.LEVER: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) { break; } if (currentSim[v.East].isBlock && b.Place == Direction.WEST) { break; } if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) { break; } if (currentSim[v.West].isBlock && b.Place == Direction.EAST) { break; } if (currentSim[v.Down].isBlock && b.Place == Direction.DOWN) { break; } if (b.Place != old) { goto case BlockType.LEVER; } b.Place = old; break; case BlockType.BUTTON: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) { break; } if (currentSim[v.East].isBlock && b.Place == Direction.WEST) { break; } if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) { break; } if (currentSim[v.West].isBlock && b.Place == Direction.EAST) { break; } if (b.Place != old) { goto case BlockType.LEVER; } b.Place = old; break; case BlockType.REPEATER: if (b.Place == Direction.WEST) { b.Place = Direction.NORTH; } else { b.Place++; } break; } } else { Block oldBlock = currentSim[v]; Block b = Block.New(selectedBlock); Direction old = b.Place; switch (selectedBlock) { case BlockType.TORCH: case BlockType.LEVER: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) { currentSim[v] = b; break; } if (currentSim[v.East].isBlock && b.Place == Direction.WEST) { currentSim[v] = b; break; } if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) { currentSim[v] = b; break; } if (currentSim[v.West].isBlock && b.Place == Direction.EAST) { currentSim[v] = b; break; } if (currentSim[v.Down].isBlock && b.Place == Direction.DOWN) { currentSim[v] = b; break; } if (b.Place != old) { goto case BlockType.LEVER; } return; case BlockType.BUTTON: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) { currentSim[v] = b; break; } if (currentSim[v.East].isBlock && b.Place == Direction.WEST) { currentSim[v] = b; break; } if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) { currentSim[v] = b; break; } if (currentSim[v.West].isBlock && b.Place == Direction.EAST) { currentSim[v] = b; break; } if (b.Place != old) { goto case BlockType.LEVER; } return; case BlockType.REPEATER: if (b.Place == Direction.WEST) { b.Place = Direction.NORTH; } else { b.Place++; } currentSim[v] = b; break; case BlockType.WIRE: currentSim[v] = b; currentSim.setConnections(v); break; default: currentSim[v] = b; //if the old block was a wire, we need to recheck the connections //so that the previously wired block does not hold the wire connections //that it did previously hold // Was: | Now Is: // ┌┐ -> ┌┐ | ┌┐ -> ┌─ // └┘ -> └ | └┘ -> │ // if (oldBlock.ID == BlockType.WIRE) { currentSim.setConnections(v); } break; } } currentSim.updateT(); this.Refresh(); }
public BlockVector(BlockVector v) : this(v.X, v.Y, v.Z) { }
private BitArray isValid(BlockVector v) { return(isValid(v.X, v.Y, v.Z)); }
public bool Equals(BlockVector v) { return(this.V == v); }
private void RepeaterPower(BlockVector v) { Power(v, data[v].Place, BlockType.WIRE, 15); Power(v, data[v].Place, BlockType.BLOCK, 16); }
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); } } }
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; } } } } } } } }
public BlockNode(BlockNode N) : this() { this.B = N.B; this.V = N.V; }
public BlockNode(BlockNode N, BlockVector V) : this() { this.B = N.B; this.V = V; }
public Block this[BlockVector v] { get { return(data[v]); } set { data[v] = value; } }
public Block this[BlockVector v] { get { return(this[v.X, v.Y, v.Z]); } set { this[v.X, v.Y, v.Z] = value; } }
void UpdateLoc(Point p, int cFloor) { if (p.X < 0 || p.Y < 0 || p.X > this.Width|| p.Y > this.Height) { UpdateLoc(false); } else { currentLoc = new BlockVector((int)(p.X / scale / 9), (int)(p.Y / scale / 9), floor); UpdateLoc(true); } }
public bool canConnect(int x, int y, int tX, int tY, int z) { BlockVector v = new BlockVector(x, y, z); v.SetNext(tX, tY); Blocks test = GetBlock(v); if (test.WireConn) { return(true); } if (test.isAir) { return(GetBlockType(v.Down) == eBlock.WIRE); } if (test.isBlock) { BlockVector t = BlockVector.Null; if (GetBlockType(v.Up) == eBlock.WIRE && !(GetBlockType(v.Old.Up) == eBlock.BLOCK)) { return(true); } if (GetBlock(v.North).Mount == eMount.NORTH) { t = v.North; } if (GetBlock(v.South).Mount == eMount.SOUTH) { t = v.South; } if (GetBlock(v.East).Mount == eMount.EAST) { t = v.East; } if (GetBlock(v.West).Mount == eMount.WEST) { t = v.West; } if (GetBlock(v.Up).Mount == eMount.TOP) { t = v.Up; } if (!t.isNull) { if (GetBlockType(t) == eBlock.TORCH) { return(blockConnect(v.X, v.Y, v.Old.X - v.X, v.Old.Y - v.Y, z, false)); } else { return(GetBlock(v.Up).Mount != eMount.TOP || GetBlockType(t) != eBlock.LEVER); } } return(GetBlockType(v.Down) == eBlock.TORCH); } else { return(false); } }
public bool canConnect(int x, int y, int tX, int tY, int z) { BlockVector v = new BlockVector(x, y, z); v.SetNext(tX, tY); Blocks test = GetBlock(v); if (test.WireConn) return true; if (test.isAir) return GetBlockType(v.Down)== eBlock.WIRE; if (test.isBlock) { BlockVector t = BlockVector.Null; if (GetBlockType(v.Up) == eBlock.WIRE && !(GetBlockType(v.Old.Up) == eBlock.BLOCK)) return true; if (GetBlock(v.North).Mount == eMount.NORTH) t = v.North; if (GetBlock(v.South).Mount == eMount.SOUTH) t = v.South; if (GetBlock(v.East).Mount == eMount.EAST) t = v.East; if (GetBlock(v.West).Mount == eMount.WEST) t = v.West; if (GetBlock(v.Up).Mount == eMount.TOP) t = v.Up; if(!t.isNull) if (GetBlockType(t) == eBlock.TORCH) return blockConnect(v.X, v.Y, v.Old.X - v.X, v.Old.Y - v.Y, z, false); else return GetBlock(v.Up).Mount != eMount.TOP || GetBlockType(t) != eBlock.LEVER; return GetBlockType(v.Down) == eBlock.TORCH; } else { return false; } }
public void update() { // Clear power, tick to torches. Put in repeater in here for (int z = 0; z < lenZ; z++) { for (int y = 0; y < lenY; y++) { for (int x = 0; x < lenX; x++) { BlockVector v = new BlockVector(x, y, z); Blocks b = GetBlock(v); if (b.Type == eBlock.WIRE || b.Type == eBlock.DOORB) { SetPower(v, 0); } else if (b.isBlock) { SetPower(v, 0); if (GetBlock(v.Down).Powered&& GetBlock(v.Down).Type == eBlock.TORCH) { // A torch below a block powers the block SetPower(v, 17); } else { // Check if there is a switch on the block and turn it on if (GetBlock(v.North).isControl&& GetBlock(v.North).Mount == eMount.NORTH && GetBlock(v).Powered) { SetPower(v, 17); } if (GetBlock(v.South).isControl&& GetBlock(v.South).Mount == eMount.SOUTH && GetBlock(v).Powered) { SetPower(v, 17); } if (GetBlock(v.East).isControl&& GetBlock(v.East).Mount == eMount.EAST && GetBlock(v).Powered) { SetPower(v, 17); } if (GetBlock(v.West).isControl&& GetBlock(v.West).Mount == eMount.WEST && GetBlock(v).Powered) { SetPower(v, 17); } if (GetBlock(v.Up).isControl&& GetBlock(v.Up).Mount == eMount.TOP && GetBlock(v).Powered) { SetPower(v, 17); } } } } } } for (int z = 0; z < lenZ; z++) { for (int y = 0; y < lenY; y++) { for (int x = 0; x < lenX; x++) { BlockVector v = new BlockVector(x, y, z); Blocks b = GetBlock(v); if (b.Power >= (b.Type != eBlock.BUTTON && b.Type != eBlock.PRESS ? 16 : 1) && (b.Type == eBlock.TORCH || b.isControl || b.isBlock && b.Power == 17)) { if (GetBlock(v.Up).Type == eBlock.WIRE) { followWire(v.Up, 15); } if (GetBlock(v.Down).Type == eBlock.WIRE) { followWire(v.Down, 15); } if (GetBlock(v.North).Type == eBlock.WIRE) { followWire(v.North, 15); } if (GetBlock(v.South).Type == eBlock.WIRE) { followWire(v.South, 15); } if (GetBlock(v.East).Type == eBlock.WIRE) { followWire(v.East, 15); } if (GetBlock(v.West).Type == eBlock.WIRE) { followWire(v.West, 15); } } } } } for (int z = 0; z < lenZ; z++) { for (int y = 0; y < lenY; y++) { for (int x = 0; x < lenX; x++) { BlockVector v = new BlockVector(x, y, z); Blocks b = GetBlock(v); if ((b.isBlock && !b.Powered || b.Type == eBlock.DOORA) && (GetBlock(v.Up).Type == eBlock.WIRE && GetBlock(v.Up).Powered || blockConnect(x, y, 0, 1, z, true) || blockConnect(x, y, 0, -1, z, true) || blockConnect(x, y, 1, 0, z, true) || blockConnect(x, y, -1, 0, z, true))) { data[x, y, z].Power = 16; } } } } }
/// <summary> /// Tests if two blocks can connect /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="tX"></param> /// <param name="tY"></param> /// <param name="z"></param> /// <returns></returns> public bool canConnectOld(int x, int y, int tX, int tY, int z) { BlockVector v = new BlockVector(x, y, z); Blocks test = GetBlock(v); if (test.isAir) // if the block is Air, return the connection below return GetBlock(v.Down).WireConn; if (test.isBlock) // if there isn't a block above us ANd we have a connection on the block in front.. return !GetBlock(v.Old.Up).isBlock && GetBlock(v.Up).WireConn; if (test.Type == eBlock.REPEATER) { // Repeater matters what side its connected too. // Luckly ANYTHING can power a repeater switch (test.Mount) { case eMount.NORTH: case eMount.SOUTH: if ((tY < y || tY > y) && tX == x) return true; else return false; case eMount.EAST: case eMount.WEST: if ((tX < x || tX > x) && tY == y) return true; else return false; default: return false; } } else return true; }
public eBlock GetBlockType(BlockVector v) { if (v.Z < 0) return eBlock.BLOCK; if (v.Z >= lenZ || v.Y < 0 || v.Y >= lenY || v.X < 0 || v.X >= lenX) return eBlock.AIR; return data[v.X, v.Y, v.Z].Type; }
void Display_MouseDown(object sender, MouseEventArgs e) { if(!mouseLeftDown) switch(e.Button) { case System.Windows.Forms.MouseButtons.Left: startMouse = e.Location; startLoc = currentLoc; place(currentLoc, false); isDragging = false; mouseLeftDown = true; break; case System.Windows.Forms.MouseButtons.Right: if (currentSim[currentLoc].isControl) { currentSim[currentLoc].Powered = !currentSim[currentLoc].Powered; currentSim.updateT(); this.Invalidate(); } if (currentSim[currentLoc].isRepeater) { currentSim[currentLoc].increaseTick(); currentSim.updateT(); this.Invalidate(); } break; } }
public void SetBlock(BlockVector v, eBlock b) { if (v.Z < 0 || v.Z >= lenZ || v.Y < 0 || v.Y >= lenY || v.X < 0 || v.X >= lenX) return; data[v.X,v.Y,v.Z] = new Blocks(b); }
void Display_MouseMove(object sender, MouseEventArgs e) { UpdateLoc(e.Location, floor); if (mouseLeftDown) { if (startLoc != currentLoc) { startLoc = currentLoc; place(currentLoc, false); } } else { // Rectangle g = new Rectangle(0, 0, this.Width, blockSelect.Height); // if (g.Contains(e.Location)) // { blockSelect.Visible = true; blockSelect.Focus(); } // else // { blockSelect.Visible = false; } } }
public void tick() { for (int z = 0; z < lenZ; z++) for (int y = 0; y < lenY; y++) for (int x = 0; x < lenX; x++) { BlockVector v = new BlockVector(x, y, z); Blocks b = data[x, y, z]; if (b.Type == eBlock.TORCH) { switch (b.Mount) { case eMount.TOP: SetPower(v, GetPower(v.Down) < 16 ? 16 : 0); break; case eMount.SOUTH: SetPower(v, GetPower(v.South) < 16 ? 16 : 0); break; case eMount.NORTH: SetPower(v, GetPower(v.North) < 16 ? 16 : 0); break; case eMount.EAST: SetPower(v, GetPower(v.East) < 16 ? 16 : 0); break; case eMount.WEST: SetPower(v, GetPower(v.West) < 16 ? 16 : 0); break; } } else if (b.CtrlOn && (b.Type == eBlock.BUTTON || b.Type == eBlock.PRESS)) data[x, y, z].Power--; update(); } }
private void Display_Paint(object sender, PaintEventArgs e) { if (!stopPaint) { Graphics g = e.Graphics; g.Clear(BlockColors.cGrid); // g.PageScale g.ScaleTransform(scale, scale); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; for (int x = 0; x < currentSim.X; x++) for (int y = 0; y < currentSim.Y; y++) { BlockDrawSettings b; BlockVector v = new BlockVector(x, y, floor); if (currentSim[v].isBlock && (currentSim[v.Up].isWire || currentSim[v.Up].isPreasurePad || ((currentSim[v.Up].isTorch || currentSim[v.Up].isLeaver || currentSim[v.Up].isTorch) && currentSim[v.Up].Place == Direction.DOWN))) { v = v.Up; b = new BlockDrawSettings(currentSim[v]); b.OnBlock = true; } else { b = new BlockDrawSettings(currentSim[v]); } if (currentSim[v.Up].isBlock) b.Fog = true; Rectangle r = new Rectangle(x * 9 + 1, y * 9 + 1, 8, 8); BlockImages.gDrawBlock(g, r, b); } } }
private void followWire(BlockVector v, int p) { Blocks b = GetBlock(v); if (p <= b.Power) return; SetPower(v, p); if (p == 0) { return; } else { followWireQ(v.North, p - 1); followWireQ(v.South, p - 1); followWireQ(v.West, p - 1); followWireQ(v.East, p - 1); return; } }
private void place(BlockVector v, bool rotate) { if (currentSim[v].ID == selectedBlock) { Block b = currentSim[v]; Direction old = b.Place; switch (selectedBlock) { case BlockType.TORCH: case BlockType.LEVER: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) break; if (currentSim[v.East].isBlock && b.Place == Direction.WEST) break; if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) break; if (currentSim[v.West].isBlock && b.Place == Direction.EAST) break; if (currentSim[v.Down].isBlock && b.Place == Direction.DOWN) break; if (b.Place != old) goto case BlockType.LEVER; b.Place = old; break; case BlockType.BUTTON: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) break; if (currentSim[v.East].isBlock && b.Place == Direction.WEST) break; if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) break; if (currentSim[v.West].isBlock && b.Place == Direction.EAST) break; if (b.Place != old) goto case BlockType.LEVER; b.Place = old; break; case BlockType.REPEATER: if (b.Place == Direction.WEST) { b.Place = Direction.NORTH; } else { b.Place++; } break; } } else { Block oldBlock = currentSim[v]; Block b = Block.New(selectedBlock); Direction old = b.Place; switch (selectedBlock) { case BlockType.TORCH: case BlockType.LEVER: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) { currentSim[v] = b; break; } if (currentSim[v.East].isBlock && b.Place == Direction.WEST) { currentSim[v] = b; break; } if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) { currentSim[v] = b; break; } if (currentSim[v.West].isBlock && b.Place == Direction.EAST) { currentSim[v] = b; break; } if (currentSim[v.Down].isBlock && b.Place == Direction.DOWN) { currentSim[v] = b; break; } if (b.Place != old) goto case BlockType.LEVER; return; case BlockType.BUTTON: if (b.Place == Direction.WEST) { b.Place = Direction.DOWN; } else { b.Place++; } if (currentSim[v.South].isBlock && b.Place == Direction.NORTH) { currentSim[v] = b; break; } if (currentSim[v.East].isBlock && b.Place == Direction.WEST) { currentSim[v] = b; break; } if (currentSim[v.North].isBlock && b.Place == Direction.SOUTH) { currentSim[v] = b; break; } if (currentSim[v.West].isBlock && b.Place == Direction.EAST) { currentSim[v] = b; break; } if (b.Place != old) goto case BlockType.LEVER; return; case BlockType.REPEATER: if (b.Place == Direction.WEST) { b.Place = Direction.NORTH; } else { b.Place++; } currentSim[v] = b; break; case BlockType.WIRE: currentSim[v] = b; currentSim.setConnections(v); break; default: currentSim[v] = b; //if the old block was a wire, we need to recheck the connections //so that the previously wired block does not hold the wire connections //that it did previously hold // Was: | Now Is: // ┌┐ -> ┌┐ | ┌┐ -> ┌─ // └┘ -> └ | └┘ -> │ // if (oldBlock.ID == BlockType.WIRE) { currentSim.setConnections(v); } break; } } currentSim.updateT(); this.Refresh(); }
public Block this[BlockVector v] { get { return this[v.X, v.Y, v.Z]; } set { this[v.X, v.Y, v.Z] = value; } }
public BlockNode(Block B, BlockVector V) : this() { this.B = B; this.V = V; }