Ejemplo n.º 1
0
		public void Configure(bool enable)
		{
			if (enable)
			{
				// if never set, this is the case if:
				// - part is added in the editor
				// - module is configured first time either in editor or in flight
				// - module is added to an existing savegame
				if (!part.Resources.Contains("Atmosphere"))
				{
					// add internal atmosphere resources
					// - disabled habitats start with zero atmosphere
					Lib.AddResource(part, "Atmosphere", (state == State.enabled && Features.Pressure) ? volume : 0.0, volume);
					Lib.AddResource(part, "WasteAtmosphere", 0.0, volume);

					// add external surface shielding
					Lib.AddResource(part, "Shielding", 0.0, surface);

					// inflatable habitats can't be shielded (but still need the capacity)
					part.Resources["Shielding"].isTweakable = inflate.Length == 0;

					// if shielding feature is disabled, just hide it
					part.Resources["Shielding"].isVisible = Features.Shielding;
				}
			}
			else
			{
				Lib.RemoveResource(part, "Atmosphere", 0.0, volume);
				Lib.RemoveResource(part, "WasteAtmosphere", 0.0, volume);
				Lib.RemoveResource(part, "Shielding", 0.0, surface);
			}
		}
Ejemplo n.º 2
0
        public void Configure()
        {
            // if never set, this is the case if:
            // - part is added in the editor
            // - module is configured first time either in editor or in flight
            // - module is added to an existing savegame
            if (!part.Resources.Contains("Atmosphere"))
            {
                // add internal atmosphere resources
                // - disabled habitats start with zero atmosphere
                Lib.AddResource(part, "Atmosphere", (state == State.enabled && Features.Pressure) ? volume * 1e3 : 0.0, volume * 1e3);
                Lib.AddResource(part, "WasteAtmosphere", 0.0, volume * 1e3);

                // add external surface shielding
                Lib.AddResource(part, "Shielding", 0.0, surface);

                // inflatable habitats can't be shielded (but still need the capacity) unless they have rigid walls
                part.Resources["Shielding"].isTweakable = (Get_inflate_string().Length == 0) || inflatableUsingRigidWalls;

                // if shielding feature is disabled, just hide it
                part.Resources["Shielding"].isVisible = Features.Shielding && part.Resources["Shielding"].isTweakable;

                configured = true;
            }
        }
Ejemplo n.º 3
0
		public void SetupPod(AvailablePart p)
		{
			// get prefab
			Part prefab = p.partPrefab;

			// avoid problems with some parts that don't have a resource container (like flags)
			if (prefab.Resources == null) return;

			// do nothing if no resource on pod
			if (on_pod <= double.Epsilon) return;

			// do nothing for EVA kerbals, that have now CrewCapacity
			if (prefab.partInfo.name == "kerbalEVA" || prefab.partInfo.name == "kerbalEVAfemale") return;

			// do nothing if not manned
			if (prefab.CrewCapacity == 0) return;

			// do nothing if this isn't a command pod
			if (prefab.FindModuleImplementing<ModuleCommand>() == null) return;

			// calculate quantity
			double quantity = on_pod * (double)prefab.CrewCapacity;

			// add the resource
			Lib.AddResource(prefab, resource, empty ? 0.0 : quantity, quantity);

			// add resource cost
			p.cost += (float)(Lib.GetDefinition(resource).unitCost * (empty ? 0.0 : quantity));
		}
Ejemplo n.º 4
0
		public void SetupEva(Part p)
		{
			// do nothing if no resource on eva
			if (on_eva <= double.Epsilon) return;

			// create new resource capacity in the eva kerbal
			Lib.AddResource(p, resource, 0.0, on_eva);
		}
Ejemplo n.º 5
0
        public static void manageRescueMission(Vessel v)
        {
            // true if we detected this was a rescue mission vessel
            bool detected = false;

            // deal with rescue missions
            foreach (ProtoCrewMember c in Lib.CrewList(v))
            {
                // get kerbal data
                KerbalData kd = DB.Kerbal(c.name);

                // flag the kerbal as not rescue at prelaunch
                if (v.situation == Vessel.Situations.PRELAUNCH)
                {
                    kd.rescue = false;
                }

                // if the kerbal belong to a rescue mission
                if (kd.rescue)
                {
                    // remember it
                    detected = true;

                    // flag the kerbal as non-rescue
                    // note: enable life support mechanics for the kerbal
                    kd.rescue = false;

                    // show a message
                    Message.Post(Lib.BuildString("We found <b>", c.name, "</b>"), Lib.BuildString((c.gender == ProtoCrewMember.Gender.Male ? "He" : "She"), "'s still alive!"));
                }
            }

            // gift resources
            if (detected)
            {
                var reslib = PartResourceLibrary.Instance.resourceDefinitions;
                var parts  = Lib.GetPartsRecursively(v.rootPart);

                // give the vessel some propellant usable on eva
                string monoprop_name   = Lib.EvaPropellantName();
                double monoprop_amount = Lib.EvaPropellantCapacity();
                foreach (var part in parts)
                {
                    if (part.CrewCapacity > 0 || part.FindModuleImplementing <KerbalEVA>() != null)
                    {
                        if (Lib.Capacity(part, monoprop_name) <= double.Epsilon)
                        {
                            Lib.AddResource(part, monoprop_name, 0.0, monoprop_amount);
                        }
                        break;
                    }
                }
                ResourceCache.Produce(v, monoprop_name, monoprop_amount);

                // give the vessel some supplies
                Profile.SetupRescue(v);
            }
        }
