From 2ee1158f4305468f7de7c6490986a9018e9a8d7a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 4 Apr 2016 18:36:14 +1000 Subject: [PATCH] And so it begins.. begin modularising out physics. --- Blocks/Behaviour/Block.Behaviour.cs | 36 ++++++++++++++++++++++++++- Levels/Level.Physics.cs | 38 ++--------------------------- Levels/Physics/DoorPhysics.cs | 4 ++- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Blocks/Behaviour/Block.Behaviour.cs b/Blocks/Behaviour/Block.Behaviour.cs index 38a431c38..ca60e58b8 100644 --- a/Blocks/Behaviour/Block.Behaviour.cs +++ b/Blocks/Behaviour/Block.Behaviour.cs @@ -1,5 +1,5 @@ /* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + 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 @@ -17,6 +17,7 @@ */ using System; using MCGalaxy.BlockBehaviour; +using MCGalaxy.BlockPhysics; namespace MCGalaxy { @@ -37,6 +38,11 @@ namespace MCGalaxy { public delegate bool HandleWalkthrough(Player p, byte block, ushort x, ushort y, ushort z); internal static HandleWalkthrough[] walkthroughHandlers = new Block.HandleWalkthrough[256]; + /// Called to handle the physics for this particular block. + /// If this returns true, the usual 'death check' behaviour is skipped. + public delegate void HandlePhysics(Level lvl, Check C); + internal static HandlePhysics[] physicsHandlers = new Block.HandlePhysics[256]; + static void SetupCoreHandlers() { deleteHandlers[Block.rocketstart] = DeleteBehaviour.RocketStart; deleteHandlers[Block.firework] = DeleteBehaviour.Firework; @@ -64,6 +70,34 @@ namespace MCGalaxy { deleteHandlers[i] = DeleteBehaviour.Door; } } + SetupCorePhysicsHandlers(); + } + + static void SetupCorePhysicsHandlers() { + physicsHandlers[Block.birdblack] = BirdPhysics.Do; + physicsHandlers[Block.birdwhite] = BirdPhysics.Do; + physicsHandlers[Block.birdlava] = BirdPhysics.Do; + physicsHandlers[Block.birdwater] = BirdPhysics.Do; + physicsHandlers[Block.birdred] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.air); + physicsHandlers[Block.birdblue] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.air); + physicsHandlers[Block.birdkill] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.air); + + physicsHandlers[Block.snaketail] = SnakePhysics.DoTail; + physicsHandlers[Block.snake] = SnakePhysics.Do; + physicsHandlers[Block.rockethead] = RocketPhysics.Do; + physicsHandlers[Block.firework] = FireworkPhysics.Do; + physicsHandlers[Block.zombiebody] = ZombiePhysics.Do; + physicsHandlers[Block.zombiehead] = ZombiePhysics.DoHead; + physicsHandlers[Block.creeper] = ZombiePhysics.Do; + physicsHandlers[Block.c4] = C4Physics.DoC4; + physicsHandlers[Block.c4det] = C4Physics.DoC4Det; + + physicsHandlers[Block.fishbetta] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.water); + physicsHandlers[Block.fishshark] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.water); + physicsHandlers[Block.fishlavashark] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.lava); + physicsHandlers[Block.fishgold] = (lvl, C) => HunterPhysics.DoFlee(lvl, C, Block.water); + physicsHandlers[Block.fishsalmon] = (lvl, C) => HunterPhysics.DoFlee(lvl, C, Block.water); + physicsHandlers[Block.fishsponge] = (lvl, C) => HunterPhysics.DoFlee(lvl, C, Block.water); } } } diff --git a/Levels/Level.Physics.cs b/Levels/Level.Physics.cs index 24fd02660..4ffd698c2 100644 --- a/Levels/Level.Physics.cs +++ b/Levels/Level.Physics.cs @@ -137,7 +137,7 @@ namespace MCGalaxy { if (PhysicsUpdate != null) PhysicsUpdate(x, y, z, C.time, info, this); if (info == "" || ExtraInfoPhysics.DoDoorsOnly(this, C, null)) - DoorPhysics.Do(this, C); + DoorPhysics.Do(this, C, true); } catch { listCheckExists.Set(x, y, z, false); ListCheck.Remove(C); @@ -284,42 +284,8 @@ namespace MCGalaxy { ExtLiquidPhysics.DoMagma(this, C); break; case Block.geyser: ExtLiquidPhysics.DoGeyser(this, C); break; - case Block.birdblack: - case Block.birdwhite: - case Block.birdlava: - case Block.birdwater: - BirdPhysics.Do(this, C); break; - case Block.snaketail: - SnakePhysics.DoTail(this, C); break; - case Block.snake: - SnakePhysics.Do(this, C); break; - case Block.birdred: - case Block.birdblue: - case Block.birdkill: - HunterPhysics.DoKiller(this, C, Block.air); break; - case Block.fishbetta: - case Block.fishshark: - HunterPhysics.DoKiller(this, C, Block.water); break; - case Block.fishgold: - case Block.fishsalmon: - case Block.fishsponge: - HunterPhysics.DoFlee(this, C, Block.water); break; - case Block.fishlavashark: - HunterPhysics.DoKiller(this, C, Block.lava); break; - case Block.rockethead: - RocketPhysics.Do(this, C); break; - case Block.firework: - FireworkPhysics.Do(this, C); break; - case Block.zombiehead: - ZombiePhysics.DoHead(this, C); break; - case Block.creeper: - ZombiePhysics.Do(this, C); break; - case Block.c4: - C4Physics.DoC4(this, C); break; - case Block.c4det: - C4Physics.DoC4Det(this, C); break; default: - DoorPhysics.Do(this, C); break; + DoorPhysics.Do(this, C, false); break; } } diff --git a/Levels/Physics/DoorPhysics.cs b/Levels/Physics/DoorPhysics.cs index b3d3a3b1d..0b587f629 100644 --- a/Levels/Physics/DoorPhysics.cs +++ b/Levels/Physics/DoorPhysics.cs @@ -21,7 +21,7 @@ namespace MCGalaxy.BlockPhysics { public static class DoorPhysics { - public static void Do(Level lvl, Check C) { + public static void Do(Level lvl, Check C, bool doorsOnly) { switch (lvl.blocks[C.b]) { //Change any door blocks nearby into door_air @@ -84,6 +84,8 @@ namespace MCGalaxy.BlockPhysics { odoorPhysics(lvl, C); break; default: + Block.HandlePhysics handler = Block.physicsHandlers[lvl.blocks[C.b]]; + if (!doorsOnly && handler != null) { handler(lvl, C); return; } //non special blocks are then ignored, maybe it would be better to avoid getting here and cutting down the list if (!(C.data is string) || !((string)C.data).Contains("wait")) C.time = 255;