forked from ShadowTheAge/yafc
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lightning): Estimate required accumulators for lightning attract…
…ors.
- Loading branch information
Showing
8 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
This is the math used to calculate `requiredChargeMw` (called "_cap_" here) in `BuildAccumulatorView`. | ||
The first two equations are the starting point, and the remainder are solving for _cap_. | ||
|
||
_chargeTime_ is per lightning strike. | ||
_eff_ is the efficiency of the lightning attractor. | ||
|
||
$$chargeTime=\frac{1000MJ\times eff}{drain+cap+load}$$ | ||
$$cap\times chargeTime\times numStrikes-load\times(stormTime-chargeTime\times numStrikes)=reqMj$$ | ||
$$\frac{cap\times 1000MJ\times eff\times numStrikes}{drain+cap+load}-load\times\left(stormTime-\frac{1000MJ\times eff\times numStrikes}{drain+cap+load}\right)=reqMj$$ | ||
$$\frac{cap\times 1000MJ\times eff\times numStrikes}{drain+cap+load}-load\times stormTime+\left(\frac{load\times 1000MJ\times eff\times numStrikes}{drain+cap+load}\right)=reqMj$$ | ||
$$\frac{cap\times 1000MJ\times eff\times numStrikes-load\times stormTime\times(drain+cap+load)+load\times 1000MJ\times eff\times numStrikes}{drain+cap+load}=reqMj$$ | ||
$$cap\times 1000MJ\times eff\times numStrikes-load\times stormTime\times(drain+cap+load)+load\times 1000MJ\times eff\times numStrikes\\ | ||
=reqMj\times(drain+cap+load)$$ | ||
$$cap\times 1000MJ\times eff\times numStrikes-load\times stormTime\times drain-load\times stormTime\times cap\\ | ||
-\ load\times stormTime\times load+load\times 1000MJ\times eff\times numStrikes\\ | ||
=reqMj\times drain+reqMj\times cap+reqMj\times load$$ | ||
$$cap\times 1000MJ\times eff\times numStrikes-load\times stormTime\times cap-reqMj\times cap\\ | ||
\begin{aligned} | ||
=\ &reqMj\times drain+reqMj\times load+load\times stormTime\times drain\\ | ||
&+load\times stormTime\times load-load\times 1000MJ\times eff\times numStrikes | ||
\end{aligned}$$ | ||
$$\begin{aligned} | ||
cap\times(&1000MJ\times eff\times numStrikes-load\times stormTime-reqMj)\\ | ||
&=reqMj\times drain+load\times(reqMj+stormTime\times drain+stormTime\times load-1000MJ\times eff\times numStrikes) | ||
\end{aligned}$$ | ||
$$cap=\frac{reqMj\times drain+load\times(reqMj+stormTime\times(drain+load)-1000MJ\times eff\times numStrikes)}{1000MJ\times eff\times numStrikes-load\times stormTime-reqMj}$$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
namespace Yafc.Model; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Yafc.Model; | ||
|
||
public static class QualityExtensions { | ||
public static float GetCraftingSpeed(this IObjectWithQuality<EntityCrafter> crafter) => crafter.target.CraftingSpeed(crafter.quality); | ||
|
||
public static float GetPower(this IObjectWithQuality<Entity> entity) => entity.target.Power(entity.quality); | ||
|
||
public static float GetBeaconEfficiency(this IObjectWithQuality<EntityBeacon> beacon) => beacon.target.BeaconEfficiency(beacon.quality); | ||
|
||
public static float GetAttractorEfficiency(this IObjectWithQuality<EntityAttractor> attractor) | ||
=> attractor.target.Efficiency(attractor.quality); | ||
|
||
public static float StormPotentialPerTick(this IObjectWithQuality<EntityAttractor> attractor) | ||
=> attractor.target.StormPotentialPerTick(attractor.quality); | ||
|
||
/// <summary> | ||
/// If possible, converts an <see cref="IObjectWithQuality{T}"/> into one with a different generic parameter. | ||
/// </summary> | ||
/// <typeparam name="T">The desired type parameter for the output <see cref="IObjectWithQuality{T}"/>.</typeparam> | ||
/// <param name="obj">The input <see cref="IObjectWithQuality{T}"/> to be converted.</param> | ||
/// <param name="result">If <c><paramref name="obj"/>?.target is <typeparamref name="T"/></c>, an <see cref="IObjectWithQuality{T}"/> with | ||
/// the same target and quality as <paramref name="obj"/>. Otherwise, <see langword="null"/>.</param> | ||
/// <returns><see langword="true"/> if the conversion was successful, or <see langword="false"/> if it was not.</returns> | ||
public static bool Is<T>(this IObjectWithQuality<FactorioObject>? obj, [NotNullWhen(true)] out IObjectWithQuality<T>? result) where T : FactorioObject { | ||
if (obj is null or IObjectWithQuality<T>) { | ||
result = obj as IObjectWithQuality<T>; | ||
return result is not null; | ||
} | ||
// Use the conversion because it permits a null target. The constructor does not. | ||
result = (ObjectWithQuality<T>?)(obj.target as T, obj.quality); | ||
return result is not null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ dylib | |
Factorio | ||
Floodfill | ||
foreach | ||
Fulgoran | ||
imgui | ||
Kovarex | ||
liblua | ||
|