Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.21.1 Compatibility Fixes #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CorePartModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override string GetInfo()
else
text = "Remote Control";

text += "\nEnergy req.: " + (EnergyDrain * 60).ToString("0.00") + "/min.";
text += "\nEnergy req.: " + RTUtils.eCost(EnergyDrain); // NK

return text;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ public override string GetInfo()
if (this.EnergyDrain > 0)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain); // NK
}

//if (this.EnergyDrain0 > 0)
Expand Down
11 changes: 11 additions & 0 deletions FlightComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,17 @@ public void updateAvailableTorque()
torqueRAvailable += Math.Abs(((CommandPod)p).rotPower);
torquePYAvailable += Math.Abs(((CommandPod)p).rotPower);
}

foreach (PartModule m in p.Modules)
{
if (m is ModuleReactionWheel)
{
torqueRAvailable += ((((ModuleReactionWheel)m).PitchTorque + ((ModuleReactionWheel)m).YawTorque + ((ModuleReactionWheel)m).RollTorque) / 3)
* (p.Rigidbody.worldCenterOfMass - CoM).magnitude;
torquePYAvailable += ((((ModuleReactionWheel)m).PitchTorque + ((ModuleReactionWheel)m).YawTorque + ((ModuleReactionWheel)m).RollTorque) / 3)
* (p.Rigidbody.worldCenterOfMass - CoM).magnitude;
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions ModuleRTAnimatedAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public override string GetInfo()
if (EnergyDrain0 != EnergyDrain1)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain0 * 60).ToString("0.00") + "/min. / " + (EnergyDrain1 * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain0) + " / " + RTUtils.eCost(EnergyDrain1); // NK
}
else if (this.EnergyDrain > 0)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain); // NK
}

return text;
Expand Down
4 changes: 2 additions & 2 deletions ModuleRTAnimatedTrackAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ public override string GetInfo()
if (EnergyDrain0 != EnergyDrain1)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain0 * 60).ToString("0.00") + "/min. / " + (EnergyDrain1 * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain0) + " / " + RTUtils.eCost(EnergyDrain1); // NK
}
else if (this.EnergyDrain > 0)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain); // NK
}

return text;
Expand Down
4 changes: 2 additions & 2 deletions ModuleRTLoopAnimAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public override string GetInfo()
if (EnergyDrain0 != EnergyDrain1)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain0 * 60).ToString("0.00") + "/min. / " + (EnergyDrain1 * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain0) + " / " + RTUtils.eCost(EnergyDrain1); // NK
}
else if (this.EnergyDrain > 0)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain); // NK
}

return text;
Expand Down
4 changes: 2 additions & 2 deletions ModuleRTModalAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public override string GetInfo()
if (EnergyDrain0 != EnergyDrain1)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain0 * 60).ToString("0.00") + "/min. / " + (EnergyDrain1 * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain0) + " / " + RTUtils.eCost(EnergyDrain1); // NK
}
else if (this.EnergyDrain > 0)
{
if (text.Length > 0) text += "\n";
text += "Energy req.: " + (EnergyDrain * 60).ToString("0.00") + "/min.";
text += "Energy req.: " + RTUtils.eCost(EnergyDrain); // NK
}

return text;
Expand Down
39 changes: 38 additions & 1 deletion RTGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static bool

//Used in RelayNetwork
public static int RemoteCommandCrew = 3;
// NK add two more: allow multiple antennae/dishes, use new max range calculation
public static bool useMultiple = false; // and in RelayNode
public static bool useNewRange = false;

//Used in SatSettings
public static Rect SettingPos = new Rect((Screen.width / 2) - 175, (Screen.height / 2) - 300, 100, 200);
Expand Down Expand Up @@ -126,7 +129,9 @@ public static void Load()
RCC = "",
SETKEY = "",
EXTPACK = "",
COLFRIEND = "";
COLFRIEND = "",
MULTANT = "", // NK
NEWRANGE = ""; // NK

foreach (string s in ls)
{
Expand All @@ -142,6 +147,11 @@ public static void Load()
EXTPACK = s;
else if (s.StartsWith("Colourblind friendly mode"))
COLFRIEND = s;
// NK add two more
else if (s.StartsWith("Allow Multiple"))
MULTANT = s;
else if (s.StartsWith("New MaxRange"))
NEWRANGE = s;
}
}

Expand Down Expand Up @@ -212,6 +222,33 @@ public static void Load()
ColFriend = false;
}

