Пример #1
0
        /// <summary>
        /// Deactivate autopilot
        /// </summary>
        internal virtual bool Deactivate()
        {
            BonVoyageModule module = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (module != null)
            {
                active            = false;
                requiredPower     = 0;
                targetLatitude    = 0;
                targetLongitude   = 0;
                distanceToTarget  = 0;
                distanceTravelled = 0;
                path = null;

                module.active            = active;
                module.targetLatitude    = targetLatitude;
                module.targetLongitude   = targetLongitude;
                module.distanceToTarget  = distanceToTarget;
                module.distanceTravelled = distanceTravelled;
                module.pathEncoded       = "";
                module.requiredPower     = requiredPower;

                BonVoyage.Instance.AutopilotActivated(false);
            }

            return(!active);
        }
Пример #2
0
        /// <summary>
        /// Activate autopilot
        /// </summary>
        internal virtual bool Activate()
        {
            if (distanceToTarget == 0)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_NoRoute", 5f)).color = Color.yellow;
                return(false);
            }

            BonVoyageModule module = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (module != null)
            {
                distanceTravelled = 0;
                lastTimeUpdated   = 0;
                active            = true;

                module.active            = active;
                module.targetLatitude    = targetLatitude;
                module.targetLongitude   = targetLongitude;
                module.distanceToTarget  = distanceToTarget;
                module.distanceTravelled = distanceTravelled;
                module.pathEncoded       = PathUtils.EncodePath(path);
                module.requiredPower     = requiredPower;

                BonVoyage.Instance.AutopilotActivated(true);
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_BonVoyage"), 5f);
            }

            return(active);
        }
Пример #3
0
        /// <summary>
        /// Activate autopilot
        /// </summary>
        internal override bool Activate()
        {
            if (vessel.situation != Vessel.Situations.SPLASHED)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_Splashed"), 5f).color = Color.yellow;
                return(false);
            }

            SystemCheck();

            // At least one engine must be on
            if (engineTestResult.maxThrustSum == 0)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_EnginesNotOnline"), 5f).color = Color.yellow;
                return(false);
            }

            // Get fuel amount
            IResourceBroker broker = new ResourceBroker();

            for (int i = 0; i < propellants.Count; i++)
            {
                propellants[i].MaximumAmountAvailable = broker.AmountAvailable(vessel.rootPart, propellants[i].Name, 1, ResourceFlowMode.ALL_VESSEL);

                if (propellants[i].MaximumAmountAvailable == 0)
                {
                    ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_NotEnoughFuel"), 5f).color = Color.yellow;
                    return(false);
                }
            }

            // Power production
            if (requiredPower > (electricPower_Solar + electricPower_Other))
            {
                // If required power is greater than total power generated, then average speed can be lowered up to 87% (square root of (1 - powerReduction))
                double powerReduction = (requiredPower - (electricPower_Solar + electricPower_Other)) / requiredPower;

                if (powerReduction > 0.75)
                {
                    ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_LowPowerShip"), 5f).color = Color.yellow;
                    return(false);
                }
            }

            BonVoyageModule module = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (module != null)
            {
                //vesselHeightFromTerrain = vessel.GetHeightFromSurface();
                vesselHeightFromTerrain = 0;

                module.averageSpeed        = averageSpeed;
                module.averageSpeedAtNight = averageSpeedAtNight;
                module.manned = manned;
                module.vesselHeightFromTerrain = vesselHeightFromTerrain;
            }

            return(base.Activate());
        }
