Example #1
0
        static void FlyTo(Level lvl, ref Check C, ushort x, ushort y, ushort z, ExtBlock block)
        {
            int index = lvl.PosToInt(x, y, z);

            if (index < 0)
            {
                return;
            }

            switch (lvl.blocks[index])
            {
            case Block.Air:
                lvl.AddUpdate(index, block);
                break;

            case Block.Op_Air:
                break;

            default:
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 25;
                lvl.AddUpdate(C.b, Block.Red, false, args);
                break;
            }
        }
Example #2
0
        static void Firework(ref PhysInfo C, int size, Level lvl, Random rand)
        {
            int rand1 = rand.Next(Block.Red, Block.White);
            int rand2 = rand.Next(Block.Red, Block.White);
            int min = Math.Min(rand1, rand2), max = Math.Max(rand1, rand2);

            // Not using override, since override = true makes it more likely that a colored block will be
            // generated with no extraInfo, because it sets a Check for that position with no extraInfo.
            lvl.AddUpdate(C.Index, Block.Air, default(PhysicsArgs));

            int    index;
            ushort x = C.X, y = C.Y, z = C.Z;

            for (int yy = y - (size + 1); yy <= y + (size + 1); ++yy)
            {
                for (int zz = z - (size + 1); zz <= z + (size + 1); ++zz)
                {
                    for (int xx = x - (size + 1); xx <= x + (size + 1); ++xx)
                    {
                        if (lvl.IsAirAt((ushort)xx, (ushort)yy, (ushort)zz, out index) && rand.Next(1, 40) < 2)
                        {
                            PhysicsArgs args = default(PhysicsArgs);
                            args.Type1 = PhysicsArgs.Drop; args.Value1 = 100;
                            args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 25;
                            lvl.AddUpdate(index, (byte)rand.Next(min, max), args);
                        }
                    }
                }
            }
        }
Example #3
0
        static void ActivateTDoor(Level lvl, int index)
        {
            byte block = lvl.blocks[index];

            if (block != Block.custom_block)
            {
                if (!Block.Props[block].IsTDoor)
                {
                    return;
                }

                PhysicsArgs args = ActivateablePhysics.GetTDoorArgs(block, false);
                lvl.AddUpdate(index, Block.air, false, args);
            }
            else
            {
                block = lvl.GetExtTile(index);
                if (!lvl.CustomBlockProps[block].IsTDoor)
                {
                    return;
                }

                PhysicsArgs args = ActivateablePhysics.GetTDoorArgs(block, true);
                lvl.AddUpdate(index, Block.air, false, args);
            }
        }
        static void FlyTo(Level lvl, ref PhysInfo C, ushort x, ushort y, ushort z, BlockID block)
        {
            int     index;
            BlockID neighbour = lvl.GetBlock(x, y, z, out index);

            if (neighbour == Block.Invalid)
            {
                return;
            }

            switch (neighbour)
            {
            case Block.Air:
                lvl.AddUpdate(index, block);
                break;

            case Block.Op_Air:
                break;

            default:
                // bird died by hitting a block
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 25;
                lvl.AddUpdate(C.Index, Block.Red, args);
                break;
            }
        }
Example #5
0
        static bool MoveSnake(Level lvl, ref Check C, int index)
        {
            if (
                lvl.GetTile(lvl.IntOffset(index, 0, -1, 0)) == Block.air &&
                lvl.GetTile(index) == Block.air)
            {
                index = lvl.IntOffset(index, 0, -1, 0);
            }
            else if (
                lvl.GetTile(index) == Block.air &&
                lvl.GetTile(lvl.IntOffset(index, 0, 1, 0)) == Block.air)
            {
            }
            else if (
                lvl.GetTile(lvl.IntOffset(index, 0, 2, 0)) == Block.air &&
                lvl.GetTile(lvl.IntOffset(index, 0, 1, 0)) == Block.air)
            {
                index = lvl.IntOffset(index, 0, 1, 0);
            }

            if (lvl.AddUpdate(index, lvl.blocks[C.b]))
            {
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                args.Type2 = PhysicsArgs.Revert; args.Value2 = Block.air;
                lvl.AddUpdate(C.b, Block.snaketail, true, args);
                return(true);
            }
            return(false);
        }