// NK allow multiple antennae
temp = MULTANT.Split("=".ToCharArray());
tmp = temp[temp.Length - 1];
temp = tmp.Split(" ".ToCharArray());
try
{
if (temp[temp.Length - 1].ToLower().Equals("on")) useMultiple = true;
if (temp[temp.Length - 1].ToLower().Equals("off")) useMultiple = false;
}
catch (Exception)
{
useMultiple = false;
}
// NK new max range algorithm
temp = NEWRANGE.Split("=".ToCharArray());
tmp = temp[temp.Length - 1];
temp = tmp.Split(" ".ToCharArray());
try
{
if (temp[temp.Length - 1].ToLower().Equals("on")) useNewRange = true;
if (temp[temp.Length - 1].ToLower().Equals("off")) useNewRange = false;
}
catch (Exception)
{
ColFriend = false;
}

}
else
KSP.IO.File.WriteAllText<RemoteCore>(
Expand Down
15 changes: 9 additions & 6 deletions RTUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public static void applyLocks()
{
if (!InputLockManager.IsLocked(ControlTypes.STAGING))
InputLockManager.SetControlLock(ControlTypes.STAGING, "LockStaging");
if (!InputLockManager.IsLocked(ControlTypes.SAS))
InputLockManager.SetControlLock(ControlTypes.SAS, "LockSAS");
if (!InputLockManager.IsLocked(ControlTypes.GROUPS_ALL))
InputLockManager.SetControlLock(ControlTypes.GROUPS_ALL, "LockActions");
}
Expand All @@ -93,10 +91,6 @@ public static void removeLocks()
{
if (InputLockManager.IsLocked(ControlTypes.STAGING))
InputLockManager.RemoveControlLock("LockStaging");

if (InputLockManager.IsLocked(ControlTypes.SAS))
InputLockManager.RemoveControlLock("LockSAS");

if (InputLockManager.IsLocked(ControlTypes.GROUPS_ALL))
InputLockManager.RemoveControlLock("LockActions");
}
Expand Down Expand Up @@ -276,6 +270,15 @@ public static int restForPeriod(int[] restArray, double vector, int resting)
return resting;
}

// NK electricity
public static string eCost(float eDrain)
{
if (eDrain >= 1)
return eDrain.ToString("0.00") + "/sec.";
else
return (eDrain * 60f).ToString("0.00") + "/min.";
}

