Ejemplo n.º 1
0
 protected override bool ModifyInternal(RoomSpec spec, double scale)
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, ToString());
     }
     #endregion
     int height = spec.Random.Next((int)(_minSize * scale), (int)(_maxSize * scale));
     int width  = spec.Random.Next((int)(_minSize * scale), (int)(_maxSize * scale));
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.w(Logs.LevelGen, "Height: " + height + ", Width: " + width);
     }
     #endregion
     Point center = spec.Grids.Center;
     int   left   = center.x - (width / 2);
     int   bottom = center.y - (height / 2);
     spec.Grids.DrawRect(left, left + width, bottom, bottom + height, new StrokedAction <GenSpace>()
     {
         UnitAction   = Draw.SetTo(GridType.Floor, spec.Theme),
         StrokeAction = Draw.SetTo(GridType.Wall, spec.Theme)
     });
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, ToString());
     }
     #endregion
     return(true);
 }
Ejemplo n.º 2
0
 protected void HandleDoor(int x, int y, List <Point> doorOptions, RoomSpec spec)
 {
     if (spec.Grids.DrawDir(x, y, GridDirection.HORIZ, Draw.Walkable()))
     {
         doorOptions.Add(new Point(x, y));
     }
 }
Ejemplo n.º 3
0
 protected override bool ModifyInternal(RoomSpec spec, double scale)
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, ToString());
     }
     #endregion
     int min  = (int)(MinSize * scale);
     int max  = (int)(MaxSize * scale);
     int side = spec.Random.Next(min, max);
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.w(Logs.LevelGen, "Side: " + side);
     }
     #endregion
     Point center = spec.Grids.Center;
     int   left   = center.x - (side / 2);
     int   bottom = center.y - (side / 2);
     spec.Grids.DrawRect(left, left + side, bottom, bottom + side, new StrokedAction <GenSpace>()
     {
         UnitAction   = Draw.SetTo(GridType.Floor, spec.Theme),
         StrokeAction = Draw.SetTo(GridType.Wall, spec.Theme)
     });
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, ToString());
     }
     #endregion
     return(true);
 }
Ejemplo n.º 4
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        IPillarTheme pillarTheme = spec.Theme as IPillarTheme;

        if (pillarTheme == null)
        {
            throw new ArgumentException("Theme must be IPillarTheme");
        }
        Bounding bounds            = spec.Grids.Bounding;
        int      spacingX          = spacingOptions.Get(spec.Random);
        int      spacingY          = spec.Random.Percent(differingSpacingChance) ? spacingOptions.Get(spec.Random) : spacingX;
        Container2D <GenSpace> arr = spec.Grids;
        var pillarSet = pillarTheme.GetPillars().SmartElement;
        var call      = Draw.IsType <GenSpace>(GridType.Floor).And(Draw.Not(Draw.Blocking(Draw.Walkable())))
                        .IfThen(Draw.MergeIn(pillarSet, spec.Random, spec.Theme));

        for (int x = bounds.XMin; x < bounds.XMax; x = x + spacingX)
        {
            for (int y = bounds.YMin; y < bounds.YMax; y = y + spacingY)
            {
                call(arr, x, y);
            }
        }

        return(true);
    }
        public ActionResult DeleteConfirmed(int id)
        {
            RoomSpec roomSpec = db.RoomSpecs.Find(id);

            db.RoomSpecs.Remove(roomSpec);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, ToString());
        }
        #endregion
        Counter floorSpace;
        RandomPicker <GenSpace> picker;
        spec.Grids.DrawAll(Draw.EmptyAndFloor().IfThen(Draw.Count <GenSpace>(out floorSpace).And(Draw.PickRandom(out picker))));
        if (floorSpace < 15)
        {
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                BigBoss.Debug.w(Logs.LevelGen, "Room was too small: " + floorSpace);
            }
            #endregion
            return(false);
        }
        int treasureInRoom = treasureSizeList.Get(spec.Random);
        int trapsInRoom    = (floorSpace - treasureInRoom) / 8;
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.w(Logs.LevelGen, "Treasure In Room: " + treasureInRoom);
            BigBoss.Debug.w(Logs.LevelGen, "Floor Space: " + floorSpace + " Traps In Room: " + trapsInRoom);
        }
        #endregion

        List <Value2D <GenSpace> > treasureList = picker.Pick(spec.Random, treasureInRoom, 2, true);
        foreach (Value2D <GenSpace> val in treasureList)
        {
            spec.Grids.SetTo(val, GridType.Chest, spec.Theme);
        }

        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            spec.Grids.ToLog(Logs.LevelGen, "After picking treasure");
        }
        #endregion

        List <Value2D <GenSpace> > trapList = picker.Pick(spec.Random, trapsInRoom, 0, true);
        foreach (Value2D <GenSpace> val in trapList)
        {
            spec.Grids.SetTo(val, GridType.Trap, spec.Theme);
        }
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printFooter(Logs.LevelGen, ToString());
        }
        #endregion
        return(true);
    }
