Example #1
0
        public Location(Map map, Point position)
        {
            Map = map
#if DEBUG
                  ?? throw new ArgumentNullException(nameof(map))
#endif
            ;
            Position = position;
        }
Example #2
0
        private Direction(int index, string name, Point vector)
        {
            Index  = (sbyte)index;
            m_Name = name;
            Vector = vector;
            float num = (float)Math.Sqrt((double)(vector.X * vector.X + vector.Y * vector.Y));

            NormalizedVector = num != 0.0f ? new PointF((float)vector.X / num, (float)vector.Y / num) : PointF.Empty;
        }
Example #3
0
        public Location(Map map, Point position)
        {
#if DEBUG
            if (null == map)
            {
                throw new ArgumentNullException(nameof(map));
            }
#endif
            Map      = map;
            Position = position;
        }
Example #4
0
 public static Direction FromVector(Point v)
 {
     foreach (Direction direction in COMPASS)
     {
         if (direction.Vector == v)
         {
             return(direction);
         }
     }
     return(null);
 }
Example #5
0
        public static Direction ApproximateFromVector(Point v)
        {
            PointF pointF = new PointF(v.X, v.Y);
            float  num1   = (float)Math.Sqrt((double)pointF.X * (double)pointF.X + (double)pointF.Y * (double)pointF.Y);

            if ((double)num1 == 0.0)
            {
                return(N);
            }
            pointF.X /= num1;
            pointF.Y /= num1;
            Direction dir = COMPASS.Minimize(d => Math.Abs(pointF.X - d.NormalizedVector.X) + Math.Abs(pointF.Y - d.NormalizedVector.Y));

            return(dir ?? N);
        }
Example #6
0
        public District this[Point pt]
        {
            get {
#if DEBUG
                if (!InBounds(pt))
                {
                    throw new InvalidOperationException("not in bounds");
                }
#endif
                return(m_DistrictsGrid[pt.X, pt.Y]);
            }
            set {
#if DEBUG
                if (!InBounds(pt))
                {
                    throw new InvalidOperationException("not in bounds");
                }
#endif
                m_DistrictsGrid[pt.X, pt.Y] = value;
            }
        }
Example #7
0
 public District?At(Point pt)
 {
     return(InBounds(pt) ? m_DistrictsGrid[pt.X, pt.Y] : null);
 }
Example #8
0
 public bool InBounds(Point pt)
 {
     return(0 <= pt.X && m_Size > pt.X && 0 <= pt.Y && m_Size > pt.Y);
 }
