Skip to content

Commit

Permalink
New Condition: Part
Browse files Browse the repository at this point in the history
  • Loading branch information
jwvanderbeck committed Mar 28, 2015
1 parent 6a503a7 commit 6af0734
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Binary file modified GameData/RealScience/Plugins/RealScience.dll
Binary file not shown.
82 changes: 82 additions & 0 deletions source/Conditions/RealScienceCondition_Part.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;

using UnityEngine;

namespace RealScience.Conditions
{
class RealScienceCondition_Part : RealScienceCondition
{
// common properties
public string conditionType = "Part";
public bool restriction = false;
public string exclusion = "";
public float dataRateModifier = 1f;
// specific properties
public string requiredPartName;

public override float DataRateModifier
{
get { return dataRateModifier; }
}
public override bool IsRestriction
{
get { return restriction; }
}
public override string Exclusion
{
get { return exclusion; }
}

public override bool Evaluate(Part part, float deltaTime)
{
foreach(Part vPart in part.vessel.Parts)
{
if (vPart.partName.ToLower() == requiredPartName)
return true;
}
return false;
}
public override void Load(ConfigNode node)
{
// Load common properties
if (node.HasValue("conditionType"))
conditionType = node.GetValue("conditionType");
if (node.HasValue("exclusion"))
exclusion = node.GetValue("exclusion");
if (node.HasValue("restriction"))
{
try
{
restriction = bool.Parse(node.GetValue("restriction"));
}
catch (FormatException)
{
restriction = false;
}
}
if (node.HasValue("dataRateModifier"))
{
try
{
dataRateModifier = float.Parse(node.GetValue("dataRateModifier"));
}
catch (FormatException)
{
dataRateModifier = 1f;
}
}
// Load specific properties
if (node.HasValue("requiredPartName"))
requiredPartName = node.GetValue("requiredPartName");
}
public override void Save(ConfigNode node)
{
// Save common properties
node.AddValue("conditionType", conditionType);
node.AddValue("restriction", restriction);
node.AddValue("exclusion", exclusion);
node.AddValue("dataRateModifier", dataRateModifier);
node.AddValue("requiredPartName", requiredPartName);
}
}
}
1 change: 1 addition & 0 deletions source/RealScience.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="Conditions\RealScienceCondition_Biome.cs" />
<Compile Include="Conditions\RealScienceCondition_Body.cs" />
<Compile Include="Conditions\RealScienceCondition_Orbit.cs" />
<Compile Include="Conditions\RealScienceCondition_Part.cs" />
<Compile Include="Conditions\RealScienceCondition_Resource.cs" />
<Compile Include="Conditions\RealScienceCondition_Situation.cs" />
<Compile Include="FrameworkExt\ClassDefinitions.cs" />
Expand Down

0 comments on commit 6af0734

Please sign in to comment.