Skip to content

Commit

Permalink
Showing 11 changed files with 121 additions and 82 deletions.
62 changes: 0 additions & 62 deletions GameData/RP-0/Plugins/Courses.cfg

This file was deleted.

Binary file modified GameData/RP-0/Plugins/RP0.dll
Binary file not shown.
Binary file modified GameData/RP-0/Plugins/RP0KCTBinder.dll
Binary file not shown.
13 changes: 9 additions & 4 deletions Source/Crew/ActiveCourse.cs
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ public class ActiveCourse : CourseTemplate
public List<ProtoCrewMember> Students = new List<ProtoCrewMember>();

public double elapsedTime = 0;
public double startTime = 0d;
public bool Started = false, Completed = false;


@@ -30,6 +31,7 @@ public ConfigNode AsConfigNode()
ConfigNode node = new ConfigNode("ACTIVE_COURSE");
node.AddValue("id", id);
node.AddValue("name", name);
node.AddValue("startTime", startTime);
node.AddValue("elapsedTime", elapsedTime);
node.AddValue("Started", Started);
node.AddValue("Completed", Completed);
@@ -45,6 +47,7 @@ public ConfigNode AsConfigNode()

public void FromConfigNode(ConfigNode node)
{
node.TryGetValue("startTime", ref startTime);
node.TryGetValue("elapsedTime", ref elapsedTime);
node.TryGetValue("Started", ref Started);
node.TryGetValue("Completed", ref Completed);
@@ -103,16 +106,18 @@ public void RemoveStudent(string student)
RemoveStudent(HighLogic.CurrentGame.CrewRoster[student]);
}

public bool ProgressTime(double dT)
public bool ProgressTime(double curT)
{
if (!Started)
return false;
if (!Completed)
{
elapsedTime += dT;
Completed = elapsedTime >= time;
{
UnityEngine.Debug.Log("Course " + id + " applying " + curT);
elapsedTime = curT - startTime;
Completed = curT > startTime + time;
if (Completed) //we finished the course!
{
UnityEngine.Debug.Log("Course " + id + " COMPLETE");
CompleteCourse();
}
}
2 changes: 1 addition & 1 deletion Source/Crew/CourseTemplate.cs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public class CourseTemplate

public string[] classes = { }; //which classes can take this course (empty == all)
public int minLevel = 0; //minimum kerbal level required to take the course
public int maxLevel = 5; //max kerbal level allowed to take the course
public int maxLevel = 99; //max kerbal level allowed to take the course

public int seatMax = -1; //maximum number of kerbals allowed in the course at once
public int seatMin = 0; //minimum number of kerbals required to start the course
49 changes: 40 additions & 9 deletions Source/Crew/CrewHandler.cs
Original file line number Diff line number Diff line change
@@ -32,10 +32,7 @@ public class CrewHandler : ScenarioModule
[KSPField(isPersistant = true)]
public double nextUpdate = -1d;

[KSPField(isPersistant = true)]
public double lastUpdate = 0d;

protected double updateInterval = 86400d;
protected double updateInterval = 3600d;



@@ -75,6 +72,7 @@ public override void OnAwake()
GameEvents.OnCrewmemberHired.Add(OnCrewHired);
GameEvents.onGUIAstronautComplexSpawn.Add(ACSpawn);
GameEvents.onGUIAstronautComplexDespawn.Add(ACDespawn);
GameEvents.OnPartPurchased.Add(new EventData<AvailablePart>.OnEvent(onPartPurchased));

cliTooltip = typeof(KSP.UI.CrewListItem).GetField("tooltipController", BindingFlags.NonPublic | BindingFlags.Instance);

@@ -177,8 +175,6 @@ public void Update()
if (nextUpdate < time)
{
nextUpdate = time + updateInterval;
double delta = time - lastUpdate;
lastUpdate = time;

foreach (KeyValuePair<string, double> kvp in kerbalRetireTimes)
{
@@ -226,13 +222,12 @@ public void Update()
toRemove.Clear();
}

for (int i = 0; i < ActiveCourses.Count; i++)
for (int i = ActiveCourses.Count; i-- > 0;)
{
ActiveCourse course = ActiveCourses[i];
if (course.ProgressTime(delta)) //returns true when the course completes
if (course.ProgressTime(time)) //returns true when the course completes
{
ActiveCourses.RemoveAt(i);
i--;
}
}
}
@@ -311,6 +306,7 @@ public void OnDestroy()
GameEvents.OnCrewmemberHired.Remove(OnCrewHired);
GameEvents.onGUIAstronautComplexSpawn.Remove(ACSpawn);
GameEvents.onGUIAstronautComplexDespawn.Remove(ACDespawn);
GameEvents.OnPartPurchased.Remove(new EventData<AvailablePart>.OnEvent(onPartPurchased));
}

#endregion
@@ -524,10 +520,45 @@ protected void GenerateOfferedCourses() //somehow provide some variable options
OfferedCourses.Add(duplicate);
}

foreach (AvailablePart ap in PartLoader.LoadedPartsList)
{
if (ap.partPrefab.CrewCapacity > 0 /*&& ap.TechRequired != "start"*/)
{
if (ResearchAndDevelopment.PartModelPurchased(ap))
{
OfferedCourses.Add(GenerateCourseForPart(ap));
}
}
}

Debug.Log("[FS] Offering " + OfferedCourses.Count + " courses.");
//fire an event to let other mods add available courses (where they can pass variables through then)
}

