Skip to content

Commit

Permalink
Unlock credit by step function
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanKell committed Aug 7, 2023
1 parent 298f9c7 commit 145ea91
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
9 changes: 6 additions & 3 deletions GameData/RP-1/MaintenanceSettings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ MAINTENANCESETTINGS
salaryResearchers = 600
researchersToUnlockCreditSalaryMultiplier
{
key = 300 0.6 0 0
key = 600 0.35
key = 1600 0.2 0 0
150 = 0.6
300 = 0.5
600 = 0.35
1000 = 0.25
1600 = 0.2
9999999 = 0.15
}
nautYearlyUpkeepAdd = 10000
nautYearlyUpkeepBase = 2500
Expand Down
6 changes: 4 additions & 2 deletions Source/Maintenance/MaintenanceSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace RP0
using RP0.DataTypes;

namespace RP0
{
public class MaintenanceSettings
{
Expand All @@ -15,7 +17,7 @@ public class MaintenanceSettings
public int salaryResearchers = 1000;

[Persistent]
public FloatCurve researchersToUnlockCreditSalaryMultiplier = new FloatCurve();
public PersistentSortedListValueTypes<int, double> researchersToUnlockCreditSalaryMultiplier = new PersistentSortedListValueTypes<int, double>();

[Persistent]
public double hangarCostForMaintenanceOffset = 240000d;
Expand Down
27 changes: 24 additions & 3 deletions Source/UnlockCreditHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,30 @@ public class UnlockCreditHandler : ScenarioModule

public double TotalCredit => _totalCredit;

public double CreditForTime(double UT) => UT
* MaintenanceHandler.Instance.ResearchSalaryPerDay * (1d / 86400d)
* MaintenanceHandler.Settings.researchersToUnlockCreditSalaryMultiplier.Evaluate((float)MaintenanceHandler.Instance.Researchers);
public double CreditForTime(double UT)
{
double sum = 0d;
double mult = UT * MaintenanceHandler.Settings.salaryResearchers * (1d / (86400d * 365.25d));

int res = KerbalConstructionTimeData.Instance.Researchers;
int totalCounted = 0;

foreach (var kvp in MaintenanceHandler.Settings.researchersToUnlockCreditSalaryMultiplier)
{
if (totalCounted >= res)
break;

int amountToCount = kvp.Key - totalCounted;
int remaining = res - totalCounted;
if (amountToCount > remaining)
amountToCount = remaining;

sum += amountToCount * kvp.Value;
totalCounted += amountToCount;
}

return sum * mult;
}

public double GetCreditAmount(string tech) => _totalCredit;
public double GetCreditAmount(List<AvailablePart> partList) => _totalCredit;
Expand Down

0 comments on commit 145ea91

Please sign in to comment.