Skip to content

Commit

Permalink
Merge pull request #49 from BobPalmer/DEVELOP
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BobPalmer committed Jan 19, 2016
2 parents be6d17d + a5518c4 commit bb2226f
Show file tree
Hide file tree
Showing 25 changed files with 901 additions and 145 deletions.
Binary file removed FOR_RELEASE/GameData/ModuleManager.2.6.13.dll
Binary file not shown.
Binary file added FOR_RELEASE/GameData/ModuleManager.2.6.17.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
0.3.0 - 2016.01.18
------------------
EVA timer is now based on how long the kerbal has been EVA.
Habitation space is now a thing - see the forum for details.
The in-flight view has had a visual refresh to reflect the new data.
Multiple LS configs are now supported, with a delta inclusive of the most pessimistic changes being used.
Added displays to the tracking station, space center, and VAB/SPH
SPH display includes build aid information for the current vessel
Reduced mass of Nom-O-Matic 5000
Kerbals no longer raid the supply tins - but they will unlock all of them.
Corrected stack nodes for nom tanks
Kerbals in command seats should properly consume supplies
Recyclers and Habitation calculations, if enabled, can extend to nearby landed vessels to better facilitate disconnected bases.

0.2.1 - 2016.01.01
------------------
Fixed bug where crew were starving on Kerbin
Expand Down
44 changes: 44 additions & 0 deletions FOR_RELEASE/GameData/UmbraSpaceIndustries/LifeSupport/LSModule.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
//Suggested values for dedicated hab parts:
// Kerbal Months should equal mass * 5
// ReplacementParts = 100 * crew capacity + 100 * Kerbal Months.
//For parts that act as hab multipliers, a multiplier equal to the tonnage works well.

@PART[crewCabin]
{
MODULE
{
name = ModuleLifeSupport
}

RESOURCE
{
name = ReplacementParts
amount = 1600
maxAmount = 1600
}

MODULE
{
name = ModuleHabitation
KerbalMonths = 12
}
}