Example #6
0
        static bool MoveSnake(Level lvl, ref PhysInfo C, ushort x, ushort y, ushort z)
        {
            int index;

            // Move snake up or down blocks
            if (lvl.IsAirAt(x, (ushort)(y - 1), z, out index) && lvl.IsAirAt(x, y, z))
            {
            }
            else if (lvl.IsAirAt(x, y, z, out index) && lvl.IsAirAt(x, (ushort)(y + 1), z))
            {
            }
            else if (lvl.IsAirAt(x, (ushort)(y + 1), z, out index) && lvl.IsAirAt(x, (ushort)(y + 2), z))
            {
            }
            else
            {
                return(false);
            }

            if (lvl.AddUpdate(index, C.Block))
            {
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                args.Type2 = PhysicsArgs.Revert; args.Value2 = Block.Air;
                lvl.AddUpdate(C.Index, Block.SnakeTail, args, true);
                return(true);
            }
            return(false);
        }
        public static void Do(Level lvl, ref PhysInfo C)
        {
            if (C.Data.Type1 != PhysicsArgs.Custom)
            {
                return;
            }
            if (C.Data.Data == 0)
            {
                BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock << Block.ExtendedShift));
                bool    tdoor = lvl.Props[block].IsTDoor;

                if (tdoor)
                {
                    tDoor(lvl, ref C);
                }
                else
                {
                    Door(lvl, ref C);
                }
            }

            if (C.Data.Data <= C.Data.Value1)   // value1 for wait time
            {
                C.Data.Data++;
            }
            else
            {
                PhysicsArgs dArgs = default(PhysicsArgs);
                dArgs.ExtBlock = C.Data.ExtBlock;
                lvl.AddUpdate(C.Index, C.Data.Value2, dArgs);
                C.Data.Data = PhysicsArgs.RemoveFromChecks;
            }
        }
Example #8
0
        internal static PhysicsArgs GetDoorArgs(byte raw, bool isExt, out byte physForm)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.Type1    = PhysicsArgs.Wait; args.Value1 = 16 - 1;
            args.Type2    = PhysicsArgs.Revert; args.Value2 = raw;
            args.Door     = true;
            args.ExtBlock = isExt;

            physForm = Block.door_tree_air; // air
            if (isExt)
            {
            }
            else if (raw == Block.air_door || raw == Block.air_switch)
            {
                args.Value1 = 4 - 1;
            }
            else if (raw == Block.door_green)
            {
                physForm = Block.door_green_air; // red wool
            }
            else if (raw == Block.door_tnt)
            {
                args.Value1 = 4 - 1; physForm = Block.door_tnt_air; // lava
            }
            return(args);
        }
Example #9
0
        public static void DoAir(Level lvl, ref Check C)
        {
            ushort x, y, z;

            lvl.IntToPos(C.b, out x, out y, out z);

            ActivateablePhysics.CheckNeighbours(lvl, x, y, z);
            ActivateablePhysics.CheckAt(lvl, lvl.PosToInt(x, (ushort)(y - 1), z));

            //Edge of map water
            if (lvl.Config.EdgeWater && (y < lvl.Config.EdgeLevel && y >= (lvl.Config.EdgeLevel + lvl.Config.SidesOffset)))
            {
                if (x == 0 || x == lvl.Width - 1 || z == 0 || z == lvl.Length - 1)
                {
                    ExtBlock    block = ExtBlock.FromRaw((byte)lvl.Config.HorizonBlock);
                    PhysicsArgs args  = default(PhysicsArgs);
                    args.ExtBlock = block.BlockID == Block.custom_block;
                    lvl.AddUpdate(C.b, block.RawID, false, args);
                }
            }
            if (!C.data.HasWait)
            {
                C.data.Data = PhysicsArgs.RemoveFromChecks;
            }
        }
