public override void OnStart(PartModule.StartState state)
        {
            try
            {
                attachedRCS         = this.part.FindModuleImplementing <ModuleRCS>();
                attachedModuleRCSFX = attachedRCS as FNModuleRCSFX;

                if (!isInitialised)
                {
                    if (attachedModuleRCSFX != null)
                    {
                        useLeverEnabled        = attachedModuleRCSFX.useLever;
                        precisionFactorLimiter = attachedModuleRCSFX.precisionFactor * 100;
                        fullThrustMinLimiter   = attachedModuleRCSFX.fullThrustMin * 100;
                        fullThrustEnabled      = attachedModuleRCSFX.fullThrust;
                        useThrotleEnabled      = attachedModuleRCSFX.useThrottle;
                    }
                }

                if (attachedModuleRCSFX != null)
                {
                    attachedModuleRCSFX.Fields["RCS"].guiActive         = true;
                    attachedModuleRCSFX.Fields["enableYaw"].guiActive   = true;
                    attachedModuleRCSFX.Fields["enablePitch"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableRoll"].guiActive  = true;
                    attachedModuleRCSFX.Fields["enableX"].guiActive     = true;
                    attachedModuleRCSFX.Fields["enableY"].guiActive     = true;
                    attachedModuleRCSFX.Fields["enableZ"].guiActive     = true;
                    attachedModuleRCSFX.fullThrust      = fullThrustEnabled;
                    attachedModuleRCSFX.fullThrustMin   = fullThrustMinLimiter / 100;
                    attachedModuleRCSFX.useLever        = useLeverEnabled;
                    attachedModuleRCSFX.precisionFactor = precisionFactorLimiter / 100;
                }

                // old legacy stuff
                if (baseThrust == 0 && maxThrust > 0)
                {
                    baseThrust = maxThrust;
                }

                if (partMass == 0)
                {
                    partMass = part.mass;
                }

                if (String.IsNullOrEmpty(displayName))
                {
                    displayName = part.partInfo.title;
                }

                String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
                this.resources_to_supply = resources_to_supply;

                oldThrustLimiter  = thrustLimiter;
                oldPowerEnabled   = powerEnabled;
                efficencyModifier = (float)g0 * 0.5f / 1000.0f / efficency;
                efficencyStr      = (efficency * 100).ToString() + "%";

                if (!String.IsNullOrEmpty(AnimationName))
                {
                    rcsStates = SetUpAnimation(AnimationName, this.part);
                }

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);

                delayedVerificationPropellant = true;
                // find correct fuel mode index
                if (!String.IsNullOrEmpty(fuel_mode_name))
                {
                    Debug.Log("ElectricRCSController OnStart loaded fuelmode " + fuel_mode_name);
                    Current_propellant = _propellants.FirstOrDefault(p => p.PropellantName == fuel_mode_name);
                }
                if (Current_propellant != null && _propellants.Contains(Current_propellant))
                {
                    fuel_mode = _propellants.IndexOf(Current_propellant);
                    Debug.Log("ElectricRCSController OnStart index of fuelmode " + Current_propellant.PropellantGUIName + " = " + fuel_mode);
                }

                base.OnStart(state);

                Fields["electricalPowerConsumptionStr"].guiActive = showConsumption;
            }
            catch (Exception e)
            {
                Debug.LogError("ElectricRCSController OnStart Error: " + e.Message);
                throw;
            }
        }
Example #2
0
 public override void OnStart(PartModule.StartState state)
 {
     Log.Info("ModuleKrKerbalParachute.OnStart, name:" + kerbalName);
     closedDrag = part.maximum_drag;
 }
 public override void OnStart(PartModule.StartState state)
 {
     predictor = core.GetComputerModule <MechJebModuleLandingPredictions>();
     autopilot = core.GetComputerModule <MechJebModuleLandingAutopilot>();
 }
