Skip to content
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

Request for comments: Prepare resources for better mod-ability #4146

Conversation

SomeTroglodyte
Copy link
Collaborator

Inspired by #3242: Concept on how to begin making resources more mod-able.

  • Centralize logic (e.g. terrainsCanBeFoundOn would still work as private)
  • Allow more than 1 unique with compatibility
  • Parameterize the one existing unique
  • Two new uniques as samples

Questions:

  • Is this the correct approach?
  • Why does TileInfo.normalizeToRuleset use a different logic? Would making it use ! isAllowedOnTile hurt? How? (and if it stays it would need to respect those uniques too)
  • That hardcoded Snow Hill exclusion - how to best 'soften' that? I gave it lower precedence so mods could override, but this still looks a tad inelegant
  • +15 production could use the stats mechanic, but percent? Smells like it needs an idea, which is why i postponed parameterizing the wonder part

@SomeTroglodyte SomeTroglodyte changed the title Reques for comments: Prepare resources for better mod-ability Request for comments: Prepare resources for better mod-ability Jun 14, 2021
@SomeTroglodyte
Copy link
Collaborator Author

P.S.: This would cover @GoldenBronze's "River" post cheaply - but as I said, that part is just a demo of the possibilities

@yairm210
Copy link
Owner

If anything, resource uniques should be merged into global uniques, so they won't need any special attention. This is actually much simpler that other solutions as well :)

@@ -433,7 +435,7 @@ class CityStats {
if (cityInfo.getRuleset().modOptions.uniques.contains("Can convert gold to science with sliders")) {
val amountConverted = (newFinalStatList.values.sumByDouble { it.gold.toDouble() }
* cityInfo.civInfo.tech.goldPercentConvertedToScience).toInt().toFloat()
if (amountConverted > 0) // Don't want you converting negative gold to negative science yaknow
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't I just remove the "yaknow" which triggers the spellchecker? ... yup. Such language may be nice to lighten a mood - but aren't we in the worst possible mood beyond redemption when coding anyway? 😉

@@ -661,8 +661,7 @@ open class TileInfo {

if (resource != null && !ruleset.tileResources.containsKey(resource)) resource = null
if (resource != null) {
val resourceObject = ruleset.tileResources[resource]!!
if (resourceObject.terrainsCanBeFoundOn.none { it == baseTerrain || terrainFeatures.contains(it) })
if (ruleset.tileResources[resource]!!.mustRemoveFromTile(this))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just !isAllowedOnTile(this)? Why make an extra function? I think the performance difference is negligible

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a comment to that (is there)? The original code did already check differently, so I left the discrepancy but wrapped it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the same check, if we're unifying things

for (terrain in resource.terrainsCanBeFoundOn)
if (!terrains.containsKey(terrain))
lines += "${resource.name} can be found on terrain $terrain which does not exist!"
warningCount += resource.checkModLinks(this, lines)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't think this is good. Mod links should be checked in the ruleset, not in the resource...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marginal decision either way. Makes property access a bit shorter on average was the idea methinks.

* @param ruleset The ruleset to search for viable terrains
* @return Terrain name or null if impossible due to [ruleset] inconsistency
*/
fun getSampleTerrain(ruleset: Ruleset): String? {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For one usage? I don't think this is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. That's got to do with "general structure" - I generalized as much as possible first, planning to fold such stuff later if rarely (or not at all) used...

@SomeTroglodyte
Copy link
Collaborator Author

SomeTroglodyte commented Jun 17, 2021

If anything, resource uniques should be merged into global uniques, so they won't need any special attention. This is actually much simpler that other solutions as well :)

Limit them to civ-global effects? Marble isn't global, or is it? Pretty sure it's per city. And some mod ideas are tile-specific properties, like 'resource allowed on river tiles only' or 'your kumquat disappears if you chop the jungle'...

@yairm210
Copy link
Owner

Marble is global. Marble anywhere = marble in civ = wonder bonus.

@SomeTroglodyte
Copy link
Collaborator Author

You're right, I just checked - CityStats line 95 decides that.

Then we should maybe change that to per city: "in the city where it is worked"? Would this kind of change be an argument in favour of the general architecture I suggested here? Seems not to me, I mean, woudn't make any big difference.

@SomeTroglodyte SomeTroglodyte deleted the Prepare-resource-uniques branch July 13, 2021 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants