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; } } builder.SetCraftMass(mass); }
private void DoWork_Cancel(double kerbalHours) { var built = builtStuff.required; var cost = buildCost.required; var base_kerbalHours = Math.Abs(kerbalHours); 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 amount = work / bres.kerbalHours; double base_amount = Math.Abs(amount); if (amount > remaining) { amount = remaining; } count++; did_work = true; // do only the work required to process the actual amount // of returned or disposed resource kerbalHours -= work * amount / base_amount; bres.amount += amount; //Debug.Log("remove delta: "+amount); bres.deltaAmount = amount; double capacity = padResources.ResourceCapacity(bres.name) - padResources.ResourceAmount(bres.name); if (amount > capacity) { amount = capacity; } if (amount / base_amount <= 1e-10) { continue; } padResources.TransferResource(bres.name, amount); } } while (did_work && kerbalHours / base_kerbalHours > 1e-10); SetPadMass(); if (count == 0) { state = State.Planning; KACalarmID = ""; } }