Ejemplo n.º 6
0
		public void SetupRescue(Vessel v)
		{
			// do nothing if no resource on rescue
			if (on_rescue <= double.Epsilon) return;

			// if the vessel has no capacity
			if (ResourceCache.Info(v, resource).capacity <= double.Epsilon)
			{
				// find the first useful part
				Part p = v.parts.Find(k => k.CrewCapacity > 0 || k.FindModuleImplementing<KerbalEVA>() != null);

				// add capacity
				Lib.AddResource(p, resource, 0.0, on_rescue);
			}

			// add resource to the vessel
			ResourceCache.Produce(v, resource, on_rescue);
		}
Ejemplo n.º 7
0
        public void Configure(bool enable, int multiple = 1)
        {
            if (enable)
            {
                // if never set, this is the case if:
                // - part is added in the editor
                // - module is configured first time either in editor or in flight
                // - module is added to an existing savegame
                if (!part.Resources.Contains("Atmosphere"))
                {
                    // add internal atmosphere resources
                    // - disabled habitats start with zero atmosphere
                    Lib.AddResource(part, "Atmosphere", (state == State.enabled && Features.Pressure) ? volume * 1e3 : 0.0, volume * 1e3);
                    Lib.AddResource(part, "WasteAtmosphere", 0.0, volume * 1e3);
                    Lib.AddResource(part, "MoistAtmosphere", 0.0, volume * 1e3);

                    // add external surface shielding
                    Lib.AddResource(part, "Shielding", 0.0, surface);

                    // inflatable habitats can't be shielded (but still need the capacity) unless they have rigid walls
                    part.Resources["Shielding"].isTweakable = (Get_inflate_string().Length == 0) || inflatableUsingRigidWalls;

                    // if shielding feature is disabled, just hide it
                    part.Resources["Shielding"].isVisible = Features.Shielding && part.Resources["Shielding"].isTweakable;

                    // In the first time playing with Kerbalism, MM will add Nitrogen for existed vessels, but it will be empty
                    // Fixing missing Module by hard code, logic based in Default.cfg
                    double amount = part.CrewCapacity * 500.0;
                    if (part.partInfo.name == "mk3Cockpit_Shuttle" || part.partInfo.name == "Large_Crewed_Lab")
                    {
                        amount *= 3;
                    }

                    Lib.AddResource(part, "Nitrogen", (state == State.enabled && Features.Pressure) ? amount : 0.0, amount);
                }
            }
            else
            {
                Lib.RemoveResource(part, "Atmosphere", 0.0, volume * 1e3);
                Lib.RemoveResource(part, "WasteAtmosphere", 0.0, volume * 1e3);
                Lib.RemoveResource(part, "MoistAtmosphere", 0.0, volume * 1e3);
                Lib.RemoveResource(part, "Shielding", 0.0, surface);
            }
        }
Ejemplo n.º 8
0
 ///<summary> Called by Configure.cs. Configures the controller to settings passed from the configure module</summary>
 public void Configure(bool enable)
 {
     if (enable)
     {
         // if never set
         // - this is the case in the editor, the first time, or in flight
         //   in the case the module was added post-launch, or EVA kerbals
         if (!part.Resources.Contains(resource))
         {
             // add the resource
             // - always add the specified amount, even in flight
             Lib.AddResource(part, resource, (!broken && running) ? capacity : 0.0, capacity);
         }
     }
     else
     {
         Lib.RemoveResource(part, resource, 0.0, capacity);
     }
 }
Ejemplo n.º 9
0
        public void Configure(bool enable, int multiple = 1)
        {
            // make sure multiple is not zero
            multiple = multiple == 0 ? 1 : multiple;

            if (enable)
            {
                // if never set
                // - this is the case in the editor, the first time, or in flight
                //   in the case the module was added post-launch, or EVA kerbals
                if (!part.Resources.Contains(resource))
                {
                    // add the resource
                    // - always add the specified amount, even in flight
                    Lib.AddResource(part, resource, capacity * multiple, capacity * multiple);
                }
                // has multiple changed
                else if (this.multiple != multiple)
                {
                    // multiple has increased
                    if (this.multiple < multiple)
                    {
                        Lib.AddResource(part, resource, capacity * (multiple - this.multiple), capacity * (multiple - this.multiple));
                    }
                    // multiple has decreased
                    else
                    {
                        Lib.RemoveResource(part, resource, 0.0, capacity * (this.multiple - multiple));
                    }
                }
                this.multiple = multiple;
            }
            else
            {
                Lib.RemoveResource(part, resource, 0.0, capacity * this.multiple);
                this.multiple = 1;
            }
        }
