Exemple #1
0
 public void UpdateWithMin(LocationPair loc)
 {
     if (!IsValid() || loc.Distance < Distance)
     {
         SetLocations(loc);
     }
 }
Exemple #2
0
        private LocationPair FindMinDistancePair(List <int> arr1, List <int> arr2)
        {
            if (arr1 == null || arr2 == null || arr1.Count == 0 || arr2.Count == 0)
            {
                return(null);
            }

            int          index1  = 0;
            int          index2  = 0;
            LocationPair best    = new LocationPair(arr1[0], arr2[0]);
            LocationPair current = new LocationPair(arr1[0], arr2[0]);

            while (index1 < arr1.Count && index2 < arr2.Count)
            {
                current.SetLocations(arr1[index1], arr2[index2]);
                best.UpdateWithMin(current);
                if (current.Location1 < current.Location2)
                {
                    index1++;
                }
                else
                {
                    index2++;
                }
            }

            return(best);
        }
Exemple #3
0
        public LocationPair TryToBuild(Int2 buildingSize)
        {
            if (!IsAvailableToBuild() || !IsAvailableToGrow())
            {
                return(null);
            }

            List <Direction> availableDirs = CanSplitIn();

            if (availableDirs.Count <= 0)
            {
                return(null);
            }

            LocationPair buildingBounds = null;

            foreach (Direction dir in availableDirs)
            {
                Tile toConsider = ground.getDirection(dir);
                buildingBounds = StructureBuilder.BoundsForStructure(toConsider, dir, buildingSize.x, buildingSize.y);

                if (buildingBounds != null)
                {
                    availableDepths[(int)(dir)] = buildingBounds.SpaceInDirection(dir);
                    break;
                }
            }

            return(buildingBounds);
        }
        public bool IsLocationIncludes(Bounds bounds, LocationPair innerLocation, double radius)
        {
            var middle   = GetMiddle(bounds);
            var distance = GetDistance(middle, innerLocation);

            return(distance < radius);
        }
    public Structure buildStructure(Road connectedTo, Direction directionFromRoad, Structure.Type givenType, int width, int depth)
    {
//		Debug.LogError("building " + givenType.ToString() + " to the " + directionFromRoad + " of " + connectedTo.foundation.ToS() + " with width " + width + " and depth " + depth);
        Tile targetDriveway = connectedTo.foundation.getDirection(directionFromRoad);
//		Debug.LogError("target driveway: " + targetDriveway.ToS() + " - " + targetDriveway.Loc().ToString());

        LocationPair locals = BoundsForStructure(targetDriveway, directionFromRoad, width, depth);

        return(buildStructure(connectedTo, directionFromRoad, givenType, locals));
    }