Example #4
0
 public override void OnStart(PartModule.StartState state)
 {
     FindAnimations();
 }
        public override void OnStart(PartModule.StartState state)
        {
            if (state != StartState.Editor)
            {
                started = true;
            }
            else
            {
                started = false;
            }
            // Get moduleEngines
            PartModuleList pml = this.part.Modules;

            for (int i = 0; i < pml.Count; i++)
            {
                PartModule curModule = pml.GetModule(i);
                engine = curModule.GetComponent <ModuleEnginesFX>();
            }

            if (engine != null)
            {
                Debug.Log("NFPP: Engine Check Passed");
            }

            foreach (Propellant prop in engine.propellants)
            {
                if (prop.name == FuelName)
                {
                    fuelPropellant = prop;
                }
                if (prop.name == "ElectricCharge")
                {
                    ecPropellant = prop;
                }
            }



            if (UseDirectThrottle)
            {
                ChangeIspAndThrust(engine.requestedThrottle);
            }
            else
            {
                ChangeIspAndThrust(CurThrustSetting / 100f);
            }

            if (state != StartState.Editor)
            {
                SetupVariableEngines();
            }


            CalculateCurves();

            Debug.Log("NFPP: Variable ISP engine setup complete");
            if (UseDirectThrottle)
            {
                Debug.Log("NFPP: Using direct throttle method");
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            var range = (UI_FloatRange)this.Fields["CurrentSafetyOverride"].uiControlEditor;

            range.minValue = 0f;
            range.maxValue = MaximumTemperature;

            range          = (UI_FloatRange)this.Fields["CurrentSafetyOverride"].uiControlFlight;
            range.minValue = 0f;
            range.maxValue = MaximumTemperature;

            throttleCurve = new FloatCurve();
            throttleCurve.Add(0, 0, 0, 0);
            throttleCurve.Add(50, 20, 0, 0);
            throttleCurve.Add(100, 100, 0, 0);

            if (UseStagingIcon)
            {
                //this.part.stackIcon.CreateIcon();
                //this.part.stackIcon.SetIcon(DefaultIcons.FUEL_TANK);
            }
            else
            {
                Utils.LogWarn("Fission Reactor: Staging Icon Disabled!");
            }

            if (FirstLoad)
            {
                this.CurrentSafetyOverride = this.CriticalTemperature;
                FirstLoad = false;
            }

            if (state != StartState.Editor)
            {
                core = this.GetComponent <ModuleCoreHeat>();
                if (core == null)
                {
                    Utils.LogError("Fission Reactor: Could not find core heat module!");
                }

                SetupResourceRatios();
                // Set up staging icon heat bar

                if (UseStagingIcon)
                {
                    infoBox = this.part.stackIcon.DisplayInfo();
                }

                if (OverheatAnimation != "")
                {
                    overheatStates = Utils.SetUpAnimation(OverheatAnimation, this.part);
                }

                if (FollowThrottle)
                {
                    reactorEngine = this.GetComponent <FissionEngine>();
                }

                if (UseForcedActivation)
                {
                    this.part.force_activate();
                }
            }
            else
            {
                //this.CurrentSafetyOverride = this.NominalTemperature;
            }


            base.OnStart(state);
        }
Example #7
0
        /// <summary>Configures the part for editor and flight.</summary>
        /// <remarks>
        /// Most importantly, it grabs a list of wheel colliders to be
        /// used later. Also configures visibility of tweakables, figures
        /// out the parts orientation and position in the vessel to calculate
        /// steering angles and sets some defaults.
        /// </remarks>
        /// <param name="state">Start state. Set by KSP to declare the scene it initializes this class in.</param>
        public override void OnStart(PartModule.StartState state)          //when started
        {
            base.OnStart(state);

            fSusInc = KFPersistenceManager.suspensionIncrement;

            CustomResourceTextSetup();

            fColliderMass = 10;

            var partOrientationForward = new Vector3(0f, 0f, 0f);
            var partOrientationRight   = new Vector3(0f, 0f, 0f);
            var partOrientationUp      = new Vector3(0f, 0f, 0f);

            if (!string.Equals(orientationObjectName, "Default"))
            {
                                #if DEBUG
                KFLog.Warning("Setting transformed part orientation.");
                                #endif

                partOrientationUp      = transform.Search(orientationObjectName).up;
                partOrientationForward = transform.Search(orientationObjectName).forward;
                partOrientationRight   = transform.Search(orientationObjectName).right;
            }
            else
            {
                                #if DEBUG
                KFLog.Warning("Setting default part orientation.");
                                #endif

                partOrientationUp      = part.transform.up;
                partOrientationForward = part.transform.forward;
                partOrientationRight   = part.transform.right;
            }

            if (hasRetractAnimation)
            {
                foreach (ModuleAnimateGeneric ma in part.FindModulesImplementing <ModuleAnimateGeneric>())
                {
                    ma.Actions["ToggleAction"].active   = false;
                    ma.Events["Toggle"].guiActive       = false;
                    ma.Events["Toggle"].guiActiveEditor = false;
                }
                SetupAnimation();
            }

            //disables tweakables if being used on a passive part (mecannum wheel or skid, for example)
            if (disableTweakables)
            {
                KFLog.Warning("Disabling tweakables.");
                foreach (BaseField k in Fields)
                {
                                        #if DEBUG
                    KFLog.Log(string.Format("Found {0}", k.guiName));
                                        #endif

                    k.guiActive       = false;
                    k.guiActiveEditor = false;
                }
                foreach (BaseAction a in Actions)
                {
                                        #if DEBUG
                    KFLog.Log(string.Format("Found {0}", a.guiName));
                                        #endif

                    a.active = false;
                }
                foreach (BaseEvent e in Events)
                {
                                        #if DEBUG
                    KFLog.Log(string.Format("Found {0}", e.guiName));
                                        #endif

                    e.active = false;
                }
            }

            if (fStartRetracted)
            {
                isRetracted = true;
            }

            if (!isRetracted)
            {
                fCurrentTravel = fRideHeight;                 //set up correct values from persistence
            }
            else
            {
                fCurrentTravel = 0f;
            }

                        #if DEBUG
            KFLog.Log(string.Format("\"appliedRideHeight\" = {0}", appliedRideHeight));
                        #endif

            // Disable retract tweakables if retract option not specified.
            if (HighLogic.LoadedSceneIsEditor && !hasRetract)
            {
                part.DisableAnimateButton();
                Actions["AGToggleDeployed"].active       = false;
                Actions["Deploy"].active                 = false;
                Actions["Retract"].active                = false;
                Fields["startRetracted"].guiActiveEditor = false;
            }

            if (HighLogic.LoadedSceneIsFlight && (!Equals(vessel.vesselType, VesselType.Debris) && !Equals(vessel.vesselType, VesselType.EVA)))
            {
                if (isDustEnabled)
                {
                    _dustFX = part.gameObject.GetComponent <KFDustFX>();
                    if (Equals(_dustFX, null))
                    {
                        _dustFX = part.gameObject.AddComponent <KFDustFX>();
                        _dustFX.OnStart(state);
                        _dustFX.tweakScaleFactor = tweakScaleCorrector;
                    }
                }

                fAppliedTravel = fRideHeight / 100f;
                StartCoroutine(StartupStuff());
                maxRPM         /= tweakScaleCorrector;
                fStartRetracted = false;
                if (!hasRetract)
                {
                    part.DisableAnimateButton();
                }

                // Wheel steering ratio setup
                rootIndexLong = WheelUtils.GetRefAxis(part.transform.forward, vessel.rootPart.transform);
                rootIndexLat  = WheelUtils.GetRefAxis(part.transform.right, vessel.rootPart.transform);
                rootIndexUp   = WheelUtils.GetRefAxis(part.transform.up, vessel.rootPart.transform);

                fSteeringRatio = WheelUtils.SetupRatios(rootIndexLong, part, vessel, fGroupNumber);
                GetControlAxis();

                if (fTorque > 2f)
                {
                    fTorque /= 100f;
                }

                wheelCount = 0;

                foreach (WheelCollider wheelCollider in part.GetComponentsInChildren <WheelCollider>())
                {
                    wheelCount++;
                    JointSpring userSpring = wheelCollider.suspensionSpring;
                    userSpring.spring = fSpringRate * tweakScaleCorrector;
                    userSpring.damper = fDamperRate * tweakScaleCorrector;
                    wheelCollider.suspensionSpring   = userSpring;
                    wheelCollider.suspensionDistance = wheelCollider.suspensionDistance * fAppliedTravel;
                    wcList.Add(wheelCollider);
                    suspensionDistance.Add(wheelCollider.suspensionDistance);
                    wheelCollider.enabled          = true;
                    wheelCollider.gameObject.layer = 27;
                }

                if (brakesApplied)
                {
                    fBrakeTorque = brakingTorque;                     // Were the brakes left applied?
                }
                if (isRetracted)
                {
                    RetractDeploy("retract");
                }
                isReady = true;
            }
            DestroyBounds();
            SetupWaterSlider();

            GameEvents.onGamePause.Add(OnPause);
            GameEvents.onGameUnpause.Add(OnUnpause);
        }
Example #8
0
 public override void OnStart(PartModule.StartState state)
 {
     SEP_Utilities.onWindowSpawn.Add(onWindowSpawn);
     SEP_Utilities.onWindowDestroy.Add(onWindowDestroy);
 }
Example #9
0
 public override void OnStart(PartModule.StartState state)
 {
     autopilot = core.GetComputerModule <MechJebModuleRoverController>();
 }
Example #10
0
 /// <inheritdoc/>
 public override void OnStart(PartModule.StartState state)
 {
     base.OnStart(state);
     InitStartState();
     RegisterGameEventListener(GameEvents.onPartDeCoupleComplete, OnPartDeCoupleCompleteEvent);
 }
Example #11
0
 protected override void hideEditorGUI(PartModule.StartState state)
 {
     base.hideEditorGUI(state);
 }
Example #12
0
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);
            flameout = false;
            SetUnflameout();
            // set initial params
            engineTemp      = 288.15d;
            currentThrottle = 0f;

            if (ambientTherm == null)
            {
                ambientTherm = new EngineThermodynamics();
            }
            if (inletTherm == null)
            {
                inletTherm = new EngineThermodynamics();
            }

            // Get emissives
            emissiveAnims = new List <ModuleAnimateEmissive>();
            int mCount = part.Modules.Count;

            for (int i = 0; i < mCount; ++i)
            {
                if (part.Modules[i] is ModuleAnimateEmissive)
                {
                    emissiveAnims.Add(part.Modules[i] as ModuleAnimateEmissive);
                }
            }

            FitEngineIfNecessary();

            HideEventsActions();
            // Set up ours
            Events["vShutdown"].active = false;
            Events["vActivate"].active = false;

            if (state != StartState.PreLaunch)
            {
                if (EngineIgnited)
                {
                    if (allowShutdown)
                    {
                        Events["vShutdown"].active = true;
                    }
                    else
                    {
                        Events["vShutdown"].active = false;
                    }
                    Events["vActivate"].active = false;
                }
                else
                {
                    Events["vShutdown"].active = false;
                    if (!allowRestart && engineShutdown)
                    {
                        Events["vActivate"].active = false;
                    }
                    else
                    {
                        Events["vActivate"].active = true;
                    }
                }
            }
        }
