Merge pull request #73 from UnknownShadow200/Physics3

Even more cleanup of block physics.
This commit is contained in:
Hetal728 2015-11-19 19:18:55 -05:00
commit 65f35cf916
6 changed files with 509 additions and 1111 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,211 @@
/*
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.BlockPhysics {
public static class DoorPhysics {
public static void Do(Level lvl, Check C) {
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
switch (lvl.blocks[C.b]) {
//Change any door blocks nearby into door_air
case Block.door_air:
case Block.door2_air:
case Block.door3_air:
case Block.door4_air:
case Block.door5_air:
case Block.door6_air:
case Block.door7_air:
case Block.door8_air:
case Block.door10_air:
case Block.door12_air:
case Block.door13_air:
case Block.door_iron_air:
case Block.door_gold_air:
case Block.door_cobblestone_air:
case Block.door_red_air:
case Block.door_dirt_air:
case Block.door_grass_air:
case Block.door_blue_air:
case Block.door_book_air:
AnyDoor(lvl, C, x, y, z, 16);
break;
case Block.door11_air:
case Block.door14_air:
AnyDoor(lvl, C, x, y, z, 4, true);
break;
case Block.door9_air:
AnyDoor(lvl, C, x, y, z, 4);
break;
case Block.odoor1_air:
case Block.odoor2_air:
case Block.odoor3_air:
case Block.odoor4_air:
case Block.odoor5_air:
case Block.odoor6_air:
case Block.odoor7_air:
case Block.odoor8_air:
case Block.odoor9_air:
case Block.odoor10_air:
case Block.odoor11_air:
case Block.odoor12_air:
case Block.odoor1:
case Block.odoor2:
case Block.odoor3:
case Block.odoor4:
case Block.odoor5:
case Block.odoor6:
case Block.odoor7:
case Block.odoor8:
case Block.odoor9:
case Block.odoor10:
case Block.odoor11:
case Block.odoor12:
odoorPhysics(lvl, C);
break;
default:
//non special blocks are then ignored, maybe it would be better to avoid getting here and cutting down the list
if (!C.extraInfo.Contains("wait")) C.time = 255;
break;
}
}
public static void odoorPhysics(Level lvl, Check C) {
if (C.time != 0) {
C.time = 0;
return;
}
odoorNeighbour(lvl, C, lvl.IntOffset(C.b, -1, 0, 0));
odoorNeighbour(lvl, C, lvl.IntOffset(C.b, +1, 0, 0));
odoorNeighbour(lvl, C, lvl.IntOffset(C.b, 0, -1, 0));
odoorNeighbour(lvl, C, lvl.IntOffset(C.b, 0, +1, 0));
odoorNeighbour(lvl, C, lvl.IntOffset(C.b, 0, 0, -1));
odoorNeighbour(lvl, C, lvl.IntOffset(C.b, 0, 0, +1));
C.time++;
}
static void odoorNeighbour(Level lvl, Check C, int offset) {
int index = C.b + offset;
byte block = Block.odoor(lvl.GetTile(index));
if (block == lvl.blocks[C.b])
lvl.AddUpdate(index, block, true);
}
static void AnyDoor(Level lvl, Check C, ushort x, ushort y, ushort z, int timer, bool instaUpdate = false) {
if (C.time != 0) {
CheckDoorRevert(lvl, C, timer);
return;
}
PhysDoor(lvl, (ushort)(x + 1), y, z, instaUpdate);
PhysDoor(lvl, (ushort)(x - 1), y, z, instaUpdate);
PhysDoor(lvl, x, y, (ushort)(z + 1), instaUpdate);
PhysDoor(lvl, x, y, (ushort)(z - 1), instaUpdate);
PhysDoor(lvl, x, (ushort)(y - 1), z, instaUpdate);
PhysDoor(lvl, x, (ushort)(y + 1), z, instaUpdate);
if (lvl.blocks[C.b] != Block.door8_air) {
CheckDoorRevert(lvl, C, timer);
return;
}
for (int xx = -1; xx <= 1; xx++)
for (int yy = -1; yy <= 1; yy++)
for (int zz = -1; zz <= 1; zz++)
{
byte b = lvl.GetTile(lvl.IntOffset(C.b, xx, yy, zz));
if (b == Block.rocketstart) {
if (lvl.physics == 5) {
lvl.Blockchange(x, y, z, Block.air);
return;
}
int b1 = lvl.IntOffset(C.b, xx * 3, yy * 3, zz * 3);
int b2 = lvl.IntOffset(C.b, xx * 2, yy * 2, zz * 2);
bool unblocked = lvl.GetTile(b1) == Block.air && lvl.GetTile(b2) == Block.air &&
!lvl.ListUpdate.Exists(u => u.b == b1) &&
!lvl.ListUpdate.Exists(u => u.b == b2);
if (unblocked) {
lvl.AddUpdate(b1, Block.rockethead);
lvl.AddUpdate(b2, Block.fire);
}
} else if (b == Block.firework) {
if (lvl.physics == 5) {
lvl.Blockchange(x, y, z, Block.air);
return;
}
int b1 = lvl.IntOffset(C.b, xx, yy + 1, zz);
int b2 = lvl.IntOffset(C.b, xx, yy + 2, zz);
bool unblocked = lvl.GetTile(b1) == Block.air && lvl.GetTile(b2) == Block.air &&
!lvl.ListUpdate.Exists(u => u.b == b1) &&
!lvl.ListUpdate.Exists(u => u.b == b2);
if (unblocked) {
lvl.AddUpdate(b2, Block.firework);
lvl.AddUpdate(b1, Block.lavastill, false, "dissipate 100");
}
} else if (b == Block.tnt) {
if (lvl.physics == 5) {
lvl.Blockchange(x, y, z, Block.air);
return;
}
lvl.MakeExplosion((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz), 0);
}
}
CheckDoorRevert(lvl, C, timer);
}
static void CheckDoorRevert(Level lvl, Check C, int timer) {
if (C.time < timer) {
C.time++;
} else {
lvl.AddUpdate(C.b, Block.SaveConvert(lvl.blocks[C.b])); //turn back into door
C.time = 255;
}
}
static void PhysDoor(Level lvl, ushort x, ushort y, ushort z, bool instaUpdate) {
int index = lvl.PosToInt(x, y, z);
if (index < 0) return;
byte rawBlock = lvl.blocks[index];
byte airDoor = Block.DoorAirs(rawBlock);
if (airDoor != 0) {
if (!instaUpdate)
lvl.AddUpdate(index, airDoor);
else
lvl.Blockchange(x, y, z, airDoor);
return;
}
if (Block.tDoor(rawBlock))
lvl.AddUpdate(index, Block.air, false, "wait 16 door 1 revert " + rawBlock.ToString());
byte oDoor = Block.odoor(rawBlock);
if (oDoor != Block.Zero)
lvl.AddUpdate(index, oDoor, true);
}
}
}

View File

@ -0,0 +1,151 @@
/*
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.BlockPhysics {
public static class HunterPhysics {
public static void DoKiller(Level lvl, Check C, Random rand, byte target) {
Player closest = AIPhysics.ClosestPlayer(lvl, C);
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
if (closest != null && rand.Next(1, 20) < 19) {
int index = 0, dirsVisited = 0;
switch (rand.Next(1, 10)) {
case 1:
case 2:
case 3:
if ((closest.pos[0] / 32) - x != 0) {
index = lvl.PosToInt((ushort)(x + Math.Sign((closest.pos[0] / 32) - x)), y, z);
if (MoveFish(lvl, C, index, target)) return;
}
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 4;
case 4:
case 5:
case 6:
if ((closest.pos[1] / 32) - y != 0) {
index = lvl.PosToInt(x, (ushort)(y + Math.Sign((closest.pos[1] / 32) - y)), z);
if (MoveFish(lvl, C, index, target)) return;
}
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 7;
case 7:
case 8:
case 9:
if ((closest.pos[2] / 32) - z != 0) {
index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((closest.pos[2] / 32) - z)));
if (MoveFish(lvl, C, index, target)) return;
}
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 1;
}
}
RandomlyMove(lvl, C, rand, x, y, z, target);
}
public static void DoFlee(Level lvl, Check C, Random rand, byte target) {
Player closest = AIPhysics.ClosestPlayer(lvl, C);
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
if (closest != null && rand.Next(1, 20) < 19) {
int index = 0, dirsVisited = 0;
switch (rand.Next(1, 10)) {
case 1:
case 2:
case 3:
if ((closest.pos[0] / 32) - x != 0) {
index = lvl.PosToInt((ushort)(x - Math.Sign((closest.pos[0] / 32) - x)), y, z);
if (MoveFish(lvl, C, index, target)) return;
}
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 4;
case 4:
case 5:
case 6:
if ((closest.pos[1] / 32) - y != 0) {
index = lvl.PosToInt(x, (ushort)(y - Math.Sign((closest.pos[1] / 32) - y)), z);
if (MoveFish(lvl, C, index, target)) return;
}
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 7;
case 7:
case 8:
case 9:
if ((closest.pos[2] / 32) - z != 0) {
index = lvl.PosToInt(x, y, (ushort)(z - Math.Sign((closest.pos[2] / 32) - z)));
if (MoveFish(lvl, C, index, target)) return;
}
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 1;
}
}
RandomlyMove(lvl, C, rand, x, y, z, target);
}
static bool MoveFish(Level lvl, Check C, int index, byte target) {
if (index >= 0 && lvl.blocks[index] == target && lvl.AddUpdate(index, lvl.blocks[C.b])) {
lvl.AddUpdate(C.b, target);
return true;
}
return false;
}
static void RandomlyMove(Level lvl, Check C, Random rand, ushort x, ushort y, ushort z, byte target ) {
switch (rand.Next(1, 15)) {
case 1:
if (MoveFish(lvl, C, lvl.PosToInt(x, (ushort)(y - 1), z), target)) return;
goto case 3;
case 2:
if (MoveFish(lvl, C, lvl.PosToInt(x, (ushort)(y + 1), z), target)) return;
goto case 6;
case 3:
case 4:
case 5:
if (MoveFish(lvl, C, lvl.PosToInt((ushort)(x - 1), y, z), target)) return;
goto case 9;
case 6:
case 7:
case 8:
if (MoveFish(lvl, C, lvl.PosToInt((ushort)(x + 1), y, z), target)) return;
goto case 12;
case 9:
case 10:
case 11:
MoveFish(lvl, C, lvl.PosToInt(x, y, (ushort)(z - 1)), target);
break;
case 12:
case 13:
case 14:
MoveFish(lvl, C, lvl.PosToInt(x, y, (ushort)(z + 1)), target);
break;
}
}
}
}

View File

@ -0,0 +1,105 @@
/*
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;
using System.Collections.Generic;
namespace MCGalaxy.BlockPhysics {
public static class TntPhysics {
static void ShowWarningFuse(Level lvl, ushort x, ushort y, ushort z) {
lvl.Blockchange(x, (ushort)(y + 1), z, lvl.GetTile(x, (ushort)(y + 1), z) == Block.lavastill ? Block.air : Block.lavastill);
lvl.Blockchange(x, (ushort)(y - 1), z, lvl.GetTile(x, (ushort)(y - 1), z) == Block.lavastill ? Block.air : Block.lavastill);
lvl.Blockchange((ushort)(x + 1), y, z, lvl.GetTile((ushort)(x + 1), y, z) == Block.lavastill ? Block.air : Block.lavastill);
lvl.Blockchange((ushort)(x - 1), y, z, lvl.GetTile((ushort)(x - 1), y, z) == Block.lavastill ? Block.air : Block.lavastill);
lvl.Blockchange(x, y, (ushort)(z + 1), lvl.GetTile(x, y, (ushort)(z + 1)) == Block.lavastill ? Block.air : Block.lavastill);
lvl.Blockchange(x, y, (ushort)(z - 1), lvl.GetTile(x, y, (ushort)(z - 1)) == Block.lavastill ? Block.air : Block.lavastill);
}
public static void DoLargeTnt(Level lvl, Check C, Random rand, int power) {
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
if (lvl.physics < 3) {
lvl.Blockchange(x, y, z, Block.air);
} else {
if (C.time < 5 && lvl.physics == 3) {
C.time++;
ShowWarningFuse(lvl, x, y, z);
return;
}
lvl.MakeExplosion(x, y, z, power);
}
}
public static void DoSmallTnt(Level lvl, Check C, Random rand) {
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
if (C.p != null && C.p.PlayingTntWars) {
int power = 2, threshold = 3;
switch (TntWarsGame.GetTntWarsGame(C.p).GameDifficulty) {
case TntWarsGame.TntWarsDifficulty.Easy:
threshold = 7;
break;
case TntWarsGame.TntWarsDifficulty.Normal:
threshold = 5;
break;
case TntWarsGame.TntWarsDifficulty.Extreme:
power = 3;
break;
}
if (C.time < threshold) {
C.time++;
lvl.Blockchange(x, (ushort)(y + 1), z, lvl.GetTile(x, (ushort)(y + 1), z) == Block.lavastill
? Block.air : Block.lavastill);
return;
}
if (C.p.TntWarsKillStreak >= TntWarsGame.Properties.DefaultStreakTwoAmount
&& TntWarsGame.GetTntWarsGame(C.p).Streaks) {
power++;
}
lvl.MakeExplosion(x, y, z, power - 2, true, TntWarsGame.GetTntWarsGame(C.p));
List<Player> Killed = new List<Player>();
Player.players.ForEach(
delegate(Player p1)
{
if (p1.level == lvl && p1.PlayingTntWars && p1 != C.p
&& Math.Abs((int)(p1.pos[0] / 32) - x) + Math.Abs((int)(p1.pos[1] / 32) - y) + Math.Abs((int)(p1.pos[2] / 32) - z) < ((power * 3) + 1)) {
Killed.Add(p1);
}
});
TntWarsGame.GetTntWarsGame(C.p).HandleKill(C.p, Killed);
} else {
if (lvl.physics < 3) {
lvl.Blockchange(x, y, z, Block.air);
} else {
if (C.time < 5 && lvl.physics == 3) {
C.time++;
lvl.Blockchange(x, (ushort)(y + 1), z, lvl.GetTile(x, (ushort)(y + 1), z) == Block.lavastill
? Block.air : Block.lavastill);
return;
}
lvl.MakeExplosion(x, y, z, 0);
}
}
}
}
}

View File

@ -32,28 +32,28 @@ namespace MCGalaxy.BlockPhysics {
lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.air);
return;
}
bool skip = false;
bool checkTime = true;
int index = 0;
Player foundPlayer = AIPhysics.ClosestPlayer(lvl, C);
Player closest = AIPhysics.ClosestPlayer(lvl, C);
if (foundPlayer != null && rand.Next(1, 20) < 18) {
if (closest != null && rand.Next(1, 20) < 18) {
if (rand.Next(1, 7) <= 3) {
index = lvl.PosToInt((ushort)(x + Math.Sign((foundPlayer.pos[0] / 32) - x)), y, z);
if (index != C.b && MoveZombie(lvl, C, index, ref skip)) return;
index = lvl.PosToInt((ushort)(x + Math.Sign((closest.pos[0] / 32) - x)), y, z);
if (index != C.b && MoveZombie(lvl, C, index)) return;
index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((foundPlayer.pos[2] / 32) - z)));
if (index != C.b && MoveZombie(lvl, C, index, ref skip)) return;
index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((closest.pos[2] / 32) - z)));
if (index != C.b && MoveZombie(lvl, C, index)) return;
} else {
index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((foundPlayer.pos[2] / 32) - z)));
if (index != C.b && MoveZombie(lvl, C, index, ref skip)) return;
index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((closest.pos[2] / 32) - z)));
if (index != C.b && MoveZombie(lvl, C, index)) return;
index = lvl.PosToInt((ushort)(x + Math.Sign((foundPlayer.pos[0] / 32) - x)), y, z);
if (index != C.b && MoveZombie(lvl, C, index, ref skip)) return;
index = lvl.PosToInt((ushort)(x + Math.Sign((closest.pos[0] / 32) - x)), y, z);
if (index != C.b && MoveZombie(lvl, C, index)) return;
}
skip = true;
checkTime = false;
}
if (!skip && C.time < 3) {
if (checkTime && C.time < 3) {
C.time++;
return;
}
@ -64,57 +64,47 @@ namespace MCGalaxy.BlockPhysics {
case 1:
case 2:
case 3:
skip = false;
index = lvl.IntOffset(C.b, -1, 0, 0);
if (MoveZombie(lvl, C, index, ref skip)) return;
if (MoveZombie(lvl, C, index)) return;
dirsVisited++;
if (dirsVisited >= 4) return;
else goto case 4;
break;
goto case 4;
case 4:
case 5:
case 6:
skip = false;
index = lvl.IntOffset(C.b, 1, 0, 0);
if (MoveZombie(lvl, C, index, ref skip)) return;
if (MoveZombie(lvl, C, index)) return;
dirsVisited++;
if (dirsVisited >= 4) return;
else goto case 7;
break;
goto case 7;
case 7:
case 8:
case 9:
skip = false;
index = lvl.IntOffset(C.b, 0, 0, 1);
if (MoveZombie(lvl, C, index, ref skip)) return;
if (MoveZombie(lvl, C, index)) return;
dirsVisited++;
if (dirsVisited >= 4) return;
else goto case 10;
break;
goto case 10;
case 10:
case 11:
case 12:
skip = false;
index = lvl.IntOffset(C.b, 0, 0, -1);
if (MoveZombie(lvl, C, index, ref skip)) return;
if (MoveZombie(lvl, C, index)) return;
dirsVisited++;
if (dirsVisited >= 4) return;
else goto case 1;
break;
goto case 1;
}
lvl.AddUpdate(C.b, Block.air);
lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.air);
}
static bool MoveZombie(Level lvl, Check C, int index, ref bool skip) {
skip = false;
static bool MoveZombie(Level lvl, Check C, int index) {
if(
lvl.GetTile(lvl.IntOffset(index, 0, -1, 0)) == Block.air &&
lvl.GetTile(index) == Block.air) {
@ -127,10 +117,10 @@ namespace MCGalaxy.BlockPhysics {
lvl.GetTile(lvl.IntOffset(index, 0, 1, 0)) == Block.air) {
index = lvl.IntOffset(index, 0, 1, 0);
} else {
skip = true;
return false;
}
if (!skip && lvl.AddUpdate(index, lvl.blocks[C.b])) {
if (lvl.AddUpdate(index, lvl.blocks[C.b])) {
lvl.AddUpdate(lvl.IntOffset(index, 0, 1, 0), Block.zombiehead);
lvl.AddUpdate(C.b, Block.air);
lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.air);

View File

@ -431,10 +431,13 @@
<Compile Include="Levels\IO\LvlProperties.cs" />
<Compile Include="Levels\Physics\AIPhysics.cs" />
<Compile Include="Levels\Physics\BirdPhysics.cs" />
<Compile Include="Levels\Physics\DoorPhysics.cs" />
<Compile Include="Levels\Physics\FinitePhysics.cs" />
<Compile Include="Levels\Physics\FirePhysics.cs" />
<Compile Include="Levels\Physics\HunterPhysics.cs" />
<Compile Include="Levels\Physics\RocketPhysics.cs" />
<Compile Include="Levels\Physics\TrainPhysics.cs" />
<Compile Include="Levels\Physics\TntPhysics.cs" />
<Compile Include="Levels\Physics\ZombiePhysics.cs" />
<Compile Include="Player\Alias.cs" />
<Compile Include="API\API.cs" />