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);
                }
            }
        }
 public void Start(Collider field)
 {
     RecycleField = field;
     GameEvents.onVesselWasModified.Add(onVesselWasModified);
     recycler_resources = new VesselResources(recycler.vessel, recycle_parts);
     fsm.StartFSM(start_state);
 }
Example #3
0
        void ProcessResource(VesselResources vr, string res, BuildResourceSet rd, bool xfer)
        {
            var amount = vr.ResourceAmount(res);
            var mass   = amount * ExRecipeDatabase.ResourceDensity(res);

            ProcessIngredient(new Ingredient(res, mass), rd, xfer);
        }
Example #4
0
 void onVesselWasModified(Vessel v)
 {
     if (v == recycler.vessel)
     {
         recycler_resources = new VesselResources(recycler.vessel, recycle_parts);
     }
 }
		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);
				}
			}
		}
 internal void SetupCraftResources(Vessel vsl)
 {
     craftResources = new VesselResources(vsl);
     foreach (var br in buildCost.optional)
     {
         var amount = craftResources.ResourceAmount(br.name);
         craftResources.TransferResource(br.name, -amount);
     }
 }
 void onVesselWasModified(Vessel v)
 {
     if (v == builder.vessel)
     {
         padResources = new VesselResources(builder.vessel);
         if (craftRoot != null && craftRoot.vessel != builder.vessel)
         {
             CleaupAfterRelease();
         }
     }
 }
        public CostReport getBuildCost(ConfigNode craft)
        {
            lockedParts = false;
            ShipConstruct ship = new ShipConstruct();

            if (!ship.LoadShip(craft))
            {
                return(null);
            }
            if (!ship.shipPartsUnlocked)
            {
                lockedParts = true;
            }
            GameObject ro          = ship.parts[0].localRoot.gameObject;
            Vessel     craftVessel = ro.AddComponent <Vessel>();

            craftVessel.Initialize(true);
            foreach (Part part in craftVessel.parts)
            {
                part.ModulesOnStart();
            }
            if (ExSettings.B9Wings_Present)
            {
                if (!InitializeB9Wings(craftVessel) &&
                    ExSettings.FAR_Present)
                {
                    InitializeFARSurfaces(craftVessel);
                }
            }
            else if (ExSettings.FAR_Present)
            {
                InitializeFARSurfaces(craftVessel);
            }

            // needed for displaying optional resources during the planning
            // stage.
            craftResources = new VesselResources(craftVessel);

            BuildCost resources = new BuildCost();

            foreach (Part p in craftVessel.parts)
            {
                resources.addPart(p);
            }
            craftVessel.Die();

            return(resources.cost);
        }
        internal void FindVesselResources()
        {
            padResources = new VesselResources(builder.vessel);
            var craft_parts = CraftParts();

            if (craft_parts.Count > 0)
            {
                craftResources = new VesselResources();
            }
            foreach (var part in craft_parts)
            {
                padResources.RemovePart(part);
                craftResources.AddPart(part);
            }
            if (craftResources == null && craftConfig != null)
            {
                getBuildCost(craftConfig);
            }
        }
		void ProcessResource (VesselResources vr, string res, BuildResourceSet rd, bool xfer)
		{
			var amount = vr.ResourceAmount (res);
			var mass = amount * ExRecipeDatabase.ResourceDensity (res);

			ProcessIngredient (new Ingredient (res, mass), rd, xfer);
		}
        private float ReclaimResource(string resource, double amount,
								  string vessel_name, string name=null)
        {
            PartResourceDefinition res_def;
            res_def = PartResourceLibrary.Instance.GetDefinition (resource);
            VesselResources recycler = new VesselResources (vessel);

            if (res_def == null) {
            return 0;
            }

            if (name == null) {
            name = resource;
            }
            double remain = amount;
            // any resources that can't be pumped or don't flow just "evaporate"
            // FIXME: should this be a little smarter and convert certain such
            // resources into rocket parts?
            if (res_def.resourceTransferMode != ResourceTransferMode.NONE
            && res_def.resourceFlowMode != ResourceFlowMode.NO_FLOW) {
            remain = recycler.TransferResource (resource, amount);
            }
            Debug.Log (String.Format ("[EL] {0}-{1}: {2} taken {3} reclaimed, {4} lost", vessel_name, name, amount, amount - remain, remain));
            return (float) (amount * res_def.density);
        }
 public BuildCost()
 {
     resources    = new VesselResources();
     container    = new VesselResources();
     hullResoures = new VesselResources();
 }
		void onVesselWasModified (Vessel v)
		{
			if (v == builder.vessel) {
				padResources = new VesselResources (builder.vessel);
				if (craftRoot != null && craftRoot.vessel != builder.vessel) {
					CleaupAfterRelease ();
				}
			}
		}
		public BuildCost ()
		{
			resources = new VesselResources ();
			container = new VesselResources ();
			hullResoures = new VesselResources ();
		}
		internal void FindVesselResources ()
		{
			padResources = new VesselResources (builder.vessel);
			var craft_parts = CraftParts ();
			if (craft_parts.Count > 0) {
				craftResources = new VesselResources ();
			}
			foreach (var part in craft_parts) {
				padResources.RemovePart (part);
				craftResources.AddPart (part);
			}
			if (craftResources == null && craftConfig != null) {
				getBuildCost (craftConfig);
			}
		}
		public CostReport getBuildCost (ConfigNode craft)
		{
			lockedParts = false;
			ShipConstruct ship = new ShipConstruct ();
			if (!ship.LoadShip (craft)) {
				return null;
			}
			if (!ship.shipPartsUnlocked) {
				lockedParts = true;
			}
			GameObject ro = ship.parts[0].localRoot.gameObject;
			Vessel craftVessel = ro.AddComponent<Vessel>();
			craftVessel.Initialize (true);
			if (ExSettings.B9Wings_Present) {
				if (!InitializeB9Wings (craftVessel)
					&& ExSettings.FAR_Present) {
					InitializeFARSurfaces (craftVessel);
				}
			} else if (ExSettings.FAR_Present) {
				InitializeFARSurfaces (craftVessel);
			}

			// needed for displaying optional resources during the planning
			// stage.
			craftResources = new VesselResources (craftVessel);

			BuildCost resources = new BuildCost ();

			foreach (Part p in craftVessel.parts) {
				resources.addPart (p);
			}
			craftVessel.Die ();

			return resources.cost;
		}
		internal void SetupCraftResources (Vessel vsl)
		{
			craftResources = new VesselResources (vsl);
			foreach (var br in buildCost.optional) {
				var amount = craftResources.ResourceAmount (br.name);
				craftResources.TransferResource (br.name, -amount);
			}
		}
        double ProcessResources(VesselResources resources, List<BuildResource> report_resources)
        {
            double hullMass = 0;
            var reslist = resources.resources.Keys.ToList ();
            foreach (string res in reslist) {
                double amount = resources.ResourceAmount (res);
                var br = new BuildResource (res, amount);

                if (br.hull) {
                    //FIXME better hull resources check
                    hullMass += br.mass;
                } else {
                    report_resources.Add (br);
                }
            }
            return hullMass;
        }
        public float RecycleVessel(Vessel v)
        {
            float ConversionEfficiency = 0.8f;
            double amount;
            VesselResources scrap = new VesselResources (v);

            PartResourceDefinition rp_def;
            string target_resource = ExSettings.HullRecycleTarget;
            rp_def = PartResourceLibrary.Instance.GetDefinition (target_resource);

            if (FlightGlobals.ActiveVessel == v)
            FlightGlobals.ForceSetActiveVessel (this.vessel);
            float mass = 0;
            foreach (var crew in v.GetVesselCrew ()) {
            mass += RecycleKerbal (crew, null);
            }
            foreach (string resource in scrap.resources.Keys) {
            amount = scrap.ResourceAmount (resource);
            mass += ReclaimResource (resource, amount, v.name);
            scrap.TransferResource (resource, -amount);
            }
            float hull_mass = v.GetTotalMass ();
            amount = hull_mass * ConversionEfficiency / rp_def.density;
            mass += ReclaimResource (target_resource, amount, v.name, String.Format ("hull({0})", target_resource));
            v.Die ();
            return mass;
        }
		void onVesselWasModified (Vessel v)
		{
			if (v == recycler.vessel) {
				recycler_resources = new VesselResources (recycler.vessel, recycle_parts);
			}
		}
        public CostReport getBuildCost(ConfigNode craft)
        {
            lockedParts = false;
            ShipConstruct ship = new ShipConstruct ();
            if (!ship.LoadShip (craft)) {
                return null;
            }
            if (!ship.shipPartsUnlocked) {
                lockedParts = true;
            }
            GameObject ro = ship.parts[0].localRoot.gameObject;
            Vessel dummy = ro.AddComponent<Vessel>();
            dummy.Initialize (true);
            if (ExSettings.B9Wings_Present) {
                if (!InitializeB9Wings (dummy) && ExSettings.FAR_Present) {
                    InitializeFARSurfaces (dummy);
                }
            } else if (ExSettings.FAR_Present) {
                InitializeFARSurfaces (dummy);
            }
            if (ExSettings.KAS_Present) {
                InitializeKASContainers (dummy);
            }

            craftResources = new VesselResources (dummy);

            BuildCost resources = new BuildCost ();

            foreach (Part p in ship.parts) {
                resources.addPart (p);
            }
            dummy.Die ();

            return resources.cost;
        }