Skip to content

Commit

Permalink
Add ExperimentCount, ExperimentId, ScienceTypeId
Browse files Browse the repository at this point in the history
Issue #260
  • Loading branch information
MOARdV committed Mar 2, 2019
1 parent 8e31fd1 commit 543d558
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Source/MASFlightComputerProxy3.cs
Expand Up @@ -1643,6 +1643,23 @@ public string ExperimentBiome(double experimentId)
return string.Empty;
}

/// <summary>
/// Returns a count of the total number of experiments of the specified science type.
/// If an invalid science type is selected, returns 0.
/// </summary>
/// <param name="scienceTypeId">An integer in the range [0, `fc.ScienceTypeTotal()`).</param>
/// <returns>The total number of experiments for the selected science type.</returns>
public double ExperimentCount(double scienceTypeId)
{
int id = (int)scienceTypeId;
if (id >= 0 && id < vc.scienceType.Length)
{
return vc.scienceType[id].experiments.Count;
}

return 0.0;
}

/// <summary>
/// Returns the size of the data for experiment `experimentId`.
///
Expand Down Expand Up @@ -1670,6 +1687,27 @@ public double ExperimentDataSize(double experimentId)
return 0.0;
}

/// <summary>
/// Returns the `experimentId` value for the selected experiment for the science type ID. This
/// value may then be used as the parameter for science fields that require `experimentId`. If
/// an invalid `scienceTypeId` or `experimentIndex` is used, this function returns -1.
/// </summary>
/// <param name="scienceTypeId">An integer in the range [0, `fc.ScienceTypeTotal()`).</param>
/// <param name="experimentIndex">An integer in the range [0, `fc.ExperimentCount(scienceTypeId)`).</param>
/// <returns>The experimentId for the selected experiment, or -1 if an invalid id or index was provided.</returns>
public double ExperimentId(double scienceTypeId, double experimentIndex)
{
int id = (int)scienceTypeId;
int expIdx = (int)experimentIndex;
if (id >= 0 && id < vc.scienceType.Length && expIdx >= 0 && expIdx < vc.scienceType[id].experiments.Count)
{
int hashCode = vc.scienceType[id].experiments[expIdx].GetHashCode();
return Array.FindIndex(vc.moduleScienceExperiment, x => x.GetHashCode() == hashCode);
}

return -1.0;
}

/// <summary>
/// Returns the results of the selected experiment.
///
Expand Down Expand Up @@ -2064,6 +2102,21 @@ public string ScienceType(double scienceTypeId)
return string.Empty;
}

/// <summary>
/// Returns a number usable as the `scienceTypeId` parameter in science functions
/// based on the `scienceTypeName` parameter. If an invalid name is supplied, or
/// there are no experiments of the named type, returns -1.
///
/// Note that `scienceTypeName` is the "id" field for the corresponding EXPERIMENT_DEFINITION
/// from ScienceDefs.cfg (or another science definition config file).
/// </summary>
/// <param name="scienceTypeName">The id of the science.</param>
/// <returns>An integer in the range [0, `fc.ScienceTypeTotal()`), or -1.</returns>
public double ScienceTypeId(string scienceTypeName)
{
return Array.FindIndex(vc.scienceType, x => x.type.id == scienceTypeName);
}

/// <summary>
/// Returns the total number of categories of science experiments aboard the vessel.
/// </summary>
Expand Down

0 comments on commit 543d558

Please sign in to comment.