Exemple #6
0
        public LocationPair FindClosest(string[] words, string word1, string word2)
        {
            LocationPair best    = new LocationPair(-1, -1);
            LocationPair current = new LocationPair(-1, -1);

            for (int i = 0; i < words.Length; i++)
            {
                string word = words[i];
                if (word == word1)
                {
                    current.Location1 = i;
                    best.UpdateWithMin(current);
                }
                else if (word == word2)
                {
                    current.Location2 = i;
                    best.UpdateWithMin(current);
                }
            }

            return(best);
        }
    public Structure buildStructure(Road connectedTo, Direction directionFromRoad, Structure.Type givenType, LocationPair locals)
    {
        if (locals == null)
        {
            return(null);
        }

        Int2 localLowerLeft  = locals.lowerLeft;
        Int2 localUpperRight = locals.upperRight;

        int depth = locals.DistanceInDirection(directionFromRoad);

        //		Debug.LogError("local lower left: " + localLowerLeft.ToString());
        //		Debug.LogError("local upper right: " + localUpperRight.ToString());

        Int2 globalLowerLeft  = localLowerLeft;
        Int2 globalUpperRight = localUpperRight;

        switch (directionFromRoad)
        {
        case Direction.East:
            globalLowerLeft  = Directions.InDirectionForDistance(localUpperRight, Directions.oppositeOf(directionFromRoad), depth);
            globalUpperRight = Directions.InDirectionForDistance(localLowerLeft, directionFromRoad, depth);
            break;

        case Direction.South:
            globalLowerLeft  = localUpperRight;
            globalUpperRight = localLowerLeft;
            break;

        case Direction.West:
            globalUpperRight = Directions.InDirectionForDistance(localUpperRight, Directions.oppositeOf(directionFromRoad), depth);
            globalLowerLeft  = Directions.InDirectionForDistance(localLowerLeft, directionFromRoad, depth);
            break;
        }

        //		Debug.LogError("global lower left: " + globalLowerLeft.ToString());
        //		Debug.LogError("global upper right: " + globalUpperRight.ToString());

        Structure built = new Structure(connectedTo, directionFromRoad, givenType, globalLowerLeft, globalUpperRight);

        return(built);
    }
        private void UpdateMap()
        {
            if (_height > 1 && _width > 1 && _image != null)
            {
                int width  = (int)Math.Ceiling(_width);
                int height = (int)Math.Ceiling(_height);

                Point p = new Point(width, height);
                if (_requestedImages.Contains(p))
                {
                    return;
                }
                _requestedImages.Add(p);

                var format = StaticMapsUrlFormat;

                // This code is buggy on purpose, having been updated and
                // changed so many times. Ugh. Should rewrite.

                // This now supports not having a pushpin.
                LocationPair lp = PointOfInterest;
                LocationPair cp = lp;
                if (lp == null)
                {
                    // return;
                    format = format.Replace(PushPinFormat, string.Empty);
                    cp     = CenterPointIfAvailable;
                }

                //string format = StaticMapsUrlFormat;
                //LocationPair cp = CenterPointIfAvailable;
                //if (cp == null)
                {
                    // swap
                    //cp = lp;
                    //format = format.Replace(PushPinFormat, string.Empty);
                    //lp = null;
                }

                IAppInfo iai = Application.Current as IAppInfo;
                string   key = "";
                if (iai != null)
                {
                    key = iai.BKey;
                }

                if (cp == null)
                {
                    return;
                }

                Uri uri = new Uri(string.Format(
                                      CultureInfo.InvariantCulture,
                                      format,
                                      cp.Latitude,
                                      cp.Longitude,
                                      ZoomLevel,
                                      width,
                                      height,
                                      cp.Latitude,
                                      cp.Longitude,
                                      36,                                        // pin styles at http://msdn.microsoft.com/en-us/library/ff701719.aspx
                                      key
                                      ), UriKind.Absolute);

//#if DEBUG_STATIC_BING_MAPS
                System.Diagnostics.Debug.WriteLine("Getting a Bing map " + uri.ToString());
//#endif

                if (!SmoothlyFadeIn)
                {
                    _image.AreAnimationsEnabled = false;
                }

                _image.ImageSource = uri;
            }
            else
            {
#if DEBUG_STATIC_BING_MAPS
                Debug.WriteLine("Bing Maps: The image {2}, height {0}, and width {1} are not appropriate to display a map currently.", _height, _width, _image == null ? "null image" : "image exists in tree");
#endif
            }
        }
Exemple #9
0
 public void SetLocations(LocationPair loc)
 {
     SetLocations(loc.Location1, loc.Location2);
 }
Exemple #10
0
    private void HandleStructureRequest(StructureRequest request)
    {
        Debug.LogError("handling a structure request " + request.ToString());

        if (expandableRoads.Count <= 0)
        {
            return;
        }

        LocationPair bounds = null;

        Road            success  = null;
        List <RoadNode> toRemove = new List <RoadNode>();

        foreach (RoadNode toConsider in expandableRoads)
        {
            if (!toConsider.IsAvailable())
            {
                toRemove.Add(toConsider);
                continue;
            }

            bounds = toConsider.TryToBuild(request.size);
            if (bounds != null)
            {
                success = (Road)(toConsider.ground.Surface);
                break;
            }
        }

        foreach (RoadNode removed in toRemove)
        {
            expandableRoads.RemoveAll((elem) => (elem == removed));
        }

        if (bounds == null)
        {
            bool someoneChanged = false;
            foreach (RoadNode toGrow in expandableRoads)
            {
                RoadNode expanded = toGrow.Grow();
                if (expanded != null)
                {
                    expandableRoads.Add(expanded);
                    someoneChanged = true;
                    break;
                }
            }

            if (!someoneChanged)
            {
                foreach (RoadNode toSplit in expandableRoads)
                {
                    RoadNode split = toSplit.Split();
                    if (split != null)
                    {
                        expandableRoads.Add(split);
                        someoneChanged = true;
                        break;
                    }
                }
            }

            if (someoneChanged)
            {
                request.Reject();
            }
        }
        else
        {
//			buildStructure(Road connectedTo, Direction directionFromRoad, Structure.Type givenType, LocationPair locals)
            structurer.buildStructure(success, bounds.toHere, Structure.Type.House, bounds);
        }
    }
 public double GetDistance(LocationPair location, LocationPair innerLocation)
 {
     return(GetDistanceFromLatLonInKm(location.Latitude, location.Longitude, innerLocation.Latitude, innerLocation.Longitude));
 }