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

            // Update zone properties.
            UpdateAquaticCellsAround();
            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);

            // Udpdate fish stock.
            if ((this.fishStock < this.maxFishStock) &&
                viableCellsCount > 0)
            {
                float fishSpawnRateFactor = 1f;
                Util_Zone_Fishing.UpdateFishSpawnRateFactor(this.Map, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount,
                                                            this.isAffectedByToxicFallout, this.isAffectedByBadTemperature, ref fishSpawnRateFactor);
                float fishSpawnMtb       = baseFishSpawnMtbPier * fishSpawnRateFactor;
                int   missingFishesCount = this.maxFishStock - this.fishStock;
                for (int missingFishIndex = 0; missingFishIndex < missingFishesCount; missingFishIndex++)
                {
                    bool fishShouldBeSpawned = Rand.MTBEventOccurs(fishSpawnMtb, 1, MapComponent_FishingZone.updatePeriodInTicks);
                    if (fishShouldBeSpawned)
                    {
                        this.fishStock++;
                    }
                }
            }
            else if (this.fishStock > this.maxFishStock)
            {
                int surplusFishesCount = this.fishStock - this.maxFishStock;
                this.fishStock -= surplusFishesCount;
            }
        }
Example #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).
            UpdateAquaticCellsAround();
            // 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);

            // Udpdate fish stock.
            if ((this.fishesPosition.Count < this.maxFishStock) &&
                viableCellsCount > 0)
            {
                float fishSpawnRateFactor = 1f;
                Util_Zone_Fishing.UpdateFishSpawnRateFactor(this.Map, this.oceanCellsCount, this.riverCellsCount, this.marshCellsCount,
                                                            this.isAffectedByToxicFallout, this.isAffectedByBadTemperature, ref fishSpawnRateFactor);
                float fishSpawnMtb       = baseFishSpawnMtbZone * fishSpawnRateFactor;
                int   missingFishesCount = this.maxFishStock - this.fishesPosition.Count;
                for (int missingFishIndex = 0; missingFishIndex < missingFishesCount; missingFishIndex++)
                {
                    bool fishShouldBeSpawned = Rand.MTBEventOccurs(fishSpawnMtb, 1, MapComponent_FishingZone.updatePeriodInTicks);
                    if (fishShouldBeSpawned)
                    {
                        // Try to spawn a new fish.
                        for (int tryIndex = 0; tryIndex < 5; tryIndex++)
                        {
                            IntVec3 spawnCell = this.Cells.RandomElement();
                            if (this.fishesPosition.Contains(spawnCell) == false)
                            {
                                this.fishesPosition.Add(spawnCell);
                                break;
                            }
                        }
                    }
                }
            }
            else if (this.fishesPosition.Count > maxFishStock)
            {
                int surplusFishesCount = this.fishesPosition.Count - maxFishStock;
                for (int surplusFishIndex = 0; surplusFishIndex < surplusFishesCount; surplusFishIndex++)
                {
                    IntVec3 fishPos = fishesPosition.RandomElement();
                    this.fishesPosition.Remove(fishPos);
                }
            }
        }