Exemplo n.º 1
0
        void SetPadMass()
        {
            double mass = 0;

            if (builtStuff != null && buildCost != null)
            {
                var built = builtStuff.required;
                var cost  = buildCost.required;

                foreach (var bres in built)
                {
                    var cres = ExBuildWindow.FindResource(cost, bres.name);
                    mass += (cres.amount - bres.amount) * bres.density;
                }
            }
            part.mass = base_mass + (float)mass;
        }
        private void DoWork_Cancel(double kerbalHours)
        {
            var built = builtStuff.required;
            var cost  = buildCost.required;

            bool did_work;
            int  count;

            do
            {
                count = 0;
                foreach (var bres in built)
                {
                    var cres = ExBuildWindow.FindResource(cost, bres.name);
                    if (cres.amount - bres.amount > 0)
                    {
                        count++;
                    }
                }
                if (count == 0)
                {
                    break;
                }

                double work = kerbalHours / count;
                did_work = false;
                count    = 0;
                foreach (var bres in built)
                {
                    var    cres      = ExBuildWindow.FindResource(cost, bres.name);
                    double remaining = cres.amount - bres.amount;
                    if (remaining < 0)
                    {
                        continue;
                    }
                    double mass        = work / 5;              //FIXME not hard-coded (5Kh/t)
                    double amount      = mass / bres.density;
                    double base_amount = amount;

                    if (amount > remaining)
                    {
                        amount = remaining;
                    }
                    double capacity = padResources.ResourceCapacity(bres.name)
                                      - padResources.ResourceAmount(bres.name);
                    if (amount > capacity)
                    {
                        amount = capacity;
                    }
                    if (amount <= 0)
                    {
                        break;
                    }
                    count++;
                    did_work = true;
                    // do only the work required to process the actual amount
                    // of returned resource
                    kerbalHours -= work * amount / base_amount;
                    bres.amount += amount;
                    padResources.TransferResource(bres.name, amount);
                }
            } while (did_work && kerbalHours > 0);

            SetPadMass();

            if (count == 0)
            {
                state = State.Planning;
            }
        }