Esempio n. 1
0
        // ===================== Main Work Function =====================
        /// <summary>
        /// Periodically resplenishes the fish stock if possible.
        /// </summary>
        public override void TickRare()
        {
            base.TickRare();

            // Update zone properties.
            UpdateCells();
            Util_Zone_Fishing.UpdateZoneProperties(this.Map, this.aquaticCells, ref this.oceanCellsCount, ref this.riverCellsCount, ref this.marshCellsCount,
                                                   ref this.isAffectedByBiome, ref this.isAffectedByToxicFallout, ref this.isAffectedByBadTemperature, ref this.maxFishStock);
            this.cachedSpeciesInZone = Util_Zone_Fishing.GetSpeciesInZoneText(this.Map.Biome, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount);

            // Udpdate fish stock.
            if ((this.fishStock < this.maxFishStock) &&
                viableCellsCount > 0)
            {
                float fishSpawnRateFactor = 0f;
                Util_Zone_Fishing.ComputeFishSpawnRateFactor(this.Map, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount,
                                                             this.isAffectedByToxicFallout, this.isAffectedByBadTemperature, out fishSpawnRateFactor);
                cachedFishSpawnMtb = baseFishSpawnMtbPier * fishSpawnRateFactor;
                int missingFishesCount = this.maxFishStock - this.fishStock;
                for (int missingFishIndex = 0; missingFishIndex < missingFishesCount; missingFishIndex++)
                {
                    bool fishShouldBeSpawned = Rand.MTBEventOccurs(cachedFishSpawnMtb, 1, MapComponent_FishingZone.updatePeriodInTicks);
                    if (fishShouldBeSpawned)
                    {
                        this.fishStock++;
                    }
                }
            }
            else if (this.fishStock > this.maxFishStock)
            {
                int surplusFishesCount = this.fishStock - this.maxFishStock;
                this.fishStock -= surplusFishesCount;
            }
        }
Esempio n. 2
0
        // ===================== Other functions =====================
        public void UpdateZone()
        {
            // Check current zone cells are valid. Remove invalid ones (terrain may have changed with moisture pump or mods).
            UpdateCellsAndFishingSpots();

            // Update zone properties.
            Util_Zone_Fishing.UpdateZoneProperties(this.Map, this.Cells, ref this.oceanCellsCount, ref this.riverCellsCount, ref this.marshCellsCount,
                                                   ref this.isAffectedByBiome, ref this.isAffectedByToxicFallout, ref this.isAffectedByBadTemperature, ref this.maxFishStock);
            this.cachedSpeciesInZone = Util_Zone_Fishing.GetSpeciesInZoneText(this.Map.Biome, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount);

            // Udpdate fish stock.
            if ((this.fishingSpots.Count < this.maxFishStock) &&
                this.viableCellsCount > 0)
            {
                float fishSpawnRateFactor = 0f;
                Util_Zone_Fishing.ComputeFishSpawnRateFactor(this.Map, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount,
                                                             this.isAffectedByToxicFallout, this.isAffectedByBadTemperature, out fishSpawnRateFactor);
                cachedFishSpawnMtb = baseFishSpawnMtbZone * fishSpawnRateFactor;

                // Check if fishes should be spawned.
                int missingFishesCount = this.maxFishStock - this.fishingSpots.Count;
                int fishesToSpawnCount = 0;
                for (int missingFishIndex = 0; missingFishIndex < missingFishesCount; missingFishIndex++)
                {
                    bool fishShouldBeSpawned = Rand.MTBEventOccurs(cachedFishSpawnMtb, 1, MapComponent_FishingZone.updatePeriodInTicks);
                    if (fishShouldBeSpawned)
                    {
                        fishesToSpawnCount++;
                    }
                }

                if (fishesToSpawnCount > 0)
                {
                    // Update bank and bridge cells.
                    List <IntVec3> bankCells   = new List <IntVec3>();
                    List <IntVec3> bridgeCells = new List <IntVec3>();
                    GetFreeBankAndBridgeCells(missingFishesCount, ref bankCells, ref bridgeCells);
                    // Actually try to spawn fishes.
                    for (int newFishIndex = 0; newFishIndex < fishesToSpawnCount; newFishIndex++)
                    {
                        if ((bankCells.Count == 0) &&
                            (bridgeCells.Count == 0))
                        {
                            break;
                        }
                        TrySpawnNewFish(ref bankCells, ref bridgeCells);
                    }
                }
            }
            else if (this.fishingSpots.Count > maxFishStock)
            {
                int surplusFishesCount = this.fishingSpots.Count - maxFishStock;
                for (int surplusFishIndex = 0; surplusFishIndex < surplusFishesCount; surplusFishIndex++)
                {
                    IntVec3 position = fishingSpots.RandomElement();
                    this.fishingSpots.Remove(position);
                }
            }
        }