Ejemplo n.º 7
0
    protected override bool ModifyInternal(RoomSpec spec, double scale)
    {
        _amounts.Freshen();
        _primitives.Freshen();
        byte amount             = _amounts.Get(spec.Random);
        List <BaseRoomMod> mods = _primitives.Get(spec.Random, amount);

        throw new NotImplementedException("");
        return(true);
    }
Ejemplo n.º 8
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        UndeadTombTheme undeadTheme = spec.Theme as UndeadTombTheme;

        if (undeadTheme == null)
        {
            throw new ArgumentException("Theme needs to be undead themed.");
        }
        var                     tombCollection = undeadTheme.Tombs.SmartElement;
        ThemeElement            tombProto      = tombCollection.Proto;
        List <List <Bounding> > options        = spec.Grids.FindRectanglesMaximized(tombProto.GridWidth + 2, tombProto.GridLength + 2, true, new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.IsType <GenSpace>(GridType.Floor),
            StrokeAction = Draw.Walkable()
        }, spec.Grids.Bounding);

        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Printing tomb layout options");
            for (int i = 0; i < options.Count; i++)
            {
                MultiMap <GenSpace> tmp = new MultiMap <GenSpace>(spec.Grids);
                foreach (Bounding bound in options[i])
                {
                    tmp.DrawRect(bound.XMin, bound.XMax, bound.YMin, bound.YMax, new StrokedAction <GenSpace>()
                    {
                        UnitAction   = Draw.SetTo(GridType.Wall, spec.Theme),
                        StrokeAction = Draw.True <GenSpace>()
                    });
                }
                tmp.ToLog(Logs.LevelGen, "Option " + i);
            }
            BigBoss.Debug.printFooter(Logs.LevelGen, "Printing tomb layout options");
        }
        #endregion
        while (options.Count > 0)
        {
            List <Bounding> set = options.RandomTake(spec.Random);
            if (set.Count > MIN_TOMBS)
            {
                foreach (Bounding tombBound in set)
                {
                    GenDeploy tomb = new GenDeploy(tombCollection.Get(spec.Random));
                    spec.Grids.DrawRect(tombBound.XMin, tombBound.XMax, tombBound.YMin, tombBound.YMax, new StrokedAction <GenSpace>()
                    {
                        UnitAction   = Draw.MergeIn(tomb, spec.Theme),
                        StrokeAction = Draw.True <GenSpace>()
                    });
                }
                return(true);
            }
        }
        return(false);
    }
 public ActionResult Edit([Bind(Include = "Id,Specification,RoomId")] RoomSpec roomSpec)
 {
     if (ModelState.IsValid)
     {
         db.Entry(roomSpec).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RoomId = new SelectList(db.Rooms, "Id", "RoomName", roomSpec.RoomId);
     return(View(roomSpec));
 }
        public ActionResult Create([Bind(Include = "Id,Specification,RoomId")] RoomSpec roomSpec)
        {
            if (ModelState.IsValid)
            {
                db.RoomSpecs.Add(roomSpec);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RoomId = new SelectList(db.Rooms, "Id", "RoomName", roomSpec.RoomId);
            return(View(roomSpec));
        }
Ejemplo n.º 11
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        int secretRoomSize = 2;

        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Hidden Room Mod");
            spec.Grids.ToLog(Logs.LevelGen, "Final Room After placing doors");
        }
        #endregion

        RandomPicker <GenSpace> picker;
        spec.Grids.DrawPotentialExternalDoors(Draw.PickRandom(out picker));

        Value2D <GenSpace> doorSpace;
        if (!picker.Pick(spec.Random, out doorSpace))
        {
            return(false);
        }
        var floors = new List <Value2D <GenSpace> >();
        spec.Grids.DrawRect(
            (doorSpace.x - secretRoomSize), (doorSpace.x + secretRoomSize),
            (doorSpace.y - secretRoomSize), (doorSpace.y + secretRoomSize),
            new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.IsTypeThen(GridType.NULL, Draw.SetTo(GridType.Floor, spec.Theme).And(Draw.AddTo(floors))),
            StrokeAction = Draw.IsType <GenSpace>(GridType.NULL).IfThen(Draw.SetTo(GridType.Wall, spec.Theme))
        });
        bool chest = spec.Random.Percent(.75d);
        if (chest)
        {
            List <Value2D <GenSpace> > chestOptions = new List <Value2D <GenSpace> >();
            spec.Grids.DrawPoints(floors.Cast <Point>(),
                                  Draw.Not(Draw.HasAround(false, Draw.IsType <GenSpace>(GridType.Door)))
                                  .IfThen(Draw.AddTo(chestOptions)));
            spec.Grids.SetTo(chestOptions.Random(spec.Random), GridType.Chest, spec.Theme);
        }
        else
        {
            spec.Grids.SetTo(floors.Random(spec.Random), GridType.SmallLoot, spec.Theme);
        }
        spec.Grids.SetTo(doorSpace, GridType.Door, spec.Theme);
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            spec.Grids.ToLog(Logs.LevelGen, "Final Room After placing doors");
            BigBoss.Debug.printFooter(Logs.LevelGen, "Hidden Room Mod");
        }
        #endregion
        return(true);
    }
