Example #1
0
        void PostInit()
        {
            try
            {
                Rules = Ruleset.Load(modData, this, Tileset, RuleDefinitions, WeaponDefinitions,
                                     VoiceDefinitions, NotificationDefinitions, MusicDefinitions, SequenceDefinitions);
            }
            catch (Exception e)
            {
                InvalidCustomRules = true;
                Rules = Ruleset.LoadDefaultsForTileSet(modData, Tileset);
                Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message);
            }

            Rules.Sequences.Preload();

            var tl = new MPos(0, 0).ToCPos(this);
            var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);

            AllCells = new CellRegion(Grid.Type, tl, br);

            var btl = new PPos(Bounds.Left, Bounds.Top);
            var bbr = new PPos(Bounds.Right - 1, Bounds.Bottom - 1);

            SetBounds(btl, bbr);

            CustomTerrain = new CellLayer <byte>(this);
            foreach (var uv in AllCells.MapCoords)
            {
                CustomTerrain[uv] = byte.MaxValue;
            }

            AllEdgeCells = UpdateEdgeCells();
        }
Example #2
0
 public CellRegionEnumerator(CellRegion region)
     : this()
 {
     r = region;
     Reset();
     current = new MPos(u, v).ToCPos(r.gridType);
 }
Example #3
0
        void PostInit()
        {
            rules = Exts.Lazy(() =>
            {
                try
                {
                    return(Game.modData.RulesetCache.LoadMapRules(this));
                }
                catch (Exception e)
                {
                    InvalidCustomRules = true;
                    Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message);
                }

                return(Game.modData.DefaultRules);
            });

            cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]);

            var tl = Map.MapToCell(TileShape, new CPos(Bounds.Left, Bounds.Top));
            var br = Map.MapToCell(TileShape, new CPos(Bounds.Right - 1, Bounds.Bottom - 1));

            Cells = new CellRegion(TileShape, tl, br);

            CustomTerrain = new CellLayer <byte>(this);
            foreach (var cell in Cells)
            {
                CustomTerrain[cell] = byte.MaxValue;
            }
        }
Example #4
0
        /// <summary>Expand the specified region with an additional cordon. This may expand the region outside the map borders.</summary>
        public static CellRegion Expand(CellRegion region, int cordon)
        {
            var tl = new MPos(region.mapTopLeft.U - cordon, region.mapTopLeft.V - cordon).ToCPos(region.gridType);
            var br = new MPos(region.mapBottomRight.U + cordon, region.mapBottomRight.V + cordon).ToCPos(region.gridType);

            return(new CellRegion(region.gridType, tl, br));
        }
Example #5
0
        /// <summary>Expand the specified region with an additional cordon. This may expand the region outside the map borders.</summary>
        public static CellRegion Expand(CellRegion region, int cordon)
        {
            var offset = new CVec(cordon, cordon);
            var tl     = Map.MapToCell(region.shape, Map.CellToMap(region.shape, region.TopLeft) - offset);
            var br     = Map.MapToCell(region.shape, Map.CellToMap(region.shape, region.BottomRight) + offset);

            return(new CellRegion(region.shape, tl, br));
        }
Example #6
0
        public void ResizeCordon(int left, int top, int right, int bottom)
        {
            Bounds = Rectangle.FromLTRB(left, top, right, bottom);

            var tl = Map.MapToCell(TileShape, new CPos(Bounds.Left, Bounds.Top));
            var br = Map.MapToCell(TileShape, new CPos(Bounds.Right - 1, Bounds.Bottom - 1));

            Cells = new CellRegion(TileShape, tl, br);
        }
Example #7
0
        public Func <MPos, bool> ShroudObscuresTest(CellRegion region)
        {
            var rp = RenderPlayer;

            if (rp == null)
            {
                return(FalsePredicate);
            }
            var predicate = rp.Shroud.IsExploredTest(region);

            return(uv => !predicate(uv));
        }
Example #8
0
        public Func <CPos, bool> FogObscuresTest(CellRegion region)
        {
            var rp = RenderPlayer;

            if (rp == null)
            {
                return(FalsePredicate);
            }
            var predicate = rp.Shroud.IsVisibleTest(region);

            return(cell => !predicate(cell));
        }
Example #9
0
        void PostInit()
        {
            rules = Exts.Lazy(() =>
            {
                try
                {
                    return(Game.ModData.RulesetCache.Load(this));
                }
                catch (Exception e)
                {
                    InvalidCustomRules = true;
                    Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message);
                }

                return(Game.ModData.DefaultRules);
            });

            cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]);

            var tl = new MPos(0, 0).ToCPos(this);
            var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);

            AllCells = new CellRegion(Grid.Type, tl, br);

            var btl = new PPos(Bounds.Left, Bounds.Top);
            var bbr = new PPos(Bounds.Right - 1, Bounds.Bottom - 1);

            SetBounds(btl, bbr);

            CustomTerrain = new CellLayer <byte>(this);
            foreach (var uv in AllCells.MapCoords)
            {
                CustomTerrain[uv] = byte.MaxValue;
            }

            var leftDelta   = Grid.Type == MapGridType.RectangularIsometric ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0);
            var topDelta    = Grid.Type == MapGridType.RectangularIsometric ? new WVec(0, -512, 0) : new WVec(512, -512, 0);
            var rightDelta  = Grid.Type == MapGridType.RectangularIsometric ? new WVec(512, 0, 0) : new WVec(512, 512, 0);
            var bottomDelta = Grid.Type == MapGridType.RectangularIsometric ? new WVec(0, 512, 0) : new WVec(-512, 512, 0);

            CellCorners = CellCornerHalfHeights.Select(ramp => new WVec[]
            {
                leftDelta + new WVec(0, 0, 512 * ramp[0]),
                topDelta + new WVec(0, 0, 512 * ramp[1]),
                rightDelta + new WVec(0, 0, 512 * ramp[2]),
                bottomDelta + new WVec(0, 0, 512 * ramp[3])
            }).ToArray();
        }
Example #10
0
        void PostInit()
        {
            rules         = Exts.Lazy(() => Game.modData.RulesetCache.LoadMapRules(this));
            cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]);

            var tl = Map.MapToCell(TileShape, new CPos(Bounds.Left, Bounds.Top));
            var br = Map.MapToCell(TileShape, new CPos(Bounds.Right - 1, Bounds.Bottom - 1));

            Cells = new CellRegion(TileShape, tl, br);

            CustomTerrain = new CellLayer <int>(this);
            foreach (var cell in Cells)
            {
                CustomTerrain[cell] = -1;
            }
        }
Example #11
0
        public void Resize(int width, int height)                       // editor magic.
        {
            var oldMapTiles     = MapTiles.Value;
            var oldMapResources = MapResources.Value;
            var oldMapHeight    = MapHeight.Value;
            var newSize         = new Size(width, height);

            MapTiles     = Exts.Lazy(() => CellLayer.Resize(oldMapTiles, newSize, oldMapTiles[MPos.Zero]));
            MapResources = Exts.Lazy(() => CellLayer.Resize(oldMapResources, newSize, oldMapResources[MPos.Zero]));
            MapHeight    = Exts.Lazy(() => CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero]));
            MapSize      = new int2(newSize);

            var tl = new MPos(0, 0).ToCPos(this);
            var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);

            AllCells = new CellRegion(Grid.Type, tl, br);
        }
Example #12
0
        public void Resize(int width, int height)
        {
            var oldMapTiles     = Tiles;
            var oldMapResources = Resources;
            var oldMapHeight    = Height;
            var newSize         = new Size(width, height);

            Tiles     = CellLayer.Resize(oldMapTiles, newSize, oldMapTiles[MPos.Zero]);
            Resources = CellLayer.Resize(oldMapResources, newSize, oldMapResources[MPos.Zero]);
            Height    = CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero]);
            MapSize   = new int2(newSize);

            var tl = new MPos(0, 0);
            var br = new MPos(MapSize.X - 1, MapSize.Y - 1);

            AllCells = new CellRegion(Grid.Type, tl.ToCPos(this), br.ToCPos(this));
            SetBounds(new PPos(tl.U + 1, tl.V + 1), new PPos(br.U - 1, br.V - 1));
        }
Example #13
0
        public void SetBounds(MPos tl, MPos br)
        {
            // The tl and br coordinates are inclusive, but the Rectangle
            // is exclusive.  Pad the right and bottom edges to match.
            Bounds            = Rectangle.FromLTRB(tl.U, tl.V, br.U + 1, br.V + 1);
            CellsInsideBounds = new CellRegion(TileShape, tl.ToCPos(this), br.ToCPos(this));

            // Directly calculate the projected map corners in world units avoiding unnecessary
            // conversions.  This abuses the definition that the width of the cell is always
            // 1024 units, and that the height of two rows is 2048 for classic cells and 1024
            // for diamond cells.
            var wtop    = tl.V * 1024;
            var wbottom = (br.V + 1) * 1024;

            if (TileShape == TileShape.Diamond)
            {
                wtop    /= 2;
                wbottom /= 2;
            }

            ProjectedTopLeft     = new WPos(tl.U * 1024, wtop, 0);
            ProjectedBottomRight = new WPos(br.U * 1024 - 1, wbottom - 1, 0);
        }
Example #14
0
 public CellRegionEnumerator(CellRegion region)
 {
     r = region;
     Reset();
 }
Example #15
0
 public MapCoordsRegion(CellRegion region)
 {
     r = region;
 }
Example #16
0
 public bool Contains(CellRegion region)
 {
     return
         (TopLeft.X <= region.TopLeft.X && TopLeft.Y <= region.TopLeft.Y &&
          BottomRight.X >= region.BottomRight.X && BottomRight.Y >= region.BottomRight.Y);
 }
Example #17
0
 public MapCoordsEnumerator(CellRegion region)
     : this()
 {
     r = region;
     Reset();
 }