protected override float PlaceRoom(List <RoomDef> Collision, RoomDef Prev, RoomDef Next, float Angle)
        {
            var v = base.PlaceRoom(Collision, Prev, Next, Angle);

            if (v > -1 && Next is ShopRoom)
            {
                Log.Info("Placing sub shop rooms");

                foreach (var r in SubShop)
                {
                    var a = Rnd.Angle();
                    var i = 0;

                    while (true)
                    {
                        var an = PlaceRoom(Collision, Next, r, a % 360);

                        if ((int)an != -1)
                        {
                            break;
                        }

                        i++;

                        if (i > 36)
                        {
                            Log.Error("Failed.");
                            return(-1);
                        }

                        a += 10;
                    }
                }

                /*if (SubShop.Count > 0) {
                 *      for (var i = 0; i < SubShop.Count - 1; i++) {
                 *              for (var j = i + 1; j < SubShop.Count; j++) {
                 *                      SubShop[i].ConnectTo(SubShop[j]);
                 *              }
                 *      }
                 * }*/

                Log.Info("Failed to fail.");
            }

            return(v);
        }
Exemple #2
0
        public override void PostInit()
        {
            base.PostInit();

            X -= 16;
            Y -= 16;

            Width        = 32;
            Height       = 32;
            angle        = Rnd.Angle();
            targetScale  = Rnd.Float(0.7f, 1.2f);
            AlwaysActive = true;

            AddTag(Tags.Mess);

            var list = Animations.Get("splash_fx").Layers.First().Value;

            region = list[Rnd.Int(list.Count)].Texture;
        }
 protected virtual float RandomBranchAngle(RoomDef R)
 {
     return(Rnd.Angle());
 }
Exemple #4
0
        private bool PlaceBoss(List <RoomDef> Init, RoomDef R)
        {
            var a = Direction;
            var i = 0;

            while (true)
            {
                var an = PlaceRoom(Init, R, Boss, a);

                if ((int)an != -1)
                {
                    break;
                }

                i++;

                if (i > 36)
                {
                    return(false);
                }

                a += 10;
            }

            if (Granny != null)
            {
                a = Rnd.Angle();
                i = 0;

                while (true)
                {
                    var an = PlaceRoom(Init, Boss, Granny, a);

                    if ((int)an != -1)
                    {
                        break;
                    }

                    i++;

                    if (i > 72)
                    {
                        return(false);
                    }

                    a += 5;
                }
            }

            if (OldMan != null)
            {
                a = Rnd.Angle();
                i = 0;

                while (true)
                {
                    var an = PlaceRoom(Init, Boss, OldMan, a);

                    if ((int)an != -1)
                    {
                        break;
                    }

                    i++;

                    if (i > 72)
                    {
                        return(false);
                    }

                    a += 5;
                }
            }

            return(true);
        }
Exemple #5
0
 public LineBuilder()
 {
     Direction = Rnd.Angle();
 }
