-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add support for Program Modifiers #2423
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using KSP.Localization; | ||
using System.Collections.Generic; | ||
using static ConfigNode; | ||
using static RP0.Programs.Program; | ||
|
||
namespace RP0.Programs | ||
{ | ||
public class ProgramModifier : IConfigNode | ||
{ | ||
[Persistent] | ||
public string srcProgram; | ||
[Persistent] | ||
public string tgtProgram; | ||
[Persistent] | ||
public double nominalDurationYears = -1; | ||
[Persistent] | ||
public double baseFunding = -1; | ||
[Persistent] | ||
public string fundingCurve = null; | ||
[Persistent] | ||
public double repDeltaOnCompletePerYearEarly = -1; | ||
[Persistent] | ||
public double repPenaltyPerYearLate = -1; | ||
[Persistent] | ||
public float repToConfidence = -1f; | ||
[Persistent] | ||
public int slots = -1; | ||
public Dictionary<Speed, float> confidenceCosts = new Dictionary<Speed, float>(); | ||
|
||
public ProgramModifier() | ||
{ | ||
} | ||
|
||
public ProgramModifier(ConfigNode n) : this() | ||
{ | ||
Load(n); | ||
} | ||
|
||
public void Load(ConfigNode node) | ||
{ | ||
LoadObjectFromConfig(this, node); | ||
LoadConfidenceCosts(node, confidenceCosts); | ||
} | ||
|
||
public void Save(ConfigNode node) | ||
{ | ||
CreateConfigFromObject(this, node); | ||
} | ||
|
||
public void Apply(Program program) | ||
{ | ||
if (nominalDurationYears != -1) | ||
program.nominalDurationYears = nominalDurationYears; | ||
|
||
if (baseFunding != -1) | ||
program.baseFunding = baseFunding; | ||
|
||
if (fundingCurve != null) | ||
program.fundingCurve = fundingCurve; | ||
|
||
if (repDeltaOnCompletePerYearEarly != -1) | ||
program.repDeltaOnCompletePerYearEarly = repDeltaOnCompletePerYearEarly; | ||
|
||
if (repPenaltyPerYearLate != -1) | ||
program.repPenaltyPerYearLate = repPenaltyPerYearLate; | ||
|
||
if (repToConfidence != -1) | ||
program.repToConfidence = repToConfidence; | ||
|
||
if (slots != -1) | ||
program.slots = slots; | ||
|
||
if (confidenceCosts.Count > 0) | ||
{ | ||
foreach (KeyValuePair<Speed, float> kvp in confidenceCosts) | ||
{ | ||
program.confidenceCosts[kvp.Key] = kvp.Value; | ||
} | ||
} | ||
} | ||
|
||
public override string ToString() => $"{srcProgram} -> {tgtProgram}"; | ||
|
||
public string GetDiffString() | ||
{ | ||
Program baseline = ProgramHandler.ProgramDict[tgtProgram].GetStrategy().Program; | ||
|
||
var sb = StringBuilderCache.Acquire(); | ||
sb.AppendFormat("* {0}\n", baseline.title); | ||
|
||
const string diffFormat = " - {0}: {1} -> {2}\n"; | ||
if (nominalDurationYears != -1 && baseline.nominalDurationYears != nominalDurationYears) | ||
sb.AppendFormat(diffFormat, "Nominal duration (years)", baseline.nominalDurationYears, nominalDurationYears); | ||
|
||
if (baseFunding != -1 && baseline.baseFunding != baseFunding) | ||
sb.AppendFormat(diffFormat, "Total funds", CalcTotalFunding(baseline.baseFunding).ToString("N0"), CalcTotalFunding(baseFunding).ToString("N0")); | ||
|
||
if (fundingCurve != null && baseline.fundingCurve != fundingCurve) | ||
sb.AppendFormat(diffFormat, "Funding curve", baseline.fundingCurve, fundingCurve); | ||
|
||
if (slots != -1 && baseline.slots != slots) | ||
sb.AppendFormat(diffFormat, "Slots", baseline.slots, slots); | ||
|
||
if (confidenceCosts.Count > 0) | ||
{ | ||
foreach (KeyValuePair<Speed, float> kvp in confidenceCosts) | ||
{ | ||
if (baseline.confidenceCosts[kvp.Key] != kvp.Value) | ||
{ | ||
string speedTitle = Localizer.GetStringByTag("#rp0_Admin_Program_Speed" + (int)kvp.Key); | ||
sb.AppendFormat(" - Confidence for {0}: {1} -> {2}\n", speedTitle, baseline.confidenceCosts[kvp.Key], kvp.Value); | ||
} | ||
} | ||
} | ||
|
||
return sb.ToStringAndRelease(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you define two PM config with different source programs that modifies the same target program, you'd apply both and I am not sure the result would be deterministic here or be the intended effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PMs get applied in the order they are configured and thus the effects should be deterministic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So since "modifiers" just a new value configuration, the last one configured is the only one used at the end right? or could we do partial PM configs that could be combined? (One defines nee confidence, one defines new fundingcurve)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They would combine.