Example #9
0
        public uint SubwayLayout(Point pos)
        {
            if (40 > Engine.RogueGame.Options.DistrictSize)
            {
                return(0);                                      // 30 is known to be impossible to get a subway station.  40 is ok
            }
            // precompute some line segments
            const uint E_W       = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint N_S       = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.S;
            const uint N_E       = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.E;
            const uint N_W       = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint S_E       = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.S;
            const uint S_W       = (uint)Compass.XCOMlike.S * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint N_NEUTRAL = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint E_NEUTRAL = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint S_NEUTRAL = (uint)Compass.XCOMlike.S * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint W_NEUTRAL = (uint)Compass.XCOMlike.W * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint FOUR_WAY  = N_S * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_W;
            const uint N_TEE     = N_NEUTRAL * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_W;
            const uint S_TEE     = S_NEUTRAL * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_W;
            const uint E_TEE     = N_S * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_NEUTRAL;
            const uint W_TEE     = N_S * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + W_NEUTRAL;

            if (0 == pos.Y)
            {
                if (0 == pos.X)
                {
                    return(S_E);
                }
                else if (Size / 2 == pos.X)
                {
                    return(S_TEE);
                }
                else if (Size - 1 == pos.X)
                {
                    return(S_W);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (Size / 2 == pos.Y)
            {
                if (0 == pos.X)
                {
                    return(E_TEE);
                }
                else if (Size / 2 == pos.X)
                {
                    return(FOUR_WAY);
                }
                else if (Size - 1 == pos.X)
                {
                    return(W_TEE);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (Size - 1 == pos.Y)
            {
                if (0 == pos.X)
                {
                    return(N_E);
                }
                else if (Size / 2 == pos.X)
                {
                    return(N_TEE);
                }
                else if (Size - 1 == pos.X)
                {
                    return(N_W);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (0 == pos.X)
            {
                return(N_S);
            }
            else if (Size / 2 == pos.X)
            {
                return(N_S);
            }
            else if (Size - 1 == pos.X)
            {
                return(N_S);
            }
            return(0); // any valid layout will have at least one line segment and thus be non-zero
        }
Example #10
0
        public void ForceKnown(Point x) // for world creation
        {
            var map = m_Actor.Location.Map;

            ItemMemory?.Set(new Location(map, x), null, map.LocalTime.TurnCounter);
        }
Example #11
0
 public Location_stack_r(Map m, Point pos)
 {
     Map_code = m.encode();
     Position = pos;
 }
Example #12
0
 public int fromWorldPos(Point pt)
 {
     return(pt.X + m_Size * pt.Y);
 }
Example #13
0
        public uint HighwayLayout(Point pos)
        {
            // precompute some line segments (must agree with BaseTownGenerator::NewSurfaceBlocks)
            const uint E_W      = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint N_S      = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.S;
            const uint N_E      = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.E;
            const uint N_W      = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint S_E      = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.S;
            const uint S_W      = (uint)Compass.XCOMlike.S * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint FOUR_WAY = N_S * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_W; // not quite right but we can counter-adjust later

            // map generation, so doesn't have to be fast
            var tl_highway  = CHAR_CityLimits.Location + Direction.NW;
            var br_highway  = CHAR_CityLimits.Location + CHAR_CityLimits.Size;
            var mid_highway = CHAR_CityLimits.Location + CHAR_CityLimits.Size / 2;

            if (tl_highway.Y == pos.Y)
            {
                if (tl_highway.X == pos.X)
                {
                    return(S_E);
                }
                else if (br_highway.X == pos.X)
                {
                    return(S_W);
                }
                else if (mid_highway.X == pos.X)
                {
                    return(FOUR_WAY);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (br_highway.Y == pos.Y)
            {
                if (tl_highway.X == pos.X)
                {
                    return(N_E);
                }
                else if (br_highway.X == pos.X)
                {
                    return(N_W);
                }
                else if (mid_highway.X == pos.X)
                {
                    return(FOUR_WAY);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (tl_highway.X == pos.X)
            {
                return((mid_highway.Y == pos.Y) ? FOUR_WAY : N_S);
            }
            else if (br_highway.X == pos.X)
            {
                return((mid_highway.Y == pos.Y) ? FOUR_WAY : N_S);
            }
            return(0); // any valid layout will have at least one line segment and thus be non-zero
        }
Example #14
0
        public uint SubwayLayout(Point pos)
        {
            if (40 > Engine.RogueGame.Options.DistrictSize)
            {
                return(0);                                      // 30 is known to be impossible to get a subway station.  40 is ok
            }
            if (!CHAR_CityLimits.Contains(pos))
            {
                return(0);                          // no subway outside of city limits.
            }
            // precompute some line segments
            const uint E_W       = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint N_S       = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.S;
            const uint N_E       = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.E;
            const uint N_W       = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint S_E       = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.S;
            const uint S_W       = (uint)Compass.XCOMlike.S * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.XCOMlike.W;
            const uint N_NEUTRAL = (uint)Compass.XCOMlike.N * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint E_NEUTRAL = (uint)Compass.XCOMlike.E * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint S_NEUTRAL = (uint)Compass.XCOMlike.S * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint W_NEUTRAL = (uint)Compass.XCOMlike.W * (uint)Compass.reference.XCOM_EXT_STRICT_UB + (uint)Compass.reference.NEUTRAL;
            const uint FOUR_WAY  = N_S * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_W;
            const uint N_TEE     = N_NEUTRAL * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_W;
            const uint S_TEE     = S_NEUTRAL * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_W;
            const uint E_TEE     = N_S * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + E_NEUTRAL;
            const uint W_TEE     = N_S * (uint)Compass.reference.XCOM_LINE_SEGMENT_UB + W_NEUTRAL;

            // map generation, so doesn't have to be fast
            var tl_city  = CHAR_CityLimits.Location;
            var br_city  = CHAR_CityLimits.Location + CHAR_CityLimits.Size + Direction.NW;
            var mid_city = CHAR_CityLimits.Location + CHAR_CityLimits.Size / 2;

            if (tl_city.Y == pos.Y)
            {
                if (tl_city.X == pos.X)
                {
                    return(S_E);
                }
                else if (mid_city.X == pos.X)
                {
                    return(S_TEE);
                }
                else if (br_city.X == pos.X)
                {
                    return(S_W);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (mid_city.Y == pos.Y)
            {
                if (tl_city.X == pos.X)
                {
                    return(E_TEE);
                }
                else if (mid_city.X == pos.X)
                {
                    return(FOUR_WAY);
                }
                else if (br_city.X == pos.X)
                {
                    return(W_TEE);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (br_city.Y == pos.Y)
            {
                if (tl_city.X == pos.X)
                {
                    return(N_E);
                }
                else if (mid_city.X == pos.X)
                {
                    return(N_TEE);
                }
                else if (br_city.X == pos.X)
                {
                    return(N_W);
                }
                else
                {
                    return(E_W);
                }
            }
            else if (tl_city.X == pos.X)
            {
                return(N_S);
            }
            else if (mid_city.X == pos.X)
            {
                return(N_S);
            }
            else if (br_city.X == pos.X)
            {
                return(N_S);
            }
            return(0); // any valid layout will have at least one line segment and thus be non-zero
        }
Example #15
0
 public MapCode(Point k, short v)
 {
     Key   = k;
     Value = v;
 }