Пример #4
0
        /// <summary>
        /// Activate autopilot
        /// </summary>
        internal override bool Activate()
        {
            if (vessel.situation != Vessel.Situations.LANDED)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_Landed"), 5f).color = Color.yellow;
                return(false);
            }

            SystemCheck();

            // No driving until at least 3 operable wheels are touching the ground - tricycles are allowed
            if ((wheelTestResult.inTheAir > 0) && (wheelTestResult.operable < 3))
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_WheelsNotTouching"), 5f).color = Color.yellow;
                return(false);
            }
            if (wheelTestResult.operable < 3)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_WheelsNotOperable"), 5f).color = Color.yellow;
                return(false);
            }

            // At least 2 wheels must be on
            if (wheelTestResult.online < 2)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_WheelsNotOnline"), 5f).color = Color.yellow;
                return(false);
            }

            // Power production
            if (requiredPower > (electricPower_Solar + electricPower_Other))
            {
                // If required power is greater then total power generated, then average speed can be lowered up to 75%
                double speedReduction = (requiredPower - (electricPower_Solar + electricPower_Other)) / requiredPower;

                if (speedReduction > 0.75)
                {
                    ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_LowPower"), 5f).color = Color.yellow;
                    return(false);
                }
            }

            BonVoyageModule module = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (module != null)
            {
                //vesselHeightFromTerrain = vessel.heightFromTerrain + wheelTestResult.maxWheelRadius;
                vesselHeightFromTerrain = vessel.radarAltitude;

                module.averageSpeed        = averageSpeed;
                module.averageSpeedAtNight = averageSpeedAtNight;
                module.manned = manned;
                module.vesselHeightFromTerrain = vesselHeightFromTerrain;
            }

            return(base.Activate());
        }