Example #13
0
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            emptyAnimation = part.FindModelAnimators(animationName)[0];
            anim           = emptyAnimation[animationName];

            //set max and min for wheel height
            var wheelHeightTweakable = (UI_FloatRange)Fields["wheelHeight"].uiControlEditor;

            wheelHeightTweakable.maxValue = maxHeight;
            wheelHeightTweakable.minValue = minHeight;

            //set max wheelAngle tweakable
            var wheelAngleTweakable = (UI_FloatRange)Fields["wheelAngle"].uiControlEditor;

            wheelAngleTweakable.maxValue = maxWheelAngle;
            wheelAngleTweakable.minValue = 0;

            //set min/max leg tilt tweakable
            var tiltAngleTweakable = (UI_FloatRange)Fields["legAngle"].uiControlEditor;

            tiltAngleTweakable.maxValue = maxTilt;
            tiltAngleTweakable.minValue = minTilt;

            //set max brakeTorque tweakable
            var brakeTorqueTweakable = (UI_FloatRange)Fields["brakeTorque"].uiControlEditor;

            brakeTorqueTweakable.maxValue = maxBrakeTorque;



            //tiltTransforms
            tiltTransform              = part.FindModelTransform(tiltTransformName);
            tiltTargetTransform        = part.FindModelTransform(tiltTargetTransformName);
            tiltRetractTargetTransform = part.FindModelTransform(tiltRetractTargetTransformName);

            //deployTransforms
            deployTransform        = part.FindModelTransform(deployTransformName);
            deployTargetTransform  = part.FindModelTransform(deployTargetTransformName);
            retractTargetTransform = part.FindModelTransform(retractTargetTransformName);

            //wheelTransforms
            wheelHingeTransform           = part.FindModelTransform(wheelHingeTransformName);
            retractedWheelTargetTransform = part.FindModelTransform(retractedWheelTargetTransformName);
            deployedWheelTargetTransform  = part.FindModelTransform(deployedWheelTargetTransformName);

            wheelColliderTarget          = part.FindModelTransform(wheelColliderTargetName);
            wheelColliderHolderTransform = part.FindModelTransform("wheelColliderHolder");

            wheelAlignmentTransform = part.FindModelTransform(wheelAlignmentTransformName);

            if (canSteer)
            {
                steeringTransform = part.FindModelTransform(steeringTransformName);
            }

            initialHeight = Vector3.Distance(deployedWheelTargetTransform.localPosition, retractedWheelTargetTransform.localPosition);

            SetUpDoors();

            if (animSpeedP > 0)
            {
                animNormTimeP = 1;
            }
            else if (animSpeedP < 0)
            {
                animNormTimeP = 0;
            }


            anim.normalizedTime = animNormTimeP;

            float animNormTime = 1 - animNormTimeP;

            animNormTime = Mathf.Clamp01(animNormTime);

            if (animNormTime >= 1)
            {
                CurrentState = GearStates.Deployed;
            }
            else if (animNormTime <= 0)
            {
                CurrentState = GearStates.Retracted;
            }
            else if (anim.speed < 0)
            {
                CurrentState = GearStates.Deploying;
            }
            else
            {
                CurrentState = GearStates.Retracting;
            }

            if (posAndRotSaved)
            {
                LoadPosAndRot();
            }

            if (CurrentState == GearStates.Deployed || CurrentState == GearStates.Deploying)
            {
                wheelHingeTransform.localPosition = deployedWheelTargetTransform.localPosition;
                wheelHingeTransform.localRotation = deployedWheelTargetTransform.localRotation;
                tiltTransform.localRotation       = tiltTargetTransform.localRotation;
                deployTransform.localRotation     = deployTargetTransform.localRotation;
            }
            else
            {
                wheelHingeTransform.localPosition = retractedWheelTargetTransform.localPosition;
                wheelHingeTransform.localRotation = retractedWheelTargetTransform.localRotation;
                tiltTransform.localRotation       = tiltRetractTargetTransform.localRotation;
                deployTransform.localRotation     = retractTargetTransform.localRotation;
            }

            part.OnEditorAttach += new Callback(OnEditorAttach);


            //fs wheel overrides
            fsWheel             = part.FindModuleImplementing <FSBDwheel>();
            fsWheel.brakeTorque = brakeTorque;


            //scale
            transform.localScale = algScale * Vector3.one;

            if (part.FindModelTransform(boundsCollider) != null)
            {
                DestroyImmediate(part.FindModelTransform(boundsCollider).gameObject);
            }

            if (!HighLogic.LoadedSceneIsEditor)
            {
                showSettings = false;
            }
            RefreshTweakables();

            wheelColliders = part.FindModelComponents <WheelCollider>();

            previousState = CurrentState;
            part.SendMessage("GeometryPartModuleRebuildMeshData");

            if (state != StartState.Editor)
            {
                part.mass = baseMass * Mathf.Pow(algScale, 3);
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            Actions["ToggleToggleResourceAction"].guiName = Events["ToggleResource"].guiName = String.Format("Toggle Resource");

            if (state == StartState.Editor)
            {
                return;
            }

            this.part.force_activate();

            // verify if body has atmosphere at all
            if (!vessel.mainBody.atmosphere)
            {
                return;
            }

            // verify scoop was enabled
            if (!scoopIsEnabled)
            {
                return;
            }

            // verify a timestamp is available
            if (last_active_time == 0)
            {
                return;
            }

            // verify any power was avaialble in previous save
            if (last_power_percentage < 0.01)
            {
                return;
            }

            // verify altitude is not too high
            if (vessel.altitude > (PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody) * PluginHelper.MaxAtmosphericAltitudeMult))
            {
                ScreenMessages.PostScreenMessage("Vessel is too high for resource accumulation", 10, ScreenMessageStyle.LOWER_CENTER);
                return;
            }

            // verify altitude is not too low
            if (vessel.altitude < (PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)))
            {
                ScreenMessages.PostScreenMessage("Vessel is too low for resource accumulation", 10, ScreenMessageStyle.LOWER_CENTER);
                return;
            }

            // verify eccentricity
            if (vessel.orbit.eccentricity > 0.1)
            {
                string message = "Eccentricity of " + vessel.orbit.eccentricity.ToString("0.0000") + " is too High for resource accumulations";
                ScreenMessages.PostScreenMessage(message, 10.0f, ScreenMessageStyle.LOWER_CENTER);
                return;
            }

            // verify that an electric or Thermal engine is available with high enough ISP
            var highIspEngine = part.vessel.parts.Find(p =>
                                                       p.FindModulesImplementing <ElectricEngineControllerFX>().Any(e => e.baseISP > 4200) ||
                                                       p.FindModulesImplementing <ThermalNozzleController>().Any(e => e.AttachedReactor.CoreTemperature > 40000));

            if (highIspEngine == null)
            {
                ScreenMessages.PostScreenMessage("No engine available, with high enough Isp and propelant switch ability to compensate for atmospheric drag", 10, ScreenMessageStyle.LOWER_CENTER);
                return;
            }

            // calcualte time past since last frame
            double time_diff = (Planetarium.GetUniversalTime() - last_active_time) * 55;

            // scoop athmosphere for entire durration
            ScoopAthmosphere(time_diff, true);
        }
 public override void OnStart(PartModule.StartState state)
 {
     base.OnStart(state);
     this.rcs = base.part.FindModuleImplementing <ModuleRCS>();
 }
