Esempio n. 1
0
        public static BioVessel Load(ConfigNode node)
        {
            string vesselName = Utilities.GetValue(node, "vesselName", "Unknown");
            double lastUpdate = Utilities.GetValue(node, "lastUpdate", 0.0);

            BioVessel info = new BioVessel(vesselName, lastUpdate);
            info.bioMass = Utilities.GetValue(node, "bioMass", 0.0);
            info.maxBioMass = Utilities.GetValue(node, "maxBioMass", 0.0);

            info.remainingWater = Utilities.GetValue(node, "remainingWater", 0.0);
            info.remainingWasteWater = Utilities.GetValue(node, "remainingWasteWater", 0.0);
            info.remainingOxygen = Utilities.GetValue(node, "remainingOxygen", 0.0);
            info.remainingCO2 = Utilities.GetValue(node, "remainingCO2", 0.0);

            info.lastWater = Utilities.GetValue(node, "lastWater", 0.0);
            info.lastWasteWater = Utilities.GetValue(node, "lastWasteWater", 0.0);
            info.lastOxygen = Utilities.GetValue(node, "lastOxygen", 0.0);
            info.lastCO2 = Utilities.GetValue(node, "lastCO2", 0.0);

            info.estimatedWaterConsumptionPerDeltaTime = Utilities.GetValue(node, "estimatedWaterConsumptionPerDeltaTime", 0.0);
            info.estimatedWasteWaterConsumptionPerDeltaTime = Utilities.GetValue(node, "estimatedWasteWaterConsumptionPerDeltaTime", 0.0);
            info.estimatedOxygenConsumptionPerDeltaTime = Utilities.GetValue(node, "estimatedOxygenConsumptionPerDeltaTime", 0.0);
            info.estimatedCO2ConsumptionPerDeltaTime = Utilities.GetValue(node, "estimatedCO2ConsumptionPerDeltaTime", 0.0);

            info.estimatedWaterTime = Utilities.GetValue(node, "estimatedWaterTime", 0.0);
            info.estimatedWasteWaterTime = Utilities.GetValue(node, "estimatedWasteWaterTime", 0.0);
            info.estimatedOxygenTime = Utilities.GetValue(node, "estimatedOxygenTime", 0.0);
            info.estimatedCO2Time = Utilities.GetValue(node, "estimatedCO2Time", 0.0);

            return info;
        }
Esempio n. 2
0
 private void ConsumeResources(double currentTime, Vessel vessel, BioVessel bioVessel)
 {
     bioVessel.lastUpdate = currentTime;
     bioVessel.vesselName = vessel.vesselName;
 }
Esempio n. 3
0
        void FixedUpdate()
        {
            if (Time.timeSinceLevelLoad < 1.0f || !FlightGlobals.ready || noUpdate)
            {
                return;
            }

            double currentTime = Planetarium.GetUniversalTime();
            var allVessels = FlightGlobals.Vessels;
            var knownVessels = saveGame.BioVessels;

            var vesselsToDelete = new List<Guid>();
            foreach (var entry in knownVessels)
            {
                Guid vesselId = entry.Key;
                BioVessel bioVessel = entry.Value;
                Vessel vessel = allVessels.Find(v => v.id == vesselId);

                if (vessel == null)
                {
                    this.Log("Deleting vessel " + bioVessel.vesselName + " - vessel does not exist anymore");
                    vesselsToDelete.Add(vesselId);
                    continue;
                }

                if (vessel.loaded)
                {
                    double bioMass = UpdateVesselInfo(bioVessel, vessel,currentTime);

                    if (bioMass == 0.0)
                    {
                        this.Log("Deleting vessel " + bioVessel.vesselName + " - no BioMass-Modules onboard");
                        vesselsToDelete.Add(vesselId);
                        continue;
                    }
                }

                if (vessel.loaded)
                {
                    //TODO: Deplenish Ressources
                    ConsumeResources(currentTime, vessel, bioVessel);
                }
            }

            vesselsToDelete.ForEach(id => knownVessels.Remove(id));

            foreach (Vessel vessel in allVessels.Where(v => v.loaded))
            {
                if (!knownVessels.ContainsKey(vessel.id) && IsLaunched(vessel))
                {
                    BioVessel vesselInfo = new BioVessel(vessel.vesselName, currentTime);
                    double bioMass = UpdateVesselInfo(vesselInfo, vessel,currentTime);
                    if (bioMass != 0.0)
                    {
                        this.Log("New vessel: " + vessel.vesselName + " (" + vessel.id + ")");
                        knownVessels[vessel.id] = vesselInfo;
                    }
                }
            }
        }
Esempio n. 4
0
        private double UpdateVesselInfo(BioVessel bioVessel, Vessel vessel, double currentTime)
        {
            bioVessel.lastWater = bioVessel.remainingWater;
            bioVessel.lastWasteWater = bioVessel.remainingWasteWater;
            bioVessel.lastOxygen = bioVessel.remainingOxygen;
            bioVessel.lastCO2 = bioVessel.remainingCO2;

            bioVessel.ClearAmounts();

            foreach (Part part in vessel.parts)
            {
                foreach (PartResource resource in part.Resources)
                {
                    if (resource.flowState)
                    {
                        if (resource.info.id == globalSettings.BioMassId)
                        {
                            bioVessel.bioMass += resource.amount;
                            bioVessel.maxBioMass += resource.maxAmount;
                        }
                        if (resource.info.id == globalSettings.WaterId)
                        {
                            bioVessel.remainingWater += resource.amount;
                        }
                        if (resource.info.id == globalSettings.WasteWaterId)
                        {
                            bioVessel.remainingWasteWater += resource.amount;
                        }
                        if (resource.info.id == globalSettings.OxygenId)
                        {
                            bioVessel.remainingOxygen += resource.amount;
                        }
                        if (resource.info.id == globalSettings.CO2Id)
                        {
                            bioVessel.remainingCO2 += resource.amount;
                        }
                    }
                }
            }

            //Calculate Estimated Consumption Rates
            double currentdeltaTime = currentTime - bioVessel.lastUpdate;
            bioVessel.estimatedWaterConsumptionPerDeltaTime = bioVessel.lastWater - bioVessel.remainingWater;
            bioVessel.estimatedWasteWaterConsumptionPerDeltaTime = bioVessel.lastWasteWater - bioVessel.remainingWasteWater;
            bioVessel.estimatedOxygenConsumptionPerDeltaTime = bioVessel.lastOxygen - bioVessel.remainingOxygen;
            bioVessel.estimatedCO2ConsumptionPerDeltaTime = bioVessel.lastCO2 - bioVessel.remainingCO2;

            bioVessel.estimatedWaterConsumptionPerDeltaTime =
                (bioVessel.estimatedWaterConsumptionPerDeltaTime / currentdeltaTime);
            bioVessel.estimatedWasteWaterConsumptionPerDeltaTime =
                (bioVessel.estimatedWasteWaterConsumptionPerDeltaTime / currentdeltaTime);
            bioVessel.estimatedOxygenConsumptionPerDeltaTime =
                (bioVessel.estimatedOxygenConsumptionPerDeltaTime / currentdeltaTime);
            bioVessel.estimatedCO2ConsumptionPerDeltaTime =
                (bioVessel.estimatedCO2ConsumptionPerDeltaTime / currentdeltaTime);

            bioVessel.estimatedWaterTime = bioVessel.lastUpdate + (bioVessel.remainingWater / Math.Abs(bioVessel.estimatedWaterConsumptionPerDeltaTime));
            bioVessel.estimatedOxygenTime = bioVessel.lastUpdate + (bioVessel.remainingOxygen / Math.Abs(bioVessel.estimatedOxygenConsumptionPerDeltaTime));
            bioVessel.estimatedCO2Time = bioVessel.lastUpdate + (bioVessel.remainingCO2 / Math.Abs(bioVessel.estimatedCO2ConsumptionPerDeltaTime));
            bioVessel.estimatedWasteWaterTime = bioVessel.lastUpdate + (bioVessel.remainingWasteWater / Math.Abs(bioVessel.estimatedWasteWaterConsumptionPerDeltaTime));

            return bioVessel.maxBioMass;
        }