Example #1
0
        void Process_cryotank(Part p, PartModule m)
        {
            // is cooling available
            bool available = Lib.ReflectionValue <bool>(m, "CoolingEnabled");

            // get list of fuels, do nothing if no fuels
            IList fuels = Lib.ReflectionValue <IList>(m, "fuels");

            if (fuels == null)
            {
                return;
            }

            // get cooling cost
            double cooling_cost = Lib.ReflectionValue <float>(m, "CoolingCost");

            string fuel_name    = "";
            double amount       = 0.0;
            double total_cost   = 0.0;
            double boiloff_rate = 0.0;

            // calculate EC cost of cooling
            foreach (object fuel in fuels)
            {
                fuel_name = Lib.ReflectionValue <string>(fuel, "fuelName");
                // if fuel_name is null, don't do anything
                if (fuel_name == null)
                {
                    continue;
                }

                // get amount in the part
                amount = Lib.Amount(p, fuel_name);

                // if there is some fuel
                if (amount > double.Epsilon)
                {
                    // if cooling is enabled
                    if (available)
                    {
                        // calculate ec consumption
                        total_cost += cooling_cost * amount * 0.001;
                    }
                    // if cooling is disabled
                    else
                    {
                        // get boiloff rate per-second
                        boiloff_rate = Lib.ReflectionValue <float>(fuel, "boiloffRate") / 360000.0f;

                        // let it boil off
                        Resource(fuel_name).Consume(amount * boiloff_rate, "cryotank");
                    }
                }
            }

            // apply EC consumption
            Resource("ElectricCharge").Consume(total_cost, "cryotank");
        }