public override void Perform(Vec3U16[] marks, Player p, Level lvl, Brush brush) { Vec3U16 p1 = marks[0], p2 = marks[1]; List <FillPos> buffer = new List <FillPos>(); DrawLine(p1.X, p1.Y, p1.Z, MaxLength, p2.X, p2.Y, p2.Z, buffer); if (WallsMode) { ushort yy1 = p1.Y, yy2 = p2.Y; p1.Y = Math.Min(yy1, yy2); p2.Y = Math.Max(yy1, yy2); } for (int i = 0; i < buffer.Count; i++) { FillPos pos = buffer[i]; if (WallsMode) { for (ushort yy = p1.Y; yy <= p2.Y; yy++) { PlaceBlock(p, lvl, pos.X, yy, pos.Z, brush); } } else { PlaceBlock(p, lvl, pos.X, pos.Y, pos.Z, brush); } } }
void FindNext(Vec3U16 lookedAt, ref Vec3U16 pos, List <FillPos> buffer) { LineDrawOp.DrawLine(pos.X, pos.Y, pos.Z, 2, lookedAt.X, lookedAt.Y, lookedAt.Z, buffer); FillPos end = buffer[buffer.Count - 1]; pos.X = end.X; pos.Y = end.Y; pos.Z = end.Z; buffer.Clear(); }
void PullBack(Player p, FillPos cur, FillPos target, int dirX, int dirZ) { byte type = p.level.GetTile(cur.X, cur.Y, cur.Z), extType = 0; if (type == Block.custom_block) { extType = p.level.GetExtTile(cur.X, cur.Y, cur.Z); } p.level.Blockchange(p, cur.X, cur.Y, cur.Z, type); while (cur.X != target.X || cur.Z != target.Z) { byte tile = p.level.GetTile(cur.X, cur.Y, cur.Z), extTile = 0; if (tile == Block.custom_block) { extTile = p.level.GetExtTile(cur.X, cur.Y, cur.Z); } if (tile == type) { if (tile != Block.custom_block || (tile == Block.custom_block && extTile == extType)) { p.level.Blockchange(p, cur.X, cur.Y, cur.Z, 0); } } cur.X = (ushort)(cur.X - dirX); cur.Z = (ushort)(cur.Z - dirZ); if (cur.X >= p.level.Width || cur.Z >= p.level.Length) { return; } tile = p.level.GetTile(cur.X, cur.Y, cur.Z); if (tile == Block.mushroom) { p.level.Blockchange(p, cur.X, cur.Y, cur.Z, type, extType); } Thread.Sleep(250); } }
private static bool CalculateFillBuffer(ZoneTool z, Vector3 position, Vector3 direction, ItemClass.Zone requiredZone, bool occupied1, bool occupied2) { var m_fillBuffer1 = (ulong[])typeof(ZoneTool).GetField("m_fillBuffer1", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(z); for (int index = 0; index < 64; ++index) { m_fillBuffer1[index] = 0UL; } if (!occupied2) { float angle = Mathf.Atan2(-direction.x, direction.z); float num1 = position.x - 256f; float num2 = position.z - 256f; float num3 = position.x + 256f; float num4 = position.z + 256f; int num5 = Mathf.Max((int)((num1 - 46f) / 64f + FakeZoneManager.HALFGRID), 0); int num6 = Mathf.Max((int)((num2 - 46f) / 64f + FakeZoneManager.HALFGRID), 0); int num7 = Mathf.Min((int)((num3 + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1); int num8 = Mathf.Min((int)((num4 + 46f) / 64f + FakeZoneManager.HALFGRID), FakeZoneManager.GRIDSIZE - 1); ZoneManager instance = Singleton <ZoneManager> .instance; for (int index1 = num6; index1 <= num8; ++index1) { for (int index2 = num5; index2 <= num7; ++index2) { ushort blockIndex = instance.m_zoneGrid[index1 * FakeZoneManager.GRIDSIZE + index2]; int num9 = 0; while ((int)blockIndex != 0) { Vector3 vector3 = instance.m_blocks.m_buffer[(int)blockIndex].m_position; if ((double)Mathf.Max(Mathf.Max(num1 - 46f - vector3.x, num2 - 46f - vector3.z), Mathf.Max((float)((double)vector3.x - (double)num3 - 46.0), (float)((double)vector3.z - (double)num4 - 46.0))) < 0.0) { CalculateFillBuffer(z, position, direction, angle, blockIndex, ref instance.m_blocks.m_buffer[(int)blockIndex], requiredZone, occupied1, occupied2); } blockIndex = instance.m_blocks.m_buffer[(int)blockIndex].m_nextGridBlock; if (++num9 >= ZoneManager.MAX_BLOCK_COUNT) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace); break; } } } } } if (((long)m_fillBuffer1[32] & 4294967296L) != 0L) { m_fillPositions.Clear(); int num1 = 0; int num2 = 32; int num3 = 32; int num4 = 32; int num5 = 32; FillPos fillPos1; fillPos1.m_x = (byte)32; fillPos1.m_z = (byte)32; m_fillPositions.Add(fillPos1); m_fillBuffer1[32] &= 18446744069414584319UL; while (num1 < m_fillPositions.m_size) { FillPos fillPos2 = m_fillPositions.m_buffer[num1++]; if ((int)fillPos2.m_z > 0) { FillPos fillPos3 = fillPos2; --fillPos3.m_z; if (((long)m_fillBuffer1[(int)fillPos3.m_z] & 1L << (int)fillPos3.m_x) != 0L) { m_fillPositions.Add(fillPos3); m_fillBuffer1[(int)fillPos3.m_z] &= (ulong)~(1L << (int)fillPos3.m_x); if ((int)fillPos3.m_z < num3) { num3 = (int)fillPos3.m_z; } } } if ((int)fillPos2.m_x > 0) { FillPos fillPos3 = fillPos2; --fillPos3.m_x; if (((long)m_fillBuffer1[(int)fillPos3.m_z] & 1L << (int)fillPos3.m_x) != 0L) { m_fillPositions.Add(fillPos3); m_fillBuffer1[(int)fillPos3.m_z] &= (ulong)~(1L << (int)fillPos3.m_x); if ((int)fillPos3.m_x < num2) { num2 = (int)fillPos3.m_x; } } } if ((int)fillPos2.m_x < 63) { FillPos fillPos3 = fillPos2; ++fillPos3.m_x; if (((long)m_fillBuffer1[(int)fillPos3.m_z] & 1L << (int)fillPos3.m_x) != 0L) { m_fillPositions.Add(fillPos3); m_fillBuffer1[(int)fillPos3.m_z] &= (ulong)~(1L << (int)fillPos3.m_x); if ((int)fillPos3.m_x > num4) { num4 = (int)fillPos3.m_x; } } } if ((int)fillPos2.m_z < 63) { FillPos fillPos3 = fillPos2; ++fillPos3.m_z; if (((long)m_fillBuffer1[(int)fillPos3.m_z] & 1L << (int)fillPos3.m_x) != 0L) { m_fillPositions.Add(fillPos3); m_fillBuffer1[(int)fillPos3.m_z] &= (ulong)~(1L << (int)fillPos3.m_x); if ((int)fillPos3.m_z > num5) { num5 = (int)fillPos3.m_z; } } } } for (int index = 0; index < 64; ++index) { m_fillBuffer1[index] = 0UL; } for (int index = 0; index < m_fillPositions.m_size; ++index) { FillPos fillPos2 = m_fillPositions.m_buffer[index]; m_fillBuffer1[(int)fillPos2.m_z] |= (ulong)(1L << (int)fillPos2.m_x); } return(true); } for (int index = 0; index < 64; ++index) { m_fillBuffer1[index] = 0UL; } return(false); }