Ejemplo n.º 12
0
    protected override bool ModifyInternal(RoomSpec spec, double scale)
    {
        spec.RoomModifiers.RemoveMod(this);
        BaseRoomMod baseMod = spec.RoomModifiers.BaseMods.Get(spec.Random);

        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.w(Logs.LevelGen, "Picked base mod " + baseMod);
        }
        #endregion
        scale *= 2d;
        baseMod.Modify(spec, scale);
        int             numTombs     = spec.Random.Next(2, 5) * 2;
        List <Bounding> largestRects = spec.Grids.FindLargestRectangles(false, new StrokedAction <GenSpace>()
        {
            UnitAction = Draw.IsType <GenSpace>(GridType.Floor)
        }, spec.Grids.Bounding);
        if (largestRects.Count == 0)
        {
            return(false);
        }
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
        {
            BigBoss.Debug.w(Logs.LevelGen, "Largest Rect Options");
            foreach (Bounding bounds in largestRects)
            {
                MultiMap <GenSpace> tmp = new MultiMap <GenSpace>(spec.Grids);
                tmp.DrawRect(bounds, new StrokedAction <GenSpace>()
                {
                    UnitAction = Draw.SetTo(GridType.INTERNAL_RESERVED_BLOCKED, spec.Theme)
                });
                tmp.ToLog(Logs.LevelGen);
            }
        }
        #endregion
        Bounding bound = largestRects.Random(spec.Random);
        // Place tombs

        int buffer     = spec.Random.NextBool() ? 1 : 2;
        int pillarSize = 3;
        // Place pillars
        //spec.Grids.DrawRect(bound.XMin + buffer, bound.XMin + pillarSize + buffer - 1, bound.YMin + buffer, bound.YMin + pillarSize + buffer - 1, Draw.SetTo(GridType.Pillar, spec.Theme));
        //spec.Grids.DrawRect(bound.XMax - 3, bound.XMin + 3, bound.YMin, bound.YMin + 3, Draw.SetTo(GridType.Pillar, spec.Theme));
        //spec.Grids.DrawRect(bound.XMin, bound.XMin + 3, bound.YMin, bound.YMin + 3, Draw.SetTo(GridType.Pillar, spec.Theme));
        //spec.Grids.DrawRect(bound.XMin, bound.XMin + 3, bound.YMin, bound.YMin + 3, Draw.SetTo(GridType.Pillar, spec.Theme));
        // Remove more tomb mods
        spec.RoomModifiers.RemoveMod(new MassTombRoom(), true);
        return(false);
    }
        // GET: RoomSpecs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RoomSpec roomSpec = db.RoomSpecs.Find(id);

            if (roomSpec == null)
            {
                return(HttpNotFound());
            }
            return(View(roomSpec));
        }
        // GET: RoomSpecs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RoomSpec roomSpec = db.RoomSpecs.Find(id);

            if (roomSpec == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RoomId = new SelectList(db.Rooms, "Id", "RoomName", roomSpec.RoomId);
            return(View(roomSpec));
        }
