Ejemplo n.º 1
0
        public void drawFlightWindow()
        {
            Dictionary <int, List <ShipSupply> > snapshot = SnackSnapshot.Instance().TakeSnapshot();
            var keys = snapshot.Keys.ToList();
            List <ShipSupply> supplies;

            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(300), GUILayout.Width(300));
            keys.Sort();
            foreach (int planet in keys)
            {
                if (!snapshot.TryGetValue(planet, out supplies))
                {
                    GUILayout.Label("Can't seem to get supplies");
                    GUILayout.EndScrollView();
                }

                if (!GameSettings.KERBIN_TIME)
                {
                    GUILayout.Label("<color=lightblue>Time format: 24hr/day, 365 day/year</color>");
                }

                if (SnacksProperties.EnableRandomSnacking)
                {
                    GUILayout.Label("<color=yellow>The following are estimates</color>");
                }

                GUILayout.Label("<color=lightblue><b>" + supplies.First().BodyName + ":</b></color>");
                foreach (ShipSupply supply in supplies)
                {
                    if (supply.DayEstimate < 0)
                    {
                        GUILayout.Label("<color=white><b>" + supply.VesselName + "</b></color>");
                        GUILayout.Label("<color=white> Crew: " + supply.CrewCount + ", Snacks: " + supply.SnackAmount + "/" + supply.SnackMaxAmount + "</color>");
                        GUILayout.Label("<color=white> Duration: Indefinite</color>");
                    }
                    else if (supply.Percent > 50)
                    {
                        GUILayout.Label("<color=white><b>" + supply.VesselName + "</b></color>");
                        GUILayout.Label("<color=white> Crew: " + supply.CrewCount + ", Snacks: " + supply.SnackAmount + "/" + supply.SnackMaxAmount + "</color>");
                        GUILayout.Label("<color=white> Duration: " + timeFormat(supply.DayEstimate) + "</color>");
                    }
                    else if (supply.Percent > 25)
                    {
                        GUILayout.Label("<color=yellow><b>" + supply.VesselName + "</b></color>");
                        GUILayout.Label("<color=yellow> Crew: " + supply.CrewCount + ", Snacks: " + supply.SnackAmount + "/" + supply.SnackMaxAmount + "</color>");
                        GUILayout.Label("<color=yellow> Duration: " + timeFormat(supply.DayEstimate) + "</color>");
                    }
                    else
                    {
                        GUILayout.Label("<color=red><b>" + supply.VesselName + "</b></color>");
                        GUILayout.Label("<color=red> Crew: " + supply.CrewCount + ", Snacks: " + supply.SnackAmount + "/" + supply.SnackMaxAmount + "</color>");
                        GUILayout.Label("<color=red> Duration: " + timeFormat(supply.DayEstimate) + "</color>");
                    }
                }
            }

            GUILayout.EndScrollView();
        }
Ejemplo n.º 2
0
 public static SnackSnapshot Instance()
 {
     if (snapshot == null)
     {
         snapshot = new SnackSnapshot();
         snapshot.Vessels();
     }
     return snapshot;
 }
Ejemplo n.º 3
0
 private void OnVesselChange(Vessel data)
 {
     //Debug.Log("OnVesselChange");
     try
     {
         SnackSnapshot.Instance().RebuildSnapshot();
     }
     catch { }
 }
Ejemplo n.º 4
0
 private void OnVesselWasModified(Vessel data)
 {
     //Debug.Log("OnVesselWasModified");
     try
     {
         SnackSnapshot.Instance().RebuildSnapshot();
     }
     catch { }
 }
Ejemplo n.º 5
0
 public static SnackSnapshot Instance()
 {
     if (snapshot == null)
     {
         snapshot = new SnackSnapshot();
         snapshot.TakeSnapshot();
     }
     return(snapshot);
 }
