public void MountPointSelect()
        {
            if (mountPointIndex < 0 || mountPointIndex > map.mountPoints.Count)
            {
                return;
            }

            // If no country is selected (the mount point could be at sea) select it
            MountPoint mp             = map.mountPoints[mountPointIndex];
            int        mpCountryIndex = mp.countryIndex;

            if (mpCountryIndex < 0)
            {
                SetInfoMsg("Country not found in this country file.");
            }

            if (countryIndex != mpCountryIndex && mpCountryIndex >= 0)
            {
                ClearSelection();
                countryIndex       = mpCountryIndex;
                countryRegionIndex = map.countries[countryIndex].mainRegionIndex;
                CountryRegionSelect();
            }

            // Just in case makes GUICountryIndex selects appropiate value in the combobox
            GUIMountPointName = mp.name;
            SyncGUIMountPointSelection();
            if (mountPointIndex >= 0)
            {
                GUIMountPointNewName = mp.name;
                GUIMountPointNewType = mp.type.ToString();
                MountPointHighlightSelection();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of mount points that are visible (front facing camera)
        /// </summary>
        public List <MountPoint> GetVisibleMountPoints()
        {
            List <MountPoint> vc = new List <MountPoint>(30);

            if (mountPoints == null)
            {
                return(null);
            }
            for (int k = 0; k < mountPoints.Count; k++)
            {
                MountPoint mp = mountPoints[k];

                // Check if city is facing camera
                Vector3 center = transform.TransformPoint(mp.unitySphereLocation);
                Vector3 dir    = center - transform.position;
                float   d      = Vector3.Dot(Camera.main.transform.forward, dir);
                if (d < -0.2f)
                {
                    // Check if city is inside viewport
                    Vector3 vpos = Camera.main.WorldToViewportPoint(center);
                    if (vpos.x >= 0 && vpos.x <= 1 && vpos.y >= 0 && vpos.y <= 1)
                    {
                        vc.Add(mp);
                    }
                }
            }
            return(vc);
        }
Esempio n. 3
0
        public MountPoint Clone()
        {
            // Clone dictionary
            Dictionary <string, string> tags = new Dictionary <string, string>(customTags.Count, customTags.Comparer);

            foreach (KeyValuePair <string, string> entry in customTags)
            {
                tags.Add(entry.Key, (string)entry.Value.Clone());
            }
            MountPoint c = new MountPoint(name, countryIndex, provinceIndex, unitySphereLocation, type, tags);

            return(c);
        }
Esempio n. 4
0
        /// <summary>
        /// Redraws the mounts points but only in editor time. This is automatically called by Redraw(). Used internally by the Map Editor. You should not need to call this method directly.
        /// </summary>
        public void DrawMountPoints()
        {
            // Create mount points layer
            Transform t = transform.Find(MOUNT_POINTS_LAYER);

            if (t != null)
            {
                DestroyImmediate(t.gameObject);
            }
            if (Application.isPlaying || mountPoints == null)
            {
                return;
            }

            mountPointsLayer = new GameObject(MOUNT_POINTS_LAYER);
            mountPointsLayer.transform.SetParent(transform, false);
            mountPointsLayer.layer = gameObject.layer;
            if (_earthInvertedMode)
            {
                mountPointsLayer.transform.localScale *= 0.99f;
            }

            // Draw mount points marks
            int mountPointCount = mountPoints.Count;

            for (int k = 0; k < mountPointCount; k++)
            {
                MountPoint mp    = mountPoints [k];
                GameObject mpObj = Instantiate(mountPointSpot);
                mpObj.name = k.ToString();
                mpObj.transform.position = transform.TransformPoint(mp.unitySphereLocation);
                if (_earthInvertedMode)
                {
                    mpObj.transform.LookAt(transform.position + mp.unitySphereLocation * 2);
                }
                else
                {
                    mpObj.transform.LookAt(transform.position);
                }
                mpObj.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy;
                mpObj.transform.SetParent(mountPointsLayer.transform, true);
            }

            MountPointScaler mpScaler = mountPointsLayer.GetComponent <MountPointScaler> () ?? mountPointsLayer.AddComponent <MountPointScaler> ();

            mpScaler.map = this;
            mpScaler.ScaleMountPoints();
        }
        public bool MountPointAddNewTag()
        {
            if (mountPointIndex < 0)
            {
                return(false);
            }
            MountPoint mp = map.mountPoints[mountPointIndex];

            if (!mp.customTags.ContainsKey(GUIMountPointNewTagKey))
            {
                mp.customTags.Add(GUIMountPointNewTagKey, GUIMountPointNewTagValue);
                GUIMountPointNewTagKey   = "";
                GUIMountPointNewTagValue = "";
                mountPointChanges        = true;
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        bool GetMountPointUnderMouse(int countryIndex, Vector3 localPoint, out int mountPointIndex)
        {
            float hitPrecission = MOUNT_POINT_HIT_PRECISION * _cityIconSize * 5.0f;

            for (int c = 0; c < mountPoints.Count; c++)
            {
                MountPoint mp = mountPoints[c];
                if (mp.countryIndex == countryIndex)
                {
                    if ((mp.unitySphereLocation - localPoint).magnitude < hitPrecission)
                    {
                        mountPointIndex = c;
                        return(true);
                    }
                }
            }
            mountPointIndex = -1;
            return(false);
        }
        /// <summary>
        /// Exports the geographic data in packed string format.
        /// </summary>
        public string GetMountPointsGeoData()
        {
            StringBuilder sb = new StringBuilder();

            for (int k = 0; k < map.mountPoints.Count; k++)
            {
                MountPoint mp = map.mountPoints[k];
                if (k > 0)
                {
                    sb.Append("|");
                }
                sb.Append(mp.name + "$");
                string province = "";
                if (mp.provinceIndex >= 0 && mp.provinceIndex < map.provinces.Length)
                {
                    province = map.provinces[mp.provinceIndex].name;
                }
                string country = "";
                if (mp.countryIndex >= 0 && mp.countryIndex < map.countries.Length)
                {
                    country = map.countries[mp.countryIndex].name;
                }
                sb.Append(province + "$");
                sb.Append(country + "$");
                sb.Append(mp.type + "$");
                sb.Append((int)(mp.unitySphereLocation.x * WorldMapGlobe.MAP_PRECISION) + "$");
                sb.Append((int)(mp.unitySphereLocation.y * WorldMapGlobe.MAP_PRECISION) + "$");
                sb.Append((int)(mp.unitySphereLocation.z * WorldMapGlobe.MAP_PRECISION) + "$");
                int tc = 0;
                foreach (string key in mp.customTags.Keys)
                {
                    if (tc++ > 0)
                    {
                        sb.Append("$");
                    }
                    sb.Append(key);
                    sb.Append("&");
                    sb.Append(mp.customTags[key]);
                }
            }
            return(sb.ToString());
        }
        /// <summary>
        /// Adds a new mount point to current country.
        /// </summary>
        public void MountPointCreate(Vector3 newPoint)
        {
            if (countryIndex < 0)
            {
                return;
            }
            GUIMountPointName = "New Mount Point " + (map.mountPoints.Count + 1);
            newPoint          = newPoint.normalized * 0.5f;
            MountPoint newMountPoint = new MountPoint(GUIMountPointName, countryIndex, provinceIndex, newPoint);

            if (map.mountPoints == null)
            {
                map.mountPoints = new List <MountPoint>();
            }
            map.mountPoints.Add(newMountPoint);
            map.DrawMountPoints();
            lastMountPointCount = -1;
            ReloadMountPointNames();
            mountPointChanges = true;
        }
Esempio n. 9
0
        /// <summary>
        /// Reads the mount points data from a packed string.
        /// </summary>
        void ReadMountPointsPackedString(string s)
        {
            string[] mountPointsList  = s.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            int      mountPointsCount = mountPointsList.Length;

            mountPoints = new List <MountPoint> (mountPointsCount);

            for (int k = 0; k < mountPointsCount; k++)
            {
                string[] mountPointInfo = mountPointsList [k].Split(new char[] { '$' });
                string   name           = mountPointInfo [0];
                string   country        = mountPointInfo [2];
                int      countryIndex   = GetCountryIndex(country);
                if (countryIndex >= 0)
                {
                    string province                  = mountPointInfo [1];
                    int    provinceIndex             = GetProvinceIndex(countryIndex, province);
                    int    type                      = int.Parse(mountPointInfo [3]);
                    float  x                         = float.Parse(mountPointInfo [4]) / MAP_PRECISION;
                    float  y                         = float.Parse(mountPointInfo [5]) / MAP_PRECISION;
                    float  z                         = float.Parse(mountPointInfo [6]) / MAP_PRECISION;
                    Dictionary <string, string> tags = new Dictionary <string, string>();
                    for (int t = 7; t < mountPointInfo.Length; t++)
                    {
                        string   tag     = mountPointInfo[t];
                        string[] tagInfo = tag.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                        if (tagInfo != null && tagInfo.Length > 1)
                        {
                            string key   = tagInfo[0];
                            string value = tagInfo[1];
                            if (!tags.ContainsKey(key))
                            {
                                tags.Add(key, value);
                            }
                        }
                    }
                    MountPoint mountPoint = new MountPoint(name, countryIndex, provinceIndex, new Vector3(x, y, z), type, tags);
                    mountPoints.Add(mountPoint);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Returns a list of mount points that are visible and located inside the rectangle defined by two given sphere points
        /// </summary>
        public List <MountPoint> GetVisibleMountPoints(Vector3 rectTopLeft, Vector3 rectBottomRight)
        {
            Vector2 latlon0, latlon1;

            latlon0 = Conversion.GetBillboardPosFromSpherePoint(rectTopLeft);
            latlon1 = Conversion.GetBillboardPosFromSpherePoint(rectBottomRight);
            Rect rect = new Rect(latlon0.x, latlon1.y, latlon1.x - latlon0.x, latlon0.y - latlon1.y);
            List <MountPoint> selectedMountPoints = new List <MountPoint>();

            int mpCount = mountPoints.Count;

            for (int k = 0; k < mpCount; k++)
            {
                MountPoint mp   = mountPoints[k];
                Vector2    bpos = Conversion.GetBillboardPosFromSpherePoint(mp.unitySphereLocation);
                if (rect.Contains(bpos))
                {
                    selectedMountPoints.Add(mp);
                }
            }
            return(selectedMountPoints);
        }
        public bool InstantiateCulturalLandmark(MountPoint mountPoint)
        {
            if (!started)
            {
                Start();
            }

            string mountPointName = mountPoint.name;

            if (mountPointName == null)
            {
                errorHandler.ReportError("Cultural mount point name missing", ErrorState.close_window);
                return(false);
            }

            string tempName = mountPointName.Replace("The", "");

            tempName = tempName.Replace(" ", "");
            var model = Resources.Load <GameObject>(landmarkFilePath + tempName);

            if (model == null)
            {
                errorHandler.ReportError("Unable to load cultural landmark model", ErrorState.close_window);
                return(false);
            }

            var modelClone = Instantiate(model);

            if (modelClone == null)
            {
                errorHandler.ReportError("Failed to instantiate " + mountPointName, ErrorState.close_window);
                return(false);
            }

            Landmark landmarkComponent = modelClone.GetComponent(typeof(Landmark)) as Landmark;

            if (landmarkComponent == null)
            {
                errorHandler.ReportError(mountPointName + " landmark component missing", ErrorState.close_window);
                return(false);
            }

            landmarkComponent.MountPoint = mountPoint;
            landmarkComponent.ObjectName = mountPointName;
            landmarkComponent.CellIndex  = worldMapGlobe.GetCellIndex(mountPoint.localPosition);
            if (landmarkComponent.CellIndex < 0 || landmarkComponent.CellIndex > worldMapGlobe.cells.Length)
            {
                errorHandler.ReportError("Invalid cell index for " + mountPointName, ErrorState.close_window);
                return(false);
            }

            landmarkComponent.CellLocation          = worldMapGlobe.cells[landmarkComponent.CellIndex];
            landmarkComponent.CellLocation.canCross = false;
            worldMapGlobe.AddMarker(modelClone, mountPoint.localPosition, 0.001f, false, -5.0f, true, true);
            landmarkComponent.CellLocation.occupants.Add(landmarkComponent);
            string landmarkID = landmarkComponent.GetInstanceID().ToString();

            mappablesManager.MappedObjects.Add(landmarkID, landmarkComponent);
            CulturalLandmarks.Add(landmarkID, landmarkComponent);
            CulturalLandmarksByName.Add(landmarkComponent.ObjectName, landmarkComponent);

            return(true);
        }