Ejemplo n.º 15
0
    protected override bool ModifyInternal(RoomSpec spec, double scale)
    {
        ShortMax = (int)(ShortMax * scale);
        ShortMin = (int)(ShortMin * scale);
        LongMin  = (int)(LongMin * scale);
        LongMax  = (int)(LongMax * scale);
        // First Rect
        int shortSide = spec.Random.Next(ShortMin, ShortMax);
        int longSide  = spec.Random.Next(LongMin, LongMax);

        spec.Grids.DrawRect(0, shortSide, 0, longSide, new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.SetTo(GridType.Floor, spec.Theme),
            StrokeAction = Draw.SetTo(GridType.Wall, spec.Theme)
        });

        // Second rect
        int  otherLongSide  = spec.Random.Next(ShortMin, LongMax - shortSide);
        int  otherShortSide = spec.Random.Next(ShortMin, Math.Min(longSide - 2, ShortMax));
        bool center         = spec.Random.NextBool();
        int  yStart;

        if (center)
        {
            yStart = ((longSide / 2) - (otherShortSide / 2));
        }
        else
        {
            int buffer = longSide - otherShortSide / 3;
            int max    = longSide - otherShortSide + 1 - buffer;
            if (buffer >= max)
            {
                yStart = ((longSide / 2) - (otherShortSide / 2));
            }
            else
            {
                yStart = spec.Random.Next(buffer, max);
            }
        }
        spec.Grids.DrawRect(shortSide - 1, shortSide + otherLongSide - 1, yStart, yStart + otherShortSide, new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.SetTo(GridType.Floor, spec.Theme),
            StrokeAction = Draw.IsTypeThen(GridType.NULL, Draw.SetTo(GridType.Wall, spec.Theme))
        });

        spec.Grids.Rotate(spec.Random.NextRotation());
        return(true);
    }
Ejemplo n.º 16
0
    protected bool ApplyMod <T>(RoomSpec spec, ProbabilityPool <T> mods)
        where T : RoomModifier
    {
        mods.BeginTaking();
        T mod;

        while (mods.Take(spec.Random, out mod))
        {
            #region DEBUG
            float stepTime = 0;
            if (BigBoss.Debug.logging(Logs.LevelGenMain))
            {
                BigBoss.Debug.w(Logs.LevelGenMain, "   Applying: " + mod);
            }
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                stepTime = Time.realtimeSinceStartup;
                BigBoss.Debug.w(Logs.LevelGen, "Applying: " + mod);
            }
            #endregion
            Container2D <GenSpace> backupGrid = new MultiMap <GenSpace>(spec.Grids);
            if (mod.Modify(spec))
            {
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    spec.Grids.ToLog(Logs.LevelGen, "Applying " + mod + " took " + (Time.realtimeSinceStartup - stepTime) + " seconds.");
                }
                #endregion
                mods.EndTaking();
                return(true);
            }
            else
            {
                spec.Grids = backupGrid;
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    spec.Grids.ToLog(Logs.LevelGen, "Couldn't apply mod.  Processing " + mod + " took " + (Time.realtimeSinceStartup - stepTime) + " seconds.");
                }
                #endregion
            }
        }
        mods.EndTaking();
        return(false);
    }
Ejemplo n.º 17
0
        private void Window_AirQuality_Message(RoomSpec myData)
        {
            mylist = new List <Alerts>();
            int result   = Convert.ToInt32(myData.qai);
            int seuilAir = 50;

            Debug.WriteLine("myData.qai = {0}", myData.qai);
            Debug.WriteLine("result = {0}", result);
            if (result == seuilAir)
            {
                Alerts myAlert = new Alerts();

                myAlert.imageName = "alerte1_0003s_0006s_0000_fenetre-ouverte.png";
                myAlert.errorText = "Fermez la fenêtre de " + myData.name + " pour concerver votre niveau de confort";
                mylist.Add(myAlert);
            }
        }
Ejemplo n.º 18
0
    protected override bool ModifyInternal(RoomSpec spec, double scale)
    {
        int radius = spec.Random.Next((int)(MinRadius * scale), (int)(MaxRadius * scale));
        int center = spec.Grids.Width / 2;

        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.w(Logs.LevelGen, "Radius: " + radius);
        }
        #endregion
        spec.Grids.DrawCircle(center, center, radius, new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.SetTo(GridType.Floor, spec.Theme),
            StrokeAction = Draw.SetTo(GridType.Wall, spec.Theme)
        });
        return(true);
    }
Ejemplo n.º 19
0
 // Use this for initialization
 void Start()
 {
     System.Random rand = new System.Random();
     for (int i = 0; i < 100; i++)
     {
         try
         {
             LayoutObject obj   = new LayoutObject("Room Test " + i);
             RoomSpec     spec  = new RoomSpec(obj, 1, null, rand);
             TRoomMod     troom = new TRoomMod();
             troom.Modify(spec);
             spec.Grids.ToLog(Logs.LevelGenMain, "Test TRoom " + i);
         }
         catch (Exception ex)
         {
             BigBoss.Debug.w(Logs.LevelGenMain, "Exception " + ex);
         }
     }
 }
Ejemplo n.º 20
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        List <Bounding> options = spec.Grids.FindRectangles(5, 5, false, new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.Walkable(),
            StrokeAction = Draw.Not(Draw.Blocking(Draw.Walkable())).And(Draw.IsType <GenSpace>(GridType.Floor).Or(Draw.WallType <GenSpace>()))
        }, spec.Grids.Bounding);

        while (options.Count > 0)
        {
            Bounding bounding = options.RandomTake(spec.Random);
            Point    center   = bounding.GetCenter();
            if (spec.Grids[center].Type != GridType.Floor)
            {
                return(false);
            }
            List <Point> doors = new List <Point>();
            HandleDoor(bounding.XMin, center.y, doors, spec);
            HandleDoor(bounding.XMin, center.y, doors, spec);
            HandleDoor(center.x, bounding.YMin, doors, spec);
            HandleDoor(center.x, bounding.YMax, doors, spec);
            if (doors.Count == 0)
            {
                return(false);
            }
            // Draw it
            spec.Grids.DrawRect(bounding.XMin, bounding.XMax, bounding.YMin, bounding.YMax, new StrokedAction <GenSpace>()
            {
                StrokeAction = Draw.SetTo(GridType.Wall, spec.Theme),
                UnitAction   = Draw.SetTo(GridType.Floor, spec.Theme)
            });
            foreach (var door in doors)
            {
                spec.Grids.SetTo(door, GridType.Door, spec.Theme);
            }
            spec.Grids.SetTo(center, GridType.Chest, spec.Theme);
            return(true);
        }
        return(true);
    }
Ejemplo n.º 21
0
    public Blueprint(int width, int height, int roomsRemaining)
    {
        this.width = width;
        this.height = height;
        this.roomsRemaining = roomsRemaining;

        map = new RoomSpec[width,height];

        for(int i = 0; i<width; i++){
            for(int j = 0; j<height; j++){
                map[i,j] = new RoomSpec();
            }
        }

        x = Mathf.FloorToInt(Random.value*width);
        y = Mathf.FloorToInt(Random.value*height);
        map[x,y].markRoomAsStart();

        tracePath();

        map[x,y].markRoomAsBoss();
    }
