Exemple #1
0
        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));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }