public static float GetDepth(string city, float duration, float targetIntensity)
        {
            DepthDurationFrequencyIO instance = DepthDurationFrequencyIO.instance;

            if (instance.DDFAtlas.ContainsKey(city))
            {
                float[,] DDFmatrix = instance.DDFAtlas[city];
                float returnPeriodIndex = instance.GetReturnPeriodIndex(targetIntensity);
                float durationIndex     = instance.GetDurationIndex(duration);
                if (returnPeriodIndex >= 0f && durationIndex >= 0f)
                {
                    int   returnPeriodIndexFloor      = (int)Math.Floor(returnPeriodIndex);
                    float returnPeriodIndexPercentage = returnPeriodIndex - (float)returnPeriodIndexFloor;
                    int   returnPeriodIndexCeil       = (int)Math.Ceiling(returnPeriodIndex);
                    int   durationIndexFloor          = (int)Math.Floor(durationIndex);
                    float durationIndexPercentage     = durationIndex - (float)durationIndexFloor;
                    int   durationIndexCeil           = (int)Math.Ceiling(durationIndex);
                    float[,] depths = { { DDFmatrix[durationIndexFloor, returnPeriodIndexFloor], DDFmatrix[durationIndexFloor, returnPeriodIndexCeil] },
                                        { DDFmatrix[durationIndexCeil,  returnPeriodIndexFloor], DDFmatrix[durationIndexCeil,  returnPeriodIndexCeil] } };

                    float depthAtDurationFloor = Mathf.Lerp(depths[0, 0], depths[0, 1], returnPeriodIndexPercentage);
                    float depthAtDurationCeil  = Mathf.Lerp(depths[1, 0], depths[1, 1], returnPeriodIndexPercentage);
                    float actualDepth          = Mathf.Lerp(depthAtDurationFloor, depthAtDurationCeil, durationIndexPercentage);
                    return(actualDepth);
                }
            }
            return(0f);
        }
Beispiel #2
0
 private string[] getCityNamesDropDownOptions()
 {
     try {
         string[] modCityNames  = DepthDurationFrequencyIO.GetCityNames();
         string[] fullCityNames = new string[modCityNames.Length + 1];
         fullCityNames[0] = ModSettings.UnmoddedCityName;
         Array.Copy(modCityNames, 0, fullCityNames, 1, modCityNames.Length);
         return(fullCityNames);
     } catch (Exception e)
     {
         Debug.Log("[RF]GetCityNamesDropDownOptions Could not get city names encountered exception " + e);
         string[] fullCityNames = new string[1];
         fullCityNames[0] = ModSettings.UnmoddedCityName;
         return(fullCityNames);
     }
 }
Beispiel #3
0
        private void OnCityNameDropDownChanged(int sel)
        {
            ModSettings.CityName = cityNames[sel];
            if (sel != 0 && ModSettings.AutomaticStormDistribution)
            {
                if (DepthDurationFrequencyIO.GetStormDistributionForCity(ModSettings.CityName) != "")
                {
                    ModSettings.StormDistributionName       = DepthDurationFrequencyIO.GetStormDistributionForCity(ModSettings.CityName);
                    StormDistributionDropDown.selectedIndex = getStormDistributionIndex(ModSettings.StormDistributionName);
                }
            }

            if (sel == 0)
            {
                StormDistributionDropDown.selectedIndex = 0;
            }
        }
Beispiel #4
0
 private void OnStormDistributionDropDownChanged(int sel)
 {
     ModSettings.StormDistributionName = stormDistributionNames[sel];
     if (sel == 0)
     {
         CityNameDropDown.selectedIndex = 0;
         ModSettings.CityName           = cityNames[0];
     }
     if (CityNameDropDown.selectedIndex == 0)
     {
         foreach (string city in cityNames)
         {
             if (DepthDurationFrequencyIO.GetStormDistributionForCity(city) == ModSettings.StormDistributionName && DepthDurationFrequencyIO.GetStormDistributionForCity(city) != "")
             {
                 ModSettings.CityName           = city;
                 CityNameDropDown.selectedIndex = getCityNameIndex(city);
             }
         }
     }
 }