Example #16
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    upgradePartModule();
                }
                return;
            }

            if (isupgraded)
            {
                upgradePartModule();
            }
            else
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    hasrequiredupgrade = true;
                }
            }

            // update gui names
            Events["BeginResearch"].guiName = beginResearchName;

            reprocessor         = new NuclearFuelReprocessor(part);
            antimatterGenerator = new AntimatterGenerator(part, 1, PartResourceLibrary.Instance.GetDefinition(InterstellarResourcesConfiguration.Instance.Antimatter));

            part.force_activate();

            anim  = part.FindModelAnimators(animName1).FirstOrDefault();
            anim2 = part.FindModelAnimators(animName2).FirstOrDefault();
            if (anim != null && anim2 != null)
            {
                anim[animName1].layer  = 1;
                anim2[animName2].layer = 1;
                if (IsEnabled)
                {
                    //anim [animName1].normalizedTime = 1f;
                    //anim2 [animName2].normalizedTime = 1f;
                    //anim [animName1].speed = -1f;
                    //anim2 [animName2].speed = -1f;
                    anim.Blend(animName1, 1, 0);
                    anim2.Blend(animName2, 1, 0);
                }
                else
                {
                    //anim [animName1].normalizedTime = 0f;
                    //anim2 [animName2].normalizedTime = 0f;
                    //anim [animName1].speed = 1f;
                    //anim2 [animName2].speed = 1f;
                    //anim.Blend (animName1, 0, 0);global_rate_multipliers
                    //anim2.Blend (animName2, 0, 0);
                    play_down = false;
                }
                //anim.Play ();
                //anim2.Play ();
            }

            if (IsEnabled && last_active_time != 0)
            {
                double global_rate_multipliers = 1;
                crew_capacity_ratio     = ((float)(part.protoModuleCrew.Count)) / ((float)part.CrewCapacity);
                global_rate_multipliers = global_rate_multipliers * crew_capacity_ratio;

                if (active_mode == 0) // Science persistence
                {
                    var time_diff                 = Planetarium.GetUniversalTime() - last_active_time;
                    var altitude_multiplier       = Math.Max((vessel.altitude / (vessel.mainBody.Radius)), 1);
                    var kerbalResearchSkillFactor = part.protoModuleCrew.Sum(proto_crew_member => GetKerbalScienceFactor(proto_crew_member) / 2f);

                    double science_to_increment = kerbalResearchSkillFactor * GameConstants.baseScienceRate * time_diff
                                                  / PluginHelper.SecondsInDay * electrical_power_ratio * global_rate_multipliers * PluginHelper.getScienceMultiplier(vessel)
                                                  / (Math.Sqrt(altitude_multiplier));

                    science_to_increment = (double.IsNaN(science_to_increment) || double.IsInfinity(science_to_increment)) ? 0 : science_to_increment;
                    science_to_add      += science_to_increment;
                }
                else if (active_mode == 2) // Antimatter persistence
                {
                    var deltaTime = Planetarium.GetUniversalTime() - last_active_time;

                    var electrical_power_provided_in_Megajoules = electrical_power_ratio * global_rate_multipliers * powerReqMult * PluginHelper.BaseAMFPowerConsumption * deltaTime;

                    antimatterGenerator.Produce(electrical_power_provided_in_Megajoules);
                }
            }
        }
Example #17
0
 public override void OnStart(PartModule.StartState state)
 {
     initializeData();
     assignResourcesToPart(false);
     brandNewPart = false;
 }
Example #18
0
 public virtual void OnStart(PartModule.StartState state)
 {
 }
Example #19
0
 public override void OnStart(PartModule.StartState state)
 {
     lastUpdateTime = Time.time;
     this.part.force_activate();
 }
Example #20
0
        public override void OnStart(PartModule.StartState state)
        {
            onStop = new EventData <float>("SIGINT_" + part.flightID + "_OnStop");
            onMove = new EventData <float, float>("SIGINT_" + part.flightID + "_OnMove");

            assignTransforms();
            assignObjects();

            base.OnStart(state);

            if (scienceExp != null)
            {
                sitMask = (int)scienceExp.situationMask;
                bioMask = sitMask;
            }

            if (anim != null && anim[animationName] != null)
            {
                scalarStep = 1 / anim[animationName].length;
            }

            Events["fixPart"].guiName = "Fix Dish";

            if (useFairings)
            {
                fairings = part.FindModulesImplementing <ModuleJettison>();

                if (fairings.Count > 0)
                {
                    if (part.stagingIcon == string.Empty && overrideStagingIconIfBlank)
                    {
                        part.stagingIcon = DefaultIcons.FUEL_TANK.ToString();
                    }

                    foreach (ModuleJettison j in fairings)
                    {
                        if (j == null)
                        {
                            continue;
                        }

                        j.Actions["JettisonAction"].active      = false;
                        j.Events["Jettison"].active             = false;
                        j.Events["Jettison"].guiActiveUnfocused = false;
                        j.Events["Jettison"].guiActiveEditor    = false;
                    }

                    Events["jettison"].active        = !IsDeployed;
                    Actions["jettisonAction"].active = !IsDeployed;
                }
            }
            else
            {
                Events["jettison"].active        = false;
                Actions["jettisonAction"].active = false;
            }

            if (state == StartState.Editor)
            {
                return;
            }

            if (IsDeployed)
            {
                deployScalar = 1;
                scalar       = 1;
                return;
            }

            if (useFairings)
            {
                if (fairings.Count > 0)
                {
                    foreach (ModuleJettison j in fairings)
                    {
                        if (j == null)
                        {
                            continue;
                        }

                        if (j.isJettisoned)
                        {
                            return;
                        }
                    }
                }
            }

            setTransformState(false);
        }
