From 5d7c2fc1ed0f86aac59ee7baadf0b9b6c3caa06c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 23 Jan 2016 12:03:56 +1100 Subject: [PATCH] H:/PortableApps/GitPortable/App/Git/line uses DrawOp now, also remove duplication of line making code in CmdMissile. --- Commands/{other => Chat}/CmdEmote.cs | 2 +- Commands/{other => Chat}/CmdHigh5.cs | 31 ++---- Commands/{other => Chat}/CmdHug.cs | 22 ++-- Commands/{Games => Fun}/CmdCountdown.cs | 0 Commands/{Games => Fun}/CmdCtf.cs | 0 Commands/{Games => Fun}/CmdDisinfect.cs | 0 Commands/{other => Fun}/CmdFlipHeads.cs | 0 Commands/{other => Fun}/CmdFliphead.cs | 0 Commands/{Games => Fun}/CmdInfect.cs | 0 Commands/{Games => Fun}/CmdInfected.cs | 0 Commands/{Games => Fun}/CmdLavaSurvival.cs | 0 Commands/{Games => Fun}/CmdTntWars.cs | 0 Commands/{Games => Fun}/CmdZombieGame.cs | 0 Commands/{Games => Fun}/CmdZombieSpawn.cs | 0 Commands/{Games => Fun}/CmdZombieSurvival.cs | 0 Commands/building/CmdCuboid.cs | 5 +- Commands/building/CmdLine.cs | 89 +++------------ Commands/building/CmdPyramid.cs | 5 +- Commands/building/CmdReplace.cs | 5 +- Commands/building/CmdReplaceNot.cs | 5 +- Commands/building/CmdSpheroid.cs | 7 +- Commands/other/CmdMissile.cs | 107 +++--------------- Drawing/DrawOps/DrawOp.cs | 9 ++ Drawing/DrawOps/LineDrawOp.cs | 109 +++++++++++++++++++ Levels/Level.cs | 35 ++---- MCGalaxy_.csproj | 33 +++--- 26 files changed, 201 insertions(+), 263 deletions(-) rename Commands/{other => Chat}/CmdEmote.cs (96%) rename Commands/{other => Chat}/CmdHigh5.cs (62%) rename Commands/{other => Chat}/CmdHug.cs (68%) rename Commands/{Games => Fun}/CmdCountdown.cs (100%) rename Commands/{Games => Fun}/CmdCtf.cs (100%) rename Commands/{Games => Fun}/CmdDisinfect.cs (100%) rename Commands/{other => Fun}/CmdFlipHeads.cs (100%) rename Commands/{other => Fun}/CmdFliphead.cs (100%) rename Commands/{Games => Fun}/CmdInfect.cs (100%) rename Commands/{Games => Fun}/CmdInfected.cs (100%) rename Commands/{Games => Fun}/CmdLavaSurvival.cs (100%) rename Commands/{Games => Fun}/CmdTntWars.cs (100%) rename Commands/{Games => Fun}/CmdZombieGame.cs (100%) rename Commands/{Games => Fun}/CmdZombieSpawn.cs (100%) rename Commands/{Games => Fun}/CmdZombieSurvival.cs (100%) create mode 100644 Drawing/DrawOps/LineDrawOp.cs diff --git a/Commands/other/CmdEmote.cs b/Commands/Chat/CmdEmote.cs similarity index 96% rename from Commands/other/CmdEmote.cs rename to Commands/Chat/CmdEmote.cs index 9bebc8b33..c0c8618ed 100644 --- a/Commands/other/CmdEmote.cs +++ b/Commands/Chat/CmdEmote.cs @@ -21,7 +21,7 @@ namespace MCGalaxy.Commands { public override string name { get { return "emote"; } } public override string shortcut { get { return "<3"; } } - public override string type { get { return CommandTypes.Other; } } + public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } public CmdEmote() { } diff --git a/Commands/other/CmdHigh5.cs b/Commands/Chat/CmdHigh5.cs similarity index 62% rename from Commands/other/CmdHigh5.cs rename to Commands/Chat/CmdHigh5.cs index b93e15ecf..26af93d8d 100644 --- a/Commands/other/CmdHigh5.cs +++ b/Commands/Chat/CmdHigh5.cs @@ -23,33 +23,24 @@ namespace MCGalaxy.Commands { public override string name { get { return "high5"; } } public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Other; } } + public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public CmdHigh5() { } - public override void Use(Player p, string message) - { - if (message == "") - { - Help(p); - return; - } - Player player1 = Player.Find(message); - if (player1 == null || player1.hidden) - { - Player.SendMessage(p, "Could not find player specified."); - return; + + public override void Use(Player p, string message) { + if (message == "") { Help(p); return; } + Player who = Player.Find(message); + if (who == null || who.hidden) { + Player.SendMessage(p, "Could not find player specified."); return; } - string giver = (p == null) ? "The Console" : p.DisplayName; - string color = (p == null) ? "" : p.color; - Player.SendMessage(player1, giver + " just highfived you"); - Player.GlobalMessage(color + giver + " " + Server.DefaultColor + "just highfived " + player1.color + player1.DisplayName); + string giver = (p == null) ? "(console)" : p.color + p.DisplayName; + Player.SendMessage(who, giver + " just highfived you"); + Player.GlobalMessage(giver + " %Sjust highfived " + who.color + who.DisplayName); } - // This one controls what happens when you use /help [commandname]. - public override void Help(Player p) - { + public override void Help(Player p) { Player.SendMessage(p, "/high5 - High five someone :D"); } } diff --git a/Commands/other/CmdHug.cs b/Commands/Chat/CmdHug.cs similarity index 68% rename from Commands/other/CmdHug.cs rename to Commands/Chat/CmdHug.cs index ef35a1e58..13b8ef8b6 100644 --- a/Commands/other/CmdHug.cs +++ b/Commands/Chat/CmdHug.cs @@ -23,22 +23,22 @@ namespace MCGalaxy { public override string name { get { return "hug"; } } public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Other; } } + public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override void Use(Player p, string message) - { + + public override void Use(Player p, string message) { + if (message == "") { Help(p); return; } Player who = Player.Find(message); - if (who == null || who.hidden) { Player.SendMessage(p, "Could not find specified player!"); return; } - else - { - string msg = String.Format("the {0}Console [&a{1}{0}]", Server.DefaultColor, Server.ZallState); - string giver = (p == null) ? msg : p.color + p.DisplayName; - Player.GlobalMessage(who.color + who.DisplayName + Server.DefaultColor + " was hugged by " + giver); + if (who == null || who.hidden) { + Player.SendMessage(p, "Could not find player specified."); return; } + + string giver = (p == null) ? "(console)" : p.color + p.DisplayName; + Player.GlobalMessage(who.color + who.DisplayName + " %Swas hugged by " + giver); } - public override void Help(Player p) - { + + public override void Help(Player p) { Player.SendMessage(p, "/hug - hugs the given player"); } } diff --git a/Commands/Games/CmdCountdown.cs b/Commands/Fun/CmdCountdown.cs similarity index 100% rename from Commands/Games/CmdCountdown.cs rename to Commands/Fun/CmdCountdown.cs diff --git a/Commands/Games/CmdCtf.cs b/Commands/Fun/CmdCtf.cs similarity index 100% rename from Commands/Games/CmdCtf.cs rename to Commands/Fun/CmdCtf.cs diff --git a/Commands/Games/CmdDisinfect.cs b/Commands/Fun/CmdDisinfect.cs similarity index 100% rename from Commands/Games/CmdDisinfect.cs rename to Commands/Fun/CmdDisinfect.cs diff --git a/Commands/other/CmdFlipHeads.cs b/Commands/Fun/CmdFlipHeads.cs similarity index 100% rename from Commands/other/CmdFlipHeads.cs rename to Commands/Fun/CmdFlipHeads.cs diff --git a/Commands/other/CmdFliphead.cs b/Commands/Fun/CmdFliphead.cs similarity index 100% rename from Commands/other/CmdFliphead.cs rename to Commands/Fun/CmdFliphead.cs diff --git a/Commands/Games/CmdInfect.cs b/Commands/Fun/CmdInfect.cs similarity index 100% rename from Commands/Games/CmdInfect.cs rename to Commands/Fun/CmdInfect.cs diff --git a/Commands/Games/CmdInfected.cs b/Commands/Fun/CmdInfected.cs similarity index 100% rename from Commands/Games/CmdInfected.cs rename to Commands/Fun/CmdInfected.cs diff --git a/Commands/Games/CmdLavaSurvival.cs b/Commands/Fun/CmdLavaSurvival.cs similarity index 100% rename from Commands/Games/CmdLavaSurvival.cs rename to Commands/Fun/CmdLavaSurvival.cs diff --git a/Commands/Games/CmdTntWars.cs b/Commands/Fun/CmdTntWars.cs similarity index 100% rename from Commands/Games/CmdTntWars.cs rename to Commands/Fun/CmdTntWars.cs diff --git a/Commands/Games/CmdZombieGame.cs b/Commands/Fun/CmdZombieGame.cs similarity index 100% rename from Commands/Games/CmdZombieGame.cs rename to Commands/Fun/CmdZombieGame.cs diff --git a/Commands/Games/CmdZombieSpawn.cs b/Commands/Fun/CmdZombieSpawn.cs similarity index 100% rename from Commands/Games/CmdZombieSpawn.cs rename to Commands/Fun/CmdZombieSpawn.cs diff --git a/Commands/Games/CmdZombieSurvival.cs b/Commands/Fun/CmdZombieSurvival.cs similarity index 100% rename from Commands/Games/CmdZombieSurvival.cs rename to Commands/Fun/CmdZombieSurvival.cs diff --git a/Commands/building/CmdCuboid.cs b/Commands/building/CmdCuboid.cs index 702483ef7..27e57c23e 100644 --- a/Commands/building/CmdCuboid.cs +++ b/Commands/building/CmdCuboid.cs @@ -48,10 +48,7 @@ namespace MCGalaxy.Commands } if (brush == null) brush = new SolidBrush(cpos.type, cpos.extType); - ushort x1 = Math.Min(cpos.x, x), x2 = Math.Max(cpos.x, x); - ushort y1 = Math.Min(cpos.y, y), y2 = Math.Max(cpos.y, y); - ushort z1 = Math.Min(cpos.z, z), z2 = Math.Max(cpos.z, z); - if (!DrawOp.DoDrawOp(drawOp, brush, p, x1, y1, z1, x2, y2, z2)) + if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) return; if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); diff --git a/Commands/building/CmdLine.cs b/Commands/building/CmdLine.cs index 865aba1c6..6f2073111 100644 --- a/Commands/building/CmdLine.cs +++ b/Commands/building/CmdLine.cs @@ -53,94 +53,33 @@ namespace MCGalaxy.Commands { RevertAndClearState(p, x, y, z); CatchPos cpos = (CatchPos)p.blockchangeObject; GetRealBlock(type, extType, p, ref cpos); - List buffer = new List(); - Pos pos = new Pos(); if (cpos.solid == SolidType.straight) { - int xdif = Math.Abs(cpos.x - x); - int ydif = Math.Abs(cpos.y - y); - int zdif = Math.Abs(cpos.z - z); + int dx = Math.Abs(cpos.x - x); + int dy = Math.Abs(cpos.y - y); + int dz = Math.Abs(cpos.z - z); - if (xdif > ydif && xdif > zdif) { + if (dx > dy && dx > dz) { y = cpos.y; z = cpos.z; - } else if (ydif > xdif && ydif > zdif) { + } else if (dy > dx && dy > dz) { x = cpos.x; z = cpos.z; - } else if (zdif > ydif && zdif > xdif) { + } else if (dz > dy && dz > dx) { y = cpos.y; x = cpos.x; } } - - Line lx, ly, lz; - int[] pixel = { cpos.x, cpos.y, cpos.z }; - int dx = x - cpos.x, dy = y - cpos.y, dz = z - cpos.z; - lx.inc = Math.Sign(dx); ly.inc = Math.Sign(dy); lz.inc = Math.Sign(dz); - - int xLen = Math.Abs(dx), yLen = Math.Abs(dy), zLen = Math.Abs(dz); - lx.dx2 = xLen << 1; ly.dx2 = yLen << 1; lz.dx2 = zLen << 1; - lx.index = 0; ly.index = 1; lz.index = 2; - - if (xLen >= yLen && xLen >= zLen) - DoLine(ly, lz, lx, xLen, pixel, buffer); - else if (yLen >= xLen && yLen >= zLen) - DoLine(lx, lz, ly, yLen, pixel, buffer); - else - DoLine(ly, lx, lz, zLen, pixel, buffer); - - pos.x = (ushort)pixel[0]; pos.y = (ushort)pixel[1]; pos.z = (ushort)pixel[2]; - buffer.Add(pos); - int maxLen = cpos.data == null ? int.MaxValue : (ushort)cpos.data; - - int count = Math.Min(buffer.Count, maxLen); - if (cpos.solid == SolidType.walls) - count *= Math.Abs(cpos.y - y); - - if (count > p.group.maxBlocks) { - Player.SendMessage(p, "You tried to draw " + count + " blocks at once."); - Player.SendMessage(p, "You are limited to " + p.group.maxBlocks); + + LineDrawOp drawOp = new LineDrawOp(); + drawOp.WallsMode = cpos.solid == SolidType.walls; + if (cpos.data != null) + drawOp.MaxLength = (ushort)cpos.data; + Brush brush = new SolidBrush(cpos.type, cpos.extType); + + if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) return; - } - - for (int i = 0; i < maxLen && i < buffer.Count; i++) { - pos = buffer[i]; - if (cpos.solid == SolidType.walls) { - for (ushort yy = Math.Min(cpos.y, y); yy <= Math.Max(cpos.y, y); yy++) { - p.level.Blockchange(p, pos.x, yy, pos.z, type, extType); - } - } else { - p.level.Blockchange(p, pos.x, pos.y, pos.z, type, extType); - } - } - - count = Math.Min(maxLen, buffer.Count); - Player.SendMessage(p, "Line was " + count + " blocks long."); if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); } - struct Line { public int dx2, inc, index; } - - struct Pos { public ushort x, y, z; } - - static void DoLine(Line l1, Line l2, Line l3, int len, int[] pixel, List buffer) { - int err_1 = l1.dx2 - len, err_2 = l2.dx2 - len; - Pos pos; - for (int i = 0; i < len; i++) { - pos.x = (ushort)pixel[0]; pos.y = (ushort)pixel[1]; pos.z = (ushort)pixel[2]; - buffer.Add(pos); - - if (err_1 > 0) { - pixel[l1.index] += l1.inc; - err_1 -= l3.dx2; - } - if (err_2 > 0) { - pixel[l2.index] += l2.inc; - err_2 -= l3.dx2; - } - err_1 += l1.dx2; err_2 += l2.dx2; - pixel[l3.index] += l3.inc; - } - } - public override void Help(Player p) { Player.SendMessage(p, "%T/line [block type] "); Player.SendMessage(p, " %HCreates a line between two points."); diff --git a/Commands/building/CmdPyramid.cs b/Commands/building/CmdPyramid.cs index 9582a0f2e..a3487fb85 100644 --- a/Commands/building/CmdPyramid.cs +++ b/Commands/building/CmdPyramid.cs @@ -45,10 +45,7 @@ namespace MCGalaxy.Commands drawOp = new PyramidReverseDrawOp(); break; } - ushort x1 = Math.Min(cpos.x, x), x2 = Math.Max(cpos.x, x); - ushort y1 = Math.Min(cpos.y, y), y2 = Math.Max(cpos.y, y); - ushort z1 = Math.Min(cpos.z, z), z2 = Math.Max(cpos.z, z); - if (!DrawOp.DoDrawOp(drawOp, brush, p, x1, y1, z1, x2, y2, z2)) + if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) return; if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); diff --git a/Commands/building/CmdReplace.cs b/Commands/building/CmdReplace.cs index 9c52e6c84..04d0668e6 100644 --- a/Commands/building/CmdReplace.cs +++ b/Commands/building/CmdReplace.cs @@ -45,14 +45,11 @@ namespace MCGalaxy.Commands { public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); CatchPos cpos = (CatchPos)p.blockchangeObject; - ushort x1 = Math.Min(cpos.x, x), x2 = Math.Max(cpos.x, x); - ushort y1 = Math.Min(cpos.y, y), y2 = Math.Max(cpos.y, y); - ushort z1 = Math.Min(cpos.z, z), z2 = Math.Max(cpos.z, z); ReplaceDrawOp drawOp = new ReplaceDrawOp(); drawOp.ToReplace = toAffect; drawOp.Target = target; - if (!DrawOp.DoDrawOp(drawOp, null, p, x1, y1, z1, x2, y2, z2)) + if (!DrawOp.DoDrawOp(drawOp, null, p, cpos.x, cpos.y, cpos.z, x, y, z)) return; if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); diff --git a/Commands/building/CmdReplaceNot.cs b/Commands/building/CmdReplaceNot.cs index 529822c11..6b4528f0e 100644 --- a/Commands/building/CmdReplaceNot.cs +++ b/Commands/building/CmdReplaceNot.cs @@ -44,14 +44,11 @@ namespace MCGalaxy.Commands { public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); CatchPos cpos = (CatchPos)p.blockchangeObject; - ushort x1 = Math.Min(cpos.x, x), x2 = Math.Max(cpos.x, x); - ushort y1 = Math.Min(cpos.y, y), y2 = Math.Max(cpos.y, y); - ushort z1 = Math.Min(cpos.z, z), z2 = Math.Max(cpos.z, z); ReplaceNotDrawOp drawOp = new ReplaceNotDrawOp(); drawOp.ToReplace = toAffect; drawOp.Target = target; - if (!DrawOp.DoDrawOp(drawOp, null, p, x1, y1, z1, x2, y2, z2)) + if (!DrawOp.DoDrawOp(drawOp, null, p, cpos.x, cpos.y, cpos.z, x, y, z)) return; if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); diff --git a/Commands/building/CmdSpheroid.cs b/Commands/building/CmdSpheroid.cs index 0d37f680a..ca5af0bd5 100644 --- a/Commands/building/CmdSpheroid.cs +++ b/Commands/building/CmdSpheroid.cs @@ -39,11 +39,8 @@ namespace MCGalaxy.Commands { case SolidType.vertical: drawOp = new CylinderDrawOp(); break; } - - ushort x1 = Math.Min(cpos.x, x), x2 = Math.Max(cpos.x, x); - ushort y1 = Math.Min(cpos.y, y), y2 = Math.Max(cpos.y, y); - ushort z1 = Math.Min(cpos.z, z), z2 = Math.Max(cpos.z, z); - if (!DrawOp.DoDrawOp(drawOp, brush, p, x1, y1, z1, x2, y2, z2)) + + if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z)) return; if (p.staticCommands) p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1); diff --git a/Commands/other/CmdMissile.cs b/Commands/other/CmdMissile.cs index 351c2184c..0d6e49025 100644 --- a/Commands/other/CmdMissile.cs +++ b/Commands/other/CmdMissile.cs @@ -184,6 +184,7 @@ namespace MCGalaxy.Commands pos.z = startZ; int total = 0; + List buffer = new List(2); while (true) { @@ -198,7 +199,7 @@ namespace MCGalaxy.Commands CatchPos lookedAt; int i; - for (i = 1; true; i++) + for (i = 1; ; i++) { lookedAt.x = (ushort)Math.Round(startX + (double)(a * i)); lookedAt.y = (ushort)Math.Round(startY + (double)(c * i)); @@ -266,7 +267,7 @@ namespace MCGalaxy.Commands lookedAt.y = (ushort)Math.Round(startY + (double)(c * (i - 1))); lookedAt.z = (ushort)Math.Round(startZ + (double)(b * (i - 1))); - findNext(lookedAt, ref pos); + FindNext(lookedAt, ref pos, buffer); by = p.level.GetTile(pos.x, pos.y, pos.z); if (total > 3) @@ -361,100 +362,22 @@ namespace MCGalaxy.Commands })); gunThread.Name = "MCG_Missile"; gunThread.Start(); - } - public override void Help(Player p) - { - Player.SendMessage(p, "/missile [at end] - Allows you to fire missiles at people"); - Player.SendMessage(p, "Available [at end] values: &cexplode, destroy"); - Player.SendMessage(p, "Differs from /gun in that the missile is guided"); - } + } struct CatchPos { public ushort x, y, z; } struct Pos { public ushort x, y, z; public int ending; } - void findNext(CatchPos lookedAt, ref CatchPos pos) - { - int dx, dy, dz, l, m, n, x_inc, y_inc, z_inc, err_1, err_2, dx2, dy2, dz2; - int[] pixel = new int[3]; - - pixel[0] = pos.x; pixel[1] = pos.y; pixel[2] = pos.z; - dx = lookedAt.x - pos.x; dy = lookedAt.y - pos.y; dz = lookedAt.z - pos.z; - - x_inc = (dx < 0) ? -1 : 1; l = Math.Abs(dx); - y_inc = (dy < 0) ? -1 : 1; m = Math.Abs(dy); - z_inc = (dz < 0) ? -1 : 1; n = Math.Abs(dz); - - dx2 = l << 1; dy2 = m << 1; dz2 = n << 1; - - if ((l >= m) && (l >= n)) - { - err_1 = dy2 - l; - err_2 = dz2 - l; - - pixel[0] += x_inc; - if (err_1 > 0) - { - pixel[1] += y_inc; - err_1 -= dx2; - } - if (err_2 > 0) - { - pixel[2] += z_inc; - err_2 -= dx2; - } - err_1 += dy2; - err_2 += dz2; - - pos.x = (ushort)pixel[0]; - pos.y = (ushort)pixel[1]; - pos.z = (ushort)pixel[2]; - } - else if ((m >= l) && (m >= n)) - { - err_1 = dx2 - m; - err_2 = dz2 - m; - - pixel[1] += y_inc; - if (err_1 > 0) - { - pixel[0] += x_inc; - err_1 -= dy2; - } - if (err_2 > 0) - { - pixel[2] += z_inc; - err_2 -= dy2; - } - err_1 += dx2; - err_2 += dz2; - - pos.x = (ushort)pixel[0]; - pos.y = (ushort)pixel[1]; - pos.z = (ushort)pixel[2]; - } - else - { - err_1 = dy2 - n; - err_2 = dx2 - n; - - pixel[2] += z_inc; - if (err_1 > 0) - { - pixel[1] += y_inc; - err_1 -= dz2; - } - if (err_2 > 0) - { - pixel[0] += x_inc; - err_2 -= dz2; - } - err_1 += dy2; - err_2 += dx2; - - pos.x = (ushort)pixel[0]; - pos.y = (ushort)pixel[1]; - pos.z = (ushort)pixel[2]; - } + void FindNext(CatchPos lookedAt, ref CatchPos pos, List 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(); + } + + public override void Help(Player p) { + Player.SendMessage(p, "/missile [at end] - Allows you to fire missiles at people"); + Player.SendMessage(p, "Available [at end] values: &cexplode, destroy"); + Player.SendMessage(p, "Differs from /gun in that the missile is guided"); } } } diff --git a/Drawing/DrawOps/DrawOp.cs b/Drawing/DrawOps/DrawOp.cs index 2cbfcd8cc..60718e565 100644 --- a/Drawing/DrawOps/DrawOp.cs +++ b/Drawing/DrawOps/DrawOp.cs @@ -27,6 +27,8 @@ namespace MCGalaxy { protected const int reloadLimit = 10000; protected int method; + public virtual bool MinMaxCoords { get { return true; } } + public abstract string Name { get; } public abstract int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2); @@ -91,6 +93,13 @@ namespace MCGalaxy { public static bool DoDrawOp(DrawOp op, Brush brush, Player p, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { int affected = 0; + if (op.MinMaxCoords) { + ushort xx1 = x1, yy1 = y1, zz1 = z1, xx2 = x2, yy2 = y2, zz2 = z2; + x1 = Math.Min(xx1, xx2); x2 = Math.Max(xx1, xx2); + y1 = Math.Min(yy1, yy2); y2 = Math.Max(yy1, yy2); + z1 = Math.Min(zz1, zz2); z2 = Math.Max(zz1, zz2); + } + if (!op.CanDraw(x1, y1, z1, x2, y2, z2, p, out affected)) return false; Player.SendMessage(p, op.Name + ": affecting up to an estimated " + affected + " blocks"); diff --git a/Drawing/DrawOps/LineDrawOp.cs b/Drawing/DrawOps/LineDrawOp.cs new file mode 100644 index 000000000..c91afca22 --- /dev/null +++ b/Drawing/DrawOps/LineDrawOp.cs @@ -0,0 +1,109 @@ +/* + Copyright 2011 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; + +namespace MCGalaxy { + + public class LineDrawOp : DrawOp { + + public bool WallsMode; + public int MaxLength = int.MaxValue; + + public override string Name { get { return "Line"; } } + + public override bool MinMaxCoords { get { return false; } } + + public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { + double dx = Math.Abs(x2 - x1) + 0.25, dy = Math.Abs(y2 - y1) + 0.25, dz = Math.Abs(z2 - z1) + 0.25; + if (WallsMode) { + int baseLen = (int)Math.Ceiling(Math.Sqrt(dx * dx + dz * dz)); + return Math.Min(baseLen, MaxLength) * (Math.Abs(y2 - y1) + 1); + } else { + int baseLen = (int)Math.Ceiling(Math.Sqrt(dx * dx + dy * dy + dz * dz)); + return Math.Min(baseLen, MaxLength); + } + } + + public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2, + ushort y2, ushort z2, Player p, Level lvl, Brush brush) { + List buffer = new List(); + DrawLine(x1, y1, z1, MaxLength, x2, y2, z2, buffer); + if (WallsMode) { + ushort yy1 = y1, yy2 = y2; + y1 = Math.Min(yy1, yy2); y2 = Math.Max(yy1, yy2); + } + + for (int i = 0; i < buffer.Count; i++) { + FillPos pos = buffer[i]; + if (WallsMode) { + for (ushort yy = y1; yy <= y2; yy++) + PlaceBlock(p, lvl, pos.X, yy, pos.Z, brush); + } else { + PlaceBlock(p, lvl, pos.X, pos.Y, pos.Z, brush); + } + } + } + + internal static void DrawLine(ushort x1, ushort y1, ushort z1, int maxLen, + ushort x2, ushort y2, ushort z2, List buffer) { + Line lx, ly, lz; + int[] pixel = { x1, y1, z1 }; + int dx = x2 - x1, dy = y2 - y1, dz = z2 - z1; + lx.inc = Math.Sign(dx); ly.inc = Math.Sign(dy); lz.inc = Math.Sign(dz); + + int xLen = Math.Abs(dx), yLen = Math.Abs(dy), zLen = Math.Abs(dz); + lx.dx2 = xLen << 1; ly.dx2 = yLen << 1; lz.dx2 = zLen << 1; + lx.index = 0; ly.index = 1; lz.index = 2; + + if (xLen >= yLen && xLen >= zLen) + DoLine(ly, lz, lx, xLen, pixel, maxLen, buffer); + else if (yLen >= xLen && yLen >= zLen) + DoLine(lx, lz, ly, yLen, pixel, maxLen, buffer); + else + DoLine(ly, lx, lz, zLen, pixel, maxLen, buffer); + + FillPos pos; + pos.X = (ushort)pixel[0]; pos.Y = (ushort)pixel[1]; pos.Z = (ushort)pixel[2]; + buffer.Add(pos); + } + + struct Line { public int dx2, inc, index; } + + static void DoLine(Line l1, Line l2, Line l3, int len, + int[] pixel, int maxLen, List buffer) { + int err_1 = l1.dx2 - len, err_2 = l2.dx2 - len; + FillPos pos; + for (int i = 0; i < len && i < (maxLen - 1); i++) { + pos.X = (ushort)pixel[0]; pos.Y = (ushort)pixel[1]; pos.Z = (ushort)pixel[2]; + buffer.Add(pos); + + if (err_1 > 0) { + pixel[l1.index] += l1.inc; + err_1 -= l3.dx2; + } + if (err_2 > 0) { + pixel[l2.index] += l2.inc; + err_2 -= l3.dx2; + } + err_1 += l1.dx2; err_2 += l2.dx2; + pixel[l3.index] += l3.inc; + } + } + } +} diff --git a/Levels/Level.cs b/Levels/Level.cs index ad4570ad4..195567533 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -680,35 +680,16 @@ namespace MCGalaxy return true; } - public void ChatLevel(string message) - { - foreach (Player pl in Player.players.Where(pl => pl.level == this)) - { - pl.SendMessage(message); - } - } + public void ChatLevel(string message) { ChatLevel(message, LevelPermission.Banned); } - public void ChatLevelOps(string message) - { - foreach ( - Player pl in - Player.players.Where( - pl => - pl.level == this && - pl.group.Permission >= Server.opchatperm)) - { - pl.SendMessage(message); - } - } + public void ChatLevelOps(string message) { ChatLevel(message, Server.opchatperm); } - public void ChatLevelAdmins(string message) - { - foreach ( - Player pl in - Player.players.Where( - pl => pl.level == this && - pl.group.Permission >= Server.adminchatperm)) - { + public void ChatLevelAdmins(string message) { ChatLevel(message, Server.adminchatperm); } + + public void ChatLevel(string message, LevelPermission minPerm) { + foreach (Player pl in Player.players) { + if (pl.level != this) continue; + if (pl.group.Permission < minPerm) continue; pl.SendMessage(message); } } diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 7fc3aaad0..300264330 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -138,10 +138,13 @@ + + + @@ -167,16 +170,18 @@ - - - - - - - - - - + + + + + + + + + + + + @@ -306,17 +311,12 @@ - - - - - @@ -396,6 +396,7 @@ + @@ -697,7 +698,7 @@ - +