Ejemplo n.º 22
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        int size = spec.Random.Next(3, 5);

        BigBoss.Debug.w(Logs.LevelGen, "Size: " + size);
        // Add an extra 2 for stroke width for analysis
        size += 2;
        List <Bounding> locations = spec.Grids.FindRectangles(size, size, false, new StrokedAction <GenSpace>()
        {
            UnitAction   = Draw.Or(Draw.IsType <GenSpace>(GridType.Floor), Draw.IsType <GenSpace>(GridType.Wall)).And(Draw.Empty()),
            StrokeAction = Draw.Walkable()
        },
                                                              spec.Grids.Bounding);

        if (locations.Count == 0)
        {
            return(false);
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
        {
            BigBoss.Debug.w(Logs.LevelGen, locations.Count + " Options: ");
            var save = new MultiMap <GenSpace>();
            var copy = new Array2D <GenSpace>(spec.Grids);
            foreach (Bounding r in locations)
            {
                save.Clear();
                copy.DrawRect(r.XMin + 1, r.XMax - 1, r.YMin + 1, r.YMax - 1, Draw.AddTo(save).And(Draw.SetTo(GridType.Path_Vert, spec.Theme)));
                copy.ToLog(Logs.LevelGen);
                copy.PutAll(save);
            }
        }
        #endregion
        Bounding l = locations.Random(spec.Random);
        // Draw inner square without stroke (stroke was just used to analyze surroundings)
        spec.Grids.DrawRect(l.XMin + 1, l.XMax - 1, l.YMin + 1, l.YMax - 1, Draw.SetTo(GridType.Wall, spec.Theme));
        return(true);
    }
Ejemplo n.º 23
0
    private void InstantiateCriticalPathRooms()
    {
        int i = 0;                              // grid position we are currently spawning
        int j = UnityEngine.Random.Range(0, 4); // grid position we are currently spawning

        Direction?prev_dir = null;

        bool hasPlacedExitDoor = false;

        while (true)
        {
            //Debug.Log("running i=" + i + " j=" + j);

            bool thisIsFirstRoom = prev_dir == null;

            // where we can go from current i, j
            Direction[] validDirections = Array.FindAll(allDirections, d =>
                                                        d != Direction.Top && // never go up
                                                        (j > 0 || d != Direction.Left) && // do not go left if we're at the leftmost room already
                                                        (j < 3 || d != Direction.Right) && // do not go right if we're at the rightmost room already
                                                        (i < 3 || d != Direction.Bottom) && // do not go bottom if we're at the lowest room already
                                                        (grid[i + d.IndexDelta().i, j + d.IndexDelta().j] == null) // do not go on an already spawned room
                                                        );

            // chosen direction
            Direction?dir = validDirections.GetRandNul();

            // filter prefabs by rooms that have an entrance in the chosen exit direction
            GameObject[] roomPrefabsThatHaveExitInChosenDir = Array.FindAll(roomPrefabs, rp =>
            {
                RoomSpec spec = rp.GetComponentInChildren <RoomSpec>(true);
                return(spec != null &&
                       (prev_dir == null || spec.HasExit(prev_dir.Value.Invert())) &&  // entrance from previous dir
                       (dir == null || spec.HasExit(dir.Value)) &&  // exit in next dir
                       (!thisIsFirstRoom || spec.canSpawnPlayer) &&  // if this is the first room we are spawning, it must have a player spawn location
                       (dir != null || spec.hasExitDoor)     // has exit door if it is last spawning room
                       );
            }
                                                                            );

            // pick one randomly
            GameObject roomPrefab = roomPrefabsThatHaveExitInChosenDir.GetRand();
            if (roomPrefab == null)
            {
                throw new Exception("thisIsFirstRoom=" + thisIsFirstRoom + " add a room prefab that has an exit of type " + (dir != null ? dir.Value.ToString() : "null"));
            }

            // spawn
            //Debug.Log("spawning i=" + i + " j=" + j);
            float x = (j - 1) * roomSize - roomSize / 2;
            float y = -((i - 1) * roomSize - roomSize / 2);
            grid[i, j] = Instantiate(roomPrefab, new Vector3(x, y, 0), Quaternion.identity).GetComponent <RoomSpec>();

            // place the player (already spawned) here
            if (thisIsFirstRoom)
            {
                player.transform.position = grid[i, j].playerSpawnLocation.transform.position;
            }

            // put exit door and stop
            if (dir == null)
            {
                exitDoor.transform.position = grid[i, j].exitSpawnLocation.transform.position;
                break;
            }

            // save values as previous
            prev_dir = dir;

            // move pointers in the next dir
            i += dir.Value.IndexDelta().i;
            j += dir.Value.IndexDelta().j;
        }
    }
Ejemplo n.º 24
0
 protected abstract bool ModifyInternal(RoomSpec spec, double scale);
Ejemplo n.º 25
0
 protected override bool ModifyInternal(RoomSpec spec)
 {
     return(ModifyInternal(spec, 1d));
 }
