Exemple #1
0
        public override void OnGameSettingsApplied()
        {
            //Update seconds per cycle
            secondsPerCycle = SnacksScenario.GetSecondsPerDay() / SnacksProperties.MealsPerDay;

            //Update input amounts
            inputList[0].amount = SnacksProperties.SnacksPerMeal;

            //Update output amounts
            outputList.Clear();
            if (SnacksProperties.RecyclersEnabled)
            {
                ProcessedResource resource = new ProcessedResource(SnacksProperties.SoilResourceName, SnacksProperties.SnacksResourceName, SnacksProperties.SnacksPerMeal, false, false, false);
                outputList.Add(resource);
            }

            //Outcomes
            outcomes.Clear();
            outcomes.Add(new FundingPenalty(true, "Kerbals are hungry for snacks! You have been fined {0:N2} Funds", SnacksProperties.FinePerKerbal));
            outcomes.Add(new RepPenalty(true, SnacksProperties.RepLostWhenHungry, "Kerbals are hungry for snacks! Your reputation has decreased by {0:N3}"));
            outcomes.Add(new SciencePenalty(true));
            if (SnacksProperties.CanStarveToDeath)
            {
                outcomes.Add(new DeathPenalty(SnacksProperties.SnacksResourceName, SnacksProperties.MealsSkippedBeforeDeath, "has died from a lack of Snacks!"));
            }
            if (SnacksProperties.FaintWhenHungry)
            {
                outcomes.Add(new FaintPenalty(SnacksProperties.SnacksResourceName, SnacksProperties.MealsBeforeFainting, SnacksProperties.NapTime * 60f, "has fainted from a lack of Snacks!"));
            }

            if (SnacksScenario.Instance.rosterResources.ContainsKey(StressProcessor.StressResourceName))
            {
                outcomes.Add(new ProduceResource(StressProcessor.StressResourceName, 1.0, false, string.Empty));
            }
        }
Exemple #2
0
        protected virtual void updateAstronautData(Vessel vessel, ProcessedResource resource, SnacksProcessorResult result)
        {
            ProtoCrewMember[] astronauts;
            AstronautData     astronautData;

            //Get astronauts
            if (vessel.loaded)
            {
                astronauts = vessel.GetVesselCrew().ToArray();
            }
            else
            {
                astronauts = vessel.protoVessel.GetVesselCrew().ToArray();
            }

            for (int index = 0; index < astronauts.Length; index++)
            {
                //Get astronaut data
                astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]);
                if (astronautData == null)
                {
                    continue;
                }

                //If the result was successful then remove failed count and increment success count.
                if (result.completedSuccessfully)
                {
                    //Increment success count
                    if (!astronautData.processedResourceSuccesses.ContainsKey(resource.resourceName))
                    {
                        astronautData.processedResourceSuccesses.Add(resource.resourceName, 0);
                    }
                    astronautData.processedResourceSuccesses[resource.resourceName] += 1;

                    //Remove failure count
                    if (astronautData.processedResourceFailures.ContainsKey(resource.resourceName))
                    {
                        astronautData.processedResourceFailures.Remove(resource.resourceName);
                    }
                }

                //Otherwise, remove success count and increment failed count.
                else
                {
                    //Increment failure count
                    if (!astronautData.processedResourceFailures.ContainsKey(resource.resourceName))
                    {
                        astronautData.processedResourceFailures.Add(resource.resourceName, 0);
                    }
                    astronautData.processedResourceFailures[resource.resourceName] += 1;

                    //Remove success count
                    if (astronautData.processedResourceSuccesses.ContainsKey(resource.resourceName))
                    {
                        astronautData.processedResourceSuccesses.Remove(resource.resourceName);
                    }
                }
            }
        }
Exemple #3
0
        public SnacksResourceProcessor()
        {
            name = SnacksProcessorName;

            //Get input list
            inputList = new List <ProcessedResource>();
            ProcessedResource resource = new ProcessedResource(SnacksProperties.SnacksResourceName, null, SnacksProperties.SnacksPerMeal);

            inputList.Add(resource);

            //Get output list
            outputList = new List <ProcessedResource>();

            //Setup the amounts and such based on current game settings
            OnGameSettingsApplied();
        }
