protected void CreateDelegates() { ParameterDelegateMatchType matchType = ParameterDelegateMatchType.FILTER; if (maxCount == 0) { matchType = ParameterDelegateMatchType.NONE; } // Filter by type if (antennaType == AntennaType.Dish) { AddParameter(new ParameterDelegate <IAntenna>("Type: " + antennaType, a => a.CanTarget, matchType)); } else if (antennaType == AntennaType.Omni) { AddParameter(new ParameterDelegate <IAntenna>("Type: " + antennaType, a => !a.CanTarget, matchType)); } // Filter for active vessel if (activeVessel) { AddParameter(new ParameterDelegate <IAntenna>("Target: Active vessel", a => a.Target == NetworkManager.ActiveVesselGuid || a.Omni > 0.0, matchType)); } // Filter for celestial bodies else if (targetBody != null) { AddParameter(new ParameterDelegate <IAntenna>("Target: " + targetBody.CleanDisplayName(), a => a.Target == targetBody.Guid(), matchType)); } // Activated and powered AddParameter(new ParameterDelegate <IAntenna>("Activated", a => a.Activated, matchType, true)); AddParameter(new ParameterDelegate <IAntenna>("Powered", a => a.Powered, matchType, true)); // Filter for range if (minRange != 0.0 || maxRange != double.MaxValue) { string output = "Range: "; if (maxRange == double.MaxValue) { output += "At least " + RemoteTechAssistant.RangeString(minRange); } else if (minRange == 0) { output += "At most " + RemoteTechAssistant.RangeString(maxRange); } else { output += "Between " + RemoteTechAssistant.RangeString(minRange) + " and " + RemoteTechAssistant.RangeString(maxRange); } AddParameter(new ParameterDelegate <IAntenna>(output, a => Math.Max(a.Omni, a.Dish) >= minRange && Math.Max(a.Omni, a.Dish) <= maxRange, matchType)); } // Extra filter for celestial bodies if (!activeVessel && targetBody != null) { double distance = (Planetarium.fetch.Home.position - targetBody.position).magnitude; AddParameter(new ParameterDelegate <IAntenna>("Range: In range of " + targetBody.CleanDisplayName(true), a => Math.Max(a.Omni, a.Dish) >= distance, matchType, true)); } // Validate count if (minCount != 0 || maxCount != int.MaxValue && !(minCount == maxCount && maxCount == 0)) { AddParameter(new CountParameterDelegate <IAntenna>(minCount, maxCount)); } }
protected void CreateDelegates() { ParameterDelegateMatchType matchType = ParameterDelegateMatchType.FILTER; if (maxCount == 0) { matchType = ParameterDelegateMatchType.NONE; } // Filter by type if (antennaType == AntennaType.Dish) { AddParameter(new ParameterDelegate <IAntenna>(Localizer.Format("#cc.remotetech.param.HasAntenna.type", antennaType.displayDescription()), a => a.CanTarget, matchType)); } else if (antennaType == AntennaType.Omni) { AddParameter(new ParameterDelegate <IAntenna>(Localizer.Format("#cc.remotetech.param.HasAntenna.type", antennaType.displayDescription()), a => !a.CanTarget, matchType)); } // Filter for active vessel if (activeVessel) { AddParameter(new ParameterDelegate <IAntenna>(Localizer.Format("#cc.remotetech.param.HasAntenna.target", Localizer.GetStringByTag("#RT_ModuleUI_ActiveVessel")), a => a.Target == NetworkManager.ActiveVesselGuid || a.Omni > 0.0, matchType)); } // Filter for celestial bodies else if (targetBody != null) { AddParameter(new ParameterDelegate <IAntenna>(Localizer.Format("#cc.remotetech.param.HasAntenna.target", targetBody.displayName), a => a.Target == targetBody.Guid(), matchType)); } // Activated and powered AddParameter(new ParameterDelegate <IAntenna>(Localizer.GetStringByTag("#cc.remotetech.param.HasAntenna.activated"), a => a.Activated, matchType, true)); AddParameter(new ParameterDelegate <IAntenna>(Localizer.GetStringByTag("#cc.remotetech.param.HasAntenna.powered"), a => a.Powered, matchType, true)); // Filter for range if (minRange != 0.0 || maxRange != double.MaxValue) { string countStr; if (maxRange == double.MaxValue) { countStr = Localizer.Format("#cc.param.count.atLeast", RemoteTechAssistant.RangeString(minRange)); } else if (minRange == 0) { countStr = Localizer.Format("#cc.param.count.atMost", RemoteTechAssistant.RangeString(maxRange)); } else { countStr = Localizer.Format("#cc.param.count.between", RemoteTechAssistant.RangeString(minRange), RemoteTechAssistant.RangeString(maxRange)); } AddParameter(new ParameterDelegate <IAntenna>(Localizer.Format("#cc.remotetech.param.HasAntenna.range", countStr), a => Math.Max(a.Omni, a.Dish) >= minRange && Math.Max(a.Omni, a.Dish) <= maxRange, matchType)); } // Extra filter for celestial bodies if (!activeVessel && targetBody != null) { double distance = (Planetarium.fetch.Home.position - targetBody.position).magnitude; AddParameter(new ParameterDelegate <IAntenna>(Localizer.Format("#cc.remotetech.param.HasAntenna.range.body", targetBody.displayName), a => Math.Max(a.Omni, a.Dish) >= distance, matchType, true)); } // Validate count if (minCount != 0 || maxCount != int.MaxValue && !(minCount == maxCount && maxCount == 0)) { AddParameter(new CountParameterDelegate <IAntenna>(minCount, maxCount)); } }