Example #10
0
        static void FlyTo(Level lvl, ref Check C, int x, int y, int z)
        {
            int index = lvl.PosToInt((ushort)x, (ushort)y, (ushort)z);

            if (index < 0)
            {
                return;
            }

            switch (lvl.blocks[index])
            {
            case Block.air:
                lvl.AddUpdate(index, lvl.blocks[C.b]);
                break;

            case Block.op_air:
                break;

            default:
                PhysicsArgs args = default(PhysicsArgs);
                args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 25;
                lvl.AddUpdate(C.b, Block.red, false, args);
                break;
            }
        }
Example #11
0
        static void Firework(ushort x, ushort y, ushort z, int size, Level lvl, Random rand)
        {
            if (lvl.physics < 1 || lvl.physics == 5)
            {
                return;
            }
            int rand1 = rand.Next(Block.red, Block.white);
            int rand2 = rand.Next(Block.red, Block.white);
            int min = Math.Min(rand1, rand2), max = Math.Max(rand1, rand2);

            // Not using override, since override = true makes it more likely that a colored block will be
            // generated with no extraInfo, because it sets a Check for that position with no extraInfo.
            lvl.AddUpdate(lvl.PosToInt(x, y, z), Block.air);

            for (ushort yy = (ushort)(y - (size + 1)); yy <= (ushort)(y + (size + 1)); ++yy)
            {
                for (ushort zz = (ushort)(z - (size + 1)); zz <= (ushort)(z + (size + 1)); ++zz)
                {
                    for (ushort xx = (ushort)(x - (size + 1)); xx <= (ushort)(x + (size + 1)); ++xx)
                    {
                        int index = lvl.PosToInt(xx, yy, zz);
                        if (index >= 0 && lvl.blocks[index] == Block.air && rand.Next(1, 40) < 2)
                        {
                            PhysicsArgs args = default(PhysicsArgs);
                            args.Type1 = PhysicsArgs.Drop; args.Value1 = 100;
                            args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 25;
                            lvl.AddUpdate(index, (byte)rand.Next(min, max), false, args);
                        }
                    }
                }
            }
        }
        internal static PhysicsArgs GetTDoorArgs(BlockID block)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.Type1    = PhysicsArgs.Custom; args.Value1 = 16;
            args.Type2    = PhysicsArgs.Revert; args.Value2 = (BlockRaw)block;
            args.ExtBlock = (byte)(block >> Block.ExtendedShift);
            return(args);
        }
Example #13
0
        static void DoOther(Level lvl, ref PhysInfo C, ref ExtraInfoArgs args)
        {
            Random rand = lvl.physRandom;

            if (args.Rainbow)
            {
                if (C.Data.Data < 4)
                {
                    C.Data.Data++;
                }
                else
                {
                    DoRainbow(lvl, ref C, rand, args.RainbowNum);
                }
                return;
            }

            if (args.Revert)
            {
                PhysicsArgs revertArgs = default(PhysicsArgs);
                revertArgs.ExtBlock = args.ExtBlock;
                lvl.AddUpdate(C.Index, args.RevertType, revertArgs);

                C.Data.ResetTypes();
                C.Data.Data = PhysicsArgs.RemoveFromChecks;
            }

            ushort x = C.X, y = C.Y, z = C.Z;

            // Not setting drop = false can cause occasional leftover blocks, since C.extraInfo is emptied, so
            // drop can generate another block with no dissipate/explode information.
            if (args.Dissipate && rand.Next(1, 100) <= args.DissipateNum)
            {
                if (!lvl.listUpdateExists.Get(x, y, z))
                {
                    lvl.AddUpdate(C.Index, Block.Air, default(PhysicsArgs));
                    C.Data.ResetTypes();
                    args.Drop = false;
                }
                else
                {
                    lvl.AddUpdate(C.Index, C.Block, C.Data);
                }
            }

            if (args.Explode && rand.Next(1, 100) <= args.ExplodeNum)
            {
                lvl.MakeExplosion(x, y, z, 0);
                C.Data.ResetTypes();
                args.Drop = false;
            }

            if (args.Drop && rand.Next(1, 100) <= args.DropNum)
            {
                DoDrop(lvl, ref C, rand, args.DropNum, x, y, z);
            }
        }