Exemple #6
0
        public override List <RoomDef> Build(List <RoomDef> Init)
        {
            SetupRooms(Init);

            if (Entrance == null)
            {
                Log.Error("No entrance!");
                return(null);
            }

            var Branchable = new List <RoomDef>();

            Entrance.SetSize();
            Entrance.SetPos(0, 0);
            Branchable.Add(Entrance);

            if (MultiConnection.Count == 0)
            {
                PlaceRoom(Init, Entrance, Exit, Rnd.Angle());

                if (Boss != null && !PlaceBoss(Init, Exit))
                {
                    return(null);
                }

                return(Init);
            }

            var RoomsOnPath = (int)(MultiConnection.Count * PathLength) + Rnd.Chances(PathLenJitterChances);

            RoomsOnPath = Math.Min(RoomsOnPath, MultiConnection.Count);
            RoomDef Curr        = Entrance;
            var     PathTunnels = ArrayUtils.Clone(PathTunnelChances);

            for (var I = 0; I <= RoomsOnPath; I++)
            {
                if (I == RoomsOnPath && Exit == null)
                {
                    continue;
                }

                var Tunnels = Rnd.Chances(PathTunnels);

                if (Tunnels == -1)
                {
                    PathTunnels = ArrayUtils.Clone(PathTunnelChances);
                    Tunnels     = Rnd.Chances(PathTunnels);
                }

                PathTunnels[Tunnels]--;

                if (I != 0 && Run.Depth != 0)
                {
                    for (var J = 0; J < Tunnels; J++)
                    {
                        var T = RoomRegistry.Generate(RoomType.Connection, LevelSave.BiomeGenerated);

                        if (Math.Abs(PlaceRoom(Init, Curr, T, Direction + Rnd.Float(-PathVariance, PathVariance)) - (-1)) < 0.01f)
                        {
                            return(null);
                        }

                        Branchable.Add(T);
                        Init.Add(T);
                        Curr = T;
                    }
                }

                var R = I == RoomsOnPath ? Exit : MultiConnection[I];


                if (Math.Abs(PlaceRoom(Init, Curr, R, Direction + Rnd.Float(-PathVariance, PathVariance)) - (-1)) < 0.01f)
                {
                    return(null);
                }

                if (R == Exit && Boss != null && !PlaceBoss(Init, R))
                {
                    return(null);
                }

                Branchable.Add(R);
                Curr = R;
            }

            var RoomsToBranch = new List <RoomDef>();

            for (var I = RoomsOnPath; I < MultiConnection.Count; I++)
            {
                RoomsToBranch.Add(MultiConnection[I]);
            }

            RoomsToBranch.AddRange(SingleConnection);

            WeightRooms(Branchable);

            if (!CreateBranches(Init, Branchable, RoomsToBranch, BranchTunnelChances))
            {
                return(null);
            }

            FindNeighbours(Init);

            foreach (var R in Init)
            {
                foreach (var N in R.Neighbours)
                {
                    if (!N.Connected.ContainsKey(R) && Rnd.Float() < ExtraConnectionChance)
                    {
                        R.ConnectWithRoom(N);
                    }
                }
            }

            return(Init);
        }
        public override List <RoomDef> Build(List <RoomDef> Init)
        {
            SetupRooms(Init);

            if (Entrance == null)
            {
                return(null);
            }

            var Branchable = new List <RoomDef>();

            Entrance.SetSize();
            Entrance.SetPos(0, 0);

            Branchable.Add(Entrance);
            var RoomsToBranch = new List <RoomDef>(MultiConnection);

            if (Exit != null)
            {
                RoomsToBranch.Add(Exit);
            }

            RoomsToBranch.AddRange(SingleConnection);

            if (!CreateBranches(Init, Branchable, RoomsToBranch, BranchTunnelChances))
            {
                return(null);
            }

            var a = Rnd.Angle() - 90;
            var i = 0;

            if (Boss != null)
            {
                while (true)
                {
                    var an = PlaceRoom(Init, Exit, Boss, a);

                    if ((int)an != -1)
                    {
                        break;
                    }

                    i++;

                    if (i > 36)
                    {
                        return(null);
                    }

                    a += 10;
                }

                a = Rnd.Angle();
                i = 0;

                if (Granny != null)
                {
                    while (true)
                    {
                        var an = PlaceRoom(Init, Boss, Granny, a);

                        if ((int)an != -1)
                        {
                            break;
                        }

                        i++;

                        if (i > 72)
                        {
                            return(null);
                        }

                        a += 5;
                    }
                }

                a = Rnd.Angle();
                i = 0;

                if (OldMan != null)
                {
                    while (true)
                    {
                        var an = PlaceRoom(Init, Boss, OldMan, a);

                        if ((int)an != -1)
                        {
                            break;
                        }

                        i++;

                        if (i > 72)
                        {
                            return(null);
                        }

                        a += 5;
                    }
                }
            }

            FindNeighbours(Init);

            foreach (RoomDef R in Init)
            {
                foreach (RoomDef N in R.Neighbours)
                {
                    if (!N.Connected.ContainsKey(R) && Rnd.Float() < ExtraConnectionChance)
                    {
                        R.ConnectWithRoom(N);
                    }
                }
            }

            return(Init);
        }