Ejemplo n.º 10
0
        public void configure()
        {
            // shortcut to resource library
            var reslib = PartResourceLibrary.Instance.resourceDefinitions;

            // reset extra cost and mass
            extra_cost = 0.0;
            extra_mass = 0.0;

            // find modules unlocked by tech
            unlocked = new List <ConfigureSetup>();
            foreach (ConfigureSetup setup in setups)
            {
                // if unlocked
                if (setup.tech.Length == 0 || Lib.HasTech(setup.tech))
                {
                    // unlock
                    unlocked.Add(setup);
                }
            }

            // make sure configuration include all available slots
            // this also create default configuration
            // - we don it only in the editor
            // - we avoid corner case when cfg was never set up (because craft was never in VAB)
            if (Lib.IsEditor() || selected.Count == 0)
            {
                while (selected.Count < Math.Min(slots, (uint)unlocked.Count))
                {
                    selected.Add(unlocked.Find(k => selected.IndexOf(k.name) == -1).name);
                }
            }

            // for each setup
            foreach (ConfigureSetup setup in setups)
            {
                // detect if the setup is selected
                bool active = selected.Contains(setup.name);

                // detect if the setup was previously selected
                bool prev_active = prev_selected.Contains(setup.name);

                // for each module specification in the setup
                foreach (ConfigureModule cm in setup.modules)
                {
                    // try to find the module
                    PartModule m = find_module(cm);

                    // if the module exist
                    if (m != null)
                    {
                        // call configure/deconfigure functions on module if available
                        IConfigurable configurable_module = m as IConfigurable;
                        if (configurable_module != null)
                        {
                            configurable_module.Configure(active);
                        }

                        // enable/disable the module
                        m.isEnabled = active;
                        m.enabled   = active;
                    }
                }

                // for each resource specification in the setup
                foreach (ConfigureResource cr in setup.resources)
                {
                    // ignore non-existing resources
                    if (!reslib.Contains(cr.name))
                    {
                        continue;
                    }

                    // get resource unit cost
                    double unit_cost = reslib[cr.name].unitCost;

                    // parse resource amount and capacity
                    double amount   = Lib.Parse.ToDouble(cr.amount);
                    double capacity = Lib.Parse.ToDouble(cr.maxAmount);

                    // (de)install resource
                    if ((prev_active != (active && capacity > 0.0)) || (reconfigure_cs && initialized))
                    {
                        // if previously selected
                        if (prev_active)
                        {
                            // remove the resources
                            Lib.RemoveResource(part, cr.name, amount, capacity);
                        }

                        // if selected
                        if (active && capacity > 0.0)
                        {
                            // add the resources
                            // - in flight, do not add amount
                            Lib.AddResource(part, cr.name, Lib.IsFlight() ? 0.0 : amount, capacity);
                        }
                    }

                    // add resource cost
                    if (active)
                    {
                        extra_cost += amount * unit_cost;
                    }
                }

                // add setup extra cost and mass
                if (active)
                {
                    extra_cost += setup.cost;
                    extra_mass += setup.mass;
                }
            }

            // remember previously selected setups
            prev_selected.Clear();
            foreach (string s in selected)
            {
                prev_selected.Add(s);
            }

            // save configuration
            WriteArchive archive = new WriteArchive();

            archive.save(selected.Count);
            foreach (string s in selected)
            {
                archive.save(s);
            }
            cfg = archive.serialize();

            // save previous configuration
            archive = new WriteArchive();
            archive.save(prev_selected.Count);
            foreach (string s in prev_selected)
            {
                archive.save(s);
            }
            prev_cfg = archive.serialize();

            // in the editor
            if (Lib.IsEditor())
            {
                // for each part in the symmetry group (avoid infinite recursion)
                if (!avoid_inf_recursion)
                {
                    avoid_inf_recursion = true;
                    foreach (Part p in part.symmetryCounterparts)
                    {
                        // get the Configure module
                        Configure c = p.FindModulesImplementing <Configure>().Find(k => k.title == title);

                        // both modules will share configuration
                        c.selected = selected;

                        // re-configure the other module
                        c.configure();
                    }
                    avoid_inf_recursion = false;
                }
            }

            // refresh this part ui
            MonoUtilities.RefreshContextWindows(part);

            // refresh VAB ui
            if (Lib.IsEditor())
            {
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }

            // this was configured at least once
            initialized = true;
        }