Skip to content

Commit

Permalink
Showing 7 changed files with 84 additions and 50 deletions.
Binary file modified GameData/RP-0/Plugins/RP0.dll
Binary file not shown.
4 changes: 3 additions & 1 deletion Source/Crew/ActiveCourse.cs
Original file line number Diff line number Diff line change
@@ -181,7 +181,9 @@ public void CompleteCourse()
exp.pcmName = student.name;
exp.expiration = expiration;
if (expirationUseStupid)
exp.expiration *= (1.5d - student.stupidity);
exp.expiration *= UtilMath.Lerp(CrewHandler.Instance.settings.trainingProficiencyStupidMin,
CrewHandler.Instance.settings.trainingProficiencyStupidMax,
student.stupidity);
exp.expiration += Planetarium.GetUniversalTime();
}

11 changes: 7 additions & 4 deletions Source/Crew/CourseTemplate.cs
Original file line number Diff line number Diff line change
@@ -177,11 +177,14 @@ public double GetTime(List<ProtoCrewMember> students)
if (students == null || !timeUseStupid)
return time;

double maxStupid = 0d;
foreach (ProtoCrewMember pcm in students)
maxStupid = Math.Max(pcm.stupidity, maxStupid);
double averageStupid = 0d;
int sC = students.Count;
for(int i = sC; i-- > 0;)
averageStupid += students[i].stupidity;

return time * (0.5d + maxStupid);
averageStupid /= sC;

return time * UtilMath.Lerp(CrewHandler.Instance.settings.trainingMissionStupidMin, CrewHandler.Instance.settings.trainingMissionStupidMax, averageStupid);
}

public double GetExpiration(ProtoCrewMember pcm)
51 changes: 30 additions & 21 deletions Source/Crew/CrewHandler.cs
Original file line number Diff line number Diff line change
@@ -90,6 +90,8 @@ public void Save(ConfigNode node)

#region Fields

public CrewHandlerSettings settings = new CrewHandlerSettings();

protected Dictionary<string, double> kerbalRetireTimes = new Dictionary<string, double>();

protected HashSet<string> retirees = new HashSet<string>();
@@ -165,6 +167,9 @@ public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);

foreach (ConfigNode stg in GameDatabase.Instance.GetConfigNodes("CREWHANDLERSETTINGS"))
settings.Load(stg);

kerbalRetireTimes.Clear();
ConfigNode n = node.GetNode("RETIRETIMES");
if (n != null)
@@ -461,7 +466,7 @@ public void AddExpiration(TrainingExpiration e)
protected void ACSpawn()
{
inAC = true;
countAvailable = countKIA = 0;
countAvailable = countKIA = -1;
}

protected void ACDespawn()
@@ -529,44 +534,45 @@ protected void VesselRecoveryRequested(Vessel v)
double constant = 0.5d;
if (hasSpace)
{
multiplier += 2d;
constant += 2d;
multiplier += settings.recSpace.x;
constant += settings.recSpace.y;
}
if (hasOrbit)
{
multiplier += 5d;
constant += 10d;
multiplier += settings.recOrbit.x;
constant += settings.recOrbit.y;
}
if (hasOther)
{
multiplier += 10d;
constant += 10d;
multiplier += settings.recOtherBody.x;
constant += settings.recOtherBody.y;
}
if (hasEVA)
{
multiplier += 15d;
constant += 20d;
multiplier += settings.recEVA.x;
constant += settings.recEVA.y;
}
if (hasEVAOther)
{
multiplier += 20d;
constant += 25d;
multiplier += settings.recEVAOther.x;
constant += settings.recEVAOther.y;
}
if (hasOrbitOther)
{
multiplier += 15d;
constant += 10d;
multiplier += settings.recOrbitOther.x;
constant += settings.recOrbitOther.y;
}
if (hasLandOther)
{
multiplier += 30d;
constant += 30d;
multiplier += settings.recLandOther.x;
constant += settings.recLandOther.y;
}

