public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { //Only applies to Career mode if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { //Apply funding loss if (SnacksProperties.LoseFundsWhenHungry) { double fine = finePerKerbal * result.affectedKerbalCount; Funding.Instance.AddFunds(-fine, TransactionReasons.Any); if (!string.IsNullOrEmpty(playerMessage)) { if (playerMessage.Contains("{0:N2}")) { ScreenMessages.PostScreenMessage(string.Format(playerMessage, fine), 5, ScreenMessageStyle.UPPER_LEFT); } else { ScreenMessages.PostScreenMessage(playerMessage, 5, ScreenMessageStyle.UPPER_LEFT); } } } } //Call the base class base.ApplyOutcome(vessel, result); }
public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { //Only applies to Career mode if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { float repLoss = repLossPerKerbal * result.affectedKerbalCount; Reputation.Instance.AddReputation(-repLoss, TransactionReasons.Any); if (!string.IsNullOrEmpty(playerMessage)) { if (playerMessage.Contains("{0:N3}")) { ScreenMessages.PostScreenMessage(string.Format(playerMessage, repLoss), 5, ScreenMessageStyle.UPPER_LEFT); } else { ScreenMessages.PostScreenMessage(playerMessage, 5, ScreenMessageStyle.UPPER_LEFT); } } } //Call the base class base.ApplyOutcome(vessel, result); }
public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { ProtoCrewMember[] astronauts; AstronautData astronautData; //Get vessel crew if (result.afftectedAstronauts != null && result.afftectedAstronauts.Count > 0) { astronauts = result.afftectedAstronauts.ToArray(); } else if (vessel.loaded) { astronauts = vessel.GetVesselCrew().ToArray(); } else { astronauts = vessel.protoVessel.GetVesselCrew().ToArray(); } //Clear out exempt crew List <ProtoCrewMember> nonExemptCrew = new List <ProtoCrewMember>(); for (int index = 0; index < astronauts.Length; index++) { astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]); if (astronautData.isExempt) { continue; } nonExemptCrew.Add(astronauts[index]); } if (nonExemptCrew.Count == 0) { base.ApplyOutcome(vessel, result); return; } astronauts = nonExemptCrew.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.isExempt) { continue; } applyOutcome(vessel, astronauts[index], astronautData); } //Call the base class base.ApplyOutcome(vessel, result); }
/// <summary> /// Applies the outcome to the vessel's crew /// </summary> /// <param name="vessel">The Vessel being processed.</param> /// <param name="result">The Result of the processing attempt.</param> public virtual void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { int count = childOutcomes.Count; for (int index = 0; index < count; index++) { childOutcomes[index].ApplyOutcome(vessel, result); } }
public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { if ((HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) && SnacksProperties.LoseScienceWhenHungry) { //If the vessel is loaded, apply the penalties. if (vessel.loaded) { int count = vessel.vesselModules.Count; SnacksVesselModule snacksVesselModule; int sciencePenalties = 0; for (int index = 0; index < count; index++) { if (vessel.vesselModules[index] is SnacksVesselModule) { snacksVesselModule = (SnacksVesselModule)vessel.vesselModules[index]; sciencePenalties = result.affectedKerbalCount + snacksVesselModule.sciencePenalties; break; } } //Apply Science penalties for (int index = 0; index < sciencePenalties; index++) { applySciencePenalties(vessel); } } //Not loaded, keep track of how many penalties we acquire else { ScreenMessages.PostScreenMessage("Kerbals have ruined some science aboard the " + vessel.vesselName + "! Check the vessel for details.", 5f, ScreenMessageStyle.UPPER_LEFT); ConfigNode node = vessel.protoVessel.vesselModules; if (node.HasNode(SnacksVesselModule.SnacksVesselModuleNode)) { node = node.GetNode(SnacksVesselModule.SnacksVesselModuleNode); int sciencePenalties = 0; if (node.HasValue(SnacksVesselModule.ValueSciencePenalties)) { int.TryParse(node.GetValue(SnacksVesselModule.ValueSciencePenalties), out sciencePenalties); sciencePenalties += result.affectedKerbalCount; node.SetValue(SnacksVesselModule.ValueSciencePenalties, sciencePenalties); } else { sciencePenalties = result.crewCount - result.affectedKerbalCount; node.AddValue(SnacksVesselModule.ValueSciencePenalties, sciencePenalties); } } } } //Call the base class base.ApplyOutcome(vessel, result); }
/// <summary> /// Initializes a new instance of the <see cref="T:Snacks.SnacksEvent"/> class. /// </summary> public SnacksEvent() { outcomes = new List <BaseOutcome>(); preconditions = new List <BasePrecondition>(); result = new SnacksProcessorResult(); result.affectedKerbalCount = 1; result.crewCapacity = 1; result.crewCount = 1; result.appliedPerCrew = true; result.afftectedAstronauts = new List <ProtoCrewMember>(); }
public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { ProtoCrewMember[] astronauts = null; AstronautData astronautData = null; string message = string.Empty; //Get the crew manifest if (result.afftectedAstronauts != null) { astronauts = result.afftectedAstronauts.ToArray(); } else if (vessel.loaded) { astronauts = vessel.GetVesselCrew().ToArray(); } else { astronauts = vessel.protoVessel.GetVesselCrew().ToArray(); } //Select random crew if needed if (selectRandomCrew) { int randomIndex = UnityEngine.Random.Range(0, astronauts.Length - 1); astronauts = new ProtoCrewMember[] { astronauts[randomIndex] }; } //Go through each kerbal and set their condition for (int index = 0; index < astronauts.Length; index++) { astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]); astronautData.SetCondition(conditionName); //If the vessel is loaded then remove skills if (vessel.loaded) { SnacksScenario.Instance.RemoveSkillsIfNeeded(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); }
protected virtual void applyFailureOutcomes(Vessel vessel, SnacksProcessorResult result) { int count = outcomes.Count; List <BaseOutcome> enabledOutcomes = new List <BaseOutcome>(); List <BaseOutcome> randomOutcomes = new List <BaseOutcome>(); bool randomOutcomesEnabled = SnacksProperties.RandomPenaltiesEnabled; //Find the outcomes that are enabled and add them to the appropriate lists. for (int index = 0; index < count; index++) { if (outcomes[index].IsEnabled()) { if (outcomes[index].canBeRandom && randomOutcomesEnabled) { randomOutcomes.Add(outcomes[index]); } else { enabledOutcomes.Add(outcomes[index]); } } } //Now go through and apply the outcomes (if any). count = enabledOutcomes.Count; for (int index = 0; index < count; index++) { enabledOutcomes[index].ApplyOutcome(vessel, result); } //Finally, pick a random outcome to apply (if any). if (randomOutcomes.Count > 0) { int randomIndex = UnityEngine.Random.Range(0, randomOutcomes.Count - 1); randomOutcomes[randomIndex].ApplyOutcome(vessel, result); } }
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); } } } }
/// <summary> /// Initializes a new instance of the <see cref="T:Snacks.SnacksEvent"/> class. /// </summary> /// <param name="node">A ConfigNode specifying the initialization parameters.</param> public SnacksEvent(ConfigNode node) : base() { if (!node.HasValue(SnacksEventName)) { return; } result = new SnacksProcessorResult(); result.affectedKerbalCount = 1; result.crewCapacity = 1; result.crewCount = 1; result.appliedPerCrew = true; result.afftectedAstronauts = new List <ProtoCrewMember>(); name = node.GetValue(SnacksEventName); if (node.HasValue(SnacksEventCategory)) { eventCategory = (SnacksEventCategories)Enum.Parse(typeof(SnacksEventCategories), node.GetValue(SnacksEventCategory)); } if (node.HasValue(SnacksEventAffectedKerbals)) { affectedKerbals = (KerbalsAffectedTypes)Enum.Parse(typeof(KerbalsAffectedTypes), node.GetValue(SnacksEventAffectedKerbals)); } if (node.HasValue(SnacksEventPlayerMessage)) { playerMessage = node.GetValue(SnacksEventPlayerMessage); } if (node.HasValue(SnacksEventDaysBetweenChecks)) { double.TryParse(node.GetValue(SnacksEventDaysBetweenChecks), out daysBetweenChecks); secondsBetweenChecks = daysBetweenChecks * SnacksScenario.GetSecondsPerDay(); } else if (node.HasValue(SnacksEventSecondsBetweenChecks)) { double.TryParse(node.GetValue(SnacksEventSecondsBetweenChecks), out secondsBetweenChecks); } //Preconditions preconditions = new List <BasePrecondition>(); if (node.HasNode(BasePrecondition.PRECONDITION)) { ConfigNode[] nodes = node.GetNodes(BasePrecondition.PRECONDITION); BasePrecondition precondition; for (int index = 0; index < nodes.Length; index++) { precondition = SnacksScenario.Instance.CreatePrecondition(nodes[index]); if (precondition != null) { preconditions.Add(precondition); } } } //Outcomes outcomes = new List <BaseOutcome>(); if (node.HasNode(BaseOutcome.OUTCOME)) { ConfigNode[] nodes = node.GetNodes(BaseOutcome.OUTCOME); BaseOutcome outcome; for (int index = 0; index < nodes.Length; index++) { outcome = SnacksScenario.Instance.CreateOutcome(nodes[index]); if (outcome != null) { outcomes.Add(outcome); } } } }
/// <summary> /// Consumes the resource. /// </summary> /// <param name="vessel">The vessel to work on</param> /// <param name="elapsedTime">Elapsed seconds</param> /// <param name="crewCount">Current crew count</param> /// <param name="crewCapacity">Current crew capacity</param> /// <returns>A SnacksConsumerResult containing the resuls of the consumption.</returns> public SnacksProcessorResult ConsumeResource(Vessel vessel, double elapsedTime, int crewCount, int crewCapacity) { List <ProtoPartResourceSnapshot> protoPartResources = new List <ProtoPartResourceSnapshot>(); SnacksProcessorResult result = new SnacksProcessorResult(); result.resourceName = resourceName; result.resultType = SnacksResultType.resultConsumption; result.crewCapacity = crewCapacity; result.crewCount = crewCount; if (!isRosterResource) { double vesselCurrentAmount = 0; double vesselMaxAmount = 0; double requestAmount = amount; //Get current totals getResourceTotals(vessel, 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; return(result); } //Multiply request amount by crew count requestAmount *= crewCount; //If we have enough to support the whole crew, then we're good. if ((vesselCurrentAmount / requestAmount) >= 0.999) { //Request resource requestResource(vessel, requestAmount, protoPartResources); //Update results result.affectedKerbalCount = crewCount; result.completedSuccessfully = true; result.currentAmount = vesselCurrentAmount - requestAmount; result.maxAmount = vesselMaxAmount; } //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); requestAmount = totalServed * amount; requestResource(vessel, requestAmount, protoPartResources); result.completedSuccessfully = false; result.currentAmount = vesselCurrentAmount - requestAmount; result.maxAmount = vesselMaxAmount; result.affectedKerbalCount = crewCount - totalServed; } } //Process the roster resource else { consumeRosterInputs(vessel, elapsedTime); } return(result); }
/// <summary> /// Produces the resource /// </summary> /// <param name="vessel">The vessel to work on</param> /// <param name="elapsedTime">Elapsed seconds</param> /// <param name="crewCount">Current crew count</param> /// <param name="crewCapacity">Current crew capacity</param> /// <param name="consumptionResults">Results of resource consumption.</param> /// <returns>A SnacksConsumerResult containing the resuls of the production.</returns> public SnacksProcessorResult ProduceResource(Vessel vessel, double elapsedTime, int crewCount, int crewCapacity, Dictionary <string, SnacksProcessorResult> consumptionResults) { SnacksProcessorResult dependencyConsumptionResult; int adjustedCrewCount = crewCount; List <ProtoPartResourceSnapshot> protoPartResources = new List <ProtoPartResourceSnapshot>(); //If our output depends upon the results of a dependency resource, then retrieve the results. if (!string.IsNullOrEmpty(dependencyResourceName) && consumptionResults.ContainsKey(dependencyResourceName)) { dependencyConsumptionResult = consumptionResults[dependencyResourceName]; adjustedCrewCount = dependencyConsumptionResult.affectedKerbalCount; } SnacksProcessorResult result = new SnacksProcessorResult(); result.resourceName = resourceName; result.resultType = SnacksResultType.resultProduction; result.crewCapacity = crewCapacity; result.crewCount = crewCount; if (!isRosterResource) { double vesselCurrentAmount = 0; double vesselMaxAmount = 0; double supplyAmount = amount; //Get current totals getResourceTotals(vessel, out vesselCurrentAmount, out vesselMaxAmount, protoPartResources); //Multiply supply amount by crew count supplyAmount *= adjustedCrewCount; //Make sure we have enough room if (vesselCurrentAmount + supplyAmount <= vesselMaxAmount) { //Add resource addResource(vessel, supplyAmount, protoPartResources); //Update results result.affectedKerbalCount = adjustedCrewCount; result.completedSuccessfully = true; result.currentAmount = vesselCurrentAmount + supplyAmount; result.maxAmount = vesselMaxAmount; } else { int totalServed = (int)Math.Floor(vesselCurrentAmount / amount); supplyAmount = totalServed * amount; //Add resource addResource(vessel, supplyAmount, protoPartResources); //Update results result.completedSuccessfully = false; result.currentAmount = vesselCurrentAmount + supplyAmount; result.maxAmount = vesselMaxAmount; result.affectedKerbalCount = crewCount - totalServed; } } else { produceRosterOutputs(vessel, elapsedTime); } return(result); }
public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { ProtoCrewMember[] astronauts; AstronautData astronautData; //Get the astronauts if (vessel.loaded) { astronauts = vessel.GetVesselCrew().ToArray(); } else { astronauts = vessel.protoVessel.GetVesselCrew().ToArray(); } //If crew member has failed too many cycles then it's time to die. List <ProtoCrewMember> doomed = new List <ProtoCrewMember>(); KerbalRoster roster = HighLogic.CurrentGame.CrewRoster; for (int index = 0; index < astronauts.Length; index++) { astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]); //Handle exemptions if (astronautData.isExempt) { continue; } //Add to our cleanup list if (astronautData.processedResourceFailures.ContainsKey(resourceName) && astronautData.processedResourceFailures[resourceName] >= cyclesBeforeDeath) { doomed.Add(astronauts[index]); } } //Remove the dead crew int count = doomed.Count; string message = ""; for (int index = 0; index < count; index++) { //Unregister the crew member SnacksScenario.Instance.UnregisterCrew(doomed[index]); //Remove from ship doomed[index].seat.part.RemoveCrewmember(doomed[index]); if (vessel.loaded) { vessel.RemoveCrew(doomed[index]); vessel.CrewListSetDirty(); } else { vessel.protoVessel.RemoveCrew(doomed[index]); vessel.CrewListSetDirty(); } //Mark status astronauts[index].rosterStatus = ProtoCrewMember.RosterStatus.Dead; //Give player the bad news message = astronauts[index].name + " " + playerMessage; Debug.Log("[DeathPenalty] - " + message); ScreenMessages.PostScreenMessage(message, 5.0f, ScreenMessageStyle.UPPER_CENTER); } //Call the base class base.ApplyOutcome(vessel, result); }
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); } }
public override void onKerbalBoardedVessel(ProtoCrewMember astronaut, Part part) { if (part == null || part.vessel == null) { return; } ProtoCrewMember[] astronauts = null; AstronautData astronautData = null; Vessel vessel = part.vessel; SnacksProcessorResult result = new SnacksProcessorResult(); SnacksRosterResource resource; bool completedSuccessfully = true; //Get the crew manifest if (vessel.loaded) { astronauts = vessel.GetVesselCrew().ToArray(); } else { astronauts = vessel.protoVessel.GetVesselCrew().ToArray(); } if (astronauts.Length == 0) { return; } //Update max space updateMaxSpace(part.vessel); result.crewCount = astronauts.Length; result.crewCapacity = astronauts.Length; result.resourceName = StressResourceName; result.completedSuccessfully = true; //Now make sure kerbals aren't stressed out, or apply outcomes if they are. for (int index = 0; index < astronauts.Length; index++) { //Reset flag completedSuccessfully = true; //Get astronaut data astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]); if (astronautData == null) { continue; } if (!astronautData.rosterResources.ContainsKey(StressResourceName)) { continue; } //Get the Stress roster resource resource = astronautData.rosterResources[StressResourceName]; //Check for failure conditions if (resource.amount >= resource.maxAmount) { //Set the flags completedSuccessfully = false; result.completedSuccessfully = false; //Incease affected kerbal count result.affectedKerbalCount += 1; //Add astronaut to the affected list if (result.afftectedAstronauts == null) { result.afftectedAstronauts = new List <ProtoCrewMember>(); } result.afftectedAstronauts.Add(astronauts[index]); } } //Process results if (!completedSuccessfully) { applyFailureOutcomes(vessel, result); } else { removeFailureOutcomes(vessel); } }
public override void onVesselLoaded(Vessel vessel) { ProtoCrewMember[] astronauts = null; AstronautData astronautData = null; SnacksProcessorResult result = new SnacksProcessorResult(); //Get the crew manifest if (vessel.loaded) { astronauts = vessel.GetVesselCrew().ToArray(); } else { astronauts = vessel.protoVessel.GetVesselCrew().ToArray(); } if (astronauts.Length == 0) { return; } //Update max space updateMaxSpace(vessel); //Setup result productionResults.Clear(); result.crewCount = vessel.GetCrewCount(); result.crewCapacity = vessel.GetCrewCapacity(); result.resourceName = StressResourceName; result.completedSuccessfully = true; SnacksRosterResource resource; for (int index = 0; index < astronauts.Length; index++) { //Get astronaut data astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]); if (astronautData == null) { continue; } if (!astronautData.rosterResources.ContainsKey(StressResourceName)) { continue; } //Get the Stress roster resource resource = astronautData.rosterResources[StressResourceName]; //Check for failure conditions if (resource.amount >= resource.maxAmount) { //Set the flag result.completedSuccessfully = false; //Incease affected kerbal count result.affectedKerbalCount += 1; //Add astronaut to the affected list if (result.afftectedAstronauts == null) { result.afftectedAstronauts = new List <ProtoCrewMember>(); } result.afftectedAstronauts.Add(astronauts[index]); } } //Process results //First clear the failure outcomes, then apply to any who are affected. removeFailureOutcomes(vessel, false); if (!result.completedSuccessfully) { applyFailureOutcomes(vessel, result); } }
public override void ProcessResources(Vessel vessel, double elapsedTime, int crewCount, int crewCapacity) { ProtoCrewMember[] astronauts = null; AstronautData astronautData = null; SnacksProcessorResult result = new SnacksProcessorResult(); bool completedSuccessfully = true; float stress = 0; remainingTime += elapsedTime; while (remainingTime >= secondsPerCycle) { //Update remaining time remainingTime -= secondsPerCycle; //Get the crew manifest if (vessel.loaded) { astronauts = vessel.GetVesselCrew().ToArray(); } else { astronauts = vessel.protoVessel.GetVesselCrew().ToArray(); } if (astronauts.Length == 0) { return; } //Setup result productionResults.Clear(); result.crewCount = crewCount; result.crewCapacity = crewCapacity; result.resourceName = StressResourceName; result.completedSuccessfully = true; //Update max space updateMaxSpace(vessel); //Now increase stress in the vessel's crew. SnacksRosterResource resource; for (int index = 0; index < astronauts.Length; index++) { //Reset flag completedSuccessfully = true; //Get astronaut data astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]); if (astronautData == null) { continue; } if (!astronautData.rosterResources.ContainsKey(StressResourceName)) { continue; } //Get the Stress roster resource resource = astronautData.rosterResources[StressResourceName]; //Increase stress; stupidity matters stress = (1 - astronauts[index].stupidity); //Is kerbal a badass? Then reduce acquired stress if (astronauts[index].isBadass) { stress *= 0.5f; } //Account for homerworld or world with oxygen atmosphere if (vessel.mainBody.isHomeWorld && vessel.LandedOrSplashed) { stress *= 0.25f; } else if (vessel.mainBody.atmosphere && vessel.mainBody.atmosphereContainsOxygen && vessel.LandedOrSplashed) { stress *= 0.75f; } resource.amount += stress; astronautData.rosterResources[StressResourceName] = resource; //Check for failure conditions if (resource.amount >= resource.maxAmount) { //Set the flags completedSuccessfully = false; result.completedSuccessfully = false; //Incease affected kerbal count result.affectedKerbalCount += 1; //Add astronaut to the affected list if (result.afftectedAstronauts == null) { result.afftectedAstronauts = new List <ProtoCrewMember>(); } result.afftectedAstronauts.Add(astronauts[index]); } //Process results if (!completedSuccessfully) { applyFailureOutcomes(vessel, result); } else { removeFailureOutcomes(vessel); } } //Record results productionResults.Add(StressResourceName, result); } }
public override void ApplyOutcome(Vessel vessel, SnacksProcessorResult result) { ProtoCrewMember[] astronauts; AstronautData astronautData; //Get affected astronauts if (result.afftectedAstronauts != null) { astronauts = result.afftectedAstronauts.ToArray(); } else if (vessel.loaded) { astronauts = vessel.GetVesselCrew().ToArray(); } else { astronauts = vessel.protoVessel.GetVesselCrew().ToArray(); } //Get valid astronauts List <ProtoCrewMember> validAstronauts = new List <ProtoCrewMember>(); for (int index = 0; index < astronauts.Length; index++) { if (astronauts[index].type == ProtoCrewMember.KerbalType.Unowned) { continue; } validAstronauts.Add(astronauts[index]); } if (validAstronauts.Count == 0) { return; } else { astronauts = validAstronauts.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++) { if (astronauts[index].type == ProtoCrewMember.KerbalType.Unowned) { continue; } astronautData = SnacksScenario.Instance.GetAstronautData(astronauts[index]); if (astronautData == null) { continue; } astronautData.SetCondition(conditionName); SnacksScenario.Instance.SetAstronautData(astronautData); SnacksScenario.Instance.RemoveSkillsIfNeeded(astronauts[index]); } //Inform player if (!string.IsNullOrEmpty(playerMessage)) { string message = playerMessage; ScreenMessages.PostScreenMessage(message, 5, ScreenMessageStyle.UPPER_LEFT); } //Call the base class base.ApplyOutcome(vessel, result); }