From 33aab11a23ae42df014d04fc48aa9949440caa3e Mon Sep 17 00:00:00 2001 From: Simon Weinberger Date: Fri, 27 Dec 2024 08:53:47 +0100 Subject: [PATCH 1/3] apply base effects to calculations --- Yafc.Model/Model/RecipeParameters.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Yafc.Model/Model/RecipeParameters.cs b/Yafc.Model/Model/RecipeParameters.cs index 19243851..2ccf8ffd 100644 --- a/Yafc.Model/Model/RecipeParameters.cs +++ b/Yafc.Model/Model/RecipeParameters.cs @@ -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; @@ -51,7 +51,7 @@ public static RecipeParameters CalculateParameters(RecipeRow row) { ObjectWithQuality? 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; @@ -59,10 +59,14 @@ public static RecipeParameters CalculateParameters(RecipeRow row) { 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; @@ -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; } @@ -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); } } From 01548580dc2df7ddddddddb370f7986a69c8602e Mon Sep 17 00:00:00 2001 From: Simon Weinberger Date: Fri, 27 Dec 2024 08:54:05 +0100 Subject: [PATCH 2/3] show base effects in module customization UI --- Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs b/Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs index 19b0b2be..a29992a9 100644 --- a/Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs +++ b/Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs @@ -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); From 77abbd6c2a5cffad66f979be17c3c82cf3dd1692 Mon Sep 17 00:00:00 2001 From: Simon Weinberger Date: Fri, 27 Dec 2024 09:09:20 +0100 Subject: [PATCH 3/3] add base effect to entity tooltip --- Yafc/Widgets/ObjectTooltip.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Yafc/Widgets/ObjectTooltip.cs b/Yafc/Widgets/ObjectTooltip.cs index 34e12a45..7d114dfd 100644 --- a/Yafc/Widgets/ObjectTooltip.cs +++ b/Yafc/Widgets/ObjectTooltip.cs @@ -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) {