Skip to content

Commit

Permalink
Showing 5 changed files with 90 additions and 33 deletions.
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.
37 changes: 32 additions & 5 deletions Source/Crew/ActiveCourse.cs
Original file line number Diff line number Diff line change
@@ -79,35 +79,45 @@ public bool MeetsStudentReqs(ProtoCrewMember student)
return false;

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

int needCount = pCount;
bool needAnyStill = pACount > 0;

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

string tgt = string.IsNullOrEmpty(e.target) ? string.Empty : e.target;

for (int preIdx = pCount; preIdx-- > 0 && needCount > 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] && tgt == preReqs[preIdx, 1]))
{
pChecker[preIdx] = false;
--needCount;
}
}

for (int anyIdx = pACount; anyIdx-- > 0 && needAnyStill;)
{
if (e.type == preReqsAny[anyIdx, 0] && tgt == preReqsAny[anyIdx, 1])
needAnyStill = false;
}

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

if (needCount > 0)
if (needCount > 0 || needAnyStill)
return false;
}
return true;
@@ -187,6 +197,23 @@ public void CompleteCourse()
if (student == null)
continue;

if (ExpireLog != null)
{
foreach (ConfigNode.Value v in ExpireLog.values)
{
for (int i = student.careerLog.Count; i-- > 0;)
{
FlightLog.Entry e = student.careerLog.Entries[i];
if (CrewHandler.TrainingExpiration.Compare(v.value, e))
{
e.type = "expired_" + e.type;
CrewHandler.Instance.RemoveExpiration(student.name, v.value);
break;
}
}
}
}

if (RewardLog != null)
{
if (student.flightLog.Count > 0)
44 changes: 20 additions & 24 deletions Source/Crew/CourseTemplate.cs
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ public class CourseTemplate

public bool Available = true; //Whether the course is currently being offered

public string[] activePreReqs = { }; //prereqs that must not be expired
public string[,] preReqs = { }; //prereqs that must be taken, but can be expired
public string[,] preReqsAny = { };
public string[,] preReqs = { };
public bool[] pChecker = { }; // prereq checker;
public string[,] conflicts = { }; //course IDs that cannot be taken while this course is not expired

@@ -39,7 +39,7 @@ public class CourseTemplate

public int rewardXP = 0; //pure XP reward
public ConfigNode RewardLog = null; //the flight log to insert
// public ConfigNode[] Expiry = { }; //The list of ways that course experience can be lost
public ConfigNode ExpireLog = null; // expire all these on complete

public CourseTemplate(ConfigNode source)
{
@@ -74,9 +74,23 @@ public void PopulateFromSourceNode(ConfigNode source = null)

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

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

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

tmpStr = source.GetValue("preReqs");
if (!string.IsNullOrEmpty(tmpStr))
@@ -149,27 +163,9 @@ public void PopulateFromSourceNode(ConfigNode source = null)
if (r != null)
{
RewardLog = r.GetNode("FLIGHTLOG");
ExpireLog = r.GetNode("EXPIRELOG");
r.TryGetValue("XPAmt", ref rewardXP);
}

/* Expiry = source.GetNodes("EXPIRY");
foreach (ConfigNode node in Expiry)
ConfigNodeExtensions.ReplaceValuesInNode(node, variables);*/

/*string logStr = "Course created";
logStr += "\nID: " + id;
logStr += "\nName: " + name;
logStr += "\nAvailable: " + Available;
logStr += "\nprereqs: " + preReqs.GetLength(0);
logStr += "\ntime: " + time;
logStr += "\nrepeatable: " + repeatable;
logStr += "\nXP: " + rewardXP;
logStr += "\nLog: ";
if (RewardLog != null)
foreach (ConfigNode.Value v in RewardLog.values)
logStr += "\n" + v.value;
UnityEngine.Debug.Log(logStr);*/
}

public double GetTime(List<ProtoCrewMember> students)
42 changes: 38 additions & 4 deletions Source/Crew/CrewHandler.cs
Original file line number Diff line number Diff line change
@@ -28,11 +28,10 @@ public TrainingExpiration(ConfigNode node)
Load(node);
}

public bool Compare(int idx, FlightLog.Entry e)
public static bool Compare(string str, 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 tgLen = (string.IsNullOrEmpty(e.target) ? 0 : e.target.Length);
int iC = str.Length;
if (iC != 1 + tyLen + tgLen)
return false;
@@ -56,6 +55,11 @@ public bool Compare(int idx, FlightLog.Entry e)
return true;
}

public bool Compare(int idx, FlightLog.Entry e)
{
return Compare(entries[idx], e);
}

public void Load(ConfigNode node)
{
foreach (ConfigNode.Value v in node.values)
@@ -807,9 +811,13 @@ protected void GenerateCourseProf(AvailablePart ap)
n2.SetValue("id", "profR_" + name);
n2.SetValue("name", "Refresher: " + name);
n2.SetValue("time", 1d + TrainingDatabase.GetTime(name) * 86400d * settings.trainingProficiencyRefresherTimeMult);
n2.AddValue("preReqs", "expired_TRAINING_proficiency:" + name);
n2.AddValue("preReqsAny", "expired_TRAINING_proficiency:" + name + ",TRAINING_proficiency:" + name);
n2.RemoveValue("conflicts");

r = n2.GetNode("REWARD");
r.SetValue("XPAmt", "0");
ConfigNode exp = r.AddNode("EXPIRELOG");
exp.AddValue("0", "TRAINING_proficiency," + name);

c = new CourseTemplate(n2);
c.PopulateFromSourceNode();
@@ -862,6 +870,32 @@ protected string GetPrettyCourseName(string str)
}
}

public bool RemoveExpiration(string pcmName, string entry)
{
for (int i = expireTimes.Count; i-- > 0;)
{
TrainingExpiration e = expireTimes[i];

if (e.pcmName != pcmName)
continue;

for (int j = e.entries.Count; j-- > 0;)
{
if (e.entries[j] == entry)
{
e.entries.RemoveAt(j);

if (e.entries.Count == 0)
expireTimes.RemoveAt(i);

return true;
}
}
}

return false;
}

#endregion
}
}

0 comments on commit 3927322

Please sign in to comment.