mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Style: Move activate functions out of DoorPhysics to allow them to be used by other block physics.
This commit is contained in:
parent
cdbb58f3a3
commit
3714775621
83
Levels/Physics/ActivateablePhysics.cs
Normal file
83
Levels/Physics/ActivateablePhysics.cs
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/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 ActivateablePhysics {
|
||||
|
||||
/// <summary> Activates fireworks, rockets, and TNT in 1 block radius around (x, y, z) </summary>
|
||||
public static void DoNeighbours(Level lvl, int index, ushort x, ushort y, ushort z) {
|
||||
for (int yy = -1; yy <= 1; yy++)
|
||||
for (int zz = -1; zz <= 1; zz++)
|
||||
for (int xx = -1; xx <= 1; xx++)
|
||||
{
|
||||
byte b = lvl.GetTile(lvl.IntOffset(index, xx, yy, zz));
|
||||
if (b == Block.rocketstart) {
|
||||
int b1 = lvl.IntOffset(index, xx * 3, yy * 3, zz * 3);
|
||||
int b2 = lvl.IntOffset(index, xx * 2, yy * 2, zz * 2);
|
||||
bool unblocked = lvl.GetTile(b1) == Block.air && lvl.GetTile(b2) == Block.air &&
|
||||
!lvl.listUpdateExists.Get(x + xx * 3, y + yy * 3, z + zz * 3) &&
|
||||
!lvl.listUpdateExists.Get(x + xx * 2, y + yy * 2, z + zz * 2);
|
||||
|
||||
if (unblocked) {
|
||||
lvl.AddUpdate(b1, Block.rockethead);
|
||||
lvl.AddUpdate(b2, Block.lava_fire);
|
||||
}
|
||||
} else if (b == Block.firework) {
|
||||
int b1 = lvl.IntOffset(index, xx, yy + 1, zz);
|
||||
int b2 = lvl.IntOffset(index, xx, yy + 2, zz);
|
||||
bool unblocked = lvl.GetTile(b1) == Block.air && lvl.GetTile(b2) == Block.air &&
|
||||
!lvl.listUpdateExists.Get(x + xx, y + yy + 1, z + zz) &&
|
||||
!lvl.listUpdateExists.Get(x + xx, y + yy + 2, z + zz);
|
||||
|
||||
if (unblocked) {
|
||||
lvl.AddUpdate(b2, Block.firework);
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 100;
|
||||
lvl.AddUpdate(b1, Block.lavastill, false, args);
|
||||
}
|
||||
} else if (b == Block.tnt) {
|
||||
lvl.MakeExplosion((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Activates doors, tdoors and toggles odoors at (x, y, z) </summary>
|
||||
public static void DoDoors(Level lvl, ushort x, ushort y, ushort z, bool instant) {
|
||||
int index = lvl.PosToInt(x, y, z);
|
||||
if (index < 0) return;
|
||||
byte b = lvl.blocks[index];
|
||||
|
||||
byte airDoor = Block.DoorAirs(b);
|
||||
if (airDoor != 0) {
|
||||
if (!instant) lvl.AddUpdate(index, airDoor);
|
||||
else lvl.Blockchange(x, y, z, airDoor);
|
||||
} else if (Block.Props[b].IsTDoor) {
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.Type1 = PhysicsArgs.Wait; args.Value1 = 16;
|
||||
args.Type2 = PhysicsArgs.Revert; args.Value2 = b;
|
||||
args.TDoor = true;
|
||||
lvl.AddUpdate(index, Block.air, false, args);
|
||||
} else {
|
||||
byte oDoor = Block.odoor(b);
|
||||
if (oDoor != Block.Zero)
|
||||
lvl.AddUpdate(index, oDoor, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -41,99 +41,34 @@ namespace MCGalaxy.BlockPhysics {
|
||||
lvl.AddUpdate(index, block, true);
|
||||
}
|
||||
|
||||
//Change any door blocks nearby into door_air
|
||||
public static void AnyDoor(Level lvl, ref Check C, int timer, bool instaUpdate = false) {
|
||||
ushort x, y, z;
|
||||
//Change any door blocks nearby into door_air
|
||||
public static void AnyDoor(Level lvl, ref Check C, int timer, bool instant = false) {
|
||||
ushort x, y, z;
|
||||
lvl.IntToPos(C.b, out x, out y, out z);
|
||||
if (C.data.Data != 0) {
|
||||
CheckDoorRevert(lvl, ref 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);
|
||||
ActivateablePhysics.DoDoors(lvl, (ushort)(x + 1), y, z, instant);
|
||||
ActivateablePhysics.DoDoors(lvl, (ushort)(x - 1), y, z, instant);
|
||||
ActivateablePhysics.DoDoors(lvl, x, y, (ushort)(z + 1), instant);
|
||||
ActivateablePhysics.DoDoors(lvl, x, y, (ushort)(z - 1), instant);
|
||||
ActivateablePhysics.DoDoors(lvl, x, (ushort)(y - 1), z, instant);
|
||||
ActivateablePhysics.DoDoors(lvl, x, (ushort)(y + 1), z, instant);
|
||||
|
||||
if (lvl.blocks[C.b] != Block.door_green_air) {
|
||||
CheckDoorRevert(lvl, ref C, timer); return;
|
||||
if (lvl.blocks[C.b] == Block.door_green_air && lvl.physics != 5) {
|
||||
ActivateablePhysics.DoNeighbours(lvl, C.b, x, y, z);
|
||||
}
|
||||
|
||||
if (lvl.physics != 5)
|
||||
ActivateNeighbours(lvl, ref C, x, y, z);
|
||||
CheckDoorRevert(lvl, ref C, timer);
|
||||
}
|
||||
|
||||
static void ActivateNeighbours(Level lvl, ref Check C, ushort x, ushort y, ushort z) {
|
||||
for (int yy = -1; yy <= 1; yy++)
|
||||
for (int zz = -1; zz <= 1; zz++)
|
||||
for (int xx = -1; xx <= 1; xx++)
|
||||
{
|
||||
byte b = lvl.GetTile(lvl.IntOffset(C.b, xx, yy, zz));
|
||||
if (b == Block.rocketstart) {
|
||||
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.listUpdateExists.Get(x + xx * 3, y + yy * 3, z + zz * 3) &&
|
||||
!lvl.listUpdateExists.Get(x + xx * 2, y + yy * 2, z + zz * 2);
|
||||
|
||||
if (unblocked) {
|
||||
lvl.AddUpdate(b1, Block.rockethead);
|
||||
lvl.AddUpdate(b2, Block.lava_fire);
|
||||
}
|
||||
} else if (b == Block.firework) {
|
||||
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.listUpdateExists.Get(x + xx, y + yy + 1, z + zz) &&
|
||||
!lvl.listUpdateExists.Get(x + xx, y + yy + 2, z + zz);
|
||||
|
||||
if (unblocked) {
|
||||
lvl.AddUpdate(b2, Block.firework);
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 100;
|
||||
lvl.AddUpdate(b1, Block.lavastill, false, args);
|
||||
}
|
||||
} else if (b == Block.tnt) {
|
||||
lvl.MakeExplosion((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckDoorRevert(Level lvl, ref Check C, int timer) {
|
||||
if (C.data.Data < timer) {
|
||||
C.data.Data++;
|
||||
} else {
|
||||
lvl.AddUpdate(C.b, Block.Props[lvl.blocks[C.b]].DoorId);
|
||||
lvl.AddUpdate(C.b, Block.Props[lvl.blocks[C.b]].DoorId);
|
||||
C.data.Data = 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.Props[rawBlock].IsTDoor) {
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.Type1 = PhysicsArgs.Wait; args.Value1 = 16;
|
||||
args.Type2 = PhysicsArgs.Revert; args.Value2 = rawBlock;
|
||||
args.TDoor = true;
|
||||
lvl.AddUpdate(index, Block.air, false, args);
|
||||
}
|
||||
byte oDoor = Block.odoor(rawBlock);
|
||||
if (oDoor != Block.Zero)
|
||||
lvl.AddUpdate(index, oDoor, true);
|
||||
}
|
||||
}
|
||||
}
|
@ -519,6 +519,7 @@
|
||||
<Compile Include="Levels\LevelActions.cs" />
|
||||
<Compile Include="Levels\LevelEnv.cs" />
|
||||
<Compile Include="Levels\LevelInfo.cs" />
|
||||
<Compile Include="Levels\Physics\ActivateablePhysics.cs" />
|
||||
<Compile Include="Levels\Physics\AIPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\AirPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\BirdPhysics.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user