/// <summary> /// Called when a tourist needs to be generated and added to the palyer's inventory /// </summary> public void GenerateTourist() { //Get Player Character IPlayerCharacter playerCharacter = playerManager.PlayerCharacter; if (playerCharacter == null) { errorHandler.ReportError("Player character missing", ErrorState.restart_scene); return; } //Intantiate tourist GameObject touristObject = Instantiate(touristPrefab, new Vector3(0, 0, 0), Quaternion.identity); touristObject.transform.parent = inventoryUI.UIObject.transform; IInventoryTourist tourist = touristObject.GetComponent(typeof(IInventoryTourist)) as IInventoryTourist; if (tourist == null) { errorHandler.ReportError("Tourist component of tourist prefab missing", ErrorState.restart_scene); return; } //Give tourist its image tourist.InventoryIcon = Resources.Load <Sprite>(touristImageFiles[touristImageIndex]); touristImageIndex++; if (touristImageIndex >= NUMBER_OF_TOURIST_IMAGES) { touristImageIndex = 0; } //Add tourist to player's inventory playerCharacter.Inventory.AddItem(tourist, 0); //Check if a region switch is needed touristsInCurrentRegion++; int rand = Random.Range(MIN_TIME_IN_REGION, MAX_TIME_IN_REGION); if (touristsInCurrentRegion >= rand) { //Switch regions try { int newRegionNeighbourIndex = Random.Range(0, CurrentRegion.neighbouringRegions.Count - 1); CurrentRegion = CurrentRegion.neighbouringRegions[newRegionNeighbourIndex]; touristsInCurrentRegion = 0; } catch (System.Exception ex) { errorHandler.CatchException(ex, ErrorState.restart_scene); } } }
public bool SetDestination(IInventoryTourist tourist, TouristRegion touristRegion) { if (tourist == null) { errorHandler.ReportError("Unable to Set Tourist Destination.", ErrorState.restart_scene); return(false); } if (started == false) { Start(); } bool destinationSet = false; //Get possible Provinces List <int> provinceChoices = GetProvinceDestinations(touristRegion, touristManager.RecentProvinceDestinations); //Get possible Landmarks List <string> landmarkChoices = GetLandmarkDestinations(touristRegion, touristManager.RecentLandmarkDestinations); //Get possible Countries List <int> countryChoices = GetCountryDestinations(touristRegion, touristManager.RecentCountryDestinations); //Treat all three lists as a combined list and get a random number that points to an element from one of them destinationIndex = Random.Range(0, provinceChoices.Count + landmarkChoices.Count + countryChoices.Count); if (destinationIndex < provinceChoices.Count) { destinationSet = SetProvinceDestination(provinceChoices[destinationIndex], tourist); } else if ((destinationIndex >= provinceChoices.Count) && (destinationIndex < (landmarkChoices.Count + provinceChoices.Count))) { destinationIndex = destinationIndex - provinceChoices.Count; destinationSet = SetLandmarkDestination(landmarkChoices[destinationIndex], tourist); } else if (destinationIndex >= provinceChoices.Count + landmarkChoices.Count) { destinationIndex = destinationIndex - provinceChoices.Count - landmarkChoices.Count; destinationSet = SetCountryDestination(countryChoices[destinationIndex], tourist); } else { errorHandler.ReportError("Unable to Set Tourist Destination.", ErrorState.restart_scene); } return(destinationSet); }
/// <summary> /// Sets a tourists desired destination to a given country /// </summary> /// <param name="provinceIndex"> The country being set as the destination </param> /// <param name="tourist"> The tourist whose destination is being set </param> private bool SetCountryDestination(int countryIndex, IInventoryTourist tourist) { tourist.DestinationType = DestinationType.country; try { tourist.CountryDestination = worldMapGlobe.countries[countryIndex]; } catch { errorHandler.ReportError("Country does not exist", ErrorState.close_window); return(false); } tourist.DestinationName = tourist.CountryDestination.name; //Update List of Recent Country Destinations touristManager.RecentCountryDestinations.Insert(0, countryIndex); while (touristManager.RecentCountryDestinations.Count >= touristManager.TrackingTime) { touristManager.RecentCountryDestinations.RemoveAt(touristManager.TrackingTime - 1); } return(true); }
/// <summary> /// Sets a tourists desired destination to a given landmark /// </summary> /// <param name="landmark"> The landmark being set as the destination </param> /// <param name="tourist"> The tourist whose destination is being set </param> private bool SetLandmarkDestination(string landmark, IInventoryTourist tourist) { tourist.DestinationType = DestinationType.landmark; try { tourist.LandmarkDestination = landmarkManager.CulturalLandmarksByName[landmark]; } catch { errorHandler.ReportError(landmark + " does not exist", ErrorState.close_window); return(false); } tourist.DestinationName = tourist.LandmarkDestination.ObjectName; //Update List of Recent Landmark Destinations touristManager.RecentLandmarkDestinations.Insert(0, landmark); while (touristManager.RecentLandmarkDestinations.Count >= touristManager.TrackingTime) { touristManager.RecentLandmarkDestinations.RemoveAt(touristManager.TrackingTime - 1); } return(true); }
/// <summary> /// Sets a tourists desired destination to a given province /// </summary> /// <param name="provinceIndex"> The province being set as the destination </param> /// <param name="tourist"> The tourist whose destination is being set </param> private bool SetProvinceDestination(int provinceIndex, IInventoryTourist tourist) { tourist.DestinationType = DestinationType.province; try { tourist.ProvinceDestination = worldMapGlobe.provinces[provinceIndex]; } catch { errorHandler.ReportError("Error Setting Province Destination", ErrorState.close_window); return(false); } tourist.DestinationName = tourist.ProvinceDestination.name; //Update List of Recent Province Destinations touristManager.RecentProvinceDestinations.Insert(0, provinceIndex); while (touristManager.RecentProvinceDestinations.Count >= touristManager.TrackingTime) { touristManager.RecentProvinceDestinations.RemoveAt(touristManager.TrackingTime - 1); } return(true); }