Example #21
0
        public override void OnStart(PartModule.StartState state)
        {
            exoticResourceDefinition = PartResourceLibrary.Instance.GetDefinition(InterstellarResourcesConfiguration.Instance.ExoticMatter);
            var exoticMatterResource = part.Resources[InterstellarResourcesConfiguration.Instance.ExoticMatter];

            // reset Exotic Matter Capacity
            if (exoticMatterResource != null)
            {
                part.mass = partMass;
                var ratio = Math.Min(1, Math.Max(0, exoticMatterResource.amount / exoticMatterResource.maxAmount));
                exoticMatterResource.maxAmount = 0.001;
                exoticMatterResource.amount    = exoticMatterResource.maxAmount * ratio;
            }

            InstanceID = GetInstanceID();

            if (IsSlave)
            {
                UnityEngine.Debug.Log("KSPI - AlcubierreDrive Slave " + InstanceID + " Started");
            }
            else
            {
                UnityEngine.Debug.Log("KSPI - AlcubierreDrive Master " + InstanceID + " Started");
            }

            if (!String.IsNullOrEmpty(AnimationName))
            {
                animationState = SetUpAnimation(AnimationName, this.part);
            }

            try
            {
                Events["StartCharging"].active       = !IsSlave;
                Events["StopCharging"].active        = !IsSlave;
                Events["ActivateWarpDrive"].active   = !IsSlave;
                Events["DeactivateWarpDrive"].active = !IsSlave;
                Events["ToggleWarpSpeedUp"].active   = !IsSlave;
                Events["ToggleWarpSpeedDown"].active = !IsSlave;
                Events["ReduceWarpPower"].active     = !IsSlave;

                Fields["exotic_power_required"].guiActive     = !IsSlave;
                Fields["WarpEngineThrottle"].guiActive        = !IsSlave;
                Fields["maximumAllowedWarpThrotle"].guiActive = !IsSlave;
                Fields["warpToMassRatio"].guiActive           = !IsSlave;
                Fields["vesselTotalMass"].guiActive           = !IsSlave;
                Fields["DriveStatus"].guiActive = !IsSlave;
                Fields["minPowerRequirementForLightSpeed"].guiActive            = !IsSlave;
                Fields["currentPowerRequirementForWarp"].guiActive              = !IsSlave;
                Fields["sumOfAlcubierreDrives"].guiActive                       = !IsSlave;
                Fields["PowerRequirementForMaximumAllowedLightSpeed"].guiActive = !IsSlave;

                Actions["StartChargingAction"].guiName       = Events["StartCharging"].guiName = String.Format("Start Charging");
                Actions["StopChargingAction"].guiName        = Events["StopCharging"].guiName = String.Format("Stop Charging");
                Actions["ToggleChargingAction"].guiName      = String.Format("Toggle Charging");
                Actions["ActivateWarpDriveAction"].guiName   = Events["ActivateWarpDrive"].guiName = String.Format("Activate Warp Drive");
                Actions["DeactivateWarpDriveAction"].guiName = Events["DeactivateWarpDrive"].guiName = String.Format("Deactivate Warp Drive");
                Actions["ToggleWarpSpeedUpAction"].guiName   = Events["ToggleWarpSpeedUp"].guiName = String.Format("Warp Speed (+)");
                Actions["ToggleWarpSpeedDownAction"].guiName = Events["ToggleWarpSpeedDown"].guiName = String.Format("Warp Speed (-)");

                minimum_selected_factor = engine_throtle.ToList().IndexOf(engine_throtle.First(w => w == 1f));
                if (selected_factor == -1)
                {
                    selected_factor = minimum_selected_factor;
                }

                if (state == StartState.Editor)
                {
                    return;
                }

                if (!IsSlave)
                {
                    UnityEngine.Debug.Log("KSPI - AlcubierreDrive Create Slaves");
                    alcubierreDrives = part.vessel.FindPartModulesImplementing <AlcubierreDrive>();
                    foreach (var drive in alcubierreDrives)
                    {
                        var driveId = drive.GetInstanceID();
                        if (driveId != InstanceID)
                        {
                            drive.IsSlave = true;
                            UnityEngine.Debug.Log("KSPI - AlcubierreDrive " + driveId + " != " + InstanceID);
                        }
                    }
                }

                UnityEngine.Debug.Log("KSPI - AlcubierreDrive OnStart step C ");

                this.part.force_activate();
                if (serialisedwarpvector != null)
                {
                    heading_act = ConfigNode.ParseVector3D(serialisedwarpvector);
                }

                warp_effect  = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                warp_effect2 = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

                warp_effect1_renderer = warp_effect.GetComponent <Renderer>();
                warp_effect2_renderer = warp_effect2.GetComponent <Renderer>();

                warp_effect1_collider = warp_effect.GetComponent <Collider>();
                warp_effect2_collider = warp_effect2.GetComponent <Collider>();

                warp_effect1_collider.enabled = false;
                warp_effect2_collider.enabled = false;

                Vector3 ship_pos     = new Vector3(part.transform.position.x, part.transform.position.y, part.transform.position.z);
                Vector3 end_beam_pos = ship_pos + transform.up * warp_size;
                Vector3 mid_pos      = (ship_pos - end_beam_pos) / 2.0f;

                warp_effect.transform.localScale = new Vector3(effectSize1, mid_pos.magnitude, effectSize1);
                warp_effect.transform.position   = new Vector3(mid_pos.x, ship_pos.y + mid_pos.y, mid_pos.z);
                warp_effect.transform.rotation   = part.transform.rotation;

                warp_effect2.transform.localScale = new Vector3(effectSize2, mid_pos.magnitude, effectSize2);
                warp_effect2.transform.position   = new Vector3(mid_pos.x, ship_pos.y + mid_pos.y, mid_pos.z);
                warp_effect2.transform.rotation   = part.transform.rotation;

                //warp_effect.layer = LayerMask.NameToLayer("Ignore Raycast");
                //warp_effect.renderer.material = new Material(KSP.IO.File.ReadAllText<AlcubierreDrive>("AlphaSelfIllum.shader"));

                warp_effect1_renderer.material.shader = Shader.Find("Unlit/Transparent");
                warp_effect2_renderer.material.shader = Shader.Find("Unlit/Transparent");

                warp_textures = new Texture[33];

                const string warp_tecture_path = "WarpPlugin/ParticleFX/warp";
                for (int i = 0; i < 11; i++)
                {
                    warp_textures[i] = GameDatabase.Instance.GetTexture((i > 0)
                        ? warp_tecture_path + (i + 1).ToString()
                        : warp_tecture_path, false);
                }

                warp_textures[11] = GameDatabase.Instance.GetTexture("WarpPlugin/ParticleFX/warp10", false);
                for (int i = 12; i < 33; i++)
                {
                    int j = i > 17 ? 34 - i : i;
                    warp_textures[i] = GameDatabase.Instance.GetTexture(j > 1 ?
                                                                        warp_tecture_path + (j + 1).ToString() : warp_tecture_path, false);
                }

                warp_textures2 = new Texture[33];

                const string warpr_tecture_path = "WarpPlugin/ParticleFX/warpr";
                for (int i = 0; i < 11; i++)
                {
                    warp_textures2[i] = GameDatabase.Instance.GetTexture((i > 0)
                        ? warpr_tecture_path + (i + 1).ToString()
                        : warpr_tecture_path, false);
                }

                warp_textures2[11] = GameDatabase.Instance.GetTexture("WarpPlugin/ParticleFX/warpr10", false);
                for (int i = 12; i < 33; i++)
                {
                    int j = i > 17 ? 34 - i : i;
                    warp_textures2[i] = GameDatabase.Instance.GetTexture(j > 1 ?
                                                                         warpr_tecture_path + (j + 1).ToString() : warpr_tecture_path, false);
                }

                warp_effect1_renderer.material.color = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.5f);
                warp_effect2_renderer.material.color = new Color(Color.red.r, Color.red.g, Color.red.b, 0.1f);

                warp_effect1_renderer.material.mainTexture = warp_textures[0];
                warp_effect1_renderer.receiveShadows       = false;
                //warp_effect.layer = LayerMask.NameToLayer ("Ignore Raycast");
                //warp_effect.collider.isTrigger = true;
                warp_effect2_renderer.material.mainTexture       = warp_textures2[0];
                warp_effect2_renderer.receiveShadows             = false;
                warp_effect2_renderer.material.mainTextureOffset = new Vector2(-0.2f, -0.2f);
                //warp_effect2.layer = LayerMask.NameToLayer ("Ignore Raycast");
                //warp_effect2.collider.isTrigger = true;
                warp_effect2_renderer.material.renderQueue = 1000;
                warp_effect1_renderer.material.renderQueue = 1001;

                /*gameObject.AddComponent<Light>();
                 * gameObject.light.color = Color.cyan;
                 * gameObject.light.intensity = 1f;
                 * gameObject.light.range = 4000f;
                 * gameObject.light.type = LightType.Spot;
                 * gameObject.light.transform.position = end_beam_pos;
                 * gameObject.light.cullingMask = ~0;*/

                //light.

                warp_sound        = gameObject.AddComponent <AudioSource>();
                warp_sound.clip   = GameDatabase.Instance.GetAudioClip("WarpPlugin/Sounds/warp_sound");
                warp_sound.volume = GameSettings.SHIP_VOLUME;

                //warp_sound.panLevel = 0;
                warp_sound.panStereo   = 0;
                warp_sound.rolloffMode = AudioRolloffMode.Linear;
                warp_sound.Stop();

                if (IsEnabled)
                {
                    warp_sound.Play();
                    warp_sound.loop = true;
                }

                bool manual_upgrade = false;
                if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
                {
                    if (upgradeTechReq != null)
                    {
                        if (PluginHelper.hasTech(upgradeTechReq))
                        {
                            hasrequiredupgrade = true;
                        }
                        else if (upgradeTechReq == "none")
                        {
                            manual_upgrade = true;
                        }
                    }
                    else
                    {
                        manual_upgrade = true;
                    }
                }
                else
                {
                    hasrequiredupgrade = true;
                }

                if (warpInit == false)
                {
                    warpInit = true;
                    if (hasrequiredupgrade)
                    {
                        isupgraded = true;
                    }
                }

                if (manual_upgrade)
                {
                    hasrequiredupgrade = true;
                }


                if (isupgraded)
                {
                    warpdriveType = upgradedName;
                }
                else
                {
                    warpdriveType = originalName;
                }

                //warp_effect.transform.localScale.y = 2.5f;
                //warp_effect.transform.localScale.z = 200f;

                // disable charging at startup
                //IsCharging = false;
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("[KSPI] - AlcubierreDrive OnStart 1 Exception " + e.Message);
            }

            warpdriveType = originalName;
        }
