Example #1
0
        public Tile(Map Map, Coordinate Coordinate, TileRuleSet RuleSet, IdGenerator IdGenerator)
        {
            this.Map        = Map;
            this.Coordinate = Coordinate;
            this.RuleSet    = RuleSet;
            Id            = IdGenerator.GenerateId();
            HexCoordinate = new HexCoordinate(Coordinate);
            Bounds        = CalculateBounds();

            Configuration = new TileConfiguration();
            Rules         = new TileRulesCalculator(this);
            Configuration.OnReconfigure += (sender, e) => Rules.Recalculate();
        }
Example #2
0
        public Tile(SerializationInputStream Stream, Map Map, TileRuleSet RuleSet, IdGenerator IdGenerator)
        {
            this.Map      = Map;
            Coordinate    = new Coordinate(Stream);
            HexCoordinate = new HexCoordinate(Coordinate);
            Id            = IdGenerator.GenerateId();
            Configuration = new TileConfiguration(Stream);
            Bounds        = CalculateBounds();

            this.RuleSet = RuleSet;
            Rules        = new TileRulesCalculator(this);
            Configuration.OnReconfigure += (sender, e) => Rules.Recalculate();
        }
Example #3
0
        static Tile[] FindLOS(Map Map, HexCoordinate From, HexCoordinate To, bool Dither)
        {
            var count = From.Distance(To);
            var tiles = new Tile[count + 1];
            var step  = 1.0 / count;

            for (int i = 0; i < count + 1; ++i)
            {
                Coordinate c = HexCoordinate.Interpolate(From, To, step * i, Dither ? -.01 : 0).ToCoordinate();
                if (c.X < 0 || c.X >= Map.Tiles.GetLength(0) || c.Y < 0 || c.Y >= Map.Tiles.GetLength(1))
                {
                    return(null);
                }
                tiles[i] = Map.Tiles[c.X, c.Y];
            }
            return(tiles);
        }
Example #4
0
 public IEnumerable <LineOfSight> GetLinesOfSight(int Range, Tile Tile)
 {
     if (Tile != null)
     {
         for (int i = -Range; i <= Range; ++i)
         {
             for (int j = Math.Max(-Range, -(i + Range)); j <= Math.Min(Range, Range - i); ++j)
             {
                 HexCoordinate p = Tile.HexCoordinate;
                 var           c = new HexCoordinate(p.X + i, p.Y + j, p.Z - i - j).ToCoordinate();
                 if (c.X >= 0 && c.X < Tile.Map.Tiles.GetLength(0) &&
                     c.Y >= 0 && c.Y < Tile.Map.Tiles.GetLength(1))
                 {
                     yield return(GetLineOfSight(Tile, Tile.Map.Tiles[c.X, c.Y]));
                 }
             }
         }
     }
 }
 public int Distance(HexCoordinate To)
 {
     return(Math.Max(Math.Abs(X - To.X), Math.Max(Math.Abs(Y - To.Y), Math.Abs(Z - To.Z))));
 }
 public static HexCoordinate Interpolate(HexCoordinate c1, HexCoordinate c2, double t, double Dither = 0)
 {
     return(Round(c1.X * (1 - t) + c2.X * t, c1.Y * (1 - t) + c2.Y * t, c1.Z * (1 - t) + c2.Z * t, Dither));
 }
Example #7
0
 public Coordinate(HexCoordinate From)
 {
     X = From.X + (From.Z + 1) / 2;
     Y = From.Z;
 }