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

Add optional built building count to recipe rows #118

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions YAFC/Workspace/ProductionTable/ProductionTableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,28 @@ private void BuildRecipeEntity(ImGui gui, RecipeRow recipe)
if (recipe.isOverviewMode)
return;
bool clicked;
if (recipe.fixedBuildings > 0)
using (var group = gui.EnterGroup(default, RectAllocator.Stretch, spacing:0f))
{
var evt = gui.BuildFactorioObjectWithEditableAmount(recipe.entity, recipe.fixedBuildings, UnitOfMeasure.None, out var newAmount);
if (evt == GoodsWithAmountEvent.TextEditing)
recipe.RecordUndo().fixedBuildings = newAmount;
clicked = evt == GoodsWithAmountEvent.ButtonClick;
group.SetWidth(3f);
if (recipe.fixedBuildings > 0)
{
var evt = gui.BuildFactorioObjectWithEditableAmount(recipe.entity, recipe.fixedBuildings, UnitOfMeasure.None, out var newAmount);
if (evt == GoodsWithAmountEvent.TextEditing)
recipe.RecordUndo().fixedBuildings = newAmount;
clicked = evt == GoodsWithAmountEvent.ButtonClick;
}
else
clicked = gui.BuildFactorioObjectWithAmount(recipe.entity, recipe.buildingCount, UnitOfMeasure.None) && recipe.recipe.crafters.Length > 0;

if (recipe.builtBuildings != null)
{
if (gui.BuildTextInput(DataUtils.FormatAmount(Convert.ToSingle(recipe.builtBuildings), UnitOfMeasure.None), out var newText, null, Icon.None, true, default, RectAlignment.Middle, SchemeColor.Grey))
{
if (DataUtils.TryParseAmount(newText, out var newAmount, UnitOfMeasure.None))
recipe.RecordUndo().builtBuildings = Convert.ToInt32(newAmount);
}
}
}
else
clicked = gui.BuildFactorioObjectWithAmount(recipe.entity, recipe.buildingCount, UnitOfMeasure.None) && recipe.recipe.crafters.Length > 0;


if (clicked)
Expand Down Expand Up @@ -340,6 +353,17 @@ private void ShowEntityDropPown(ImGui imgui, RecipeRow recipe)
if (gui.BuildButton("Set fixed building count") && gui.CloseDropdown())
recipe.RecordUndo().fixedBuildings = recipe.buildingCount <= 0f ? 1f : recipe.buildingCount;
}

if (recipe.builtBuildings != null)
{
if (gui.BuildButton("Clear built building count") && gui.CloseDropdown())
recipe.RecordUndo().builtBuildings = null;
}
else
{
if (gui.BuildButton("Set built building count") && gui.CloseDropdown())
recipe.RecordUndo().builtBuildings = Math.Max(0, Convert.ToInt32(Math.Ceiling(recipe.buildingCount)));
}

if (recipe.entity != null && gui.BuildButton("Create single building blueprint") && gui.CloseDropdown())
{
Expand Down Expand Up @@ -512,7 +536,7 @@ private void BuildShoppngList(RecipeRow recipeRoot)
if (recipe.entity != null)
{
shopList.TryGetValue(recipe.entity, out var prev);
var count = MathUtils.Ceil(recipe.buildingCount);
var count = MathUtils.Ceil(recipe.builtBuildings ?? recipe.buildingCount);
shopList[recipe.entity] = prev + count;
if (recipe.parameters.modules.modules != null)
{
Expand Down Expand Up @@ -864,7 +888,8 @@ protected override void BuildPageTooltip(ImGui gui, ProductionTable contents)
{WarningFlags.TemperatureForIngredientNotMatch, "This recipe does care about ingridient temperature, and the temperature range does not match"},
{WarningFlags.ReactorsNeighboursFromPrefs, "Assumes reactor formation from preferences"},
{WarningFlags.AssumesNauvisSolarRatio, "Energy production values assumes Nauvis solar ration (70% power output). Don't forget accumulators."},
{WarningFlags.RecipeTickLimit, "Production is limited to 60 recipes per second (1/tick). This interacts weirdly with productivity bonus - actual productivity may be imprecise and may depend on your setup - test your setup before commiting to it."}
{WarningFlags.RecipeTickLimit, "Production is limited to 60 recipes per second (1/tick). This interacts weirdly with productivity bonus - actual productivity may be imprecise and may depend on your setup - test your setup before commiting to it."},
{WarningFlags.ExceedsBuiltCount, "This recipe requires more buildings than are currently built."}
};

private void BuildRecipePad(ImGui gui, RecipeRow row)
Expand Down
9 changes: 8 additions & 1 deletion YAFCmodel/Model/ProductionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,22 @@ public override async Task<string> Solve(ProjectPage page)

}

var builtCountExceeded = false;
for (var i = 0; i < allRecipes.Count; i++)
{
var recipe = allRecipes[i];
recipe.recipesPerSecond = vars[i].SolutionValue();

if (recipe.buildingCount > recipe.builtBuildings)
{
recipe.parameters.warningFlags |= WarningFlags.ExceedsBuiltCount;
builtCountExceeded = true;
}
}

CalculateFlow(null);
solver.Dispose();
return null;
return builtCountExceeded ? "This model requires more buildings than are currently built" : null;
}

private void FindAllRecipeLinks(RecipeRow recipe, List<ProductionLink> sources, List<ProductionLink> targets)
Expand Down
1 change: 1 addition & 0 deletions YAFCmodel/Model/ProductionTableContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public class RecipeRow : ModelObject<ProductionTable>, IModuleFiller
public Goods fuel { get; set; }
public RecipeLinks links { get; internal set; }
public float fixedBuildings { get; set; }
public int? builtBuildings { get; set; }
public bool enabled { get; set; } = true;
public bool hierarchyEnabled { get; internal set; }
public int tag { get; set; }
Expand Down
1 change: 1 addition & 0 deletions YAFCmodel/Model/RecipeParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum WarningFlags
// Solution errors
DeadlockCandidate = 1 << 16,
OverproductionRequired = 1 << 17,
ExceedsBuiltCount = 1 << 18,

// Not implemented warnings
TemperatureForIngredientNotMatch = 1 << 24,
Expand Down