public CheckList Allowed(Vessel vessel)
        {
            var checkList = new CheckList();

            checkList.Check(Valid(), "invalid mission departure mission");
            if (!checkList.CheckSucces)
            {
                return(checkList);
            }

            checkList.Check(AllowedVessel(vessel), "vessel not allowed");
            if (!checkList.CheckSucces)
            {
                return(checkList);
            }

            List <Part> departureParts = RmmUtil.GetDockedParts(vessel, RmmUtil.GetDockedPart(vessel, RmmUtil.GetVesselPart(vessel, flightIdDepartureDockPart)));

            checkList.Check(departureParts != null, "no docked vessel on docking port");
            if (!checkList.CheckSucces)
            {
                return(checkList);
            }

            checkList.Check(RmmUtil.AstronautCrewCount(departureParts) >= _mission.Departure.Crew, "not enough crew");
            int crewCapacity = 0;

            foreach (MissionLanding missionLanding in _mission.Landings)
            {
                crewCapacity += missionLanding.CrewCapacity;
            }
            checkList.Check(RmmUtil.AstronautCrewCount(departureParts) <= crewCapacity, "too many crew");

            foreach (MissionResource missionResource in _mission.Departure.Resources)
            {
                if (!_mission.Departure.Proppellants.Contains(missionResource.Name))
                {
                    continue;
                }

                checkList.Check(RmmUtil.ReadResource(departureParts, missionResource.Name) >= (missionResource.Amount * 0.99), "insufficient " + missionResource.Name);
            }

            double vesselCargoMass = 0;
            List <MissionResource> vesselResources = MissionResource.GetMissionResourceList(departureParts);

            foreach (MissionResource vesselResource in vesselResources)
            {
                if (Proppelants.Contains(vesselResource.Name))
                {
                    continue;
                }

                vesselCargoMass += RmmUtil.Mass(vesselResource.Name, vesselResource.Amount);
            }
            LoggerRmm.Debug(vesselCargoMass + " " + CargoMass);
            checkList.Check((vesselCargoMass * 0.99) <= CargoMass, "too much cargomass");

            return(checkList);
        }
        public override void OnSave(ConfigNode gameNode)
        {
            base.OnSave(gameNode);

            try
            {
                ConfigNode registeredLocations = new ConfigNode("REGISTEREDLOCATIONS");
                foreach (RegisteredDockingPort registeredDockingPort in this.RegisteredDockingPorts)
                {
                    ConfigNode dockingPortConfig = ConfigNode.CreateConfigFromObject(registeredDockingPort);
                    dockingPortConfig.name = "DOCKINGPORT";
                    registeredLocations.AddNode(dockingPortConfig);
                }

                gameNode.AddNode(registeredLocations);

                ConfigNode orderedMissions = new ConfigNode("ORDEREDMISSIONS");
                foreach (OrderedMission orderedMission in this.OrderedMissions)
                {
                    ConfigNode orderedMissionConfig = orderedMission.SaveNode();
                    orderedMissions.AddNode(orderedMissionConfig);
                }

                gameNode.AddNode(orderedMissions);
            }
            catch
            {
                LoggerRmm.Error("Rmm: saving to savefile failed");
            }
        }
        public override void OnLoad(ConfigNode gameNode)
        {
            base.OnLoad(gameNode);

            this.RegisteredDockingPorts.Clear();
            this.OrderedMissions.Clear();

            try
            {
                ConfigNode registeredLocations = gameNode.GetNode("REGISTEREDLOCATIONS");
                if (registeredLocations != null)
                {
                    foreach (ConfigNode dockingPortConfig in registeredLocations.GetNodes("DOCKINGPORT"))
                    {
                        RegisteredDockingPort dockingPort = ConfigNode.CreateObjectFromConfig <RegisteredDockingPort>(dockingPortConfig);
                        this.RegisteredDockingPorts.Add(dockingPort);
                    }
                }

                ConfigNode orderedMissions = gameNode.GetNode("ORDEREDMISSIONS");
                if (orderedMissions != null)
                {
                    foreach (ConfigNode orderedMissionConfig in orderedMissions.GetNodes("ORDEREDMISSION"))
                    {
                        OrderedMission orderedMission = OrderedMission.LoadNode(orderedMissionConfig);
                        this.OrderedMissions.Add(orderedMission);
                    }
                }
            }
            catch
            {
                LoggerRmm.Error("RMM: loading from savefile failed");
            }
        }
Exemple #4
0
        public void StartTracking(string name)
        {
            Tracking tracking = null;

            if (_startTrackingVessel != null)
            {
                foreach (Part part in _startTrackingVessel.parts)
                {
                    var trackingModule = part.Modules.OfType <RMMModule>().FirstOrDefault();
                    if (trackingModule != null)
                    {
                        tracking = trackingModule.TrackingModule;
                        break;
                    }
                }
            }

            if (_startDockingPort != null)
            {
                List <Part> dockedVesselParts = RmmUtil.GetDockedParts(_startDockingPort.vessel, _startDockingPort);
                foreach (Part part in dockedVesselParts)
                {
                    var trackingModule = part.Modules.OfType <RMMModule>().FirstOrDefault();
                    if (trackingModule != null)
                    {
                        tracking = trackingModule.TrackingModule;
                        break;
                    }
                }
            }

            if (tracking == null)
            {
                LoggerRmm.Warning("no tracking module on vessel");
                return;
            }

            if (_startTrackingVessel != null)
            {
                tracking.StartLaunchMission(name);
            }

            if (_startDockingPort != null)
            {
                tracking.StartDepartMission(name, _startDockingPort);
            }

            CancelStartTracking();
        }
        public CheckList Allowed(Vessel vessel)
        {
            var checkList = new CheckList();

            checkList.Check(Valid(), "invalid arrival mission");
            if (!checkList.CheckSucces)
            {
                return(checkList);
            }

            checkList.Check(AllowedLocation(vessel), "location not allowed");
            checkList.Check(CrewCount >= _mission.Arrival.Crew, "not enough crew");
            checkList.Check(CrewCount <= _mission.Arrival.CrewCapacity, "too many crew");
            checkList.Check(flightIdArrivalDockPart > 0, "no docking port selected");
            LoggerRmm.Debug("aa23");
            return(checkList);
        }
        public CheckList AllowedLocation(Vessel vessel)
        {
            LoggerRmm.Debug("aa3");
            var checkList = new CheckList();

            LoggerRmm.Debug("aa31");
            checkList.Check(Valid(), "invalid arrival mission");
            if (!checkList.CheckSucces)
            {
                return(checkList);
            }
            LoggerRmm.Debug("aa32");
            checkList.Check(vessel.situation == Vessel.Situations.ORBITING, "vessel not in orbit");
            checkList.Check(vessel.mainBody.name == _mission.Arrival.Body, "vessel not at " + _mission.Arrival.Body);
            checkList.Check(RmmUtil.HomeBody(_mission.Arrival.Body) || vessel.orbit.semiMajorAxis < _mission.Arrival.Orbit.semiMajorAxis * 1.3, "vessel orbit too high");
            LoggerRmm.Debug("aa33");
            return(checkList);
        }