//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); }
private bool attemptDelivery(MKSLtransfer delivery) { var target = FlightGlobals.Vessels.Find(x => x.id == delivery.VesselTo.id); if (target == null) { return(false); } delivery.VesselTo = target; //check if orbit changed of destination if destination is orbital if (delivery.orbit) { if (!checkStaticOrbit(delivery.VesselTo, delivery.SMA, delivery.ECC, delivery.INC)) { delivery.delivered = false; return(false); } } //check if location changed of destination if destination is surface //if (!delivery.orbit) //{ // if (!checkStaticLocation(delivery.VesselTo, delivery.LON, delivery.LAT)) // { // delivery.delivered = false; // return false; // } //} //TODO: fix the checkstaticlocation. it uses activevessel instead of the target makeDelivery(delivery); return(true); }
public MKSTransferView(MKSLtransfer transfer, ITransferListViewer parent) : base(transfer.transferName, 175, 450) { _parent = parent; _transfer = transfer; SetVisible(true); }
private TransferValidationResult _checkTransferAmounts(MKSLtransfer trans, TransferCostPaymentModes paymentMode) { var res = new[] { true, true }; var validationMess = ""; var totals = new Dictionary <string, double>(); foreach (var tRes in trans.transferList) { totals.Add(tRes.resourceName, tRes.amount); if (this.readResource(trans.VesselFrom, tRes.resourceName)[0] < tRes.amount) { res[0] = res[1] = false; validationMess = validationMess + "insufficient " + tRes.resourceName + " "; break; } } if (res[1]) { Func <string, double, double> subtractTransfer = (n, a) => { if (totals.ContainsKey(n)) { return(a - totals[n]); } return(a); }; foreach (var cRes in trans.costList) { var totalAvail = 0d; switch (paymentMode) { case TransferCostPaymentModes.Source: { totalAvail = subtractTransfer(cRes.resourceName, this.readResource(trans.VesselFrom, cRes.resourceName)[0]); } break; case TransferCostPaymentModes.Target: { totalAvail = this.readResource(trans.VesselTo, cRes.resourceName)[0]; } break; case TransferCostPaymentModes.Both: { totalAvail = this.readResource(trans.VesselTo, cRes.resourceName)[0] + subtractTransfer(cRes.resourceName, this.readResource(trans.VesselFrom, cRes.resourceName)[0]); } break; } if (!(totalAvail < cRes.amount)) { continue; } validationMess = validationMess + "insufficient " + cRes.resourceName + " "; res[1] = false; break; } } return(new TransferValidationResult(res[0], res[1], validationMess)); }
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 makeDelivery(MKSLtransfer transfer) { foreach (MKSLresource res in transfer.transferList) { try { transfer.VesselTo.ExchangeResources(res.resourceName, res.amount); } catch (Exception e) { this.Log(e.StackTrace); } } transfer.delivered = true; }
public void updateCostList(MKSLtransfer trans) { double PSSM = getValueFromStrPlanet(_central.DistanceModifierPlanet, _central.vessel.mainBody.name); double PSOM = getValueFromStrPlanet(_central.SurfaceOrbitModifierPlanet, _central.vessel.mainBody.name); double POSM = getValueFromStrPlanet(_central.OrbitSurfaceModifierPlanet, _central.vessel.mainBody.name); double ATUP = 1; double ATDO = 1; if (_central.vessel.mainBody.atmosphere) { ATUP = (double)_central.AtmosphereUpModifier; ATDO = (double)_central.AtmosphereDownModifier; } foreach (MKSLresource res in trans.costList) { ///take into account amount ///take into account celestialbody if ((trans.VesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.PRELAUNCH) && (trans.VesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselTo.protoVessel.situation == Vessel.Situations.SPLASHED)) { double distance = _central.GetDistanceBetweenPoints(trans.VesselFrom.protoVessel.latitude, trans.VesselFrom.protoVessel.longitude, trans.VesselTo.protoVessel.latitude, trans.VesselTo.protoVessel.longitude); res.amount = res.costPerMass * trans.totalMass() * distance * _central.vessel.mainBody.GeeASL * _central.DistanceModifier * PSSM; } else if ((trans.VesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.PRELAUNCH) && (trans.VesselTo.protoVessel.situation == Vessel.Situations.ORBITING)) { res.amount = res.costPerMass * trans.totalMass() * _central.vessel.mainBody.GeeASL * _central.vessel.mainBody.Radius * ATUP * _central.SurfaceOrbitModifier * PSOM; } else if ((trans.VesselFrom.protoVessel.situation == Vessel.Situations.ORBITING) && (trans.VesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselTo.protoVessel.situation == Vessel.Situations.SPLASHED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.PRELAUNCH)) { res.amount = res.costPerMass * trans.totalMass() * _central.vessel.mainBody.GeeASL * _central.vessel.mainBody.Radius * ATDO * _central.OrbitSurfaceModifier * POSM; } else //Working code - going to just use the same calc as surface to surface for orbit to orbit for now { double distance = _central.GetDistanceBetweenPoints(trans.VesselFrom.protoVessel.latitude, trans.VesselFrom.protoVessel.longitude, trans.VesselTo.protoVessel.latitude, trans.VesselTo.protoVessel.longitude); res.amount = res.costPerMass * trans.totalMass() * distance * _central.vessel.mainBody.GeeASL * _central.DistanceModifier * PSSM; } } }
protected override void DrawWindowContents(int windowId) { if (_showIncoming) { currenTranferList = _model.KnownTransfers.Where(x => x.VesselTo.id == FlightGlobals.ActiveVessel.id); } else { currenTranferList = _model.KnownTransfers; } GUILayout.BeginVertical(); string incomingButtonText = (_showIncoming) ? "Show All" : "Show Incoming"; if (GUILayout.Button(incomingButtonText, MKSGui.buttonStyle, GUILayout.Width(150))) { _showIncoming = !_showIncoming; } GUILayout.Label("Current transfers", MKSGui.labelStyle, GUILayout.Width(150)); _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true, GUILayout.MaxHeight(300)); foreach (MKSLtransfer trans in currenTranferList) { if (GUILayout.Button(trans.transferName + " (" + Utilities.FormatTime(trans.arrivaltime - Planetarium.GetUniversalTime()) + ")", MKSGui.buttonStyle, GUILayout.Width(135), GUILayout.Height(22))) { _selectedTransfer = trans; if (_transferView == null) { _transferView = new MKSTransferView(_selectedTransfer, this); } else { _transferView.Transfer = _selectedTransfer; } } } GUILayout.EndScrollView(); if (GUILayout.Button("Close", MKSGui.buttonStyle, GUILayout.Width(150))) { SetVisible(false); } GUILayout.EndVertical(); }
public void updateArrivalTime(MKSLtransfer trans) { double prepT = (double)_central.PrepTime; double TpD = getValueFromStrPlanet(_central.TimePerDistancePlanet, _central.vessel.mainBody.name); if (1 == TpD) { TpD = _central.TimePerDistance; } double TtfLO = getValueFromStrPlanet(_central.TimeToFromLOPlanet, _central.vessel.mainBody.name); if (1 == TtfLO) { TtfLO = _central.TimeToFromLO; } if ((trans.VesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.PRELAUNCH) && (trans.VesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselTo.protoVessel.situation == Vessel.Situations.SPLASHED || trans.VesselTo.protoVessel.situation == Vessel.Situations.PRELAUNCH)) { double distance = _central.GetDistanceBetweenPoints(trans.VesselFrom.protoVessel.latitude, trans.VesselFrom.protoVessel.longitude, trans.VesselTo.protoVessel.latitude, trans.VesselTo.protoVessel.longitude); trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + (distance * TpD); } else if ((trans.VesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED || trans.VesselFrom.protoVessel.situation == Vessel.Situations.PRELAUNCH) && (trans.VesselTo.protoVessel.situation == Vessel.Situations.ORBITING)) { trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + TtfLO; } else if ((trans.VesselFrom.protoVessel.situation == Vessel.Situations.ORBITING) && (trans.VesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.VesselTo.protoVessel.situation == Vessel.Situations.SPLASHED || trans.VesselTo.protoVessel.situation == Vessel.Situations.PRELAUNCH)) { trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + TtfLO; } else //More working code { double distance = _central.GetDistanceBetweenPoints(trans.VesselFrom.protoVessel.latitude, trans.VesselFrom.protoVessel.longitude, trans.VesselTo.protoVessel.latitude, trans.VesselTo.protoVessel.longitude); trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + (distance * TpD); } }
public void createTransfer(MKSLtransfer trans) { trans.costList = trans.costList.Where(x => x.amount > 0).ToList(); trans.transferList = trans.transferList.Where(x => x.amount > 0).ToList(); foreach (MKSLresource costRes in trans.costList) { double AmountToGather = costRes.amount; double AmountGathered = 0; AmountGathered += -_central.vessel.ExchangeResources(costRes.resourceName, -(AmountToGather - AmountGathered)); AmountGathered += -trans.VesselFrom.ExchangeResources(costRes.resourceName, -(AmountToGather - AmountGathered)); } foreach (MKSLresource transRes in trans.transferList) { transRes.amount = -trans.VesselFrom.ExchangeResources(transRes.resourceName, -transRes.amount); } trans.delivered = false; updateArrivalTime(trans); if (trans.VesselTo.situation == Vessel.Situations.ORBITING) { trans.orbit = true; trans.SMA = trans.VesselTo.protoVessel.orbitSnapShot.semiMajorAxis; trans.ECC = trans.VesselTo.protoVessel.orbitSnapShot.eccentricity; trans.INC = trans.VesselTo.protoVessel.orbitSnapShot.inclination; } if (trans.VesselTo.situation == Vessel.Situations.LANDED || trans.VesselTo.situation == Vessel.Situations.SPLASHED || trans.VesselFrom.situation == Vessel.Situations.LANDED) { trans.surface = true; trans.LON = trans.VesselTo.protoVessel.longitude; trans.LAT = trans.VesselTo.protoVessel.latitude; } _central.saveCurrentTransfersList.Add(trans); SetVisible(false); }
public void Remove(MKSLtransfer transfer) { _model.removeCurrentTranfer(transfer); }
private void WindowGUIMain(int windowID) { GUI.DragWindow(new Rect(0, 0, 150, 30)); GUILayout.BeginVertical(); if (GUILayout.Button("New Transfer", buttonStyle, GUILayout.Width(150))) { //newedit = true; makeBodyVesselList(); editGUITransfer = new MKSLtransfer(); System.Random rnd = new System.Random(); editGUITransfer.transferName = rnd.Next(100000, 999999).ToString(); editGUITransfer.initTransferList(ManagedResources); editGUITransfer.initCostList(Mix1CostResources); editGUITransfer.vesselFrom = vessel; editGUITransfer.vesselTo = vessel; editGUIResource = editGUITransfer.transferList[0]; StrAmount = "0"; currentAvailable = readResource(editGUITransfer.vesselFrom, editGUIResource.resourceName); openGUIEdit(); } GUILayout.Label("Current transfers", labelStyle, GUILayout.Width(150)); scrollPositionGUICurrentTransfers = GUILayout.BeginScrollView(scrollPositionGUICurrentTransfers, false,true, GUILayout.Width(160), GUILayout.Height(180)); foreach (MKSLtransfer trans in currentTransfers) { if (GUILayout.Button(trans.transferName + " (" + deliveryTimeString(trans.arrivaltime, Planetarium.GetUniversalTime()) + ")", buttonStyle, GUILayout.Width(135), GUILayout.Height(22))) { viewCurrent = true; viewGUITransfer = trans; openGUIView(); } } GUILayout.EndScrollView(); GUILayout.Label("Previous tranfers", labelStyle, GUILayout.Width(150)); scrollPositionGUIPreviousTransfers = GUILayout.BeginScrollView(scrollPositionGUIPreviousTransfers, false, true, GUILayout.Width(160), GUILayout.Height(80)); foreach (MKSLtransfer trans in previousTransfers) { if (GUILayout.Button(trans.transferName + " " + (trans.delivered == true ? "succes" : "failure"), buttonStyle, GUILayout.Width(135), GUILayout.Height(22))) { viewCurrent = false; viewGUITransfer = trans; openGUIView(); } } GUILayout.EndScrollView(); GUILayout.Label("", labelStyle, GUILayout.Width(150)); if (GUILayout.Button("Close", buttonStyle, GUILayout.Width(150))) { closeGUIMain(); } GUILayout.EndVertical(); }
/// <summary> /// transfer functions /// </summary> /// <param name="trans"></param> public bool validateTransfer(MKSLtransfer trans, ref string validationMess) { bool check = true; validationMess = ""; //check if origin is not the same as destination if (trans.vesselFrom.id.ToString() == trans.vesselTo.id.ToString()) { validationMess = "origin and destination are equal"; return (false); } //check situation origin vessel if (trans.vesselFrom.situation != Vessel.Situations.ORBITING && trans.vesselFrom.situation != Vessel.Situations.SPLASHED && trans.vesselFrom.situation != Vessel.Situations.LANDED) { validationMess = "origin of transfer is not in a stable situation"; return (false); } //check situation destination vessel if (trans.vesselTo.situation != Vessel.Situations.ORBITING && trans.vesselTo.situation != Vessel.Situations.SPLASHED && trans.vesselTo.situation != Vessel.Situations.LANDED) { validationMess = "destination of transfer is not in a stable situation"; return (false); } //check for sufficient transfer resources foreach (MKSLresource transRes in trans.transferList) { if (readResource(trans.vesselFrom, transRes.resourceName) < transRes.amount) { check = false; validationMess = validationMess + "insufficient " + transRes.resourceName + " "; } } //check for sufficient cost resources foreach (MKSLresource costRes in trans.costList) { double totalResAmount = 0; totalResAmount = costRes.amount; foreach (MKSLresource transRes in trans.transferList) { if (costRes.resourceName == transRes.resourceName) { totalResAmount = totalResAmount + transRes.amount; } } if ((readResource(trans.vesselFrom, costRes.resourceName) + readResource(vessel, costRes.resourceName)) < totalResAmount) { check = false; validationMess = validationMess + "insufficient " + costRes.resourceName + " "; } } if (check) { validationMess = ""; return(true); } else { return(false); } }
public void updateCostList(MKSLtransfer trans) { double PSSM = getValueFromStrPlanet(DistanceModifierPlanet, vessel.mainBody.name); double PSOM = getValueFromStrPlanet(SurfaceOrbitModifierPlanet, vessel.mainBody.name); double POSM = getValueFromStrPlanet(OrbitSurfaceModifierPlanet, vessel.mainBody.name); double ATUP = 1; double ATDO = 1; if (vessel.mainBody.atmosphere) { ATUP = (double)AtmosphereUpModifier; ATDO = (double)AtmosphereDownModifier; } foreach (MKSLresource res in trans.costList) { ///take into account amount ///take into account celestialbody if ((trans.vesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED) && (trans.vesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselTo.protoVessel.situation == Vessel.Situations.SPLASHED)) { double distance = GetDistanceBetweenPoints(trans.vesselFrom.protoVessel.latitude, trans.vesselFrom.protoVessel.longitude, trans.vesselTo.protoVessel.latitude, trans.vesselTo.protoVessel.longitude); res.amount = res.costPerMass * trans.totalMass() * distance * vessel.mainBody.GeeASL * DistanceModifier * PSSM; } else if ((trans.vesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED) && (trans.vesselTo.protoVessel.situation == Vessel.Situations.ORBITING)) { res.amount = res.costPerMass * trans.totalMass() * vessel.mainBody.GeeASL * vessel.mainBody.Radius * ATUP * SurfaceOrbitModifier * PSOM; } else if ((trans.vesselFrom.protoVessel.situation == Vessel.Situations.ORBITING) && (trans.vesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselTo.protoVessel.situation == Vessel.Situations.SPLASHED)) { res.amount = res.costPerMass * trans.totalMass() * vessel.mainBody.GeeASL * vessel.mainBody.Radius * ATDO * OrbitSurfaceModifier * POSM; } else //Working code - going to just use the same calc as surface to surface for orbit to orbit for now { double distance = GetDistanceBetweenPoints(trans.vesselFrom.protoVessel.latitude, trans.vesselFrom.protoVessel.longitude, trans.vesselTo.protoVessel.latitude, trans.vesselTo.protoVessel.longitude); res.amount = res.costPerMass * trans.totalMass() * distance * vessel.mainBody.GeeASL * DistanceModifier * PSSM; } } }
public void Remove(MKSLtransfer transfer) { _model.Remove(transfer); }
public void createTransfer(MKSLtransfer trans) { foreach (MKSLresource costRes in trans.costList) { double AmountToGather = costRes.amount; double AmountGathered = 0; AmountGathered = AmountGathered + takeResources(vessel, costRes.resourceName, AmountToGather - AmountGathered); AmountGathered = AmountGathered + takeResources(trans.vesselFrom, costRes.resourceName, AmountToGather - AmountGathered); } foreach (MKSLresource transRes in trans.transferList) { transRes.amount = takeResources(trans.vesselFrom, transRes.resourceName, transRes.amount); } trans.delivered = false; updateArrivalTime(trans); if (trans.vesselTo.situation == Vessel.Situations.ORBITING) { trans.orbit = true; trans.SMA = trans.vesselTo.protoVessel.orbitSnapShot.semiMajorAxis; trans.ECC = trans.vesselTo.protoVessel.orbitSnapShot.eccentricity; trans.INC = trans.vesselTo.protoVessel.orbitSnapShot.inclination; } if (trans.vesselTo.situation == Vessel.Situations.LANDED || trans.vesselTo.situation == Vessel.Situations.SPLASHED) { trans.surface = true; trans.LON = trans.vesselTo.protoVessel.longitude; trans.LAT = trans.vesselTo.protoVessel.latitude; } if (saveCurrentTransfers == "") { saveCurrentTransfers = trans.longsavestring(); } else { saveCurrentTransfers = saveCurrentTransfers + "@" + trans.longsavestring(); } loadTransferList(currentTransfers, saveCurrentTransfers, true); closeGUIEdit(); }
private void makeDelivery(MKSLtransfer transfer) { foreach (MKSLresource res in transfer.transferList) { giveResources(FlightGlobals.ActiveVessel, res.resourceName, res.amount); } transfer.delivered = true; }
private bool attemptDelivery(ref string delivery) { MKSLtransfer transfer = new MKSLtransfer(); transfer.loadstring(delivery); //check if orbit changed of destination if destination is orbital if(transfer.orbit) { if (!checkStaticOrbit(FlightGlobals.ActiveVessel, transfer.SMA, transfer.ECC, transfer.INC)) { transfer.delivered = false; delivery = transfer.savestring(); return true; } } //check if location changed of destination if destination is surface if (transfer.orbit) { if (!checkStaticLocation(FlightGlobals.ActiveVessel, transfer.LON, transfer.LAT)) { transfer.delivered = false; delivery = transfer.savestring(); return true; } } makeDelivery(transfer); //delivery = transfer.longsavestring(); //return false; delivery = transfer.savestring(); return (true); }
internal void createTransfer(MKSLtransfer trans, TransferCostPaymentModes mode) { trans.costList = trans.costList.Where(x => x.amount > 0).ToList(); trans.transferList = trans.transferList.Where(x => x.amount > 0).ToList(); foreach (MKSLresource costRes in trans.costList) { var toDraw = -costRes.amount; switch (mode) { case TransferCostPaymentModes.Source: { trans.VesselFrom.ExchangeResources(costRes.resourceName, toDraw); } break; case TransferCostPaymentModes.Target: { trans.VesselTo.ExchangeResources(costRes.resourceName, toDraw); } break; case TransferCostPaymentModes.Both: default: { Vessel first; Vessel second; if (this._central.vessel.id == trans.VesselFrom.id) { first = trans.VesselFrom; second = trans.VesselTo; } else { first = trans.VesselTo; second = trans.VesselFrom; } var drawn = first.ExchangeResources(costRes.resourceName, toDraw); second.ExchangeResources(costRes.resourceName, toDraw - drawn); } break; } } foreach (MKSLresource transRes in trans.transferList) { transRes.amount = -trans.VesselFrom.ExchangeResources(transRes.resourceName, -transRes.amount); } trans.delivered = false; updateArrivalTime(trans); if (trans.VesselTo.situation == Vessel.Situations.ORBITING) { trans.orbit = true; trans.SMA = trans.VesselTo.protoVessel.orbitSnapShot.semiMajorAxis; trans.ECC = trans.VesselTo.protoVessel.orbitSnapShot.eccentricity; trans.INC = trans.VesselTo.protoVessel.orbitSnapShot.inclination; } if (trans.VesselTo.situation == Vessel.Situations.LANDED || trans.VesselTo.situation == Vessel.Situations.SPLASHED || trans.VesselFrom.situation == Vessel.Situations.LANDED) { trans.surface = true; trans.LON = trans.VesselTo.protoVessel.longitude; trans.LAT = trans.VesselTo.protoVessel.latitude; } _central.saveCurrentTransfersList.Add(trans); SetVisible(false); }
internal bool validateTransfer(MKSLtransfer trans, TransferCostPaymentModes mode, ref string validationMess) { bool check = true; validationMess = ""; //check if origin is not the same as destination if (trans.VesselFrom.id.ToString() == trans.VesselTo.id.ToString()) { validationMess = "origin and destination are equal"; return(false); } //check situation origin vessel if (trans.VesselFrom.situation != Vessel.Situations.ORBITING && trans.VesselFrom.situation != Vessel.Situations.SPLASHED && trans.VesselFrom.situation != Vessel.Situations.LANDED && trans.VesselFrom.situation != Vessel.Situations.PRELAUNCH) { validationMess = "origin of transfer is not in a stable situation"; return(false); } //check situation destination vessel if (trans.VesselTo.situation != Vessel.Situations.ORBITING && trans.VesselTo.situation != Vessel.Situations.SPLASHED && trans.VesselTo.situation != Vessel.Situations.LANDED && trans.VesselFrom.situation != Vessel.Situations.LANDED) { validationMess = "destination of transfer is not in a stable situation"; return(false); } ////check for sufficient transfer resources //foreach (MKSLresource transRes in trans.transferList) //{ // if (readResource(trans.VesselFrom, transRes.resourceName)[0] < transRes.amount) // { // check = false; // validationMess = validationMess + "insufficient " + transRes.resourceName + " "; // } //} ////check for sufficient cost resources //foreach (MKSLresource costRes in trans.costList) //{ // double totalResAmount = 0; // totalResAmount = costRes.amount; // foreach (MKSLresource transRes in trans.transferList) // { // if (costRes.resourceName == transRes.resourceName) // { // totalResAmount = totalResAmount + transRes.amount; // } // } // if ((readResource(trans.VesselFrom, costRes.resourceName)[0] + readResource(_central.vessel, costRes.resourceName)[0]) < totalResAmount) // { // check = false; // validationMess = validationMess + "insufficient " + costRes.resourceName + " "; // } //} var checkRes = this._checkTransferAmounts(trans, mode); check = checkRes.EnoughRes; if (check) { validationMess = ""; return(true); } validationMess = checkRes.ValidationMessage; return(false); }
public bool validateTransfer(MKSLtransfer trans, ref string validationMess) { bool check = true; validationMess = ""; //check if origin is not the same as destination if (trans.VesselFrom.id.ToString() == trans.VesselTo.id.ToString()) { validationMess = "origin and destination are equal"; return(false); } //check situation origin vessel if (trans.VesselFrom.situation != Vessel.Situations.ORBITING && trans.VesselFrom.situation != Vessel.Situations.SPLASHED && trans.VesselFrom.situation != Vessel.Situations.LANDED && trans.VesselFrom.situation != Vessel.Situations.PRELAUNCH) { validationMess = "origin of transfer is not in a stable situation"; return(false); } //check situation destination vessel if (trans.VesselTo.situation != Vessel.Situations.ORBITING && trans.VesselTo.situation != Vessel.Situations.SPLASHED && trans.VesselTo.situation != Vessel.Situations.LANDED && trans.VesselFrom.situation != Vessel.Situations.LANDED) { validationMess = "destination of transfer is not in a stable situation"; return(false); } //check for sufficient transfer resources foreach (MKSLresource transRes in trans.transferList) { if (readResource(trans.VesselFrom, transRes.resourceName) < transRes.amount) { check = false; validationMess = validationMess + "insufficient " + transRes.resourceName + " "; } } //check for sufficient cost resources foreach (MKSLresource costRes in trans.costList) { double totalResAmount = 0; totalResAmount = costRes.amount; foreach (MKSLresource transRes in trans.transferList) { if (costRes.resourceName == transRes.resourceName) { totalResAmount = totalResAmount + transRes.amount; } } if ((readResource(trans.VesselFrom, costRes.resourceName) + readResource(_central.vessel, costRes.resourceName)) < totalResAmount) { check = false; validationMess = validationMess + "insufficient " + costRes.resourceName + " "; } } if (check) { validationMess = ""; return(true); } return(false); }
//removes an entry from the current transfers public void removeCurrentTranfer(MKSLtransfer transRemove) { saveCurrentTransfersList.Remove(transRemove); savePreviousTransfersList.Add(transRemove); }
//removes an entry from the current transfers public void removeCurrentTranfer(MKSLtransfer transRemove) { //remove from current transfers save string string[] deliveries = saveCurrentTransfers.Split('@'); string newSaveCurrentTransfers = ""; foreach (String delivery in deliveries) { string[] geninfo = delivery.Split('>'); MKSLtransfer transfer = new MKSLtransfer(); transfer.loadstring(geninfo[3]); string geninfo3 = geninfo[3]; //if return is true then add the returned if (transfer.transferName != transRemove.transferName) { if (newSaveCurrentTransfers == "") { newSaveCurrentTransfers = delivery; } else { newSaveCurrentTransfers = saveCurrentTransfers + "@" + delivery; } } } //add to previous transfers save string if (savePreviousTransfers == "") { savePreviousTransfers = transRemove.savestring(); } else { savePreviousTransfers = savePreviousTransfers + "@" + transRemove.savestring(); } saveCurrentTransfers = newSaveCurrentTransfers; loadTransferList(currentTransfers, saveCurrentTransfers, true); loadTransferList(previousTransfers, savePreviousTransfers, false); }
public void updateArrivalTime(MKSLtransfer trans) { double prepT = (double)PrepTime; double TpD = getValueFromStrPlanet(TimePerDistancePlanet, vessel.mainBody.name); if (1 == TpD) { TpD = TimePerDistance; } double TtfLO = getValueFromStrPlanet(TimeToFromLOPlanet, vessel.mainBody.name); if (1 == TtfLO) { TtfLO = TimeToFromLO; } if ((trans.vesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED) && (trans.vesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselTo.protoVessel.situation == Vessel.Situations.SPLASHED)) { double distance = GetDistanceBetweenPoints(trans.vesselFrom.protoVessel.latitude, trans.vesselFrom.protoVessel.longitude, trans.vesselTo.protoVessel.latitude, trans.vesselTo.protoVessel.longitude); trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + (distance * TpD); } else if ((trans.vesselFrom.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselFrom.protoVessel.situation == Vessel.Situations.SPLASHED) && (trans.vesselTo.protoVessel.situation == Vessel.Situations.ORBITING)) { trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + TtfLO; } else if ((trans.vesselFrom.protoVessel.situation == Vessel.Situations.ORBITING) && (trans.vesselTo.protoVessel.situation == Vessel.Situations.LANDED || trans.vesselTo.protoVessel.situation == Vessel.Situations.SPLASHED)) { trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + TtfLO; } else //More working code { double distance = GetDistanceBetweenPoints(trans.vesselFrom.protoVessel.latitude, trans.vesselFrom.protoVessel.longitude, trans.vesselTo.protoVessel.latitude, trans.vesselTo.protoVessel.longitude); trans.arrivaltime = Planetarium.GetUniversalTime() + prepT + (distance * TpD); } }
/// <summary> /// manipulate save lists /// </summary> /// <param name="transferlist"></param> //converts a save string into a list of MKSLtransfers public void loadTransferList(List<MKSLtransfer> transferlist,string savestring, bool longsave) { transferlist.Clear(); if (savestring == "") { return; } string[] deliveries = savestring.Split('@'); if (longsave) { for (int i = deliveries.Length - 1; i >= 0; i--) { string[] geninfo = deliveries[i].Split('>'); if (null != geninfo[3]) { deliveries[i] = geninfo[3]; } } } for (int i = deliveries.Length - 1; i >= 0; i--) { MKSLtransfer trans = new MKSLtransfer(); trans.loadstring(deliveries[i]); transferlist.Add(trans); } }