Exemple #4
0
        public BaseResourceProcessor(ConfigNode node)
        {
            if (node.HasValue(ProcessorNodeName))
            {
                name = node.GetValue(ProcessorNodeName);
            }

            if (node.HasValue(ProcessorNodeSecondsPerCycle))
            {
                double.TryParse(node.GetValue(ProcessorNodeSecondsPerCycle), out secondsPerCycle);
            }

            //Create lists
            preconditions      = new List <BasePrecondition>();
            inputList          = new List <ProcessedResource>();
            outputList         = new List <ProcessedResource>();
            consumptionResults = new Dictionary <string, SnacksProcessorResult>();
            productionResults  = new Dictionary <string, SnacksProcessorResult>();
            outcomes           = new List <BaseOutcome>();

            //Add processed resources
            ConfigNode[]      nodes;
            ConfigNode        configNode;
            ProcessedResource resource;
            BaseOutcome       outcome;

            if (node.HasNode(ConsumedResourceNode))
            {
                nodes = node.GetNodes(ConsumedResourceNode);
                for (int index = 0; index < nodes.Length; index++)
                {
                    configNode = nodes[index];
                    resource   = new ProcessedResource();
                    resource.Load(configNode);
                    inputList.Add(resource);
                }
            }

            if (node.HasNode(ProducedResourceNode))
            {
                nodes = node.GetNodes(ProducedResourceNode);
                for (int index = 0; index < nodes.Length; index++)
                {
                    configNode = nodes[index];
                    resource   = new ProcessedResource();
                    resource.Load(configNode);
                    outputList.Add(resource);
                }
            }

            //Add outcomes
            if (node.HasNode(OutcomeNode))
            {
                nodes = node.GetNodes(OutcomeNode);
                for (int index = 0; index < nodes.Length; index++)
                {
                    configNode = nodes[index];
                    outcome    = SnacksScenario.Instance.CreateOutcome(configNode);
                    if (outcome != null)
                    {
                        outcomes.Add(outcome);
                    }
                }
            }

            //Add preconditions
            BasePrecondition precondition;

            if (node.HasNode(BasePrecondition.PRECONDITION))
            {
                nodes = node.GetNodes(BasePrecondition.PRECONDITION);
                for (int index = 0; index < nodes.Length; index++)
                {
                    configNode   = nodes[index];
                    precondition = SnacksScenario.Instance.CreatePrecondition(configNode);
                    if (precondition != null)
                    {
                        preconditions.Add(precondition);
                    }
                }
            }
        }
Exemple #5
0
        public override bool IsValid(ProtoCrewMember astronaut)
        {
            if (!base.IsValid(astronaut))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(resourceName))
            {
                return(false);
            }

            //Get roster resource
            double amount     = 0;
            double maxAmount  = 0;
            double percentage = 0;

            if (isRosterResource)
            {
                AstronautData astronautData = SnacksScenario.Instance.GetAstronautData(astronaut);
                if (astronautData == null)
                {
                    return(false);
                }
                if (!astronautData.rosterResources.ContainsKey(resourceName))
                {
                    return(false);
                }

                SnacksRosterResource rosterResource = astronautData.rosterResources[resourceName];
                amount     = rosterResource.amount;
                maxAmount  = rosterResource.maxAmount;
                percentage = amount / maxAmount;
            }

            //Try to get vessel resource
            else
            {
                if (astronaut.KerbalRef == null || astronaut.KerbalRef.InVessel == null)
                {
                    return(false);
                }

                List <ProtoPartResourceSnapshot> protoPartResources = new List <ProtoPartResourceSnapshot>();
                ProcessedResource.GetResourceTotals(astronaut.KerbalRef.InVessel, resourceName, out amount, out maxAmount, protoPartResources);
                percentage = amount / maxAmount;
            }

            //Now perform the check
            if (checkMaxAmount)
            {
                amount = maxAmount;
            }
            else if (checkAsPercentage)
            {
                amount = percentage;
            }
            switch (checkType)
            {
            case CheckValueConditionals.checkEquals:
                return(amount.Equals(valueToCheck));

            case CheckValueConditionals.checkGreaterOrEqual:
                return(amount.Equals(valueToCheck) || amount > valueToCheck);

            case CheckValueConditionals.checkGreaterThan:
                return(amount > valueToCheck);

            case CheckValueConditionals.checkLesserOrEqual:
                return(amount.Equals(valueToCheck) || amount < valueToCheck);

            case CheckValueConditionals.checkLessThan:
                return(amount < valueToCheck);
            }

            return(false);
        }
