Example #1
0
 public static void RemoveKerbal(Kerbal kerbal)
 {
     if (kerbal.pcm != null)
     {
         RemoveKerbal(kerbal.pcm);
         kerbal._pcm = null;
     }
 }
Example #2
0
 public Kerbal(Kerbal k)
 {
     _pcm            = k._pcm;
     name            = k.name;
     gender          = k.gender;
     experienceTrait = k.experienceTrait;
     kerbalType      = k.kerbalType;
 }
 public Kerbal(Kerbal k)
 {
     _pcm = k._pcm;
     name = k.name;
     gender = k.gender;
     experienceTrait = k.experienceTrait;
     kerbalType = k.kerbalType;
 }
 public KerbalData(KerbalData k)
 {
     kerbal = new Kerbal(k.kerbal);
     body = k.body;
     orbit = k.orbit;
     latitude = k.latitude;
     longitude = k.longitude;
     altitude = k.altitude;
     landed = k.landed;
     owned = k.owned;
     addToRoster = k.addToRoster;
     pqsCity = k.pqsCity;
     pqsOffset = k.pqsOffset;
     heading = k.heading;
 }
Example #5
0
        public static Kerbal Load(ConfigNode node)
        {
            string          name = ConfigNodeUtil.ParseValue <string>(node, "name");
            ProtoCrewMember crew = HighLogic.CurrentGame.CrewRoster.AllKerbals().Where(pcm => pcm.name == name).FirstOrDefault();

            if (crew != null)
            {
                return(new Kerbal(crew));
            }
            else
            {
                ProtoCrewMember.Gender gender         = ConfigNodeUtil.ParseValue <ProtoCrewMember.Gender>(node, "gender", RandomGender());
                string experienceTrait                = ConfigNodeUtil.ParseValue <string>(node, "experienceTrait", RandomExperienceTrait());
                ProtoCrewMember.KerbalType kerbalType = ConfigNodeUtil.ParseValue <ProtoCrewMember.KerbalType>(node, "kerbalType", ProtoCrewMember.KerbalType.Crew);

                Kerbal k = new Kerbal(gender, name, experienceTrait);
                k.kerbalType = kerbalType;
                return(k);
            }
        }
Example #6
0
 public PksOnStationParameter(CelestialBody body, string researchCategory, int tier, ContractConfigurator.Kerbal kerbal)
 {
     this.body             = body.name;
     this.researchCategory = researchCategory;
     this.tier             = tier;
     this.rescuedKerbal    = kerbal.name;
 }
Example #7
0
        public override bool Load(ConfigNode configNode)
        {
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <CelestialBody>(configNode, nameof(body), x => body = x, this, null, Validation.NotNull);

            // TODO: write a validator for researchCategory
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, nameof(researchCategory), x => researchCategory = x, this, null, Validation.NotNull);
            valid &= ConfigNodeUtil.ParseValue <int>(configNode, nameof(tier), x => tier = x, this, -1, x => Validation.BetweenInclusive(x, 0, 4));
            valid &= ConfigNodeUtil.ParseValue <ContractConfigurator.Kerbal>(configNode, nameof(kerbal), x => kerbal = x, this, null, Validation.NotNull);

            return(valid);
        }
Example #8
0
        void Update()
        {
            if (HighLogic.LoadedScene != GameScenes.MAINMENU &&
                ContractSystem.Instance != null &&
                ContractPreLoader.Instance != null &&
                nameQueue.Count() + routinesRunning < draftLimit &&
                nextAttempt < Time.time)
            {
                // Start the coroutine
                object      success    = (Action <Dictionary <string, string> >)(OnSuccess);
                object      failure    = (Action <string>)(OnFailure);
                IEnumerator enumerator = (IEnumerator)draftMethod.Invoke(null, new object[] { success, failure, false, true, Kerbal.RandomExperienceTrait() });
                Instance.StartCoroutine(enumerator);

                routinesRunning++;
            }
        }
 public static void RemoveKerbal(Kerbal kerbal)
 {
     if (kerbal.pcm != null)
     {
         RemoveKerbal(kerbal.pcm);
         kerbal._pcm = null;
     }
 }
        public static Kerbal Load(ConfigNode node)
        {
            string name = ConfigNodeUtil.ParseValue<string>(node, "name");
            ProtoCrewMember crew = HighLogic.CurrentGame.CrewRoster.AllKerbals().Where(pcm => pcm.name == name).FirstOrDefault();

            if (crew != null)
            {
                return new Kerbal(crew);
            }
            else
            {
                ProtoCrewMember.Gender gender = ConfigNodeUtil.ParseValue<ProtoCrewMember.Gender>(node, "gender", RandomGender());
                string experienceTrait = ConfigNodeUtil.ParseValue<string>(node, "experienceTrait", RandomExperienceTrait());
                ProtoCrewMember.KerbalType kerbalType = ConfigNodeUtil.ParseValue<ProtoCrewMember.KerbalType>(node, "kerbalType", ProtoCrewMember.KerbalType.Crew);

                Kerbal k = new Kerbal(gender, name, experienceTrait);
                k.kerbalType = kerbalType;
                return k;
            }
        }
