Modularise out MakeExplosion and reduce code duplication in MakeExplosion.

This commit is contained in:
UnknownShadow200 2016-01-23 16:57:36 +11:00
parent b8f98cb74d
commit c1d8e3d7db
2 changed files with 45 additions and 111 deletions

View File

@ -1722,116 +1722,8 @@ namespace MCGalaxy
//================================================================================================================
public void MakeExplosion(ushort x, ushort y, ushort z, int size, bool force = false, TntWarsGame CheckForExplosionZone = null)
{
//DateTime start = DateTime.Now;
int xx, yy, zz;
var rand = new Random();
byte b;
if (physics < 2 && force == false) return;
if (physics == 5 && force == false) return;
AddUpdate(PosToInt(x, y, z), Block.tntexplosion, true);
for (xx = (x - (size + 1)); xx <= (x + (size + 1)); ++xx)
for (yy = (y - (size + 1)); yy <= (y + (size + 1)); ++yy)
for (zz = (z - (size + 1)); zz <= (z + (size + 1)); ++zz)
try
{
b = GetTile((ushort)xx, (ushort)yy, (ushort)zz);
if (b == Block.tnt)
{
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.smalltnt);
}
else if (b != Block.smalltnt && b != Block.bigtnt && b != Block.nuketnt)
{
if (CheckForExplosionZone != null && b != Block.air)
{
if (CheckForExplosionZone.InZone((ushort)xx, (ushort)yy, (ushort)zz, false))
{
continue;
}
}
if (rand.Next(1, 11) <= 4)
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.tntexplosion);
else if (rand.Next(1, 11) <= 8)
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.air);
else
AddCheck(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), "drop 50 dissipate 8");
}
else
{
AddCheck(PosToInt((ushort)xx, (ushort)yy, (ushort)zz));
}
}
catch
{
}
for (xx = (x - (size + 2)); xx <= (x + (size + 2)); ++xx)
for (yy = (y - (size + 2)); yy <= (y + (size + 2)); ++yy)
for (zz = (z - (size + 2)); zz <= (z + (size + 2)); ++zz)
{
b = GetTile((ushort)xx, (ushort)yy, (ushort)zz);
if (rand.Next(1, 10) < 7)
if (Block.Convert(b) != Block.tnt)
{
if (CheckForExplosionZone != null && b != Block.air)
{
if (CheckForExplosionZone.InZone((ushort)xx, (ushort)yy, (ushort)zz, false))
{
continue;
}
}
if (rand.Next(1, 11) <= 4)
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.tntexplosion);
else if (rand.Next(1, 11) <= 8)
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.air);
else
AddCheck(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), "drop 50 dissipate 8");
}
if (b == Block.tnt)
{
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.smalltnt);
}
else if (b == Block.smalltnt || b == Block.bigtnt || b == Block.nuketnt)
{
AddCheck(PosToInt((ushort)xx, (ushort)yy, (ushort)zz));
}
}
for (xx = (x - (size + 3)); xx <= (x + (size + 3)); ++xx)
for (yy = (y - (size + 3)); yy <= (y + (size + 3)); ++yy)
for (zz = (z - (size + 3)); zz <= (z + (size + 3)); ++zz)
{
b = GetTile((ushort)xx, (ushort)yy, (ushort)zz);
if (rand.Next(1, 10) < 3)
if (Block.Convert(b) != Block.tnt)
{
if (CheckForExplosionZone != null && b != Block.air)
{
if (CheckForExplosionZone.InZone((ushort)xx, (ushort)yy, (ushort)zz, false))
{
continue;
}
}
if (rand.Next(1, 11) <= 4)
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.tntexplosion);
else if (rand.Next(1, 11) <= 8)
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.air);
else
AddCheck(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), "drop 50 dissipate 8");
}
if (b == Block.tnt)
{
AddUpdate(PosToInt((ushort)xx, (ushort)yy, (ushort)zz), Block.smalltnt);
}
else if (b == Block.smalltnt || b == Block.bigtnt || b == Block.nuketnt)
{
AddCheck(PosToInt((ushort)xx, (ushort)yy, (ushort)zz));
}
}
//Server.s.Log("Explosion: " + (DateTime.Now - start).TotalMilliseconds.ToString());
public void MakeExplosion(ushort x, ushort y, ushort z, int size, bool force = false, TntWarsGame CheckForExplosionZone = null) {
TntPhysics.MakeExplosion(this, x, y, z, size, force, CheckForExplosionZone);
}
#endregion

View File

@ -72,7 +72,7 @@ namespace MCGalaxy.BlockPhysics {
? Block.air : Block.lavastill);
return;
}
if (C.p.TntWarsKillStreak >= TntWarsGame.Properties.DefaultStreakTwoAmount
if (C.p.TntWarsKillStreak >= TntWarsGame.Properties.DefaultStreakTwoAmount
&& TntWarsGame.GetTntWarsGame(C.p).Streaks) {
power++;
}
@ -102,5 +102,47 @@ namespace MCGalaxy.BlockPhysics {
}
}
}
public static void MakeExplosion(Level lvl, ushort x, ushort y, ushort z, int size,
bool force = false, TntWarsGame game = null) {
Random rand = new Random();
if ((lvl.physics < 2 || lvl.physics == 5) && !force) return;
lvl.AddUpdate(lvl.PosToInt(x, y, z), Block.tntexplosion, true);
Explode(lvl, x, y, z, size + 1, rand, -1, game);
Explode(lvl, x, y, z, size + 2, rand, 7, game);
Explode(lvl, x, y, z, size + 3, rand, 3, game);
}
static void Explode(Level lvl, ushort x, ushort y, ushort z,
int size, Random rand, int prob, TntWarsGame game) {
for (int xx = (x - size); xx <= (x + size ); ++xx)
for (int yy = (y - size ); yy <= (y + size); ++yy)
for (int zz = (z - size); zz <= (z + size); ++zz)
{
int index = lvl.PosToInt((ushort)xx, (ushort)yy, (ushort)zz);
if (index < 0) continue;
byte b = lvl.blocks[index];
bool doDestroy = prob < 0 || rand.Next(1, 10) < prob;
if (doDestroy && Block.Convert(b) != Block.tnt) {
if (game != null && b != Block.air) {
if (game.InZone((ushort)xx, (ushort)yy, (ushort)zz, false))
continue;
}
if (rand.Next(1, 11) <= 4)
lvl.AddUpdate(index, Block.tntexplosion);
else if (rand.Next(1, 11) <= 8)
lvl.AddUpdate(index, Block.air);
else
lvl.AddCheck(index, "drop 50 dissipate 8");
} else if (b == Block.tnt) {
lvl.AddUpdate(index, Block.smalltnt);
} else if (b == Block.smalltnt || b == Block.bigtnt || b == Block.nuketnt) {
lvl.AddCheck(index);
}
}
}
}
}