Exemple #6
0
        public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result)
        {
            if (!isRosterResource && vessel != null)
            {
                List <ProtoPartResourceSnapshot> protoPartResources = new List <ProtoPartResourceSnapshot>();
                double vesselCurrentAmount = 0;
                double vesselMaxAmount     = 0;
                double demand = amount;

                //Select random amount if enabled
                if (randomMin != randomMax)
                {
                    demand = UnityEngine.Random.Range(randomMin, randomMax);
                }

                //Get current totals
                ProcessedResource.GetResourceTotals(vessel, resourceName, out vesselCurrentAmount, out vesselMaxAmount, protoPartResources);

                //If the vessel has no resource at all then it hasn't been visited in-game yet.
                if (vesselMaxAmount <= 0)
                {
                    result.resultType = SnacksResultType.notApplicable;

                    //Call the base class
                    base.ApplyOutcome(vessel, result);

                    return;
                }

                //Multiply demand by affected crew count
                if (result.appliedPerCrew && !selectRandomCrew)
                {
                    demand *= result.affectedKerbalCount;
                }

                //If we have enough to support the whole crew, then we're good.
                if ((vesselCurrentAmount / demand) >= 0.999)
                {
                    //Request resource
                    ProcessedResource.RequestResource(vessel, resourceName, demand, protoPartResources);
                }

                //We don't have enough to support the whole crew. Figure out how many we can support.
                else
                {
                    int totalServed = (int)Math.Floor(vesselCurrentAmount / amount);

                    demand = totalServed * amount;
                    ProcessedResource.RequestResource(vessel, resourceName, vesselCurrentAmount, protoPartResources);
                }

                //Inform player
                if (!string.IsNullOrEmpty(playerMessage))
                {
                    ScreenMessages.PostScreenMessage(playerMessage, 5, ScreenMessageStyle.UPPER_LEFT);
                }
            }

            else if (result.afftectedAstronauts.Count > 0)
            {
                ProtoCrewMember[] astronauts    = null;
                AstronautData     astronautData = null;
                string            message       = string.Empty;

                //Get the crew manifest
                astronauts = result.afftectedAstronauts.ToArray();

                //Select random crew if needed
                if (selectRandomCrew)
                {
                    int randomIndex = UnityEngine.Random.Range(0, astronauts.Length - 1);
                    astronauts = new ProtoCrewMember[] { astronauts[randomIndex] };
                }

                for (int index = 0; index < astronauts.Length; index++)
                {
                    astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]);

                    if (astronautData.rosterResources.ContainsKey(resourceName))
                    {
                        SnacksRosterResource resource = astronautData.rosterResources[resourceName];
                        resource.amount -= amount;
                        if (resource.amount <= 0)
                        {
                            resource.amount = 0;
                        }
                        astronautData.rosterResources[resourceName] = resource;

                        SnacksScenario.onRosterResourceUpdated.Fire(vessel, resource, astronautData, astronauts[index]);
                    }

                    //Inform player
                    if (!string.IsNullOrEmpty(playerMessage))
                    {
                        message = vessel.vesselName + ": " + astronauts[index].name + " " + playerMessage;
                        ScreenMessages.PostScreenMessage(message, 5.0f, ScreenMessageStyle.UPPER_LEFT);
                    }
                }

                //Call the base class
                base.ApplyOutcome(vessel, result);
            }
        }