Example #22
0
        public override void OnStart(PartModule.StartState state)
        {
            if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (!CompatibilityChecker.IsCompatible())
            {
                foreach (BaseAction action in Actions)
                {
                    action.active = false;
                }
                foreach (BaseEvent evnt in Events)
                {
                    evnt.active          = false;
                    evnt.guiActive       = false;
                    evnt.guiActiveEditor = false;
                }
                foreach (BaseField field in Fields)
                {
                    field.guiActive       = false;
                    field.guiActiveEditor = false;
                }
                return;
            }
            //Staging icon
            this.part.stagingIcon = "PARACHUTES";

            //Autoarming checkup
            settings = RealChuteSettings.fetch;

            //Part GUI
            Events["GUIDeploy"].active             = true;
            Events["GUICut"].active                = false;
            Events["GUISecCut"].active             = false;
            Events["GUIArm"].active                = true;
            Events["GUICutBoth"].active            = false;
            Events["GUIRepack"].guiActiveUnfocused = false;
            if (spareChutes < 0)
            {
                Fields["chuteCount"].guiActive = false;
            }
            if (!secondaryChute)
            {
                Actions["ActionSecCut"].active  = false;
                Actions["ActionCutBoth"].active = false;
                Actions["ActionCut"].guiName    = "Cut chute";
                Events["GUICut"].guiName        = "Cut chute";
            }

            if (settings.autoArm)
            {
                Events["GUIArm"].active     = false;
                Actions["ActionArm"].active = false;
            }
            else
            {
                Events["GUIArm"].active     = true;
                Actions["ActionArm"].active = true;
            }

            //Tweakables tooltip
            if (this.part.Modules.Contains("ProceduralChute") || !isTweakable)
            {
                foreach (BaseField field in Fields)
                {
                    field.guiActiveEditor = false;
                }
            }
            else if (!secondaryChute)
            {
                Fields["secPreDeployedDiameter"].guiActiveEditor = false;
                Fields["secDeployedDiameter"].guiActiveEditor    = false;
                Fields["secMinIsPressure"].guiActiveEditor       = false;
                Fields["secMinDeployment"].guiActiveEditor       = false;
                Fields["secMinPressure"].guiActiveEditor         = false;
                Fields["secDeploymentAlt"].guiActiveEditor       = false;
                Fields["secCutAlt"].guiActiveEditor             = false;
                Fields["secPreDeploymentSpeed"].guiActiveEditor = false;
                Fields["secDeploymentSpeed"].guiActiveEditor    = false;
            }

            //Initiates animations
            anim = this.part.FindModelAnimators(capName).FirstOrDefault();

            //Initiates the Parachutes
            main = new Parachute(this, false);
            if (secondaryChute)
            {
                secondary = new Parachute(this, true);
            }

            //First initiation of the part
            if (!initiated)
            {
                initiated     = true;
                capOff        = false;
                armed         = false;
                this.baseDrag = this.part.maximum_drag;
                if (spareChutes >= 0)
                {
                    chuteCount = (int)spareChutes;
                }
            }

            //Flight loading
            if (HighLogic.LoadedSceneIsFlight)
            {
                //If the part has been staged in the past
                if (capOff)
                {
                    this.part.stackIcon.SetIconColor(XKCDColors.Red);
                }
                System.Random random = new System.Random();
                main.randomTime = (float)random.NextDouble();
                if (secondaryChute)
                {
                    secondary.randomTime = (float)random.NextDouble();
                }
            }

            //GUI
            window = new Rect(200, 100, 350, 400);
        }
 public override void OnStart(PartModule.StartState state)
 {
     editedWindow = core.GetComputerModule <MechJebModuleCustomInfoWindow>();
 }
