From 655cab3ebf112ee02e690f74d2e61afbe76a43f4 Mon Sep 17 00:00:00 2001 From: safronov Date: Tue, 18 May 2021 22:29:25 +0300 Subject: [PATCH] Addition module template compatibility checks --- .../ProductionTable/ProductionTableView.cs | 2 +- YAFCmodel/Model/ProductionTableContent.cs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/YAFC/Workspace/ProductionTable/ProductionTableView.cs b/YAFC/Workspace/ProductionTable/ProductionTableView.cs index 5b7e2444..a24da8fe 100644 --- a/YAFC/Workspace/ProductionTable/ProductionTableView.cs +++ b/YAFC/Workspace/ProductionTable/ProductionTableView.cs @@ -548,7 +548,7 @@ private void ShowModuleTemplateTooltip(ImGui gui, ModuleTemplate template) gui.ShowTooltip(imGui => { if (!template.IsCompatibleWith(editingRecipeModules)) - imGui.BuildText("This module template seems incompatible with the recipe", wrap:true); + imGui.BuildText("This module template seems incompatible with the recipe or the building", wrap:true); using (var grid = imGui.EnterInlineGrid(3f, 1f)) { foreach (var module in template.list) diff --git a/YAFCmodel/Model/ProductionTableContent.cs b/YAFCmodel/Model/ProductionTableContent.cs index 2802a06c..4e34e103 100644 --- a/YAFCmodel/Model/ProductionTableContent.cs +++ b/YAFCmodel/Model/ProductionTableContent.cs @@ -70,20 +70,28 @@ public ModuleTemplate(ModelObject owner) : base(owner) {} public bool IsCompatibleWith(RecipeRow row) { + if (row.entity == null) + return false; var hasFloodfillModules = false; var hasCompatibleFloodfill = false; + var totalModules = 0; foreach (var module in list) { - var isCompatibleWithModule = row.recipe.CanAcceptModule(module.module) && (row.entity?.CanAcceptModule(module.module.module) ?? true); + var isCompatibleWithModule = row.recipe.CanAcceptModule(module.module) && row.entity.CanAcceptModule(module.module.module); if (module.fixedCount == 0) { hasFloodfillModules = true; hasCompatibleFloodfill |= isCompatibleWithModule; - } else if (!isCompatibleWithModule) - return false; + } + else + { + if (!isCompatibleWithModule) + return false; + totalModules += module.fixedCount; + } } - return !hasFloodfillModules || hasCompatibleFloodfill; + return (!hasFloodfillModules || hasCompatibleFloodfill) && row.entity.moduleSlots >= totalModules; }