Beispiel #5
0
        public void OnSettingsUI(UIHelperBase helper)
        {
            customStormDistribution      = new StormDistributionIO();
            customDepthDurationFrequency = new DepthDurationFrequencyIO();


            UIHelperBase group = helper.AddGroup("General Options");

            ChirpForecastCheckBox   = group.AddCheckbox("#RainForecast Chirps", ModSettings.ChirpForecasts, OnChirpForecastCheckBoxChanged) as UICheckBox;
            ChirpRainTweetsCheckBox = group.AddCheckbox("#Rainfall Chirps", ModSettings.ChirpRainTweets, OnChirpRainTweetsCheckBoxChanged) as UICheckBox;
            //EasyModeCheckBox = group.AddCheckbox("Easy/Casual Mode", ModSettings.EasyMode, OnEasyModeCheckBoxChanged) as UICheckBox;
            //DistrictControlCheckBox = group.AddCheckbox("District Control", ModSettings.DistrictControl, OnDistrictControlCheckBoxChanged) as UICheckBox;
            StormDrainAssetControlDropDown = group.AddDropdown("Storm Drain Asset Control", StormDrainAssetControlDropDownOptions, ModSettings.StormDrainAssetControlOption, OnStormDrainAssetControlDropDownChanged) as UIDropDown;
            SimulatePollutionCheckBox      = group.AddCheckbox("Simulate Pollution", ModSettings.SimulatePollution, OnSimulatePollutionCheckBoxChanged) as UICheckBox;
            //ImprovedInletMechanicsCheckBox = group.AddCheckbox("Improved Inlet Mechanics", ModSettings.ImprovedInletMechanics, OnImprovedInletMechanicsCheckBoxChanged) as UICheckBox;
            PreventRainBeforeMilestoneCheckBox = group.AddCheckbox("Prevent Rain Before Milestone", ModSettings.PreventRainBeforeMilestone, OnPreventRainBeforeMilestoneCheckBoxChanged) as UICheckBox;

            FreezeLandvaluesCheckBox                = group.AddCheckbox("Prevent Building Upgrades from Increased Landvalue due to Rainwater", ModSettings.FreezeLandvalues, OnFreezeLandvaluesCheckBoxChanged) as UICheckBox;
            PreviousStormDropDown                   = group.AddDropdown("Previous Storm Options (IE Loading after you saved during a storm)", previousStormDropDownOptions, ModSettings.PreviousStormOption, OnPreviousStormOptionChanged) as UIDropDown;
            GravityDrainageDropDown                 = group.AddDropdown("Gravity Drainage Options", gravityDrainageDropDownOptions, ModSettings.GravityDrainageOption, OnGravityDrainageOptionChanged) as UIDropDown;
            DifficultySlider                        = group.AddSlider("Difficulty", 0f, (float)ModSettings._maxDifficulty, (float)ModSettings._difficultyStep, (float)ModSettings.Difficulty, OnDifficultyChanged) as UISlider;
            DifficultySlider.tooltip                = ModSettings.Difficulty.ToString() + "%";
            DifficultySlider.width                 += 100;
            RefreshRateSlider                       = group.AddSlider("Refresh Rate", 1f, (float)ModSettings._maxRefreshRate, 1f, (float)ModSettings.RefreshRate, OnRefreshRateChanged) as UISlider;
            RefreshRateSlider.tooltip               = ModSettings.RefreshRate.ToString() + " seconds";
            RefreshRateSlider.width                += 100;
            BuildingFloodingToleranceSlider         = group.AddSlider("Building Flooding Tol.", (float)ModSettings._minFloodTolerance, (float)ModSettings._maxFloodTolerance, (float)ModSettings._floodToleranceStep, (float)ModSettings.BuildingFloodingTolerance, OnBuildingFloodingToleranceChanged) as UISlider;
            BuildingFloodingToleranceSlider.tooltip = ((float)ModSettings.BuildingFloodingTolerance / 100f).ToString() + " units";
            BuildingFloodingToleranceSlider.width  += 100;
            BuildingFloodedToleranceSlider          = group.AddSlider("Building Flooded Tol.", (float)ModSettings._minFloodTolerance, (float)ModSettings._maxFloodTolerance, (float)ModSettings._floodToleranceStep, (float)ModSettings.BuildingFloodedTolerance, OnBuildingFloodedToleranceChanged) as UISlider;
            BuildingFloodedToleranceSlider.tooltip  = ((float)ModSettings.BuildingFloodedTolerance / 100f).ToString() + " units";
            BuildingFloodedToleranceSlider.width   += 100;
            RoadwayFloodingToleranceSlider          = group.AddSlider("Roadway Flooding Tol.", (float)ModSettings._minFloodTolerance, (float)ModSettings._maxFloodTolerance, (float)ModSettings._floodToleranceStep, (float)ModSettings.RoadwayFloodingTolerance, OnRoadwayFloodingToleranceChanged) as UISlider;
            RoadwayFloodingToleranceSlider.tooltip  = ((float)ModSettings.RoadwayFloodingTolerance / 100f).ToString() + " units";
            RoadwayFloodingToleranceSlider.width   += 100;
            RoadwayFloodedToleranceSlider           = group.AddSlider("Roadway Flooded Tol.", (float)ModSettings._minFloodTolerance, (float)ModSettings._maxFloodTolerance, (float)ModSettings._floodToleranceStep, (float)ModSettings.RoadwayFloodedTolerance, OnRoadwayFloodedToleranceChanged) as UISlider;
            RoadwayFloodedToleranceSlider.tooltip   = ((float)ModSettings.RoadwayFloodedTolerance / 100f).ToString() + " units";
            RoadwayFloodedToleranceSlider.width    += 100;

            PedestrianPathFloodingToleranceSlider         = group.AddSlider("Ped. Path Flooding Tol.", (float)ModSettings._minFloodTolerance, (float)ModSettings._maxFloodTolerance, (float)ModSettings._floodToleranceStep, (float)ModSettings.PedestrianPathFloodingTolerance, OnPedestrianPathFloodingToleranceChanged) as UISlider;
            PedestrianPathFloodingToleranceSlider.tooltip = ((float)ModSettings.PedestrianPathFloodingTolerance / 100f).ToString() + " units";
            PedestrianPathFloodingToleranceSlider.width  += 100;
            PedestrianPathFloodedToleranceSlider          = group.AddSlider("Ped. Path Flooded Tol.", (float)ModSettings._minFloodTolerance, (float)ModSettings._maxFloodTolerance, (float)ModSettings._floodToleranceStep, (float)ModSettings.PedestrianPathFloodedTolerance, OnPedestrianPathFloodedToleranceChanged) as UISlider;
            PedestrianPathFloodedToleranceSlider.tooltip  = ((float)ModSettings.PedestrianPathFloodedTolerance / 100f).ToString() + " units";
            PedestrianPathFloodedToleranceSlider.width   += 100;
            UIHelperBase StormWaterSimulationGroup = helper.AddGroup("Stormwater Simulation Settings");

            AutomaticallyPickStormDistributionCheckBox = StormWaterSimulationGroup.AddCheckbox("Automatically Select Storm Distribution", ModSettings.AutomaticStormDistribution, OnAutomaticStormDistributionCheckBoxChanged) as UICheckBox;
            cityNames                          = getCityNamesDropDownOptions();
            CityNameDropDown                   = StormWaterSimulationGroup.AddDropdown("City used for Depth-Duration-Frequency Data", cityNames, getCityNameIndex(ModSettings.CityName), OnCityNameDropDownChanged) as UIDropDown;
            stormDistributionNames             = getStormDistributionDropDownOptions();
            StormDistributionDropDown          = StormWaterSimulationGroup.AddDropdown("Storm Distribution", stormDistributionNames, getStormDistributionIndex(ModSettings.StormDistributionName), OnStormDistributionDropDownChanged) as UIDropDown;
            TimeScaleDropDown                  = StormWaterSimulationGroup.AddDropdown("Storm Simulation Time Scale Multiplier", TimeScalesString, getTimeScaleIndex(ModSettings.TimeScale), OnTimeScaleChanged) as UIDropDown;
            MinimumStormDurationSlider         = StormWaterSimulationGroup.AddSlider("Min. Storm Duration", ModSettings._minStormDuration, ModSettings._maxStormDuration, ModSettings._stormDurationStep, (float)ModSettings.MinimumStormDuration, onMinimumStormDurationChanged) as UISlider;
            MinimumStormDurationSlider.tooltip = convertMinToHourMin((float)ModSettings.MinimumStormDuration);
            MinimumStormDurationSlider.width  += 100;
            MaximumStormDurationSlider         = StormWaterSimulationGroup.AddSlider("Max. Storm Duration", ModSettings._minStormDuration, ModSettings._maxStormDuration, ModSettings._stormDurationStep, (float)ModSettings.MaximumStormDuration, onMaximumStormDurationChanged) as UISlider;

            MaximumStormDurationSlider.tooltip  = convertMinToHourMin((float)ModSettings.MaximumStormDuration);
            MaximumStormDurationSlider.width   += 100;
            MaximumStormIntensitySlider         = StormWaterSimulationGroup.AddSlider("Max. Intensity", ModSettings._minStormIntensity, ModSettings._maxStormIntensity, ModSettings._stormIntenistyStep, (float)ModSettings.MaximumStormIntensity, onMaximumStormIntensityChanged) as UISlider;
            MaximumStormIntensitySlider.tooltip = ModSettings.MaximumStormIntensity.ToString() + " Units/Hour";
            MaximumStormIntensitySlider.width  += 100;
            UIHelperBase PublicBuildingsRunOffCoefficientsGroup = helper.AddGroup("Public Buildings Runoff Coefficient Settings");

            initializeRunoffCoefficientSliders();
            createRunoffCoefficientSliders(PublicBuildingsRunOffCoefficientsGroup, PublicBuildingsRunoffCoefficientSliders);

            UIHelperBase PrivateBuildingsRunoffCoefficientsGroup = helper.AddGroup("Private Buildings Runoff Coefficient Settings");

            createRunoffCoefficientSliders(PrivateBuildingsRunoffCoefficientsGroup, PrivateBuildingsRunoffCoefficientSliders);

            UIHelperBase ResetGroup = helper.AddGroup("Reset");

            ResetAllButton = ResetGroup.AddButton("Reset All", resetAllSettings) as UIButton;

            UIHelperBase SafelyRemoveRainfallGroup = helper.AddGroup("Safely Remove Rainfall");

            DeleteAssetsButton = SafelyRemoveRainfallGroup.AddButton("Delete Rainfall Assets", deleteAllAssets) as UIButton;
            CleanUpCycleButton = SafelyRemoveRainfallGroup.AddButton("Clean Up Cycle", cleanUpCycle) as UIButton;
            EndStormButton     = SafelyRemoveRainfallGroup.AddButton("End Storm", endStorm) as UIButton;
        }
        public DepthDurationFrequencyIO()
        {
            instance      = this;
            fileDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\Cities_Skylines\";
            filePath      = fileDirectory + "RFDepthDurationFrequency.csv";
            fileName      = "RFDepthDurationFrequency.csv";
            initializeDefaultDDFAtlas();
            if (!File.Exists(fileName))
            {
                try
                {
                    string deliminator = ",";
                    writer = new StreamWriter(File.OpenWrite(fileName));
                    foreach (KeyValuePair <string, float[, ]> pair in defaultDDFAtlas)
                    {
                        string cityName = pair.Key;
                        string intensityCurveName;
                        if (defaultCityIntensityCurve.ContainsKey(cityName))
                        {
                            intensityCurveName = defaultCityIntensityCurve[cityName];
                        }
                        else
                        {
                            intensityCurveName = "";
                        }
                        StringBuilder firstLine = new StringBuilder();
                        firstLine.Append(cityName + deliminator + intensityCurveName + deliminator);

                        for (int i = 3; i < numberOfStormFrequencies; i++)
                        {
                            firstLine.Append(deliminator);
                        }
                        writer.WriteLine(firstLine);

                        for (int i = 0; i < numberOfStormDurations; i++)
                        {
                            StringBuilder nextLine = new StringBuilder();
                            for (int j = 0; j < numberOfStormFrequencies; j++)
                            {
                                nextLine.Append(pair.Value[i, j].ToString());
                                if (j < numberOfStormDurations - 1)
                                {
                                    nextLine.Append(deliminator);
                                }
                            }
                            writer.WriteLine(nextLine);
                        }
                    }

                    writer.Close();
                    Debug.Log("[RF].DepthDurationFrequency Successfullly wrote new DDF matrix file.");
                }
                catch (IOException ex)
                {
                    Debug.Log("[RF].DepthDurationFrequency Could not write DDF matrix file encountered excpetion " + ex.ToString());

                    /*cityIntensityCurve = defaultCityIntensityCurve;
                     * DDFAtlas = defaultDDFAtlas;
                     * cityNames = defaultCityNames;*/
                }
            }
            try
            {
                reader             = new StreamReader(File.OpenRead(fileName));
                DDFAtlas           = new Dictionary <string, float[, ]>();
                cityIntensityCurve = new Dictionary <string, string>();
                cityNames          = new List <string>();
                while (!reader.EndOfStream)
                {
                    string   nextCityLine        = reader.ReadLine();
                    string[] nextCityLineColumns = nextCityLine.Split(',');

                    string cityName = nextCityLineColumns[0];
                    cityNames.Add(cityName);
                    DDFAtlas.Add(cityName, new float[numberOfStormDurations, numberOfStormFrequencies]);
                    SortedList <float, float> emptyIntensityCurve = new SortedList <float, float>();
                    if (StormDistributionIO.GetDepthCurve(nextCityLineColumns[1], ref emptyIntensityCurve))
                    {
                        cityIntensityCurve.Add(cityName, nextCityLineColumns[1]);
                        Debug.Log("[RF].DepthDurationFrequency Added " + cityName.ToString() + " with default intensity curve" + nextCityLineColumns[1] + " to city list");
                    }


                    for (int i = 0; i < numberOfStormDurations; i++)
                    {
                        if (!reader.EndOfStream)
                        {
                            string   line   = reader.ReadLine();
                            string[] values = line.Split(',');
                            for (int j = 0; j < numberOfStormFrequencies; j++)
                            {
                                DDFAtlas[cityName][i, j] = (float)Convert.ToDecimal(values[j]);
                            }
                        }
                        else
                        {
                            DDFAtlas.Remove(cityName);
                        }
                    }
                }
                reader.Close();

                Debug.Log("[RF].DepthDurationFrequency Successfullly imported Depth-Duration-Frequency matrix file.");

                /*
                 * for (float i=30f; i<=1440f; i+=15f)
                 * {
                 *   for (float j=0.25f; j<=1.00f; j+=0.05f)
                 *   {
                 *       float depth = GetDepth("Boise. Idaho. USA", i, j);
                 *       Debug.Log("[RF] for Boise Idaho with duration i= " + i.ToString() + " & targetIntensity = " + j.ToString() + " depth = " + depth.ToString());
                 *   }
                 *
                 * }
                 */
                /*Used to create default data
                 * StringBuilder sb = new StringBuilder();
                 * sb.AppendLine("Dictionary<string, float[,]> defaultDDFAtlas = new Dictionary<string, float[,]> { ");
                 * foreach (string city in cityNames)
                 * {
                 *  sb.Append("{");
                 *  sb.Append("\"" + city + "\", new float[,] {");
                 *  for (int i = 0; i < numberOfStormDurations; i++)
                 *  {
                 *      sb.Append("{");
                 *      for (int j = 0; j < numberOfStormFrequencies; j++)
                 *      {
                 *          sb.Append(DDFAtlas[city][i, j].ToString() + "f");
                 *          if (j < numberOfStormFrequencies - 1)
                 *              sb.Append(", ");
                 *      }
                 *      sb.Append("}");
                 *      if (i < numberOfStormDurations - 1)
                 *          sb.Append(",");
                 *  }
                 *  sb.AppendLine("}},");
                 * }
                 * sb.AppendLine("};");
                 * Debug.Log(sb);
                 */
            }
            catch (FileNotFoundException)
            {
                Debug.Log("[RF].DepthDurationFrequency file not found at " + fileDirectory + fileName);
                cityIntensityCurve = defaultCityIntensityCurve;
                DDFAtlas           = defaultDDFAtlas;
                cityNames          = defaultCityNames;
            }
            catch (DirectoryNotFoundException)
            {
                Debug.Log("[RF].DepthDurationFrequency Directory not found at " + fileDirectory);
                cityIntensityCurve = defaultCityIntensityCurve;
                DDFAtlas           = defaultDDFAtlas;
                cityNames          = defaultCityNames;
            }
            catch (IOException ex)
            {
                Debug.Log("[RF].DepthDurationFrequency Could not read Depth Duration Frequency file encountered excpetion " + ex.ToString());
                cityIntensityCurve = defaultCityIntensityCurve;
                DDFAtlas           = defaultDDFAtlas;
                cityNames          = defaultCityNames;
            }
        }