@PART[*]:HAS[!MODULE[ModuleLifeSupport],#CrewCapacity[*],~CrewCapacity[0]]:FOR[USILifeSupport]
{
MODULE
{
name = ModuleLifeSupport
}

RESOURCE
{
name = ReplacementParts
amount = 100
maxAmount = 100
@amount *= #$/CrewCapacity$
@maxAmount *= #$/CrewCapacity$
}
}

@PART[*]:HAS[!MODULE[ModuleLifeSupport],MODULE[KerbalSeat]]:FOR[USILifeSupport]
Expand All @@ -12,4 +47,13 @@
{
name = ModuleLifeSupport
}

RESOURCE
{
name = ReplacementParts
amount = 500
maxAmount = 500
@amount *= #$/CrewCapacity$
@maxAmount *= #$/CrewCapacity$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PART
manufacturer = Umbra Space Industries
description = The Nom-O-Matic offers the latest in automated gardening and food generation. Simply toss in mulch (not included!) and harvest bland but mildly nutritions noms.
attachRules = 1,1,0,0,0
mass = 1.5
mass = 0.55
dragModelType = default
maximum_drag = 0.25
minimum_drag = 0.25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ MODEL

rescaleFactor = 1

node_attach = 0,0,1.2,0,0,-1,1
node_stack_top = 0.0, .5, 0.0, 0.0, 1.0, 0.0, 1
node_stack_bottom = 0.0, -.5, 0.0, 0.0, -1.0, 0.0, 1
node_attach = 0,0,1.2,0,0,-1,2
node_stack_top = 0.0, .5, 0.0, 0.0, 1.0, 0.0, 2
node_stack_bottom = 0.0, -.5, 0.0, 0.0, -1.0, 0.0, 2


TechRequired = survivability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ MODEL
}
rescaleFactor = 1

node_attach = 0,0,1.8,0,0,-1,1
node_stack_top = 0.0, .75, 0.0, 0.0, 1.0, 0.0, 1
node_stack_bottom = 0.0, -.75, 0.0, 0.0, -1.0, 0.0, 1
node_attach = 0,0,1.8,0,0,-1,3
node_stack_top = 0.0, .75, 0.0, 0.0, 1.0, 0.0, 3
node_stack_bottom = 0.0, -.75, 0.0, 0.0, -1.0, 0.0, 3


TechRequired = survivability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ RESOURCE_DEFINITION
transfer = PUMP
unitCost = 5
isTweakable = true
}
}
RESOURCE_DEFINITION
{
name = ReplacementParts
density = 0.0
flowMode = ALL_VESSEL
transfer = PUMP
unitCost = 0
isTweakable = false
isVisible = false
}
20 changes: 12 additions & 8 deletions FOR_RELEASE/GameData/UmbraSpaceIndustries/LifeSupport/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ LIFE_SUPPORT_SETTINGS
SupplyTime = 324000 //How many seconds before Kerbals are affected by no supplies
EVATime = 21600 //How many seconds before ill effects on EVA
ECAmount = 0.01 //EC per Kerbal per second
SupplyAmount = 0.00005 //Supplies consumed per Kerbal per second
WasteAmount = 0.00005 //Mulch produced per Kerbal per second
SupplyAmount = 0.00005 //Supplies consumed per Kerbal per second
WasteAmount = 0.00005 //Mulch produced per Kerbal per second
NoSupplyEffect = 1 //Effect if a Kerbal has no supplies or EC
NoSupplyEffectVets = 1 //Effect if a Kerbal is a vet and has no supplies or EC
EVAEffect = 1 //Effect if a Kerbal exceeds EVA time
EVAEffectVets = 1 //Effect if a Kerbal is a vet and exceeds EVA time
NoSupplyEffectVets = 1 //Effect if a Kerbal is a vet and has no supplies or EC
EVAEffect = 3 //Effect if a Kerbal exceeds EVA time
EVAEffectVets = 3 //Effect if a Kerbal is a vet and exceeds EVA time
NoHomeEffect = 0 //Effect if a Kerbal becomes homesick
NoHomeEffectVets = 0 //Effect if a Kerbai is a vet and becomes homesick
NoHomeEffectVets = 0 //Effect if a Kerbal is a vet and becomes homesick
HabMultiplier = 1 //Bonus to hab values (1 = default = 100% of the part's rated value)
HomeWorldAltitude = 25000 //Altitude on Kerbin that negative effects are removed
VetNames = Jebediah,Valentina,Bill,Bob
HomeWorldAltitude = 25000 //Altitude on Kerbin that negative effects are removed
BaseHabTime = 1 //How long can 1 crew capacity support 1 Kerbal, expressed in Kerbal Months
ReplacementPartAmount = 0 //How fast life support equipment and habs 'wears out'
HabRange = 150 //How close we need to be to use other vessel's habitation modules and recyclers.
EnableRecyclers = false //Use resource recyclers? Not the same as resource converteres like greenhouses!
VetNames = Jebediah,Valentina,Bill,Bob
}

// SIDE EFFECTS:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"NAME":"USI-LS",
"URL":"https://raw.githubusercontent.com/BobPalmer/USI-LS/master/GameData/UmbraSpaceIndustries/LifeSupport/USI-LS.version",
"URL":"https://raw.githubusercontent.com/BobPalmer/USI-LS/master/FOR_RELEASE/GameData/UmbraSpaceIndustries/LifeSupport/USI-LS.version",
"DOWNLOAD":"https://github.com/BobPalmer/USI-LS/releases",
"GITHUB":{
"USERNAME":"BobPalmer",
Expand All @@ -9,8 +9,8 @@
},
"VERSION":{
"MAJOR":0,
"MINOR":2,
"PATCH":1,
"MINOR":3,
"PATCH":0,
"BUILD":0
},
"KSP_VERSION":{
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions Source/USILifeSupport/LifeSupportConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class LifeSupportConfig
public float ECAmount { get; set; }
public float SupplyAmount { get; set; }
public float WasteAmount { get; set; }
public float ReplacementPartAmount { get; set; }
public int NoSupplyEffect { get; set; }
public int NoSupplyEffectVets { get; set; }
public int EVAEffect { get; set; }
Expand All @@ -16,5 +17,8 @@ public class LifeSupportConfig
public int HabMultiplier { get; set; }
public string VetNames { get; set; }
public int HomeWorldAltitude { get; set; }
public double BaseHabTime { get; set; }
public bool EnableRecyclers { get; set; }
public double HabRange { get; set; }
}
}
137 changes: 135 additions & 2 deletions Source/USILifeSupport/LifeSupportManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KolonyTools;
using UnityEngine;