Esempio n. 3
0
        // ===================== Inspection pannel functions =====================
        /// <summary>
        /// Get the string displayed in the inspection panel.
        /// </summary>
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Util_FishIndustry.GetFishSpeciesList(this.Map.Biome).NullOrEmpty())
            {
                stringBuilder.Append("FishIndustry.FishingPier_InvalidBiome".Translate());
                return(stringBuilder.ToString());
            }

            if (this.maxFishStock < 0)
            {
                // Update after a savegame loading for example.
                UpdateAquaticCellsAround();
                Util_Zone_Fishing.UpdateZoneProperties(this.Map, this.Cells, ref this.oceanCellsCount, ref this.riverCellsCount, ref this.marshCellsCount,
                                                       ref this.isAffectedByBiome, ref this.isAffectedByToxicFallout, ref this.isAffectedByBadTemperature, ref this.maxFishStock);
            }
            // Fish stock.
            stringBuilder.Append("FishIndustry.FishStock".Translate(this.fishesPosition.Count));
            // Status.
            stringBuilder.AppendLine();
            if (this.viableCellsCount < Util_Zone_Fishing.minCellsToSpawnFish)
            {
                stringBuilder.Append("FishIndustry.NotViableNow".Translate());
            }
            else
            {
                stringBuilder.Append("FishIndustry.SpeciesInZone".Translate() + Util_Zone_Fishing.GetSpeciesInZoneText(this.Map, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount));
            }
            // Affections.
            if (this.Cells.Count < Util_Zone_Fishing.minCellsToSpawnFish)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("FishIndustry.TooSmallZone".Translate());
            }
            if (this.isAffectedByBiome ||
                this.isAffectedByToxicFallout ||
                this.isAffectedByBadTemperature)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("FishIndustry.AffectedBy".Translate());
                StringBuilder effects = new StringBuilder();
                if (this.isAffectedByBiome)
                {
                    effects.Append("FishIndustry.AffectedByBiome".Translate());
                }
                if (this.isAffectedByToxicFallout)
                {
                    effects.AppendWithSeparator("FishIndustry.AffectedByToxicFallout".Translate(), "FishIndustry.AffectedBySeparator".Translate());
                }
                if (this.isAffectedByBadTemperature)
                {
                    effects.AppendWithSeparator("FishIndustry.AffectedByBadTemperature".Translate(), "FishIndustry.AffectedBySeparator".Translate());
                }
                stringBuilder.Append(effects);
            }
            return(stringBuilder.ToString());
        }
Esempio n. 4
0
        // ===================== Inspection pannel functions =====================
        /// <summary>
        /// Get the inspection string.
        /// </summary>
        ///
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Util_FishIndustry.GetFishSpeciesList(this.Map.Biome).NullOrEmpty())
            {
                stringBuilder.Append("FishIndustry.FishingPier_InvalidBiome".Translate());
                return(stringBuilder.ToString());
            }

            if (this.maxFishStock < 0)
            {
                // Update after a savegame loading for example.
                UpdateCells();
                Util_Zone_Fishing.UpdateZoneProperties(this.Map, this.aquaticCells, ref this.oceanCellsCount, ref this.riverCellsCount, ref this.marshCellsCount,
                                                       ref this.isAffectedByBiome, ref this.isAffectedByToxicFallout, ref this.isAffectedByBadTemperature, ref this.maxFishStock);
                this.cachedSpeciesInZone = Util_Zone_Fishing.GetSpeciesInZoneText(this.Map.Biome, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount);
            }
            // Fish stock.
            stringBuilder.Append("FishIndustry.FishStock".Translate(this.fishStock));
            if (Prefs.DevMode)
            {
                stringBuilder.Append("/" + this.maxFishStock);
            }
            // Status.
            stringBuilder.AppendLine();
            if (this.viableCellsCount < Util_Zone_Fishing.minCellsToSpawnFish)
            {
                stringBuilder.Append("FishIndustry.NotEnoughViableSpace".Translate());
            }
            else
            {
                stringBuilder.Append("FishIndustry.SpeciesInZone".Translate() + this.cachedSpeciesInZone);
            }
            // Affections.
            if (this.isAffectedByBiome ||
                this.isAffectedByToxicFallout ||
                this.isAffectedByBadTemperature)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("FishIndustry.AffectedBy".Translate());
                StringBuilder effects = new StringBuilder();
                if (this.isAffectedByBiome)
                {
                    effects.AppendWithComma("FishIndustry.AffectedByBiome".Translate());
                }
                if (this.isAffectedByToxicFallout)
                {
                    effects.AppendWithComma("FishIndustry.AffectedByToxicFallout".Translate());
                }
                if (this.isAffectedByBadTemperature)
                {
                    effects.AppendWithComma("FishIndustry.AffectedByBadTemperature".Translate());
                }
                stringBuilder.Append(effects);
            }
            // Debug.
            if (Prefs.DevMode)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("Spawn mean time: " + GenDate.ToStringTicksToPeriod((int)cachedFishSpawnMtb));
            }
            return(stringBuilder.ToString());
        }