Skip to content

Commit

Permalink
Addition module template compatibility checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowTheAge committed May 18, 2021
1 parent 04ff8e9 commit 655cab3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion YAFC/Workspace/ProductionTable/ProductionTableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions YAFCmodel/Model/ProductionTableContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down

0 comments on commit 655cab3

Please sign in to comment.