Add a slightly working Torus draw operation (Thanks SkinnyGamer), also fix issue #106. (Thanks FabTheZen)

This commit is contained in:
UnknownShadow200 2016-02-21 15:00:26 +11:00
parent 082017c313
commit e1811b8404
6 changed files with 109 additions and 10 deletions

View File

@ -266,6 +266,7 @@ namespace MCGalaxy
all.Add(new CmdTop()); all.Add(new CmdTop());
all.Add(new CmdTopFive()); all.Add(new CmdTopFive());
all.Add(new CmdTopTen()); all.Add(new CmdTopTen());
all.Add(new CmdTorus());
all.Add(new CmdTp()); all.Add(new CmdTp());
all.Add(new CmdTpA()); all.Add(new CmdTpA());
all.Add(new CmdTpAccept()); all.Add(new CmdTpAccept());

View File

@ -55,7 +55,7 @@ namespace MCGalaxy.Commands
if (!Player.ValidName(name)) { if (!Player.ValidName(name)) {
Player.SendMessage(p, "Invalid name!"); return; Player.SendMessage(p, "Invalid name!"); return;
} }
if (LevelInfo.ExistsOffline(message)) { if (LevelInfo.ExistsOffline(name)) {
Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return; Player.SendMessage(p, "Level \"" + name + "\" already exists!"); return;
} }

View File

@ -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.");
}
}
}

View File

@ -21,9 +21,7 @@ namespace MCGalaxy {
public class EllipsoidDrawOp : DrawOp { public class EllipsoidDrawOp : DrawOp {
public override string Name { public override string Name { get { return "Ellipsoid"; } }
get { return "Ellipsoid"; }
}
public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { 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 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 class EllipsoidHollowDrawOp : DrawOp {
public override string Name { public override string Name { get { return "Ellipsoid Hollow"; } }
get { return "Ellipsoid Hollow"; }
}
public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { 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 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 class CylinderDrawOp : DrawOp {
public override string Name { public override string Name { get { return "Cylinder"; } }
get { return "Cylinder"; }
}
public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) { 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; double rx = (x2 - x1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25;

View File

@ -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);
}
}
}
}

View File

@ -133,6 +133,7 @@
<Compile Include="Commands\Building\CmdSpin.cs" /> <Compile Include="Commands\Building\CmdSpin.cs" />
<Compile Include="Commands\Building\CmdSPlace.cs" /> <Compile Include="Commands\Building\CmdSPlace.cs" />
<Compile Include="Commands\Building\CmdStatic.cs" /> <Compile Include="Commands\Building\CmdStatic.cs" />
<Compile Include="Commands\building\CmdTorus.cs" />
<Compile Include="Commands\Building\CmdTree.cs" /> <Compile Include="Commands\Building\CmdTree.cs" />
<Compile Include="Commands\Building\CmdUndo.cs" /> <Compile Include="Commands\Building\CmdUndo.cs" />
<Compile Include="Commands\Building\CmdWrite.cs" /> <Compile Include="Commands\Building\CmdWrite.cs" />
@ -396,6 +397,7 @@
<Compile Include="Drawing\DrawOps\ReplaceDrawOp.cs" /> <Compile Include="Drawing\DrawOps\ReplaceDrawOp.cs" />
<Compile Include="Drawing\DrawOps\SpheroidDrawOp.cs" /> <Compile Include="Drawing\DrawOps\SpheroidDrawOp.cs" />
<Compile Include="Drawing\DrawOps\PyramidDrawOp.cs" /> <Compile Include="Drawing\DrawOps\PyramidDrawOp.cs" />
<Compile Include="Drawing\DrawOps\TorusDrawOp.cs" />
<Compile Include="Games\Countdown\CountdownGame.cs" /> <Compile Include="Games\Countdown\CountdownGame.cs" />
<Compile Include="Games\Countdown\CountdownGame.Game.cs" /> <Compile Include="Games\Countdown\CountdownGame.Game.cs" />
<Compile Include="Games\Countdown\CountdownMapGen.cs" /> <Compile Include="Games\Countdown\CountdownMapGen.cs" />