예제 #1
0
        public static void DoGrassDie(Level lvl, ref Check C)
        {
            if (!lvl.Config.GrassGrow)
            {
                C.data.Data = PhysicsArgs.RemoveFromChecks; return;
            }
            ushort x, y, z;

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

            if (C.data.Data > 20)
            {
                ExtBlock above = lvl.GetBlock(x, (ushort)(y + 1), z);
                if (!lvl.LightPasses(above))
                {
                    ExtBlock block = lvl.GetBlock(x, y, z);
                    ExtBlock dirt  = ExtBlock.FromIndex(lvl.Props[block.Index].DirtIndex);
                    lvl.AddUpdate(C.b, dirt);
                }
                C.data.Data = PhysicsArgs.RemoveFromChecks;
            }
            else
            {
                C.data.Data++;
            }
        }
예제 #2
0
        static ExtBlock[] MostFrequentBlocks(int[] countsRaw)
        {
            ExtBlock[] blocks = new ExtBlock[512];
            int[]      counts = new int[512]; // copy array as Sort works in place
            int        total  = 0;

            for (int i = 0; i < blocks.Length; i++)
            {
                blocks[i] = ExtBlock.FromIndex(i);
                counts[i] = countsRaw[i];
                if (counts[i] > 0)
                {
                    total++;
                }
            }
            Array.Sort(counts, blocks);

            if (total > 5)
            {
                total = 5;
            }
            ExtBlock[] mostFrequent = new ExtBlock[total];
            for (int i = 0; i < total; i++)
            {
                mostFrequent[i] = blocks[blocks.Length - 1 - i];
            }
            return(mostFrequent);
        }
