Skip to content

Commit

Permalink
Base effects other than productivity (#378)
Browse files Browse the repository at this point in the history
Applies the three relevant base effects to recipes and show some more
information in tooltips.

Fixes #372
  • Loading branch information
shpaass authored Jan 7, 2025
2 parents 25f978b + ae1bec3 commit 94f24c6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
24 changes: 16 additions & 8 deletions Yafc.Model/Model/RecipeParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public struct UsedModule {
public int beaconCount;
}

internal class RecipeParameters(float recipeTime, float fuelUsagePerSecondPerBuilding, float productivity, WarningFlags warningFlags, ModuleEffects activeEffects, UsedModule modules) {
internal class RecipeParameters(float recipeTime, float fuelUsagePerSecondPerBuilding, WarningFlags warningFlags, ModuleEffects activeEffects, UsedModule modules) {
public float recipeTime { get; } = recipeTime;
public float fuelUsagePerSecondPerBuilding { get; } = fuelUsagePerSecondPerBuilding;
public float productivity { get; } = productivity;
public float productivity => activeEffects.productivity;
public WarningFlags warningFlags { get; internal set; } = warningFlags;
public ModuleEffects activeEffects { get; } = activeEffects;
public UsedModule modules { get; } = modules;

public static RecipeParameters Empty = new(0, 0, 0, 0, default, default);
public static RecipeParameters Empty = new(0, 0, 0, default, default);

public float fuelUsagePerSecondPerRecipe => recipeTime * fuelUsagePerSecondPerBuilding;

Expand All @@ -51,18 +51,22 @@ public static RecipeParameters CalculateParameters(RecipeRow row) {
ObjectWithQuality<EntityCrafter>? entity = row.entity;
RecipeOrTechnology recipe = row.recipe;
Goods? fuel = row.fuel;
float recipeTime, fuelUsagePerSecondPerBuilding = 0, productivity;
float recipeTime, fuelUsagePerSecondPerBuilding = 0, productivity, speed, consumption;
ModuleEffects activeEffects = default;
UsedModule modules = default;

if (entity == null) {
warningFlags |= WarningFlags.EntityNotSpecified;
recipeTime = recipe.time;
productivity = 0f;
speed = 0;
consumption = 0f;
}
else {
recipeTime = recipe.time / entity.GetCraftingSpeed();
productivity = entity.target.effectReceiver.baseEffect.productivity;
speed = entity.target.effectReceiver.baseEffect.speed;
consumption = entity.target.effectReceiver.baseEffect.consumption;
EntityEnergy energy = entity.target.energy;
float energyUsage = entity.GetPower();
float energyPerUnitOfFuel = 0f;
Expand Down Expand Up @@ -154,11 +158,15 @@ public static RecipeParameters CalculateParameters(RecipeRow row) {

if (entity.target.allowedEffects != AllowedEffects.None && entity.target.allowedModuleCategories is not []) {
row.GetModulesInfo((recipeTime, fuelUsagePerSecondPerBuilding), entity.target, ref activeEffects, ref modules);
productivity += activeEffects.productivity;
recipeTime /= activeEffects.speedMod;
fuelUsagePerSecondPerBuilding *= activeEffects.energyUsageMod;
}

activeEffects.productivity += productivity;
activeEffects.speed += speed;
activeEffects.consumption += consumption;

recipeTime /= activeEffects.speedMod;
fuelUsagePerSecondPerBuilding *= activeEffects.energyUsageMod;

if (energy.drain > 0f) {
fuelUsagePerSecondPerBuilding += energy.drain / energyPerUnitOfFuel;
}
Expand All @@ -170,6 +178,6 @@ public static RecipeParameters CalculateParameters(RecipeRow row) {
}
}

return new RecipeParameters(recipeTime, fuelUsagePerSecondPerBuilding, productivity, warningFlags, activeEffects, modules);
return new RecipeParameters(recipeTime, fuelUsagePerSecondPerBuilding, warningFlags, activeEffects, modules);
}
}
12 changes: 9 additions & 3 deletions Yafc/Widgets/ObjectTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,15 @@ private void BuildEntity(Entity entity, Quality quality, ImGui gui) {
gui.BuildText(DataUtils.FormatAmount(crafter.CraftingSpeed(quality), UnitOfMeasure.Percent, "Crafting speed: "));
}

float productivity = crafter.effectReceiver?.baseEffect.productivity ?? 0;
if (productivity != 0f) {
gui.BuildText(DataUtils.FormatAmount(productivity, UnitOfMeasure.Percent, "Crafting productivity: "));
Effect baseEffect = crafter.effectReceiver.baseEffect;
if (baseEffect.speed != 0f) {
gui.BuildText(DataUtils.FormatAmount(baseEffect.speed, UnitOfMeasure.Percent, "Crafting speed: "));
}
if (baseEffect.productivity != 0f) {
gui.BuildText(DataUtils.FormatAmount(baseEffect.productivity, UnitOfMeasure.Percent, "Crafting productivity: "));
}
if (baseEffect.consumption != 0f) {
gui.BuildText(DataUtils.FormatAmount(baseEffect.consumption, UnitOfMeasure.Percent, "Energy consumption: "));
}

if (crafter.allowedEffects != AllowedEffects.None) {
Expand Down
6 changes: 6 additions & 0 deletions Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ void doToSelectedItem(EntityCrafter selectedCrafter) {
DrawRecipeModules(gui, modules.beacon, ref effects);
}

if (recipe?.entity?.target.effectReceiver.baseEffect is { } baseEffect) {
effects.productivity += baseEffect.productivity;
effects.speed += baseEffect.speed;
effects.consumption += baseEffect.consumption;
}

if (recipe != null) {
float craftingSpeed = (recipe.entity?.GetCraftingSpeed() ?? 1f) * effects.speedMod;
gui.BuildText("Current effects:", Font.subheader);
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
----------------------------------------------------------------------------------------------------------------------
Version:
Date:
Features:
- Apply productivity, speed, and consumption effects to recipes, and show them in tooltips.
Fixes:
- Building emission/absorption (pollution and spores) are displayed in tooltips again.
----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 94f24c6

Please sign in to comment.