Skip to content

Commit

Permalink
fix(#381): Rocket launch recipes use rocket capacity, not stack size. (
Browse files Browse the repository at this point in the history
…#406)

Py launch recipes now consume 5 items, instead of 1, and scale up their
output accordingly.

The satellite and space platform launch recipes are still correct. Fish
launch goes to 300 in SA instead of 100 in vanilla, but that's both a
rarely-modeled recipe and a justifiable result.
  • Loading branch information
shpaass authored Feb 4, 2025
2 parents c7fa6c6 + 2ff5108 commit f3603ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Yafc.Model/Data/DataClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ string IFactorioObjectWrapper.text {
}
}
float IFactorioObjectWrapper.amount => amount;

public static Product operator *(Product product, int factor) =>
new(product.goods, product.amountMin * factor, product.amountMax * factor, product.probability);
}

// Abstract base for anything that can be produced or consumed by recipes (etc)
Expand Down Expand Up @@ -669,6 +672,9 @@ public class EntityCrafter : EntityWithModules {
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;
// For rocket silos, the number of inventory slots. Launch recipes are limited by both weight and available slots.
internal int rocketInventorySize;

public virtual float baseCraftingSpeed {
// The speed of a lab is baseSpeed * (1 + researchSpeedBonus) * Math.Min(0.2, 1 + moduleAndBeaconSpeedBonus)
get => _craftingSpeed * (1 + (factorioType == "lab" ? Project.current.settings.researchSpeedBonus : 0));
Expand Down
24 changes: 21 additions & 3 deletions Yafc.Parser/Data/FactorioDataDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using SDL2;
using Serilog;
Expand Down Expand Up @@ -558,11 +557,28 @@ private void CalculateItemWeights() {
nextWeightCalculation:;
}

// If it doesn't otherwise have a weight, it gets the default weight.
List<EntityCrafter> rocketSilos = registeredObjects.Values.OfType<EntityCrafter>().Where(e => e.factorioType == "rocket-silo").ToList();
int maxStacks = 1;// if we have no rocket silos, default to one stack.
if (rocketSilos.Count > 0) {
maxStacks = rocketSilos.Max(r => r.rocketInventorySize);
}

foreach (Item item in allObjects.OfType<Item>()) {
// If it doesn't otherwise have a weight, it gets the default weight.
if (item.weight == 0) {
item.weight = defaultItemWeight;
}

if (registeredObjects.TryGetValue((typeof(Mechanics), SpecialNames.RocketLaunch + "." + item.name), out FactorioObject? r)
&& r is Mechanics recipe) {

// The item count is initialized to 1, but it should be the rocket capacity. Scale up the ingredient and product(s).
int factor = Math.Min(rocketCapacity / item.weight, maxStacks * item.stackSize);
recipe.ingredients[0] = new(item, factor);
for (int i = 0; i < recipe.products.Length; i++) {
recipe.products[i] *= factor;
}
}
}
}

Expand All @@ -576,7 +592,9 @@ private void EnsureLaunchRecipe(Item item, Product[]? launchProducts) {
Recipe recipe = CreateSpecialRecipe(item, SpecialNames.RocketLaunch, "launched");
recipe.ingredients =
[
new Ingredient(item, item.stackSize),
// When this is called, we don't know the item weight or the rocket capacity.
// CalculateItemWeights will scale this ingredient and the products appropriately (but not the launch slot)
new Ingredient(item, 1),
new Ingredient(rocketLaunch, 1),
];
recipe.products = launchProducts ?? recipe.products ?? [];
Expand Down
2 changes: 2 additions & 0 deletions Yafc.Parser/Data/FactorioDataDeserializer_Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ private void DeserializeEntity(LuaTable table, ErrorCollector errorCollector) {
}
}
}

crafter.rocketInventorySize = rocketInventorySize;
}
}
break;
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Version:
Date:
Features:
- Detect lightning rods/collectors as electricity sources, and estimate the required accumulator count.
Fixes:
- When creating launch recipes, obey the rocket capacity, not the item stack size.
----------------------------------------------------------------------------------------------------------------------
Version: 2.7.0
Date: January 27th 2025
Expand Down

0 comments on commit f3603ca

Please sign in to comment.