// ===================== 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; } }
// ===================== 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); } } }