Exemplo n.º 1
0
 public void Load(ConfigNode node)
 {
     recycle_parts = new HashSet <uint> ();
     if (node.HasValue("recycle_parts"))
     {
         var  ids = node.GetValue("recycle_parts").Split(new char[] { ' ' });
         uint id;
         for (int i = 0; i < ids.Length; i++)
         {
             if (uint.TryParse(ids[i], out id))
             {
                 recycle_parts.Add(id);
             }
         }
     }
     if (node.HasNode("part_resource"))
     {
         part_resources = new List <BuildResource> ();
         foreach (var pr in node.GetNodes("part_resource"))
         {
             var res = new BuildResource();
             res.Load(pr);
             part_resources.Add(res);
         }
     }
     if (node.HasValue("state"))
     {
         var state = fsm.FindState(node.GetValue("state"));
         if (state != null)
         {
             start_state = state;
         }
     }
 }
        void ProcessResources(VesselResources resources, BuildResourceSet report_resources, BuildResourceSet required_resources = null)
        {
            var reslist = resources.resources.Keys.ToList();

            foreach (string res in reslist)
            {
                double amount = resources.ResourceAmount(res);
                var    recipe = ExRecipeDatabase.ResourceRecipe(res);

                if (recipe != null)
                {
                    double density = ExRecipeDatabase.ResourceDensity(res);
                    double mass    = amount * density;
                    recipe = recipe.Bake(mass);
                    foreach (var ingredient in recipe.ingredients)
                    {
                        var br     = new BuildResource(ingredient);
                        var resset = report_resources;
                        if (required_resources != null)
                        {
                            resset = required_resources;
                        }
                        resset.Add(br);
                    }
                }
                else
                {
                    var br = new BuildResource(res, amount);
                    report_resources.Add(br);
                }
            }
        }
 double TransferResource(BuildResource br, double deltat)
 {
     if (br.density > 0)
     {
         var amount      = recycler.RecycleRate * deltat / br.density;
         var base_amount = amount;
         if (amount > br.amount)
         {
             amount = br.amount;
         }
         recycler_resources.TransferResource(br.name, amount);
         br.amount -= amount;                    // any untransfered resource is lost
         br.mass    = br.amount * br.density;
         deltat     = deltat * (base_amount - amount) / base_amount;
     }
     else
     {
         // Massless resources are transferred in one tick (for now),
         // but consume the whole tick.
         recycler_resources.TransferResource(br.name, br.amount);
         br.amount = 0;
         deltat    = 0;
     }
     return(deltat);
 }
        double ResourceProgress(string label, BuildResource br,
                                BuildResource req, bool forward)
        {
            double fraction = 1;

            if (req.amount > 0)
            {
                fraction = (req.amount - br.amount) / req.amount;
            }
            double required  = br.amount;
            double available = control.padResources.ResourceAmount(br.name);
            double alarmTime;
            string percent = (fraction * 100).ToString("G4") + "%";

            if (control.paused)
            {
                percent   = percent + "[paused]";
                alarmTime = 0;                 // need assignment or compiler complains about use of unassigned variable
            }
            else
            {
                double eta = BuildETA(br, req, forward);
                alarmTime = Planetarium.GetUniversalTime() + eta;
                percent   = percent + " " + EL_Utils.TimeSpanString(eta);
            }

            GUILayout.BeginHorizontal();

            // Resource name
            GUILayout.Box(label, ELStyles.white, GUILayout.Width(125),
                          GUILayout.Height(40));

            GUILayout.BeginVertical();

            ELStyles.bar.Draw((float)fraction, percent, 300);
            GUILayout.EndVertical();

            // Calculate if we have enough resources to build
            GUIStyle requiredStyle = ELStyles.green;

            if (required > available)
            {
                requiredStyle = ELStyles.yellow;
            }
            // Required and Available
            GUILayout.Box(displayAmount(required),
                          requiredStyle, GUILayout.Width(100),
                          GUILayout.Height(40));
            GUILayout.Box(displayAmount(available),
                          ELStyles.white, GUILayout.Width(100),
                          GUILayout.Height(40));
            GUILayout.FlexibleSpace();

            GUILayout.EndHorizontal();
            return(alarmTime);
        }
Exemplo n.º 5
0
 public void Add(BuildResource res)
 {
     if (resources.ContainsKey(res.name))
     {
         resources[res.name].Merge(res);
     }
     else
     {
         resources[res.name] = res;
     }
 }
        double ResourceProgress(string label, BuildResource br,
                                BuildResource req, bool forward)
        {
            double fraction = 1;

            if (req.amount > 0)
            {
                fraction = (req.amount - br.amount) / req.amount;
            }
            double required  = br.amount;
            double available = control.padResources.ResourceAmount(br.name);
            double eta       = 0;
            string percent   = (fraction * 100).ToString("G4") + "%";

            if (control.paused)
            {
                percent = percent + "[paused]";
            }
            else
            {
                eta     = BuildETA(br, req, forward);
                percent = percent + " " + EL_Utils.TimeSpanString(eta);
            }

            GUILayout.BeginHorizontal();

            // Resource name
            GUILayout.Box(label, ELStyles.white, width125, height40);

            GUILayout.BeginVertical();

            ELStyles.bar.Draw((float)fraction, percent, 300);
            GUILayout.EndVertical();

            // Calculate if we have enough resources to build
            GUIStyle requiredStyle = ELStyles.green;

            if (required > available)
            {
                requiredStyle = ELStyles.yellow;
            }
            // Required and Available
            GUILayout.Box(displayAmount(required),
                          requiredStyle, width100, height40);
            GUILayout.Box(displayAmount(available),
                          ELStyles.white, width100, height40);
            GUILayout.FlexibleSpace();

            GUILayout.EndHorizontal();
            return(eta);
        }
        double BuildETA(BuildResource br, BuildResource req, bool forward)
        {
            double numberOfFramesLeft;

            if (br.deltaAmount <= 0)
            {
                return(0);
            }
            if (forward)
            {
                numberOfFramesLeft = (br.amount / br.deltaAmount);
            }
            else
            {
                numberOfFramesLeft = ((req.amount - br.amount) / br.deltaAmount);
            }
            return(numberOfFramesLeft * TimeWarp.fixedDeltaTime);
        }