namespace LifeSupport
{
public class LifeSupportManager : MonoBehaviour
Expand Down Expand Up @@ -80,6 +83,10 @@ public LifeSupportStatus FetchKerbal(ProtoCrewMember crew)
var k = new LifeSupportStatus();
k.KerbalName = crew.name;
k.LastMeal = Planetarium.GetUniversalTime();
k.LastOnKerbin = Planetarium.GetUniversalTime();
k.MaxOffKerbinTime = Planetarium.GetUniversalTime() + 972000000;
k.TimeInVessel = 0d;
k.LastVesselId = "??UNKNOWN??";
k.LastUpdate = Planetarium.GetUniversalTime();
k.IsGrouchy = false;
k.OldTrait = crew.experienceTrait.Title;
Expand All @@ -101,6 +108,10 @@ public void TrackKerbal(LifeSupportStatus status)
LifeSupportInfo.Add(kerbInfo);
}
kerbInfo.LastMeal = status.LastMeal;
kerbInfo.LastOnKerbin = status.LastOnKerbin;
kerbInfo.MaxOffKerbinTime = status.MaxOffKerbinTime;
kerbInfo.LastVesselId = status.LastVesselId;
kerbInfo.TimeInVessel = status.TimeInVessel;
kerbInfo.LastUpdate = status.LastUpdate;
kerbInfo.IsGrouchy = status.IsGrouchy;
kerbInfo.OldTrait = status.OldTrait;
Expand All @@ -121,8 +132,12 @@ public void TrackVessel(VesselSupplyStatus status)
vesselInfo.LastFeeding = status.LastFeeding;
vesselInfo.LastUpdate = status.LastUpdate;
vesselInfo.NumCrew = status.NumCrew;
vesselInfo.RecyclerMultiplier = status.RecyclerMultiplier;
vesselInfo.CrewCap = status.CrewCap;
vesselInfo.HabSpace = status.HabSpace;
vesselInfo.HabMultiplier = status.HabMultiplier;
vesselInfo.SuppliesLeft = status.SuppliesLeft;
LifeSupportScenario.Instance.settings.SaveVesselNode(status);
LifeSupportScenario.Instance.settings.SaveVesselNode(vesselInfo);
}

public void UntrackVessel(string vesselId)
Expand All @@ -142,6 +157,11 @@ public VesselSupplyStatus FetchVessel(string vesselId)
v.LastFeeding = Planetarium.GetUniversalTime();
v.LastUpdate = Planetarium.GetUniversalTime();
v.NumCrew = 0;
v.RecyclerMultiplier = 1;
v.CrewCap = 0;
v.HabMultiplier = 0;
v.HabSpace = 0;
v.HabSpace = 0;
v.SuppliesLeft = 0f;
v.VesselId = vesselId;
v.VesselName = "??loading??";
Expand All @@ -166,7 +186,8 @@ internal void UpdateVesselStats()
var badIDs = new List<string>();
foreach (var vInfo in LifeSupportManager.Instance.VesselSupplyInfo)
{
if(FlightGlobals.Vessels.All(v => v.id.ToString() != vInfo.VesselId))
var vsl = FlightGlobals.Vessels.FirstOrDefault(v => v.id.ToString() == vInfo.VesselId);
if(vsl == null || vInfo.NumCrew == 0)
{
badIDs.Add(vInfo.VesselId);
}
Expand All @@ -177,6 +198,118 @@ internal void UpdateVesselStats()
LifeSupportManager.Instance.UntrackVessel(id);
}
}

internal static double GetRecyclerMultiplier(Vessel vessel)
{
if (!LifeSupportSetup.Instance.LSConfig.EnableRecyclers)
return 1d;

var recyclerCap = 0f;
var recyclerVal = 1f;
var crewCount = vessel.GetCrewCount();
foreach (var r in vessel.FindPartModulesImplementing<ModuleLifeSupportRecycler>())
{
if (r.IsActivated)
{
if (r.RecyclePercent > recyclerCap)
recyclerCap = r.RecyclePercent;
var recPercent = r.RecyclePercent;
if (r.CrewCapacity < crewCount)
recPercent *= r.CrewCapacity/(float) crewCount;

recyclerVal *= (1f - recPercent);
}
}

var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vessel, true);
foreach (var v in vList)
{
foreach (var r in v.FindPartModulesImplementing<ModuleLifeSupportRecycler>())
{
if (r.IsActivated)
{
if (r.RecyclePercent > recyclerCap)
recyclerCap = r.RecyclePercent;
var recPercent = r.RecyclePercent;
if (r.CrewCapacity < crewCount)
recPercent *= r.CrewCapacity / (float)crewCount;

recyclerVal *= (1f - recPercent);
}
}
}
return Math.Max(recyclerVal, (1f - recyclerCap));
}


internal static double GetLocalHabTime(VesselSupplyStatus thisVessel)
{
//Crew ratio is important - all of a vessel's hab capabilities are increased if a full crew is not present.
var crewRatio = thisVessel.CrewCap / Math.Max(1, thisVessel.NumCrew); //This will be 1 or greater
//Hab time is a combination of four things
//First - crew capacity.
var habTime = LifeSupportSetup.Instance.LSConfig.BaseHabTime + thisVessel.HabSpace;
//Now we can do our calculation.
var habTotal = habTime * thisVessel.HabMultiplier * crewRatio * LifeSupportSetup.Instance.LSConfig.HabMultiplier;
//A Kerbal month is 30 six-hour Kerbin days.
return habTotal * (60d * 60d * 6d * 30d);
}


internal static double GetNearbyHabTime(VesselSupplyStatus thisVessel)
{
//Hab time is not only about the current vessel but also nearby landed ones.
var vsl = FlightGlobals.Vessels.FirstOrDefault(v => v.id.ToString() == thisVessel.VesselId);
double crewRatio, habTime;
var habTotal = 0d;

var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vsl, true);
foreach (var v in vList)
{
var curVsl = LifeSupportManager.Instance.FetchVessel(v.id.ToString());
crewRatio = curVsl.CrewCap / Math.Max(1, thisVessel.NumCrew); //This will be 1 or greater
//Hab time is a combination of four things
//First - crew capacity.
habTime = LifeSupportSetup.Instance.LSConfig.BaseHabTime + curVsl.HabSpace;
//Now we can do our calculation.
habTotal = habTime * curVsl.HabMultiplier * crewRatio * LifeSupportSetup.Instance.LSConfig.HabMultiplier;
}
return habTotal * (60d * 60d * 6d * 30d);
}

internal static double GetTotalHabTime(VesselSupplyStatus vsl)
{
var totHabTime = 0d;
totHabTime += GetLocalHabTime(vsl);
totHabTime += GetNearbyHabTime(vsl);
return totHabTime;
}

internal static double GetRecyclerMultiplierForParts(List<Part> pList, int crewCount)
{
if (!LifeSupportSetup.Instance.LSConfig.EnableRecyclers)
return 1d;

var recyclerCap = 0f;
var recyclerVal = 1f;

foreach (var p in pList)
{
var mod = p.FindModuleImplementing<ModuleLifeSupportRecycler>();
if (mod == null)
continue;

if (mod.RecyclePercent > recyclerCap)
recyclerCap = mod.RecyclePercent;
var recPercent = mod.RecyclePercent;
if (mod.CrewCapacity < crewCount)
recPercent *= mod.CrewCapacity / (float)crewCount;

recyclerVal *= (1f - recPercent);
}

return Math.Max(recyclerVal, (1f - recyclerCap));
}
}
}

Loading

0 comments on commit bb2226f

Please sign in to comment.