Example #14
0
        static void Explode(Level lvl, ushort x, ushort y, ushort z,
                            int size, Random rand, int prob, TWGame 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;
                        BlockID b = lvl.GetBlock((ushort)xx, (ushort)yy, (ushort)zz, out index);
                        if (b == Block.Invalid)
                        {
                            continue;
                        }

                        bool doDestroy = prob < 0 || rand.Next(1, 10) < prob;
                        if (doDestroy && Block.Convert(b) != Block.TNT)
                        {
                            if (game != null && b != Block.Air && !IsFuse(b, xx - x, yy - y, zz - z))
                            {
                                if (game.InZone((ushort)xx, (ushort)yy, (ushort)zz, game.tntImmuneZones))
                                {
                                    continue;
                                }
                            }

                            int mode = rand.Next(1, 11);
                            if (mode <= 4)
                            {
                                lvl.AddUpdate(index, Block.TNT_Explosion, default(PhysicsArgs));
                            }
                            else if (mode <= 8)
                            {
                                lvl.AddUpdate(index, Block.Air, default(PhysicsArgs));
                            }
                            else
                            {
                                PhysicsArgs args = default(PhysicsArgs);
                                args.Type1 = PhysicsArgs.Drop;      args.Value1 = 50;
                                args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 8;
                                lvl.AddCheck(index, false, args);
                            }
                        }
                        else if (b == Block.TNT)
                        {
                            lvl.AddUpdate(index, Block.TNT_Small, default(PhysicsArgs));
                        }
                        else if (b == Block.TNT_Small || b == Block.TNT_Big || b == Block.TNT_Nuke)
                        {
                            lvl.AddCheck(index);
                        }
                    }
                }
            }
        }
Example #15
0
        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;
                                }
                            }

                            int mode = rand.Next(1, 11);
                            if (mode <= 4)
                            {
                                lvl.AddUpdate(index, Block.TNT_Explosion);
                            }
                            else if (mode <= 8)
                            {
                                lvl.AddUpdate(index, Block.Air);
                            }
                            else
                            {
                                PhysicsArgs args = default(PhysicsArgs);
                                args.Type1 = PhysicsArgs.Drop; args.Value1 = 50;
                                args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 8;
                                lvl.AddCheck(index, false, args);
                            }
                        }
                        else if (b == Block.TNT)
                        {
                            lvl.AddUpdate(index, Block.TNT_Small);
                        }
                        else if (b == Block.TNT_Small || b == Block.TNT_Big || b == Block.TNT_Nuke)
                        {
                            lvl.AddCheck(index);
                        }
                    }
                }
            }
        }
Example #16
0
        internal static PhysicsArgs GetTDoorArgs(byte raw, bool isExt)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.Type1    = PhysicsArgs.Wait; args.Value1 = 16;
            args.Type2    = PhysicsArgs.Revert; args.Value2 = raw;
            args.Door     = true;
            args.ExtBlock = isExt;
            return(args);
        }
Example #17
0
        internal static PhysicsArgs GetTDoorArgs(ExtBlock block)
        {
            PhysicsArgs args = default(PhysicsArgs);

            args.Type1    = PhysicsArgs.Wait; args.Value1 = 16;
            args.Type2    = PhysicsArgs.Revert; args.Value2 = block.RawID;
            args.Door     = true;
            args.ExtBlock = block.BlockID == Block.custom_block;
            return(args);
        }
