Skip to content

Commit

Permalink
Convert UnlockSubsidyHandler to UnlockCreditHandler - now only track …
Browse files Browse the repository at this point in the history
…total unlock credit. Add an upgrade script to transition.
  • Loading branch information
NathanKell committed Jun 26, 2023
1 parent 1b1263c commit aba0cac
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 538 deletions.
2 changes: 1 addition & 1 deletion GameData/RP-1/Localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
#rp0_FacilityContextMenu_UpgradeInProgress = Construction already in progress!

// Unlock Credit
#rp0_UnlockCredit_NodeInfo = Unlock Credit: <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1><<1>>\nIncluding Parents: <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1><<2>>
#rp0_UnlockCredit_NodeInfo = Unlock Credit: <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1><<1>>
#rp0_UnlockCredit_CostAfterCredit = Cost after Credit: √<<1>>


Expand Down
2 changes: 1 addition & 1 deletion GameData/RP-1/Localization/zh-cn.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Localization
#rp0_FacilityContextMenu_UpgradeInProgress = 正在进行建设中!

// Unlock Credit
#rp0_UnlockCredit_NodeInfo = 解锁的贷款额度: <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1><<1>>\nIncluding Parents: <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1><<2>>
#rp0_UnlockCredit_NodeInfo = 解锁的贷款额度: <sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1><<1>>
#rp0_UnlockCredit_CostAfterCredit = 除去贷款后价格: √<<1>>


Expand Down
2 changes: 1 addition & 1 deletion Source/Avionics/ProceduralAvionicsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private bool DrawUnlockButton(string curCfgName, ProceduralAvionicsTechNode tech
if (unlockCost <= 0) return switchedConfig;
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.PartOrUpgradeUnlock, -unlockCost, 0d, 0d);
double trueCost = -cmq.GetTotal(CurrencyRP0.Funds);
double creditToUse = Math.Min(trueCost, UnlockSubsidyHandler.Instance.GetCreditAmount(techNode.TechNodeName));
double creditToUse = Math.Min(trueCost, UnlockCreditHandler.Instance.GetCreditAmount(techNode.TechNodeName));
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, creditToUse);
GUI.enabled = techNode.IsAvailable && cmq.CanAfford();
_gc.text = $"Unlock ({BuildCostString(Math.Max(0d, trueCost - creditToUse), trueCost)})";
Expand Down
2 changes: 1 addition & 1 deletion Source/Harmony/PartListTooltip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void PatchButtons(PartListTooltip __instance, AvailablePart avail
else if (__instance.buttonPurchase.gameObject.activeSelf || __instance.buttonPurchaseRed.gameObject.activeSelf)
{
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.PartOrUpgradeUnlock, -eCost, 0d, 0d);
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, Math.Min(-cmq.GetTotal(CurrencyRP0.Funds), UnlockSubsidyHandler.Instance.GetCreditAmount(techID)));
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, Math.Min(-cmq.GetTotal(CurrencyRP0.Funds), UnlockCreditHandler.Instance.GetCreditAmount(techID)));
// If we still can't afford, bail without setting tooltip
if (!cmq.CanAfford())
return;
Expand Down
3 changes: 1 addition & 2 deletions Source/Harmony/RDController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ internal static void Postfix_ShowNodePanel(RDController __instance, RDNode node)
if (showCredit)
{
extraText = Localizer.Format("#rp0_UnlockCredit_NodeInfo",
UnlockSubsidyHandler.Instance.GetLocalCreditAmount(node.tech.techID).ToString("N0"),
UnlockSubsidyHandler.Instance.GetCreditAmount(node.tech.techID).ToString("N0")) + "\n";
UnlockCreditHandler.Instance.GetCreditAmount(node.tech.techID).ToString("N0")) + "\n";
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Harmony/RDPartList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static bool Prefix_AddPartListItem(RDPartList __instance, AvailablePart
if (!cmq.CanAfford())
{
// try again, with credit
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, System.Math.Min(-cmq.GetTotal(CurrencyRP0.Funds), UnlockSubsidyHandler.Instance.GetCreditAmount(part.TechRequired)));
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, System.Math.Min(-cmq.GetTotal(CurrencyRP0.Funds), UnlockCreditHandler.Instance.GetCreditAmount(part.TechRequired)));
if (!cmq.CanAfford())
{
// still can't afford, so use the can't afford color
Expand Down Expand Up @@ -75,7 +75,7 @@ private static bool Prefix_AddUpgradeListItem(RDPartList __instance, PartUpgrade
// BUT if we can't afford normally, but can with credit let's fix the coloring.
if (!cmq.CanAfford())
{
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, System.Math.Min(-cmq.GetTotal(CurrencyRP0.Funds), UnlockSubsidyHandler.Instance.GetCreditAmount(upgrade.techRequired)));
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, System.Math.Min(-cmq.GetTotal(CurrencyRP0.Funds), UnlockCreditHandler.Instance.GetCreditAmount(upgrade.techRequired)));
if (!cmq.CanAfford())
{
cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.PartOrUpgradeUnlock, -upgrade.entryCost, 0d, 0d);
Expand Down
4 changes: 2 additions & 2 deletions Source/Harmony/RealFuels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ internal static bool PatchedPurchaseConfig(RealFuels.EntryCostManager __instance
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.PartOrUpgradeUnlock, -cfgCost, 0d, 0d);
double postCMQcost = -cmq.GetTotal(CurrencyRP0.Funds);
double invertCMQop = cfgCost / postCMQcost;
double credit = UnlockSubsidyHandler.Instance.GetCreditAmount(techNode);
double credit = UnlockCreditHandler.Instance.GetCreditAmount(techNode);
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, credit);
if (!cmq.CanAfford())
{
return false;
}

