Exemple #1
0
        protected new void Start()
        {
            phl = PartHighlighter.CreatePartHighlighter();
            if (phl == false)
            {
                return;
            }
            highlightID = phl.CreateHighlightList();
            if (highlightID < 0)
            {
                return;
            }

            if (this.vessel != null)
            {
                InitAllPartResources();
            }
            else
            {
                Log.Info("PWBVesselModule.Start, vessel: null");
            }

            UpdateHighlightColors();
            GameEvents.OnGameSettingsApplied.Add(UpdateHighlightColors);
            base.Start();
        }
        protected void Start()
        {
            phl = PartHighlighter.CreatePartHighlighter();
            if (phl == false)
            {
                return;
            }
            highlightID = phl.CreateHighlightList();
            if (highlightID < 0)
            {
                return;
            }

            phl.AddPartToHighlight(highlightID, this.part);
            UpdateColors();
            GameEvents.OnGameSettingsApplied.Add(UpdateColors);
        }
        public void Start()
        {
            Log.Info("Start");
            part.RestoreVariant();
#if false
            SetThrustCurve(grainName, null);
#endif

            Events["TriggerEngineFailureEvent"].active   = HighLogic.CurrentGame.Parameters.CustomParams <MSSRB_1>().devMode;
            Actions["TriggerEngineFailureAction"].active = HighLogic.CurrentGame.Parameters.CustomParams <MSSRB_1>().devMode;

#if false
            foreach (var e in Events)
            {
                Log.Info("Event: " + e.name + ", guiName = " + e.guiName);
            }
            foreach (var a in Actions)
            {
                Log.Info("Action: " + a.name + ", guiName: " + a.guiName);
            }
            foreach (var f in Fields)
            {
                Log.Info("Field: " + f.name + ", guiName: " + f.guiName);
            }
#endif

            Fields["independentThrottle"].guiActive           =
                Fields["independentThrottle"].guiActiveEditor = false;
            Fields["thrustPercentage"].guiActive           =
                Fields["thrustPercentage"].guiActiveEditor = false;



            origAtmosphereCurve = atmosphereCurve;

            PartResourceDefinition prd = PartResourceLibrary.Instance.GetDefinition(ModSegSRBs.Propellant);
            density            = prd.density;
            densityInverse     = 1.0 / prd.density;
            fuelFlowMultiplier = densityInverse * Planetarium.fetch.fixedDeltaTime;

            phl = PartHighlighter.CreatePartHighlighter();
            if (phl)
            {
                highlightID = phl.CreateHighlightList();
            }
            if (highlightID >= 0)
            {
                UpdateHighlightColors();
            }

            PartModuleList pml = part.Modules;
            if (pml.Contains("MSSRB_Fuel_Segment"))
            {
                MSSRB_Fuel_Segment moduleFuelSegment = pml["MSSRB_Fuel_Segment"] as MSSRB_Fuel_Segment;
                part.segmentWidth = moduleFuelSegment.part.segmentWidth;
            }
            else
            {
                Log.Info("MSSRB_Engine, missing MSSRB_Fuel_Segment");
            }

            foreach (var p in propellants)
            {
                if (p.name == ModSegSRBs.BurnablePropellant)
                {
                    break;
                }
                burnablePropIndx++;
            }
            foreach (var p in propellants)
            {
                if (p.name == ModSegSRBs.Propellant)
                {
                    break;
                }
                propIndx++;
            }
            ModSegSRBs.GetExtraInfo(part.baseVariant, ref part.segmentHeight, ref part.segmentWidth);

            switch (HighLogic.LoadedScene)
            {
            case GameScenes.EDITOR:
                GameEvents.onEditorPartPicked.Add(onEditorPartPicked);
                GameEvents.onEditorPartPlaced.Add(onEditorPartPlaced);
                GameEvents.onEditorPartDeleted.Add(onEditorPartDeleted);
                GameEvents.onVariantApplied.Add(onEditorVariantApplied);
                ScheduleSegmentUpdate("Start");
                break;

            case GameScenes.FLIGHT:
                failureChance = HighLogic.CurrentGame.Parameters.CustomParams <MSSRB_1>().failureChance;
                if (this.vessel.situation <= Vessel.Situations.PRELAUNCH)
                {
                    UpdateSegments();
                    foreach (var s in segments)
                    {
                        /* PartModuleList */
                        pml = s.part.Modules;
                        MSSRB_Fuel_Segment moduleFuelSegment = pml["MSSRB_Fuel_Segment"] as MSSRB_Fuel_Segment;

                        PartResourceList prl = s.part.Resources;
                        if (prl.Contains(ModSegSRBs.Propellant))
                        {
                            //Log.Info("Segment: " + s.part.partInfo.title + " contains Propellant");
                            prl[ModSegSRBs.Propellant].amount = moduleFuelSegment.MaxSolidFuel();
                        }
                        if (prl.Contains(ModSegSRBs.BurnablePropellant))
                        {
                            prl[ModSegSRBs.BurnablePropellant].amount = 0;
                            //prl[ModSegSRBs.BurnablePropellant].amount = moduleFuelSegment.MaxSolidFuel();

                            //Log.Info("Segment: " + s.part.partInfo.title + " contains BurnablePropellant");
                        }
                    }
                }
                break;
            } // switch
        }
        /// <summary>
        /// Module re-start logic. OnStart will be called usually once for each scene, editor included.
        /// Put your custom start logic in DI_Start(): if you need to act on other part's
        /// variable, this is the place to do it, not DI_Reset()
        /// </summary>
        public override void OnStart(PartModule.StartState state)
        {
            Log.Info("FailureModule.OnStart, part: " + this.part.partInfo.title);
            try
            {
                if (HighLogic.LoadedSceneIsFlight) // nothing to do in editor
                {
                    this.FailureLog("Starting in flight: last reset " + TimeOfLastReset + ", now " + DangIt.Now());

                    if (!DangIt.Instance.CurrentSettings.EnabledForSave)
                    { //Disable if we've disabled DangIt
                        foreach (var e in this.Events)
                        {
                            e.guiActive = false;
                        }
                    }

                    #region Fail and repair events

                    this.Events["Fail"].guiName        = this.FailGuiName;
                    this.Events["EvaRepair"].guiName   = this.EvaRepairGuiName;
                    this.Events["Maintenance"].guiName = this.MaintenanceString;

                    #endregion

                    // Reset the internal state at the beginning of the flight
                    // this condition also catches a revert to launch (+1 second for safety)
                    if (DangIt.Now() < (this.TimeOfLastReset + 1))
                    {
                        this.Reset();
                    }

                    // If the part was saved when it was failed,
                    // re-run the failure logic to disable it
                    // ONLY THE DISABLING PART IS RUN!
                    if (this.HasFailed)
                    {
                        this.DI_Disable();
                    }

                    this.SetFailureState(this.HasFailed);

                    if (!vesselHighlightDict.ContainsKey(vessel.id))
                    {
                        var failedHighlightID = phl.CreateHighlightList(0);
                        if (failedHighlightID < 0)
                        {
                            return;
                        }
                        if (DangIt.Instance.CurrentSettings.FlashingGlow)
                        {
                            phl.SetFlashInterval(failedHighlightID, HighLogic.CurrentGame.Parameters.CustomParams <DangItCustomParams1>().flashingInterval);
                        }
                        vesselHighlightDict[vessel.id] = failedHighlightID;
                    }
                    phl.UpdateHighlightColors(vesselHighlightDict[vessel.id], Color.red);


                    if (DangIt.Instance.CurrentSettings.EnabledForSave)
                    {
                        this.DI_Start(state);
                        this.StartCoroutine("RuntimeFetch");
                    }
                }
            }
            catch (Exception e)
            {
                OnError(e);
            }
        }