Example #18
0
        static void ActivateTDoor(Level lvl, ushort x, ushort y, ushort z)
        {
            int     index;
            BlockID block = lvl.GetBlock(x, y, z, out index);

            if (lvl.Props[block].IsTDoor)
            {
                PhysicsArgs args = ActivateablePhysics.GetTDoorArgs(block);
                lvl.AddUpdate(index, Block.Air, args);
            }
        }
Example #19
0
        public static void Do(Level lvl, ref Check C)
        {
            Random rand = lvl.physRandom;
            int    dirX = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirY = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirZ = rand.Next(1, 10) <= 5 ? 1 : -1;
            ushort x, y, z;

            lvl.IntToPos(C.b, out x, out y, out z);

            for (int cx = -dirX; cx != 2 * dirX; cx += dirX)
            {
                for (int cy = -dirY; cy != 2 * dirY; cy += dirY)
                {
                    for (int cz = -dirZ; cz != 2 * dirZ; cz += dirZ)
                    {
                        byte tileBelow = lvl.GetTile((ushort)(x + cx), (ushort)(y + cy - 1), (ushort)(z + cz));
                        byte tile      = lvl.GetTile((ushort)(x + cx), (ushort)(y + cy), (ushort)(z + cz));

                        bool isRails = false;
                        if (tileBelow != Block.custom_block)
                        {
                            isRails = Block.Props[tileBelow].IsRails;
                        }
                        else
                        {
                            byte extBelow = lvl.GetExtTile((ushort)(x + cx), (ushort)(y + cy - 1), (ushort)(z + cz));
                            isRails = lvl.CustomBlockProps[extBelow].IsRails;
                        }

                        if (isRails && (tile == Block.air || tile == Block.water))
                        {
                            lvl.AddUpdate(lvl.PosToInt((ushort)(x + cx),
                                                       (ushort)(y + cy), (ushort)(z + cz)), Block.train);
                            lvl.AddUpdate(C.b, Block.air);
                            byte newBlock = tileBelow == Block.op_air ? Block.glass : Block.obsidian;

                            tileBelow = lvl.GetTile(x, (ushort)(y - 1), z);
                            PhysicsArgs args = default(PhysicsArgs);
                            args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                            args.Type2 = PhysicsArgs.Revert; args.Value2 = tileBelow;

                            if (tileBelow == Block.custom_block)
                            {
                                args.Value2   = lvl.GetExtTile(x, (ushort)(y - 1), z);
                                args.ExtBlock = true;
                            }
                            lvl.AddUpdate(lvl.IntOffset(C.b, 0, -1, 0), newBlock, true, args);
                            return;
                        }
                    }
                }
            }
        }
        /// <summary> Activates fireworks, rockets, and TNT in 1 block radius around (x, y, z) </summary>
        public static void DoNeighbours(Level lvl, ushort x, ushort y, ushort z)
        {
            int bHead = 0, bTail = 0;

            for (int dy = -1; dy <= 1; dy++)
            {
                for (int dz = -1; dz <= 1; dz++)
                {
                    for (int dx = -1; dx <= 1; dx++)
                    {
                        BlockID block = lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz));
                        if (block == Block.RocketStart)
                        {
                            bool isFree =
                                lvl.GetBlock((ushort)(x + dx * 2), (ushort)(y + dy * 2), (ushort)(z + dz * 2), out bTail) == Block.Air &&
                                lvl.GetBlock((ushort)(x + dx * 3), (ushort)(y + dy * 3), (ushort)(z + dz * 3), out bHead) == Block.Air &&
                                !lvl.listUpdateExists.Get(x + dx * 3, y + dy * 3, z + dz * 3) &&
                                !lvl.listUpdateExists.Get(x + dx * 2, y + dy * 2, z + dz * 2);

                            if (isFree)
                            {
                                lvl.AddUpdate(bHead, Block.RocketHead, default(PhysicsArgs));
                                lvl.AddUpdate(bTail, Block.LavaFire, default(PhysicsArgs));
                            }
                        }
                        else if (block == Block.Fireworks)
                        {
                            bool isFree =
                                lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy + 1), (ushort)(z + dz), out bTail) == Block.Air &&
                                lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy + 2), (ushort)(z + dz), out bHead) == Block.Air &&
                                !lvl.listUpdateExists.Get(x + dx, y + dy + 1, z + dz) &&
                                !lvl.listUpdateExists.Get(x + dx, y + dy + 2, z + dz);

                            if (isFree)
                            {
                                lvl.AddUpdate(bHead, Block.Fireworks, default(PhysicsArgs));
                                PhysicsArgs args = default(PhysicsArgs);
                                args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 100;
                                lvl.AddUpdate(bTail, Block.StillLava, args);
                            }
                        }
                        else if (block == Block.TNT)
                        {
                            lvl.MakeExplosion((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz), 0);
                        }
                    }
                }
            }
        }