Example #11
0
        /// <summary>
        /// Loads the contract type details from the given config node.
        /// </summary>
        /// <param name="configNode">The config node to load from.</param>
        /// <returns>Whether the load was successful.</returns>
        public bool Load(ConfigNode configNode)
        {
            try
            {
                // Logging on
                LoggingUtil.CaptureLog = true;

                dataNode = new DataNode(configNode.GetValue("name"), this);

                ConfigNodeUtil.ClearCache(true);
                ConfigNodeUtil.SetCurrentDataNode(dataNode);
                bool valid = true;

                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "name", x => name = x, this);

                // Load contract text details
                valid &= ConfigNodeUtil.ParseValue <ContractGroup>(configNode, "group", x => group = x, this, (ContractGroup)null);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "title", x => title = x, this);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "tag", x => tag = x, this, "");
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "description", x => description = x, this, (string)null);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "topic", x => topic = x, this, (string)null);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "subject", x => subject = x, this, (string)null);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "motivation", x => motivation = x, this, (string)null);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "notes", x => notes = x, this, (string)null);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "synopsis", x => synopsis = x, this);
                valid &= ConfigNodeUtil.ParseValue <string>(configNode, "completedMessage", x => completedMessage = x, this);

                // Load optional attributes
                valid &= ConfigNodeUtil.ParseValue <Agent>(configNode, "agent", x => agent = x, this, (Agent)null);
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "minExpiry", x => minExpiry = x, this, 1.0f, x => Validation.GE(x, 0.0f));
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "maxExpiry", x => maxExpiry = x, this, 7.0f, x => Validation.GE(x, minExpiry));
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "deadline", x => deadline = x, this, 0.0f, x => Validation.GE(x, 0.0f));
                valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "cancellable", x => cancellable = x, this, true);
                valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "declinable", x => declinable = x, this, true);
                valid &= ConfigNodeUtil.ParseValue <List <Contract.ContractPrestige> >(configNode, "prestige", x => prestige = x, this, new List <Contract.ContractPrestige>());
                valid &= ConfigNodeUtil.ParseValue <CelestialBody>(configNode, "targetBody", x => targetBody = x, this, (CelestialBody)null);

                valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxCompletions", x => maxCompletions = x, this, 0, x => Validation.GE(x, 0));
                valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxSimultaneous", x => maxSimultaneous = x, this, 0, x => Validation.GE(x, 0));

                // Load rewards
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "rewardFunds", x => rewardFunds = x, this, 0.0f, x => Validation.GE(x, 0.0f));
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "rewardReputation", x => rewardReputation = x, this, 0.0f, x => Validation.GE(x, 0.0f));
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "rewardScience", x => rewardScience = x, this, 0.0f, x => Validation.GE(x, 0.0f));
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "failureFunds", x => failureFunds = x, this, 0.0f, x => Validation.GE(x, 0.0f));
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "failureReputation", x => failureReputation = x, this, 0.0f, x => Validation.GE(x, 0.0f));
                valid &= ConfigNodeUtil.ParseValue <float>(configNode, "advanceFunds", x => advanceFunds = x, this, 0.0f, x => Validation.GE(x, 0.0f));

                // Load other values
                valid &= ConfigNodeUtil.ParseValue <double>(configNode, "weight", x => weight = x, this, 1.0, x => Validation.GE(x, 0.0f));

                // TODO - these are to be deprecated
                if (configNode.HasValue("targetBodies"))
                {
                    valid &= ConfigNodeUtil.ParseValue <List <CelestialBody> >(configNode, "targetBodies", x => targetBodies = x, this, new List <CelestialBody>());
                    LoggingUtil.LogWarning(this, "The 'targetBodies' attribute is obsolete as of Contract Configurator 0.7.4.  It will be removed in 1.0.0 in favour of the DATA { } node.");
                }
                if (configNode.HasValue("targetVessel"))
                {
                    valid &= ConfigNodeUtil.ParseValue <Vessel>(configNode, "targetVessel", x => targetVessel = x, this, (Vessel)null);
                    LoggingUtil.LogWarning(this, "The 'targetVessel' attribute is obsolete as of Contract Configurator 0.7.4.  It will be removed in 1.0.0 in favour of the DATA { } node.");
                }
                if (configNode.HasValue("targetVessels"))
                {
                    valid &= ConfigNodeUtil.ParseValue <List <Vessel> >(configNode, "targetVessels", x => targetVessels = x, this, new List <Vessel>());
                    LoggingUtil.LogWarning(this, "The 'targetVessels' attribute is obsolete as of Contract Configurator 0.7.4.  It will be removed in 1.0.0 in favour of the DATA { } node.");
                }
                if (configNode.HasValue("targetKerbal"))
                {
                    valid &= ConfigNodeUtil.ParseValue <Kerbal>(configNode, "targetKerbal", x => targetKerbal = x, this, (Kerbal)null);
                    LoggingUtil.LogWarning(this, "The 'targetKerbal' attribute is obsolete as of Contract Configurator 0.7.4.  It will be removed in 1.0.0 in favour of the DATA { } node.");
                }
                if (configNode.HasValue("targetKerbals"))
                {
                    valid &= ConfigNodeUtil.ParseValue <List <Kerbal> >(configNode, "targetKerbals", x => targetKerbals = x, this, new List <Kerbal>());
                    LoggingUtil.LogWarning(this, "The 'targetKerbals' attribute is obsolete as of Contract Configurator 0.7.4.  It will be removed in 1.0.0 in favour of the DATA { } node.");
                }

                // Load DATA nodes
                foreach (ConfigNode data in ConfigNodeUtil.GetChildNodes(configNode, "DATA"))
                {
                    Type type          = null;
                    bool requiredValue = true;
                    valid &= ConfigNodeUtil.ParseValue <Type>(data, "type", x => type = x, this);
                    valid &= ConfigNodeUtil.ParseValue <bool>(data, "requiredValue", x => requiredValue = x, this, true);

                    if (type != null)
                    {
                        foreach (ConfigNode.Value pair in data.values)
                        {
                            string name = pair.name;
                            if (name != "type" && name != "requiredValue")
                            {
                                object value = null;

                                // Create the setter function
                                Type     actionType = typeof(Action <>).MakeGenericType(type);
                                Delegate del        = Delegate.CreateDelegate(actionType, value, typeof(ContractType).GetMethod("NullAction"));

                                // Get the ParseValue method
                                MethodInfo method = typeof(ConfigNodeUtil).GetMethods(BindingFlags.Static | BindingFlags.Public).
                                                    Where(m => m.Name == "ParseValue" && m.GetParameters().Count() == 4).Single();
                                method = method.MakeGenericMethod(new Type[] { type });

                                // Invoke the ParseValue method
                                valid &= (bool)method.Invoke(null, new object[] { data, name, del, this });

                                dataValues[name] = requiredValue;
                            }
                        }
                    }
                }

                // Check for unexpected values - always do this last
                valid &= ConfigNodeUtil.ValidateUnexpectedValues(configNode, this);

                log = LoggingUtil.capturedLog;
                LoggingUtil.CaptureLog = false;

                // Load parameters
                foreach (ConfigNode contractParameter in ConfigNodeUtil.GetChildNodes(configNode, "PARAMETER"))
                {
                    ParameterFactory paramFactory = null;
                    valid &= ParameterFactory.GenerateParameterFactory(contractParameter, this, out paramFactory);
                    if (paramFactory != null)
                    {
                        paramFactories.Add(paramFactory);
                        if (paramFactory.hasWarnings)
                        {
                            hasWarnings = true;
                        }
                    }
                }

                // Load behaviours
                foreach (ConfigNode requirementNode in ConfigNodeUtil.GetChildNodes(configNode, "BEHAVIOUR"))
                {
                    BehaviourFactory behaviourFactory = null;
                    valid &= BehaviourFactory.GenerateBehaviourFactory(requirementNode, this, out behaviourFactory);
                    if (behaviourFactory != null)
                    {
                        behaviourFactories.Add(behaviourFactory);
                        if (behaviourFactory.hasWarnings)
                        {
                            hasWarnings = true;
                        }
                    }
                }

                // Load requirements
                foreach (ConfigNode requirementNode in ConfigNodeUtil.GetChildNodes(configNode, "REQUIREMENT"))
                {
                    ContractRequirement requirement = null;
                    valid &= ContractRequirement.GenerateRequirement(requirementNode, this, out requirement);
                    if (requirement != null)
                    {
                        requirements.Add(requirement);
                        if (requirement.hasWarnings)
                        {
                            hasWarnings = true;
                        }
                    }
                }

                // Logging on
                LoggingUtil.CaptureLog = true;

                // Check we have at least one valid parameter
                if (paramFactories.Count() == 0)
                {
                    LoggingUtil.LogError(this.GetType(), ErrorPrefix() + ": Need at least one parameter for a contract!");
                    valid = false;
                }

                // Do the deferred loads
                valid &= ConfigNodeUtil.ExecuteDeferredLoads();

                config  = configNode.ToString();
                hash    = config.GetHashCode();
                enabled = valid;
                log    += LoggingUtil.capturedLog;
                LoggingUtil.CaptureLog = false;

                return(valid);
            }
            catch
            {
                enabled = false;
                throw;
            }
        }