Skip to content

Commit

Permalink
Showing 5 changed files with 125 additions and 45 deletions.
Binary file modified GameData/RP-0/Plugins/RP0.dll
Binary file not shown.
44 changes: 25 additions & 19 deletions Source/Crew/ActiveCourse.cs
Original file line number Diff line number Diff line change
@@ -76,32 +76,38 @@ public bool MeetsStudentReqs(ProtoCrewMember student)
if (!((student.type == (ProtoCrewMember.KerbalType.Crew) && (seatMax <= 0 || Students.Count < seatMax) && !student.inactive && student.rosterStatus == ProtoCrewMember.RosterStatus.Available && student.experienceLevel >= minLevel &&
student.experienceLevel <= maxLevel && (classes.Length == 0 || classes.Contains(student.trait)) && !Students.Contains(student))))
return false;
if (preReqs != null)

int pCount = preReqs.GetLength(0);
int cCount = conflicts.GetLength(0);
if (pCount > 0 || cCount > 0)
{
int pCount = preReqs.GetLength(0);
if (pCount > 0)
{
for (int i = pCount; i-- > 0;)
pChecker[i] = true;
for (int i = pCount; i-- > 0;)
pChecker[i] = true;

int needCount = pCount;
int needCount = pCount;

for (int entryIdx = student.flightLog.Count; entryIdx-- > 0 && needCount > 0;)
{
FlightLog.Entry e = student.flightLog.Entries[entryIdx];
for (int entryIdx = student.flightLog.Count; entryIdx-- > 0 && needCount > 0;)
{
FlightLog.Entry e = student.flightLog.Entries[entryIdx];

for (int preIdx = pCount; preIdx-- > 0;)
for (int preIdx = pCount; preIdx-- > 0;)
{
if (pChecker[preIdx] && (e.type == preReqs[preIdx, 0] && (string.IsNullOrEmpty(preReqs[preIdx, 1]) || e.target == preReqs[preIdx, 1])))
{
if (pChecker[preIdx] && (e.type == preReqs[preIdx, 0] && (string.IsNullOrEmpty(preReqs[preIdx, 1]) || e.target == preReqs[preIdx, 1])))
{
pChecker[preIdx] = false;
--needCount;
}
pChecker[preIdx] = false;
--needCount;
}
}
if (needCount > 0)
return false;

for (int conIdx = cCount; conIdx-- > 0;)
{
if (e.type == conflicts[conIdx, 0] && (string.IsNullOrEmpty(conflicts[conIdx, 1]) || e.target == conflicts[conIdx, 1]))
return false;
}
}

if (needCount > 0)
return false;
}
return true;
}
@@ -183,7 +189,7 @@ public void CompleteCourse()
string[] s = v.value.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
student.flightLog.AddEntry(s[0], s.Length == 1 ? null : s[1]);
if (expiration > 0d)
exp.entries.Add(s[0]);
exp.entries.Add(v.value);
}

if (expiration > 0d)
30 changes: 27 additions & 3 deletions Source/Crew/CourseTemplate.cs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public class CourseTemplate
public string[] activePreReqs = { }; //prereqs that must not be expired
public string[,] preReqs = { }; //prereqs that must be taken, but can be expired
public bool[] pChecker = { }; // prereq checker;
public string[] conflicts = { }; //course IDs that cannot be taken while this course is not expired
public string[,] conflicts = { }; //course IDs that cannot be taken while this course is not expired

public double time = 0; //how much time the course takes (in seconds)
public bool timeUseStupid = false;
@@ -95,14 +95,30 @@ public void PopulateFromSourceNode(ConfigNode source = null)
else
preReqs[i, 1] = string.Empty;
}

}

tmpStr = source.GetValue("conflicts");
if (!string.IsNullOrEmpty(tmpStr))
conflicts = tmpStr.Split(',');
{
string[] split1 = tmpStr.Split(',');
int iC = split1.Length;
conflicts = new string[iC, 2];

for (int i = 0; i < iC; ++i)
{
string[] split2 = split1[i].Split(':');
conflicts[i, 0] = split2[0];
if (split2.Length > 1)
conflicts[i, 1] = split2[1];
else
conflicts[i, 1] = string.Empty;
}
}

source.TryGetValue("time", ref time);
source.TryGetValue("timeUseStupid", ref timeUseStupid);
source.TryGetValue("expiration", ref expiration);
source.TryGetValue("expirationUseStupid", ref expirationUseStupid);

source.TryGetValue("required", ref required);

@@ -167,5 +183,13 @@ public double GetTime(List<ProtoCrewMember> students)

return time * (0.5d + maxStupid);
}

public double GetExpiration(ProtoCrewMember pcm)
{
if (pcm == null || !expirationUseStupid)
return expiration;

return expiration * (1.5d - pcm.stupidity);
}
}
}
91 changes: 69 additions & 22 deletions Source/Crew/CrewHandler.cs
Original file line number Diff line number Diff line change
@@ -28,6 +28,34 @@ public TrainingExpiration(ConfigNode node)
Load(node);
}

