Пример #1
0
        /// <summary>
        /// Check if a given location is a correct drop off location given a desired landmark
        /// </summary>
        /// <param name="dropOffCell"> The cell drop off cell </param>
        /// <param name="landmarkDestination"> The desired landmark destination </param>
        private bool AttemptLandmarkDropOff(Cell dropOffCell, Landmark landmarkDestination)
        {
            bool dropOffSuccess = false;

            if (landmarkDestination == null)
            {
                errorHandler.ReportError("Drop Off Failed: Landmark destination not set", ErrorState.close_window);
                return(false);
            }

            if (landmarkDestination.CellLocation == null)
            {
                errorHandler.ReportError("Drop Off Failed: Landmark destination's cell location not set", ErrorState.close_window);
                return(false);
            }

            if (dropOffCell == landmarkDestination.CellLocation)
            {
                dropOffSuccess = true;
            }
            else
            {
                Cell[] selectedCellNeighbours = worldMapGlobe.GetCellNeighbours(dropOffCell.index);
                foreach (Cell cell in selectedCellNeighbours)
                {
                    if (cell == landmarkDestination.CellLocation)
                    {
                        dropOffSuccess = true;
                        break;
                    }
                }
            }

            return(dropOffSuccess);
        }
        /// <summary>
        /// Set the terrain costs of all the cells that are reachable by the player
        /// </summary>
        public void SetCellCosts()
        {
            if (CellsInRange == null)
            {
                errorHandler.ReportError("Cells in range empty", ErrorState.restart_scene);
                return;
            }
            foreach (Cell cell in CellsInRange[0])
            {
                try
                {
                    //Get Climate From Cell
                    int      provinceIndex    = worldMapGlobe.GetProvinceNearPoint(cell.sphereCenter);
                    Province province         = worldMapGlobe.provinces[provinceIndex];
                    string   climateAttribute = province.attrib["ClimateGroup"];

                    //Loop Through Each Neighbor and Set the Cost from the Neighbor to the Cell
                    if (climateAttribute != "")
                    {
                        bool cellOccupied = false;
                        //Check if cell is occupied by something other than the player
                        if (cell.occupants.Any() && !cell.occupants.Contains(playerCharacter))
                        {
                            cellOccupied = true;
                        }
                        int cost = playerCharacter.ClimateCosts[climateAttribute];
                        if (cost == IMPASSABLE || cellOccupied)
                        {
                            worldMapGlobe.SetCellCanCross(cell.index, false);
                        }
                        else
                        {
                            worldMapGlobe.SetCellCanCross(cell.index, true);
                            foreach (Cell neighbour in worldMapGlobe.GetCellNeighbours(cell.index))
                            {
                                worldMapGlobe.SetCellNeighbourCost(neighbour.index, cell.index, cost, false);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    errorHandler.CatchException(ex, ErrorState.close_window);
                }
            }
        }