예제 #3
0
        static void Fix(Player p, Level lvl, ref int totalFixed, bool fixGrass, bool fixDirt)
        {
            int index = 0, maxY = lvl.Height - 1, oneY = lvl.Width * lvl.Length;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);
            ExtBlock            above = default(ExtBlock), block = default(ExtBlock);

            for (ushort y = 0; y < lvl.Height; y++)
            {
                for (ushort z = 0; z < lvl.Length; z++)
                {
                    for (ushort x = 0; x < lvl.Width; x++)
                    {
                        block.BlockID = lvl.blocks[index];
                        block.ExtID   = 0;
                        if (block.BlockID == Block.custom_block)
                        {
                            block.ExtID = lvl.GetExtTile(x, y, z);
                        }

                        if (fixGrass && lvl.Props[block.Index].GrassIndex != Block.Invalid)
                        {
                            above.BlockID = y == maxY ? Block.Air : lvl.blocks[index + oneY];
                            above.ExtID   = 0;
                            if (above.BlockID == Block.custom_block)
                            {
                                above.ExtID = lvl.GetExtTile(x, (ushort)(y + 1), z);
                            }

                            ExtBlock grass = ExtBlock.FromIndex(lvl.Props[block.Index].GrassIndex);
                            if (lvl.LightPasses(above) && p.level.DoBlockchange(p, x, y, z, grass) == 2)
                            {
                                buffer.Add(index, grass.BlockID, grass.ExtID);
                                totalFixed++;
                            }
                        }
                        else if (fixDirt && lvl.Props[block.Index].DirtIndex != Block.Invalid)
                        {
                            above.BlockID = y == maxY ? Block.Air : lvl.blocks[index + oneY];
                            above.ExtID   = 0;
                            if (above.BlockID == Block.custom_block)
                            {
                                above.ExtID = lvl.GetExtTile(x, (ushort)(y + 1), z);
                            }

                            ExtBlock dirt = ExtBlock.FromIndex(lvl.Props[block.Index].DirtIndex);
                            if (!lvl.LightPasses(above) && p.level.DoBlockchange(p, x, y, z, dirt) == 2)
                            {
                                buffer.Add(index, dirt.BlockID, dirt.ExtID);
                                totalFixed++;
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Send(true);
        }
예제 #4
0
        static void ActivateODoor(Level lvl, ExtBlock oDoor, ushort x, ushort y, ushort z)
        {
            int      index;
            ExtBlock block = lvl.GetBlock(x, y, z, out index);

            block = ExtBlock.FromIndex(lvl.Props[block.Index].oDoorIndex);

            if (index >= 0 && oDoor == block)
            {
                lvl.AddUpdate(index, oDoor, true);
            }
        }
예제 #5
0
 internal static void oDoor(Player p, ExtBlock block, ushort x, ushort y, ushort z)
 {
     if (block.BlockID == Block.oDoor_Green || block.BlockID == Block.oDoor_Green_air)
     {
         ushort oDoorOpposite = p.level.Props[block.Index].oDoorIndex;
         p.level.Blockchange(x, y, z, ExtBlock.FromIndex(oDoorOpposite));
     }
     else
     {
         p.RevertBlock(x, y, z);
     }
 }
예제 #6
0
        internal static void DirtGrow(Player p, ExtBlock block, ushort x, ushort y, ushort z)
        {
            if (SkipGrassDirt(p, block))
            {
                p.ChangeBlock(x, y, z, block); return;
            }
            Level    lvl   = p.level;
            ExtBlock above = lvl.GetBlock(x, (ushort)(y + 1), z);

            if (above.BlockID == Block.Invalid || lvl.LightPasses(above))
            {
                ushort index = p.level.Props[block.Index].GrassIndex;
                block = ExtBlock.FromIndex(index);
            }
            p.ChangeBlock(x, y, z, block);
        }
예제 #7
0
        static void GetCoreNames(List <string> names, Level lvl)
        {
            BlockProps[] props = lvl != null ? lvl.Props : Block.Props;
            for (int i = Block.Air; i < Block.Count; i++)
            {
                ExtBlock block = ExtBlock.FromIndex(i);
                if (block.BlockID == Block.custom_block)
                {
                    continue;
                }

                string name = Format(block, lvl, props);
                if (name != null)
                {
                    names.Add(name);
                }
            }
        }
예제 #8
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);
            }
        }
예제 #9
0
        static ExtBlock[] Transform(BlockDefinition[] defs, string[] mirrorDirs, string[] rotateDirs)
        {
            ExtBlock[] transform = new ExtBlock[Block.Count * 2];
            for (int i = 0; i < transform.Length; i++)
            {
                transform[i] = ExtBlock.FromIndex(i);
            }
            if (mirrorDirs == null && rotateDirs == null)
            {
                return(transform);
            }

            // Rotate/Mirror directional blocks
            for (int i = 0; i < defs.Length; i++)
            {
                if (defs[i] == null)
                {
                    continue;
                }
                int dirIndex = defs[i].Name.LastIndexOf('-');
                if (dirIndex == -1)
                {
                    continue;
                }

                BlockDefinition transformed = null;
                if (mirrorDirs != null)
                {
                    transformed = MirrorTransform(defs, i, dirIndex, mirrorDirs);
                }
                else
                {
                    transformed = RotateTransform(defs, i, dirIndex, rotateDirs);
                }

                if (transformed == null)
                {
                    continue;
                }
                ExtBlock src = ExtBlock.FromRaw(defs[i].BlockID);
                transform[src.Index] = ExtBlock.FromRaw(transformed.BlockID);
            }
            return(transform);
        }
예제 #10
0
        static void FixLight(Player p, Level lvl, ref int totalFixed)
        {
            int index = 0;
            BufferedBlockSender buffer = new BufferedBlockSender(lvl);
            ExtBlock            above = default(ExtBlock), block = default(ExtBlock);

            for (ushort y = 0; y < lvl.Height - 1; y++)
            {
                for (ushort z = 0; z < lvl.Length; z++)
                {
                    for (ushort x = 0; x < lvl.Width; x++)
                    {
                        block.BlockID = lvl.blocks[index];
                        block.ExtID   = 0;
                        bool inShadow = false;
                        if (block.BlockID == Block.custom_block)
                        {
                            block.ExtID = lvl.GetExtTile(x, y, z);
                        }

                        if (lvl.Props[block.Index].GrassIndex != Block.Invalid)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                above.BlockID = lvl.blocks[index + (lvl.Width * lvl.Length) * i];
                                above.ExtID   = 0;
                                if (above.BlockID == Block.custom_block)
                                {
                                    above.ExtID = lvl.GetExtTile(x, (ushort)(y + i), z);
                                }

                                if (!lvl.LightPasses(above))
                                {
                                    inShadow = true; break;
                                }
                            }

                            ExtBlock grass = ExtBlock.FromIndex(lvl.Props[block.Index].GrassIndex);
                            if (!inShadow && p.level.DoBlockchange(p, x, (ushort)y, z, grass) == 2)
                            {
                                buffer.Add(index, grass.BlockID, grass.ExtID);
                                totalFixed++;
                            }
                        }
                        else if (lvl.Props[block.Index].DirtIndex != Block.Invalid)
                        {
                            for (int i = 1; i < (lvl.Height - y); i++)
                            {
                                above.BlockID = lvl.blocks[index + (lvl.Width * lvl.Length) * i];
                                above.ExtID   = 0;
                                if (above.BlockID == Block.custom_block)
                                {
                                    above.ExtID = lvl.GetExtTile(x, (ushort)(y + i), z);
                                }

                                if (!lvl.LightPasses(above))
                                {
                                    inShadow = true; break;
                                }
                            }

                            ExtBlock dirt = ExtBlock.FromIndex(lvl.Props[block.Index].DirtIndex);
                            if (inShadow && p.level.DoBlockchange(p, x, (ushort)y, z, dirt) == 2)
                            {
                                buffer.Add(index, dirt.BlockID, dirt.ExtID);
                                totalFixed++;
                            }
                        }
                        index++;
                    }
                }
            }
            buffer.Send(true);
        }
예제 #11
0
 static bool SelectLevel(Level lvl, int i)
 {
     return(lvl.HasCustomProps(ExtBlock.FromIndex(i)));
 }