Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create proficiency courses for parts that are being researched
Browse files Browse the repository at this point in the history
siimav committed Jan 22, 2019
1 parent a1d3a4a commit 18dcbce
Showing 2 changed files with 73 additions and 18 deletions.
47 changes: 30 additions & 17 deletions Source/Crew/CrewHandler.cs
Original file line number Diff line number Diff line change
@@ -494,7 +494,33 @@ public void AddExpiration(TrainingExpiration e)
{
expireTimes.Add(e);
}


public void AddCoursesForTechNode(RDTech tech)
{
for (int i = 0; i < tech.partsAssigned.Count; i++)
{
AvailablePart ap = tech.partsAssigned[i];
if (ap.partPrefab.CrewCapacity > 0)
{
AddPartCourses(ap);
}
}
}

public void AddPartCourses(AvailablePart ap)
{
string name = TrainingDatabase.SynonymReplace(ap.name);
if (!partSynsHandled.Contains(name))
{
partSynsHandled.Add(name);
GenerateCourseProf(ap);
if (ResearchAndDevelopment.PartModelPurchased(ap))
{
GenerateCourseMission(ap);
}
}
}

#endregion

#region Methods
@@ -806,30 +832,17 @@ protected void GenerateOfferedCourses() //somehow provide some variable options

foreach (AvailablePart ap in PartLoader.LoadedPartsList)
{
if (ap.partPrefab.CrewCapacity > 0 /*&& ap.TechRequired != "start"*/)
if (ap.partPrefab.CrewCapacity > 0 && /*&& ap.TechRequired != "start"*/
ResearchAndDevelopment.PartModelPurchased(ap))
{
if (ResearchAndDevelopment.PartModelPurchased(ap))
{
string name = TrainingDatabase.SynonymReplace(ap.name);
if (!partSynsHandled.Contains(name))
{
partSynsHandled.Add(name);
AddPartCourses(ap);
}
}
AddPartCourses(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 void AddPartCourses(AvailablePart ap)
{
GenerateCourseProf(ap);
GenerateCourseMission(ap);
}

protected void GenerateCourseProf(AvailablePart ap)
{
ConfigNode n = new ConfigNode("FS_COURSE");
44 changes: 43 additions & 1 deletion Source/KCTBinderModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using KerbalConstructionTime;
using RP0.Crew;
using UnityEngine;

namespace RP0
{
@@ -18,6 +20,8 @@ public class KCTBinderModule : ScenarioModule
protected bool skipOne = true;
protected bool skipTwo = true;

private EventData<RDTech> onKctTechQueuedEvent;

public override void OnAwake()
{
base.OnAwake();
@@ -26,6 +30,22 @@ public override void OnAwake()
KCT_GUI.AvailabilityChecker = CheckCrewForPart;
}

public void Start()
{
onKctTechQueuedEvent = GameEvents.FindEvent<EventData<RDTech>>("OnKctTechQueued");
if (onKctTechQueuedEvent != null)
{
onKctTechQueuedEvent.Add(OnKctTechQueued);
}

StartCoroutine(CreateCoursesRoutine());
}

public void OnDestroy()
{
if (onKctTechQueuedEvent != null) onKctTechQueuedEvent.Remove(OnKctTechQueued);
}

public static bool CheckCrewForPart(ProtoCrewMember pcm, string partName)
{
// lolwut. But just in case.
@@ -112,7 +132,6 @@ protected void Update()
if (buildRate > 0.001d)
MaintenanceHandler.Instance.kctBuildRates[ksc.KSCName] = buildRate;


for (int i = ksc.LaunchPads.Count; i-- > 0;)
{
int lvl = ksc.LaunchPads[i].level;
@@ -125,5 +144,28 @@ protected void Update()
MaintenanceHandler.Instance.kctResearchRate = RDRate;
MaintenanceHandler.Instance.kctPadCounts = padCounts;
}

private void OnKctTechQueued(RDTech data)
{
CrewHandler.Instance.AddCoursesForTechNode(data);
}

private IEnumerator CreateCoursesRoutine()
{
yield return new WaitForFixedUpdate();

for (int i = 0; i < PartLoader.LoadedPartsList.Count; i++)
{
var ap = PartLoader.LoadedPartsList[i];
if (ap.partPrefab.CrewCapacity > 0)
{
var kctTech = KCT_GameStates.TechList.Find(t => t.techID == ap.TechRequired);
if (kctTech != null)
{
CrewHandler.Instance.AddPartCourses(ap);
}
}
}
}
}
}

0 comments on commit 18dcbce

Please sign in to comment.