Exemplo n.º 8
0
        void ProcessIngredient(Ingredient ingredient, BuildResourceSet rd, bool xfer)
        {
            var    res    = ingredient.name;
            Recipe recipe = null;

            // If the resource is being transfered from a tank (rather than
            // coming from the part body itself), then a transfer recipe will
            // override a recycle recipe
            if (xfer)
            {
                recipe = ExRecipeDatabase.TransferRecipe(res);
            }
            if (recipe == null)
            {
                recipe = ExRecipeDatabase.RecycleRecipe(res);
            }

            if (recipe != null)
            {
                recipe = recipe.Bake(ingredient.ratio);
                foreach (var ing in recipe.ingredients)
                {
                    if (ing.isReal)
                    {
                        var br = new BuildResource(ing);
                        rd.Add(br);
                    }
                }
            }
            else
            {
                if (ExRecipeDatabase.ResourceRecipe(res) != null)
                {
                }
                else
                {
                    if (ingredient.isReal)
                    {
                        var br = new BuildResource(ingredient);
                        rd.Add(br);
                    }
                }
            }
        }
        public void Load(ConfigNode node)
        {
            var req = node.GetNode("Required");

            foreach (var r in req.GetNodes("BuildResrouce"))
            {
                var res = new BuildResource();
                res.Load(r);
                required.Add(res);
            }
            var opt = node.GetNode("Optional");

            foreach (var r in opt.GetNodes("BuildResrouce"))
            {
                var res = new BuildResource();
                res.Load(r);
                optional.Add(res);
            }
        }
Exemplo n.º 10
0
 double DumpResource(BuildResource br, double deltat)
 {
     if (br.density > 0)
     {
         var amount      = recycler.RecycleRate * deltat / br.density;
         var base_amount = amount;
         if (amount > br.amount)
         {
             amount = br.amount;
         }
         br.amount -= amount;
         deltat     = deltat * (base_amount - amount) / base_amount;
     }
     else
     {
         br.amount = 0;
         deltat    = 0;
     }
     return(deltat);
 }
Exemplo n.º 11
0
 double ReclaimResource(BuildResource br, double deltat)
 {
     if (br.density > 0)
     {
         var amount      = recycler.RecycleRate * deltat / br.density;
         var base_amount = amount;
         if (amount > br.amount)
         {
             amount = br.amount;
         }
         var remain = recycler_resources.TransferResource(br.name, amount);
         br.amount -= amount - remain;
         br.mass    = br.amount * br.density;
         deltat     = deltat * remain / base_amount;
     }
     else
     {
         recycler_resources.TransferResource(br.name, br.amount);
         br.amount = 0;
         deltat    = 0;
     }
     return(deltat);
 }
Exemplo n.º 12
0
        double ResourceProgress(string label, BuildResource br,
                                BuildResource req, bool forward)
        {
            double fraction  = (req.amount - br.amount) / req.amount;
            double required  = br.amount;
            double available = control.padResources.ResourceAmount(br.name);
            double alarmTime;
            string percent = (fraction * 100).ToString("G4") + "% ";

            if (control.paused)
            {
                percent   = percent + "[paused]";
                alarmTime = 0;                 // need assignment or compiler complains about use of unassigned variable
            }
            else
            {
                double   numberOfFramesLeft;
                TimeSpan timeLeft;
                try {
                    if (forward)
                    {
                        numberOfFramesLeft = (br.amount / br.deltaAmount);
                    }
                    else
                    {
                        numberOfFramesLeft = ((req.amount - br.amount) / br.deltaAmount);
                    }
                    double numberOfSecondsLeft = numberOfFramesLeft * TimeWarp.fixedDeltaTime;
                    timeLeft  = TimeSpan.FromSeconds(numberOfSecondsLeft);
                    alarmTime = Planetarium.GetUniversalTime() + timeLeft.TotalSeconds;
                }
                catch {
                    // catch overflows or any other math errors, and just give a value
                    // it will be overwritten the next time
                    timeLeft  = TimeSpan.FromSeconds(0);
                    alarmTime = 0;
                }
                percent = percent + String.Format("{0:D2}:{1:D2}:{2:D2}", timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds);
            }

            GUILayout.BeginHorizontal();

            // Resource name
            GUILayout.Box(label, Styles.white, GUILayout.Width(120),
                          GUILayout.Height(40));

            GUILayout.BeginVertical();

            Styles.bar.Draw((float)fraction, percent, 300);
            GUILayout.EndVertical();

            // Calculate if we have enough resources to build
            GUIStyle requiredStyle = Styles.green;

            if (required > available)
            {
                requiredStyle = Styles.yellow;
            }
            // Required and Available
            GUILayout.Box((Math.Round(required, 2)).ToString(),
                          requiredStyle, GUILayout.Width(75),
                          GUILayout.Height(40));
            GUILayout.Box((Math.Round(available, 2)).ToString(),
                          Styles.white, GUILayout.Width(75),
                          GUILayout.Height(40));
            GUILayout.FlexibleSpace();

            GUILayout.EndHorizontal();
            return(alarmTime);
        }
Exemplo n.º 13
0
 public void Remove(BuildResource res)
 {
     resources.Remove(res.name);
 }