Skip to content

Commit

Permalink
Merge pull request #177 from BobPalmer/DEVELOP
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BobPalmer authored Dec 1, 2016
2 parents 66f45e6 + 154a0a2 commit d950842
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.5.12 - 2016.12.01
-------------------
Added reason for Kerbal effects to aid in troubleshooting

0.5.11 - 2016.11.29
-------------------
Some improved handling, fixed a habitation calculation bug

0.5.10 - 2016.11.29
-------------------
Fixed decoupler spam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"VERSION":{
"MAJOR":0,
"MINOR":5,
"PATCH":10,
"PATCH":12,
"BUILD":0
},
"KSP_VERSION":{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Source/USILifeSupport/.vs/USILifeSupport/v14/.suo
Binary file not shown.
8 changes: 5 additions & 3 deletions Source/USILifeSupport/LifeSupportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public LifeSupportStatus FetchKerbal(ProtoCrewMember crew)
k.LastEC = Planetarium.GetUniversalTime();
k.LastAtHome = Planetarium.GetUniversalTime();
k.LastSOIChange = Planetarium.GetUniversalTime();
k.MaxOffKerbinTime = 648000; //TODO - make this configurable
k.MaxOffKerbinTime = Planetarium.GetUniversalTime() + 648000;
k.TimeEnteredVessel = Planetarium.GetUniversalTime();
k.CurrentVesselId = "?UNKNOWN?";
k.PreviousVesselId = "??UNKNOWN??";
Expand Down Expand Up @@ -272,6 +272,7 @@ internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel, out int
numSharedVessels = 0;

var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false);
var hList = new List<Vessel>();
foreach (var v in vList)
{
//Hab time starts with our baseline of the crew hab plus extra hab.
Expand All @@ -284,12 +285,13 @@ internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel, out int
if (crewCap > 0)
{
numSharedVessels++;
hList.Add(v);
}
}

foreach (var v in vList)
foreach (var v in hList)
{
// Calculate HabSpace and HabMult after we know totCurCrew and totMaxCrew
// Calculate HabSpace and HabMult after we know totCurCrew and totMaxCrew
totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime * totMaxCrew) + CalculateVesselHabExtraTime(v);
totHabMult += CalculateVesselHabMultiplier(v, totCurCrew);
}
Expand Down
32 changes: 17 additions & 15 deletions Source/USILifeSupport/ModuleLifeSupportSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public VesselSupplyStatus VesselStatus

public void OnDestroy()
{
GameEvents.onVesselPartCountChanged.Remove(SetVesselDirty);
GameEvents.onVesselCrewWasModified.Remove(SetVesselDirty);
GameEvents.onVesselChange.Remove(SetVesselDirty);
//GameEvents.onVesselPartCountChanged.Remove(SetVesselDirty);
//GameEvents.onVesselCrewWasModified.Remove(SetVesselDirty);
//GameEvents.onVesselChange.Remove(SetVesselDirty);
}

public void FixedUpdate()
Expand Down Expand Up @@ -127,10 +127,11 @@ public void FixedUpdate()
//Ensure status is current
UpdateStatus();
//First - Hab effects.
if (LifeSupportManager.IsOnKerbin(vessel))
if (!offKerbin)
{
var habTime = LifeSupportManager.GetTotalHabTime(VesselStatus);
k.LastAtHome = Planetarium.GetUniversalTime();
k.MaxOffKerbinTime = 648000;
k.MaxOffKerbinTime = habTime + k.LastAtHome;
k.TimeEnteredVessel = Planetarium.GetUniversalTime();
}
else
Expand All @@ -143,8 +144,9 @@ public void FixedUpdate()
k.PreviousVesselId = k.CurrentVesselId;
k.CurrentVesselId = vessel.id.ToString();
}
isGrouchyHab = CheckHabSideEffects(k);
}
isGrouchyHab = CheckHabSideEffects(k);


