Jump to content

CSX_Ind

Members
  • Posts

    75
  • Joined

  • Last visited

Reputation

0 Neutral

Profile Information

  • About me
    Just a human
  1. Well, been doing more modeling than coding... XP
  2. Finally learned how to use GitHub, so uploaded obsolete codes to there.
  3. Just for the sake of recording - CSXPartModule.cs using UnityEngine; using KSP.IO; namespace CSX.ModuleManagement { public class CSXPartModule : PartModule { [KSPField] public string partType; } public enum CSXPartType { NONE, Power, Filter, Produce, Collector } } And fuel cell module includes - CSXFuelCell.cs using UnityEngine; using KSP.IO; using System.Collections.Generic; namespace CSX.ModuleManagement { public class CSXFuelCell : CSXPartModule { /*...*/ Then added partType to my .cfg and it worked nicely.
  4. Yup yup, tested myself, and it works nicely. Good thing I can sort my modules now Thanks!
  5. Wonder this is possible : class SomeClass : PartModule { [KSPField] public string partType; } public class SomePart : SomeClass { /*...*/ } Then in a .cfg file : PART { /*...*/ MODULE { name = SomePart partType = "PartName" } } So long story short, can I still call that field from inherited class?
  6. So, been looking into some APIs, and wanted to do some cargo type switching using right-click menu. I've looked into SetResource(ConfigNode node), but couldn't figure out how exactly it works. I don't know if that node is referring to a node under my MODULE section in Part.cfg PART { MODULE { //... Some Fields FuelTank { //...Resource } } } Something like this?
  7. Thought I did. That's what happens when you make a chart at 3 am XP
  8. Previously from this thread, thought it would be better to move the whole progress report to here since it will be full scale anyway. Long story short, this will be my very first plugin+part mod, thought it would be nice to start off from simple liquid fuel dumping to up to this point. Upon tumbling into KSP modding, had to think of what should I make or what I want to make. Although there are plenty good life support mods, I wanted to try making my own. Also, wanted to add a bit of futuristic parts like greenhouse module and cryo module. I am currently thinking about releasing three different versions of this mod, each version using- 1. Real-life resources (i.e. Carbon Dioxide, Methane, etc...) 2. Kethane (Confirmed) 3. Kerbonite (Pending) So here we go, I'll be posting source codes/updates to this thread day by day(if possible). Progress Tracker- 1. Fuel Cell (Done!) 2. Greenhouse Module (Partially done) 3. CO2/KO2 filter (Working on it) 4. Kerman control (Eating cycles and whatnot) 5. Overall ECLSS control 6. Cryo Module 7. Therman Control Panels (TCP) (Pending) 8. Medicine (Pending) 9. Random events (i.e. Diseases)
  9. Been reading some CO2 filteration, and thought maybe it's useful if I make KO2 filter instead, use the Sabatier Reaction, KO2 + 4H2 -> KH4 + 2H2O + Energy And send these Kethane to waste depository, since Kethane itself cannot be used by any of my LS module(s).
  10. Day Eight on plugin making, been focusing on crew management. Sources so far CrewManagement.cs /************************************************************************ * CSX Industry - Life Support Part+Plugin Pack for Kerbal Space Program* * * * Initial Alpha Release Version 0.3a * * * * Created by Charlie S. * * Built on July 18th, 2014 * * Initial Built on July 12th, 2014 * ************************************************************************/ using UnityEngine; using KSP.IO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CSXIndustry.CrewManage; namespace CSXIndustry { [KSPAddon(KSPAddon.Startup.Flight, false)] public class CrewManagement : MonoBehaviour { // List of crews and all the modules with crew neccessities private List<ModCrew> crews; private List<Part> foods, oxygen, water; private bool hasInit; public void Awake() // At start { hasInit = false; } public void Update() { if (!hasInit) Initialize(); // On every update frame foreach(ModCrew crew in crews) { // Update crew details crew.Update(); if(!crew.HasEaten()) // If this Kerman hasn't eaten foreach(Part part in foods) foreach(PartResource food in part.Resources) // For each food resource module if(food.resourceName == Resources.food) { // Calculate food consume and convert it to next eating timer factor double actual = part.RequestResource(Resources.food, 1.5 * TimeWarp.fixedDeltaTime); double factor = actual / 1.5; crew.SetEaten(true); // Set this Kerman to eaten status crew.SetNextEatAt(300.0 * factor); // Set next eat timer if (crew.GetEatTimer() < 1) // If this crew didn't eat { crew.SetKillTimer(crew.GetKillTimer() - (300.0 - (300.0 * factor))); // Deduct it's kill factor crew.SetNextEatAt(300.0); // But show some mercy } } if (crew.GetKillTimer() < 0) // If this Kerman's time has come { // Kill this Kerman and remove him from the list crew.KillKerman(); crews.Remove(crew); crews.TrimExcess(); } } // If there are crews still if(crews.Count > 0) { // They need to breath } } private void Initialize() { Debug.Log("Crew Management Plugin, Part of CSX_Industry 0.3a"); // Initiate new crew list Debug.Log("Initializing crews"); crews = new List<ModCrew>(); foreach (ProtoCrewMember crew in FlightGlobals.ActiveVessel.GetVesselCrew()) // Search for crews inside of this vessel { crews.Add(new ModCrew(crew)); // Add them to the crew list Debug.Log(crew.name + " has been added to crew list"); } // Initiate new food list Debug.Log("Initializing food list"); foods = new List<Part>(); oxygen = new List<Part>(); water = new List<Part>(); // Search for any part with food resources in it. foreach (Part part in FlightGlobals.ActiveVessel.Parts) foreach (PartResource resource in part.Resources) { if (resource.resourceName == Resources.food) { foods.Add(part); // Add them to the food list Debug.Log(part.name + " has been added to food module"); } else if(resource.resourceName == Resources.oxygen) { oxygen.Add(part); Debug.Log(part.name + " has been added to oxygen module"); } else if(resource.resourceName == Resources.water) { water.Add(part); Debug.Log(part.name + " has been added to water module"); } } hasInit = true; } } } ModCrew.cs /************************************************************************ * CSX Industry - Life Support Part+Plugin Pack for Kerbal Space Program* * * * Initial Alpha Release Version 0.3a * * * * Created by Charlie S. * * Built on July 18th, 2014 * * Initial Built on July 12th, 2014 * ************************************************************************/ using UnityEngine; using KSP.IO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSXIndustry.CrewManage { public class ModCrew { private double eatTimer = 300; // Timer that controls eating private bool hasEaten = true; // Boolean that checks if this crew has eaten private double killTimer = 3000; // Timer that checks if this Kerman needs to die private ProtoCrewMember crew; // Detail of this crew public ModCrew(ProtoCrewMember crew) { // Set this crew this.crew = crew; } public void Update() { // Deduct eat timer eatTimer -= 1.0 * TimeWarp.fixedDeltaTime; // If it's time to eat if(eatTimer < 1) { hasEaten = false; // Set eaten to false } } public void KillKerman() { // Report message to player that this Kerman has died due to HUNGER ScreenMessages.PostScreenMessage(crew.name + " has died due to hunger", 5.0f, ScreenMessageStyle.UPPER_CENTER); crew.Die(); // Kill this Kerman } // All Get & Set functions public bool HasEaten() { return this.hasEaten; } public void SetEaten(bool hasEaten) { this.hasEaten = hasEaten; } public double GetEatTimer() { return this.eatTimer; } public void SetNextEatAt(double eatTimer) { this.eatTimer = (int) eatTimer; } public double GetKillTimer() { return this.killTimer; } public void SetKillTimer(double killTimer) { this.killTimer = (int) killTimer; } public ProtoCrewMember GetCrew() { return this.crew; } public void SetCrew(ProtoCrewMember crew) { this.crew = crew; } } }
  11. Day Seven on plugin making, working on Carbon Dioxide management and other circulation system. But mostly on CO2. Need to think on how will the CO2 will be simulated all over a vessel.
  12. Day Six on plugin making, added crew manifest to work with food. Hasn't added carbon dioxide yet though. Don't know why but couldn't initialize crew list with Awake() function, so had to add boolean to control initialize. CrewManagement.cs /************************************************************************ * CSX Industry - Life Support Part+Plugin Pack for Kerbal Space Program* * * * Initial Alpha Release Version 0.3a * * * * Created by Charlie S. * * Built on July 18th, 2014 * * Initial Built on July 12th, 2014 * ************************************************************************/ using UnityEngine; using KSP.IO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CSXIndustry.CrewManage; namespace CSXIndustry { [KSPAddon(KSPAddon.Startup.Flight, false)] public class CrewManagement : MonoBehaviour { // List of crews and all the modules with food private List<ModCrew> crews; private List<Part> foods; private bool hasInit; public void Awake() // At start { hasInit = false; } public void Update() { if (!hasInit) Initialize(); // On every update frame foreach(ModCrew crew in crews) { // Update crew details crew.Update(); if(!crew.HasEaten()) // If this Kerman hasn't eaten foreach(Part part in foods) foreach(PartResource food in part.Resources) // For each food resource module if(food.resourceName == Resources.food) { // Calculate food consume and convert it to next eating timer factor double actual = part.RequestResource(Resources.food, 1.5 * TimeWarp.fixedDeltaTime); double factor = actual / 1.5; crew.SetEaten(true); // Set this Kerman to eaten status crew.SetNextEatAt(300.0 * factor); // Set next eat timer if (crew.GetEatTimer() < 1) // If this crew didn't eat { crew.SetKillTimer(crew.GetKillTimer() - (300.0 - (300.0 * factor))); // Deduct it's kill factor crew.SetNextEatAt(300.0); // But show some mercy } } if (crew.GetKillTimer() < 0) // If this Kerman's time has come { // Kill this Kerman and remove him from the list crew.KillKerman(); crews.Remove(crew); } } } private void Initialize() { Debug.Log("Crew Management Plugin, Part of CSX_Industry."); // Initiate new crew list Debug.Log("Initializing crews"); crews = new List<ModCrew>(); foreach (ProtoCrewMember crew in FlightGlobals.ActiveVessel.GetVesselCrew()) // Search for crews inside of this vessel { crews.Add(new ModCrew(crew)); // Add them to the crew list Debug.Log(crew.name + " has been added to crew list"); } // Initiate new food list Debug.Log("Initializing food list"); foods = new List<Part>(); // Search for any part with food resources in it. foreach (Part part in FlightGlobals.ActiveVessel.Parts) foreach (PartResource food in part.Resources) if (food.resourceName == Resources.food) { foods.Add(part); // Add them to the food list Debug.Log(part.name + " has been added to food module"); } hasInit = true; } } } ModCrew.cs - To work with ProtoCrewMember bit easier /************************************************************************ * CSX Industry - Life Support Part+Plugin Pack for Kerbal Space Program* * * * Initial Alpha Release Version 0.3a * * * * Created by Charlie S. * * Built on July 18th, 2014 * * Initial Built on July 12th, 2014 * ************************************************************************/ using UnityEngine; using KSP.IO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSXIndustry.CrewManage { public class ModCrew { private double eatTimer = 300; // Timer that controls eating private bool hasEaten = true; // Boolean that checks if this crew has eaten private double killTimer = 3000; // Timer that checks if this Kerman needs to die private ProtoCrewMember crew; // Detail of this crew public ModCrew(ProtoCrewMember crew) { // Set this crew this.crew = crew; } public void Update() { // Deduct eat timer eatTimer -= 1.0 * TimeWarp.fixedDeltaTime; // If it's time to eat if(eatTimer < 1) { hasEaten = false; // Set eaten to false } } public void KillKerman() { // Report message to player that this Kerman has died due to HUNGER ScreenMessages.PostScreenMessage(crew.name + " has died due to hunger", 5.0f, ScreenMessageStyle.UPPER_CENTER); crew.Die(); // Kill this Kerman } // All Get & Set functions public bool HasEaten() { return this.hasEaten; } public void SetEaten(bool hasEaten) { this.hasEaten = hasEaten; } public double GetEatTimer() { return this.eatTimer; } public void SetNextEatAt(double eatTimer) { this.eatTimer = (int) eatTimer; } public double GetKillTimer() { return this.killTimer; } public void SetKillTimer(double killTimer) { this.killTimer = (int) killTimer; } public ProtoCrewMember GetCrew() { return this.crew; } public void SetCrew(ProtoCrewMember crew) { this.crew = crew; } } }
  13. So if you use Part.RequestResource(name, amount), does it return how many it can draw or the leftover AFTER draw?
  14. Moving things, optimizing, and added two more module to control resource and their type. Also added lots of comments on the Fuel Cell module. FuelCell.cs /************************************************************************ * CSX Industry - Life Support Part+Plugin Pack for Kerbal Space Program* * * * Initial Alpha Release Version 0.3a * * * * Created by Charlie S. * * Built on July 18th, 2014 * ************************************************************************/ using UnityEngine; using KSP.IO; using System.Collections.Generic; namespace CSXIndustry { public class FuelCell : PartModule { private PartResource hydrogen; // Fuel cell main fuel private PartResource oxygen; // Fuel cell main fuel private PartResource water; // Cooling and Future usage for: GreenhouseMoudle private PartResource heat; // Future usage for: GreenhouseModule [KSPField(guiActive = true, guiName = "Cell Temperature ", guiUnits = "C")] private float cellTemp = 1000f; // Fuel Cell temperature public override void OnStart(PartModule.StartState state) { if(state != StartState.Editor) // When flight starts { // Set PartResource to variables this.hydrogen = this.part.Resources["Hydrogen"]; this.oxygen = this.part.Resources["Oxygen"]; this.water = this.part.Resources["Water"]; this.heat = this.part.Resources["Heat"]; // Set initial fuel cell temperature this.part.temperature = cellTemp; } } public override void OnUpdate() { if (UpdateCell()) // Update Fuel Cell and check if it's running or not { // If running, get number of parts that requires electrical charges List<Part> required = GetChargeRequired(); if(required.Count > 0) // If there is at least one part that required charging foreach (Part part in required) // For each part that requires charging part.Resources[Resources.electriccharge].amount += (0.24 / (double)required.Count) * Time.deltaTime; // Distribute these powers to them // If water tank is not full, fill them up too if (water.amount < water.maxAmount) water.amount += 1.0 * Time.deltaTime; // If heat storage is not full, fill them up too if (heat.amount < heat.maxAmount) heat.amount += 10.0 * Time.deltaTime; else cellTemp += 10f * Time.deltaTime; // If heat storage is full, then fuel cell's temperature increases } else // If Fuel Cell is not running if (cellTemp > 1000f) // If Fuel Cell is overheated cellTemp -= 1f * Time.deltaTime; // Cool it down over time if (UpdateCooling()) // If cooling is activated if (cellTemp > 1000f) // And cell is overheated cellTemp -= 15f * Time.deltaTime; // Cool it down if (oxygen.amount <= 0 || hydrogen.amount <= 0) // If either oxygen or hydrogen tank is empty DeactivateCell(); // Stop the Fuel Cell if (water.amount <= 0 || cellTemp <= 1000f) // If there is no water in water tank or the Fuel Cell is at it's normal temperature DeactivateCooling(); // Stop the cooling this.part.temperature = cellTemp; // Set Fuel Cell's temperature } private bool UpdateCell() { if (Events["DeactivateCell"].active) // If Fuel Cell is activated if (oxygen.amount > 0 && hydrogen.amount > 0) // If both tank have enough fuel to generate power { // Use fuel and return true oxygen.amount -= 1 * Time.deltaTime; hydrogen.amount -= 2 * Time.deltaTime; return true; } else return false; // Else return false; Fuel Cell has not enough fuel to generate power return false; // If not just return false; Fuel Cell is not activated } private bool UpdateCooling() { if (Events["DeactivateCooling"].active) // If cooling is activated if (water.amount > 0) // If there is enough water to run cooling { // Use water and return true water.amount -= 2 * Time.deltaTime; return true; } else return false; // Else return false; there is not enough water to run cooling return false; // If cooling is not running return false; Cooling is not activated } private List<Part> GetChargeRequired() { List<Part> list = new List<Part>(); foreach(Part part in this.vessel.parts) // For each part in entire vessel foreach(PartResource charge in part.Resources) // And for each resource in the part if(charge.resourceName == Resources.electriccharge && (charge.amount < charge.maxAmount)) // If it is electric charge and is not full list.Add(part); // Add it to the list return list; // Return the list } // Below for right-click options and action groups // [KSPEvent(guiActive = true, guiName = "Activate Fuel Cell")] public void ActivateCell() { ScreenMessages.PostScreenMessage("Fuel Cell : On", 5.0f, ScreenMessageStyle.UPPER_CENTER); Events["ActivateCell"].active = false; Events["DeactivateCell"].active = true; } [KSPEvent(guiActive = true, guiName = "Deactivate Fuel Cell", active = false)] public void DeactivateCell() { ScreenMessages.PostScreenMessage("Fuel Cell : Off", 5.0f, ScreenMessageStyle.UPPER_CENTER); Events["ActivateCell"].active = true; Events["DeactivateCell"].active = false; } [KSPEvent(guiActive = true, guiName = "Activate Cooling")] public void ActivateCooling() { Events["ActivateCooling"].active = false; Events["DeactivateCooling"].active = true; } [KSPEvent(guiActive = true, guiName = "Deactivate Cooling", active = false)] public void DeactivateCooling() { Events["ActivateCooling"].active = true; Events["DeactivateCooling"].active = false; } [KSPAction("Toggle Fuel Cell")] public void FuelCellAction(KSPActionParam param) { if (param.type == KSPActionType.Activate) ActivateCell(); else if (param.type == KSPActionType.Deactivate) DeactivateCell(); } [KSPAction("Toggle Cooling")] public void CoolingAction(KSPActionParam param) { if (param.type == KSPActionType.Activate) ActivateCooling(); else if (param.type == KSPActionType.Deactivate) DeactivateCooling(); } } } Resources.cs /************************************************************************ * CSX Industry - Life Support Part+Plugin Pack for Kerbal Space Program* * * * Initial Alpha Release Version 0.3a * * * * Created by Charlie S. * * Built on July 18th, 2014 * ************************************************************************/ namespace CSXIndustry { public class Resources { // KSP Default Resources public const string liquidfuel = "LiquidFuel"; public const string oxidizer = "Oxidizer"; public const string electriccharge = "ElectricCharge"; public const string monopropellant = "MonoPropellant"; // CSX Custom Resources public const string hydrogen = "Hydrogen"; public const string oxygen = "Oxygen"; public const string water = "Water"; public const string Heat = "Heat"; } } Now to stretch goals - Want to add a bit of futuristic module, named Greenhouse Module. It would have a capability of producing food products by spending heat, water, electricity and (further) carbon dioxide. Greenhouse Module would also generate oxygen probably..
  15. Day Five with modding, been cleaning and catching bugs last night. Fixed & Working Fuel Cell Part+Plugin PowerGenerator.cs using UnityEngine; using KSP.IO; using System.Collections.Generic; namespace PowerGenerator { public class PowerGenerator : PartModule { private PartResource hydrogen, oxygen, water, heat; [KSPField(guiActive = true, guiName = "Cell Temperature ", guiUnits = "C")] public float cellTemp = 1000; public override void OnStart(PartModule.StartState state) { this.hydrogen = this.part.Resources["Hydrogen"]; this.oxygen = this.part.Resources["Oxygen"]; this.water = this.part.Resources["Water"]; this.heat = this.part.Resources["Heat"]; this.part.temperature = cellTemp; } public override void OnUpdate() { if(this.vessel == FlightGlobals.ActiveVessel) { if(UpdateGenerator()) { double parts = CountChargeRequired(); foreach (Part part in this.vessel.parts) foreach (PartResource resource in part.Resources) if (resource.resourceName == "ElectricCharge" && (resource.amount < resource.maxAmount)) resource.amount += (0.24 / parts) * Time.deltaTime; if(water.amount < water.maxAmount) water.amount += 1 * Time.deltaTime; if (heat.amount < heat.maxAmount) heat.amount += 16.0 * Time.deltaTime; else cellTemp += 16f * Time.deltaTime; } else { if (cellTemp > 1000f) cellTemp -= 1f * Time.deltaTime; } if(UpdateCooling()) { if (cellTemp > 1000f) cellTemp -= 32f * Time.deltaTime; } if (this.oxygen.amount < 0 || this.hydrogen.amount < 0) DeactivateGenerator(); if (this.water.amount < 0) { CoolingOff(); this.water.amount = 0; } if (cellTemp <= 1000f) CoolingOff(); this.part.temperature = cellTemp; // Set Cell's temperature } } private bool UpdateGenerator() { if(Events["DeactivateGenerator"].active) { if (oxygen.amount > 0 && hydrogen.amount > 0) { oxygen.amount -= 1 * Time.deltaTime; hydrogen.amount -= 2 * Time.deltaTime; return true; } else return false; } return false; } private bool UpdateCooling() { if(Events["CoolingOff"].active) { if (water.amount > 0) { water.amount -= 2 * Time.deltaTime; return true; } else return false; } return false; } private void UpdateResources() { foreach(PartResource resource in part.Resources) { if (resource.resourceName == this.hydrogen.resourceName) resource.amount = this.hydrogen.amount; if (resource.resourceName == this.oxygen.resourceName) resource.amount = this.oxygen.amount; } } private double CountChargeRequired() { double count = 0; foreach (Part part in this.vessel.parts) foreach (PartResource resource in part.Resources) if (resource.resourceName == "ElectricCharge" && (resource.amount < resource.maxAmount)) count++; return count; } [KSPEvent(guiActive = true, guiName = "Activate Fuel Cell")] public void ActivateGenerator() { ScreenMessages.PostScreenMessage("Generator : On", 5.0f, ScreenMessageStyle.UPPER_CENTER); Events["ActivateGenerator"].active = false; Events["DeactivateGenerator"].active = true; } [KSPEvent(guiActive = true, guiName = "Deactivate Fuel Cell", active = false)] public void DeactivateGenerator() { ScreenMessages.PostScreenMessage("Generator : Off", 5.0f, ScreenMessageStyle.UPPER_CENTER); Events["ActivateGenerator"].active = true; Events["DeactivateGenerator"].active = false; } [KSPEvent(guiActive = true, guiName = "Activate Cooling")] public void CoolingOn() { Events["CoolingOn"].active = false; Events["CoolingOff"].active = true; } [KSPEvent(guiActive = true, guiName = "Deativate Cooling", active = false)] public void CoolingOff() { Events["CoolingOn"].active = true; Events["CoolingOff"].active = false; } [KSPAction("Toggle Fuel Cell")] public void ToggleFuelCellAction(KSPActionParam param) { if (param.type == KSPActionType.Activate) ActivateGenerator(); else if (param.type == KSPActionType.Deactivate) DeactivateGenerator(); } [KSPAction("Toggle Cooling")] public void ToggleCoolingAction(KSPActionParam param) { if (param.type == KSPActionType.Activate) CoolingOn(); else if (param.type == KSPActionType.Deactivate) CoolingOff(); } } } Time to Stretch goals and move onto other features that might add up to this part.
×
×
  • Create New...