Example #24
0
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES, FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);
            generatorType = originalName;
            if (state == StartState.Editor)
            {
                //if (hasTechsRequiredToUpgrade())
                //{
                //    isupgraded = true;
                //    hasrequiredupgrade = true;
                //    upgradePartModule();
                //}
                part.OnEditorAttach += OnEditorAttach;
                return;
            }

            //if (hasTechsRequiredToUpgrade())
            //{
            //    hasrequiredupgrade = true;
            //}

            this.part.force_activate();


            anim = part.FindModelAnimators(animName).FirstOrDefault();
            if (anim != null)
            {
                anim[animName].layer = 1;
                if (!IsEnabled)
                {
                    anim[animName].normalizedTime = 1f;
                    anim[animName].speed          = -1f;
                }
                else
                {
                    anim[animName].normalizedTime = 0f;
                    anim[animName].speed          = 1f;
                }
                anim.Play();
            }

            if (generatorInit == false)
            {
                generatorInit = true;
                IsEnabled     = true;
            }

            //if (isupgraded)
            //{
            //    upgradePartModule();
            //}

            foreach (AttachNode attach_node in part.attachNodes)
            {
                if (attach_node.attachedPart != null)
                {
                    List <FNThermalSource> sources = attach_node.attachedPart.FindModulesImplementing <FNThermalSource>();
                    if (sources.Count > 0)
                    {
                        myAttachedReactor = sources.First();
                        if (myAttachedReactor != null)
                        {
                            break;
                        }
                    }
                }
            }

            print("[KSP Interstellar] Configuring Generator");
        }
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                stopWatch = new Stopwatch();

                speedOfLight = GameConstants.speedOfLight * PluginHelper.SpeedOfLightMult;

                deteuriumResourceDefinition = PartResourceLibrary.Instance.GetDefinition(InterstellarResourcesConfiguration.Instance.LqdDeuterium);
                helium3ResourceDefinition   = PartResourceLibrary.Instance.GetDefinition(InterstellarResourcesConfiguration.Instance.LqdHelium3);

                densityLqdDeuterium = deteuriumResourceDefinition.density;
                densityLqdHelium3   = helium3ResourceDefinition.density;

                deteuriumFraction = densityLqdDeuterium / (densityLqdHelium3 + densityLqdDeuterium);
                helium3Fraction   = densityLqdHelium3 / (densityLqdHelium3 + densityLqdDeuterium);

                propellantAverageDensity = densityLqdDeuterium / densityLqdHelium3;

                part.maxTemp             = maxTemp;
                part.thermalMass         = 1;
                part.thermalMassModifier = 1;

                engineType = originalName;
                curEngineT = this.part.FindModuleImplementing <ModuleEngines>();

                if (curEngineT == null)
                {
                    return;
                }

                engineIsp = curEngineT.atmosphereCurve.Evaluate(0);

                // if we can upgrade, let's do so
                if (isupgraded)
                {
                    upgradePartModule();
                }
                else if (this.HasTechsRequiredToUpgrade())
                {
                    hasrequiredupgrade = true;
                }

                // calculate WasteHeat Capacity
                part.Resources[FNResourceManager.FNRESOURCE_WASTEHEAT].maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;

                if (state == StartState.Editor && this.HasTechsRequiredToUpgrade())
                {
                    isupgraded = true;
                    upgradePartModule();
                }

                if (state == StartState.Editor)
                {
                    // fetch all parts
                    var fetchedShipParts = EditorLogic.fetch.ship.parts;

                    deteuriumPartResources = fetchedShipParts
                                             .Where(m => m.Resources.Contains(InterstellarResourcesConfiguration.Instance.LqdDeuterium))
                                             .Select(m => m.Resources[InterstellarResourcesConfiguration.Instance.LqdDeuterium]).ToList();
                    helium3PartResources = fetchedShipParts
                                           .Where(m => m.Resources.Contains(InterstellarResourcesConfiguration.Instance.LqdHelium3))
                                           .Select(m => m.Resources[InterstellarResourcesConfiguration.Instance.LqdHelium3]).ToList();
                }
                else
                {
                    //deteuriumPartResources = part.GetConnectedResources(InterstellarResourcesConfiguration.Instance.LqdDeuterium).ToList();
                    deteuriumPartResources = part.vessel.parts.SelectMany(p => p.Resources.Where(r => r.resourceName == InterstellarResourcesConfiguration.Instance.LqdDeuterium)).ToList();

                    //helium3PartResources = part.GetConnectedResources(InterstellarResourcesConfiguration.Instance.LqdHelium3).ToList();
                    deteuriumPartResources = part.vessel.parts.SelectMany(p => p.Resources.Where(r => r.resourceName == InterstellarResourcesConfiguration.Instance.LqdHelium3)).ToList();
                }

                // bind with fields and events
                deactivateRadSafetyEvent = Events["DeactivateRadSafety"];
                activateRadSafetyEvent   = Events["ActivateRadSafety"];
                retrofitEngineEvent      = Events["RetrofitEngine"];
                radhazardstrField        = Fields["radhazardstr"];
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("[KSPI] - Error OnStart " + e.Message + " stack " + e.StackTrace);
            }
        }
