Пример #1
0
 public void Reverse(Dir8 dir, Dir8 expected, bool exception = false)
 {
     if (exception)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => { dir.Reverse(); });
     }
     else
     {
         Assert.That(dir.Reverse(), Is.EqualTo(expected));
         Assert.That(expected.Reverse(), Is.EqualTo(dir));
     }
 }
Пример #2
0
        public void ResizeJustified(int width, int height, Dir8 anchorDir)
        {
            RogueElements.Grid.LocAction changeOp = (Loc effectLoc) => { };
            RogueElements.Grid.LocAction newOp    = (Loc effectLoc) => { Tiles[effectLoc.X][effectLoc.Y] = new AutoTile(); };

            Loc diff = RogueElements.Grid.ResizeJustified(ref Tiles,
                                                          width, height, anchorDir.Reverse(), changeOp, newOp);
        }
Пример #3
0
        private void preCalculateCoverage(StablePriorityQueue <int, Loc> tilesToHit, int delay)
        {
            Loc topLeft = Origin - new Loc(MaxRadius);

            bool[][] connectionGrid = new bool[MaxRadius * 2 + 1][];
            for (int xx = 0; xx < connectionGrid.Length; xx++)
            {
                connectionGrid[xx] = new bool[MaxRadius * 2 + 1];
            }

            connectionGrid[Origin.X - topLeft.X][Origin.Y - topLeft.Y] = true;
            tilesToHit.Enqueue(calculateTimeToHit(Origin) + delay, Origin);

            Loc backup = Origin;

            if (MaxRadius > 0 && ZoneManager.Instance.CurrentMap.TileBlocked(Origin, true))
            {
                backup += Dir.Reverse().GetLoc();
            }

            Grid.FloodFill(new Rect(Origin - new Loc(MaxRadius), new Loc(MaxRadius * 2 + 1)),
                           (Loc testLoc) =>
            {
                if (connectionGrid[testLoc.X - topLeft.X][testLoc.Y - topLeft.Y])
                {
                    return(true);
                }
                if (!Collision.InBounds(ZoneManager.Instance.CurrentMap.Width, ZoneManager.Instance.CurrentMap.Height, testLoc))
                {
                    return(true);
                }
                if (!IsInSquareHitbox(testLoc, Origin, MaxRadius, HitArea, Dir))
                {
                    return(true);
                }
                if (ZoneManager.Instance.CurrentMap.TileBlocked(testLoc, true))
                {
                    return(true);
                }

                return(false);
            },
                           (Loc testLoc) =>
            {
                return(false);
            },
                           (Loc fillLoc) =>
            {
                if (fillLoc != Origin)
                {
                    connectionGrid[fillLoc.X - topLeft.X][fillLoc.Y - topLeft.Y] = true;
                    tilesToHit.Enqueue(calculateTimeToHit(fillLoc) + delay, fillLoc);
                }
            },
                           backup);
        }
Пример #4
0
        public void ResizeJustified(int width, int height, Dir8 anchorDir)
        {
            foreach (MapLayer layer in Layers)
            {
                layer.ResizeJustified(width, height, anchorDir);
            }

            //tiles
            Grid.LocAction changeOp = (Loc loc) => { Tiles[loc.X][loc.Y].Effect.UpdateTileLoc(loc); };
            Grid.LocAction newOp    = (Loc loc) => { Tiles[loc.X][loc.Y] = new Tile(0, loc); };

            Loc diff = Grid.ResizeJustified(ref Tiles, width, height, anchorDir.Reverse(), changeOp, newOp);

            //discovery array
            changeOp = (Loc loc) => { };
            newOp    = (Loc loc) => { };

            Grid.ResizeJustified(ref DiscoveryArray, width, height, anchorDir.Reverse(), changeOp, newOp);

            foreach (Character character in IterateCharacters())
            {
                character.CharLoc = Collision.ClampToBounds(width, height, character.CharLoc + diff);
                character.UpdateFrame();
                UpdateExploration(character);
            }

            //items
            foreach (MapItem item in Items)
            {
                item.TileLoc = Collision.ClampToBounds(width, height, item.TileLoc + diff);
            }

            //entry points
            for (int ii = 0; ii < EntryPoints.Count; ii++)
            {
                EntryPoints[ii] = new LocRay8(EntryPoints[ii].Loc + diff, EntryPoints[ii].Dir);
            }
        }
