Skip to content

Commit

Permalink
Show the total I/O for unloading crafters when they output multiple p…
Browse files Browse the repository at this point in the history
…roducts.
  • Loading branch information
veger committed Oct 31, 2024
1 parent f9947ad commit 5a534c1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions Yafc.Model/Data/DataClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ public static bool CanAcceptModule(ModuleSpecification module, AllowedEffects ef
public class EntityCrafter : EntityWithModules {
public int itemInputs { get; internal set; }
public int fluidInputs { get; internal set; } // fluid inputs for recipe, not including power
public bool hasVectorToPlaceResult { get; internal set; }
public Goods[]? inputs { get; internal set; }
public RecipeOrTechnology[] recipes { get; internal set; } = null!; // null-forgiving: Set in the first step of CalculateMaps
private float _craftingSpeed = 1;
Expand Down
20 changes: 16 additions & 4 deletions Yafc.Model/Model/ProductionTableContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,21 @@ public class RecipeRow : ModelObject<ProductionTable>, IGroupedElement<Productio
public EntityCrafter? entity {
get => _entity;
set {
if (SerializationMap.IsDeserializing || fixedBuildings == 0 || _entity == value) {
if (_entity == value) {
// Nothing to do
return;
}

if (SerializationMap.IsDeserializing) {
// Just apply the deserialized entity and stop further processing
_entity = value;
return;
}
else if (fixedFuel && !(value?.energy.fuels ?? []).Contains(_fuel)) {
// We're changing both the entity and the fuel (changing between electric, fluid-burning, item-burning, heat-powered, and steam-powered crafter categories)
// Don't try to preserve fuel consumption in this case.

if (fixedBuildings == 0 || (fixedFuel && !(value?.energy.fuels ?? []).Contains(_fuel))) {
// We're either changing both the entity and the fuel (changing between electric, fluid-burning, item-burning, heat-powered, and steam-powered crafter categories),
// or fixedBuilding is zero.
// Don't try to preserve fuel consumption in these cases.
fixedBuildings = 0;
_entity = value;
}
Expand All @@ -264,6 +273,9 @@ public EntityCrafter? entity {
_entity = value;
}
}

// By default show the total item consumption and production signals for unloading crafters (miners, recyclers, etc) when they output multiple products.
showTotalIO |= value?.hasVectorToPlaceResult == true && recipe.products.Length > 1;
}
}
public Goods? fuel {
Expand Down
7 changes: 7 additions & 0 deletions Yafc.Parser/Data/FactorioDataDeserializer_Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ private void DeserializeEntity(LuaTable table, ErrorCollector errorCollector) {
crafter.fluidInputs = CountFluidBoxes(fluidBoxes, true);
}

if (table.Get("vector_to_place_result", out LuaTable? hasVectorToPlaceResult)) {
crafter.hasVectorToPlaceResult = hasVectorToPlaceResult != null;
}

Recipe? fixedRecipe = null;

if (table.Get("fixed_recipe", out string? fixedRecipeName)) {
Expand Down Expand Up @@ -360,6 +364,9 @@ private void DeserializeEntity(LuaTable table, ErrorCollector errorCollector) {
drill.fluidInputs = 1;
}

// All drills have/require the vector_to_place_result to drop their items
drill.hasVectorToPlaceResult = true;

foreach (string resource in resourceCategories.ArrayElements<string>()) {
recipeCrafters.Add(drill, SpecialNames.MiningRecipe + resource);
}
Expand Down

0 comments on commit 5a534c1

Please sign in to comment.