Example #21
0
        /// <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.LavaFire);
                            }
                        }
                        else if (b == Block.Fireworks)
                        {
                            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.Fireworks);
                                PhysicsArgs args = default(PhysicsArgs);
                                args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 100;
                                lvl.AddUpdate(b1, Block.StillLava, false, args);
                            }
                        }
                        else if (b == Block.TNT)
                        {
                            lvl.MakeExplosion((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz), 0);
                        }
                    }
                }
            }
        }
Example #22
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 block = lvl.blocks[index];
            bool ext   = block == Block.custom_block;

            BlockProps[] props = Block.Props;
            if (ext)
            {
                block = lvl.GetExtTile(x, y, z);
                props = lvl.CustomBlockProps;
            }

            if (props[block].IsDoor)
            {
                byte        physForm;
                PhysicsArgs args = GetDoorArgs(block, ext, out physForm);
                if (!instant)
                {
                    lvl.AddUpdate(index, physForm, false, args);
                }
                else
                {
                    lvl.Blockchange(index, physForm, false, args);
                }
            }
            else if (props[block].IsTDoor)
            {
                PhysicsArgs args = GetTDoorArgs(block, ext);
                lvl.AddUpdate(index, Block.air, false, args);
            }
            else
            {
                byte oDoor = props[block].ODoorId;
                if (oDoor != Block.Invalid)
                {
                    lvl.AddUpdate(index, oDoor, true);
                }
            }
        }
Example #23
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;
            ExtBlock block = lvl.GetBlock(x, y, z, out index);

            if (index == -1)
            {
                return;
            }

            int i = block.Index;

            if (lvl.Props[i].IsDoor)
            {
                byte        physForm;
                PhysicsArgs args = GetDoorArgs(block, out physForm);
                if (!instant)
                {
                    lvl.AddUpdate(index, physForm, false, args);
                }
                else
                {
                    lvl.Blockchange(index, (ExtBlock)physForm, false, args);
                }
            }
            else if (lvl.Props[i].IsTDoor)
            {
                PhysicsArgs args = GetTDoorArgs(block);
                lvl.AddUpdate(index, Block.Air, false, args);
            }
            else
            {
                ushort oDoorIndex = lvl.Props[i].oDoorIndex;
                if (oDoorIndex == Block.Invalid)
                {
                    return;
                }
                ExtBlock oDoor = ExtBlock.FromIndex(oDoorIndex);

                PhysicsArgs args = default(PhysicsArgs);
                args.ExtBlock = oDoor.BlockID == Block.custom_block;
                lvl.AddUpdate(index, oDoor.RawID, true, args);
            }
        }
