Exemplo n.º 1
0
        /// <summary>
        /// Create a ghost path to build a new section of path
        /// </summary>
        /// <param name="data"></param>
        public GhostPath(PathData data)
            : base(data)
        {
            this.startClickLocation = null;
            this.Position = Input.IsoWorld.Clone();

            this.segments = new List<PathSegment>();
            this.ghostCursor = new PathSegment(this.data, Input.IsoWorld);

            this.Position = Input.IsoWorld.Clone();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of a path on the world map
        /// </summary>
        /// <param name="position">Position of the building</param>
        /// <param name="segment">Segment information</param>
        public Path(PathSegment segment)
            : base(segment.WorldPosition.y)
        {
            this.segment = segment;

            this.Clickable = true;
            this.Position = segment.WorldPosition;
            this.Size = new Pair<int>(Constants.TILE_WIDTH, Constants.TILE_HEIGHT);

            this.DirtyPathBit = true;
            DirtySurroundingBits();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the list of path segments between two points
        /// This is not fast, it may need to be optimized later.
        /// </summary>
        /// <returns></returns>
        private List<PathSegment> GetPathSegments()
        {
            List<PathSegment> ret = new List<PathSegment>();
            var curSeg = new PathSegment(this.data, Input.IsoWorld.Clone());
            ret.Add(curSeg);

            this.segmentsValid = curSeg.IsValidSegment;

            if (Math.Abs(curSeg.WorldPosition.x - this.startClickLocation.x) % Path.dx[2] != 0 || Math.Abs(curSeg.WorldPosition.y - this.startClickLocation.y) % Path.dy[1] != 0)
            {
                Logger.Log(LogLevel.Error, "Bad snapping coordinates", string.Format("Very bad. Somehow the coordinates are not snapped to a grid! {0} -> {1}", curSeg.WorldPosition, this.startClickLocation));
            }

            while (!curSeg.WorldPosition.Equals(this.startClickLocation))
            {
                PathSegment nextSegment = null;
                double currentDist = Double.MaxValue; // Geometry.Dist(curSeg.WorldPosition, this.startClickLocation);

                for (int i = 0; i < Path.dx.Length; ++i)
                {
                    var newGridPosition = new Pair<int>(curSeg.WorldPosition.x + Path.dx[i], curSeg.WorldPosition.y + Path.dy[i]);
                    var newGridDist = Geometry.Dist(newGridPosition, this.startClickLocation);

                    if (newGridDist < currentDist)
                    {
                        nextSegment = new PathSegment(this.data, newGridPosition);
                        currentDist = newGridDist;
                    }
                }

                curSeg = nextSegment;
                ret.Add(curSeg);

                this.segmentsValid = this.segmentsValid && curSeg.IsValidSegment;
            }

            return ret;
        }