Exemplo n.º 1
0
        protected void CreateDelegates()
        {
            // Filter for celestial bodies
            if (targetBody != null && string.IsNullOrEmpty(biome))
            {
                AddParameter(new ParameterDelegate <Vessel>("Destination: " + targetBody.CleanDisplayName(),
                                                            subj => FlightGlobals.currentMainBody == targetBody, true));
            }

            // Filter for biome
            if (!string.IsNullOrEmpty(biome))
            {
                Biome  b     = new Biome(targetBody, biome);
                string title = b.IsKSC() ? "Location: " : "Biome: ";

                AddParameter(new ParameterDelegate <Vessel>(title + b,
                                                            subj => CheckBiome(FlightGlobals.ActiveVessel)));
            }

            // Filter for situation
            if (situation != null)
            {
                AddParameter(new ParameterDelegate <Vessel>("Situation: " + situation.Value.Print(),
                                                            subj => FlightGlobals.ActiveVessel != null && ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel) == situation));
            }

            // Filter for location
            if (location != null)
            {
                AddParameter(new ParameterDelegate <Vessel>("Location: " + location,
                                                            subj => FlightGlobals.ActiveVessel != null && ((location != BodyLocation.Surface) ^ FlightGlobals.ActiveVessel.LandedOrSplashed)));
            }

            // Add the experiments
            foreach (string exp in experiment)
            {
                string            experimentStr   = string.IsNullOrEmpty(exp) ? "Any" : ExperimentName(exp);
                ContractParameter experimentParam = AddParameter(new ParameterDelegate <Vessel>("Experiment: " +
                                                                                                experimentStr, subj => recoveryDone.ContainsKey(exp)));

                // Add the subject
                ContractParameter subjectParam = new ParameterDelegate <Vessel>("", subj => true);
                subjectParam.ID = exp + "Subject";
                experimentParam.AddParameter(subjectParam);

                // Filter for recovery
                if (recoveryMethod != ScienceRecoveryMethod.None)
                {
                    ContractParameter recoveryParam = experimentParam.AddParameter(new ParameterDelegate <Vessel>("Recovery: " +
                                                                                                                  RecoveryMethod(exp).Print(), subj => false));
                }
            }
        }
        protected void CreateDelegates()
        {
            // Filter for celestial bodies
            if (targetBody != null && string.IsNullOrEmpty(biome))
            {
                AddParameter(new ParameterDelegate <Vessel>(Localizer.Format("#cc.param.CollectScience.destination", targetBody.displayName),
                                                            subj => FlightGlobals.currentMainBody == targetBody, true)).ID = "destination";
            }

            // Filter for biome
            if (!string.IsNullOrEmpty(biome))
            {
                Biome  b     = new Biome(targetBody, biome);
                string title = Localizer.Format(b.IsKSC() ? "#cc.param.CollectScience.location" : "#cc.param.CollectScience.biome", b);

                AddParameter(new ParameterDelegate <Vessel>(title,
                                                            subj => CheckBiome(FlightGlobals.ActiveVessel))).ID = "biome";
            }

            // Filter for situation
            if (situation != null)
            {
                AddParameter(new ParameterDelegate <Vessel>(Localizer.Format("#cc.param.CollectScience.situation", situation.Value.Print()),
                                                            subj => FlightGlobals.ActiveVessel != null && ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel) == situation)).ID = "situation";
            }

            // Filter for location
            if (location != null)
            {
                AddParameter(new ParameterDelegate <Vessel>(Localizer.Format("#cc.param.CollectScience.location", location),
                                                            subj => FlightGlobals.ActiveVessel != null && ((location != BodyLocation.Surface) ^ FlightGlobals.ActiveVessel.LandedOrSplashed))).ID = "location";
            }

            // Add the experiments
            foreach (string exp in experiment)
            {
                string            experimentStr   = string.IsNullOrEmpty(exp) ? Localizer.GetStringByTag("#cc.science.experiment.any") : ExperimentName(exp);
                ContractParameter experimentParam = AddParameter(new ParameterDelegate <Vessel>(Localizer.Format("#cc.param.CollectScience.experiment",
                                                                                                                 experimentStr), subj => recoveryDone.ContainsKey(exp)));
                experimentParam.ID = "experiment";

                // Add the subject
                experimentParam.AddParameter(new ParameterDelegate <Vessel>("", subj => true)).ID = exp + "Subject";

                // Filter for recovery
                if (recoveryMethod != ScienceRecoveryMethod.None)
                {
                    experimentParam.AddParameter(new ParameterDelegate <Vessel>(Localizer.Format("#cc.param.CollectScience.recovery",
                                                                                                 RecoveryMethod(exp).Print()), subj => false)).ID = "recovery";
                }
            }
        }
        protected void CreateDelegates()
        {
            foreach (Filter filter in filters)
            {
                if (filter.type == ParameterDelegateMatchType.VALIDATE)
                {
                    foreach (AvailablePart part in filter.parts)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => p.partInfo.name == part.name,
                                                                       part.title, false));
                    }

                    // Filter by part modules
                    foreach (string partModule in filter.partModules)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => PartHasModule(p, partModule),
                                                                       "with module: " + ModuleName(partModule), false));
                    }

                    // Filter by part module types
                    foreach (string partModuleType in filter.partModuleTypes)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => PartHasObjective(p, partModuleType),
                                                                       "with module type: " + partModuleType, false));
                    }
                }
                else
                {
                    // Filter by part
                    if (filter.parts.Any())
                    {
                        AddParameter(new ParameterDelegate <Part>(filter.type.Prefix() + "type: " +
                                                                  filter.parts.Select(p => p.title).Aggregate((sum, s) => sum + " or " + s),
                                                                  p => filter.parts.Any(pp => p.partInfo.name == pp.name), filter.type));
                    }

                    // Filter by part modules
                    foreach (string partModule in filter.partModules)
                    {
                        AddParameter(new ParameterDelegate <Part>(filter.type.Prefix() + "module: " + ModuleName(partModule), p => PartHasModule(p, partModule), filter.type));
                    }

                    // Filter by part modules
                    foreach (string partModuleType in filter.partModuleTypes)
                    {
                        AddParameter(new ParameterDelegate <Part>(filter.type.Prefix() + "module type: " + partModuleType, p => PartHasObjective(p, partModuleType), filter.type));
                    }

                    // Filter by part modules - extended mode
                    foreach (ConfigNode.ValueList list in filter.partModuleExtended)
                    {
                        ContractParameter wrapperParam = AddParameter(new AllParameterDelegate <Part>(filter.type.Prefix() + "module", filter.type));

                        foreach (ConfigNode.Value v in list)
                        {
                            string name = Regex.Replace(v.name, @"([A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $1");
                            name = name.Substring(0, 1).ToUpper() + name.Substring(1);
                            string value = v.name == "name" ? ModuleName(v.value) : v.value;

                            ParameterDelegateMatchType childFilter = ParameterDelegateMatchType.FILTER;
                            wrapperParam.AddParameter(new ParameterDelegate <Part>(childFilter.Prefix() + name + ": " + value, p => PartModuleCheck(p, v), childFilter));
                        }
                    }

                    // Filter by category
                    if (filter.category != null)
                    {
                        AddParameter(new ParameterDelegate <Part>(filter.type.Prefix() + "category: " + filter.category,
                                                                  p => p.partInfo.category == filter.category.Value, filter.type));
                    }

                    // Filter by manufacturer
                    if (filter.manufacturer != null)
                    {
                        AddParameter(new ParameterDelegate <Part>(filter.type.Prefix() + "manufacturer: " + filter.manufacturer,
                                                                  p => p.partInfo.manufacturer == filter.manufacturer, filter.type));
                    }
                }
            }

            // Validate count
            if (minCount != 0 || maxCount != int.MaxValue && !(minCount == maxCount && maxCount == 0))
            {
                AddParameter(new CountParameterDelegate <Part>(minCount, maxCount));
            }
        }
        protected void CreateDelegates()
        {
            foreach (Filter filter in filters)
            {
                if (filter.type == ParameterDelegateMatchType.VALIDATE)
                {
                    foreach (AvailablePart part in filter.parts)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => p.partInfo.name == part.name,
                                                                       part.title, false));
                    }

                    // Filter by part modules
                    foreach (string partModule in filter.partModules)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => PartHasModule(p, partModule),
                                                                       Localizer.Format("#cc.param.PartValidation.withModule", ModuleName(partModule)), false));
                    }

                    // Filter by part module types
                    foreach (string partModuleType in filter.partModuleTypes)
                    {
                        AddParameter(new CountParameterDelegate <Part>(filter.minCount, filter.maxCount, p => PartHasObjective(p, partModuleType),
                                                                       Localizer.Format("#cc.param.PartValidation.withModuleType", ModuleTypeName(partModuleType)), false));
                    }
                }
                else
                {
                    // Filter by part
                    if (filter.parts.Any())
                    {
                        AddParameter(new ParameterDelegate <Part>(
                                         Localizer.Format("#cc.param.PartValidation.type", filter.type.Prefix(), LocalizationUtil.LocalizeList <AvailablePart>(LocalizationUtil.Conjunction.OR, filter.parts, p => p.title)),
                                         p => filter.parts.Any(pp => p.partInfo.name == pp.name), filter.type));
                    }

                    // Filter by part modules
                    foreach (string partModule in filter.partModules)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.module", filter.type.Prefix(), ModuleName(partModule)), p => PartHasModule(p, partModule), filter.type));
                    }

                    // Filter by part modules
                    foreach (string partModuleType in filter.partModuleTypes)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.moduleType", filter.type.Prefix(), ModuleTypeName(partModuleType)), p => PartHasObjective(p, partModuleType), filter.type));
                    }

                    // Filter by part modules - extended mode
                    foreach (List <Tuple <string, string, string> > list in filter.partModuleExtended)
                    {
                        ContractParameter wrapperParam = AddParameter(new AllParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.moduleShort", filter.type.Prefix()), filter.type));

                        foreach (Tuple <string, string, string> v in list)
                        {
                            string name = v.Item1;
                            string label;
                            if (string.IsNullOrEmpty(v.Item2))
                            {
                                label = Regex.Replace(name, @"([A-Z]+?(?=[A-Z][^A-Z])|\B[A-Z]+?(?=[^A-Z]))", " $1");
                                label = label.Substring(0, 1).ToUpper() + label.Substring(1);
                            }
                            else
                            {
                                label = v.Item2;
                            }
                            string value = name == "name" ? ModuleName(v.Item3) : v.Item3;

                            ParameterDelegateMatchType childFilter = ParameterDelegateMatchType.FILTER;
                            wrapperParam.AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.generic", childFilter.Prefix(), label, value), p => PartModuleCheck(p, v), childFilter));
                        }
                    }

                    // Filter by category
                    if (filter.category != null)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.category", filter.type.Prefix(), filter.category),
                                                                  p => p.partInfo.category == filter.category.Value, filter.type));
                    }

                    // Filter by manufacturer
                    if (filter.manufacturer != null)
                    {
                        AddParameter(new ParameterDelegate <Part>(Localizer.Format("#cc.param.PartValidation.manufacturer", filter.type.Prefix(), filter.manufacturer),
                                                                  p => p.partInfo.manufacturer == filter.manufacturer, filter.type));
                    }
                }
            }

            // Validate count
            if (minCount != 0 || maxCount != int.MaxValue && !(minCount == maxCount && maxCount == 0))
            {
                AddParameter(new CountParameterDelegate <Part>(minCount, maxCount));
            }
        }