double retTime;
if (kerbalRetireTimes.TryGetValue(pcm.name, out retTime))
{
double offset = constant * 86400d * 100d / (1 + curFlight * curFlight) * (0.8d + (1d - pcm.stupidity) * 0.6d);
double offset = constant * 86400d * settings.retireOffsetBaseMult / (1 + Math.Pow(Math.Max(curFlight + settings.retireOffsetFlightNumOffset, 0d), settings.retireOffsetFlightNumPow)
* UtilMath.Lerp(settings.retireOffsetStupidMin, settings.retireOffsetStupidMax, pcm.stupidity));
if (offset > 0d)
{
retTime += offset;
@@ -627,7 +633,9 @@ protected void OnCrewHired(ProtoCrewMember pcm, int idx)

protected double GetServiceTime(ProtoCrewMember pcm)
{
return 86400d * 365d * (5d + pcm.courage * 3d + (1d - pcm.stupidity));
return 86400d * 365d * (settings.retireBaseYears
+ UtilMath.Lerp(settings.retireCourageMin, settings.retireCourageMax, pcm.courage)
+ UtilMath.Lerp(settings.retireStupidMin, settings.retireStupidMax, pcm.stupidity));
}

protected void FixTooltip(KSP.UI.CrewListItem cli)
@@ -770,13 +778,13 @@ protected void GenerateCourseProf(AvailablePart ap)
n.AddValue("id", "prof_" + name);
n.AddValue("name", "Proficiency: " + name);
n.AddValue("time", 1d + (TrainingDatabase.GetTime(name) * 86400d));
n.AddValue("expiration", 4d * 86400d * 365d);
n.AddValue("expiration", settings.trainingProficiencyExpirationYears * 86400d * 365d);
n.AddValue("expirationUseStupid", true);

n.AddValue("conflicts", "TRAINING_proficiency:" + name);

ConfigNode r = n.AddNode("REWARD");
r.AddValue("XPAmt", "1");
r.AddValue("XPAmt", settings.trainingProficiencyXP);
ConfigNode l = r.AddNode("FLIGHTLOG");
l.AddValue("0", "TRAINING_proficiency," + name);

@@ -787,7 +795,7 @@ protected void GenerateCourseProf(AvailablePart ap)
ConfigNode n2 = n.CreateCopy();
n2.SetValue("id", "profR_" + name);
n2.SetValue("name", "Refresher: " + name);
n2.SetValue("time", 1d + TrainingDatabase.GetTime(name) * 86400d * 0.25d);
n2.SetValue("time", 1d + TrainingDatabase.GetTime(name) * 86400d * settings.trainingProficiencyRefresherTimeMult);
n2.AddValue("preReqs", "expired_TRAINING_proficiency:" + name);
r = n2.GetNode("REWARD");
r.SetValue("XPAmt", "0");
@@ -805,8 +813,9 @@ protected void GenerateCourseMission(AvailablePart ap)
n.AddValue("id", "msn_" + name);
n.AddValue("name", "Mission: " + name);
n.AddValue("time", 1d + TrainingDatabase.GetTime(name + "_Mission") * 86400d);
n.AddValue("timeUseStupid", true);
n.AddValue("seatMax", ap.partPrefab.CrewCapacity * 2);
n.AddValue("expiration", 120d * 86400d);
n.AddValue("expiration", settings.trainingMissionExpirationDays * 86400d);

n.AddValue("preReqs", "TRAINING_proficiency:" + name);
n.AddValue("conflicts", "TRAINING_mission:" + name);
23 changes: 0 additions & 23 deletions Source/Crew/CrewHandlerData.cs

This file was deleted.

43 changes: 43 additions & 0 deletions Source/Crew/CrewHandlerSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KSP;
using UnityEngine;
using System.Reflection;

namespace RP0.Crew
{
public class CrewHandlerSettings : IConfigNode
{
[Persistent]
public Vector2 recSpace = new Vector2(2, 2), recOrbit = new Vector2(5, 10), recOtherBody = new Vector2(10, 10),
recEVA = new Vector2(15, 20), recEVAOther = new Vector2(20, 25), recOrbitOther = new Vector2(15, 10), recLandOther = new Vector2(30, 30);

[Persistent]
public double retireOffsetBaseMult = 100d, retireOffsetFlightNumPow = 1.5d, retireOffsetFlightNumOffset = -3d, retireOffsetStupidMin = 1.4d, retireOffsetStupidMax = 0.8d;

[Persistent]
public double retireBaseYears = 5d, retireCourageMin = 0d, retireCourageMax = 3d, retireStupidMin = 1d, retireStupidMax = 0d;

[Persistent]
public double trainingProficiencyExpirationYears = 4d, trainingProficiencyStupidMin = 1.5d, trainingProficiencyStupidMax = 0.5d, trainingProficiencyRefresherTimeMult = 0.25d;

[Persistent]
public int trainingProficiencyXP = 1;

[Persistent]
public double trainingMissionExpirationDays = 120d, trainingMissionStupidMin = 0.5d, trainingMissionStupidMax = 1.5d;


public void Load(ConfigNode node)
{
ConfigNode.LoadObjectFromConfig(this, node);
}

public void Save(ConfigNode node)
{
ConfigNode.CreateConfigFromObject(this, node);
}
}
}
2 changes: 1 addition & 1 deletion Source/RP0.csproj
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@
<ItemGroup>
<Compile Include="Crew\ActiveCourse.cs" />
<Compile Include="Crew\CourseTemplate.cs" />
<Compile Include="Crew\CrewHandlerData.cs" />
<Compile Include="Crew\CrewHandlerSettings.cs" />
<Compile Include="Crew\TrainingDatabase.cs" />
<Compile Include="Crew\FSGUI.cs" />
<Compile Include="EntryCostStorage.cs" />

0 comments on commit c18dc8e

Please sign in to comment.