protected CourseTemplate GenerateCourseForPart(AvailablePart ap)
{
ConfigNode n = new ConfigNode("FS_COURSE");
{
n.AddValue("id", "prof_" + ap.name);
n.AddValue("name", ap.title);
n.AddValue("time", 3600d + EntryCostStorage.GetCost(ap.name) * 5177d);

ConfigNode r = n.AddNode("REWARD");
r.AddValue("XPAmt", "1");
ConfigNode l = r.AddNode("FLIGHTLOG");
l.AddValue("0", "TRAINING_proficiency," + ap.name);
}
CourseTemplate c = new CourseTemplate(n);
c.PopulateFromSourceNode();

return c;
}

protected void onPartPurchased(AvailablePart ap)
{
OfferedCourses.Add(GenerateCourseForPart(ap));
}

#endregion
}
}
10 changes: 5 additions & 5 deletions Source/Crew/FSGUI.cs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ protected void DrawMainGUI(int windowID)

GUILayout.BeginVertical(GUILayout.Width(250)); //offered/active list
int oldStatus = offeredActiveToolbar;
offeredActiveToolbar = GUILayout.Toolbar(offeredActiveToolbar, new string[] { "Offered", "Active" });
offeredActiveToolbar = GUILayout.Toolbar(offeredActiveToolbar, new string[] { "Proficiencies", "Active Training" });
if (offeredActiveToolbar != oldStatus)
{
selectedCourse = null;
@@ -44,7 +44,7 @@ protected void DrawMainGUI(int windowID)
{
foreach (CourseTemplate template in CrewHandler.Instance.OfferedCourses)
{
if (GUILayout.Button(template.id + " - " + template.name))
if (GUILayout.Button(template.name))
{
selectedCourse = new ActiveCourse(template);
}
@@ -54,7 +54,7 @@ protected void DrawMainGUI(int windowID)
{
foreach (ActiveCourse course in CrewHandler.Instance.ActiveCourses)
{
if (GUILayout.Button(course.id + " - " + course.name)) //show percent complete?
if (GUILayout.Button(course.name)) //show percent complete?
{
selectedCourse = course;
}
@@ -70,7 +70,7 @@ protected void DrawMainGUI(int windowID)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(selectedCourse.id + " - " + selectedCourse.name);
GUILayout.Label(selectedCourse.name);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

@@ -144,7 +144,7 @@ protected void DrawMainGUI(int windowID)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(selectedCourse.id + " - " + selectedCourse.name);
GUILayout.Label(selectedCourse.name);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

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

namespace RP0
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class EntryCostStorage : MonoBehaviour
{
protected static Dictionary<string, int> originalEntryCosts = new Dictionary<string, int>();

public static int GetCost(string partName)
{
int tmp;
if (originalEntryCosts.TryGetValue(partName, out tmp))
return tmp;

return 0;
}

protected bool run = true;

public void Update()
{
if (run)
{
originalEntryCosts.Clear();

foreach (AvailablePart ap in PartLoader.LoadedPartsList)
originalEntryCosts[ap.name] = ap.entryCost;

run = false;

GameObject.Destroy(this);
}
}
}
}
22 changes: 22 additions & 0 deletions Source/KCTBinderModule.cs
Original file line number Diff line number Diff line change
@@ -20,6 +20,28 @@ public class KCTBinderModule : ScenarioModule
protected bool skipOne = true;
protected bool skipTwo = true;

public override void OnAwake()
{
base.OnAwake();

KCT_GUI.UseAvailabilityChecker = true;
KCT_GUI.AvailabilityChecker = CheckCrewForPart;
}

public static bool CheckCrewForPart(ProtoCrewMember pcm, string partName)
{
if (EntryCostStorage.GetCost(partName) == 1)
return true;

for (int i = pcm.flightLog.Entries.Count; i-- > 0;)
{
FlightLog.Entry e = pcm.flightLog.Entries[i];
if (e.type == "TRAINING_proficiency" && e.target == partName)
return true;
}
return false;
}

protected void Update()
{
if (HighLogic.CurrentGame == null || KerbalConstructionTime.KerbalConstructionTime.instance == null)
1 change: 1 addition & 0 deletions Source/RP0.csproj
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@
<Compile Include="Crew\ActiveCourse.cs" />
<Compile Include="Crew\CourseTemplate.cs" />
<Compile Include="Crew\FSGUI.cs" />
<Compile Include="EntryCostStorage.cs" />
<Compile Include="Maintenance\MaintenanceHandler.cs" />
<Compile Include="Crew\CrewHandler.cs" />
<Compile Include="LoadingScreenChanger.cs" />
3 changes: 2 additions & 1 deletion Source/RP0KCTBinder.csproj
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@
<Private>False</Private>
</Reference>
<Reference Include="KerbalConstructionTime">
<HintPath>..\..\..\..\..\..\Games\RO_122\GameData\KerbalConstructionTime\plugins\KerbalConstructionTime.dll</HintPath>
<HintPath>..\..\KCT\GameData\KerbalConstructionTime\plugins\KerbalConstructionTime.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System">
@@ -81,6 +81,7 @@
<ProjectReference Include="RP0.csproj">
<Project>{997854f8-4efb-4a78-87bc-f7c8cea64669}</Project>
<Name>RP0</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 comments on commit d9b035f

Please sign in to comment.