Example #24
0
        static Player GetPlayer(ref PhysicsArgs args)
        {
            if (args.Type1 != PhysicsArgs.Custom)
            {
                return(null);
            }

            int id = args.Value1 | args.Value2 << 8 | (args.Data & 0xF) << 16;

            Player[] players = PlayerInfo.Online.Items;
            for (int i = 0; i < players.Length; i++)
            {
                if (players[i].SessionID == id)
                {
                    return(players[i]);
                }
            }
            return(null);
        }
Example #25
0
        static bool MoveSnakeY(Level lvl, ref PhysInfo C, ushort x, ushort y, ushort z)
        {
            int     index;
            BlockID block  = lvl.GetBlock(x, y, z, out index);
            BlockID above  = lvl.GetBlock(x, (ushort)(y + 1), z);
            BlockID above2 = lvl.GetBlock(x, (ushort)(y + 2), z);

            if (block == Block.Air && (above == Block.Grass || above == Block.Dirt && above2 == Block.Air))
            {
                if (lvl.AddUpdate(index, C.Block))
                {
                    PhysicsArgs args = default(PhysicsArgs);
                    args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                    args.Type2 = PhysicsArgs.Revert; args.Value2 = Block.Air;
                    lvl.AddUpdate(C.Index, Block.SnakeTail, args, true);
                    return(true);
                }
            }
            return(false);
        }
Example #26
0
        static bool MoveSnakeY(Level lvl, ref Check C, int index)
        {
            byte block       = lvl.GetTile(index);
            byte blockAbove  = lvl.GetTile(lvl.IntOffset(index, 0, 1, 0));
            byte block2Above = lvl.GetTile(lvl.IntOffset(index, 0, 2, 0));

            if (block == Block.air &&
                (blockAbove == Block.grass ||
                 blockAbove == Block.dirt && block2Above == Block.air))
            {
                if (lvl.AddUpdate(index, lvl.blocks[C.b]))
                {
                    PhysicsArgs args = default(PhysicsArgs);
                    args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
                    args.Type2 = PhysicsArgs.Revert; args.Value2 = Block.air;
                    lvl.AddUpdate(C.b, Block.snaketail, true, args);
                    return(true);
                }
            }
            return(false);
        }
Example #27
0
        public static void Do(Level lvl, ref Check C)
        {
            Random rand = lvl.physRandom;
            int    dirX = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirY = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirZ = rand.Next(1, 10) <= 5 ? 1 : -1;
            ushort x, y, z;

            lvl.IntToPos(C.b, out x, out y, out z);

            for (int dx = -dirX; dx != 2 * dirX; dx += dirX)
            {
                for (int dy = -dirY; dy != 2 * dirY; dy += dirY)
                {
                    for (int dz = -dirZ; dz != 2 * dirZ; dz += dirZ)
                    {
                        ExtBlock below   = lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy - 1), (ushort)(z + dz));
                        ExtBlock block   = lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz));
                        bool     isRails = lvl.Props[below.Index].IsRails;

                        if (isRails && (block.BlockID == Block.Air || block.BlockID == Block.Water) &&
                            !lvl.listUpdateExists.Get(x + dx, y + dy, z + dz))
                        {
                            lvl.AddUpdate(lvl.PosToInt((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz)), Block.Train);
                            lvl.AddUpdate(C.b, Block.Air);
                            byte newBlock = below.BlockID == Block.Op_Air ? Block.Glass : Block.Obsidian;

                            below = lvl.GetBlock(x, (ushort)(y - 1), z);
                            PhysicsArgs args = default(PhysicsArgs);
                            args.Type1    = PhysicsArgs.Wait; args.Value1 = 5;
                            args.Type2    = PhysicsArgs.Revert; args.Value2 = below.RawID;
                            args.ExtBlock = below.BlockID == Block.custom_block;

                            lvl.AddUpdate(lvl.IntOffset(C.b, 0, -1, 0), newBlock, true, args);
                            return;
                        }
                    }
                }
            }
        }