Example #26
0
        public override void OnStart(PartModule.StartState state)
        {
            print("[KSP Interstellar]  Generator OnStart Begin " + startcount);

            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES, FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;

            if (state == PartModule.StartState.Docked)
            {
                base.OnStart(state);
                return;
            }

            // calculate WasteHeat Capacity
            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);

            if (wasteheatPowerResource != null)
            {
                var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * ratio;
            }

            previousTimeWarp  = TimeWarp.fixedDeltaTime - 1.0e-6f;
            megajouleResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_MEGAJOULES);

            base.OnStart(state);
            generatorType = originalName;

            Fields["maxChargedPower"].guiActive = chargedParticleMode;
            Fields["maxThermalPower"].guiActive = !chargedParticleMode;

            if (state == StartState.Editor)
            {
                if (this.HasTechsRequiredToUpgrade())
                {
                    isupgraded         = true;
                    hasrequiredupgrade = true;
                    upgradePartModule();
                }
                part.OnEditorAttach += OnEditorAttach;
                return;
            }

            if (this.HasTechsRequiredToUpgrade())
            {
                hasrequiredupgrade = true;
            }

            this.part.force_activate();

            anim = part.FindModelAnimators(animName).FirstOrDefault();
            if (anim != null)
            {
                anim[animName].layer = 1;
                if (!IsEnabled)
                {
                    anim[animName].normalizedTime = 1f;
                    anim[animName].speed          = -1f;
                }
                else
                {
                    anim[animName].normalizedTime = 0f;
                    anim[animName].speed          = 1f;
                }
                anim.Play();
            }

            if (generatorInit == false)
            {
                generatorInit = true;
                IsEnabled     = true;
            }

            if (isupgraded)
            {
                upgradePartModule();
            }

            FindAttachedThermalSource();

            UpdateHeatExchangedThrustDivisor();

            print("[KSP Interstellar]  Generator OnStart Finished");
        }
Example #27
0
        public override void OnStart(PartModule.StartState state)
        {
            //Connection with IRRobotics sequencer
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (assembly.FullName.Contains("InfernalRobotics"))
                {
                    this.compatiblePluginsInstalled.Add("IRSequencer");
                }
                else if (assembly.FullName.Contains("kOS"))
                {
                    this.compatiblePluginsInstalled.Add("kOS");
                }
            }
            List <String> actionsNamesList = new List <String> ();

            actionsNamesList.Add("Timer");
            actionsNamesList.Add("Decouple");
            actionsNamesList.Add("Dock Shield");
            actionsNamesList.Add("Staging");
            actionsNamesList.Add("Target Dock");
            actionsNamesList.Add("Target Body");
            actionsNamesList.Add("Control From");
            actionsNamesList.Add("Pause");
            actionsNamesList.Add("Crew Transfer");
            actionsNamesList.Add("Quicksave");
            actionsNamesList.Add("RCS");
            actionsNamesList.Add("Switch Vessel");
            actionsNamesList.Add("Activate Engine");
            actionsNamesList.Add("SAS");
            actionsNamesList.Add("Maneuver");
            actionsNamesList.Add("Execute node");
            actionsNamesList.Add("Action Group");
            actionsNamesList.Add("Node tolerance");
            actionsNamesList.Add("Warp");
            actionsNamesList.Add("Wait for");
            actionsNamesList.Add("Load Script");
            actionsNamesList.Add("MODULE Ascent Autopilot");
            actionsNamesList.Add("MODULE Docking Autopilot");
            actionsNamesList.Add("MODULE Landing");
            actionsNamesList.Add("MODULE Rendezvous");
            actionsNamesList.Add("MODULE Rendezvous Autopilot");
            if (checkCompatiblePluginInstalled("IRSequencer"))
            {
                actionsNamesList.Add("[IR Sequencer] Sequence");
            }
            if (checkCompatiblePluginInstalled("kOS"))
            {
                actionsNamesList.Add("[kOS] Command");
            }

            actionNames = actionsNamesList.ToArray();

            //Don't know why sometimes this value can be "empty" but not null, causing an empty vessel name...
            if (vesselSaveName != null)
            {
                if (vesselSaveName.Length == 0)
                {
                    vesselSaveName = null;
                }
            }

            if (vessel != null)
            {
                if (vesselSaveName == null)
                {
                    //Try to have only one vessel name, whatever the new vessel name. We use the vessel name of the first time the system was instanciated
                    //Can cause problem with load/save...
                    vesselSaveName = vessel != null?string.Join("_", vessel.vesselName.Split(System.IO.Path.GetInvalidFileNameChars())) : null;                       // Strip illegal char from the filename
                }

                //MechJebCore instances
                List <MechJebCore> mechjebCoresList = vessel.FindPartModulesImplementing <MechJebCore>();
                if (mechjebCoresList.Count > 1)
                {
                    foreach (MechJebCore mjCore in mechjebCoresList)
                    {
                        if (mjCore.GetComputerModule <MechJebModuleScript>() != null)
                        {
                            if (mjCore.GetComputerModule <MechJebModuleScript>().vesselSaveName == null)
                            {
                                mjCore.GetComputerModule <MechJebModuleScript>().vesselSaveName = vesselSaveName;                                //Set the unique vessel name
                            }
                        }
                    }
                }
            }
            this.LoadScriptModuleConfig();
            this.moduleStarted = true;
        }
Example #28
0
 public extern override void OnStart(PartModule.StartState state);
Example #29
0
        public override void OnStart(PartModule.StartState state)
        {
            if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (!CompatibilityChecker.IsAllCompatible())
            {
                foreach (BaseAction action in Actions)
                {
                    action.active = false;
                }
                foreach (BaseEvent evnt in Events)
                {
                    evnt.active          = false;
                    evnt.guiActive       = false;
                    evnt.guiActiveEditor = false;
                }
                Fields["chuteCount"].guiActive = false;
                return;
            }

            //Staging icon
            this.part.stagingIcon = "PARACHUTES";

            //Autoarming checkup
            settings = RealChuteSettings.fetch;

            //Part GUI
            if (spareChutes < 0)
            {
                Fields["chuteCount"].guiActive = false;
            }
            if (!secondaryChute)
            {
                Actions["ActionCut"].guiName = "Cut chute";
                Events["GUICut"].guiName     = "Cut chute";
            }
            Actions["ActionArm"].active = !settings.autoArm;

            //Initiates the Parachutes
            LoadParachutes();
            parachutes.ForEach(p => p.Initialize());

            //First initiation of the part
            if (!initiated)
            {
                initiated = true;
                armed     = false;
                if (spareChutes >= 0)
                {
                    chuteCount = (int)spareChutes;
                }
            }

            //Flight loading
            if (HighLogic.LoadedSceneIsFlight)
            {
                System.Random random = new System.Random();
                parachutes.ForEach(p => p.randomTime = (float)random.NextDouble());

                //Hide/show UI event addition
                GameEvents.onHideUI.Add(HideUI);
                GameEvents.onShowUI.Add(ShowUI);

                if (canRepack)
                {
                    SetRepack();
                }
            }

            //GUI
            window = new Rect(200, 100, 350, 400);
        }
 public void OnStart(PartModule.StartState state)
 {
     m_startState = state;
     // Single Target Mode.
     Debug.Log("Trying to get field info of: " + targetField);
     SetInitialValueOfField(targetField);
 }
Example #31
0
 public override void OnStart(PartModule.StartState state)
 {
     base.OnStart(state);
     this.module = base.part.Modules["FARControllableSurface"];
 }