//Second - Supply
if (offKerbin && (deltaTime - resultSupply.TimeFactor > tolerance))
Expand Down Expand Up @@ -179,21 +181,21 @@ public void FixedUpdate()
ApplyEffect(k, c,
LifeSupportManager.isVet(k.KerbalName)
? LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffectVets
: LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect);
: LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect,"power loss");
}
else if (isGrouchySupplies)
{
ApplyEffect(k, c,
LifeSupportManager.isVet(k.KerbalName)
? LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffectVets
: LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect);
: LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect,"lack of supplies");
}
else if (isGrouchyHab)
{
ApplyEffect(k, c,
LifeSupportManager.isVet(k.KerbalName)
? LifeSupportScenario.Instance.settings.GetSettings().NoHomeEffectVets
: LifeSupportScenario.Instance.settings.GetSettings().NoHomeEffect);
: LifeSupportScenario.Instance.settings.GetSettings().NoHomeEffect,"homesickness");
}
else if (c.experienceTrait.Title != k.OldTrait)
{
Expand Down Expand Up @@ -476,7 +478,7 @@ private void RemoveGrouchiness(ProtoCrewMember c, LifeSupportStatus k)
}
}

private void ApplyEffect(LifeSupportStatus kStat, ProtoCrewMember crew, int effectId)
private void ApplyEffect(LifeSupportStatus kStat, ProtoCrewMember crew, int effectId, string reason)
{
/*
* SIDE EFFECTS:
Expand All @@ -496,7 +498,7 @@ private void ApplyEffect(LifeSupportStatus kStat, ProtoCrewMember crew, int effe
case 1: //Grouchy
if (crew.type != ProtoCrewMember.KerbalType.Tourist)
{
msg = string.Format("{0} refuses to work", crew.name);
msg = string.Format("{0} refuses to work {1}", crew.name, reason);
kStat.OldTrait = crew.experienceTrait.Title;
crew.type = ProtoCrewMember.KerbalType.Tourist;
KerbalRoster.SetExperienceTrait(crew, "Tourist");
Expand All @@ -506,7 +508,7 @@ private void ApplyEffect(LifeSupportStatus kStat, ProtoCrewMember crew, int effe
break;
case 2: //Mutinous
{
msg = string.Format("{0} has become mutinous", crew.name);
msg = string.Format("{0} has become mutinous due to {1}", crew.name, reason);
kStat.OldTrait = crew.experienceTrait.Title;
crew.type = ProtoCrewMember.KerbalType.Tourist;
KerbalRoster.SetExperienceTrait(crew, "Tourist");
Expand All @@ -516,21 +518,21 @@ private void ApplyEffect(LifeSupportStatus kStat, ProtoCrewMember crew, int effe
}
break;
case 3: //Return to KSC
msg = string.Format("{0} gets fed up and wanders back to the KSC", crew.name);
msg = string.Format("{0} gets fed up and wanders back to the KSC due to {1}", crew.name, reason);
LifeSupportManager.Instance.UntrackKerbal(crew.name);
crew.rosterStatus = ProtoCrewMember.RosterStatus.Available;
vessel.CrewListSetDirty();
RemoveCrewFromPart(crew);
break;
case 4: //Despawn
msg = string.Format("{0} has gone missing", crew.name);
msg = string.Format("{0} has gone missing due to {1}", crew.name, reason);
LifeSupportManager.Instance.UntrackKerbal(crew.name);
vessel.CrewListSetDirty();
RemoveCrewFromPart(crew);
crew.rosterStatus = ProtoCrewMember.RosterStatus.Missing;
break;
case 5: //Kill
msg = string.Format("{0} has died", crew.name);
msg = string.Format("{0} has died due to {1}", crew.name, reason);
LifeSupportManager.Instance.UntrackKerbal(crew.name);
vessel.CrewListSetDirty();
RemoveCrewFromPart(crew);
Expand Down

0 comments on commit d950842

Please sign in to comment.