Example #1
0
        private bool CheckOutOfRange(UncertainRange range, float min, float max)
        {
            if (range != null)
            {
                return(range.CheckOutOfRange(min, max));
            }

            return(false);
        }
Example #2
0
        public List <Tuple <float, FishDef> > GetUpdatedFishList(List <FishDef> fishList, TerrainType type, bool IsMarshTerrain = false)
        {
            if (needsInitialize)
            {
                needsInitialize = false;
                MapInitialize();
                UpdateInfo();
            }

            List <Tuple <float, FishDef> > fishByWeight = new List <Tuple <float, FishDef> >();

            var constWeightFish    = fishList.Where(fish => fish.fishProperties.WeightType == WeightingType.Static);
            var relativeWeightFish = fishList.Where(fish => fish.fishProperties.WeightType == WeightingType.StaticFactor);

            float tempWeightMod     = 0;
            float humWeightMod      = 0;
            float swampWeightMod    = 0;
            float currentFishWeight = 1;
            float totalWeight       = 0;

            fishByWeight.Clear();
            //Log.Message("constweight");
            foreach (var fish in constWeightFish)
            {
                tempWeightMod  = (float)UncertainRange.GetWeightPercent(fish.fishProperties.TemperatureRange, map.mapTemperature.OutdoorTemp);
                humWeightMod   = (float)UncertainRange.GetWeightPercent(fish.fishProperties.HumidityRange, averageMapHumidity);
                swampWeightMod = fish.fishProperties.MarshFactor * (float)UncertainRange.GetWeightPercent(fish.fishProperties.SwampinessRange, averageSwampiness + (IsMarshTerrain ? 0.8f : 0));

                currentFishWeight = fish.fishProperties.Weight * tempWeightMod * humWeightMod * (1 + swampWeightMod);
                //Log.Message(fish.defName + " " + fish.fishProperties.Weight + " tempWeightMod:" + tempWeightMod + " humWeightMod:" + humWeightMod + " swampWeightMod:" + swampWeightMod + " weight:" + currentFishWeight + " OutdoorTemp:" + map.mapTemperature.OutdoorTemp);

                //if (fish.defName == "Sturgeon")
                //{

                //}

                totalWeight += Math.Abs(currentFishWeight);

                if (currentFishWeight > 0.001f)
                {
                    fishByWeight.Add(new Tuple <float, FishDef>(currentFishWeight, fish));
                }
            }

            if (totalWeight <= 0.2)
            {
                totalWeight = 1;
            }
            //Log.Message("relativeWeight");

            foreach (var fish in relativeWeightFish)
            {
                tempWeightMod  = (float)UncertainRange.GetWeightPercent(fish.fishProperties.TemperatureRange, map.mapTemperature.OutdoorTemp);
                humWeightMod   = (float)UncertainRange.GetWeightPercent(fish.fishProperties.HumidityRange, map.TileInfo.rainfall);
                swampWeightMod = fish.fishProperties.MarshFactor * (float)UncertainRange.GetWeightPercent(fish.fishProperties.SwampinessRange, averageSwampiness + (IsMarshTerrain ? 0.8f : 0));

                currentFishWeight = totalWeight * fish.fishProperties.Weight * tempWeightMod * humWeightMod * (1 + swampWeightMod);

                //Log.Message(fish.defName + " " + fish.fishProperties.Weight + " tempWeightMod:" + tempWeightMod + " humWeightMod:" + humWeightMod + " swampWeightMod:" + swampWeightMod + " weight:" + currentFishWeight + " OutdoorTemp:" + map.mapTemperature.OutdoorTemp);

                totalWeight += Math.Abs(currentFishWeight);
                if (currentFishWeight > 0.001f)
                {
                    fishByWeight.Add(new Tuple <float, FishDef>(currentFishWeight, fish));
                }
            }


            return(fishByWeight);
        }
        public static double GetWeightPercent(UncertainRange valueRange, double value)
        {
            if (valueRange != null)
            {
                if (valueRange.fav.HasValue)
                {
                    if (value > valueRange.fav)
                    {
                        if (valueRange.max.HasValue)
                        {
                            if (value < valueRange.max)
                            {
                                return((1 + Math.Cos(Math.PI * (value - valueRange.fav.Value) / (valueRange.max.Value - valueRange.fav.Value))) / 2);
                            }
                            else
                            {
                                return(0);
                            }
                        }
                        else
                        {
                            return((1 + Math.Cos(Math.PI * (1 - 1 / (value + 1 - valueRange.fav.Value)))) / 2);
                        }
                    }
                    else
                    if (value < valueRange.fav)
                    {
                        if (valueRange.min.HasValue)
                        {
                            if (value > valueRange.min)
                            {
                                return((1 + Math.Cos(Math.PI * (value - valueRange.fav.Value) / (valueRange.min.Value - valueRange.fav.Value))) / 2);
                            }
                            else
                            {
                                return(0);
                            }
                        }
                        else
                        {
                            return((1 + Math.Cos(Math.PI * (1 + 1 / (value - valueRange.fav.Value - 1)))) / 2);
                            //return (1 + Math.Cos(Math.PI / (1 + Math.Abs(value - valueRange.fav.Value)))) / 2;
                        }
                    }
                    else
                    {
                        return(1);
                    }
                }
                else if (valueRange.min.HasValue && valueRange.max.HasValue)
                {
                    if (valueRange.min.Value < value && value < valueRange.max.Value)
                    {
                        return((1 + Math.Cos(Math.PI * (1 + 2 * (value - valueRange.min.Value) / (valueRange.max.Value - valueRange.min.Value)))) / 2);
                    }
                    return(0);
                }
                else
                if (valueRange.min.HasValue && valueRange.min.Value < value)
                {
                    return(1);
                }
                else
                if (valueRange.max.HasValue && valueRange.max.Value > value)
                {
                    return(1);
                }

                return(0);
            }

            return(1);
        }