-
Notifications
You must be signed in to change notification settings - Fork 39
Apply best available single category modules by default #622
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
base: master
Are you sure you want to change the base?
Changes from all commits
2d94265
490a578
db04f1c
be57d9e
9cd16c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -808,6 +808,68 @@ public void AutoApplyModuleTemplate(List<ProjectModuleTemplate> moduleTemplates) | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /// <summary> | ||||||||
| /// Apply a default module when this row uses a single-category module building and no template was selected. | ||||||||
| /// The chosen module is based upon the unlock order and what milestones are currently unlocked. No secondary sort on prod/speed to keep the code simpler | ||||||||
| /// </summary> | ||||||||
| public void AutoApplySingleCategoryModule() { | ||||||||
| //Don't change anything if existing modules are set | ||||||||
| if (modules != null) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| //Basic safety checks | ||||||||
| if (recipe is null || entity is null || entity.target.moduleSlots <= 0) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| if (recipe.target is not Recipe targetRecipe) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| if (entity.target.allowedModuleCategories is not [string moduleCategory]) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| Bits recipeUnlockOrder = DataUtils.GetMilestoneOrder(targetRecipe.id); | ||||||||
|
|
||||||||
| IObjectWithQuality<Module>? bestModule = null; | ||||||||
| Bits bestUnlockOrder = default; | ||||||||
|
|
||||||||
| //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)) { | ||||||||
| continue; | ||||||||
| } | ||||||||
|
|
||||||||
| //Check the recipe allows this module | ||||||||
| if (!entity.target.CanAcceptModule(module.moduleSpecification) || !recipe.target.CanAcceptModule(module)) { | ||||||||
| continue; | ||||||||
| } | ||||||||
|
|
||||||||
| //Check if this module is currently available for this recipe with the active milestones | ||||||||
| Bits moduleUnlockOrder = DataUtils.GetMilestoneOrder(module.id); | ||||||||
| if (moduleUnlockOrder.CompareTo(recipeUnlockOrder) > 0) { | ||||||||
|
Comment on lines
+852
to
+853
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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. |
||||||||
| continue; | ||||||||
| } | ||||||||
|
|
||||||||
| //Update if this module is better (milestone order) | ||||||||
| Bits moduleMilestoneOrder = Milestones.Instance.GetMilestoneResult(module.id); | ||||||||
| if (bestModule == null || moduleMilestoneOrder.CompareTo(bestUnlockOrder) > 0) { | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It might just be me, but I always have to spend a lot of effort interpreting calls to |
||||||||
| bestModule = module.With(Quality.Normal); | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||||||||
| bestUnlockOrder = moduleMilestoneOrder; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| //We have a working module, fill all the module slots | ||||||||
| if (bestModule != null) { | ||||||||
| modules = new ModuleTemplateBuilder { | ||||||||
| list = [(bestModule, 0)] | ||||||||
| }.Build(this); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| public float DetermineFlow(IObjectWithQuality<Goods> goods) { | ||||||||
| if (recipe is null) { | ||||||||
| throw new InvalidOperationException("Cannot determine flow when no recipe is selected."); | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell,
operator !=is the same as doing an explicit ordinal comparison.