Ejemplo n.º 26
0
 public bool Modify(RoomSpec spec, double scale)
 {
     return(ModifyInternal(spec, scale));
 }
Ejemplo n.º 27
0
 public bool Modify(RoomSpec spec)
 {
     return(ModifyInternal(spec));
 }
Ejemplo n.º 28
0
 protected abstract bool ModifyInternal(RoomSpec spec);
Ejemplo n.º 29
0
    protected override bool ModifyInternal(RoomSpec spec)
    {
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Splitter Mod");
        }
        #endregion
        Bounding   bounds     = spec.Grids.Bounding;
        List <int> options    = new List <int>();
        bool       horizontal = spec.Random.NextBool();
        int        from       = bounds.GetMin(horizontal);
        int        to         = bounds.GetMax(horizontal);
        int        fromAlt    = bounds.GetMin(!horizontal);
        int        toAlt      = bounds.GetMax(!horizontal);

        // Iterate and find all viable options
        for (int i = fromAlt; i <= toAlt; i++)
        {
            Counter floorCount;
            Counter side1;
            Counter side2;
            if (spec.Grids.DrawLine(from, to, i, horizontal,
                                    // If no doors around
                                    Draw.Not(Draw.Around(false, Draw.IsType <GenSpace>(GridType.Door)))
                                    // Not blocking walking
                                    .And(Draw.Not(Draw.Blocking <GenSpace>(Draw.Walkable())))
                                    // Count floors on line as well as sides
                                    .And(Draw.IsType <GenSpace>(GridType.Floor).IfThen(Draw.Count <GenSpace>(out floorCount)))
                                    .And(Draw.Loc(horizontal ? GridLocation.TOP : GridLocation.LEFT,
                                                  Draw.IsTypeThen(GridType.Floor, Draw.Count <GenSpace>(out side1))))
                                    .And(Draw.Loc(horizontal ? GridLocation.BOTTOM : GridLocation.RIGHT,
                                                  Draw.IsTypeThen(GridType.Floor, Draw.Count <GenSpace>(out side2)))))
                // Has a floor in each
                && floorCount > 0 && side1 > 0 && side2 > 0
                )
            {
                options.Add(i);
            }
        }
        if (options.Count == 0)
        {
            return(false);
        }
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.FineSteps))
        {
            foreach (int i in options)
            {
                Container2D <GenSpace> copy = new Array2D <GenSpace>(spec.Grids);
                copy.DrawLine(from, to, i, horizontal, Draw.IsType <GenSpace>(GridType.NULL).IfNotThen(Draw.SetTo(GridType.INTERNAL_RESERVED_BLOCKED, spec.Theme)));
                copy.ToLog(Logs.LevelGen);
            }
        }
        #endregion

        // Draw selected splitter
        int          picked = options.Random(spec.Random);
        List <Point> walls  = new List <Point>();
        spec.Grids.DrawLine(from, to, picked, horizontal, Draw.Not(Draw.IsType <GenSpace>(GridType.NULL)).IfThen(Draw.SetTo(GridType.Wall, spec.Theme).And(Draw.AddTo <GenSpace>(walls))));
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.w(Logs.LevelGen, "Picked splitter:");
            spec.Grids.ToLog(Logs.LevelGen);
        }
        #endregion

        spec.Grids.PlaceSomeDoors(walls, spec.Theme, spec.Random, 5);
        #region DEBUG
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printFooter(Logs.LevelGen, "Splitter Mod");
        }
        #endregion
        return(true);
    }
