Пример #1
0
        /// <summary>
        /// Looks for a random cell which is visible.
        /// </summary>
        int GetRandomVisibleCellIndex()
        {
            Vector3 pos       = Random.onUnitSphere * 0.5f;
            int     cellIndex = map.GetCellIndex(pos);

            return(cellIndex);
        }
Пример #2
0
        public void IntantiateMappables(Country country)
        {
            if (!started)
            {
                Start();
            }

            List <MountPoint> countryMountPoints = new List <MountPoint>();

            try
            {
                int countryIndex    = worldMapGlobe.GetCountryIndex(country.name);
                int mountPointCount = worldMapGlobe.GetMountPoints(countryIndex, countryMountPoints);
            }
            catch
            {
                errorHandler.ReportError("Failed to load country's mount points", ErrorState.restart_scene);
                return;
            }

            foreach (MountPoint mountPoint in countryMountPoints)
            {
                if (mountPoint.type == START_POINT && mountPoint.provinceIndex == worldMapGlobe.GetProvinceIndex(startingCountry, startingProvince))
                {
                    int startingCellIndex = worldMapGlobe.GetCellIndex(mountPoint.localPosition);
                    if (startingCellIndex < 0 || startingCellIndex > worldMapGlobe.cells.Length)
                    {
                        errorHandler.ReportError("Invalid starting mount point", ErrorState.restart_scene);
                    }
                    else
                    {
                        Cell startingCell       = worldMapGlobe.cells[startingCellIndex];
                        bool playerInstantiated = playerManager.IntantiatePlayer(startingCell);
                    }
                }
                if (mountPoint.type == CULTURAL_POINT) //&& loadedMapSettings.culturalLandmarks)
                {
                    LandmarkManager.InstantiateCulturalLandmark(mountPoint);
                }
            }
        }
Пример #3
0
 public void Update()
 {
     if (Auto)
     {
         MoveTo(currentProgress);
         currentProgress += MOVE_SPEED;
         if (currentProgress > 1f)
         {
             latlonIndex++;
             if (latlonIndex >= latLon.Count || latlonIndex < 0)
             {
                 errorHandler.ReportError("Attempted to move to invalid latlon", ErrorState.close_window);
                 return;
             }
             int newCell = worldMapGlobe.GetCellIndex(latLon[latlonIndex]);
             AnimatedObject.UpdateLocation(newCell);
             currentProgress = 0;
             if (latlonIndex >= latLon.Count - 1 || Stop)
             {
                 StopMovement();
             }
         }
     }
 }
        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);
        }
Пример #5
0
        public List <Province> GetProvicesInCell(Cell cell)
        {
            List <Province> foundProvinces   = new List <Province>();
            List <Province> checkedProvinces = new List <Province>();
            int             provinceIndex;

            try
            {
                //Create a list of points including each vertex of the cell and its center point
                List <Vector3> cellPoints = cell.vertices.ToList();
                cellPoints.Add(cell.sphereCenter);

                foreach (Vector3 cellPoint in cellPoints)
                {
                    provinceIndex = worldMapGlobe.GetProvinceIndex(cellPoint);
                    //Check if cell point is on a province
                    if (provinceIndex == -1)
                    {
                        //Get closest province to point if it is not centered on one
                        provinceIndex = worldMapGlobe.GetProvinceNearPoint(cellPoint);
                    }
                    //Add the province, if it is not already in the province list
                    Province province = worldMapGlobe.provinces[provinceIndex];
                    if (!foundProvinces.Contains(province))
                    {
                        foundProvinces.Add(province);
                    }

                    //Check to see if neighbours of province overlap with cell
                    List <Province> provinceNeighbours = worldMapGlobe.ProvinceNeighbours(provinceIndex);
                    bool            provinceOverlaps;
                    foreach (Province neighbor in provinceNeighbours)
                    {
                        //countryIndex = neighbor.countryIndex;
                        //neighborIndex = worldMapGlobe.GetProvinceIndex(countryIndex, neighbor.name);

                        //Make sure you haven't already checked the province, this saves time
                        if (!checkedProvinces.Contains(neighbor))
                        {
                            checkedProvinces.Add(neighbor);
                            provinceOverlaps = false;

                            foreach (Region region in neighbor.regions)
                            {
                                foreach (Vector3 spherePoint in region.spherePoints)
                                {
                                    if (worldMapGlobe.GetCellIndex(spherePoint) == cell.index)
                                    {
                                        provinceOverlaps = true;
                                        break;
                                    }
                                }
                                if (provinceOverlaps)
                                {
                                    break;
                                }
                            }
                            if (provinceOverlaps && !foundProvinces.Contains(province))
                            {
                                foundProvinces.Add(neighbor);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                errorHandler.CatchException(ex, ErrorState.close_window);
                return(null);
            }

            return(foundProvinces);
        }