public static SnackConfiguration Instance() { if (snackConfig == null) { snackConfig = new SnackConfiguration(); } return(snackConfig); }
void Start() //Called when vessel is placed on the launchpad { delayTime = SnackConfiguration.Instance().DelayedReaction; if (delayTime > 0) { Debug.Log("Snacks - Start FlightController"); GameEvents.onVesselChange.Add(OnVesselChangeMod); GameEvents.onFlightReady.Add(OnFlightReady); GameEvents.onVesselWasModified.Add(OnVesselChangeMod); SnackController.SnackTime += SnackController_SnackTime; } }
private bool IsOutOfSnacks(Vessel v) { if (v.GetVesselCrew().Count > 0) { List <PartResource> resources = new List <PartResource>(); v.rootPart.GetConnectedResources(SnackConfiguration.Instance().SnackResourceId, ResourceFlowMode.ALL_VESSEL, resources); foreach (PartResource r in resources) { if (r.amount > 0) { return(false); } } } else { return(false); } return(true); }
void Awake() { try { GameEvents.onCrewOnEva.Add(OnCrewOnEva); GameEvents.onCrewBoardVessel.Add(OnCrewBoardVessel); GameEvents.onGameStateLoad.Add(onLoad); GameEvents.onVesselRename.Add(OnRename); GameEvents.onVesselChange.Add(OnVesselChange); GameEvents.onVesselWasModified.Add(OnVesselWasModified); SnackConfiguration snackConfig = SnackConfiguration.Instance(); snackResourceId = snackConfig.SnackResourceId; soilResourceId = snackConfig.SoilResourceId; snackFrequency = 6 * 60 * 60 * 2 / snackConfig.MealsPerDay; snacksPerMeal = snackConfig.SnacksPerMeal; lossPerDayPerKerbal = snackConfig.LossPerDay; kerbalDeath = snackConfig.KerbalDeath; consumer = new SnackConsumer(snackConfig.SnacksPerMeal, snackConfig.LossPerDay); } catch (Exception ex) { Debug.Log("Snacks - Awake error: " + ex.Message + ex.StackTrace); } }
public Dictionary <int, List <ShipSupply> > Vessels() { try { if (vessels == null) { Debug.Log("rebuilding snapshot"); int snackResourceId = SnackConfiguration.Instance().SnackResourceId; vessels = new Dictionary <int, List <ShipSupply> >(); outOfSnacks = new Dictionary <Guid, bool>(); List <Guid> activeVessels = new List <Guid>(); foreach (Vessel v in FlightGlobals.Vessels) { //Debug.Log("processing v:" + v.vesselName); if (v.GetVesselCrew().Count > 0 && v.loaded) { activeVessels.Add(v.id); List <PartResource> resources = new List <PartResource>(); v.rootPart.GetConnectedResources(snackResourceId, ResourceFlowMode.ALL_VESSEL, resources); double snackAmount = 0; double snackMax = 0; foreach (PartResource r in resources) { snackAmount += r.amount; snackMax += r.maxAmount; } ShipSupply supply = new ShipSupply(); supply.VesselName = v.vesselName; supply.BodyName = v.mainBody.name; supply.SnackAmount = Convert.ToInt32(snackAmount); supply.SnackMaxAmount = Convert.ToInt32(snackMax); supply.CrewCount = v.GetVesselCrew().Count; supply.DayEstimate = Convert.ToInt32(snackAmount / supply.CrewCount / (SnackConfiguration.Instance().MealsPerDay *SnackConfiguration.Instance().SnacksPerMeal)); supply.Percent = snackMax == 0 ? 0 : Convert.ToInt32(snackAmount / snackMax * 100); AddShipSupply(supply, v.protoVessel.orbitSnapShot.ReferenceBodyIndex); outOfSnacks.Add(v.id, snackAmount != 0.0 ? false : true); } } foreach (var pv in HighLogic.CurrentGame.flightState.protoVessels) { //Debug.Log("processing pv:" + pv.vesselName); if (!pv.vesselRef.loaded && !activeVessels.Contains(pv.vesselID)) { if (pv.GetVesselCrew().Count < 1) { continue; } double snackAmount = 0; double snackMax = 0; foreach (ProtoPartSnapshot pps in pv.protoPartSnapshots) { var res = from r in pps.resources where r.resourceName == "Snacks" select r; if (res.Count() > 0) { ConfigNode node = res.First().resourceValues; snackAmount += Double.Parse(node.GetValue("amount")); snackMax += Double.Parse(node.GetValue("maxAmount")); } } //Debug.Log(pv.vesselName + "1"); ShipSupply supply = new ShipSupply(); supply.VesselName = pv.vesselName; supply.BodyName = pv.vesselRef.mainBody.name; supply.SnackAmount = Convert.ToInt32(snackAmount); supply.SnackMaxAmount = Convert.ToInt32(snackMax); supply.CrewCount = pv.GetVesselCrew().Count; //Debug.Log(pv.vesselName + supply.CrewCount); supply.DayEstimate = Convert.ToInt32(snackAmount / supply.CrewCount / (SnackConfiguration.Instance().MealsPerDay *SnackConfiguration.Instance().SnacksPerMeal)); //Debug.Log(pv.vesselName + supply.DayEstimate); //Debug.Log("sa:" + snackAmount + " sm:" + snackMax); supply.Percent = snackMax == 0 ? 0 : Convert.ToInt32(snackAmount / snackMax * 100); //Debug.Log(pv.vesselName + supply.Percent); AddShipSupply(supply, pv.orbitSnapShot.ReferenceBodyIndex); outOfSnacks.Add(pv.vesselID, snackAmount != 0.0 ? false : true); } } } } catch (Exception ex) { Debug.Log("building snapshot failed: " + ex.Message + ex.StackTrace); } return(vessels); }
public static SnackConfiguration Instance() { if(snackConfig == null) snackConfig = new SnackConfiguration(); return snackConfig; }