Ejemplo n.º 30
0
 void ModRooms()
 {
     foreach (LayoutObject room in Objects)
     {
         #region DEBUG
         double time = 0;
         if (BigBoss.Debug.logging(Logs.LevelGenMain))
         {
             BigBoss.Debug.w(Logs.LevelGenMain, "Mods for " + room);
         }
         if (BigBoss.Debug.logging(Logs.LevelGen))
         {
             BigBoss.Debug.CreateNewLog(Logs.LevelGen, "Level Depth " + Depth + "/" + Depth + " " + 0 + " - Generate Room " + room.Id);
             BigBoss.Debug.printHeader(Logs.LevelGen, "Modding " + room);
             time = Time.realtimeSinceStartup;
         }
         #endregion
         Theme.ChooseAllSmartObjects(Rand);
         RoomSpec spec = new RoomSpec(room, Depth, Theme, Rand);
         // Base Mod
         if (!ApplyMod(spec, spec.RoomModifiers.BaseMods))
         {
             throw new ArgumentException("Could not apply base mod");
         }
         // Definining Mod
         if (spec.RoomModifiers.AllowDefiningMod)
         {
             ApplyMod(spec, spec.RoomModifiers.DefiningMods);
         }
         // Flex Mods
         int numFlex  = Rand.Next(spec.RoomModifiers.MinFlexMods, spec.RoomModifiers.MaxFlexMods);
         int numHeavy = (int)Math.Round((numFlex / 3d) + (numFlex / 3d * Rand.NextDouble()));
         int numFill  = numFlex - numHeavy;
         // Heavy Mods
         for (int i = 0; i < numHeavy; i++)
         {
             if (!ApplyMod(spec, spec.RoomModifiers.HeavyMods))
             {
                 break;
             }
         }
         // Fill Mods
         for (int i = 0; i < numFill; i++)
         {
             if (!ApplyMod(spec, spec.RoomModifiers.FillMods))
             {
                 break;
             }
         }
         // Final Mods
         ApplyMod(spec, spec.RoomModifiers.FinalMods);
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen))
         {
             room.ToLog(Logs.LevelGen);
             BigBoss.Debug.w(Logs.LevelGen, "Modding " + room + " took " + (Time.realtimeSinceStartup - time) + " seconds.");
             BigBoss.Debug.printFooter(Logs.LevelGen, "Modding " + room);
         }
         #endregion
         if (!ValidateRoom(room))
         {
             throw new ArgumentException(room + " is not valid.");
         }
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGenMain))
     {
         foreach (LayoutObject room in Objects)
         {
             room.ToLog(Logs.LevelGenMain);
         }
     }
     #endregion
 }
Ejemplo n.º 31
0
			public static RoomSpec FromGuid(Guid g)
			{
				if (g == Guid.Empty)
					return null;

				try
				{
					RoomSpec r = new RoomSpec();
					byte[] bytes = g.ToByteArray();
					r.Version = (int)bytes[0];
					

					if (r.Version == 1)
					{
						r.RoomType = (RoomType)(int)bytes[1];
						r.ObjectType = (Model.Entities.ObjectType)(int)bytes[2];
						r.ObjectK = BitConverter.ToInt32(new byte[] { bytes[3], bytes[4], bytes[5], bytes[6] }, 0);
						r.SecondObjectType = (Model.Entities.ObjectType)(int)bytes[7];
						r.SecondObjectK = BitConverter.ToInt32(new byte[] { bytes[8], bytes[9], bytes[10], bytes[11] }, 0);

						byte[] hash = r.getHash().ToByteArray();

						if (bytes[12] != hash[0] ||
							bytes[13] != hash[1] ||
							bytes[14] != hash[2] ||
							bytes[15] != hash[3])
							return null;

						return r;
					}
					else
						return null;
				}
				catch
				{
					return null;
				}
			}
Ejemplo n.º 32
0
			protected override void Execute()
			{
				Query q = new Query();
				q.TableElement = Usr.BuddyJoin;
				q.QueryCondition = new And(Usr.GetBuddiesFullQ(UsrK.Value), Usr.LoggedInChatQ);
				q.Columns = new ColumnSet(Usr.Columns.K);
				UsrSet loggedOnBuddies = new UsrSet(q);

				System.Web.Script.Serialization.JavaScriptSerializer d = new System.Web.Script.Serialization.JavaScriptSerializer();
				ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress);

				foreach (Usr buddy in loggedOnBuddies)
				{

					RoomSpec roomSpec = new RoomSpec(RoomType.BuddyStream, Model.Entities.ObjectType.Usr, buddy.K);
					Guid roomGuid = roomSpec.Guid;
					Guid itemGuid = Guid.NewGuid();

					Item.Value.guid = itemGuid.Pack();
					Item.Value.roomGuid = roomGuid.Pack();


					cs.SendTo(roomGuid, d.Serialize(Item.Value), new int[] { buddy.K }, itemGuid);
				}
			}
Ejemplo n.º 33
0
 protected override bool ModifyInternal(RoomSpec spec)
 {
     return(true);
 }