Пример #5
0
        public static bool IsInSquareHitbox(Loc loc, Loc origin, int squareRadius, AreaLimit limit, Dir8 dir)
        {
            if (loc.X < origin.X - squareRadius || loc.X > origin.X + squareRadius)
            {
                return(false);
            }
            if (loc.Y < origin.Y - squareRadius || loc.Y > origin.Y + squareRadius)
            {
                return(false);
            }

            if (limit == AreaLimit.Cone)
            {
                //check if it's inside the cone

                //get line diff
                Loc diff = loc - origin;

                //get cone vectors
                Dir8 cone1 = DirExt.AddAngles(dir, Dir8.DownRight);
                Dir8 cone2 = DirExt.AddAngles(dir, Dir8.DownLeft);

                //get vector orthogonal1 to first cone line (aka, -second cone line)
                Loc ortho1 = cone2.GetLoc() * -1;

                //get vector orthogonal2 to second cone line ( aka, first cone line)
                Loc ortho2 = cone1.GetLoc();

                //get dot product of diff to orthogonal1; must be less than or equal to 0
                int dot1 = Loc.Dot(diff, ortho1);

                //get dot product of diff to orthogonal2; must be greater than or equal to 0
                int dot2 = Loc.Dot(diff, ortho2);

                if (dot1 > 0 || dot2 < 0)
                {
                    return(false);
                }
            }
            else if (limit == AreaLimit.Sides)
            {
                Loc diff = loc - origin;
                if (dir.IsDiagonal())
                {
                    //get cone vectors
                    Dir8 cone1 = DirExt.AddAngles(dir.Reverse(), Dir8.DownRight);
                    Dir8 cone2 = DirExt.AddAngles(dir.Reverse(), Dir8.DownLeft);

                    //get vector orthogonal1 to first cone line (aka, -second cone line)
                    Loc ortho1 = cone2.GetLoc() * -1;

                    //get vector orthogonal2 to second cone line ( aka, first cone line)
                    Loc ortho2 = cone1.GetLoc();

                    //get dot product of diff to orthogonal1; must be less than or equal to 0
                    int dot1 = Loc.Dot(diff, ortho1);

                    //get dot product of diff to orthogonal2; must be greater than or equal to 0
                    int dot2 = Loc.Dot(diff, ortho2);

                    if (dot1 > 0 || dot2 < 0)
                    {
                        return(false);
                    }

                    //additionally, both dot products cannot be a nonzero
                    if (dot1 != 0 && dot2 != 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    //check if it's inside the sides
                    int dot = Loc.Dot(diff, dir.GetLoc());

                    //check if the other point is EXACTLY perpendicular
                    if (dot != 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #6
0
        /// <summary>
        /// Changes size without changing the start.
        /// </summary>
        /// <param name="newSize"></param>
        /// <param name="dir"></param>
        /// <param name="anchorDir">The anchor point of the initial floor rect.</param>
        public void Resize(Loc newSize, Dir8 dir, Dir8 anchorDir)
        {
            Loc diff       = Grid.GetResizeOffset(this.Size.X, this.Size.Y, newSize.X, newSize.Y, dir);
            Loc anchorDiff = Grid.GetResizeOffset(this.Size.X, this.Size.Y, newSize.X, newSize.Y, anchorDir.Reverse());

            this.Start -= diff;
            this.Size   = newSize;
            for (int ii = 0; ii < this.Rooms.Count; ii++)
            {
                this.Rooms[ii].RoomGen.SetLoc(this.Rooms[ii].RoomGen.Draw.Start + anchorDiff - diff);
            }

            for (int ii = 0; ii < this.Halls.Count; ii++)
            {
                this.Halls[ii].RoomGen.SetLoc(this.Halls[ii].RoomGen.Draw.Start + anchorDiff - diff);
            }
        }
Пример #7
0
        public void ResizeJustified(int width, int height, Dir8 anchorDir)
        {
            foreach (MapLayer layer in Layers)
            {
                layer.ResizeJustified(width, height, anchorDir);
            }

            int divSize = GraphicsManager.TEX_SIZE;

            RogueElements.Grid.LocAction blockChangeOp = (Loc effectLoc) => { obstacles[effectLoc.X][effectLoc.Y].Bounds = new Rect(effectLoc.X * divSize, effectLoc.Y * divSize, divSize, divSize); };
            RogueElements.Grid.LocAction blocknewOp    = (Loc effectLoc) => { obstacles[effectLoc.X][effectLoc.Y] = new GroundWall(effectLoc.X * divSize, effectLoc.Y * divSize, divSize, divSize); };

            Loc texDiff = RogueElements.Grid.ResizeJustified(ref obstacles,
                                                             width * TexSize, height * TexSize, anchorDir.Reverse(), blockChangeOp, blocknewOp);

            foreach (GroundChar character in IterateCharacters())
            {
                character.SetMapLoc(RogueElements.Collision.ClampToBounds(width * TileSize - character.Width, height * TileSize - character.Height, character.MapLoc + texDiff * divSize));
                character.UpdateFrame();
            }

            this.grid = new AABB.Grid(width, height, GraphicsManager.TileSize);
        }
Пример #8
0
        public void ResizeJustified(int width, int height, Dir8 anchorDir)
        {
            foreach (MapLayer layer in Layers)
            {
                layer.ResizeJustified(width, height, anchorDir);
            }

            int divSize = GraphicsManager.TEX_SIZE;

            RogueElements.Grid.LocAction blockChangeOp = (Loc effectLoc) => { obstacles[effectLoc.X][effectLoc.Y].Bounds = new Rect(effectLoc.X * divSize, effectLoc.Y * divSize, divSize, divSize); };
            RogueElements.Grid.LocAction blocknewOp    = (Loc effectLoc) => { obstacles[effectLoc.X][effectLoc.Y] = new GroundWall(effectLoc.X * divSize, effectLoc.Y * divSize, divSize, divSize); };

            Loc texDiff = RogueElements.Grid.ResizeJustified(ref obstacles,
                                                             width * TexSize, height * TexSize, anchorDir.Reverse(), blockChangeOp, blocknewOp);

            foreach (GroundChar character in ZoneManager.Instance.CurrentGround.IterateCharacters())
            {
                Loc newLoc = character.MapLoc + texDiff * divSize;
                if (newLoc.X < 0)
                {
                    newLoc.X = 0;
                }
                else if (newLoc.X >= width)
                {
                    newLoc.X = width - 1;
                }
                if (newLoc.Y < 0)
                {
                    newLoc.Y = 0;
                }
                else if (newLoc.Y >= height)
                {
                    newLoc.Y = height - 1;
                }

                character.SetMapLoc(newLoc);
                character.UpdateFrame();
            }

            this.grid = new AABB.Grid(width, height, GraphicsManager.TileSize);
        }