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

Base effects other than productivity #378

Open
wants to merge 3 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
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