double excessCost = UnlockSubsidyHandler.Instance.SpendCredit(techNode, postCMQcost);
double excessCost = UnlockCreditHandler.Instance.SpendCredit(techNode, postCMQcost);
if (excessCost > 0d)
{
Funding.Instance.AddFunds(-excessCost * invertCMQop, TransactionReasonsRP0.PartOrUpgradeUnlock.Stock());
Expand Down
2 changes: 1 addition & 1 deletion Source/Harmony/ScienceWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static string GetTooltipText()
{
return Localizer.Format("#rp0_Widgets_Science_Tooltip",
System.Math.Max(0, KerbalConstructionTimeData.Instance.SciPointsTotal).ToString("N1"),
UnlockSubsidyHandler.Instance.TotalCredit.ToString("N0"));
UnlockCreditHandler.Instance.TotalCredit.ToString("N0"));
}
}
}
4 changes: 2 additions & 2 deletions Source/KerbalConstructionTime/BuildItems/TechItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ public double IncrementProgress(double UTDiff)
KCTGameStates.RecalculateBuildRates(); // this might change other rates

double portion = toGo / increment;
RP0.UnlockSubsidyHandler.Instance.IncrementCreditTime(techID, portion * UTDiff);
RP0.UnlockCreditHandler.Instance.IncrementCreditTime(techID, portion * UTDiff);
return (1d - portion) * UTDiff;
}

RP0.UnlockSubsidyHandler.Instance.IncrementCreditTime(techID, UTDiff);
RP0.UnlockCreditHandler.Instance.IncrementCreditTime(techID, UTDiff);
return 0d;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/KerbalConstructionTime/Utilities/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public static int FindUnlockCost(List<AvailablePart> availableParts)
public static void UnlockExperimentalParts(List<AvailablePart> availableParts)
{
// this will spend the funds, which is why we set costsFunds=false below.
RP0.UnlockSubsidyHandler.Instance.SpendCreditAndCost(availableParts);
RP0.UnlockCreditHandler.Instance.SpendCreditAndCost(availableParts);

foreach (var ap in availableParts)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/KerbalConstructionTime/VesselBuildValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void ProcessPartAvailability(BuildListVessel blv)
var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.PartOrUpgradeUnlock, -unlockCost, 0d, 0d);
double postCMQUnlockCost = -cmq.GetTotal(CurrencyRP0.Funds);

double credit = UnlockSubsidyHandler.Instance.GetCreditAmount(partList);
double credit = UnlockCreditHandler.Instance.GetCreditAmount(partList);

double spentCredit = Math.Min(postCMQUnlockCost, credit);
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, spentCredit);
Expand Down Expand Up @@ -374,7 +374,7 @@ private DialogGUIBase[] ConstructPartConfigErrorsUI(Dictionary<Part, List<PartCo
string costStr = cmq.GetCostLineOverride(true, false, false, true);
double trueTotal = -cmq.GetTotal(CurrencyRP0.Funds);
double invertCMQOp = error.CostToResolve / trueTotal;
double creditAmtToUse = Math.Min(trueTotal, UnlockSubsidyHandler.Instance.GetCreditAmount(error.TechToResolve));
double creditAmtToUse = Math.Min(trueTotal, UnlockCreditHandler.Instance.GetCreditAmount(error.TechToResolve));
cmq.AddDeltaAuthorized(CurrencyRP0.Funds, creditAmtToUse);
string afterCreditLine = cmq.GetCostLineOverride(true, false, true, true);
if (string.IsNullOrEmpty(afterCreditLine))
Expand Down
6 changes: 3 additions & 3 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
[assembly: AssemblyInformationalVersion("@ASSEMBLYINFORMATIONALVERSION@")]
[assembly: KSPAssembly("RP-0", @MAJOR@, @MINOR@)]
#else
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0.0")]
[assembly: KSPAssembly("RP-0", 2, 0)]
[assembly: AssemblyFileVersion("2.3.0.0")]
[assembly: AssemblyInformationalVersion("2.3.0.0")]
[assembly: KSPAssembly("RP-0", 2, 3)]
#endif

[assembly: KSPAssemblyDependency("ModularFlightIntegrator", 1, 0)]
Expand Down
4 changes: 3 additions & 1 deletion Source/RP0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<Compile Include="Harmony\RealFuels.cs" />
<Compile Include="Harmony\Strategy.cs" />
<Compile Include="Harmony\StrategySystemConfig.cs" />
<Compile Include="UnlockSubsidyHandler.cs" />
<Compile Include="UnlockCreditHandler.cs" />
<Compile Include="LocalizationHandler.cs" />
<Compile Include="EntryCostStorage.cs" />
<Compile Include="FirstStart.cs" />
Expand Down Expand Up @@ -191,6 +191,7 @@
<Compile Include="Tooling\ToolingScenario.cs" />
<Compile Include="Tooling\ModuleToolingPTank.cs" />
<Compile Include="UI\TooltipController_TextFunc.cs" />
<Compile Include="UpgradeScripts\UpgradeUnlockCredit.cs" />
<Compile Include="Utilities\BypassCertificateHandler.cs" />
<Compile Include="Utilities\CSV\CsvWriter.cs" />
<Compile Include="Utilities\ContinuousLogger.cs" />
Expand Down Expand Up @@ -392,6 +393,7 @@
<Publicize Include="Assembly-CSharp" />
<DoNotPublicize Include="Assembly-CSharp:BaseField`1.OnValueModified" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
</PropertyGroup>
Expand Down
Loading

0 comments on commit aba0cac

Please sign in to comment.