Skip to content

Modded rare features not appearing on top of Hill tiles #13112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
SpacedOutChicken opened this issue Mar 30, 2025 · 1 comment
Open
1 task done

Modded rare features not appearing on top of Hill tiles #13112

SpacedOutChicken opened this issue Mar 30, 2025 · 1 comment
Labels

Comments

@SpacedOutChicken
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Game Version

4.15.19

Describe the bug

I'm trying to create a rare feature that only appears on top of hills, and so far it's not working. The feature either doesn't appear at all or it replaces the hill instead of being on top of it.

Steps to Reproduce

Here are the two ways I've tried to add the rare feature:

{ "name": "Feature 1", "type": "TerrainFeature", "movementCost": 1, "occursOn": ["Hill"], "uniques": ["Rare feature"] }
{ "name": "Feature 2", "type": "TerrainFeature", "movementCost": 1, "occursOn": ["Tundra","Plains","Grassland","Desert","Snow","Hill"], "uniques": ["Rare feature", "Doesn't generate naturally <in tiles without [Hill]>"] }

Feature 1 never shows up. Feature 2 shows up next to Hill tiles but not on top of them.

Screenshots

No response

Link to save file

No response

Operating System

Linux

Additional Information

No response

@SomeTroglodyte
Copy link
Collaborator

Yup:

  • MapGenerator.kt#L605-L606 - the second line is geared to allow hills, but hills can't satisfy the first line looking for baseTerrain1, so you'll need to include both all candidate baseTerrains and Hills in occursOn to have a chance... Explains Feature 1.
  • As for Feature 2: I see only one actual implementation for UniqueType.NoNaturalGeneration - for Resources, so it seems the UniqueTarget.Terrain is wrong. Does not quite explain your observation, however.

Patch idea, untested:

Index: core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt
--- a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt	(revision f2688b4b84b52172eaad93ca89156426485cd78e)
+++ b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt	(date 1743430840659)
@@ -598,17 +598,17 @@
     private fun spawnRareFeatures(tileMap: TileMap) {
         val rareFeatures = ruleset.terrains.values.filter {
             it.type == TerrainType.TerrainFeature && it.hasUnique(UniqueType.RareFeature)
-        }
+        }.associateWith { it.occursOn.toSet() }
         for (tile in tileMap.values.asSequence().filter { it.terrainFeatures.isEmpty() }) {
-            if (randomness.RNG.nextDouble() <= tileMap.mapParameters.rareFeaturesRichness) {
-                val possibleFeatures = rareFeatures.filter {
-                    it.occursOn.contains(tile.baseTerrain)
-                            && (!tile.isHill() || it.occursOn.contains(Constants.hill))
-                            && NaturalWonderGenerator.fitsTerrainUniques(it, tile)
-                }
-                if (possibleFeatures.any())
-                    tile.addTerrainFeature(possibleFeatures.random(randomness.RNG).name)
-            }
+            if (randomness.RNG.nextDouble() > tileMap.mapParameters.rareFeaturesRichness) continue
+            val allTerrainSet = tile.allTerrains.toSet()
+            val possibleFeatures = rareFeatures.filter {
+                    it.value.intersect(allTerrainSet).isNotEmpty()
+                        && (!tile.isHill() || Constants.hill in it.value)
+                        && NaturalWonderGenerator.fitsTerrainUniques(it.key, tile)
+            }
+            if (possibleFeatures.any())
+                tile.addTerrainFeature(possibleFeatures.keys.random(randomness.RNG).name)
         }
     }
 

Footnotes

  1. But back then... looong looong ago.. Oh my the backward compatibility code is still there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants