Example #1
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);

            // Make zombie fall down
            if (lvl.GetTile(x, (ushort)(y - 1), z) == Block.air)
            {
                lvl.AddUpdate(C.b, Block.zombiehead);
                lvl.AddUpdate(lvl.IntOffset(C.b, 0, -1, 0), lvl.blocks[C.b]);
                lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.air);
                return;
            }
            bool   checkTime = true;
            int    index     = 0;
            Player closest   = AIPhysics.ClosestPlayer(lvl, ref C);

            if (closest != null && rand.Next(1, 20) < 18)
            {
                if (rand.Next(1, 7) <= 3)
                {
                    index = lvl.PosToInt((ushort)(x + Math.Sign((closest.pos[0] / 32) - x)), y, z);
                    if (index != C.b && MoveZombie(lvl, ref C, index))
                    {
                        return;
                    }

                    index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((closest.pos[2] / 32) - z)));
                    if (index != C.b && MoveZombie(lvl, ref C, index))
                    {
                        return;
                    }
                }
                else
                {
                    index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((closest.pos[2] / 32) - z)));
                    if (index != C.b && MoveZombie(lvl, ref C, index))
                    {
                        return;
                    }

                    index = lvl.PosToInt((ushort)(x + Math.Sign((closest.pos[0] / 32) - x)), y, z);
                    if (index != C.b && MoveZombie(lvl, ref C, index))
                    {
                        return;
                    }
                }
                checkTime = false;
            }

            if (checkTime && C.data.Data < 3)
            {
                C.data.Data++;
                return;
            }

            int dirsVisited = 0;

            switch (rand.Next(1, 13))
            {
            case 1:
            case 2:
            case 3:
                index = lvl.IntOffset(C.b, -1, 0, 0);
                if (MoveZombie(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 4;

            case 4:
            case 5:
            case 6:
                index = lvl.IntOffset(C.b, 1, 0, 0);
                if (MoveZombie(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 7;

            case 7:
            case 8:
            case 9:
                index = lvl.IntOffset(C.b, 0, 0, 1);
                if (MoveZombie(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 10;

            case 10:
            case 11:
            case 12:
                index = lvl.IntOffset(C.b, 0, 0, -1);
                if (MoveZombie(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 1;
            }
            lvl.AddUpdate(C.b, Block.air);
            lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.air);
        }
Example #2
0
        public static void DoFlee(Level lvl, ref Check C, byte target)
        {
            Random rand = lvl.physRandom;
            Player closest = AIPhysics.ClosestPlayer(lvl, ref 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, ref 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, ref 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, ref C, index, target))
                        {
                            return;
                        }
                    }
                    dirsVisited++;
                    if (dirsVisited >= 3)
                    {
                        break;
                    }
                    goto case 1;
                }
            }
            RandomlyMove(lvl, ref C, rand, x, y, z, target);
        }
Example #3
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);
            int    dirsVisited = 0, index = 0;
            Player foundPlayer = AIPhysics.ClosestPlayer(lvl, ref C);

            if (foundPlayer != null && rand.Next(1, 20) < 19)
            {
                switch (rand.Next(1, 10))
                {
                case 1:
                case 2:
                case 3:
                    index = lvl.PosToInt((ushort)(x + Math.Sign((foundPlayer.pos[0] / 32) - x)), y, z);
                    if (index != C.b && MoveSnake(lvl, ref C, index))
                    {
                        return;
                    }

                    dirsVisited++;
                    if (dirsVisited >= 3)
                    {
                        break;
                    }
                    goto case 4;

                case 4:
                case 5:
                case 6:
                    index = lvl.PosToInt(x, (ushort)(y + Math.Sign((foundPlayer.pos[1] / 32) - y)), z);
                    if (index != C.b && MoveSnakeY(lvl, ref C, index))
                    {
                        return;
                    }

                    dirsVisited++;
                    if (dirsVisited >= 3)
                    {
                        break;
                    }
                    goto case 7;

                case 7:
                case 8:
                case 9:
                    index = lvl.PosToInt(x, y, (ushort)(z + Math.Sign((foundPlayer.pos[2] / 32) - z)));
                    if (index != C.b && MoveSnake(lvl, ref C, index))
                    {
                        return;
                    }

                    dirsVisited++;
                    if (dirsVisited >= 3)
                    {
                        break;
                    }
                    goto case 1;
                }
            }

            dirsVisited = 0;
            switch (rand.Next(1, 13))
            {
            case 1:
            case 2:
            case 3:
                index = lvl.IntOffset(C.b, -1, 0, 0);
                if (MoveSnake(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 4;

            case 4:
            case 5:
            case 6:
                index = lvl.IntOffset(C.b, 1, 0, 0);
                if (MoveSnake(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 7;

            case 7:
            case 8:
            case 9:
                index = lvl.IntOffset(C.b, 0, 0, 1);
                if (MoveSnake(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 10;

            case 10:
            case 11:
            case 12:
            default:
                index = lvl.IntOffset(C.b, 0, 0, -1);
                if (MoveSnake(lvl, ref C, index))
                {
                    return;
                }

                dirsVisited++;
                if (dirsVisited >= 4)
                {
                    return;
                }
                goto case 1;
            }
        }