Apply best available single category modules by default#622
Apply best available single category modules by default#622craig-johnston wants to merge 5 commits intoYafc-CE:masterfrom
Conversation
…efault modules based on the milestones that are unlocked.
veger
left a comment
There was a problem hiding this comment.
Code looks good to me.
I do wonder if we need to check some other mod packs to see if they are not broken by this, as we do not know how their modules work? (At least I do not... 😉)
|
I've tested briefly space age; it does nothing, as expected. |
|
I was indeed thinking about angels/bobs, as they introduce some new modules (at least back when I played them). I do not have a lot of experience with mod suites, so I do not have a list of which made changes to modules unfortunately. If there are no others, we cannot test, and a (quick) angels/bobs is all that can be done... |
|
Quick Angels/bobs test shows no conflict, it doesn't pick anything for the modules, same as space age. |
|
|
||
| //Update if this module is better (milestone order) | ||
| Bits moduleMilestoneOrder = Milestones.Instance.GetMilestoneResult(module.id); | ||
| if (bestModule == null || moduleMilestoneOrder.CompareTo(bestUnlockOrder) > 0) { |
There was a problem hiding this comment.
| if (bestModule == null || moduleMilestoneOrder.CompareTo(bestUnlockOrder) > 0) { | |
| if (bestModule == null || moduleMilestoneOrder > bestUnlockOrder) { |
It might just be me, but I always have to spend a lot of effort interpreting calls to CompareTo
| Bits moduleUnlockOrder = DataUtils.GetMilestoneOrder(module.id); | ||
| if (moduleUnlockOrder.CompareTo(recipeUnlockOrder) > 0) { |
There was a problem hiding this comment.
| Bits moduleUnlockOrder = DataUtils.GetMilestoneOrder(module.id); | |
| if (moduleUnlockOrder.CompareTo(recipeUnlockOrder) > 0) { | |
| if (module.IsAccessibleWithCurrentMilestones()) { |
Based on the comment, I think this is the test you want. This way the relative unlock order isn't relevant, just whether the module is unlocked.
| //Loop over all modules finding the one that is usable, unlocked, and unlocks latest according to milestones | ||
| foreach (Module module in Database.allModules) { | ||
| //Check module is in the building's allowed category | ||
| if (!string.Equals(module.moduleSpecification.category, moduleCategory, StringComparison.Ordinal)) { |
There was a problem hiding this comment.
| if (!string.Equals(module.moduleSpecification.category, moduleCategory, StringComparison.Ordinal)) { | |
| if (module.moduleSpecification.category != moduleCategory) { |
As far as I can tell, operator != is the same as doing an explicit ordinal comparison.
| //Update if this module is better (milestone order) | ||
| Bits moduleMilestoneOrder = Milestones.Instance.GetMilestoneResult(module.id); | ||
| if (bestModule == null || moduleMilestoneOrder.CompareTo(bestUnlockOrder) > 0) { | ||
| bestModule = module.With(Quality.Normal); |
There was a problem hiding this comment.
Is Quality.Normal correct here, or should it be Quality.MaxAccessible?
If no modules are set and the building takes special modules, apply default modules based on the milestones that are unlocked.
This is a QOL change for Py players in particular.
Adding recipe to create 1/s moss in existing YAFC:

Same action with this PR:

And example using Wood processing TURD at py3 - Saw blade 2 auto-selected:

This is a single function addition to calculate and apply the best module, so fairly isolated.
I've tested using Py mods.
As per comment in the code, I did not do a secondary sort. If two modules are unlocked at the same milestone, it'll just pick one for simplicity. If/when this case comes up there will be more info about which secondary sort option to take rather than guessing now and making the code more complex.