public static string length(double m)
{
if (m >= 1000000000000000000)
Expand Down
106 changes: 82 additions & 24 deletions RelayNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,49 +175,107 @@ List<RelayNode> reconstructPath(Dictionary<RelayNode, RelayNode> cameFrom, Relay
return tmp;
}

bool inRange(RelayNode na, RelayNode nb)
// NK pull out distance return
// NK new distance calcs
// = weaker + sqrt(weaker * stronger), with these maximums:
// antenna to either: Max of 100x weaker.
// dish to dish: Max of 1000x weaker.
static float distFunc(float minRange, float maxRange, float clamp)
{
if (RTGlobals.useNewRange)
{
float temp = minRange + (float)Math.Sqrt(minRange * maxRange);
if (temp > clamp)
return clamp;
return temp;
}
else
return minRange;
}

if (CheatOptions.InfiniteEVAFuel)
return true;

float distance = (float)(na.Position - nb.Position).magnitude / 1000;
public static float nodeDistance(RelayNode na, RelayNode nb)
{
return (float)(na.Position - nb.Position).magnitude;
}

if (na.HasAntenna && nb.HasAntenna && na.AntennaRange >= distance && nb.AntennaRange >= distance) { return true; }
if (na.HasDish && nb.HasAntenna && ((nb.AntennaRange * 2) >= distance))
public static float maxDistance(RelayNode na, RelayNode nb)
{
float aRange = 0, bRange = 0, aSumRange = 0, bSumRange = 0;
float clamp = 1000f;
bool aDish = false, bDish = false;

// get max-range dish pointed at other node
if (na.HasDish)
{
foreach (DishData naData in na.DishData)
{
if (((naData.pointedAt.Equals(nb.Orbits) && !na.Orbits.Equals(nb.Orbits)) || naData.pointedAt.Equals(nb.ID)) && (naData.dishRange >= distance)) { return true; }
if (((naData.pointedAt.Equals(nb.Orbits) && !na.Orbits.Equals(nb.Orbits)) || naData.pointedAt.Equals(nb.ID)))
{
aDish = true;
if (naData.dishRange >= aRange)
aRange = naData.dishRange;
aSumRange += naData.dishRange;
}

}
}
if(RTGlobals.useMultiple)
aRange = (float)Math.Round(aRange + (aSumRange - aRange) * 0.25f);

if (nb.HasDish && na.HasAntenna && ((na.AntennaRange * 2) >= distance))
if(nb.HasDish)
{
foreach (DishData nbData in nb.DishData)
{
if (((nbData.pointedAt.Equals(na.Orbits) && !nb.Orbits.Equals(na.Orbits)) || nbData.pointedAt.Equals(na.ID)) && (nbData.dishRange >= distance)) { return true; }
if (((nbData.pointedAt.Equals(na.Orbits) && !nb.Orbits.Equals(na.Orbits)) || nbData.pointedAt.Equals(na.ID)))
{
bDish = true;
if (nbData.dishRange >= bRange)
aRange = nbData.dishRange;
bSumRange += nbData.dishRange;
}
}
}
if (RTGlobals.useMultiple)
bRange = (float)Math.Round(bRange + (bSumRange - bRange) * 0.25f);

if (na.HasDish && nb.HasDish)
// if no dish, get antenna. If neither, fail.
if (!aDish)
{
clamp = 100f;
if (na.HasAntenna)
aRange = na.AntennaRange;
else
return 0f;
}
if (!bDish)
{
clamp = 100f;
if (nb.HasAntenna)
bRange = nb.AntennaRange;
else
return 0f;
}

bool aDish = false;
bool bDish = false;
foreach (DishData naData in na.DishData)
{
if (((naData.pointedAt.Equals(nb.Orbits) && !na.Orbits.Equals(nb.Orbits)) || naData.pointedAt.Equals(nb.ID)) && (naData.dishRange >= distance)) { aDish = true; break; }
}
foreach (DishData nbData in nb.DishData)
{
if (((nbData.pointedAt.Equals(na.Orbits) && !nb.Orbits.Equals(na.Orbits)) || nbData.pointedAt.Equals(na.ID)) && (nbData.dishRange >= distance)) { bDish = true; break; }
}

return aDish && bDish;
// return distance using distance function; clamp to 1000x min range if both dishes or 100x if one or both isn't
if (aRange < bRange)
{
return distFunc(aRange, bRange, clamp * aRange);
}
else
{
return distFunc(bRange, aRange, clamp * bRange);
}
}

bool inRange(RelayNode na, RelayNode nb)
{

if (CheatOptions.InfiniteEVAFuel)
return true;

return false;
// NK refactor distance functions
float distance = nodeDistance(na, nb) * 0.001f; // convert to km
return maxDistance(na, nb) >= distance;

}

Expand Down
12 changes: 12 additions & 0 deletions RelayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void ConstructFromUnloaded()
if (hasCommand) break;
}

float sumRange = 0f; // NK allow multiple antennae

foreach (ProtoPartSnapshot p in this.vessel.protoVessel.protoPartSnapshots)
{
foreach (ProtoPartModuleSnapshot s in p.modules)
Expand All @@ -50,6 +52,7 @@ void ConstructFromUnloaded()
this.hasAntenna = true;
this.antennaRange = lngth;
}
sumRange += lngth; // NK allow multiple antennae
}

if (n.HasValue("dishRange"))
Expand All @@ -69,6 +72,9 @@ void ConstructFromUnloaded()

}
}
// NK allow multiple antennae
if (this.hasAntenna && RTGlobals.useMultiple)
this.antennaRange = (float)Math.Round(this.antennaRange + (sumRange - this.antennaRange) * 0.25f);
}


Expand All @@ -87,6 +93,8 @@ void ConstructFromLoaded()
if (hasCommand) break;
}

float sumRange = 0f; // NK allow multiple antennae

foreach (Part p in vessel.parts)
foreach (PartModule m in p.Modules)
{
Expand All @@ -98,6 +106,7 @@ void ConstructFromLoaded()
this.hasAntenna = true;
this.antennaRange = lngth;
}
sumRange += lngth; // NK allow multiple antennae
}

if (RTUtils.containsField(m, "dishRange"))
Expand All @@ -115,6 +124,9 @@ void ConstructFromLoaded()
}
}
}
// NK allow multiple antennae
if (this.hasAntenna && RTGlobals.useMultiple)
this.antennaRange = (float)Math.Round(this.antennaRange + (sumRange - this.antennaRange) * 0.25f);

}

Expand Down
Loading