public bool checkDeliveries(MKSLTranferList savestring, MKSLTranferList completeddeliveries) { if (!savestring.Any()) { return(false); } bool action = false; foreach (var delivery in savestring) { if (Planetarium.GetUniversalTime() > Convert.ToDouble(delivery.arrivaltime)) {//FlightGlobals.ActiveVessel.id == delivery.VesselTo.id && //if return is true then add the returned if (attemptDelivery(delivery)) { completeddeliveries.Add(delivery); action = true; } } } if (action) { completeddeliveries.ForEach(x => savestring.Remove(x)); } return(action); }
//public void Remove(MKSLtransfer transfer) //{ // Vessel ves = FlightGlobals.Vessels.Find(x => x.id == transfer.VesselFrom.id); // if (ves.packed && !ves.loaded) //inactive vessel // { // foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) // { // foreach (ProtoPartModuleSnapshot pm in p.modules) // { // if (pm.moduleName != "MKSLcentral") continue; // var savestring = new MKSLTranferList(); // savestring.Load(pm.moduleValues.GetNode("saveCurrentTransfersList")); // var currentNode = new ConfigNode(); // savestring.Save(currentNode); // pm.moduleValues.SetNode("saveCurrentTransfersList", currentNode); // var previouseList = pm.moduleValues.GetNode("savePreviousTransfersList"); // var previouse = new MKSLTranferList(); // previouse.Load(previouseList); // previouse.Add(transfer); // var previousNode = new ConfigNode(); // previouse.Save(previousNode); // pm.moduleValues.SetNode("savePreviousTransfersList", previousNode); // } // } // } // else //active vessel // { // foreach (Part p in ves.parts) // { // foreach (PartModule pm in p.Modules) // { // if (pm.moduleName == "MKSLcentral") // { // MKSLcentral MKSLc = p.Modules.OfType<MKSLcentral>().FirstOrDefault(); // MKSLc.saveCurrentTransfersList.RemoveAll(x => x.transferName == transfer.transferName); // MKSLc.savePreviousTransfersList.Add(transfer); // } // } // } // } // KnownTransfers.RemoveAll(x => x.transferName == transfer.transferName); //} public void Remove(MKSLtransfer transfer) { Vessel ves = FlightGlobals.Vessels.Find(x => x.id == transfer.VesselFrom.id); DoToVesselMKSLCentral(ves, (pm, savestring) => { var currentNode = new ConfigNode(); savestring.Save(currentNode); pm.moduleValues.SetNode("saveCurrentTransfersList", currentNode); var previouseList = pm.moduleValues.GetNode("savePreviousTransfersList"); var previouse = new MKSLTranferList(); previouse.Load(previouseList); previouse.Add(transfer); var previousNode = new ConfigNode(); previouse.Save(previousNode); pm.moduleValues.SetNode("savePreviousTransfersList", previousNode); }, MKSLc => { MKSLc.saveCurrentTransfersList.RemoveAll(x => x.transferName == transfer.transferName); MKSLc.savePreviousTransfersList.Add(transfer); }); KnownTransfers.RemoveAll(x => x.transferName == transfer.transferName); }
void Awake() { if (ToolbarManager.ToolbarAvailable) { this.orbLogTButton = ToolbarManager.Instance.add("UKS", "orbLog"); orbLogTButton.TexturePath = "UmbraSpaceIndustries/Kolonization/OrbitalLogistics24"; orbLogTButton.ToolTip = "USI Orbital Logistics"; orbLogTButton.Enabled = true; orbLogTButton.OnClick += (e) => { if (windowVisible) { GuiOff(); windowVisible = false; } else { GuiOn(); windowVisible = true; } }; } else { var texture = new Texture2D(36, 36, TextureFormat.RGBA32, false); var textureFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "OrbitalLogistics.png"); texture.LoadImage(File.ReadAllBytes(textureFile)); this.orbLogButton = ApplicationLauncher.Instance.AddModApplication(GuiOn, GuiOff, null, null, null, null, ApplicationLauncher.AppScenes.ALWAYS, texture); } KnownTransfers = new MKSLTranferList(); nextchecktime = Planetarium.GetUniversalTime() + 2; }
private MKSLTranferList GetTransfers() { var transfers = new MKSLTranferList(); foreach (Vessel ves in FlightGlobals.Vessels) { DoToVesselMKSLCentral(ves, (part, list) => transfers.AddRange(list), c => transfers.AddRange(c.saveCurrentTransfersList)); } return(transfers); }
public void Remove(MKSLtransfer transfer) { Vessel ves = FlightGlobals.Vessels.Find(x => x.id == transfer.VesselFrom.id); if (ves.packed && !ves.loaded) //inactive vessel { foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) { foreach (ProtoPartModuleSnapshot pm in p.modules) { if (pm.moduleName != "MKSLcentral") { continue; } var savestring = new MKSLTranferList(); savestring.Load(pm.moduleValues.GetNode("saveCurrentTransfersList")); var currentNode = new ConfigNode(); savestring.Save(currentNode); pm.moduleValues.SetNode("saveCurrentTransfersList", currentNode); var previouseList = pm.moduleValues.GetNode("savePreviousTransfersList"); var previouse = new MKSLTranferList(); previouse.Load(previouseList); previouse.Add(transfer); var previousNode = new ConfigNode(); previouse.Save(previousNode); pm.moduleValues.SetNode("savePreviousTransfersList", previousNode); } } } else //active vessel { foreach (Part p in ves.parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "MKSLcentral") { MKSLcentral MKSLc = p.Modules.OfType <MKSLcentral>().FirstOrDefault(); MKSLc.saveCurrentTransfersList.RemoveAll(x => x.transferName == transfer.transferName); MKSLc.savePreviousTransfersList.Add(transfer); } } } } KnownTransfers.RemoveAll(x => x.transferName == transfer.transferName); }
//private void Ondraw() //{ // if (!(nextchecktime < Planetarium.GetUniversalTime())) return; // KnownTransfers = GetTransfers(); // foreach (Vessel ves in FlightGlobals.Vessels) // { // if (FlightGlobals.ActiveVessel.protoVessel.orbitSnapShot.ReferenceBodyIndex != // ves.protoVessel.orbitSnapShot.ReferenceBodyIndex) continue; // if (ves.packed && !ves.loaded) //inactive vessel // { // foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) // { // foreach (ProtoPartModuleSnapshot pm in p.modules) // { // if (pm.moduleName != "MKSLcentral") continue; // var savestring = new MKSLTranferList(); // savestring.Load(pm.moduleValues.GetNode("saveCurrentTransfersList")); // var completeddeliveries = new MKSLTranferList(); // if (savestring.Count > 0) // { // this.Log("delivering from active" + savestring.First().transferName + " with " + savestring.First().transferList.First().resourceName + ":" + savestring.First().transferList.First().amount); // } // if (checkDeliveries(savestring, completeddeliveries)) // { // var currentNode = new ConfigNode(); // savestring.Save(currentNode); // pm.moduleValues.SetNode("saveCurrentTransfersList", currentNode); // var previouseList = pm.moduleValues.GetNode("savePreviousTransfersList"); // var previouse = new MKSLTranferList(); // previouse.Load(previouseList); // previouse.AddRange(completeddeliveries); // var previousNode = new ConfigNode(); // previouse.Save(previousNode); // pm.moduleValues.SetNode("savePreviousTransfersList", previousNode); // } // } // } // } // else //active vessel // { // foreach (Part p in ves.parts) // { // foreach (PartModule pm in p.Modules) // { // if (pm.moduleName == "MKSLcentral") // { // MKSLcentral MKSLc = p.Modules.OfType<MKSLcentral>().FirstOrDefault(); // var savestring = MKSLc.saveCurrentTransfersList; // if (savestring.Count > 0) // { // this.Log("delivering from active" + savestring.First().transferName + " with "+ savestring.First().transferList.First().resourceName+":"+savestring.First().transferList.First().amount); // } // var completeddeliveries = new MKSLTranferList(); // if (checkDeliveries(savestring, completeddeliveries)) // { // MKSLc.savePreviousTransfersList.AddRange(completeddeliveries); // } // } // } // } // } // } // nextchecktime = Planetarium.GetUniversalTime() + 60; //} private void Ondraw() { if (!(nextchecktime < Planetarium.GetUniversalTime())) { return; } KnownTransfers = GetTransfers(); foreach (Vessel ves in FlightGlobals.Vessels) { if (FlightGlobals.ActiveVessel.protoVessel.orbitSnapShot.ReferenceBodyIndex != ves.protoVessel.orbitSnapShot.ReferenceBodyIndex) { continue; } DoToVesselMKSLCentral(ves, (pm, savestring) => { var completeddeliveries = new MKSLTranferList(); if (checkDeliveries(savestring, completeddeliveries)) { var currentNode = new ConfigNode(); savestring.Save(currentNode); pm.moduleValues.SetNode("saveCurrentTransfersList", currentNode); var previouseList = pm.moduleValues.GetNode("savePreviousTransfersList"); var previouse = new MKSLTranferList(); previouse.Load(previouseList); previouse.AddRange(completeddeliveries); var previousNode = new ConfigNode(); previouse.Save(previousNode); pm.moduleValues.SetNode("savePreviousTransfersList", previousNode); } }, MKSLc => { var savestring = MKSLc.saveCurrentTransfersList; var completeddeliveries = new MKSLTranferList(); if (checkDeliveries(savestring, completeddeliveries)) { MKSLc.savePreviousTransfersList.AddRange(completeddeliveries); } }); } nextchecktime = Planetarium.GetUniversalTime() + 60; }
private void DoToVesselMKSLCentral(Vessel ves, Action <ProtoPartModuleSnapshot, MKSLTranferList> protoPartAction, Action <MKSLcentral> centralAction) { try { if (ves.packed && !ves.loaded) //inactive vessel { foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) { foreach (ProtoPartModuleSnapshot pm in p.modules) { if (pm.moduleName != "MKSLcentral") { continue; } var savestring = new MKSLTranferList(); savestring.Load(pm.moduleValues.GetNode("saveCurrentTransfersList")); protoPartAction(pm, savestring); } } } else //active vessel { foreach (Part p in ves.parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "MKSLcentral") { MKSLcentral MKSLc = p.Modules.OfType <MKSLcentral>().FirstOrDefault(); centralAction(MKSLc); } } } } } catch (Exception e) { this.Log("couldnt read transfers " + e.StackTrace); } }
private MKSLTranferList GetTransfers() { var transfers = new MKSLTranferList(); foreach (Vessel ves in FlightGlobals.Vessels) { if (ves.packed && !ves.loaded) //inactive vessel { foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) { foreach (ProtoPartModuleSnapshot pm in p.modules) { if (pm.moduleName != "MKSLcentral") { continue; } var tempTranferList = new MKSLTranferList(); tempTranferList.Load(pm.moduleValues.GetNode("saveCurrentTransfersList")); transfers.AddRange(tempTranferList); } } } else //active vessel { foreach (Part p in ves.parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "MKSLcentral") { MKSLcentral MKSLc = p.Modules.OfType <MKSLcentral>().FirstOrDefault(); var tempTranferList = MKSLc.saveCurrentTransfersList; transfers.AddRange(tempTranferList); } } } } } this.Log("found " + transfers.Count); return(transfers); }
private void Awake() { KnownTransfers = new MKSLTranferList(); RenderingManager.AddToPostDrawQueue(144, Ondraw); nextchecktime = Planetarium.GetUniversalTime() + 2; }
public void UpdateTransfers() { KnownTransfers = GetTransfers(); }
private void Ondraw() { if (!(nextchecktime < Planetarium.GetUniversalTime())) { return; } KnownTransfers = GetTransfers(); foreach (Vessel ves in FlightGlobals.Vessels) { if (FlightGlobals.ActiveVessel.protoVessel.orbitSnapShot.ReferenceBodyIndex != ves.protoVessel.orbitSnapShot.ReferenceBodyIndex) { continue; } if (ves.packed && !ves.loaded) //inactive vessel { foreach (ProtoPartSnapshot p in ves.protoVessel.protoPartSnapshots) { foreach (ProtoPartModuleSnapshot pm in p.modules) { if (pm.moduleName != "MKSLcentral") { continue; } var savestring = new MKSLTranferList(); savestring.Load(pm.moduleValues.GetNode("saveCurrentTransfersList")); var completeddeliveries = new MKSLTranferList(); if (savestring.Count > 0) { this.Log("delivering from active" + savestring.First().transferName + " with " + savestring.First().transferList.First().resourceName + ":" + savestring.First().transferList.First().amount); } if (checkDeliveries(savestring, completeddeliveries)) { var currentNode = new ConfigNode(); savestring.Save(currentNode); pm.moduleValues.SetNode("saveCurrentTransfersList", currentNode); var previouseList = pm.moduleValues.GetNode("savePreviousTransfersList"); var previouse = new MKSLTranferList(); previouse.Load(previouseList); previouse.AddRange(completeddeliveries); var previousNode = new ConfigNode(); previouse.Save(previousNode); pm.moduleValues.SetNode("savePreviousTransfersList", previousNode); } } } } else //active vessel { foreach (Part p in ves.parts) { foreach (PartModule pm in p.Modules) { if (pm.moduleName == "MKSLcentral") { MKSLcentral MKSLc = p.Modules.OfType <MKSLcentral>().FirstOrDefault(); var savestring = MKSLc.saveCurrentTransfersList; if (savestring.Count > 0) { this.Log("delivering from active" + savestring.First().transferName + " with " + savestring.First().transferList.First().resourceName + ":" + savestring.First().transferList.First().amount); } var completeddeliveries = new MKSLTranferList(); if (checkDeliveries(savestring, completeddeliveries)) { MKSLc.savePreviousTransfersList.AddRange(completeddeliveries); } } } } } } nextchecktime = Planetarium.GetUniversalTime() + 60; }