Пример #5
0
        /// <summary>
        /// Load BV controllers from the config
        /// </summary>
        internal void LoadControllers()
        {
            Vessel            vessel = null;
            ProtoPartSnapshot part   = null;

            BVControllers.Clear();

            for (int i = 0; i < FlightGlobals.Vessels.Count; i++)
            {
                vessel = FlightGlobals.Vessels[i];
                ConfigNode vesselConfigNode = new ConfigNode();
                vessel.protoVessel.Save(vesselConfigNode);
                for (int k = 0; k < vessel.protoVessel.protoPartSnapshots.Count; k++)
                {
                    part = vessel.protoVessel.protoPartSnapshots[k];
                    ProtoPartModuleSnapshot module = part.FindModule("BonVoyageModule");
                    if (module != null)
                    {
                        ConfigNode BVModule   = module.moduleValues;
                        string     vesselType = BVModule.GetValue("vesselType");
                        if (vessel.isActiveVessel)
                        {
                            BonVoyageModule m = vessel.FindPartModuleImplementing <BonVoyageModule>();
                            if (m != null)
                            {
                                vesselType = m.vesselType;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        BVController controller = null;
                        switch (vesselType)
                        {
                        case "0":     // rover
                            controller = new RoverController(vessel, BVModule);
                            break;

                        case "1":     // ship
                            controller = new ShipController(vessel, BVModule);
                            break;

                        default:     // default to rover
                            controller = new RoverController(vessel, BVModule);
                            break;
                        }
                        BVControllers.Add(controller);
                        break;
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Active vessel changed, deal with it.
        /// </summary>
        /// <param name="vessel">Vessel.</param>
        public void onVesselChange(Vessel vessel)
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            currentModule = vessel.FindPartModuleImplementing <BonVoyageModule> ();
            if (currentModule != null)
            {
                currentModule.SystemCheck();
                UpdateWayPoints();
                if (currentModule.isActive)
                {
                    InputLockManager.SetControlLock(lockMask, "BonVoyageInputLock");
                    return;
                }
            }
            InputLockManager.RemoveControlLock("BonVoyageInputLock");
        }
Пример #7
0
        /// <summary>
        /// Activate autopilot
        /// </summary>
        internal override bool Activate()
        {
            if (vessel.situation != Vessel.Situations.LANDED && vessel.situation != Vessel.Situations.SPLASHED)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_Landed_Splashed"), 5f).color = Color.yellow;
                return(false);
            }

            SystemCheck();

            BonVoyageModule module = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (module != null)
            {
                vesselHeightFromTerrain = vessel.radarAltitude;

                module.averageSpeed            = averageSpeed;
                module.vesselHeightFromTerrain = vesselHeightFromTerrain;
            }

            return(base.Activate());
        }
Пример #8
0
        /// <summary>
        /// Vessel changed. Refresh vessel list in the main window if it's still visible and hide control window (scene was not switched)
        /// </summary>
        /// <param name="vessel"></param>
        public void OnVesselChange(Vessel vessel)
        {
            if (MainView != null)
            {
                MainModel.RefreshVesselListLayout();
            }
            if (controlViewVisible)
            {
                ToggleControlWindow();
            }

            BonVoyageModule currentModule = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (currentModule != null)
            {
                if (currentModule.active)
                {
                    InputLockManager.SetControlLock(lockMask, "BonVoyageInputLock");
                    return;
                }
            }
            InputLockManager.RemoveControlLock("BonVoyageInputLock");
        }
Пример #9
0
        /// <summary>
        /// Active vessel changed, deal with it.
        /// </summary>
        /// <param name="vessel">Vessel.</param>
        public void onVesselChange(Vessel vessel)
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            currentModule = vessel.FindPartModuleImplementing <BonVoyageModule> ();
//			if (wayPoints != null)
//				wayPoints.Clear ();
            if (currentModule != null)
            {
                currentModule.SystemCheck();
                UpdateWayPoints();
//				wayPoints = PathUtils.DecodePath (currentModule.pathEncoded, currentModule.vessel.mainBody);
                if (currentModule.isActive)
                {
                    InputLockManager.SetControlLock(lockMask, "BonVoyageInputLock");
                    return;
                }
            }

//			currentModule = null;
//			foreach (var rover in activeRovers)
//			{
//				if (rover.vessel == vessel)
////					ControlThis (rover.vessel.FindPartModuleImplementing<BonVoyageModule> (), false);
//					currentModule = rover.vessel.FindPartModuleImplementing<BonVoyageModule>();
//
//				if (rover.vessel == vessel && rover.bvActive)
//				{
//					InputLockManager.SetControlLock(lockMask, "BonVoyageInputLock");
//					return;
//				}
//			}
            InputLockManager.RemoveControlLock("BonVoyageInputLock");
        }
Пример #10
0
        /// <summary>
        /// Get speed penalty for unmanned ship based on tech available
        /// </summary>
        /// <returns></returns>
        internal int GetUnmannedSpeedPenalty()
        {
            BonVoyageModule module = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (module != null)
            {
                switch (module.techLevel)
                {
                case 2:     // unmannedTech
                    return(60);

                case 3:     // automation
                    return(40);

                case 4:     // artificialIntelligence
                    return(20);

                default:     // no tech
                    return(80);
                }
            }

            return(80);
        }
Пример #11
0
        /// <summary>
        /// Activate autopilot
        /// </summary>
        internal override bool Activate()
        {
            if (vessel.situation != Vessel.Situations.LANDED && vessel.situation != Vessel.Situations.PRELAUNCH)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_Landed"), 5f).color = Color.yellow;
                return(false);
            }

            SystemCheck();

            // No driving until at least 3 operable wheels are touching the ground - tricycles are allowed
            if ((wheelTestResult.inTheAir > 0) && (wheelTestResult.operable < 3))
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_WheelsNotTouching"), 5f).color = Color.yellow;
                return(false);
            }
            if (wheelTestResult.operable < 3)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_WheelsNotOperable"), 5f).color = Color.yellow;
                return(false);
            }

            // At least 2 wheels must be on
            if (wheelTestResult.online < 2)
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_WheelsNotOnline"), 5f).color = Color.yellow;
                return(false);
            }

            // Get fuel amount if fuel cells are used
            if (fuelCells.Use && !CheatOptions.InfinitePropellant)
            {
                IResourceBroker broker = new ResourceBroker();
                var             iList  = fuelCells.InputResources;
                for (int i = 0; i < iList.Count; i++)
                {
                    iList[i].MaximumAmountAvailable = broker.AmountAvailable(vessel.rootPart, iList[i].Name, 1, ResourceFlowMode.ALL_VESSEL);

                    if (iList[i].MaximumAmountAvailable == 0)
                    {
                        ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_NotEnoughFuel"), 5f).color = Color.yellow;
                        return(false);
                    }
                }
            }

            // Power production
            if (requiredPower > (electricPower_Solar + electricPower_Other))
            {
                // If required power is greater than total power generated, then average speed can be lowered up to 75%
                double speedReduction = (requiredPower - (electricPower_Solar + electricPower_Other)) / requiredPower;

                if (speedReduction > 0.75)
                {
                    ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_BV_Warning_LowPowerRover"), 5f).color = Color.yellow;
                    return(false);
                }
            }

            BonVoyageModule module = vessel.FindPartModuleImplementing <BonVoyageModule>();

            if (module != null)
            {
                vesselHeightFromTerrain = vessel.radarAltitude;

                module.averageSpeed        = averageSpeed;
                module.averageSpeedAtNight = averageSpeedAtNight;
                module.manned = manned;
                module.vesselHeightFromTerrain = vesselHeightFromTerrain;
            }

            return(base.Activate());
        }