diff --git a/Commands/Command.All.cs b/Commands/Command.All.cs index 4fb420e0d..e4425b923 100644 --- a/Commands/Command.All.cs +++ b/Commands/Command.All.cs @@ -266,6 +266,7 @@ namespace MCGalaxy all.Add(new CmdTop()); all.Add(new CmdTopFive()); all.Add(new CmdTopTen()); + all.Add(new CmdTorus()); all.Add(new CmdTp()); all.Add(new CmdTpA()); all.Add(new CmdTpAccept()); diff --git a/Commands/World/CmdNewLvl.cs b/Commands/World/CmdNewLvl.cs index 0833d214b..941866588 100644 --- a/Commands/World/CmdNewLvl.cs +++ b/Commands/World/CmdNewLvl.cs @@ -55,7 +55,7 @@ namespace MCGalaxy.Commands if (!Player.ValidName(name)) { Player.SendMessage(p, "Invalid name!"); return; } - if (LevelInfo.ExistsOffline(message)) { + if (LevelInfo.ExistsOffline(name)) { Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return; } diff --git a/Commands/building/CmdTorus.cs b/Commands/building/CmdTorus.cs new file mode 100644 index 000000000..b5d1f2bb8 --- /dev/null +++ b/Commands/building/CmdTorus.cs @@ -0,0 +1,51 @@ +/* + Copyright 2015 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; + +namespace MCGalaxy.Commands { + + public sealed class CmdTorus : DrawCmd { + + public override string name { get { return "torus"; } } + public override string shortcut { get { return "tor"; } } + + protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { + RevertAndClearState(p, x, y, z); + CatchPos cpos = (CatchPos)p.blockchangeObject; + GetRealBlock(type, extType, p, ref cpos); + DrawOp drawOp = new TorusDrawOp(); + Brush brush = new SolidBrush(cpos.type, cpos.extType); + + 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); + } + + protected override SolidType GetType(string msg) { + return SolidType.solid; + } + + public override void Help(Player p) { + Player.SendMessage(p, "/torus [type] - create a radius of blocks."); + Player.SendMessage(p, "Radius of the tube is calculated based on " + + "vertical difference between the two corners."); + } + } +} + diff --git a/Drawing/DrawOps/SpheroidDrawOp.cs b/Drawing/DrawOps/SpheroidDrawOp.cs index 27b262b8f..226024cf0 100644 --- a/Drawing/DrawOps/SpheroidDrawOp.cs +++ b/Drawing/DrawOps/SpheroidDrawOp.cs @@ -21,9 +21,7 @@ namespace MCGalaxy { public class EllipsoidDrawOp : DrawOp { - public override string Name { - get { return "Ellipsoid"; } - } + public override string Name { get { return "Ellipsoid"; } } public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { double rx = (x2 - x1) / 2.0 + 0.25, ry = (y2 - y1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25; @@ -50,9 +48,7 @@ namespace MCGalaxy { public class EllipsoidHollowDrawOp : DrawOp { - public override string Name { - get { return "Ellipsoid Hollow"; } - } + public override string Name { get { return "Ellipsoid Hollow"; } } public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { double rx = (x2 - x1) / 2.0 + 0.25, ry = (y2 - y1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25; @@ -85,9 +81,7 @@ namespace MCGalaxy { public class CylinderDrawOp : DrawOp { - public override string Name { - get { return "Cylinder"; } - } + public override string Name { get { return "Cylinder"; } } public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { double rx = (x2 - x1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25; diff --git a/Drawing/DrawOps/TorusDrawOp.cs b/Drawing/DrawOps/TorusDrawOp.cs new file mode 100644 index 000000000..75c0d54ff --- /dev/null +++ b/Drawing/DrawOps/TorusDrawOp.cs @@ -0,0 +1,51 @@ +/* + Copyright 2015 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; + +namespace MCGalaxy { + + public class TorusDrawOp : DrawOp { + + public override string Name { get { return "Torus"; } } + + public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { + double rx = (x2 - x1) / 2.0 + 0.25, ry = (y2 - y1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25; + double rTube = ry, rCentre = Math.Min(rx, rz) - rTube; + return (int)(2 * Math.PI * Math.PI * rTube * rTube * rCentre); + } + + public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2, + ushort y2, ushort z2, Player p, Level lvl, Brush brush) { + double cx = (x1 + x2) / 2.0, cy = (y1 + y2) / 2.0, cz = (z1 + z2) / 2.0; + double rx = (x2 - x1) / 2.0 + 0.25, ry = (y2 - y1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25; + double rTube = ry, rCentre = Math.Min(rx, rz) - rTube; + + for (ushort yy = y1; yy <= y2; yy++) + for (ushort zz = z1; zz <= z2; zz++) + for (ushort xx = x1; xx <= x2; xx++) + { + double dx = xx - cx, dy = yy - cy, dz = zz - cz; + dx *= dx; dy *= dy; dz *= dz; + double dInner = rCentre - Math.Sqrt( dx + dz ); + + if (dInner * dInner + dy <= rTube * rTube * 0.5) + PlaceBlock(p, lvl, xx, yy, zz, brush); + } + } + } +} diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 49779d535..8d7862576 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -133,6 +133,7 @@ + @@ -396,6 +397,7 @@ +