Exemple #8
0
        public override List <RoomDef> Build(List <RoomDef> Init)
        {
            SetupRooms(Init);

            if (Entrance == null)
            {
                return(null);
            }

            Entrance.SetPos(0, 0);
            Entrance.SetSize();
            var StartAngle = Rnd.Angle();
            var Loop       = new List <RoomDef>();

            var RoomsOnLoop = (int)(MultiConnection.Count * PathLength) + Rnd.Chances(PathLenJitterChances);

            RoomsOnLoop = Math.Min(RoomsOnLoop, MultiConnection.Count);
            RoomsOnLoop++;
            var PathTunnels = ArrayUtils.Clone(PathTunnelChances);

            for (var i = MultiConnection.Count - 1; i >= 0; i--)
            {
                var r = MultiConnection[i];

                if (r is ConnectionRoom)
                {
                    Loop.Add(r);
                    MultiConnection.RemoveAt(i);
                }
            }

            for (var I = 0; I < RoomsOnLoop; I++)
            {
                if (I == 0)
                {
                    Loop.Add(Entrance);
                }
                else
                {
                    Loop.Add(MultiConnection[0]);
                    MultiConnection.RemoveAt(0);
                }

                var Tunnels = Rnd.Chances(PathTunnels);

                if (Tunnels == -1)
                {
                    PathTunnels = ArrayUtils.Clone(PathTunnelChances);
                    Tunnels     = Rnd.Chances(PathTunnels);
                }

                PathTunnels[Tunnels]--;

                for (var J = 0; J < Tunnels; J++)
                {
                    Loop.Add(RoomRegistry.Generate(RoomType.Connection, LevelSave.BiomeGenerated));
                }
            }

            if (Exit != null)
            {
                Loop.Insert((Loop.Count + 1) / 2, Exit);
            }

            if (LevelSave.BiomeGenerated is LibraryBiome)
            {
                var c = (Loop.Count + 1);

                Loop.Insert(c / 4, new LibraryConnectionRoom());
                Loop.Insert(c / 4 * 3, new LibraryConnectionRoom {
                    BottomHalf = true
                });
            }

            RoomDef Prev = Entrance;
            float   TargetAngle;

            for (var I = 1; I < Loop.Count; I++)
            {
                var R = Loop[I];
                TargetAngle = StartAngle + this.TargetAngle(I / (float)Loop.Count);

                if ((int)PlaceRoom(Init, Prev, R, TargetAngle) != -1)
                {
                    Prev = R;

                    if (!Init.Contains(Prev))
                    {
                        Init.Add(Prev);
                    }

                    if (R == Exit && Boss != null)
                    {
                        var a = TargetAngle - 90;
                        var i = 0;

                        while (true)
                        {
                            var an = PlaceRoom(Init, R, Boss, a);

                            if ((int)an != -1)
                            {
                                break;
                            }

                            i++;

                            if (i > 36)
                            {
                                return(null);
                            }

                            a += 10;
                        }

                        a = Rnd.Angle();
                        i = 0;

                        if (Granny != null)
                        {
                            while (true)
                            {
                                var an = PlaceRoom(Init, Boss, Granny, a);

                                if ((int)an != -1)
                                {
                                    break;
                                }

                                i++;

                                if (i > 72)
                                {
                                    return(null);
                                }

                                a += 5;
                            }
                        }

                        a = Rnd.Angle();
                        i = 0;

                        if (OldMan != null)
                        {
                            while (true)
                            {
                                var an = PlaceRoom(Init, Boss, OldMan, a);

                                if ((int)an != -1)
                                {
                                    break;
                                }

                                i++;

                                if (i > 72)
                                {
                                    return(null);
                                }

                                a += 5;
                            }
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }

            while (!Prev.ConnectTo(Entrance))
            {
                var C = RoomRegistry.Generate(RoomType.Regular, LevelSave.BiomeGenerated);

                if ((int)PlaceRoom(Loop, Prev, C, AngleBetweenRooms(Prev, Entrance)) == -1)
                {
                    return(null);
                }

                Loop.Add(C);
                Init.Add(C);
                Prev = C;
            }

            LoopCenter = new Vector2();

            foreach (var R in Loop)
            {
                LoopCenter.X += (R.Left + R.Right) / 2f;
                LoopCenter.Y += (R.Top + R.Bottom) / 2f;
            }

            LoopCenter.X /= Loop.Count;
            LoopCenter.Y /= Loop.Count;
            var Branchable    = new List <RoomDef>(Loop);
            var RoomsToBranch = new List <RoomDef>();

            RoomsToBranch.AddRange(MultiConnection);
            RoomsToBranch.AddRange(SingleConnection);
            WeightRooms(Branchable);

            if (!CreateBranches(Init, Branchable, RoomsToBranch, BranchTunnelChances))
            {
                return(null);
            }

            FindNeighbours(Init);

            foreach (var R in Init)
            {
                foreach (var N in R.Neighbours)
                {
                    if (!N.Connected.ContainsKey(R) && Rnd.Float() < ExtraConnectionChance)
                    {
                        R.ConnectWithRoom(N);
                    }
                }
            }

            if (!Prev.Connected.ContainsKey(Entrance))
            {
                Prev.Neighbours.Add(Entrance);
                Entrance.Neighbours.Add(Prev);
                Prev.Connected[Entrance] = null;
                Entrance.Connected[Prev] = null;
            }

            return(Init);
        }