Skip to content

Commit

Permalink
feat: apply base effects to calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
SWeini authored and shpaass committed Jan 6, 2025
1 parent 999a3f9 commit 981f1fe
Showing 1 changed file with 16 additions and 8 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);
}
}

0 comments on commit 981f1fe

Please sign in to comment.