Skip to content

Commit

Permalink
Fix bug of valid connection displayed in wrong constellation colour
Browse files Browse the repository at this point in the history
  • Loading branch information
KSP-TaxiService committed Jul 26, 2021
1 parent be7cda8 commit e4c0a62
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ private Color getConstellationColor(CommNode a, CommNode b)
continue;
}

//ensure connection can be established on this frequency (eg 1<->1 not 1<->2)
if (a.isHome != true && b.isHome != true) //skip if either A or B CommNet Home (always relay)
{
var vesselA = (a.GetVessel().connection as IModularCommNetVessel).GetModuleOfType<CNCCommNetVessel>();
var vesselB = (b.GetVessel().connection as IModularCommNetVessel).GetModuleOfType<CNCCommNetVessel>();
if (!vesselA.isConnectionEligible(vesselB, commonFreqs[i]))
{
continue;
}
}

thisRange = CNCCommNetScenario.RangeModel.GetMaximumRange(CNCCommNetScenario.Instance.getCommPower(a, commonFreqs[i]), CNCCommNetScenario.Instance.getCommPower(b, commonFreqs[i]));
if(thisRange > longestRange)
{
Expand Down
27 changes: 27 additions & 0 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public enum FrequencyListOperation
protected bool stageActivated = false;
public bool IsCommandable = true;

public List<CNCAntennaPartInfo> Antennas { get { return vesselAntennas; } }

/// <summary>
/// Retrieve the CNC data from the vessel, in addition of stock network joining
/// </summary>
Expand Down Expand Up @@ -893,5 +895,30 @@ protected void groundSciencePartStateChange(ModuleGroundSciencePart sciencePart)
this.rebuildFreqList(true);
}
}

/// <summary>
/// Check if this and target vessels can establish connection of specific frequency
/// </summary>
public bool isConnectionEligible(CNCCommNetVessel otherVessel, short targetFreq)
{
for(int i = 0; i < this.vesselAntennas.Count; i++)
{
if(this.vesselAntennas[i].frequency == targetFreq)
{
for(int j = 0; j < otherVessel.Antennas.Count; j++)
{
if (otherVessel.Antennas[j].frequency == targetFreq)
{
if(this.vesselAntennas[i].antennaType == AntennaType.RELAY || otherVessel.Antennas[j].antennaType == AntennaType.RELAY)
{
return true;
}
}
}
}
}

return false; //cannot connect to each other
}
}
}

0 comments on commit e4c0a62

Please sign in to comment.