Ejemplo n.º 6
0
        void Start()
        {
            if (HighLogic.LoadedScene != GameScenes.FLIGHT &&
                HighLogic.LoadedScene != GameScenes.SPACECENTER &&
                HighLogic.LoadedScene != GameScenes.TRACKSTATION)
            {
                return;
            }

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                checkAndShowWelcomeMessage();
            }

            try
            {
                //register penalty handlers
                penaltyHandlers.Add(new MissingMealsMonitor());
                penaltyHandlers.Add(new FundingPenalty());
                penaltyHandlers.Add(new RepPenalty());
                penaltyHandlers.Add(new SciencePenalty());
//                penaltyHandlers.Add(new VesselControlPenalty());
                penaltyHandlers.Add(new FaintPenalty());
                penaltyHandlers.Add(new DeathPenalty());

                //Setup the inital settings.
                GameSettingsApplied();

                //Calculate next snack time
                if (SnacksProperties.EnableRandomSnacking)
                {
                    nextSnackTime = random.NextDouble() * snackFrequency + Planetarium.GetUniversalTime();
                }
                else
                {
                    nextSnackTime = snackFrequency + Planetarium.GetUniversalTime();
                }

                //To handle installations to existing saves, be sure to register the crew of existing but unloaded vessels.
                Vessel[] unloadedVessels = FlightGlobals.VesselsUnloaded.ToArray();
                for (int index = 0; index < unloadedVessels.Length; index++)
                {
                    SnacksScenario.Instance.RegisterCrew(unloadedVessels[index]);
                }

                //Take a snapshot
                if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
                {
                    SnackSnapshot.Instance().TakeSnapshot();
                }
            }
            catch (Exception ex)
            {
                Debug.Log("Snacks - Start error: " + ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 7
0
 private void OnCrewBoardVessel(GameEvents.FromToAction <Part, Part> data)
 {
     try
     {
         Part   evaKerbal    = data.from;
         Part   boardedPart  = data.to;
         double kerbalSnacks = consumer.GetSnackResource(evaKerbal, SnacksProperties.SnacksPerMeal);
         boardedPart.RequestResource(SnacksProperties.SnackResourceID, -kerbalSnacks, ResourceFlowMode.ALL_VESSEL);
         SnackSnapshot.Instance().RebuildSnapshot();
         SnacksScenario.Instance.RegisterCrew(boardedPart.vessel);
     }
     catch (Exception ex)
     {
         Debug.Log("Snacks - OnCrewBoardVessel: " + ex.Message + ex.StackTrace);
     }
 }
Ejemplo n.º 8
0
 private void OnCrewBoardVessel(GameEvents.FromToAction <Part, Part> data)
 {
     try
     {
         //Debug.Log("EVA End");
         double got = consumer.GetSnackResource(data.from, 1.0);
         //Debug.Log("EVA Got:" + got);
         List <PartResource> resources = new List <PartResource>();
         data.to.GetConnectedResources(snackResourceId, ResourceFlowMode.ALL_VESSEL, resources);
         resources.First().amount += got;
         SnackSnapshot.Instance().SetRebuildSnapshot();
     }
     catch (Exception ex)
     {
         Debug.Log("Snacks - OnCrewBoardVessel: " + ex.Message + ex.StackTrace);
     }
 }
Ejemplo n.º 9
0
        public void drawEditorWindow()
        {
            ShipSupply supply = SnackSnapshot.Instance().TakeEditorSnapshot();

            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(300), GUILayout.Width(300));

            if (!GameSettings.KERBIN_TIME)
            {
                GUILayout.Label("<color=lightblue>Time format: 24hr/day, 365 day/year</color>");
            }

            if (SnacksProperties.EnableRandomSnacking || SnacksProperties.RecyclersEnabled)
            {
                GUILayout.Label("<color=yellow>The following are estimates</color>");
            }

            GUILayout.Label("<color=white>Snacks: " + supply.SnackAmount + "/" + supply.SnackMaxAmount + "</color>");
            //GUILayout.Label("<color=white>Days (Cur Crew): " + supply.DayEstimate + "</color>");
            //GUILayout.Label("<color=white>Days (Max Crew): " + supply.MaxDayEstimate + "</color>");

            if (supply.DayEstimate > 0)
            {
                GUILayout.Label("<color=white>Current Crew: " + supply.CrewCount + "</color>");
                GUILayout.Label("<color=white>Duration: " + timeFormat(supply.DayEstimate) + "</color>");
            }
            else
            {
                GUILayout.Label("<color=white>Current Crew: " + supply.CrewCount + "</color>");
                GUILayout.Label("<color=white>Duration: Indefinite</color>");
            }

            if (supply.MaxDayEstimate > 0)
            {
                GUILayout.Label("<color=white>Max Crew: " + supply.MaxCrewCount + "</color>");
                GUILayout.Label("<color=white>Duration: " + timeFormat(supply.MaxDayEstimate) + "</color>");
            }
            else
            {
                GUILayout.Label("<color=white>Max Crew: " + supply.MaxCrewCount + "</color>");
                GUILayout.Label("<color=white>Duration: Indefinite</color>");
            }


            GUILayout.EndScrollView();
        }
Ejemplo n.º 10
0
        void FixedUpdate()
        {
            if (HighLogic.LoadedScene != GameScenes.SPACECENTER &&
                HighLogic.LoadedScene != GameScenes.FLIGHT &&
                HighLogic.LoadedScene != GameScenes.TRACKSTATION)
            {
                return;
            }
            try
            {
                double currentTime = Planetarium.GetUniversalTime();

                if (currentTime > nextSnackTime)
                {
                    //Setup next snacking time.
                    if (SnacksProperties.EnableRandomSnacking)
                    {
                        System.Random rand = new System.Random();
                        nextSnackTime = rand.NextDouble() * snackFrequency + currentTime;
                    }
                    else
                    {
                        nextSnackTime = snackFrequency + currentTime;
                    }

                    Debug.Log("Snack time!  Next Snack Time!:" + nextSnackTime);

                    //Eat snacks!
                    EatSnacks();

                    //Update the snapshot
                    SnackSnapshot.Instance().RebuildSnapshot();

                    //Fire snack tick event
                    onSnackTick.Fire();
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[Snacks] - FixedUpdate: " + ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 11
0
        void FixedUpdate()
        {
            try
            {
                double currentTime = Planetarium.GetUniversalTime();

                if (currentTime > snackTime)
                {
                    System.Random rand = new System.Random();
                    snackTime = rand.NextDouble() * snackFrequency + currentTime;
                    Debug.Log("Snack time!  Next Snack Time!:" + currentTime);
                    EatSnacks();
                    SnackSnapshot.Instance().SetRebuildSnapshot();
                }
            }
            catch (Exception ex)
            {
                Debug.Log("Snacks - FixedUpdate: " + ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 12
0
        internal override void DrawWindow(int id)
        {
            if (hedStyle == null)
            {
                SetupStyles();
            }
            DragEnabled     = true;
            TooltipsEnabled = true;
            scrollPos       = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(300), GUILayout.Width(300));

            Dictionary <int, List <ShipSupply> > snapshot = SnackSnapshot.Instance().Vessels();
            var keys = snapshot.Keys.ToList();

            keys.Sort();
            foreach (int planet in keys)
            {
                List <ShipSupply> supplies;
                snapshot.TryGetValue(planet, out supplies);
                //supplies.Sort();
                GUILayout.Label(supplies.First().BodyName + ":", hedStyle);
                foreach (ShipSupply supply in supplies)
                {
                    if (supply.Percent > 50)
                    {
                        GUILayout.Label(new GUIContent(supply.VesselName + ": " + supply.SnackAmount + "/" + supply.SnackMaxAmount, "Crew: " + supply.CrewCount + "  Duration*: " + supply.DayEstimate + " days"), regStyle);
                    }
                    else if (supply.Percent > 25)
                    {
                        GUILayout.Label(new GUIContent(supply.VesselName + ": " + supply.SnackAmount + "/" + supply.SnackMaxAmount, "Crew: " + supply.CrewCount + "  Duration*: " + supply.DayEstimate + " days"), yelStyle);
                    }
                    else
                    {
                        GUILayout.Label(new GUIContent(supply.VesselName + ": " + supply.SnackAmount + "/" + supply.SnackMaxAmount, "Crew: " + supply.CrewCount + "  Duration*: " + supply.DayEstimate + " days"), redStyle);
                    }
                }
            }

            GUILayout.EndScrollView();
        }
Ejemplo n.º 13
0
        private void OnCrewOnEva(GameEvents.FromToAction <Part, Part> data)
        {
            try
            {
                Part   evaKerbal    = data.to;
                Part   partExited   = data.from;
                double snacksAmount = consumer.GetSnackResource(partExited, SnacksProperties.SnacksPerMeal);

                if (evaKerbal.Resources.Contains(SnacksProperties.SnackResourceID) == false)
                {
                    ConfigNode node = new ConfigNode("RESOURCE");
                    node.AddValue("name", SnacksProperties.SnacksResourceName);
                    node.AddValue("maxAmount", "1");
                    evaKerbal.Resources.Add(node);
                }
                evaKerbal.Resources[SnacksProperties.SnacksResourceName].amount = snacksAmount;
                SnackSnapshot.Instance().RebuildSnapshot();
            }
            catch (Exception ex)
            {
                Debug.Log("Snacks - OnCrewOnEva " + ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 14
0
        private void OnCrewOnEva(GameEvents.FromToAction <Part, Part> data)
        {
            try
            {
                //Debug.Log("EVA start");
                double got = consumer.GetSnackResource(data.from, 1.0);
                //Debug.Log("EVA Got:" + got);
                if (!data.to.Resources.Contains(snackResourceId))
                {
                    ConfigNode node = new ConfigNode("RESOURCE");
                    node.AddValue("name", "Snacks");
                    data.to.Resources.Add(node);
                }
                List <PartResource> resources = new List <PartResource>();
                data.to.GetConnectedResources(snackResourceId, ResourceFlowMode.ALL_VESSEL, resources);
                resources.First().amount    = got;
                resources.First().maxAmount = 1;
                SnackSnapshot.Instance().SetRebuildSnapshot();

                if (!data.to.Resources.Contains(soilResourceId))
                {
                    ConfigNode node = new ConfigNode("RESOURCE");
                    node.AddValue("name", "Soil");
                    data.to.Resources.Add(node);
                }
                resources = new List <PartResource>();
                data.to.GetConnectedResources(soilResourceId, ResourceFlowMode.ALL_VESSEL, resources);
                resources.First().amount    = 0;
                resources.First().maxAmount = 1;

                data.to.AddModule("EVANutritiveAnalyzer");
            }
            catch (Exception ex)
            {
                Debug.Log("Snacks - OnCrewOnEva " + ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 15
0
 private void OnVesselChange(Vessel data)
 {
     //Debug.Log("OnVesselChange");
     SnackSnapshot.Instance().SetRebuildSnapshot();
 }
Ejemplo n.º 16
0
 private void OnRename(GameEvents.HostedFromToAction <Vessel, string> data)
 {
     //Debug.Log("OnRename");
     SnackSnapshot.Instance().RebuildSnapshot();
 }
Ejemplo n.º 17
0
 private void onLoad(ConfigNode node)
 {
     //Debug.Log("onLoad");
     SnackSnapshot.Instance().RebuildSnapshot();
 }
Ejemplo n.º 18
0
 private void OnVesselWasModified(Vessel data)
 {
     //Debug.Log("OnVesselWasModified");
     SnackSnapshot.Instance().SetRebuildSnapshot();
 }