public bool Compare(int idx, FlightLog.Entry e)
{
string str = entries[idx];
int tyLen = (string.IsNullOrEmpty(e.type) ? 0 : e.type.Length);
int tgLen = (string.IsNullOrEmpty(e.target ) ? 0 : e.target.Length);
int iC = str.Length;
if (iC != 1 + tyLen + tgLen)
return false;
int i = 0;
for (; i < tyLen; ++i)
{
if (str[i] != e.type[i])
return false;
}

if (str[i] != ',')
return false;
++i;
for (int j = 0; j < tgLen && i < iC; ++j)
{
if (str[i] != e.target[j])
return false;
++i;
}

return true;
}

public void Load(ConfigNode node)
{
foreach (ConfigNode.Value v in node.values)
@@ -279,25 +307,6 @@ public void Update()
}
}
}
if (toRemove.Count > 0)
{
string msgStr = "The following retirements have occurred:\n";
foreach (string s in toRemove)
{
kerbalRetireTimes.Remove(s);
msgStr += "\n" + s;
}

PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
"Crew Retirement",
msgStr,
"OK",
true,
HighLogic.UISkin);

toRemove.Clear();
}

for (int i = ActiveCourses.Count; i-- > 0;)
{
@@ -321,12 +330,13 @@ public void Update()
int eC = e.entries.Count;
if (eC == 0)
break;

FlightLog.Entry ent = pcm.flightLog[j];
for (int k = eC; k-- > 0;)
{
if (pcm.flightLog[j].type == e.entries[k])
if (e.Compare(k, ent))
{
pcm.flightLog[j].type = "expired_" + pcm.flightLog[j].type;
ScreenMessages.PostScreenMessage(pcm.name + ": Expired: " + GetPrettyCourseName(ent.type) + ent.target);
ent.type = "expired_" + ent.type;
e.entries.RemoveAt(k);
}
}
@@ -335,6 +345,27 @@ public void Update()
expireTimes.RemoveAt(i);
}
}

// TODO remove from courses? Except I think they won't retire if inactive either so that's ok.
if (toRemove.Count > 0)
{
string msgStr = "The following retirements have occurred:\n";
foreach (string s in toRemove)
{
kerbalRetireTimes.Remove(s);
msgStr += "\n" + s;
}

PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
"Crew Retirement",
msgStr,
"OK",
true,
HighLogic.UISkin);

toRemove.Clear();
}
}

// UI fixing
@@ -695,6 +726,8 @@ protected void GenerateCourseProf(AvailablePart ap)
n.AddValue("expiration", 4d * 86400d * 365d);
n.AddValue("expirationUseStupid", true);

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

ConfigNode r = n.AddNode("REWARD");
r.AddValue("XPAmt", "1");
ConfigNode l = r.AddNode("FLIGHTLOG");
@@ -729,6 +762,7 @@ protected void GenerateCourseMission(AvailablePart ap)
n.AddValue("expiration", 120d * 86400d);

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

ConfigNode r = n.AddNode("REWARD");
ConfigNode l = r.AddNode("FLIGHTLOG");
@@ -744,6 +778,19 @@ protected void onPartPurchased(AvailablePart ap)
AddPartCourses(ap);
}

protected string GetPrettyCourseName(string str)
{
switch (str)
{
case "TRAINING_proficiency":
return "Proficiency with ";
case "TRAINING_mission":
return "Mission training for ";
default:
return "Training for ";
}
}

#endregion
}
}
5 changes: 4 additions & 1 deletion Source/Crew/FSGUI.cs
Original file line number Diff line number Diff line change
@@ -75,8 +75,9 @@ protected void DrawMainGUI(int windowID)
GUILayout.EndHorizontal();

GUILayout.Label(selectedCourse.description);
double endTime = selectedCourse.GetTime(selectedCourse.Students) + Planetarium.GetUniversalTime();

GUILayout.Label("Course ends: " + KSPUtil.PrintDate(selectedCourse.GetTime(selectedCourse.Students) + Planetarium.GetUniversalTime(), true));
GUILayout.Label("Course ends: " + KSPUtil.PrintDate(endTime, true));

//select the kerbals. Two lists, the current Students and the available ones
GUILayout.BeginHorizontal();
@@ -91,6 +92,8 @@ protected void DrawMainGUI(int windowID)
selectedCourse.Students.RemoveAt(i);
--i;
}
if (selectedCourse.expiration > 0d)
GUILayout.Label("Will expire: " + KSPUtil.PrintDate(endTime + selectedCourse.GetExpiration(student), false));

}
GUILayout.EndScrollView();

0 comments on commit 8b5144f

Please sign in to comment.