Example #28
0
        public static void Do(Level lvl, ref Check C)
        {
            Random rand = lvl.physRandom;
            ushort x, y, z;

            lvl.IntToPos(C.b, out x, out y, out z);

            if (lvl.GetTile(x, (ushort)(y - 1), z) != Block.lavastill)
            {
                return;
            }

            if (lvl.GetTile(x, (ushort)(y + 1), z) == Block.air)
            {
                bool keepGoing = true;
                if ((lvl.Height * 80 / 100) < y)
                {
                    keepGoing = rand.Next(1, 20) > 1;
                }

                if (keepGoing)
                {
                    int  bAbove    = lvl.PosToInt(x, (ushort)(y + 1), z);
                    bool unblocked = bAbove < 0 || !lvl.listUpdateExists.Get(x, y + 1, z);
                    if (unblocked)
                    {
                        PhysicsArgs args = default(PhysicsArgs);
                        args.Type1 = PhysicsArgs.Wait; args.Value1 = 1;
                        args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 100;

                        lvl.AddUpdate(bAbove, Block.firework, false);
                        lvl.AddUpdate(C.b, Block.lavastill, false, args);
                        args.Data = C.data.Data;
                        C.data    = args;
                        return;
                    }
                }
            }
            Firework(x, y, z, 4, lvl, rand);
        }
Example #29
0
        public static void Do(Level lvl, ref PhysInfo C)
        {
            Random rand = lvl.physRandom;
            int    dirX = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirY = rand.Next(1, 10) <= 5 ? 1 : -1;
            int    dirZ = rand.Next(1, 10) <= 5 ? 1 : -1;
            ushort x = C.X, y = C.Y, z = C.Z;

            for (int dx = -dirX; dx != 2 * dirX; dx += dirX)
            {
                for (int dy = -dirY; dy != 2 * dirY; dy += dirY)
                {
                    for (int dz = -dirZ; dz != 2 * dirZ; dz += dirZ)
                    {
                        int     index;
                        BlockID below   = lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy - 1), (ushort)(z + dz));
                        BlockID block   = lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz), out index);
                        bool    isRails = lvl.Props[below].IsRails;

                        if (isRails && (block == Block.Air || block == Block.Water) && !lvl.listUpdateExists.Get(x + dx, y + dy, z + dz))
                        {
                            lvl.AddUpdate(index, Block.Train, default(PhysicsArgs));
                            lvl.AddUpdate(C.Index, Block.Air, default(PhysicsArgs));
                            BlockID newBlock = below == Block.Op_Air ? Block.Glass : Block.Obsidian;

                            int belowIndex;
                            below = lvl.GetBlock(x, (ushort)(y - 1), z, out belowIndex);
                            PhysicsArgs args = default(PhysicsArgs);
                            args.Type1    = PhysicsArgs.Wait; args.Value1 = 5;
                            args.Type2    = PhysicsArgs.Revert; args.Value2 = (BlockRaw)below;
                            args.ExtBlock = (byte)(below >> Block.ExtendedShift);

                            lvl.AddUpdate(belowIndex, newBlock, args, true);
                            return;
                        }
                    }
                }
            }
        }
        /// <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;
            BlockID block = lvl.GetBlock(x, y, z, out index);

            if (index == -1)
            {
                return;
            }

            if (lvl.Props[block].IsDoor)
            {
                BlockID     physForm;
                PhysicsArgs args = GetDoorArgs(block, out physForm);
                if (!instant)
                {
                    lvl.AddUpdate(index, physForm, args);
                }
                else
                {
                    lvl.Blockchange(index, physForm, false, args);
                }
            }
            else if (lvl.Props[block].IsTDoor)
            {
                PhysicsArgs args = GetTDoorArgs(block);
                lvl.AddUpdate(index, Block.Air, args);
            }
            else
            {
                BlockID oDoor = lvl.Props[block].oDoorBlock;
                if (oDoor == Block.Invalid)
                {
                    return;
                }
                lvl.AddUpdate(index, oDoor, true);
            }
        }